1
- using KernelAbstractions, Test
1
+ using KernelAbstractions, CUDA, Test
2
2
3
3
# Note: kernels affect second element because some CPU defaults will affect the
4
4
# first element of a pointer if not specified, so I am covering the bases
5
5
@kernel function atomic_add_kernel (input, b)
6
6
atomic_add! (pointer (input,2 ),b)
7
7
end
8
8
9
+ @kernel function atomic_sub_kernel (input, b)
10
+ atomic_sub! (pointer (input,2 ),b)
11
+ end
12
+
13
+ @kernel function atomic_inc_kernel (input, b)
14
+ atomic_inc! (pointer (input,2 ),b)
15
+ end
16
+
17
+ @kernel function atomic_dec_kernel (input, b)
18
+ atomic_dec! (pointer (input,2 ),b)
19
+ end
20
+
9
21
function atomics_testsuite (backend)
10
22
11
23
@testset " atomic addition tests" begin
12
24
types = [Int32, Int64, UInt32, UInt64, Float32]
13
- if ArrayT = = CuArray
25
+ if ArrayT ! = CuArray
14
26
CUDA. capability (CUDA. device ()) >= v " 6.0" && push! (types, Float64)
15
27
CUDA. capability (CUDA. device ()) >= v " 7.0" && push! (types, Float16)
16
28
else
@@ -27,4 +39,52 @@ function atomics_testsuite(backend)
27
39
@test Array (A)[2 ] == 1024
28
40
end
29
41
end
42
+
43
+ @testset " atomic subtraction tests" begin
44
+ types = [Int32, Int64, UInt32, UInt64, Float32]
45
+ if ArrayT == CuArray
46
+ CUDA. capability (CUDA. device ()) >= v " 6.0" && push! (types, Float64)
47
+ CUDA. capability (CUDA. device ()) >= v " 7.0" && push! (types, Float16)
48
+ else
49
+ push! (types, Float64)
50
+ push! (types, Float16)
51
+ end
52
+
53
+ for T in types
54
+ A = ArrayT {T} ([2048 ,2048 ])
55
+
56
+ kernel = atomic_sub_kernel (backend (), 4 )
57
+ wait (kernel (A, one (T), ndrange= (1024 )))
58
+
59
+ @test Array (A)[2 ] == 1024
60
+ end
61
+ end
62
+
63
+ @testset " atomic inc tests" begin
64
+ types = [Int32]
65
+
66
+ for T in types
67
+ A = ArrayT {T} ([0 ,0 ])
68
+
69
+ kernel = atomic_inc_kernel (backend (), 4 )
70
+ wait (kernel (A, T (512 ), ndrange= (768 )))
71
+
72
+ @test Array (A)[2 ] == 255
73
+ end
74
+ end
75
+
76
+ @testset " atomic dec tests" begin
77
+ types = [Int32]
78
+
79
+ for T in types
80
+ A = ArrayT {T} ([1024 ,1024 ])
81
+
82
+ kernel = atomic_inc_kernel (backend (), 4 )
83
+ wait (kernel (A, T (512 ), ndrange= (256 )))
84
+
85
+ @test Array (A)[2 ] == 257
86
+ end
87
+ end
88
+
89
+
30
90
end
0 commit comments