You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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?
The text was updated successfully, but these errors were encountered:
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
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 togpu_throw($(Symbol("SomeException")))
, and at the LLVM level then simply detect thegpu_throw
, look up the symbol by dereferencing the pointer as embedded in the IR, and emit calls toreport_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?
The text was updated successfully, but these errors were encountered: