Skip to content

Commit 5f99533

Browse files
authored
Fix zeros erroring on an empty shape (#515)
1 parent 05a3c05 commit 5f99533

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/cpu.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ end
4949
const CPU_GRAINSIZE = 1024 # Vectorization, 4x unrolling, minimal grain size
5050
function default_cpu_workgroupsize(ndrange)
5151
# if the total kernel is small, don't launch multiple tasks
52-
if prod(ndrange) <= CPU_GRAINSIZE
52+
n = prod(ndrange)
53+
if iszero(n)
54+
# If the ndrange is zero return a workgroupsize of (1, 1,...)
55+
return map(one, ndrange)
56+
elseif n <= CPU_GRAINSIZE
5357
return ndrange
5458
else
5559
available = Ref(CPU_GRAINSIZE)

test/test.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,14 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
296296
@test KernelAbstractions.default_cpu_workgroupsize((5, 7, 13, 17)) == (5, 7, 13, 2)
297297
end
298298

299+
@testset "empty arrays" begin
300+
backend = Backend()
301+
@test size(allocate(backend, Float32, 0)) == (0,)
302+
@test size(allocate(backend, Float32, 3, 0)) == (3, 0)
303+
@test size(allocate(backend, Float32, 0, 9)) == (0, 9)
304+
@test size(KernelAbstractions.zeros(backend, Float32, 0)) == (0,)
305+
@test size(KernelAbstractions.zeros(backend, Float32, 3, 0)) == (3, 0)
306+
@test size(KernelAbstractions.zeros(backend, Float32, 0, 9)) == (0, 9)
307+
end
308+
299309
end

0 commit comments

Comments
 (0)