diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 0e57c6d..b5a2427 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -7,11 +7,11 @@ steps: julia -e 'using Pkg println("--- :julia: Instantiating environment") - Pkg.activate("lib/AtomixCUDA") + Pkg.add("CUDA") Pkg.develop(PackageSpec(name="Atomix", path=".")) println("+++ :julia: Running tests") - Pkg.test()' + Pkg.test("Atomix", test_args=["--CUDA"])' agents: queue: "juliagpu" cuda: "*" @@ -26,14 +26,15 @@ steps: julia -e 'using Pkg println("--- :julia: Instantiating environment") - Pkg.activate("lib/AtomixMetal") + Pkg.add("Metal") Pkg.develop(PackageSpec(name="Atomix", path=".")) println("+++ :julia: Running tests") - Pkg.test()' + Pkg.test("Atomix", test_args=["--Metal"])' agents: queue: "juliaecosystem" os: "macos" arch: "aarch64" if: build.message !~ /\[skip tests\]/ timeout_in_minutes: 15 + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 845e409..0806cff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,8 @@ jobs: matrix: julia-version: - '1' - - '1.6' + - 'lts' + - 'pre' fail-fast: false name: Test Julia ${{ matrix.julia-version }} steps: @@ -33,24 +34,6 @@ jobs: flags: Pkg.test name: codecov-umbrella - aqua: - runs-on: ubuntu-latest - strategy: - matrix: - julia-version: - - '1' - - '1.6' - fail-fast: false - steps: - - uses: actions/checkout@v4 - - - uses: julia-actions/setup-julia@v2 - with: - version: ${{ matrix.julia-version }} - - uses: julia-actions/cache@v2 - - - uses: tkf/julia-aqua@v1 - documenter: runs-on: ubuntu-latest steps: @@ -78,17 +61,10 @@ jobs: if: steps.build-and-deploy.outcome == 'skipped' run: julia -e 'using Run; Run.docs()' - # https://github.com/tkf/julia-code-style-suggesters - code-style: - if: always() && github.event.pull_request - runs-on: ubuntu-latest - steps: - - uses: tkf/julia-code-style-suggesters@v1 - # A job that succeeds if and only if all jobs succeed. all-success: if: always() && github.event.pull_request - needs: [test, aqua, documenter, code-style] + needs: [test, documenter] runs-on: ubuntu-latest steps: # https://github.com/tkf/merge-conclusions-action diff --git a/Project.toml b/Project.toml index 38aa10e..c2564f1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,11 +1,21 @@ name = "Atomix" uuid = "a9b6321e-bd34-4604-b9c9-b65b8de01458" authors = ["Takafumi Arakaki and contributors"] -version = "1.0" +version = "0.2.0" [deps] UnsafeAtomics = "013be700-e6cd-48c3-b4a1-df204f14c38f" [compat] +CUDA = "5" +Metal = "1" UnsafeAtomics = "0.1, 0.2" -julia = "1.6" +julia = "1.10" + +[extensions] +AtomixCUDAExt = "CUDA" +AtomixMetalExt = "Metal" + +[weakdeps] +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +Metal = "dde4c033-4e86-420c-a63e-0dd931031962" diff --git a/docs/Project.toml b/docs/Project.toml index bbd3304..c19204d 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,5 +1,6 @@ [deps] +Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" [compat] -Documenter = "1.7" +Documenter = "1" diff --git a/docs/make.jl b/docs/make.jl index 7627915..42427db 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,14 +1,18 @@ using Documenter using Atomix -makedocs( - sitename = "Atomix", - modules = [Atomix], - warnonly = :missing_docs +makedocs(; + sitename="Atomix", + modules=[Atomix], + format=Documenter.HTML(; + # Only create web pretty-URLs on the CI + prettyurls=get(ENV, "CI", nothing) == "true", + ), + warnonly=:missing_docs, ) deploydocs( - repo = "github.com/JuliaConcurrent/Atomix.jl", - devbranch = "main", - push_preview = true, + repo="github.com/JuliaConcurrent/Atomix.jl", + devbranch="main", + push_preview=true, ) diff --git a/docs/make_local.jl b/docs/make_local.jl new file mode 100644 index 0000000..2068806 --- /dev/null +++ b/docs/make_local.jl @@ -0,0 +1,5 @@ +# Activate docs environment and use ("develop") local library +using Pkg +Pkg.activate(@__DIR__) +Pkg.develop(path=joinpath(@__DIR__, "..")) +include("make.jl") diff --git a/lib/AtomixCUDA/src/AtomixCUDA.jl b/ext/AtomixCUDAExt.jl similarity index 96% rename from lib/AtomixCUDA/src/AtomixCUDA.jl rename to ext/AtomixCUDAExt.jl index 4b433c1..5a79d62 100644 --- a/lib/AtomixCUDA/src/AtomixCUDA.jl +++ b/ext/AtomixCUDAExt.jl @@ -1,5 +1,5 @@ # TODO: respect ordering -module AtomixCUDA +module AtomixCUDAExt using Atomix: Atomix, IndexableRef using CUDA: CUDA, CuDeviceArray @@ -55,4 +55,4 @@ end return old => op(old, x) end -end # module AtomixCUDA +end # module AtomixCUDAExt diff --git a/lib/AtomixMetal/src/AtomixMetal.jl b/ext/AtomixMetalExt.jl similarity index 96% rename from lib/AtomixMetal/src/AtomixMetal.jl rename to ext/AtomixMetalExt.jl index 8a76279..7df0bb6 100644 --- a/lib/AtomixMetal/src/AtomixMetal.jl +++ b/ext/AtomixMetalExt.jl @@ -1,5 +1,5 @@ # TODO: respect ordering -module AtomixMetal +module AtomixMetalExt using Atomix: Atomix, IndexableRef using Metal: Metal, MtlDeviceArray @@ -55,4 +55,4 @@ end return old => op(old, x) end -end # module AtomixMetal +end # module AtomixMetalExt diff --git a/lib/AtomixCUDA/.gitignore b/lib/AtomixCUDA/.gitignore deleted file mode 100644 index 4fc6527..0000000 --- a/lib/AtomixCUDA/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -Manifest.toml - diff --git a/lib/AtomixCUDA/LICENSE b/lib/AtomixCUDA/LICENSE deleted file mode 100644 index 02e1d79..0000000 --- a/lib/AtomixCUDA/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Takafumi Arakaki and contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lib/AtomixCUDA/Project.toml b/lib/AtomixCUDA/Project.toml deleted file mode 100644 index 2f93523..0000000 --- a/lib/AtomixCUDA/Project.toml +++ /dev/null @@ -1,13 +0,0 @@ -name = "AtomixCUDA" -uuid = "6171a885-8764-404f-b64d-f8edb1679b6f" -authors = ["Takafumi Arakaki and contributors"] -version = "1.0" - -[deps] -Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458" -CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" - -[compat] -julia = "1.6" -Atomix = "1" -CUDA = "5" diff --git a/lib/AtomixCUDA/README.md b/lib/AtomixCUDA/README.md deleted file mode 100644 index 4789416..0000000 --- a/lib/AtomixCUDA/README.md +++ /dev/null @@ -1 +0,0 @@ -# AtomixCUDA diff --git a/lib/AtomixCUDA/test/AtomixCUDATests/Project.toml b/lib/AtomixCUDA/test/AtomixCUDATests/Project.toml deleted file mode 100644 index dcb7605..0000000 --- a/lib/AtomixCUDA/test/AtomixCUDATests/Project.toml +++ /dev/null @@ -1,13 +0,0 @@ -name = "AtomixCUDATests" -uuid = "210b840b-8615-4854-b591-ce0d4815b014" -authors = ["Takafumi Arakaki and contributors"] -version = "0.1.0-DEV" - -[deps] -Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458" -AtomixCUDA = "6171a885-8764-404f-b64d-f8edb1679b6f" -CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[compat] -julia = "1.6" diff --git a/lib/AtomixCUDA/test/AtomixCUDATests/src/AtomixCUDATests.jl b/lib/AtomixCUDA/test/AtomixCUDATests/src/AtomixCUDATests.jl deleted file mode 100644 index b472702..0000000 --- a/lib/AtomixCUDA/test/AtomixCUDATests/src/AtomixCUDATests.jl +++ /dev/null @@ -1,7 +0,0 @@ -module AtomixCUDATests - -include("utils.jl") -include("test_core.jl") -include("test_sugar.jl") - -end # module AtomixCUDATests diff --git a/lib/AtomixCUDA/test/AtomixCUDATests/src/test_sugar.jl b/lib/AtomixCUDA/test/AtomixCUDATests/src/test_sugar.jl deleted file mode 100644 index ad19aba..0000000 --- a/lib/AtomixCUDA/test/AtomixCUDATests/src/test_sugar.jl +++ /dev/null @@ -1,36 +0,0 @@ -module TestSugar - -import AtomixCUDA - -using Atomix: @atomic -using CUDA -using CUDA: @allowscalar -using Test - -using ..Utils: cuda - -# Not implemented: -#= -function test_get_set() - A = CUDA.ones(Int, 3) - cuda() do - GC.@preserve A begin - x = @atomic A[begin] - @atomic A[end-2] = -x - end - end - @test collect(A) == [-1, 1, 1] -end -=# - -function test_inc() - A = CUDA.ones(Int, 3) - cuda() do - GC.@preserve A begin - @atomic A[begin] += 1 - end - end - @test collect(A) == [2, 1, 1] -end - -end # module diff --git a/lib/AtomixCUDA/test/AtomixCUDATests/src/utils.jl b/lib/AtomixCUDA/test/AtomixCUDATests/src/utils.jl deleted file mode 100644 index e9faf60..0000000 --- a/lib/AtomixCUDA/test/AtomixCUDATests/src/utils.jl +++ /dev/null @@ -1,13 +0,0 @@ -module Utils - -using CUDA - -function cuda(f) - function g() - f() - nothing - end - CUDA.@cuda g() -end - -end # module diff --git a/lib/AtomixCUDA/test/Project.toml b/lib/AtomixCUDA/test/Project.toml deleted file mode 100644 index 77d6950..0000000 --- a/lib/AtomixCUDA/test/Project.toml +++ /dev/null @@ -1,6 +0,0 @@ -[deps] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -TestFunctionRunner = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" - -[compat] -TestFunctionRunner = "0.1" diff --git a/lib/AtomixCUDA/test/runtests.jl b/lib/AtomixCUDA/test/runtests.jl deleted file mode 100644 index d358b79..0000000 --- a/lib/AtomixCUDA/test/runtests.jl +++ /dev/null @@ -1,2 +0,0 @@ -using TestFunctionRunner -TestFunctionRunner.@run diff --git a/lib/AtomixMetal/LICENSE b/lib/AtomixMetal/LICENSE deleted file mode 100644 index 02e1d79..0000000 --- a/lib/AtomixMetal/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Takafumi Arakaki and contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lib/AtomixMetal/Project.toml b/lib/AtomixMetal/Project.toml deleted file mode 100644 index 408b31e..0000000 --- a/lib/AtomixMetal/Project.toml +++ /dev/null @@ -1,13 +0,0 @@ -name = "AtomixMetal" -uuid = "fc0d88fc-5db5-40d7-bf35-da84fd759def" -authors = ["Andrei-Leonard Nicusan and contributors"] -version = "1.0" - -[deps] -Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458" -Metal = "dde4c033-4e86-420c-a63e-0dd931031962" - -[compat] -julia = "1.6" -Atomix = "1" -Metal = "1" diff --git a/lib/AtomixMetal/README.md b/lib/AtomixMetal/README.md deleted file mode 100644 index 761f883..0000000 --- a/lib/AtomixMetal/README.md +++ /dev/null @@ -1 +0,0 @@ -# AtomixMetal \ No newline at end of file diff --git a/lib/AtomixMetal/test/AtomixMetalTests/Project.toml b/lib/AtomixMetal/test/AtomixMetalTests/Project.toml deleted file mode 100644 index 243a1a7..0000000 --- a/lib/AtomixMetal/test/AtomixMetalTests/Project.toml +++ /dev/null @@ -1,13 +0,0 @@ -name = "AtomixMetalTests" -uuid = "03c00b03-d8de-4838-97ce-ef69879af46e" -authors = ["Andrei-Leonard Nicusan and contributors"] -version = "0.1.0-DEV" - -[deps] -Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458" -AtomixMetal = "fc0d88fc-5db5-40d7-bf35-da84fd759def" -Metal = "dde4c033-4e86-420c-a63e-0dd931031962" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[compat] -julia = "1.6" diff --git a/lib/AtomixMetal/test/AtomixMetalTests/src/AtomixMetalTests.jl b/lib/AtomixMetal/test/AtomixMetalTests/src/AtomixMetalTests.jl deleted file mode 100644 index 8ee7760..0000000 --- a/lib/AtomixMetal/test/AtomixMetalTests/src/AtomixMetalTests.jl +++ /dev/null @@ -1,7 +0,0 @@ -module AtomixMetalTests - -include("utils.jl") -include("test_core.jl") -include("test_sugar.jl") - -end # module AtomixMetalTests diff --git a/lib/AtomixMetal/test/AtomixMetalTests/src/test_sugar.jl b/lib/AtomixMetal/test/AtomixMetalTests/src/test_sugar.jl deleted file mode 100644 index 97363b8..0000000 --- a/lib/AtomixMetal/test/AtomixMetalTests/src/test_sugar.jl +++ /dev/null @@ -1,36 +0,0 @@ -module TestSugar - -import AtomixMetal - -using Atomix: @atomic -using Metal -using Metal: @allowscalar -using Test - -using ..Utils: metal - -# Not implemented: -#= -function test_get_set() - A = CUDA.ones(Int, 3) - cuda() do - GC.@preserve A begin - x = @atomic A[begin] - @atomic A[end-2] = -x - end - end - @test collect(A) == [-1, 1, 1] -end -=# - -function test_inc() - A = Metal.ones(Int32, 3) - metal() do - GC.@preserve A begin - @atomic A[begin] += 1 - end - end - @test collect(A) == [2, 1, 1] -end - -end # module diff --git a/lib/AtomixMetal/test/AtomixMetalTests/src/utils.jl b/lib/AtomixMetal/test/AtomixMetalTests/src/utils.jl deleted file mode 100644 index 9abe2f0..0000000 --- a/lib/AtomixMetal/test/AtomixMetalTests/src/utils.jl +++ /dev/null @@ -1,13 +0,0 @@ -module Utils - -using Metal - -function metal(f) - function g() - f() - nothing - end - Metal.@metal g() -end - -end # module diff --git a/lib/AtomixMetal/test/Project.toml b/lib/AtomixMetal/test/Project.toml deleted file mode 100644 index 77d6950..0000000 --- a/lib/AtomixMetal/test/Project.toml +++ /dev/null @@ -1,6 +0,0 @@ -[deps] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -TestFunctionRunner = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" - -[compat] -TestFunctionRunner = "0.1" diff --git a/lib/AtomixMetal/test/runtests.jl b/lib/AtomixMetal/test/runtests.jl deleted file mode 100644 index d358b79..0000000 --- a/lib/AtomixMetal/test/runtests.jl +++ /dev/null @@ -1,2 +0,0 @@ -using TestFunctionRunner -TestFunctionRunner.@run diff --git a/test/AtomixTests/Project.toml b/test/AtomixTests/Project.toml deleted file mode 100644 index be211b1..0000000 --- a/test/AtomixTests/Project.toml +++ /dev/null @@ -1,13 +0,0 @@ -name = "AtomixTests" -uuid = "6f95a7dd-85ce-4dbe-a121-27757241c193" -authors = ["Takafumi Arakaki and contributors"] -version = "0.1.0-DEV" - -[deps] -Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458" -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -UnsafeAtomics = "013be700-e6cd-48c3-b4a1-df204f14c38f" - -[compat] -julia = "1" diff --git a/test/AtomixTests/src/AtomixTests.jl b/test/AtomixTests/src/AtomixTests.jl deleted file mode 100644 index 81ffda2..0000000 --- a/test/AtomixTests/src/AtomixTests.jl +++ /dev/null @@ -1,11 +0,0 @@ -module AtomixTests - -include("test_core.jl") -include("test_sugar.jl") -include("test_doctest.jl") - -if VERSION >= v"1.7" - include("test_fallback.jl") -end - -end # module AtomixTests diff --git a/test/AtomixTests/src/test_core.jl b/test/AtomixTests/src/test_core.jl deleted file mode 100644 index 65354c8..0000000 --- a/test/AtomixTests/src/test_core.jl +++ /dev/null @@ -1,35 +0,0 @@ -module TestCore - -using Atomix -using Atomix.Internal: referenceable -using Test - -function test_indexableref() - A = ones(Int, 3) - ref = Atomix.IndexableRef(A, (1,)) - @test eltype(ref) === Int - @test Atomix.get(ref) === 1 - Atomix.set!(ref, 123) - @test Atomix.get(ref) === 123 - @test Atomix.modify!(ref, +, 1) === (123 => 124) - @test Atomix.get(ref) === 124 - @test Atomix.swap!(ref, 345) == 124 - @test Atomix.get(ref) === 345 - @test Atomix.replace!(ref, 345, 567) === (old = 345, success = true) - @test Atomix.replace!(ref, 345, 567) === (old = 567, success = false) -end - -function test_referenceablearray() - @testset for a in Any[ - ones(Int, 3), - view(ones(Int, 3), 1:2), - view(ones(Int, 2, 3), 1:1, 1:2), - ones(Int, 3)', - ] - ra = referenceable(a) - @test size(ra) == size(a) - @test IndexStyle(ra) == IndexStyle(a) - end -end - -end # module diff --git a/test/AtomixTests/src/test_doctest.jl b/test/AtomixTests/src/test_doctest.jl deleted file mode 100644 index fed6d6b..0000000 --- a/test/AtomixTests/src/test_doctest.jl +++ /dev/null @@ -1,11 +0,0 @@ -module TestDoctest - -import Atomix -using Documenter: doctest -using Test - -function test_doctest() - doctest(Atomix; manual = false) -end - -end # module diff --git a/test/AtomixTests/src/test_fallback.jl b/test/AtomixTests/src/test_fallback.jl deleted file mode 100644 index c3041aa..0000000 --- a/test/AtomixTests/src/test_fallback.jl +++ /dev/null @@ -1,34 +0,0 @@ -module TestFallback - -using Atomix: @atomic, @atomicreplace, @atomicswap -using Test - -mutable struct Atomic{T} - @atomic x::T -end - -function test() - a = Atomic(123) - @test (@atomic a.x) == 123 - @test (@atomic :monotonic a.x) == 123 - @atomic a.x = 456 - @test (@atomic a.x) == 456 - @atomic :monotonic a.x = 123 - @test (@atomic a.x) == 123 - @test (@atomic a.x += 111) == 234 - @test (@atomic :monotonic a.x += 111) == 345 - @test (@atomic a.x + 111) == (345 => 456) - @test (@atomic :monotonic a.x + 111) == (456 => 567) - @test (@atomicswap a.x = 123) == 567 - @test (@atomicswap :monotonic a.x = 234) == 123 - @test (@atomicreplace a.x 234 => 123) == (old = 234, success = true) - @test (@atomicreplace a.x 234 => 123) == (old = 123, success = false) - @test (@atomicreplace :monotonic a.x 123 => 234) == (old = 123, success = true) - @test (@atomicreplace :monotonic a.x 123 => 234) == (old = 234, success = false) - @test (@atomicreplace :monotonic :monotonic a.x 234 => 123) == - (old = 234, success = true) - @test (@atomicreplace :monotonic :monotonic a.x 234 => 123) == - (old = 123, success = false) -end - -end # module diff --git a/test/AtomixTests/src/test_sugar.jl b/test/AtomixTests/src/test_sugar.jl deleted file mode 100644 index 4777f9c..0000000 --- a/test/AtomixTests/src/test_sugar.jl +++ /dev/null @@ -1,63 +0,0 @@ -module TestSugar - -using Atomix: @atomic, @atomicreplace, @atomicswap -using Test - -function test_get() - A = [42] - @test (@atomic A[1]) === 42 - @test (@atomic A[end]) === 42 - @test (@atomic :monotonic A[begin]) === 42 - order = :monotonic - @test (@atomic order A[begin]) === 42 -end - -function test_get_2d() - A = view([11 12; 21 22], 1:2, 1:2) - @test IndexStyle(A) isa IndexCartesian - @test (@atomic A[1]) === 11 - @test (@atomic A[2]) === 21 - @test (@atomic A[end]) === 22 - @test (@atomic A[2, 1]) === 21 - @test (@atomic A[end, 1]) === 21 - @test (@atomic A[1, end]) === 12 -end - -function test_set() - A = [42, 43] - @atomic A[1] = 123 - @atomic A[end] = 124 - @test A[1] === 123 - @test A[end] === 124 -end - -function test_inc() - A = [1, 1] - @test (@atomic A[1] += 123) === 124 - @test A[1] === 124 - @test (@atomic A[end] += 123) === 124 - @test A[end] === 124 -end - -function test_swap() - A = [1, 1] - @test (@atomicswap A[1] = 123) === 1 - @test A[1] === 123 - @test (@atomicswap A[end] = 456) === 1 - @test A[end] === 456 -end - -function test_cas() - A = [1, 1] - @test (@atomicreplace A[1] 1 => 123) == (old = 1, success = true) - @test A[1] === 123 - @test (@atomicreplace A[1] 1 => 456) == (old = 123, success = false) - @test A[1] === 123 - @test (@atomicreplace A[end] 1 => 789) == (old = 1, success = true) - @test A[end] === 789 - update = 789 => 123 - @test (@atomicreplace A[end] update) == (old = 789, success = true) - @test A[end] === 123 -end - -end # module diff --git a/test/Project.toml b/test/Project.toml index c60b383..f27b1a7 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,8 +1,4 @@ [deps] -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -TestFunctionRunner = "792026f5-ac9a-4a19-adcb-47b0ce2deb5d" -UnsafeAtomics = "013be700-e6cd-48c3-b4a1-df204f14c38f" - -[compat] -UnsafeAtomics = "0.2" diff --git a/test/runtests.jl b/test/runtests.jl index d358b79..3892706 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,2 +1,152 @@ -using TestFunctionRunner -TestFunctionRunner.@run +using Atomix +using Atomix.Internal: referenceable +using Atomix: @atomic, @atomicreplace, @atomicswap +using Test + + +@testset "Aqua.jl" begin + using Aqua + Aqua.test_all(Atomix) +end + + +@testset "test_indexableref" begin + A = ones(Int, 3) + ref = Atomix.IndexableRef(A, (1,)) + @test eltype(ref) === Int + @test Atomix.get(ref) === 1 + Atomix.set!(ref, 123) + @test Atomix.get(ref) === 123 + @test Atomix.modify!(ref, +, 1) === (123 => 124) + @test Atomix.get(ref) === 124 + @test Atomix.swap!(ref, 345) == 124 + @test Atomix.get(ref) === 345 + @test Atomix.replace!(ref, 345, 567) === (old = 345, success = true) + @test Atomix.replace!(ref, 345, 567) === (old = 567, success = false) +end + + +@testset "test_referenceablearray" begin + for a in Any[ + ones(Int, 3), + view(ones(Int, 3), 1:2), + view(ones(Int, 2, 3), 1:1, 1:2), + ones(Int, 3)', + ] + ra = referenceable(a) + @test size(ra) == size(a) + @test IndexStyle(ra) == IndexStyle(a) + end +end + + +@testset "test_fallback" begin + + mutable struct Atomic{T} + @atomic x::T + end + + a = Atomic(123) + @test (@atomic a.x) == 123 + @test (@atomic :monotonic a.x) == 123 + @atomic a.x = 456 + @test (@atomic a.x) == 456 + @atomic :monotonic a.x = 123 + @test (@atomic a.x) == 123 + @test (@atomic a.x += 111) == 234 + @test (@atomic :monotonic a.x += 111) == 345 + @test (@atomic a.x + 111) == (345 => 456) + @test (@atomic :monotonic a.x + 111) == (456 => 567) + @test (@atomicswap a.x = 123) == 567 + @test (@atomicswap :monotonic a.x = 234) == 123 + @test (@atomicreplace a.x 234 => 123) == (old = 234, success = true) + @test (@atomicreplace a.x 234 => 123) == (old = 123, success = false) + @test (@atomicreplace :monotonic a.x 123 => 234) == (old = 123, success = true) + @test (@atomicreplace :monotonic a.x 123 => 234) == (old = 234, success = false) + @test (@atomicreplace :monotonic :monotonic a.x 234 => 123) == + (old = 234, success = true) + @test (@atomicreplace :monotonic :monotonic a.x 234 => 123) == + (old = 123, success = false) +end + + +@testset "test_get" begin + A = [42] + @test (@atomic A[1]) === 42 + @test (@atomic A[end]) === 42 + @test (@atomic :monotonic A[begin]) === 42 + order = :monotonic + @test (@atomic order A[begin]) === 42 +end + + +@testset "test_get_2d" begin + A = view([11 12; 21 22], 1:2, 1:2) + @test IndexStyle(A) isa IndexCartesian + @test (@atomic A[1]) === 11 + @test (@atomic A[2]) === 21 + @test (@atomic A[end]) === 22 + @test (@atomic A[2, 1]) === 21 + @test (@atomic A[end, 1]) === 21 + @test (@atomic A[1, end]) === 12 +end + + +@testset "test_set" begin + A = [42, 43] + @atomic A[1] = 123 + @atomic A[end] = 124 + @test A[1] === 123 + @test A[end] === 124 +end + + +@testset "test_inc" begin + A = [1, 1] + @test (@atomic A[1] += 123) === 124 + @test A[1] === 124 + @test (@atomic A[end] += 123) === 124 + @test A[end] === 124 +end + + +@testset "test_swap" begin + A = [1, 1] + @test (@atomicswap A[1] = 123) === 1 + @test A[1] === 123 + @test (@atomicswap A[end] = 456) === 1 + @test A[end] === 456 +end + + +@testset "test_cas" begin + A = [1, 1] + @test (@atomicreplace A[1] 1 => 123) == (old = 1, success = true) + @test A[1] === 123 + @test (@atomicreplace A[1] 1 => 456) == (old = 123, success = false) + @test A[1] === 123 + @test (@atomicreplace A[end] 1 => 789) == (old = 1, success = true) + @test A[end] === 789 + update = 789 => 123 + @test (@atomicreplace A[end] update) == (old = 789, success = true) + @test A[end] === 123 +end + + +# KernelAbstractions backend tests +# Pass command-line argument to test suite to install the right backend, e.g. +# julia> import Pkg +# julia> Pkg.test("Atomix", test_args=["--Metal"]) +if "--Metal" in ARGS + import Pkg + Pkg.add("Metal") + include("test_atomix_metal.jl") +elseif "--CUDA" in ARGS + import Pkg + Pkg.add("CUDA") + include("test_atomix_cuda.jl") +elseif "--oneAPI" in ARGS + import Pkg + Pkg.add("oneAPI") + include("test_atomix_oneapi.jl") +end diff --git a/lib/AtomixCUDA/test/AtomixCUDATests/src/test_core.jl b/test/test_atomix_cuda.jl similarity index 69% rename from lib/AtomixCUDA/test/AtomixCUDATests/src/test_core.jl rename to test/test_atomix_cuda.jl index 077d22a..487eae2 100644 --- a/lib/AtomixCUDA/test/AtomixCUDATests/src/test_core.jl +++ b/test/test_atomix_cuda.jl @@ -1,13 +1,20 @@ -module TestCore - -import AtomixCUDA - -using Atomix using CUDA using CUDA: @allowscalar -using Test -using ..Utils: cuda + +@testset "AtomixCUDAExt:extension_found" begin + @test !isnothing(Base.get_extension(Atomix, :AtomixCUDAExt)) +end + + +function cuda(f) + function g() + f() + nothing + end + CUDA.@cuda g() +end + # Not implemented: #= @@ -24,7 +31,8 @@ function test_get_set() end =# -function test_cas() + +@testset "AtomixCUDAExt:test_cas" begin idx = ( data = 1, cas1_ok = 2, @@ -47,7 +55,8 @@ function test_cas() @test collect(A) == [42, 1, 1] end -function test_inc() + +@testset "AtomixCUDAExt:test_inc" begin A = CUDA.CuVector(1:3) cuda() do GC.@preserve A begin @@ -60,4 +69,13 @@ function test_inc() @test collect(A) == [2, 1, 2] end -end # module + +@testset "AtomixCUDAExt:test_inc_sugar" begin + A = CUDA.ones(Int, 3) + cuda() do + GC.@preserve A begin + @atomic A[begin] += 1 + end + end + @test collect(A) == [2, 1, 1] +end diff --git a/lib/AtomixMetal/test/AtomixMetalTests/src/test_core.jl b/test/test_atomix_metal.jl similarity index 69% rename from lib/AtomixMetal/test/AtomixMetalTests/src/test_core.jl rename to test/test_atomix_metal.jl index f982a2a..7d9a2d3 100644 --- a/lib/AtomixMetal/test/AtomixMetalTests/src/test_core.jl +++ b/test/test_atomix_metal.jl @@ -1,13 +1,20 @@ -module TestCore - -import AtomixMetal - -using Atomix using Metal using Metal: @allowscalar -using Test -using ..Utils: metal + +@testset "AtomixMetalExt:extension_found" begin + @test !isnothing(Base.get_extension(Atomix, :AtomixMetalExt)) +end + + +function metal(f) + function g() + f() + nothing + end + Metal.@metal g() +end + # Not implemented: #= @@ -24,7 +31,8 @@ function test_get_set() end =# -function test_cas() + +@testset "AtomixMetalExt:test_cas" begin idx = ( data = 1, cas1_ok = 2, @@ -47,7 +55,8 @@ function test_cas() @test collect(A) == [42, 1, 1] end -function test_inc() + +@testset "AtomixMetalExt:test_inc" begin A = Metal.MtlVector(Int32(1):Int32(3)) metal() do GC.@preserve A begin @@ -60,4 +69,13 @@ function test_inc() @test collect(A) == [2, 1, 2] end -end # module + +@testset "AtomixMetalExt:test_inc_sugar" begin + A = Metal.ones(Int32, 3) + metal() do + GC.@preserve A begin + @atomic A[begin] += 1 + end + end + @test collect(A) == [2, 1, 1] +end diff --git a/test/test_atomix_oneapi.jl b/test/test_atomix_oneapi.jl new file mode 100644 index 0000000..ca6dfba --- /dev/null +++ b/test/test_atomix_oneapi.jl @@ -0,0 +1,81 @@ +using oneAPI +using oneAPI: @allowscalar + + +@testset "AtomixoneAPIExt:extension_found" begin + @test !isnothing(Base.get_extension(Atomix, :AtomixoneAPIExt)) +end + + +function oneapi(f) + function g() + f() + nothing + end + oneAPI.@oneapi g() +end + + +# Not implemented: +#= +function test_get_set() + A = CUDA.ones(Int, 3) + cuda() do + GC.@preserve A begin + ref = Atomix.IndexableRef(A, (1,)) + x = Atomix.get(ref) + Atomix.set!(ref, -x) + end + end + @test collect(A) == [-1, 1, 1] +end +=# + + +@testset "AtomixoneAPIExt:test_cas" begin + idx = ( + data = 1, + cas1_ok = 2, + cas2_ok = 3, + # ... + ) + @assert minimum(idx) >= 1 + @assert maximum(idx) == length(idx) + + A = oneAPI.zeros(Int32, length(idx)) + oneapi() do + GC.@preserve A begin + ref = Atomix.IndexableRef(A, (1,)) + (old, success) = Atomix.replace!(ref, 0, 42) + A[idx.cas1_ok] = old == 0 && success + (old, success) = Atomix.replace!(ref, 0, 43) + A[idx.cas2_ok] = old == 42 && !success + end + end + @test collect(A) == [42, 1, 1] +end + + +@testset "AtomixoneAPIExt:test_inc" begin + A = oneAPI.oneVector(Int32(1):Int32(3)) + oneapi() do + GC.@preserve A begin + ref = Atomix.IndexableRef(A, (1,)) + pre, post = Atomix.modify!(ref, +, 1) + A[2] = pre + A[3] = post + end + end + @test collect(A) == [2, 1, 2] +end + + +@testset "AtomixoneAPIExt:test_inc_sugar" begin + A = oneAPI.ones(Int32, 3) + oneapi() do + GC.@preserve A begin + @atomic A[begin] += 1 + end + end + @test collect(A) == [2, 1, 1] +end