You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KernelInterface: describe grid limits that bound work-items, not work-groups #882
KI.max_num_groups(backend) is the maximum number of work-groups per dimension, and has to hold for any work-group size. That matches CUDA, which limits the number of blocks per dimension ((2³¹−1, 65535, 65535)), but not back ends that limit the number of work-items per grid dimension:
Metal: groups * threads ≤ 2³²−1 per dimension. It reports typemax(UInt32) ÷ max_threadgroup_dims, i.e. ~4.2M groups on an M1, where 256-wide groups could have ~16.7M.
KA only uses this in select_launch (src/launch.jl), to choose between NDLaunch and LinearLaunch, so the underestimate never rejects a launch; the back end's check at launch stays authoritative. It does push very large 2-D/3-D grids to the linearized launch, which costs index divisions, and KI users get a misleading limit.
Proposal (additive, can go in a KI 0.4.x):
add KI.max_grid_size(backend)::NTuple{3, Int}, the maximum number of work-items per dimension, defaulting to typemax(Int)s;
back ends report their actual limits in both queries (Metal: max_num_groups = typemax(UInt32), max_grid_size = typemax(UInt32));
Caveat: with a tuned work-group size, select_launch picks the launch type before the size is known, and assumes one work-item per group. That stays conservative unless tuning moves earlier.
Activity