1- export CLArray, CLVector, CLMatrix, CLVecOrMat, is_device, is_shared, is_host
1+ export CLArray, CLVector, CLMatrix, CLVecOrMat,
2+ device_accessible, host_accessible
23
34
45# # array type
@@ -176,11 +177,9 @@ memtype(x::CLArray) = memtype(typeof(x))
176177memtype (:: Type{<:CLArray{<:Any, <:Any, M}} ) where {M} = @isdefined (M) ? M : Any
177178
178179# can we read this array from the device (i.e. derive a CLPtr)?
179- is_device (a:: CLArray ) =
180+ device_accessible (a:: CLArray ) =
180181 memtype (a) in (cl. UnifiedDeviceMemory, cl. UnifiedSharedMemory, cl. SharedVirtualMemory, cl. Buffer)
181- is_shared (a:: CLArray ) =
182- memtype (a) in (cl. UnifiedSharedMemory, cl. SharedVirtualMemory)
183- is_host (a:: CLArray ) =
182+ host_accessible (a:: CLArray ) =
184183 memtype (a) in (cl. UnifiedHostMemory, cl. UnifiedSharedMemory, cl. SharedVirtualMemory)
185184
186185
@@ -272,12 +271,12 @@ Base.convert(::Type{T}, x::T) where {T <: CLArray} = x
272271
273272# # indexing
274273
275- function Base. getindex (x:: CLArray{<:Any, <:Any, <:Union{cl.UnifiedHostMemory, cl.UnifiedSharedMemory}} , I:: Int )
274+ function Base. getindex (x:: CLArray{<:Any, <:Any, <:Union{cl.UnifiedHostMemory, cl.UnifiedSharedMemory, cl.SharedVirtualMemory }} , I:: Int )
276275 @boundscheck checkbounds (x, I)
277276 return GC. @preserve x unsafe_load (host_pointer (x, I))
278277end
279278
280- function Base. setindex! (x:: CLArray{<:Any, <:Any, <:Union{cl.UnifiedHostMemory, cl.UnifiedSharedMemory}} , v, I:: Int )
279+ function Base. setindex! (x:: CLArray{<:Any, <:Any, <:Union{cl.UnifiedHostMemory, cl.UnifiedSharedMemory, cl.SharedVirtualMemory }} , v, I:: Int )
281280 @boundscheck checkbounds (x, I)
282281 return GC. @preserve x unsafe_store! (host_pointer (x, I), v)
283282end
@@ -286,14 +285,14 @@ end
286285# # interop with libraries
287286
288287function Base. unsafe_convert (:: Type{Ptr{T}} , x:: CLArray{T} ) where {T}
289- if ! is_host (x)
288+ if ! host_accessible (x)
290289 throw (ArgumentError (" cannot take the CPU address of a $(typeof (x)) " ))
291290 end
292291 return convert (Ptr{T}, x. data[]) + x. offset * Base. elsize (x)
293292end
294293
295294function Base. unsafe_convert (:: Type{CLPtr{T}} , x:: CLArray{T} ) where {T}
296- if ! is_device (x)
295+ if ! device_accessible (x)
297296 throw (ArgumentError (" cannot take the device address of a $(typeof (x)) " ))
298297 end
299298 return convert (CLPtr{T}, x. data[]) + x. offset * Base. elsize (x)
@@ -485,16 +484,14 @@ Base.unsafe_convert(::Type{CLPtr{T}}, A::PermutedDimsArray) where {T} =
485484# # unsafe_wrap
486485
487486"""
488- unsafe_wrap(Array, arr::CLArray{_,_,cl.UnifiedSharedMemory} )
487+ unsafe_wrap(Array, arr::CLArray)
489488
490489Wrap a Julia `Array` around the buffer that backs a `CLArray`. This is only possible if the
491- GPU array is backed by a shared buffer, i.e. if it was created with `CLArray{T}(undef, ...)`.
490+ GPU array is backed by host memory, such as unified (host or shared) memory, or shared
491+ virtual memory.
492492"""
493- function Base. unsafe_wrap (:: Type{Array} , arr:: CLArray{T, N, cl.UnifiedSharedMemory} ) where {T, N}
494- # TODO : can we make this more convenient by increasing the buffer's refcount and using
495- # a finalizer on the Array? does that work when taking views etc of the Array?
496- ptr = reinterpret (Ptr{T}, pointer (arr))
497- return unsafe_wrap (Array, ptr, size (arr))
493+ function Base. unsafe_wrap (:: Type{Array} , arr:: CLArray{T, N} ) where {T, N}
494+ return unsafe_wrap (Array, host_pointer (arr), size (arr))
498495end
499496
500497
0 commit comments