Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't disallow Bottom returns. #510

Merged
merged 1 commit into from
Sep 12, 2023
Merged

Don't disallow Bottom returns. #510

merged 1 commit into from
Sep 12, 2023

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Sep 11, 2023

Trial balloon. Currently, we eagerly disallow returns, even of Union{} (which indicates an error):

julia> @cuda threads=(10, 10) kernel(array_dev)
ERROR: GPU compilation of MethodInstance for kernel(::CuDeviceVector{Int64, 1, Int32}) failed
KernelError: kernel returns a value of type `Union{}`

Make sure your kernel function ends in `return`, `return nothing` or `nothing`.
If the returned value is of type `Union{}`, your Julia code probably throws an exception.
Inspect the code with `@device_code_warntype` for more details.

Stacktrace:
  [1] check_method(job::GPUCompiler.CompilerJob)
    @ GPUCompiler ~/Julia/pkg/GPUCompiler/src/validation.jl:36
  [2] macro expansion
    @ GPUCompiler ~/Julia/pkg/GPUCompiler/src/driver.jl:122 [inlined]

I'm not sure that's very user-friendly however, as it requires the user to use Cthulhu or similar to figure out where the error was introduced. If we just allow the error, it's likely that we'll be able to report something better later on:

julia> @cuda threads=(10, 10) kernel(array_dev)
ERROR: InvalidIRError: compiling MethodInstance for kernel(::CuDeviceVector{Int64, 1, Int32}) resulted in invalid LLVM IR
...
Reason: unsupported use of an undefined name (use of 'i32')
Stacktrace:
 [1] kernel
   @ ./REPL[3]:2

cc @vchuravy

Although we inferred some kind of error, it's likely that deferring
validation will yield better error messages.
@maleadt maleadt marked this pull request as draft September 11, 2023 14:57
@vchuravy
Copy link
Member

I like this! Gives a much better error in the end/

@maleadt
Copy link
Member Author

maleadt commented Sep 12, 2023

Yeah this seems strictly better. Because of how test suites rely on the KernelError though, we'll have to make this a breaking change (albeit one easy to adapt to).

@maleadt maleadt marked this pull request as ready for review September 12, 2023 08:04
@maleadt maleadt merged commit 96c351e into master Sep 12, 2023
@maleadt maleadt deleted the tb/return_bottom branch September 12, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants