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
8 changes: 4 additions & 4 deletions src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ Allocate a storage array appropriate for the computational backend.
!!! note
Backend implementations **must** implement `allocate(::NewBackend, T, dims::Tuple)`
"""
allocate(backend::Backend, T, dims...) = allocate(backend, T, dims)
allocate(backend::Backend, T, dims::Tuple) = throw(MethodError(allocate, (backend, T, dims)))
allocate(backend::Backend, T::Type, dims...) = allocate(backend, T, dims)
allocate(backend::Backend, T::Type, dims::Tuple) = throw(MethodError(allocate, (backend, T, dims)))

"""
zeros(::Backend, Type, dims...)::AbstractArray

Allocate a storage array appropriate for the computational backend filled with zeros.
"""
zeros(backend::Backend, T, dims...) = zeros(backend, T, dims)
zeros(backend::Backend, T::Type, dims...) = zeros(backend, T, dims)
function zeros(backend::Backend, ::Type{T}, dims::Tuple) where {T}
data = allocate(backend, T, dims...)
fill!(data, zero(T))
Expand All @@ -553,7 +553,7 @@ end

Allocate a storage array appropriate for the computational backend filled with ones.
"""
ones(backend::Backend, T, dims...) = ones(backend, T, dims)
ones(backend::Backend, T::Type, dims...) = ones(backend, T, dims)
function ones(backend::Backend, ::Type{T}, dims::Tuple) where {T}
data = allocate(backend, T, dims)
fill!(data, one(T))
Expand Down
7 changes: 7 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
@test size(KernelAbstractions.zeros(backend, Float32, 0, 9)) == (0, 9)
end

@testset "Malformed allocations" begin
backend = Backend()
@test_throws MethodError KernelAbstractions.zeros(backend, 2, 2)
@test_throws MethodError KernelAbstractions.ones(backend, 2, 2)
@test_throws MethodError KernelAbstractions.allocate(backend, 2, 2)
end

@kernel cpu = false function gpu_return_kernel!(x)
i = @index(Global)
if i ≤ (length(x) ÷ 2)
Expand Down
Loading