Skip to content

Use GPUToolbox's shared throw overrides - #1217

Merged
maleadt merged 2 commits into
mainfrom
tb/gputoolbox-throw
Nov 10, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/gputoolbox-throw

Conversation

@maleadt

@maleadt maleadt commented Nov 10, 2026

Copy link
Copy Markdown
Member

GPUToolbox v3.6.0 (JuliaGPU/GPUToolbox.jl#43, #44) adds Overlays.throw_overrides, a method table that overrides Base's throw helpers that format their message at run time. On Julia 1.10, Rational arithmetic reaches such a helper (Base.__throw_rational_argerror_typemin) whenever a denominator can be negative, so any kernel doing Rational multiplication, addition or negation fails to compile with an InvalidIRError. Julia 1.11 has the same problem with Base.__throw_rational_numerator_typemin, and on 1.12 and later the table is empty.

This PR:

  • stacks throw_overrides under AMDGPU's method table through GPUCompiler.method_tables;
  • implements GPUToolbox.Overlays.device_throw, the hook that the shared overrides throw through, with @gputhrow. Their exceptions are then reported by type (e.g. ArgumentError) like AMDGPU's own quirks, instead of as Unknown exception;
  • bumps the GPUToolbox compat to 3.6;
  • adds tests to test/device/exceptions.jl. They check that Rational arithmetic, negation and construction compile and give correct results, that a typemin denominator or numerator reports the same exception type as on the host, and that device_throw reports its exception type.

Tested on gfx1036 (RDNA2):

  • test/device/exceptions.jl on main: on Julia 1.10.12 the Rational kernel fails with an InvalidIRError, and on 1.13.2 device_throw is reported as Unknown exception. With this PR it passes on both.
  • device, core, kernelabstractions_tests and kernelinterface_tests with --jobs=4: all pass on 1.10.12 (13297 passed, 14 broken) and 1.13.2 (13319 passed, 14 broken).

Requires GPUToolbox v3.6.0 to be registered (JuliaRegistries/General#175594).

Julia 1.10 formats the message of the error that `Rational` throws for a
typemin denominator, which fails to compile for the device, breaking all
`Rational` arithmetic with a negative denominator in kernels. GPUToolbox's
`throw_overrides` throw these errors with a constant message instead.
GPUToolbox's shared overrides throw through `Overlays.device_throw`, with
a constant exception type and message. Implement it with `@gputhrow`, so
that these exceptions report their type like AMDGPU's own quirks, instead
of as an unknown exception.
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with 74cf40077, the merge base.
The environment differs from the baseline's: AMDGPUExt 0.10.5 → 0.5.12, AcceleratedKernels 0.5.11 → 0.5.12, GPUCompiler 2.21.0 → 2.22.0, GPUToolbox 3.5.1 → 3.6.0, Hwloc_jll 2.15.0+0 → 2.15.0+3, KernelAbstractions 0.10.5 → 0.10.7, KernelInterface 0.4.5 → 0.4.6, LinearAlgebraExt 0.10.5 → 0.1.46, SPIRV_LLVM_Backend_jll 23.1.4+2 → 23.1.4+5, SparseArraysExt 0.10.5 → 0.10.7, StaticArraysCore 1.4.4 → 1.4.5, StaticArraysExt 0.10.5 → 0.1.46, pocl_standalone_jll 7.2.3+7 → 7.2.3+8.

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.2% 2 9 69
Latency −2.1% 1 1 3
Applications −2.7% 0 1 14
Benchmark Baseline This PR Change
Performance
array/accumulate/Int64/1d 96.3 µs 67.0 µs −30.4% 🟢 faster
array/permutedims/4d 48.2 µs 35.5 µs −26.5% 🟢 faster
array/reverse/1dL 58.0 µs 46.2 µs −20.3% 🟢 faster
array/reductions/reduce/Int64/dims=2 44.9 µs 53.2 µs +18.5% 🔴 slower
array/reductions/mapreduce/Int64/dims=2 53.2 µs 45.4 µs −14.7% 🟢 faster
array/accumulate/Float32/dims=1L 99.5 µs 85.1 µs −14.5% 🟢 faster
array/reductions/reduce/Int64/dims=1 46.0 µs 40.1 µs −12.8% 🟢 faster
array/reverse/1d 34.0 µs 38.0 µs +11.9% 🔴 slower
array/accumulate/Int64/dims=2L 154 µs 141 µs −8.7% 🟢 faster
array/accumulate/Float32/dims=2 96.9 µs 89.7 µs −7.5% 🟢 faster
array/accumulate/Int64/dims=2 101 µs 96.3 µs −4.8% 🟢 faster
Latency
precompile 29.6 s 24.9 s −15.9% 🟢 faster
import 1.29 s 1.40 s +8.7% 🔴 slower
Applications
gemm/tiled 2.60 ms 1.89 ms −27.4% 🟢 faster
All benchmarks
Benchmark Baseline This PR Change
Performance
amdgpu/synchronization/context/device 1.60 µs 1.58 µs −0.8%
amdgpu/synchronization/stream/blocking 230 ns 225 ns −2.2%
amdgpu/synchronization/stream/nonblocking 343 ns 350 ns +2.1%
array/accumulate/Float32/1d 76.7 µs 76.8 µs +0.1%
array/accumulate/Float32/dims=1 61.2 µs 61.6 µs +0.7%
array/accumulate/Float32/dims=1L 99.5 µs 85.1 µs −14.5% 🟢 faster
array/accumulate/Float32/dims=2 96.9 µs 89.7 µs −7.5% 🟢 faster
array/accumulate/Float32/dims=2L 97.7 µs 101 µs +2.9%
array/accumulate/Int64/1d 96.3 µs 67.0 µs −30.4% 🟢 faster
array/accumulate/Int64/dims=1 71.3 µs 66.8 µs −6.4%
array/accumulate/Int64/dims=1L 90.6 µs 91.3 µs +0.8%
array/accumulate/Int64/dims=2 101 µs 96.3 µs −4.8% 🟢 faster
array/accumulate/Int64/dims=2L 154 µs 141 µs −8.7% 🟢 faster
array/broadcast 21.3 µs 21.8 µs +2.3%
array/construct 1.50 µs 1.52 µs +1.6%
array/copy 36.9 µs 37.8 µs +2.5%
array/copyto!/cpu_to_gpu 84.3 µs 84.1 µs −0.3%
array/copyto!/gpu_to_cpu 83.9 µs 84.1 µs +0.2%
array/copyto!/gpu_to_gpu 23.4 µs 24.9 µs +6.4%
array/iteration/findall/bool 86.9 µs 85.3 µs −1.8%
array/iteration/findall/int 95.5 µs 93.6 µs −2.0%
array/iteration/findfirst/bool 47.1 µs 47.9 µs +1.7%
array/iteration/findfirst/int 46.5 µs 47.2 µs +1.6%
array/iteration/findmin/1d 86.7 µs 85.1 µs −1.8%
array/iteration/findmin/2d 73.4 µs 73.3 µs −0.1%
array/iteration/logical 82.9 µs 80.5 µs −2.9%
array/iteration/scalar 303 µs 310 µs +2.4%
array/permutedims/2d 55.8 µs 56.1 µs +0.7%
array/permutedims/3d 53.2 µs 54.1 µs +1.7%
array/permutedims/4d 48.2 µs 35.5 µs −26.5% 🟢 faster
array/random/rand!/Float32 22.9 µs 23.6 µs +2.9%
array/random/rand!/Int64 23.2 µs 26.9 µs +16.0%
array/random/rand/Float32 38.5 µs 37.8 µs −1.7%
array/random/rand/Int64 41.3 µs 41.9 µs +1.6%
array/random/randn!/Float32 32.1 µs 29.7 µs −7.5%
array/random/randn/Float32 61.6 µs 60.7 µs −1.6%
array/reductions/mapreduce/Float32/1d 65.4 µs 67.0 µs +2.4%
array/reductions/mapreduce/Float32/dims=1 49.8 µs 50.7 µs +1.7%
array/reductions/mapreduce/Float32/dims=1L 54.0 µs 54.7 µs +1.3%
array/reductions/mapreduce/Float32/dims=2 52.8 µs 52.5 µs −0.6%
array/reductions/mapreduce/Float32/dims=2L 65.8 µs 65.9 µs +0.1%
array/reductions/mapreduce/Int64/1d 57.4 µs 64.3 µs +12.0%
array/reductions/mapreduce/Int64/dims=1 46.1 µs 47.2 µs +2.2%
array/reductions/mapreduce/Int64/dims=1L 65.7 µs 66.2 µs +0.8%
array/reductions/mapreduce/Int64/dims=2 53.2 µs 45.4 µs −14.7% 🟢 faster
array/reductions/mapreduce/Int64/dims=2L 68.3 µs 65.8 µs −3.6%
array/reductions/reduce/Float32/1d 67.0 µs 64.6 µs −3.6%
array/reductions/reduce/Float32/dims=1 50.3 µs 49.0 µs −2.4%
array/reductions/reduce/Float32/dims=1L 54.1 µs 54.8 µs +1.2%
array/reductions/reduce/Float32/dims=2 52.4 µs 52.5 µs +0.3%
array/reductions/reduce/Float32/dims=2L 65.3 µs 65.8 µs +0.7%
array/reductions/reduce/Int64/1d 67.2 µs 67.3 µs +0.1%
array/reductions/reduce/Int64/dims=1 46.0 µs 40.1 µs −12.8% 🟢 faster
array/reductions/reduce/Int64/dims=1L 65.1 µs 65.6 µs +0.8%
array/reductions/reduce/Int64/dims=2 44.9 µs 53.2 µs +18.5% 🔴 slower
array/reductions/reduce/Int64/dims=2L 70.3 µs 71.2 µs +1.2%
array/reverse/1d 34.0 µs 38.0 µs +11.9% 🔴 slower
array/reverse/1d_inplace 22.9 µs 23.6 µs +2.9%
array/reverse/1dL 58.0 µs 46.2 µs −20.3% 🟢 faster
array/reverse/1dL_inplace 30.3 µs 32.1 µs +5.9%
array/reverse/2d 40.7 µs 41.1 µs +0.9%
array/reverse/2d_inplace 25.8 µs 26.2 µs +1.7%
array/reverse/2dL 66.7 µs 65.7 µs −1.4%
array/reverse/2dL_inplace 34.5 µs 34.8 µs +1.0%
array/sorting/1d 291 µs 288 µs −1.0%
kernel/indexing 20.1 µs 20.4 µs +1.2%
kernel/indexing_checked 24.1 µs 24.5 µs +1.6%
kernel/launch 750 ns 758 ns +1.0%
kernel/rand 28.0 µs 28.4 µs +1.1%
Latency
import 1.29 s 1.40 s +8.7% 🔴 slower
precompile 29.6 s 24.9 s −15.9% 🟢 faster
ttfp 1.66 s 1.71 s +2.8%
Applications
bitonic_sort 1.07 ms 1.07 ms −0.1%
byval/reference 40.1 µs 40.9 µs +2.0%
byval/slices=1 39.7 µs 41.3 µs +4.2%
byval/slices=2 161 µs 142 µs −11.7%
byval/slices=3 237 µs 233 µs −1.6%
convolution 52.1 µs 52.5 µs +0.8%
floyd_warshall 8.93 ms 8.94 ms +0.0%
gemm/tiled 2.60 ms 1.89 ms −27.4% 🟢 faster
gemm/tiled_unbounded 2.60 ms 2.62 ms +0.8%
histogram 408 µs 407 µs −0.3%
prefix_sum 195 µs 191 µs −2.0%
stencil/diffusion3d 1.55 ms 1.55 ms −0.0%
stencil/diffusion3d_checked 1.59 ms 1.60 ms +0.1%
volumerhs 4.85 ms 4.94 ms +1.9%

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

@maleadt
maleadt merged commit b5c1627 into main Nov 10, 2026
11 checks passed
luraess referenced this pull request Nov 16, 2026
rocSOLVER's gesvdj diagonalizes A'A with a Jacobi eigensolver and takes
U and S from a QR of AV, so singular values below sqrt(eps)*σ₁ are lost
while info = 0 and the residual is below tolerance: a Float64 svd, cond
or rank could silently be accurate to 1e-8 only. gesvd matches LAPACK
down to the eps*σ₁ floor. Make QRAlgorithm() the default of svd, svd!,
svdvals and svdvals! (and the target of DivideAndConquer()), as CUDA.jl
does; JacobiAlgorithm() stays available as the documented fast path
(3-9x faster on MI250X and MI300A) for well-conditioned matrices.

Upstream: ROCm/rocm-libraries#12868 (gesvdj accuracy), #15788 (cgesvd
singular vectors of a rank-deficient ComplexF32 matrix, worked around
in the test).
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