Repository navigation
Report exceptions by throw site - #616
Merged
Merged
Conversation
maleadt
force-pushed
the
tb/exception-sites
branch
from
November 18, 2026 06:39
98a66c7 to
402586d
Compare
maleadt
marked this pull request as ready for review
November 18, 2026 06:39
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #616 +/- ##
==========================================
+ Coverage 89.09% 90.04% +0.95%
==========================================
Files 18 18
Lines 1751 1688 -63
==========================================
- Hits 1560 1520 -40
+ Misses 191 168 -23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
maleadt
force-pushed
the
tb/exception-sites
branch
from
November 18, 2026 14:00
402586d to
5c352e0
Compare
Every throw site stored the exception's name and reason into the mailbox, and at debug level 2 copied each backtrace frame's strings with a byte loop, so kernels grew with their number of bounds checks: with 256 of them, 15 KB of code at -g1 and 530 KB at -g2, which took 13 s instead of 3 s to compile on PoCL. Use GPUCompiler's reporting by throw site instead. The first work-item that throws records its site's id, its position and the id of its kernel's table of sites, through a single copy of the reporting code per kernel, and the host looks up the name, reason and backtrace in that table. As the mailbox is shared by the queues of a device and only checked once they have completed, it numbers the tables of the kernels launched since its last check. `KernelException` now has the faulting work-item and work-group at every debug level, and names, reasons and backtraces are no longer truncated. The kernel with 256 bounds checks now has 4 KB of code at both levels; its run time on PoCL is unchanged at -g1 (7.9 ms vs 8.5 ms, 0.65 ms with `@inbounds`) and drops from 11.5 ms to 7.3 ms at -g2.
maleadt
force-pushed
the
tb/exception-sites
branch
from
November 19, 2026 06:01
5c352e0 to
39f82c6
Compare
This was referenced Nov 19, 2026
maleadt
added a commit
that referenced
this pull request
Nov 19, 2026
Upstream PoCL miscompiles kernels whose throw sites are reached from different barrier-separated regions, and declined the fix (pocl/pocl#2281), which the JLLs carry as a patch. Since #616 every kernel with bounds checks on both sides of a barrier has that shape: `any`, `all` and `count` give wrong results on a distribution's PoCL 7.2 under `--check-bounds=yes`, and the `pocl_local` job, which builds upstream PoCL HEAD, aborts in `ParallelRegion::chainAfter`. Stop testing upstream PoCL, drop the test skip for it, and document that PoCL should be used through pocl_jll.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kernels now report device-side exceptions through GPUCompiler's throw sites (JuliaGPU/GPUCompiler.jl#1100): a throwing work-item only records the id of its throw site and its position in the mailbox, and the host looks up the exception's name, reason and backtrace in the table of sites that compilation returns with the kernel. Until now, every throw site stored the exception's name and reason into the mailbox itself, and at debug level 2 copied each backtrace frame's strings with a byte loop, so the reporting code was repeated at each of them.
For users
KernelExceptionkeeps its fields, but has more in them:-g2;-g1, exceptions that aren't thrown by one of the quirks now have the name GPUCompiler derives for them (often the genericexception) rather than none;and at
-g2:Nothing is lost compared to before.
Implementation
exception_site(id)claims the mailbox with the existing atomic max and has the winner store the site id, the position and the id of the kernel's table of sites. The tables are carried byOpenCLResults(so they're cached with the compiled code) and by theHostKernel. Because the mailbox is shared by all queues on a device and only checked once they have completed, a site id alone doesn't identify the kernel that threw: the mailbox numbers the tables of the kernels launched since its last check (anIdDictlookup per launch, under the lock the launch already takes), passes that number throughKernelState(replacing the launch id that level 2's re-entrant reporting needed), and resets the numbering when it is checked.@gputhrowis now GPUCompiler's, and GPUToolbox'sdevice_throwoverride expands to it.Numbers
PoCL 7.2.2 (pocl_jll) on a Ryzen 9 9950X, Julia 1.13, a 1-D kernel summing 64 or 256 bounds-checked reads per work-item over 2^20 work-items in work-groups of 256, compared to the same kernel with
@inbounds:@inbounds-g1: run time-g1: code size-g2: run time-g2: code size-g2: compile + first launch-g1: run time-g2: run timeAt
-g1the run time of bounds-checked kernels doesn't change on PoCL: what remains is the cost of the checks themselves. At-g2the code no longer grows with the number of throw sites. The stack frames that PoCL's work-item loops gave level 2's reporting code (56 to 112 bytes for a KernelAbstractions kernel with 64 or 256 bounds checks, after #609) are gone.Depends on
GPUCompiler 2.23, which has JuliaGPU/GPUCompiler.jl#1100.