diff --git a/src/cpu.jl b/src/cpu.jl index c4afec5c..bae45a3a 100644 --- a/src/cpu.jl +++ b/src/cpu.jl @@ -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) diff --git a/test/test.jl b/test/test.jl index 7269c297..c77d1f1c 100644 --- a/test/test.jl +++ b/test/test.jl @@ -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