Skip to content

Use GPUToolbox's shared throw overrides - #1138

Merged
christiangnrd merged 2 commits into
mainfrom
tb/gputoolbox-throw
Nov 13, 2026
Merged

christiangnrd merged 2 commits into
mainfrom
tb/gputoolbox-throw

Conversation

@maleadt

@maleadt maleadt commented Nov 10, 2026

Copy link
Copy Markdown
Member

Adopts two additions from GPUToolbox v3.6.0:

  • Overlays.throw_overrides is now stacked under Metal's own method table. On Julia 1.10 and 1.11, some of the exceptions that Rational arithmetic throws build their message at run time, and that code doesn't compile for Metal. On 1.10, Rational negation or muladd in a kernel crashed Julia inside LLVM. This is the crash seen on the Metal CI for Test multiplication with overflow KernelAbstractions.jl#962.
  • Overlays.device_throw is the hook that those shared overrides throw through. Metal overrides it the same way @gputhrow reports exceptions, so at debug level 1 or higher an exception from a shared override reports its type and message (for example ArgumentError: invalid rational: denominator can't be typemin). Without the override it would only report that an exception occurred.

New tests cover Rational arithmetic in kernels and the messages these exceptions report. Without this change they crash Julia 1.10.

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

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with f4de21a70, 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.5% 2 5 74
Latency +0.5% 0 0 4
Applications −0.0% 0 0 5
Benchmark Baseline This PR Change
Performance
array/reductions/mapreduce/Float32/1d 215 µs 167 µs −22.5% 🟢 faster
array/reductions/mapreduce/Float32/dims=1 214 µs 183 µs −14.6% 🟢 faster
array/construct 2.29 µs 2.08 µs −9.1% 🟢 faster
array/private/iteration/scalar 1.37 ms 1.27 ms −7.1% 🟢 faster
array/shared/iteration/logical 364 µs 387 µs +6.3% 🔴 slower
kernel/launch 767 ns 804 ns +4.9% 🔴 slower
array/reductions/mapreduce/Int64/dims=2L 603 µs 579 µs −4.0% 🟢 faster
All benchmarks
Benchmark Baseline This PR Change
Performance
array/accumulate/Float32/1d 382 µs 396 µs +3.7%
array/accumulate/Float32/dims=1 366 µs 367 µs +0.4%
array/accumulate/Float32/dims=1L 8.89 ms 8.87 ms −0.2%
array/accumulate/Float32/dims=2 438 µs 435 µs −0.6%
array/accumulate/Float32/dims=2L 2.54 ms 2.53 ms −0.4%
array/accumulate/Int64/1d 520 µs 519 µs −0.3%
array/accumulate/Int64/dims=1 516 µs 509 µs −1.4%
array/accumulate/Int64/dims=1L 1.64 ms 1.63 ms −0.9%
array/accumulate/Int64/dims=2 542 µs 543 µs +0.2%
array/accumulate/Int64/dims=2L 5.44 ms 5.44 ms +0.1%
array/broadcast 238 µs 228 µs −4.1%
array/construct 2.29 µs 2.08 µs −9.1% 🟢 faster
array/permutedims/2d 340 µs 337 µs −0.8%
array/permutedims/3d 462 µs 458 µs −0.8%
array/permutedims/4d 419 µs 422 µs +0.6%
array/private/copy 227 µs 216 µs −4.9%
array/private/copyto!/cpu_to_gpu 220 µs 218 µs −0.7%
array/private/copyto!/gpu_to_cpu 221 µs 216 µs −2.6%
array/private/copyto!/gpu_to_gpu 215 µs 212 µs −1.2%
array/private/iteration/findall/bool 351 µs 348 µs −0.8%
array/private/iteration/findall/int 417 µs 420 µs +0.7%
array/private/iteration/findfirst/bool 280 µs 277 µs −1.1%
array/private/iteration/findfirst/int 271 µs 278 µs +2.3%
array/private/iteration/findmin/1d 305 µs 299 µs −1.9%
array/private/iteration/findmin/2d 472 µs 471 µs −0.2%
array/private/iteration/logical 360 µs 367 µs +2.0%
array/private/iteration/scalar 1.37 ms 1.27 ms −7.1% 🟢 faster
array/random/rand!/Float32 421 µs 425 µs +0.8%
array/random/rand!/Int64 442 µs 443 µs +0.2%
array/random/rand/Float32 440 µs 440 µs −0.1%
array/random/rand/Int64 512 µs 514 µs +0.2%
array/random/randn!/Float32 350 µs 341 µs −2.8%
array/random/randn/Float32 370 µs 366 µs −1.0%
array/reductions/mapreduce/Float32/1d 215 µs 167 µs −22.5% 🟢 faster
array/reductions/mapreduce/Float32/dims=1 214 µs 183 µs −14.6% 🟢 faster
array/reductions/mapreduce/Float32/dims=1L 577 µs 578 µs +0.2%
array/reductions/mapreduce/Float32/dims=2 247 µs 243 µs −1.6%
array/reductions/mapreduce/Float32/dims=2L 411 µs 406 µs −1.1%
array/reductions/mapreduce/Int64/1d 226 µs 215 µs −5.0%
array/reductions/mapreduce/Int64/dims=1 226 µs 224 µs −0.7%
array/reductions/mapreduce/Int64/dims=1L 995 µs 995 µs +0.1%
array/reductions/mapreduce/Int64/dims=2 263 µs 252 µs −4.1%
array/reductions/mapreduce/Int64/dims=2L 603 µs 579 µs −4.0% 🟢 faster
array/reductions/reduce/Float32/1d 214 µs 209 µs −2.5%
array/reductions/reduce/Float32/dims=1 213 µs 214 µs +0.3%
array/reductions/reduce/Float32/dims=1L 578 µs 580 µs +0.3%
array/reductions/reduce/Float32/dims=2 249 µs 230 µs −7.6%
array/reductions/reduce/Float32/dims=2L 407 µs 409 µs +0.5%
array/reductions/reduce/Int64/1d 231 µs 223 µs −3.3%
array/reductions/reduce/Int64/dims=1 229 µs 222 µs −3.3%
array/reductions/reduce/Int64/dims=1L 1.00 ms 988 µs −1.4%
array/reductions/reduce/Int64/dims=2 259 µs 254 µs −1.8%
array/reductions/reduce/Int64/dims=2L 601 µs 590 µs −1.8%
array/shared/copy 129 µs 130 µs +0.8%
array/shared/copyto!/cpu_to_gpu 37.6 µs 36.1 µs −4.0%
array/shared/copyto!/gpu_to_cpu 36.3 µs 37.2 µs +2.4%
array/shared/copyto!/gpu_to_gpu 36.4 µs 37.6 µs +3.3%
array/shared/iteration/findall/bool 357 µs 354 µs −1.0%
array/shared/iteration/findall/int 421 µs 418 µs −0.7%
array/shared/iteration/findfirst/bool 271 µs 277 µs +2.1%
array/shared/iteration/findfirst/int 281 µs 277 µs −1.6%
array/shared/iteration/findmin/1d 302 µs 301 µs −0.2%
array/shared/iteration/findmin/2d 473 µs 467 µs −1.2%
array/shared/iteration/logical 364 µs 387 µs +6.3% 🔴 slower
array/shared/iteration/scalar 78.5 ns 76.7 ns −2.2%
array/sorting/1d 1.92 ms 1.95 ms +1.7%
array/sorting/2d 8.38 ms 8.32 ms −0.7%
kernel/indexing 211 µs 198 µs −6.5%
kernel/indexing_checked 392 µs 390 µs −0.4%
kernel/launch 767 ns 804 ns +4.9% 🔴 slower
kernel/metalcall 842 ns 842 ns −0.0%
kernel/rand 405 µs 397 µs −2.0%
metal/synchronization/context 556 ns 552 ns −0.7%
metal/synchronization/stream 360 ns 352 ns −2.1%
Latency
compilation 1.74 s 1.74 s −0.1%
import 1.44 s 1.44 s −0.2%
launch 1.49 s 1.52 s +2.1%
precompile 31.2 s 31.3 s +0.3%
Applications
byval/reference 1.12 ms 1.11 ms −0.6%
byval/slices=1 1.12 ms 1.11 ms −1.1%
byval/slices=2 2.02 ms 2.04 ms +0.5%
byval/slices=3 6.79 ms 6.82 ms +0.4%
metaldevrt 389 µs 392 µs +0.7%

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

@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.94%. Comparing base (f4de21a) to head (2edaa37).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1138      +/-   ##
==========================================
+ Coverage   84.60%   88.94%   +4.33%     
==========================================
  Files         105      105              
  Lines        9426     9297     -129     
==========================================
+ Hits         7975     8269     +294     
+ Misses       1451     1028     -423     

☔ 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.

Julia 1.10 and 1.11 format the messages of the errors that `Rational`
throws for a typemin numerator or denominator at run time. That code
doesn't compile for Metal: on 1.10, `Rational` negation, or arithmetic
that normalizes the sign of a denominator (e.g. `muladd`), crashed LLVM.
GPUToolbox 3.6'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 like `@gputhrow`, so
that these exceptions report their type and message at debug level 1 and
above, instead of only that an exception occurred.
@christiangnrd

Copy link
Copy Markdown
Member

Merging to get CI green.

@christiangnrd
christiangnrd merged commit fe07490 into main Nov 13, 2026
17 checks passed
@christiangnrd
christiangnrd deleted the tb/gputoolbox-throw branch November 13, 2026 11:41
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