JuliaGPU / JuliaGPU/GPUCompiler.jl
Capture exception information
- Dominant language
- Julia
- Stars
- 187
- Forks
- 68
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 28
Description
## 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: https://github.com/JuliaGPU/GPUCompiler.jl/blob/0c9292f1b9243b0e8d4d0f6b5bf40cf5a9359b7c/src/irgen.jl#L139-L155
That means that code doing a simple `throw(BoundsError())` will result in a generic exception being reported. In https://github.com/JuliaGPU/CUDA.jl/pull/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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the exception handling in src/irgen.jl, especially the linked lines 139-155, and compare it with the workaround in CUDA.jl PR #2342. Investigate Julia IR transformations for calls to throw(::SomeException). Done means exception names such as BoundsError are preserved into the existing LLVM-level reporting path instead of becoming generic exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100