From 9c24e7a7c1b5b1db018f9748747c9842ebc01f75 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 25 Nov 2026 14:32:35 +0100 Subject: [PATCH 1/3] Stack GPUToolbox's throw overrides Julia 1.10 formats the message of the error that `Rational` throws for a typemin denominator, and Julia 1.10 and 1.11 that of negating a typemin numerator, which fails to compile for the device. That breaks every kernel that constructs a rational with a negative denominator or negates one. GPUToolbox 3.6's `throw_overrides` throw these errors with a constant message instead. --- Project.toml | 2 +- src/compiler/compilation.jl | 8 +++++--- test/execution.jl | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 5641e891..af156268 100644 --- a/Project.toml +++ b/Project.toml @@ -42,7 +42,7 @@ CEnum = "0.5, 1" Crayons = "4" GPUArrays = "12.1" GPUCompiler = "2.23" -GPUToolbox = "3.5" +GPUToolbox = "3.6" IntelITT = "0.2" KernelAbstractions = "0.10" KernelInterface = "0.4" diff --git a/src/compiler/compilation.jl b/src/compiler/compilation.jl index 49d48bde..4baa093e 100644 --- a/src/compiler/compilation.jl +++ b/src/compiler/compilation.jl @@ -40,14 +40,16 @@ GPUCompiler.uses_exception_sites(::oneAPICompilerJob) = true GPUCompiler.kernel_state_type(::oneAPICompilerJob) = KernelState # SPIR-V doesn't support 128-bit integers, so keep 64-bit integer math (e.g. `Rational` -# comparisons) that Base computes with them out of Int128 +# comparisons) that Base computes with them out of Int128. Some of Base's exceptions format +# their message with `string`, which doesn't compile, so throw those with a constant message. function GPUCompiler.method_tables(job::oneAPICompilerJob) if job.config.target.supports_fp64 - (method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.int128_overrides) + (method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.int128_overrides, + GPUToolbox.Overlays.throw_overrides) else # keep single-precision math that Base computes in Float64 out of double precision (method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.float64_overrides, - GPUToolbox.Overlays.int128_overrides) + GPUToolbox.Overlays.int128_overrides, GPUToolbox.Overlays.throw_overrides) end end diff --git a/test/execution.jl b/test/execution.jl index 76ac0813..f802dfef 100644 --- a/test/execution.jl +++ b/test/execution.jl @@ -1684,6 +1684,28 @@ end @test Array(y)[] == 0 end +@testset "Rational arithmetic" begin + # Julia 1.10 and 1.11 format the messages of `Rational` errors at run time, which + # fails to compile unless GPUToolbox's shared overrides replace them + function rational_kernel(out, a, b, c) + @inbounds out[1] = a * b + c + @inbounds out[2] = -a + return + end + out = oneArray{Rational{Int}}(undef, 2) + @oneapi rational_kernel(out, 2//3, -3//4, 1//5) + @test Array(out) == [2//3 * -3//4 + 1//5, -2//3] + + construct!(a, num, den) = (@inbounds a[1] = Rational(num, den); return) + a = oneArray([0//1]) + @oneapi construct!(a, 1, -2) + @test Array(a) == [-1//2] + @oneapi debug_level=1 construct!(a, 1, typemin(Int)) + err = kernel_exception() + @test err isa KernelException + @test Array(a) == [-1//2] +end + @testset "spills past 128 KB of scratch" begin # Each work-item keeps V vectors of 16 values live until the stores (`out` may alias # `inp`), so at SIMD32 IGC spills them, above a table of P values per work-item that it From e3ac15046e95d1f1f33ac24ddff9d5bf1a462a2d Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 25 Nov 2026 14:32:48 +0100 Subject: [PATCH 2/3] Report exceptions from GPUToolbox's shared overrides like quirks GPUToolbox's shared overrides throw through `Overlays.device_throw`, with a constant exception type and message. Report them with `@gputhrow`, so that these exceptions report their type and message like oneAPI's own quirks, instead of as an exception of unknown type. --- src/device/quirks.jl | 9 +++++++++ test/execution.jl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/device/quirks.jl b/src/device/quirks.jl index 5f701e56..eb2c593a 100644 --- a/src/device/quirks.jl +++ b/src/device/quirks.jl @@ -1,3 +1,12 @@ +# GPUToolbox's shared overrides throw through this function, with constant arguments that +# let them report like `@gputhrow` +@device_override @generated function GPUToolbox.Overlays.device_throw(::Type{E}, ::Val{reason}) where {E<:Exception, reason} + return quote + $(Expr(:meta, :noinline)) + @gputhrow $(String(nameof(E))) $(String(reason)) + end +end + # math.jl @device_override @noinline Base.Math.throw_complex_domainerror(f::Symbol, x) = @gputhrow "DomainError" "This operation requires a complex input to return a complex result" diff --git a/test/execution.jl b/test/execution.jl index f802dfef..c5e2733f 100644 --- a/test/execution.jl +++ b/test/execution.jl @@ -1700,12 +1700,44 @@ end a = oneArray([0//1]) @oneapi construct!(a, 1, -2) @test Array(a) == [-1//2] + # Julia 1.10 throws an ArgumentError, later versions an OverflowError from negating the + # denominator, which is only reported as an exception @oneapi debug_level=1 construct!(a, 1, typemin(Int)) err = kernel_exception() @test err isa KernelException + if isdefined(Base, :__throw_rational_argerror_typemin) + @test err.name == "ArgumentError" + @test err.reason == "invalid rational: denominator can't be typemin" + @test occursin("An ArgumentError was thrown by", sprint(showerror, err)) + end @test Array(a) == [-1//2] end +# GPUToolbox's shared overrides report their exceptions like `@gputhrow` does +@testset "shared override exceptions" begin + throwing() = (oneAPI.GPUToolbox.Overlays.@device_throw ArgumentError("shared reason"); return) + @oneapi debug_level=0 throwing() + err = kernel_exception() + @test err isa KernelException + @test err.name == "" + @oneapi debug_level=1 throwing() + err = kernel_exception() + @test err.name == "ArgumentError" + @test err.reason == "shared reason" + msg = sprint(showerror, err) + @test occursin("An ArgumentError was thrown by", msg) + @test occursin(": shared reason", msg) + + if VERSION < v"1.12-" + negate!(a) = (@inbounds a[1] = -a[1]; return) + a = oneArray([typemin(Int)//1]) + @oneapi debug_level=1 negate!(a) + err = kernel_exception() + @test err.name == "OverflowError" + @test err.reason == "rational numerator is typemin" + end +end + @testset "spills past 128 KB of scratch" begin # Each work-item keeps V vectors of 16 values live until the stores (`out` may alias # `inp`), so at SIMD32 IGC spills them, above a table of P values per work-item that it From 1b7d13dc3182a73861a672bb3fa4eddb18aaf903 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 25 Nov 2026 14:33:00 +0100 Subject: [PATCH 3/3] Use GPUToolbox's override of `throw_domerr_powbysq` oneAPI overlaid `throw_domerr_powbysq` for `::Any`, `::Integer` and `::AbstractMatrix` bases. When Julia 1.12+ loads a package image, it only trusts a kernel's edge to an overlay that no more specific method of the same table intersects, and verifies the others against the global method table, which doesn't have the overlay. The narrower overlays shadowed the `::Any` one, so every kernel computing an integer power was dropped from the image and compiled again in each session (fixed upstream by JuliaLang/julia#64727). GPUToolbox 3.7's `throw_overrides` has a single override, which reports the same exception through `device_throw`, so drop oneAPI's. --- Project.toml | 2 +- src/device/quirks.jl | 8 -------- test/execution.jl | 9 +++++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index af156268..5253d8d6 100644 --- a/Project.toml +++ b/Project.toml @@ -42,7 +42,7 @@ CEnum = "0.5, 1" Crayons = "4" GPUArrays = "12.1" GPUCompiler = "2.23" -GPUToolbox = "3.6" +GPUToolbox = "3.7" IntelITT = "0.2" KernelAbstractions = "0.10" KernelInterface = "0.4" diff --git a/src/device/quirks.jl b/src/device/quirks.jl index eb2c593a..1e1c6b9f 100644 --- a/src/device/quirks.jl +++ b/src/device/quirks.jl @@ -13,14 +13,6 @@ end @device_override @noinline Base.Math.throw_exp_domainerror(x) = @gputhrow "DomainError" "Exponentiation yielding a complex result requires a complex argument" -# intfuncs.jl -@device_override @noinline Base.throw_domerr_powbysq(::Any, p) = - @gputhrow "DomainError" "Cannot raise an integer to a negative power" -@device_override @noinline Base.throw_domerr_powbysq(::Integer, p) = - @gputhrow "DomainError" "Cannot raise an integer to a negative power" -@device_override @noinline Base.throw_domerr_powbysq(::AbstractMatrix, p) = - @gputhrow "DomainError" "Cannot raise an integer to a negative power" - # checked.jl @device_override @noinline Base.Checked.throw_overflowerr_binaryop(op, x, y) = @gputhrow "OverflowError" "Binary operation overflowed" diff --git a/test/execution.jl b/test/execution.jl index c5e2733f..cf829e86 100644 --- a/test/execution.jl +++ b/test/execution.jl @@ -1728,6 +1728,15 @@ end @test occursin("An ArgumentError was thrown by", msg) @test occursin(": shared reason", msg) + # integer exponentiation with a negative power + pow!(a, p) = (@inbounds a[1] = a[1]^p; return) + a = oneArray([2]) + @oneapi debug_level=1 pow!(a, -1) + err = kernel_exception() + @test err.name == "DomainError" + @test err.reason == "Cannot raise an integer to a negative power" + @test Array(a) == [2] + if VERSION < v"1.12-" negate!(a) = (@inbounds a[1] = -a[1]; return) a = oneArray([typemin(Int)//1])