Skip to content

Commit 7eb246e

Browse files
replace device
1 parent 699e129 commit 7eb246e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/ArrayInterface.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ has_parent(::Type{T}) where {T} = _has_parent(parent_type(T), T)
101101
_has_parent(::Type{T}, ::Type{T}) where {T} = False()
102102
_has_parent(::Type{T1}, ::Type{T2}) where {T1,T2} = True()
103103

104+
"""
105+
device(::Type{T}) -> AbstractDevice
106+
107+
Indicates the most efficient way to access elements from the collection in low-level code.
108+
For `GPUArrays`, will return `ArrayInterface.GPU()`.
109+
For `AbstractArray` supporting a `pointer` method, returns `ArrayInterface.CPUPointer()`.
110+
For other `AbstractArray`s and `Tuple`s, returns `ArrayInterface.CPUIndex()`.
111+
Otherwise, returns `nothing`.
112+
"""
113+
device(A) = device(typeof(A))
114+
device(::Type) = nothing
115+
device(::Type{<:Tuple}) = CPUTuple()
116+
device(::Type{T}) where {T<:Array} = CPUPointer()
104117
device(::Type{T}) where {T<:AbstractArray} = _device(has_parent(T), T)
105118
function _device(::True, ::Type{T}) where {T}
106119
if defines_strides(T)

0 commit comments

Comments
 (0)