Skip to content

Test multiplication with overflow - #962

Merged
maleadt merged 1 commit into
tb/device-throwfrom
tb/checked-mul
Nov 10, 2026
Merged

maleadt merged 1 commit into
tb/device-throwfrom
tb/checked-mul

Conversation

@maleadt

@maleadt maleadt commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #916.

Base.checked_mul, and with it Rational arithmetic, failed to build on the PoCL back end, and the LLVM SPIR-V back end computed the overflow flag of signed products wrongly (-1 * 1 overflowed, 2^62 * 2 didn't), which also affects oneAPI and OpenCL.jl. Both are fixed in the JLLs:

These are new builds of versions KA already allows, so [compat] can't require them; a fresh resolve picks them up. This adds a test comparing products and overflow flags against the host.

On Julia 1.10, Rational arithmetic also needs the back end to override Base.__throw_rational_argerror_typemin, which builds its error message with string. The CPU back end gets that override from GPUToolbox's throw_overrides (#966). Other back ends skip the Rational check on 1.10 until they adopt those overrides too (JuliaGPU/CUDA.jl#3568, JuliaGPU/AMDGPU.jl#1217, JuliaGPU/OpenCL.jl#604, JuliaGPU/oneAPI.jl#764, JuliaGPU/Metal.jl#1138); without them, Metal crashes in LLVM rather than reporting an error.

OpenCL.jl's targets that go through OpenCL C (poclc, nvidia) also need spirv2clc to translate OpSMulExtended and OpUMulExtended (JuliaGPU/spirv2clc#29), so the OpenCL CI job will fail until the new spirv2clc_jll is registered.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark results

Compared with ddab9e372, the latest measured ancestor of the merge base (1 commit before it).
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 +1.4% 1 1 32
Latency −0.6% 0 0 13
Applications −2.9% 0 0 5
Benchmark Baseline This PR Change
Performance
pocl/serial/const/unmarked 859 µs 998 µs +16.2% 🔴 slower
pocl/parallel/util/zeros-large 947 µs 917 µs −3.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 284 µs +0.0%
julia/serial/narrow/masked-reference 716 µs 702 µs −1.9%
pocl/parallel/atomics/histogram 5.17 ms 5.21 ms +0.7%
pocl/parallel/groupreduce/add-f64 1.09 ms 1.09 ms −0.2%
pocl/parallel/groupreduce/fallback 4.38 ms 4.38 ms −0.0%
pocl/parallel/groupscan/add-i32 392 µs 395 µs +0.8%
pocl/parallel/indexing/cartesian3d 39.8 µs 40.6 µs +2.2%
pocl/parallel/indexing/linear3d 39.2 µs 39.9 µs +1.7%
pocl/parallel/indexing/ntuple3d 39.0 µs 39.3 µs +0.9%
pocl/parallel/indexing/ntuple4d 127 µs 128 µs +0.2%
pocl/parallel/localmem/transpose-naive 430 µs 433 µs +0.7%
pocl/parallel/localmem/transpose-tiled 59.5 µs 63.5 µs +6.8%
pocl/parallel/private/across-barrier 42.3 µs 42.2 µs −0.3%
pocl/parallel/scheduling/default 117 µs 117 µs −0.0%
pocl/parallel/scheduling/explicit 117 µs 117 µs +0.1%
pocl/parallel/stream/copy/cache 642 ns 684 ns +6.5%
pocl/parallel/stream/copy/dram 6.33 ms 6.49 ms +2.6%
pocl/parallel/stream/triad/cache 1.10 µs 1.15 µs +5.2%
pocl/parallel/stream/triad/dram 9.64 ms 9.46 ms −1.8%
pocl/parallel/util/copyto-small 24.0 ns 25.0 ns +4.2%
pocl/parallel/util/zeros-large 947 µs 917 µs −3.1% 🟢 faster
pocl/parallel/util/zeros-small 628 ns 654 ns +4.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 998 µs +16.2% 🔴 slower
pocl/serial/math/exp-f64 126 µs 126 µs +0.2%
pocl/serial/math/sin-f64 169 µs 169 µs +0.0%
pocl/serial/narrow/masked 632 µs 632 µs −0.1%
pocl/serial/narrow/unmasked 628 µs 635 µs +1.2%
pocl/serial/stream/triad/dram 8.51 ms 8.52 ms +0.1%
Latency
host/import/ka 582 ms 580 ms −0.2%
host/precompile/ka 24.6 s 24.5 s −0.4%
host/startup 132 ms 130 ms −1.5%
pocl/parallel/launch/dynamic-default 165 ns 166 ns +0.6%
pocl/parallel/launch/groupreduce-f64 809 ns 808 ns −0.1%
pocl/parallel/launch/many-args 660 ns 657 ns −0.5%
pocl/parallel/launch/partial-workgroup 216 ns 215 ns −0.5%
pocl/serial/compile/groupreduce 1.49 s 1.48 s −0.3%
pocl/serial/compile/localmem-barrier 728 ms 725 ms −0.4%
pocl/serial/compile/new-kernel 129 ms 128 ms −0.5%
pocl/serial/compile/new-workgroupsize 8.87 ms 8.56 ms −3.5%
pocl/serial/first-kernel/cold-cache 396 ms 394 ms −0.4%
pocl/serial/first-kernel/warm-cache 320 ms 320 ms −0.1%
Applications
pocl/parallel/dgsem/fluxdiff-node 254 µs 254 µs −0.1%
pocl/parallel/dgsem/weak-element 98.7 µs 93.1 µs −5.6%
pocl/parallel/dgsem/weak-node-localmem 83.7 µs 83.5 µs −0.3%
pocl/parallel/stencil/timestep 8.49 ms 7.54 ms −11.2%
pocl/serial/stencil/timestep 9.84 ms 10.1 ms +3.1%

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

`Base.checked_mul`, and with it `Rational` arithmetic, failed to build on
the PoCL back end, and SPIR-V back ends computed the overflow flag of
signed products wrongly (#916). Compare products and overflow flags
against the host for signed and unsigned 32 and 64-bit integers.
@maleadt
maleadt changed the base branch from main to tb/device-throw November 10, 2026 11:17
@maleadt
maleadt added this pull request to stack #967 November 10, 2026 11:18
@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 84.82%. Comparing base (01aa26c) to head (8566dd7).

Additional details and impacted files
@@                 Coverage Diff                 @@
##           tb/device-throw     #962      +/-   ##
===================================================
+ Coverage            84.79%   84.82%   +0.03%     
===================================================
  Files                   31       31              
  Lines                 2926     2926              
===================================================
+ Hits                  2481     2482       +1     
+ Misses                 445      444       -1     

☔ 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 merged commit 357e487 into main Nov 10, 2026
33 of 52 checks passed
@maleadt
maleadt deleted the tb/checked-mul 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.

CPU backend: Base.checked_mul in a kernel fails to build (__spirv_SMulExtended missing in PoCL)

1 participant