Skip to content
Merged
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 @@ -43,7 +43,7 @@ CEnum = "0.5, 1"
ExprTools = "0.1"
GPUArrays = "12.1"
GPUCompiler = "2.13"
GPUToolbox = "3.3.1"
GPUToolbox = "3.4"
KernelAbstractions = "0.10"
KernelInterface = "0.4"
LLVM = "10"
Expand Down
7 changes: 5 additions & 2 deletions src/compiler/compilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ 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
function GPUCompiler.method_tables(job::oneAPICompilerJob)
if job.config.target.supports_fp64
(method_table, SPIRVIntrinsics.method_table)
(method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.int128_overrides)
else
# keep single-precision math that Base computes in Float64 out of double precision
(method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.float64_overrides)
(method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.float64_overrides,
GPUToolbox.Overlays.int128_overrides)
end
end

Expand Down
23 changes: 23 additions & 0 deletions test/device/intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ end
@test testf(a->exp.(a), Matrix{ComplexF32}([1.0 + 1.0im 1.0 - 1.0im; -1.0 + 1.0im -1.0 - 1.0im]))

end

# Base compares rationals using the 128-bit products of their numerators and
# denominators, which GPUToolbox computes in 64-bit words instead
@testset "rational comparisons" begin
# constructing the rational on the device needs `checked_neg`, which the SPIR-V
# translator can't compile (`llvm.ssub.with.overflow`)
r = 3 // 2
xs = Float32[0, -1, 1.4, 1.5, 1.6, Inf, NaN]
@test Array(map(x -> x < r, oneArray(xs))) == (xs .< r)

qs = [1//3, -5//7, 3//2, typemax(Int)//2, 2^40//3, -typemax(Int)//(2^40 + 1)]
ns = [0, -1, 2, 2^35, typemax(Int), typemin(Int)]
fs = Float32[0.3, -0.7, 1.5, 2f0^62, 3.6f11, -Inf]
for op in (<, <=, cmp)
@test Array(op.(oneArray(qs), oneArray(fs))) == op.(qs, fs)
@test Array(op.(oneArray(fs), oneArray(qs))) == op.(fs, qs)
end
for op in (<, <=)
@test Array(op.(oneArray(qs), oneArray(reverse(qs)))) == op.(qs, reverse(qs))
@test Array(op.(oneArray(qs), oneArray(ns))) == op.(qs, ns)
@test Array(op.(oneArray(ns), oneArray(qs))) == op.(ns, qs)
end
end
end


Expand Down
Loading