Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/pocl/backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,14 @@ Adapt.adapt_storage(::POCLBackend, x::AbstractArray) = isbits(x) ? x : Adapt.ada
Adapt.adapt_storage(::KA.ConstAdaptor, a::POCL.CLDeviceArray) = Base.Experimental.Const(a)


# Initialized

KA.@kernel function init_kernel(arr, f::F, ::Type{T}) where {F, T}
I = KA.@index(Global)
@inbounds arr[I] = f(T)
end
# Copying

KA.@kernel function copy_kernel(A, @Const(B))
I = KA.@index(Global)
@inbounds A[I] = B[I]
end


function KI.zeros(backend::POCLBackend, ::Type{T}, dims::Tuple; kwargs...) where {T}
arr = KI.allocate(backend, T, dims; kwargs...)
kernel = init_kernel(backend)
kernel(arr, zero, T, ndrange = length(arr))
return arr
end
function KI.ones(backend::POCLBackend, ::Type{T}, dims::Tuple; kwargs...) where {T}
arr = KI.allocate(backend, T, dims; kwargs...)
kernel = init_kernel(backend)
kernel(arr, one, T; ndrange = length(arr))
return arr
end

function KI.copyto!(backend::POCLBackend, A, B)
if KI.get_backend(A) == KI.get_backend(B) && KI.get_backend(A) isa POCLBackend
if length(A) != length(B)
Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ end
@test all(==(2.0f0), A)
end

# not part of the shared testsuite: not every back-end supports bits-union arrays
@testset "POCL zeros/ones of bits-union types" begin
for T in (Union{Missing, Bool}, Union{Missing, Int32})
Z = KernelAbstractions.zeros(POCLBackend(), T, 3)
@test eltype(Z) == T
@test all(x -> !ismissing(x) && iszero(x), Z)

O = KernelAbstractions.ones(POCLBackend(), T, 3)
@test eltype(O) == T
@test all(x -> !ismissing(x) && isone(x), O)
end
end

@testset "CPU back-end" begin
Testsuite.testsuite(CPU, "CPU", POCL, Array, POCL.CLDeviceArray)
end
Expand Down
Loading