318
318
end
319
319
320
320
# ##
321
- # GPU implementation of `@Const`
321
+ # GPU implementation of const memory
322
322
# ##
323
- struct ConstCuDeviceArray{T,N,A} <: AbstractArray{T,N}
324
- shape:: Dims{N}
325
- ptr:: CUDA.DevicePtr{T,A}
326
323
327
- # inner constructors, fully parameterized, exact types (ie. Int not <:Integer)
328
- ConstCuDeviceArray {T,N,A} (shape:: Dims{N} , ptr:: CUDA.DevicePtr{T,A} ) where {T,A,N} = new (shape,ptr)
329
- end
330
-
331
- Adapt. adapt_storage (to:: ConstAdaptor , a:: CUDA.CuDeviceArray{T,N,A} ) where {T,N,A} = ConstCuDeviceArray {T, N, A} (a. shape, a. ptr)
332
-
333
- Base. pointer (a:: ConstCuDeviceArray ) = a. ptr
334
- Base. pointer (a:: ConstCuDeviceArray , i:: Integer ) =
335
- pointer (a) + (i - 1 ) * Base. elsize (a)
336
-
337
- Base. elsize (:: Type{<:ConstCuDeviceArray{T}} ) where {T} = sizeof (T)
338
- Base. size (g:: ConstCuDeviceArray ) = g. shape
339
- Base. length (g:: ConstCuDeviceArray ) = prod (g. shape)
340
- Base. IndexStyle (:: Type{<:ConstCuDeviceArray} ) = Base. IndexLinear ()
341
-
342
- Base. unsafe_convert (:: Type{CUDA.DevicePtr{T,A}} , a:: ConstCuDeviceArray{T,N,A} ) where {T,A,N} = pointer (a)
343
-
344
- @inline function Base. getindex (A:: ConstCuDeviceArray{T} , index:: Integer ) where {T}
345
- @boundscheck checkbounds (A, index)
346
- align = Base. datatype_alignment (T)
347
- CUDA. unsafe_cached_load (pointer (A), index, Val (align)):: T
348
- end
349
-
350
- @inline function Base. unsafe_view (arr:: ConstCuDeviceArray{T, 1, A} , I:: Vararg{Base.ViewIndex,1} ) where {T, A}
351
- ptr = pointer (arr) + (I[1 ]. start- 1 )* sizeof (T)
352
- len = I[1 ]. stop - I[1 ]. start + 1
353
- return ConstCuDeviceArray {T,1,A} (len, ptr)
354
- end
324
+ Adapt. adapt_storage (to:: ConstAdaptor , a:: CUDA.CuDeviceArray ) = Base. Experimental. Const (a)
0 commit comments