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 @@ -525,15 +525,15 @@
!!! 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)))

Check warning on line 529 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L528-L529

Added lines #L528 - L529 were not covered by tests

"""
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)

Check warning on line 536 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L536

Added line #L536 was not covered by tests
function zeros(backend::Backend, ::Type{T}, dims::Tuple) where {T}
data = allocate(backend, T, dims...)
fill!(data, zero(T))
Expand All @@ -545,7 +545,7 @@

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)

Check warning on line 548 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L548

Added line #L548 was not covered by tests
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 @@ -280,6 +280,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