diff --git a/lib/KernelInterface/Project.toml b/lib/KernelInterface/Project.toml index 45450fc57..3b7847df1 100644 --- a/lib/KernelInterface/Project.toml +++ b/lib/KernelInterface/Project.toml @@ -1,7 +1,7 @@ name = "KernelInterface" uuid = "4ee993da-d684-4d17-a7dd-4e58e78d92bf" authors = ["Valentin Churavy and contributors"] -version = "0.4.3" +version = "0.4.4" [compat] julia = "1.10" diff --git a/lib/KernelInterface/src/launch.jl b/lib/KernelInterface/src/launch.jl index 568affccb..86e4babd2 100644 --- a/lib/KernelInterface/src/launch.jl +++ b/lib/KernelInterface/src/launch.jl @@ -126,12 +126,13 @@ end return p end -# whether the product of positive `dims` exceeds `limit`, without overflowing +# whether the product of positive `dims` exceeds `limit`, without overflow or division +# (this runs on every launch, and a division costs tens of cycles on some CPUs) @inline function prod_exceeds(dims::Dims, limit::Int) p = 1 for d in dims - d > limit ÷ p && return true - p *= d + p, overflow = Base.mul_with_overflow(p, d) + (overflow || p > limit) && return true end return false end @@ -206,9 +207,10 @@ Not part of the public interface; used by KernelInterface's and KernelAbstractio code. """ @inline function check_work_group_size(kernel::Kernel, items::Dims{3}) - check_work_group_dims(kernel.backend, items) + # check the total first: linearized launches put all work-items in the first dimension max_items = max_work_group_size(kernel) prod_exceeds(items, max_items) && throw_work_group_size_error(items, max_items) + check_work_group_dims(kernel.backend, items) return end diff --git a/test/runtests.jl b/test/runtests.jl index 6f18d7481..3c1323643 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -926,6 +926,10 @@ end # workgroup sizes are validated against the kernel's limits limit = KernelAbstractions.KI.max_work_group_size(CPU()) @test_throws ArgumentError fill_index!(CPU())(zeros(Int, 2limit); ndrange = 2limit, workgroupsize = 2limit) + # report the total-size limit even when linearization puts all work-items in the + # first dimension + n = limit ÷ 64 + 1 + @test_throws "work-items" fill_index!(CPU(), (64, n))(zeros(Int, 128n); ndrange = (64, n, 2)) # iteration spaces with more work-items than an `Int` can count are rejected, instead # of launching nothing because the number of workgroups overflowed