Skip to content

Commit 3fe3fe4

Browse files
committed
adding working atomic addition test
1 parent f9fbe63 commit 3fe3fe4

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

test/atomic_test.jl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
using KernelAbstractions, Test
22

3-
@kernel function kernel_atomics(input)
4-
I = @index(Global)
5-
KernelAbstractions.@atomic input[1] += 1
3+
# Note: kernels affect second element because some CPU defaults will affect the
4+
# first element of a pointer if not specified, so I am covering the bases
5+
@kernel function atomic_add_kernel(input, b)
6+
atomic_add!(pointer(input,2),b)
67
end
78

89
function atomics_testsuite(backend)
910

10-
@testset "atomic test" begin
11-
A = ArrayT{Int}(zeros(64))
11+
@testset "atomic addition tests" begin
12+
types = [Int32, Int64, UInt32, UInt64, Float32]
13+
if ArrayT == CuArray
14+
CUDA.capability(CUDA.device()) >= v"6.0" && push!(types, Float64)
15+
CUDA.capability(CUDA.device()) >= v"7.0" && push!(types, Float16)
16+
else
17+
push!(types, Float64)
18+
push!(types, Float16)
19+
end
1220

13-
kernel = kernel_atomic(backend(), 4)
14-
wait(kernel(ndrange=(length(A),)))
21+
for T in types
22+
A = ArrayT{T}([0,0])
1523

16-
@test A[1] == length(A)
24+
kernel = atomic_add_kernel(backend(), 4)
25+
wait(kernel(A, one(T), ndrange=(1024)))
26+
27+
@test Array(A)[2] == 1024
28+
end
1729
end
1830
end

0 commit comments

Comments
 (0)