Skip to content

Commit

Permalink
Fix zeros erroring on an empty shape (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
nick4f42 authored Aug 27, 2024
1 parent 05a3c05 commit 5f99533
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ end
const CPU_GRAINSIZE = 1024 # Vectorization, 4x unrolling, minimal grain size
function default_cpu_workgroupsize(ndrange)
# if the total kernel is small, don't launch multiple tasks
if prod(ndrange) <= CPU_GRAINSIZE
n = prod(ndrange)
if iszero(n)
# If the ndrange is zero return a workgroupsize of (1, 1,...)
return map(one, ndrange)
elseif n <= CPU_GRAINSIZE
return ndrange
else
available = Ref(CPU_GRAINSIZE)
Expand Down
10 changes: 10 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,14 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
@test KernelAbstractions.default_cpu_workgroupsize((5, 7, 13, 17)) == (5, 7, 13, 2)
end

@testset "empty arrays" begin
backend = Backend()
@test size(allocate(backend, Float32, 0)) == (0,)
@test size(allocate(backend, Float32, 3, 0)) == (3, 0)
@test size(allocate(backend, Float32, 0, 9)) == (0, 9)
@test size(KernelAbstractions.zeros(backend, Float32, 0)) == (0,)
@test size(KernelAbstractions.zeros(backend, Float32, 3, 0)) == (3, 0)
@test size(KernelAbstractions.zeros(backend, Float32, 0, 9)) == (0, 9)
end

end

0 comments on commit 5f99533

Please sign in to comment.