Skip to content

Commit 3035067

Browse files
committed
removing atomics for CPUs under version 1.7
1 parent b15c93e commit 3035067

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

src/atomics.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ These operations are performed in one atomic transaction.
4747
The function returns `old`.
4848
4949
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
50-
Additionally, on GPU hardware with compute capability 7.0+, values of type UInt1
51-
6 are supported.
50+
Additionally, on GPU hardware with compute capability 7.0+, values of type UInt16 are supported.
51+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
5252
"""
5353
function atomic_cas!(ptr::Ptr{T}, old::T, new::T) where T
5454
Core.Intrinsics.atomic_pointerreplace(ptr, old, new, :acquire_release, :monotonic)
@@ -62,6 +62,7 @@ It reads the value `old` located at address `ptr` and stores `val` at the same a
6262
These operations are performed in one atomic transaction. The function returns `old`.
6363
6464
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
65+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
6566
"""
6667
function atomic_xchg!(ptr::Ptr{T}, b::T) where T
6768
Core.Intrinsics.atomic_pointerswap(ptr::Ptr{T}, b::T, :monotonic)
@@ -75,6 +76,7 @@ It reads the value `old` located at address `ptr` and uses `val` in the operatio
7576
These operations are performed in one atomic transaction. The function returns `old`.
7677
7778
This function is somewhat experimental.
79+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
7880
"""
7981
function atomic_op!(ptr::Ptr{T}, op, b::T) where T
8082
Core.Intrinsics.atomic_pointermodify(ptr::Ptr{T}, op, b::T, :monotonic)
@@ -92,6 +94,7 @@ The function returns `old`.
9294
9395
This operation is supported for values of type Int32, Int64, UInt32, UInt64, and Float32.
9496
Additionally, on GPU hardware with compute capability 6.0+, values of type Float64 are supported.
97+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
9598
"""
9699
atomic_add!
97100

@@ -104,6 +107,7 @@ These operations are performed in one atomic transaction.
104107
The function returns `old`.
105108
106109
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
110+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
107111
"""
108112
atomic_sub!
109113

@@ -116,6 +120,7 @@ These operations are performed in one atomic transaction.
116120
The function returns `old`.
117121
118122
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
123+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
119124
"""
120125
atomic_and!
121126

@@ -128,6 +133,7 @@ These operations are performed in one atomic transaction.
128133
The function returns `old`.
129134
130135
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
136+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
131137
"""
132138
atomic_or!
133139

@@ -140,6 +146,7 @@ These operations are performed in one atomic transaction.
140146
The function returns `old`.
141147
142148
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
149+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
143150
"""
144151
atomic_xor!
145152

@@ -152,6 +159,7 @@ These operations are performed in one atomic transaction.
152159
The function returns `old`.
153160
154161
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
162+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
155163
"""
156164
atomic_min!
157165

@@ -164,6 +172,7 @@ These operations are performed in one atomic transaction.
164172
The function returns `old`.
165173
166174
This operation is supported for values of type Int32, Int64, UInt32 and UInt64.
175+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
167176
"""
168177
atomic_max!
169178

@@ -176,6 +185,7 @@ These three operations are performed in one atomic transaction.
176185
The function returns `old`.
177186
178187
This operation is only supported for values of type Int32.
188+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
179189
"""
180190
atomic_inc!
181191

@@ -188,5 +198,6 @@ These three operations are performed in one atomic transaction.
188198
The function returns `old`.
189199
190200
This operation is only supported for values of type Int32.
201+
Also: atomic operations for the CPU requires a Julia version of 1.7.0 or above.
191202
"""
192203
atomic_dec!

src/cpu.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,29 @@ end
269269

270270
# Argument conversion
271271
KernelAbstractions.argconvert(k::Kernel{CPU}, arg) = arg
272+
273+
###
274+
# CPU error handling if under 1.7
275+
###
276+
277+
if Base.VERSION < v"1.7.0"
278+
import KernelAbstractions: atomic_add!, atomic_and!, atomic_cas!,
279+
atomic_dec!, atomic_inc!, atomic_max!,
280+
atomic_min!, atomic_op!, atomic_or!,
281+
atomic_sub!, atomic_xchg!, atomic_xor!
282+
function atomic_error(args...)
283+
error("CPU Atomics are not allowed for julia version under 1.7!"
284+
end
285+
286+
afxs = [atomic_add!, atomic_and!, atomic_cas!, atomic_dec!,
287+
atomic_inc!, atomic_max!, atomic_min!, atomic_op!,
288+
atomic_or!, atomic_sub!, atomic_xchg!, atomic_xor! ]
289+
for afx in afxs
290+
@inline function Cassette.overdub(::CPUCtx, ::typeof(afx), args...)
291+
atomic_error(args...)
292+
end
293+
end
294+
end
295+
296+
end
297+

test/testsuite.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ function testsuite(backend, backend_str, backend_mod, AT, DAT)
7070
convert_testsuite(backend, AT)
7171
end
7272

73-
if backend_str != "ROCM"
73+
if backend_str != "ROCM" &&
74+
!(backend_str == "CPU" && Base.VERSION < v"1.7.0")
7475
@testset "Atomics" begin
7576
atomics_testsuite(backend, AT)
7677
end

0 commit comments

Comments
 (0)