Skip to content

Report exceptions by throw site - #768

Merged
maleadt merged 1 commit into
mainfrom
tb/exception-sites
Nov 20, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/exception-sites

Conversation

@maleadt

@maleadt maleadt commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Kernels now report exceptions through GPUCompiler's reporting by throw site (JuliaGPU/GPUCompiler.jl#1100). A throw only records which site threw, in which kernel, and which work-item did. The host then looks the site up in the table that compilation returned for that kernel. The device no longer passes along string pointers and backtrace frames.

This mostly matters for performance. Each bounds check used to carry its own out-of-line calls to the reporting functions, and any call left in the SPIR-V makes IGC compile the whole kernel at SIMD8 instead of SIMD32. Now all throw sites of a kernel branch to a single inlined copy of the reporting code, so the SPIR-V has no OpFunctionCall left and IGC goes back to SIMD32.

Micro-benchmark on an Iris Xe (sagittarius): 2^22 work-items, each doing N bounds-checked reads, compared with @inbounds. Best of 20 runs. The host was also running CI jobs, so absolute times are somewhat noisy.

N variant before after
256 inbounds 8.8 ms, SIMD32, 42 KB ISA 9.0 ms, SIMD32, 42 KB ISA
256 checked 49.4 ms (5.6x), SIMD8, 772 calls, 202 KB ISA 27.7 ms (3.1x), SIMD32, 0 calls, 192 KB ISA
64 inbounds 2.6 ms 2.5 ms
64 checked 7.3 ms (2.8x), SIMD8, 196 calls, 59 KB ISA 4.6 ms (1.8x), SIMD32, 0 calls, 54 KB ISA

Neither version needs spill or private memory.

What users see: KernelException keeps its fields (name, reason, work_item, work_group, backtrace). The position of the work-item that threw is now recorded at every debug level, not only at -g2:

julia> @oneapi kernel(a); synchronize()
ERROR: KernelException: A BoundsError was thrown by work-item 1×1×1 in work-group 1×1×1 on Intel(R) Iris(R) Xe Graphics: Out-of-bounds array access
For more details, run Julia with `-g2`, or launch the kernel with `@oneapi debug_level=2`.

At -g2 the hint is replaced by the backtrace, which reaches the kernel. Names and backtraces are no longer truncated or read back from device memory: the code that copied strings from the device after a throw, and validated their addresses, is gone.

Implementation notes:

  • The per-kernel table is stored in oneAPIResults, so it is cached with the CodeInstance and in package images. It is also attached to the linked ZeKernel.
  • Exceptions are still reported per stream, when the stream is synchronized. To tell which kernel threw, each launch passes an identifier for its ZeKernel in KernelState. The stream keeps the kernels launched since it last checked its report, and the host only accepts a reported kernel and site that match one of those. A corrupted report therefore yields an anonymous KernelException, never a crash.
  • @gputhrow is now GPUCompiler's.
  • Requires GPUCompiler 2.23.

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.78%. Comparing base (7ed9854) to head (d4ffbf3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #768      +/-   ##
==========================================
- Coverage   87.34%   86.78%   -0.56%     
==========================================
  Files          56       55       -1     
  Lines        5263     5094     -169     
==========================================
- Hits         4597     4421     -176     
- Misses        666      673       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt marked this pull request as ready for review November 18, 2026 06:55
@github-actions

Copy link
Copy Markdown
Contributor

Documentation preview: https://juliagpu.github.io/oneAPI.jl/previews/PR768/

Every bounds check carried its own calls to the reporting functions, which
were kept out of line as inlining them made kernels slower still. Any call
left in the SPIR-V makes IGC compile the kernel at SIMD8 rather than SIMD32,
so a kernel with 256 bounds-checked reads ran 5.6x slower than with
`@inbounds` on an Iris Xe, and one with 64 reads 2.8x.

Use GPUCompiler's reporting by throw site instead: a throw only records the id
of its site, the kernel and the position of the work-item, through a single
inlined copy of the reporting code per kernel, and the host looks the site up
in the table that compilation returned for that kernel, of those launched on
the stream since it was last checked. The SPIR-V of such
kernels has no calls left, so IGC compiles them at SIMD32, and the kernels
with 256 and 64 checked reads now run 3.1x and 1.8x slower than with
`@inbounds`.

The names, reasons and backtraces now live on the host, so they are no longer
read back from the device after a kernel threw. `KernelException` also has the
position of the work-item that threw at every debug level, rather than only
at -g2.
@maleadt
maleadt merged commit 592513a into main Nov 20, 2026
5 checks passed
@maleadt
maleadt deleted the tb/exception-sites branch November 20, 2026 07:28
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.

1 participant