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
2 changes: 1 addition & 1 deletion lib/KernelInterface/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KernelInterface"
uuid = "4ee993da-d684-4d17-a7dd-4e58e78d92bf"
authors = ["Valentin Churavy <v.churavy@gmail.com> and contributors"]
version = "0.4.3"
version = "0.4.4"

[compat]
julia = "1.10"
10 changes: 6 additions & 4 deletions lib/KernelInterface/src/launch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading