Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CEnum = "0.5, 1"
Crayons = "4"
GPUArrays = "12.1"
GPUCompiler = "2.18"
GPUToolbox = "3.5"
GPUToolbox = "3.6"
IntelITT = "0.2"
KernelAbstractions = "0.10"
KernelInterface = "0.4"
Expand Down
11 changes: 7 additions & 4 deletions src/compiler/compilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ GPUCompiler.runtime_module(::oneAPICompilerJob) = oneAPI

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
# - 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
# - replace Base helpers that format their error message at run time, which can't be
# compiled, with ones that throw 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

Expand Down
11 changes: 11 additions & 0 deletions src/device/quirks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,14 @@ end
return checkindex(Bool, eachindex(IndexLinear(), v), i)
end
end

# GPUToolbox's shared overrides throw through `device_throw`, with a constant exception type
# and reason; report them like `@gputhrow` does
@device_override @noinline function GPUToolbox.Overlays.device_throw(
::Type{E}, ::Val{reason}) where {E<:Exception, reason}
if kernel_debug_level() >= 1
reporting_call(record_exception!, string_pointer(Val(nameof(E))),
string_pointer(Val(reason)))
end
throw(nothing)
end
56 changes: 56 additions & 0 deletions test/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,62 @@ 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]
# 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 on", 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,
Val(Symbol("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 on", 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
Expand Down
Loading