Skip to content

Test checked addition and subtraction - #1139

Merged
maleadt merged 1 commit into
mainfrom
tb/add-sub-overflow
Nov 10, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/add-sub-overflow

Conversation

@maleadt

@maleadt maleadt commented Nov 10, 2026

Copy link
Copy Markdown
Member

Apple's macOS 26 back-end computes the overflow flag of signed 16 to 64-bit additions and subtractions wrongly: 0 + -1 overflows, typemin + -1 doesn't. Checked arithmetic therefore threw spurious OverflowErrors, and so did Rational + and - whenever the result was negative. That is the failure on the GitHub Actions runners of #1138. Buildkite only runs macOS 27, which isn't affected.

GPUCompiler 2.22.1 expands these operations instead (JuliaGPU/GPUCompiler.jl#1086). This bumps the compat bound and adds a runtime test over edge values. On an M3 Pro with macOS 26.7, the test fails for Int16 with GPUCompiler 2.22.0 and passes with 2.22.1.

Apple's macOS 26 back-end computes the overflow flag of signed 16 to 64-bit
additions and subtractions wrongly, so checked arithmetic, and `Rational`
`+` and `-` with a negative result, threw spurious OverflowErrors.
GPUCompiler 2.22.1 expands them instead (JuliaGPU/GPUCompiler.jl#1086).
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with ffa589b10, the merge base.
The environment differs from the baseline's: AcceleratedKernels 0.5.11 → 0.5.12, GPUCompiler 2.22.0 → 2.22.1, GPUToolbox 3.5.1 → 3.6.0, KernelAbstractions 0.10.5 → 0.10.7, KernelInterface 0.4.5 → 0.4.6, LinearAlgebraExt 0.10.5 → 0.1.46, MetalExt 0.10.5 → 0.10.7, SPIRV_LLVM_Backend_jll 23.1.4+2 → 23.1.4+5, SparseArraysExt 0.10.5 → 0.10.7, 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 −0.8% 4 4 74
Latency +7.3% 3 0 4
Applications −0.7% 0 0 5
Benchmark Baseline This PR Change
Performance
array/accumulate/Float32/dims=2L 2.65 ms 2.03 ms −23.5% 🟢 faster
kernel/indexing 194 µs 158 µs −18.7% 🟢 faster
array/private/iteration/findmin/2d 385 µs 464 µs +20.7% 🔴 slower
array/shared/iteration/findmin/2d 394 µs 470 µs +19.4% 🔴 slower
array/shared/iteration/findmin/1d 343 µs 295 µs −14.0% 🟢 faster
array/private/iteration/findmin/1d 347 µs 303 µs −12.5% 🟢 faster
array/shared/iteration/logical 365 µs 389 µs +6.7% 🔴 slower
array/private/iteration/logical 362 µs 380 µs +5.0% 🔴 slower
Latency
launch 1.36 s 1.51 s +10.9% 🔴 slower
compilation 1.59 s 1.73 s +8.9% 🔴 slower
import 1.34 s 1.44 s +7.3% 🔴 slower
All benchmarks
Benchmark Baseline This PR Change
Performance
array/accumulate/Float32/1d 387 µs 402 µs +3.9%
array/accumulate/Float32/dims=1 361 µs 370 µs +2.6%
array/accumulate/Float32/dims=1L 8.87 ms 8.86 ms −0.1%
array/accumulate/Float32/dims=2 429 µs 426 µs −0.8%
array/accumulate/Float32/dims=2L 2.65 ms 2.03 ms −23.5% 🟢 faster
array/accumulate/Int64/1d 520 µs 519 µs −0.2%
array/accumulate/Int64/dims=1 514 µs 513 µs −0.1%
array/accumulate/Int64/dims=1L 1.64 ms 1.63 ms −0.5%
array/accumulate/Int64/dims=2 539 µs 542 µs +0.6%
array/accumulate/Int64/dims=2L 5.45 ms 5.45 ms +0.2%
array/broadcast 229 µs 222 µs −3.2%
array/construct 2.13 µs 2.21 µs +3.9%
array/permutedims/2d 341 µs 340 µs −0.3%
array/permutedims/3d 461 µs 462 µs +0.2%
array/permutedims/4d 418 µs 420 µs +0.5%
array/private/copy 227 µs 222 µs −2.0%
array/private/copyto!/cpu_to_gpu 220 µs 217 µs −1.2%
array/private/copyto!/gpu_to_cpu 214 µs 209 µs −2.6%
array/private/copyto!/gpu_to_gpu 214 µs 215 µs +0.6%
array/private/iteration/findall/bool 353 µs 350 µs −0.6%
array/private/iteration/findall/int 421 µs 422 µs +0.2%
array/private/iteration/findfirst/bool 280 µs 279 µs −0.3%
array/private/iteration/findfirst/int 283 µs 275 µs −3.0%
array/private/iteration/findmin/1d 347 µs 303 µs −12.5% 🟢 faster
array/private/iteration/findmin/2d 385 µs 464 µs +20.7% 🔴 slower
array/private/iteration/logical 362 µs 380 µs +5.0% 🔴 slower
array/private/iteration/scalar 1.34 ms 1.36 ms +1.2%
array/random/rand!/Float32 416 µs 418 µs +0.5%
array/random/rand!/Int64 444 µs 448 µs +0.9%
array/random/rand/Float32 436 µs 440 µs +1.0%
array/random/rand/Int64 517 µs 512 µs −1.0%
array/random/randn!/Float32 348 µs 348 µs −0.1%
array/random/randn/Float32 367 µs 368 µs +0.4%
array/reductions/mapreduce/Float32/1d 217 µs 202 µs −6.6%
array/reductions/mapreduce/Float32/dims=1 208 µs 215 µs +3.4%
array/reductions/mapreduce/Float32/dims=1L 579 µs 578 µs −0.3%
array/reductions/mapreduce/Float32/dims=2 252 µs 250 µs −0.5%
array/reductions/mapreduce/Float32/dims=2L 419 µs 418 µs −0.4%
array/reductions/mapreduce/Int64/1d 237 µs 215 µs −9.2%
array/reductions/mapreduce/Int64/dims=1 218 µs 219 µs +0.8%
array/reductions/mapreduce/Int64/dims=1L 1000 µs 988 µs −1.2%
array/reductions/mapreduce/Int64/dims=2 264 µs 246 µs −6.9%
array/reductions/mapreduce/Int64/dims=2L 601 µs 586 µs −2.5%
array/reductions/reduce/Float32/1d 212 µs 208 µs −1.8%
array/reductions/reduce/Float32/dims=1 209 µs 213 µs +2.0%
array/reductions/reduce/Float32/dims=1L 577 µs 579 µs +0.3%
array/reductions/reduce/Float32/dims=2 254 µs 239 µs −5.9%
array/reductions/reduce/Float32/dims=2L 411 µs 409 µs −0.4%
array/reductions/reduce/Int64/1d 228 µs 218 µs −4.5%
array/reductions/reduce/Int64/dims=1 227 µs 224 µs −1.4%
array/reductions/reduce/Int64/dims=1L 1.00 ms 995 µs −0.6%
array/reductions/reduce/Int64/dims=2 247 µs 253 µs +2.4%
array/reductions/reduce/Int64/dims=2L 604 µs 582 µs −3.7%
array/shared/copy 130 µs 129 µs −0.8%
array/shared/copyto!/cpu_to_gpu 36.5 µs 37.0 µs +1.1%
array/shared/copyto!/gpu_to_cpu 36.1 µs 37.1 µs +2.9%
array/shared/copyto!/gpu_to_gpu 36.3 µs 37.9 µs +4.4%
array/shared/iteration/findall/bool 356 µs 358 µs +0.6%
array/shared/iteration/findall/int 428 µs 426 µs −0.4%
array/shared/iteration/findfirst/bool 276 µs 275 µs −0.2%
array/shared/iteration/findfirst/int 277 µs 274 µs −1.2%
array/shared/iteration/findmin/1d 343 µs 295 µs −14.0% 🟢 faster
array/shared/iteration/findmin/2d 394 µs 470 µs +19.4% 🔴 slower
array/shared/iteration/logical 365 µs 389 µs +6.7% 🔴 slower
array/shared/iteration/scalar 83.4 ns 77.6 ns −7.0%
array/sorting/1d 1.92 ms 1.92 ms +0.1%
array/sorting/2d 8.35 ms 8.35 ms +0.0%
kernel/indexing 194 µs 158 µs −18.7% 🟢 faster
kernel/indexing_checked 389 µs 392 µs +0.8%
kernel/launch 758 ns 775 ns +2.2%
kernel/metalcall 842 ns 838 ns −0.5%
kernel/rand 392 µs 403 µs +2.8%
metal/synchronization/context 552 ns 572 ns +3.5%
metal/synchronization/stream 359 ns 355 ns −1.2%
Latency
compilation 1.59 s 1.73 s +8.9% 🔴 slower
import 1.34 s 1.44 s +7.3% 🔴 slower
launch 1.36 s 1.51 s +10.9% 🔴 slower
precompile 30.4 s 31.1 s +2.2%
Applications
byval/reference 1.13 ms 1.11 ms −1.6%
byval/slices=1 1.12 ms 1.11 ms −0.7%
byval/slices=2 2.02 ms 2.03 ms +0.3%
byval/slices=3 6.84 ms 6.82 ms −0.3%
metaldevrt 394 µs 389 µs −1.1%

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

@maleadt
maleadt merged commit 8699d19 into main Nov 10, 2026
11 of 13 checks passed
@maleadt
maleadt deleted the tb/add-sub-overflow branch November 10, 2026 20:51
@christiangnrd

christiangnrd commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

I don't think this is functional on 1.10/1.11. I'll open an issue or PR depending on how much I understand the robot's solution

@christiangnrd

Copy link
Copy Markdown
Member

Oh this is #1138.

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