Skip to content

POCL: report exceptions by throw site - #982

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

maleadt merged 1 commit into
mainfrom
tb/pocl-exception-sites

Conversation

@maleadt

@maleadt maleadt commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Follow-up on #974 and #976, from the comment on #976: with a work-group whose outermost dimension is 2 (e.g. 32x32x2, which KA picks for an ndrange of 32x32x10), every bounds check still cost 8 bytes of stack per work-item. PoCL demotes the result of the inlined reporting code to an alloca, its work-item loops make that an array over the work-group, and for a trip count of 2 SROA turns its index into a pointer phi that InstCombine doesn't see through, so the write-only array stays. The underlying problem is that every bounds check carries its own copy of the reporting code, whose values are candidates for such arrays.

This uses GPUCompiler's new reporting by throw site (JuliaGPU/GPUCompiler.jl#1100): a throw records only its site's id and work-item, through one copy of the reporting code per kernel, and the host looks up what was thrown.

With 256 bounds checks:

Work-group Stack frame (before → after) Code (before → after)
64x64x1 200 B → none 82.9 KB → 6.5 KB
64x2x1 265 KB → none 117 KB → 6.6 KB
32x32x2 4.2 MB → none 122 KB → 6.6 KB
64x32x2 stack overflow → none – → 6.6 KB

KernelException now carries the exception's name, reason and the work-item that threw, and at debug level 2 a backtrace. The kernel no longer prints anything:

KernelException: BoundsError during kernel execution on work-item (16, 1, 1): Out-of-bounds array access
Stacktrace:
 [1] throw_boundserror at .../src/pocl/device/quirks.jl:35
 [2] checkbounds at ./abstractarray.jl:702
 [3] arrayset at .../src/pocl/device/array.jl:132
 [4] setindex! at .../src/pocl/device/array.jl:208
 [5] gpu_oob! at oob.jl:4

The backtrace now reaches the kernel, where it used to stop at "multiple call sites". The report only arrives once the launch completes, and names and reasons are no longer printed by the device.

Requires GPUCompiler 2.23, which has that change.

@github-actions

Copy link
Copy Markdown
Contributor

@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 89.26%. Comparing base (20ca9a8) to head (fcc8d15).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #982      +/-   ##
==========================================
- Coverage   89.73%   89.26%   -0.47%     
==========================================
  Files          33       33              
  Lines        3077     3010      -67     
==========================================
- Hits         2761     2687      -74     
- Misses        316      323       +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 force-pushed the tb/pocl-exception-sites branch from 53ce230 to ceae1e5 Compare November 18, 2026 06:34
@maleadt
maleadt marked this pull request as ready for review November 18, 2026 06:34
@maleadt
maleadt force-pushed the tb/pocl-exception-sites branch from ceae1e5 to fb78d15 Compare November 18, 2026 06:51
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with 20ca9a8d0, the merge base.
Times are the minimum time of every benchmark. A change is unusual when it exceeds both three times the benchmark's typical change between consecutive runs on the default branch and a minimum per category (performance 3%, latency 5%, applications 3%, other 3%). A benchmark that starts or stops allocating is listed however few the allocations. A single run can still be a fluke, so rerun before drawing conclusions.

Geometric mean Unusual: slower Unusual: faster Compared
Performance +1.0% 4 0 32
Latency +0.2% 1 0 13
Applications −2.2% 0 1 5
Benchmark Baseline This PR Change
Performance
pocl/parallel/util/copyto-small 23.0 ns 28.0 ns +21.7% 🔴 slower
julia/serial/narrow/masked-reference 679 µs 731 µs +7.6% 🔴 slower
julia/serial/math/exp-f64-reference 284 µs 300 µs +5.6% 🔴 slower
pocl/parallel/util/zeros-large 903 µs 947 µs +4.9% 🔴 slower
Latency
pocl/serial/compile/groupreduce 1.40 s 1.49 s +6.6% 🔴 slower
Applications
pocl/parallel/dgsem/weak-node-localmem 110 µs 92.9 µs −15.1% 🟢 faster
All benchmarks
Benchmark Baseline This PR Change
Performance
julia/serial/arithmetic/muladd-reference 655 µs 655 µs +0.0%
julia/serial/math/exp-f64-reference 284 µs 300 µs +5.6% 🔴 slower
julia/serial/narrow/masked-reference 679 µs 731 µs +7.6% 🔴 slower
pocl/parallel/atomics/histogram 5.21 ms 5.20 ms −0.0%
pocl/parallel/groupreduce/add-f64 1.10 ms 1.09 ms −0.7%
pocl/parallel/groupreduce/fallback 4.38 ms 4.38 ms +0.0%
pocl/parallel/groupscan/add-i32 394 µs 391 µs −0.5%
pocl/parallel/indexing/cartesian3d 46.5 µs 39.5 µs −15.0%
pocl/parallel/indexing/linear3d 41.9 µs 39.3 µs −6.2%
pocl/parallel/indexing/ntuple3d 44.3 µs 40.9 µs −7.8%
pocl/parallel/indexing/ntuple4d 129 µs 126 µs −2.0%
pocl/parallel/localmem/transpose-naive 432 µs 434 µs +0.5%
pocl/parallel/localmem/transpose-tiled 64.5 µs 69.0 µs +6.9%
pocl/parallel/private/across-barrier 42.3 µs 42.2 µs −0.3%
pocl/parallel/scheduling/default 117 µs 117 µs −0.1%
pocl/parallel/scheduling/explicit 117 µs 117 µs −0.1%
pocl/parallel/stream/copy/cache 673 ns 710 ns +5.5%
pocl/parallel/stream/copy/dram 6.38 ms 6.49 ms +1.8%
pocl/parallel/stream/triad/cache 1.07 µs 1.21 µs +13.1%
pocl/parallel/stream/triad/dram 9.50 ms 9.58 ms +0.8%
pocl/parallel/util/copyto-small 23.0 ns 28.0 ns +21.7% 🔴 slower
pocl/parallel/util/zeros-large 903 µs 947 µs +4.9% 🔴 slower
pocl/parallel/util/zeros-small 627 ns 629 ns +0.3%
pocl/serial/arithmetic/contract 1.85 ms 1.85 ms +0.0%
pocl/serial/arithmetic/muladd 705 µs 705 µs −0.0%
pocl/serial/const/marked 668 µs 668 µs −0.0%
pocl/serial/const/unmarked 860 µs 860 µs −0.0%
pocl/serial/math/exp-f64 124 µs 123 µs −1.1%
pocl/serial/math/sin-f64 168 µs 168 µs +0.1%
pocl/serial/narrow/masked 632 µs 634 µs +0.3%
pocl/serial/narrow/unmasked 628 µs 631 µs +0.4%
pocl/serial/stream/triad/dram 8.51 ms 8.63 ms +1.4%
Latency
host/import/ka 596 ms 601 ms +0.9%
host/precompile/ka 25.9 s 27.1 s +4.6%
host/startup 131 ms 131 ms −0.0%
pocl/parallel/launch/dynamic-default 162 ns 166 ns +2.5%
pocl/parallel/launch/groupreduce-f64 807 ns 775 ns −4.0%
pocl/parallel/launch/many-args 678 ns 679 ns +0.1%
pocl/parallel/launch/partial-workgroup 217 ns 214 ns −1.4%
pocl/serial/compile/groupreduce 1.40 s 1.49 s +6.6% 🔴 slower
pocl/serial/compile/localmem-barrier 704 ms 675 ms −4.2%
pocl/serial/compile/new-kernel 129 ms 128 ms −0.8%
pocl/serial/compile/new-workgroupsize 8.69 ms 8.69 ms +0.0%
pocl/serial/first-kernel/cold-cache 412 ms 412 ms +0.1%
pocl/serial/first-kernel/warm-cache 335 ms 331 ms −1.0%
Applications
pocl/parallel/dgsem/fluxdiff-node 252 µs 254 µs +0.5%
pocl/parallel/dgsem/weak-element 90.2 µs 90.5 µs +0.3%
pocl/parallel/dgsem/weak-node-localmem 110 µs 92.9 µs −15.1% 🟢 faster
pocl/parallel/stencil/timestep 7.51 ms 8.10 ms +7.9%
pocl/serial/stencil/timestep 10.8 ms 10.5 ms −2.8%

History: https://juliagpu.org/perf/?pkg=kernelabstractions

Every bounds check in a kernel carried a copy of the exception reporting
code, which PoCL inlines into the work-item loops. Values in that code could
get an array over the work-group, so kernels with many bounds checks needed
megabytes of stack (#974): with a work-group
whose outermost dimension is 2, e.g. 32x32x2, still 8 bytes per bounds check
per work-item after #976.

Use GPUCompiler's reporting by throw site instead: a throw only records its
site's id and work-item, through a single copy of the reporting code per
kernel, and the host looks up what was thrown. A kernel with 256 bounds
checks now has no stack frame at any work-group shape, instead of up to
4.2 MB, and 6.6 KB of code instead of 83-122 KB.

`KernelException` now names the exception, the work-item and the reason, and
at debug level 2 has a backtrace that reaches the kernel, instead of the
kernel printing them. Kernels that launch work-groups of both the full and
the bounds-checked variant look the site up in the table of the variant
that ran the work-item.
@maleadt
maleadt force-pushed the tb/pocl-exception-sites branch from fb78d15 to fcc8d15 Compare November 19, 2026 07:35
@maleadt
maleadt merged commit 301c8f3 into main Nov 19, 2026
19 of 20 checks passed
@maleadt
maleadt deleted the tb/pocl-exception-sites branch November 19, 2026 07:36
@vchuravy

Copy link
Copy Markdown
Member

Broke CI on 1.12?

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.

2 participants