diku-dk / futhark

:boom::computer::boom: A data-parallel functional programming language
http://futhark-lang.org
ISC License
2.41k stars 166 forks source link

Internal Compiler Error when Compiling to Cuda and OpenCL, Works with compilation to C #2176

Closed Holindauer closed 2 months ago

Holindauer commented 2 months ago

Hello, I have just run into an interesting bug.

While working on some futhark code, I added a new entry point to my main.fut file. There were no syntax errors/ any reason to think the code would not compile. For some reason, I was not able to compile to Cuda or OpenCL. However, compiling to C still works fine.

Not exactly sure why. It is not always consistent when/why this happens.

I noticed that even if I commented out the entry port that seemed to have caused the compilation error, it would still not compile for Cuda/OpenCL.

If I commented all of the code, then I was able to compile with Cuda/OpenCL. I could even uncomment portions of the main.fut that had been commented out and it would also compile. Though, once that entry port was uncommented, it would fail again, even after commenting out.

I was able to replicate this on two different machines.

Below are the error messages I was shown when this happened:

$ futhark opencl main.fut Internal compiler error (unhandled IO exception). Please report this at https://github.com/diku-dk/futhark/issues Scope.lookupInfo: Name mem_35410 not found in type environment. CallStack (from HasCallStack): error, called at src/Futhark/IR/Prop/Scope.hs:85:9 in futhark-0.26.0-inplace:Futhark.IR.Prop.Scope

$ futhark cuda main.fut Internal compiler error (unhandled IO exception). Please report this at https://github.com/diku-dk/futhark/issues Scope.lookupInfo: Name mem_35410 not found in type environment. CallStack (from HasCallStack): error, called at src/Futhark/IR/Prop/Scope.hs:85:9 in futhark-0.26.0-inplace:Futhark.IR.Prop.Scope

$ futhark c main.fut # <--- this works

athas commented 2 months ago

It's probably a bug in a pass that only runs with the GPU backends. Deleting entry points can cause code to go dead and be removed before it makes it to the problematic pass. Can I see the program?

Holindauer commented 2 months ago

Here is the main file with the problematic entry point at line 70:

https://github.com/Holindauer/ruthark/blob/a828904c12364ffc8aa333dcf8a66b65607a460c/fut-src/main.fut#L70

athas commented 2 months ago

I can reproduce. It is a bug in memory short circuiting. It looks like a minor oversight, and I hope that this is true.