Skip to content

Commit

Permalink
Merge pull request #74 from williamfgc/add-atomix
Browse files Browse the repository at this point in the history
Add suport for Atomix.@atomic across back ends
  • Loading branch information
williamfgc authored Apr 17, 2024
2 parents 6f17875 + 92c5837 commit 0498e7f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["pedrovalerolara <valerolarap@ornl.gov>", "williamfgc <williamfgc@yah
version = "0.0.3"

[deps]
Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[weakdeps]
Expand Down
3 changes: 2 additions & 1 deletion src/JACC.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
__precompile__(false)
module JACC

import Atomix: @atomic
# module to set back end preferences
include("JACCPreferences.jl")
include("helper.jl")

export Array
export Array, @atomic
export parallel_for

global Array
Expand Down
20 changes: 20 additions & 0 deletions test/tests_amdgpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,23 @@ end

@test Array(x_device) x_expected rtol = 1e-1
end

@testset "AtomicCounter" begin

function axpy_counter!(i, alpha, x, y, counter)
@inbounds x[i] += alpha * y[i]
JACC.@atomic counter[1] += 1
end

N = Int32(10)
# Generate random vectors x and y of length N for the interval [0, 100]
alpha = 2.5

x = JACC.Array(round.(rand(Float32, N) * 100))
y = JACC.Array(round.(rand(Float32, N) * 100))
counter = JACC.Array{Int32}([0])
JACC.parallel_for(N, axpy_counter!, alpha, x, y, counter)

@test Array(counter)[1] == N
end

20 changes: 20 additions & 0 deletions test/tests_cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ end
@test Array(x_device) x_expected rtol = 1e-1
end

@testset "AtomicCounter" begin

function axpy_counter!(i, alpha, x, y, counter)
@inbounds x[i] += alpha * y[i]
JACC.@atomic counter[1] += 1
end

N = Int32(10)
# Generate random vectors x and y of length N for the interval [0, 100]
alpha = 2.5

x = JACC.Array(round.(rand(Float32, N) * 100))
y = JACC.Array(round.(rand(Float32, N) * 100))
counter = JACC.Array{Int32}([0])
JACC.parallel_for(N, axpy_counter!, alpha, x, y, counter)

@test Array(counter)[1] == N
end





Expand Down
24 changes: 21 additions & 3 deletions test/tests_threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ end
@test x_host_JACC x_expected rtol = 1e-1
end

@testset "AtomicCounter" begin

function axpy_counter!(i, alpha, x, y, counter)
@inbounds x[i] += alpha * y[i]
JACC.@atomic counter[1] += 1
end

N = Int32(10)
# Generate random vectors x and y of length N for the interval [0, 100]
alpha = 2.5
counter = zeros(Int32, 1)

x_device = JACC.Array(round.(rand(Float32, N) * 100))
y_device = JACC.Array(round.(rand(Float32, N) * 100))
counter = JACC.Array{Int32}([0])
JACC.parallel_for(N, axpy_counter!, alpha, x_device, y_device, counter)

@test counter[1] == N

end

@testset "CG" begin

function matvecmul(i, a1, a2, a3, x, y, SIZE)
Expand Down Expand Up @@ -112,9 +133,6 @@ end
ccond = JACC.parallel_reduce(SIZE, dot, r, r)
global cond = ccond
p = copy(r_aux)

println(cond)

end
@test cond[1, 1] <= 1e-14
end
Expand Down

0 comments on commit 0498e7f

Please sign in to comment.