@@ -13,7 +13,7 @@ using GPUArrays
1313using Adapt
1414
1515import KernelAbstractions
16- import KernelAbstractions: Adapt, StaticArrays, Backend, Kernel, StaticSize, DynamicSize, partition, blocks, workitems, launch_config
16+ import KernelAbstractions: Adapt, StaticArrays, Backend, Kernel, StaticSize, DynamicSize, partition, blocks, workitems, launch_config, POCL
1717
1818
1919#
@@ -41,27 +41,6 @@ Adapt.adapt_structure(to::Adaptor, r::Base.RefValue) = JlRefValue(adapt(to, r[])
4141
4242# array type
4343
44- struct JLDeviceArray{T, N} <: AbstractDeviceArray{T, N}
45- data:: Vector{UInt8}
46- offset:: Int
47- dims:: Dims{N}
48- end
49-
50- Base. elsize (:: Type{<:JLDeviceArray{T}} ) where {T} = sizeof (T)
51-
52- Base. size (x:: JLDeviceArray ) = x. dims
53- Base. sizeof (x:: JLDeviceArray ) = Base. elsize (x) * length (x)
54-
55- Base. unsafe_convert (:: Type{Ptr{T}} , x:: JLDeviceArray{T} ) where {T} =
56- convert (Ptr{T}, pointer (x. data)) + x. offset* Base. elsize (x)
57-
58- # conversion of untyped data to a typed Array
59- function typed_data (x:: JLDeviceArray{T} ) where {T}
60- unsafe_wrap (Array, pointer (x), x. dims)
61- end
62-
63- @inline Base. getindex (A:: JLDeviceArray , index:: Integer ) = getindex (typed_data (A), index)
64- @inline Base. setindex! (A:: JLDeviceArray , x, index:: Integer ) = setindex! (typed_data (A), x, index)
6544
6645
6746#
335314
336315# # GPUArrays interfaces
337316
338- Adapt. adapt_storage (:: Adaptor , x:: JLArray{T,N} ) where {T,N} =
339- JLDeviceArray {T,N} (x. data[], x. offset, x. dims)
317+ function Adapt. adapt_storage (:: Adaptor , x:: JLArray{T,N} ) where {T,N}
318+ arr = typed_data (x)
319+ Adapt. adapt_storage (POCL. KernelAdaptor ([pointer (arr)]), arr)
320+ end
340321
341322function GPUArrays. mapreducedim! (f, op, R:: AnyJLArray , A:: Union{AbstractArray,Broadcast.Broadcasted} ;
342323 init= nothing )
@@ -377,10 +358,8 @@ KernelAbstractions.allocate(::JLBackend, ::Type{T}, dims::Tuple) where T = JLArr
377358 return ndrange, workgroupsize, iterspace, dynamic
378359end
379360
380- KernelAbstractions. isgpu (b:: JLBackend ) = false
381-
382361function convert_to_cpu (obj:: Kernel{JLBackend, W, N, F} ) where {W, N, F}
383- return Kernel {typeof(KernelAbstractions.CPU(; static = obj.backend.static )), W, N, F} (KernelAbstractions. CPU (; static = obj . backend . static ), obj. f)
362+ return Kernel {typeof(KernelAbstractions.POCLBackend( )), W, N, F} (KernelAbstractions. POCLBackend ( ), obj. f)
384363end
385364
386365function (obj:: Kernel{JLBackend} )(args... ; ndrange= nothing , workgroupsize= nothing )
391370
392371Adapt. adapt_storage (:: JLBackend , a:: Array ) = Adapt. adapt (JLArrays. JLArray, a)
393372Adapt. adapt_storage (:: JLBackend , a:: JLArrays.JLArray ) = a
394- Adapt. adapt_storage (:: KernelAbstractions.CPU , a:: JLArrays.JLArray ) = convert (Array, a)
373+ Adapt. adapt_storage (:: KernelAbstractions.POCLBackend , a:: JLArrays.JLArray ) = convert (Array, a)
395374
396375end
0 commit comments