Skip to content

Use GPUToolbox's throw overrides on the PoCL back end - #966

Merged
maleadt merged 1 commit into
mainfrom
tb/device-throw
Nov 10, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/device-throw

Conversation

@maleadt

@maleadt maleadt commented Nov 10, 2026

Copy link
Copy Markdown
Member

Some of Base's Rational helpers format their error message at run time, which can't be compiled for the device. On Julia 1.10, __throw_rational_argerror_typemin is reachable from every signed Rational operation (*, +, -, //), so any signed Rational arithmetic in a kernel on CPU() failed with an InvalidIRError; on Julia 1.11 the same happened for negation, through __throw_rational_numerator_typemin.

GPUToolbox 3.6 provides Overlays.throw_overrides (JuliaGPU/GPUToolbox.jl#43), which throws these errors with a constant message through the Overlays.device_throw hook (JuliaGPU/GPUToolbox.jl#44). This PR stacks that table under the PoCL back end's method tables and implements the hook with @gputhrow, so the exceptions report their type and message like the back end's own quirks:

ERROR: ArgumentError during kernel execution on work-item (1, 1, 1): invalid rational: denominator can't be typemin.

The new "POCL Rational errors" testset checks Rational multiply-add and negation on CPU(), and the reported exception for a typemin denominator, a typemin numerator, and a direct device_throw call.

This supersedes the PoCL-only __throw_rational_argerror_typemin quirk from #962 (fbb0ba7); whichever lands second should drop that quirk.

Requires GPUToolbox 3.6.0 (JuliaRegistries/General#175594).

Some of Base's `Rational` helpers format their error message at run time,
which can't be compiled for the device: on Julia 1.10 this broke all
signed `Rational` arithmetic in kernels on `CPU()`, and on Julia 1.11
negation. GPUToolbox 3.6 provides `throw_overrides`, which throw these
errors with a constant message through `Overlays.device_throw`; stack that
table, and implement the hook with `@gputhrow` so these exceptions report
their type and message like the back end's own quirks.
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with ddab9e372, the merge base.
The environment differs from the baseline's: GPUToolbox 3.5.1 → 3.6.0, SPIRV_LLVM_Backend_jll 23.1.4+3 → 23.1.4+5.

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 +0.9% 0 1 32
Latency −0.2% 0 0 13
Applications −3.4% 0 0 5
Benchmark Baseline This PR Change
Performance
pocl/parallel/util/zeros-large 947 µs 907 µs −4.2% 🟢 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 284 µs +0.1%
julia/serial/narrow/masked-reference 716 µs 720 µs +0.6%
pocl/parallel/atomics/histogram 5.17 ms 5.18 ms +0.2%
pocl/parallel/groupreduce/add-f64 1.09 ms 1.10 ms +0.4%
pocl/parallel/groupreduce/fallback 4.38 ms 4.38 ms −0.0%
pocl/parallel/groupscan/add-i32 392 µs 394 µs +0.5%
pocl/parallel/indexing/cartesian3d 39.8 µs 41.7 µs +4.8%
pocl/parallel/indexing/linear3d 39.2 µs 40.9 µs +4.3%
pocl/parallel/indexing/ntuple3d 39.0 µs 39.9 µs +2.3%
pocl/parallel/indexing/ntuple4d 127 µs 127 µs −0.2%
pocl/parallel/localmem/transpose-naive 430 µs 424 µs −1.4%
pocl/parallel/localmem/transpose-tiled 59.5 µs 66.5 µs +11.9%
pocl/parallel/private/across-barrier 42.3 µs 42.3 µs −0.1%
pocl/parallel/scheduling/default 117 µs 118 µs +0.1%
pocl/parallel/scheduling/explicit 117 µs 117 µs +0.2%
pocl/parallel/stream/copy/cache 642 ns 655 ns +2.0%
pocl/parallel/stream/copy/dram 6.33 ms 6.58 ms +3.9%
pocl/parallel/stream/triad/cache 1.10 µs 1.13 µs +3.1%
pocl/parallel/stream/triad/dram 9.64 ms 9.53 ms −1.2%
pocl/parallel/util/copyto-small 24.0 ns 24.0 ns +0.0%
pocl/parallel/util/zeros-large 947 µs 907 µs −4.2% 🟢 faster
pocl/parallel/util/zeros-small 628 ns 635 ns +1.1%
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 859 µs 859 µs +0.0%
pocl/serial/math/exp-f64 126 µs 127 µs +0.3%
pocl/serial/math/sin-f64 169 µs 169 µs −0.2%
pocl/serial/narrow/masked 632 µs 635 µs +0.5%
pocl/serial/narrow/unmasked 628 µs 628 µs +0.1%
pocl/serial/stream/triad/dram 8.51 ms 8.56 ms +0.5%
Latency
host/import/ka 582 ms 583 ms +0.2%
host/precompile/ka 24.6 s 24.5 s −0.3%
host/startup 132 ms 132 ms +0.1%
pocl/parallel/launch/dynamic-default 165 ns 164 ns −0.6%
pocl/parallel/launch/groupreduce-f64 809 ns 809 ns +0.0%
pocl/parallel/launch/many-args 660 ns 657 ns −0.5%
pocl/parallel/launch/partial-workgroup 216 ns 219 ns +1.4%
pocl/serial/compile/groupreduce 1.49 s 1.49 s +0.1%
pocl/serial/compile/localmem-barrier 728 ms 727 ms −0.0%
pocl/serial/compile/new-kernel 129 ms 129 ms −0.2%
pocl/serial/compile/new-workgroupsize 8.87 ms 8.68 ms −2.1%
pocl/serial/first-kernel/cold-cache 396 ms 393 ms −0.5%
pocl/serial/first-kernel/warm-cache 320 ms 320 ms −0.0%
Applications
pocl/parallel/dgsem/fluxdiff-node 254 µs 254 µs +0.1%
pocl/parallel/dgsem/weak-element 98.7 µs 93.2 µs −5.5%
pocl/parallel/dgsem/weak-node-localmem 83.7 µs 83.5 µs −0.2%
pocl/parallel/stencil/timestep 8.49 ms 7.43 ms −12.5%
pocl/serial/stencil/timestep 9.84 ms 9.99 ms +1.6%

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

@maleadt
maleadt merged commit ad09aed into main Nov 10, 2026
29 of 32 checks passed
@maleadt
maleadt deleted the tb/device-throw branch November 10, 2026 20:50
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