Skip to content
Open
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 .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
julia -e 'using Pkg

println("--- :julia: Instantiating environment")
Pkg.add("CUDA")
Pkg.add("CUDACore")
Pkg.develop(PackageSpec(name="Atomix", path="."))

println("+++ :julia: Running tests")
Expand Down
14 changes: 8 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
name = "Atomix"
uuid = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
authors = ["Takafumi Arakaki <aka.tkf@gmail.com> and contributors"]
version = "1.2.1"
version = "1.3.0"

[deps]
UnsafeAtomics = "013be700-e6cd-48c3-b4a1-df204f14c38f"

[weakdeps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CUDACore = "bd0ed864-bdfe-4181-a5ed-ce625a5fdea2"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
oneAPI = "8f75cd03-7ff8-4ecb-9b8f-daf728133b1b"
OpenCL = "08131aa3-fb12-5dee-8b74-c09406e224a2"
oneAPI = "8f75cd03-7ff8-4ecb-9b8f-daf728133b1b"

[extensions]
AtomixCUDAExt = "CUDA"
AtomixCUDACoreExt = "CUDACore"
AtomixMetalExt = "Metal"
AtomixoneAPIExt = "oneAPI"
AtomixOpenCLExt = "OpenCL"
AtomixoneAPIExt = "oneAPI"

[compat]
CUDA = "5, 6"
CUDA = "6"
Comment thread
vchuravy marked this conversation as resolved.
CUDACore = "6"
Metal = "1.7"
oneAPI = "1, 2"
OpenCL = "^0.10"
UnsafeAtomics = "0.1, 0.2, 0.3"
julia = "1.10"
oneAPI = "1, 2"
24 changes: 12 additions & 12 deletions ext/AtomixCUDAExt.jl → ext/AtomixCUDACoreExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module AtomixCUDAExt
module AtomixCUDACoreExt

using Atomix: Atomix, IndexableRef, right
using CUDA: CUDA, CuDeviceArray
using CUDACore: CUDACore, CuDeviceArray
using Core: LLVMPtr

const CuIndexableRef{Indexable<:CuDeviceArray} = IndexableRef{Indexable}
Expand All @@ -26,7 +26,7 @@ const NativeFloat = Union{Float32,Float64}
ptr = Atomix.pointer(ref)
expected = convert(eltype(ref), expected)
desired = convert(eltype(ref), desired)
old = CUDA.atomic_cas!(ptr, expected, desired)
old = CUDACore.atomic_cas!(ptr, expected, desired)
return (; old = old, success = old === expected)
end

Expand All @@ -42,14 +42,14 @@ for (op, fn) in [(+) => :atomic_add!, (-) => :atomic_sub!, (&) => :atomic_and!,
(|) => :atomic_or!, xor => :atomic_xor!, min => :atomic_min!,
max => :atomic_max!]
@eval @inline modify_native!(ptr::LLVMPtr{<:NativeInt}, ::typeof($op), x) =
CUDA.$fn(ptr, x)
CUDACore.$fn(ptr, x)
end
@inline modify_native!(ptr::LLVMPtr{Float32}, ::typeof(+), x) = CUDA.atomic_add!(ptr, x)
@inline modify_native!(ptr::LLVMPtr{Float32}, ::typeof(-), x) = CUDA.atomic_sub!(ptr, x)
@inline modify_native!(ptr::LLVMPtr{Float32}, ::typeof(+), x) = CUDACore.atomic_add!(ptr, x)
@inline modify_native!(ptr::LLVMPtr{Float32}, ::typeof(-), x) = CUDACore.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().major >= 6
CUDA.atomic_add!(ptr, x)
if CUDACore.compute_capability().major >= 6
CUDACore.atomic_add!(ptr, x)
else
modify_cas!(ptr, +, x)
end
Expand All @@ -58,10 +58,10 @@ end

# swap: exchange floats through their integer representation
@inline modify_native!(ptr::LLVMPtr{<:NativeInt}, ::typeof(right), x) =
CUDA.atomic_xchg!(ptr, x)
CUDACore.atomic_xchg!(ptr, x)
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))
old = CUDACore.atomic_xchg!(reinterpret(LLVMPtr{$I,A}, ptr), reinterpret($I, x))
return reinterpret($T, old)
end
end
Expand All @@ -73,11 +73,11 @@ end
old = Base.unsafe_load(ptr)
while true
new = convert(T, op(old, x))
seen = CUDA.atomic_cas!(ptr, old, new)
seen = CUDACore.atomic_cas!(ptr, old, new)
# bitwise comparison: `==` would spin forever on NaN
seen === old && return old
old = seen
end
end

end # module AtomixCUDAExt
end # module AtomixCUDACoreExt
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end
mutable struct Atomic{T}
@atomic x::T
end

a = Atomic(123)
@test (@atomic a.x) == 123
@test (@atomic :monotonic a.x) == 123
Expand Down Expand Up @@ -143,7 +143,7 @@ if "--Metal" in ARGS
include("test_atomix_metal.jl")
elseif "--CUDA" in ARGS
import Pkg
Pkg.add("CUDA")
Pkg.add("CUDACore")
include("test_atomix_cuda.jl")
elseif "--oneAPI" in ARGS
import Pkg
Expand Down
42 changes: 21 additions & 21 deletions test/test_atomix_cuda.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CUDA
using CUDA: @allowscalar
using CUDACore
using CUDACore: @allowscalar


@testset "AtomixCUDAExt:extension_found" begin
@test !isnothing(Base.get_extension(Atomix, :AtomixCUDAExt))
@testset "AtomixCUDACoreExt:extension_found" begin
@test !isnothing(Base.get_extension(Atomix, :AtomixCUDACoreExt))
end


Expand All @@ -12,13 +12,13 @@ function cuda(f)
f()
nothing
end
CUDA.@cuda g()
@cuda g()
end




@testset "AtomixCUDAExt:test_cas" begin
@testset "AtomixCUDACoreExt:test_cas" begin
idx = (
data = 1,
cas1_ok = 2,
Expand All @@ -28,7 +28,7 @@ end
@assert minimum(idx) >= 1
@assert maximum(idx) == length(idx)

A = CUDA.zeros(Int, length(idx))
A = CUDACore.zeros(Int, length(idx))
cuda() do
GC.@preserve A begin
ref = Atomix.IndexableRef(A, (1,))
Expand All @@ -42,8 +42,8 @@ end
end


@testset "AtomixCUDAExt:test_inc" begin
A = CUDA.CuVector(1:3)
@testset "AtomixCUDACoreExt:test_inc" begin
A = CuVector(1:3)
cuda() do
GC.@preserve A begin
ref = Atomix.IndexableRef(A, (1,))
Expand All @@ -56,8 +56,8 @@ end
end


@testset "AtomixCUDAExt:test_inc_sugar" begin
A = CUDA.ones(Int, 3)
@testset "AtomixCUDACoreExt:test_inc_sugar" begin
A = CUDACore.ones(Int, 3)
cuda() do
GC.@preserve A begin
@atomic A[begin] += 1
Expand All @@ -67,8 +67,8 @@ end
end


@testset "AtomixCUDAExt:test_get_set" begin
A = CUDA.ones(Int, 3)
@testset "AtomixCUDACoreExt:test_get_set" begin
A = CUDACore.ones(Int, 3)
cuda() do
GC.@preserve A begin
ref = Atomix.IndexableRef(A, (1,))
Expand All @@ -82,8 +82,8 @@ end
end


@testset "AtomixCUDAExt:test_swap" begin
A = CUDA.CuVector(Int[1, 0, 0])
@testset "AtomixCUDACoreExt:test_swap" begin
A = CuVector(Int[1, 0, 0])
cuda() do
GC.@preserve A begin
ref = Atomix.IndexableRef(A, (1,))
Expand All @@ -95,8 +95,8 @@ end
end


@testset "AtomixCUDAExt:test_ordering" begin
A = CUDA.ones(Int, 2)
@testset "AtomixCUDACoreExt:test_ordering" begin
A = CUDACore.ones(Int, 2)
cuda() do
GC.@preserve A begin
@atomic :monotonic A[1] += 1
Expand All @@ -107,8 +107,8 @@ end
end


@testset "AtomixCUDAExt:test_float" begin
A = CUDA.CuVector(Float32[1, 1, 1, 1, 1, 0, 0, 1])
@testset "AtomixCUDACoreExt:test_float" begin
A = CuVector(Float32[1, 1, 1, 1, 1, 0, 0, 1])
cuda() do
GC.@preserve A begin
@atomic A[1] += 1.5f0
Expand All @@ -125,8 +125,8 @@ end
end


@testset "AtomixCUDAExt:test_float64" begin
A = CUDA.CuVector(Float64[1, 1, 1, 1, 1, 0, 0, 1])
@testset "AtomixCUDACoreExt:test_float64" begin
A = CuVector(Float64[1, 1, 1, 1, 1, 0, 0, 1])
cuda() do
GC.@preserve A begin
@atomic A[1] += 1.5
Expand Down
Loading