Skip to content

Commit 589fd1a

Browse files
oscardssmithkalmareknsajko
authored
Document GenericMemory and AtomicMemory (#54642)
Closes #53854. After talking with @vtjnash, we are ready to commit to the `GenericMemory` interface. Sorry @nsajko that this took me so long to get around to. --------- Co-authored-by: Marek Kaluba <kalmar@mailbox.org> Co-authored-by: Neven Sajko <s@purelymail.com>
1 parent 7197c9e commit 589fd1a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

base/genericmemory.jl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
## genericmemory.jl: Managed Memory
44

55
"""
6-
GenericMemory{kind::Symbol, T, addrspace=Core.CPU} <: AbstractVector{T}
6+
GenericMemory{kind::Symbol, T, addrspace=Core.CPU} <: DenseVector{T}
77
8-
One-dimensional dense array with elements of type `T`.
8+
Fixed-size [`DenseVector{T}`](@ref DenseVector).
9+
10+
`kind` can currently be either `:not_atomic` or `:atomic`. For details on what `:atomic` implies, see [`AtomicMemory`](@ref)
11+
12+
`addrspace` can currently only be set to Core.CPU. It is designed to to permit extension by other systems
13+
such as GPUs, which might define values such as:
14+
```
15+
module CUDA
16+
const Generic = bitcast(Core.AddrSpace{CUDA}, 0)
17+
const Global = bitcast(Core.AddrSpace{CUDA}, 1)
18+
end
19+
```
20+
The exact semantics of these other addrspaces is defined by the specific backend, but will error if the user is attempting to access these on the CPU.
921
1022
!!! compat "Julia 1.11"
1123
This type requires Julia 1.11 or later.
@@ -15,7 +27,7 @@ GenericMemory
1527
"""
1628
Memory{T} == GenericMemory{:not_atomic, T, Core.CPU}
1729
18-
One-dimensional dense array with elements of type `T`.
30+
Fixed-size [`DenseVector{T}`](@ref DenseVector).
1931
2032
!!! compat "Julia 1.11"
2133
This type requires Julia 1.11 or later.
@@ -25,8 +37,18 @@ Memory
2537
"""
2638
AtomicMemory{T} == GenericMemory{:atomic, T, Core.CPU}
2739
28-
One-dimensional dense array with elements of type `T`, where each element is
29-
independently atomic when accessed, and cannot be set non-atomically.
40+
Fixed-size [`DenseVector{T}`](@ref DenseVector).
41+
Access to its any of its elements is performed atomically (with `:monotonic` ordering).
42+
Setting any of the elements must be accomplished using the `@atomic` macro and explicitly specifying ordering.
43+
44+
!!! warning
45+
Each element is independently atomic when accessed, and cannot be set non-atomically.
46+
Currently the `@atomic` macro and higher level interface have not been completed,
47+
but the building blocks for a future implementation are the internal intrinsics
48+
`Core.memoryrefget`, `Core.memoryrefset!`, `Core.memoryref_isassigned`, `Core.memoryrefswap!`,
49+
`Core.memoryrefmodify!`, and `Core.memoryrefreplace!`.
50+
51+
For details, see [Atomic Operations](@ref man-atomic-operations)
3052
3153
!!! compat "Julia 1.11"
3254
This type requires Julia 1.11 or later.

doc/src/base/arrays.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Base.StridedArray
3030
Base.StridedVector
3131
Base.StridedMatrix
3232
Base.StridedVecOrMat
33+
Base.GenericMemory
3334
Base.Memory
3435
Base.memoryref
3536
Base.Slices

0 commit comments

Comments
 (0)