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

Capture exception information #574

Open
maleadt opened this issue Apr 25, 2024 · 0 comments
Open

Capture exception information #574

maleadt opened this issue Apr 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@maleadt
Copy link
Member

maleadt commented Apr 25, 2024

Problem

GPUCompiler requires back-ends to provide a report_exception(name::String) function, which it invokes from IR with the name of the exception type as figured out from the code generated by Julia. As this happens at the LLVM level though, we can only figure out the exception type if we spot calls to well-known runtime functions:

GPUCompiler.jl/src/irgen.jl

Lines 139 to 155 in 0c9292f

throw_functions = [
# unsupported runtime functions that are used to throw specific exceptions
"jl_throw" => "exception",
"jl_error" => "error",
"jl_too_few_args" => "too few arguments exception",
"jl_too_many_args" => "too many arguments exception",
"jl_type_error" => "type error",
"jl_type_error_rt" => "type error",
"jl_undefined_var_error" => "undefined variable error",
"jl_bounds_error" => "bounds error",
"jl_bounds_error_v" => "bounds error",
"jl_bounds_error_int" => "bounds error",
"jl_bounds_error_tuple_int" => "bounds error",
"jl_bounds_error_unboxed_int" => "bounds error",
"jl_bounds_error_ints" => "bounds error",
"jl_eof_error" => "EOF error",
]

That means that code doing a simple throw(BoundsError()) will result in a generic exception being reported. In JuliaGPU/CUDA.jl#2342, I work around this by making it possible to forward additional information to the CUDA.jl-specific exception reporting code, however, it would be better if GPUCompiler could just figure out some more by looking at the Julia IR.

Potential solution

So instead of emitting exceptions during LLVM IR generation, we need a pass that operates on Julia IR and here detects calls to throw(::SomeException). It's not entirely clear what to replace this with, as we ultimately need a global string pointer with the exception name. Maybe it would work to emit a call to gpu_throw($(Symbol("SomeException"))), and at the LLVM level then simply detect the gpu_throw, look up the symbol by dereferencing the pointer as embedded in the IR, and emit calls to report_name etc as we currently do.

I'm happy to work on this, but am not familiar enough with IR transformations to implement the first part of this proposal. @vchuravy Do you have a clear view on how to do this (and maybe the time to POC it) so that I could continue to make things work with the existing exception code?

@maleadt maleadt added the enhancement New feature or request label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant