Atomix.jl

Atomix — Module

Atomix

Dev CI

Atomix.jl implements @atomic, @atomicswap, and @atomicreplace that are superset of the macros in Base. In addition to atomic operations on the fields as implemented in Base, they support atomic operations on array elements.

julia> using Atomix: @atomic, @atomicswap, @atomicreplace

julia> A = ones(Int, 3);

julia> @atomic A[1] += 1;  # fetch-and-increment

julia> @atomic A[1]
2

julia> @atomicreplace A[begin+1] 1 => 42  # compare-and-swap
(old = 1, success = true)

julia> @inbounds @atomic :monotonic A[begin+1]  # specify ordering and skip bound check
42

julia> @atomicswap A[end] = 123
1

julia> A[end]
123

Atomic operations on GPU arrays are atomic with respect to the threads of the device, like the plain atomics of CUDA C or HIP. They are not guaranteed to be atomic with respect to the host or other devices accessing the same memory.

source
Atomix.@atomic — Macro
Atomix.@atomic

A superset of Base.@atomic supporting atomic operations on array elements. Atomic operations on fields dispatches to Base.@atomic.

source
Atomix.@atomicswap — Macro
Atomix.@atomicswap

A superset of Base.@atomicswap supporting atomic operations on array elements. Atomic operations on fields dispatches to Base.@atomicswap.

source
Atomix.@atomicreplace — Macro
Atomix.@atomicreplace

A superset of Base.@atomicreplace supporting atomic operations on array elements. Atomic operations on fields dispatches to Base.@atomicreplace.

source