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
11 changes: 6 additions & 5 deletions ext/AtomixCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ end
@inline modify_native!(ptr::LLVMPtr{Float32}, ::typeof(-), x) = CUDA.atomic_sub!(ptr, x)
# Float64 atomic add needs compute capability 6.0; use compare-and-swap below that.
@inline function modify_native!(ptr::LLVMPtr{Float64}, ::typeof(+), x)
if CUDA.compute_capability() >= v"6.0"
if CUDA.compute_capability().major >= 6
CUDA.atomic_add!(ptr, x)
else
modify_cas!(ptr, +, x)
Expand All @@ -59,10 +59,11 @@ end
# swap: exchange floats through their integer representation
@inline modify_native!(ptr::LLVMPtr{<:NativeInt}, ::typeof(right), x) =
CUDA.atomic_xchg!(ptr, x)
@inline function modify_native!(ptr::LLVMPtr{T,A}, ::typeof(right), x) where {T<:NativeFloat,A}
I = CUDA.inttype(T)
old = CUDA.atomic_xchg!(reinterpret(LLVMPtr{I,A}, ptr), reinterpret(I, x))
return reinterpret(T, old)
for (T, I) in [Float32 => UInt32, Float64 => UInt64]
@eval @inline function modify_native!(ptr::LLVMPtr{$T,A}, ::typeof(right), x) where {A}
old = CUDA.atomic_xchg!(reinterpret(LLVMPtr{$I,A}, ptr), reinterpret($I, x))
return reinterpret($T, old)
end
end

# everything else (float min/max, arbitrary functions): compare-and-swap loop
Expand Down
22 changes: 20 additions & 2 deletions test/test_atomix_cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end


@testset "AtomixCUDAExt:test_float" begin
A = CUDA.CuVector(Float32[1, 1, 1, 1, 1, 0])
A = CUDA.CuVector(Float32[1, 1, 1, 1, 1, 0, 0, 1])
cuda() do
GC.@preserve A begin
@atomic A[1] += 1.5f0
Expand All @@ -118,7 +118,25 @@ end
# no native instruction: compare-and-swap loop
pre, post = @atomic A[5] * 4f0
A[6] = pre + post
A[7] = @atomicswap A[8] = 8f0
end
end
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5]
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5, 1, 8]
end


@testset "AtomixCUDAExt:test_float64" begin
A = CUDA.CuVector(Float64[1, 1, 1, 1, 1, 0, 0, 1])
cuda() do
GC.@preserve A begin
@atomic A[1] += 1.5
@atomic A[2] -= 0.5
@atomic max(A[3], 3.0)
@atomic min(A[4], -1.0)
pre, post = @atomic A[5] * 4.0
A[6] = pre + post
A[7] = @atomicswap A[8] = 8.0
end
end
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5, 1, 8]
end
5 changes: 3 additions & 2 deletions test/test_atomix_metal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ end


@testset "AtomixMetalExt:test_float" begin
A = Metal.MtlVector(Float32[1, 1, 1, 1, 1, 0])
A = Metal.MtlVector(Float32[1, 1, 1, 1, 1, 0, 0, 1])
metal() do
GC.@preserve A begin
@atomic A[1] += 1.5f0
Expand All @@ -134,7 +134,8 @@ end
# no native instruction: compare-and-swap loop
pre, post = @atomic A[5] * 4f0
A[6] = pre + post
A[7] = @atomicswap A[8] = 8f0
end
end
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5]
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5, 1, 8]
end
5 changes: 3 additions & 2 deletions test/test_atomix_oneapi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end


@testset "AtomixoneAPIExt:test_float" begin
A = oneAPI.oneVector(Float32[1, 1, 1, 1, 1, 0])
A = oneAPI.oneVector(Float32[1, 1, 1, 1, 1, 0, 0, 1])
oneapi() do
GC.@preserve A begin
@atomic A[1] += 1.5f0
Expand All @@ -118,7 +118,8 @@ end
# no native instruction: compare-and-swap loop
pre, post = @atomic A[5] * 4f0
A[6] = pre + post
A[7] = @atomicswap A[8] = 8f0
end
end
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5]
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5, 1, 8]
end
22 changes: 20 additions & 2 deletions test/test_atomix_opencl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end


@testset "AtomixOpenCLExt:test_float" begin
A = OpenCL.CLArray(Float32[1, 1, 1, 1, 1, 0])
A = OpenCL.CLArray(Float32[1, 1, 1, 1, 1, 0, 0, 1])
opencl() do
GC.@preserve A begin
@atomic A[1] += 1.5f0
Expand All @@ -118,7 +118,25 @@ end
# no native instruction: compare-and-swap loop
pre, post = @atomic A[5] * 4f0
A[6] = pre + post
A[7] = @atomicswap A[8] = 8f0
end
end
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5]
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5, 1, 8]
end


@testset "AtomixOpenCLExt:test_float64" begin
A = OpenCL.CLArray(Float64[1, 1, 1, 1, 1, 0, 0, 1])
opencl() do
GC.@preserve A begin
@atomic A[1] += 1.5
@atomic A[2] -= 0.5
@atomic max(A[3], 3.0)
@atomic min(A[4], -1.0)
pre, post = @atomic A[5] * 4.0
A[6] = pre + post
A[7] = @atomicswap A[8] = 8.0
end
end
@test collect(A) == [2.5, 0.5, 3, -1, 4, 5, 1, 8]
end
Loading