Repository navigation
Fix @index(Global, Linear) for padded ndranges (2.9 backport) - #738
Merged
Merged
Conversation
michel2323
force-pushed
the
fix-global-linear-2.9
branch
2 times, most recently
from
October 23, 2026 16:47
476b1b3 to
37ca0cf
Compare
The KernelAbstractions back-end returned the hardware global id for `@index(Global, Linear)`. That only equals the linear index into `ndrange` when the work-group size divides every dimension of it; otherwise KernelAbstractions pads the range and kernels skip elements and write out of bounds. GPUArrays' `getindex`, `permutedims` and `rmul!` kernels all rely on this index, so e.g. `x[:, 1:2]` on a 513x3 matrix returned zeros, `x[:, 2, :, :]` on a (64, 4, 500, B) array was wrong for every B >= 2, and `rmul!` on a (64, 1000, 16) ComplexF32 array page-faulted. Map the id through the iteration space instead, as the CPU back-end and CUDA.jl do, and add regression tests for padded N-d ranges with automatic and explicit work-group sizes plus the reported `getindex`, `permutedims` and `rmul!` cases. Backport to the 2.9 series (KernelAbstractions 0.9 / GPUArrays 11); main gets this through the KernelInterface back-end (#653). Analysis and patch by Wilkie Olin-Ammentorp (@wilkieolin). Fixes #509 Co-authored-by: Wilkie Olin-Ammentorp <10157823+wilkieolin@users.noreply.github.com>
michel2323
force-pushed
the
fix-global-linear-2.9
branch
from
October 27, 2026 13:39
37ca0cf to
e006c33
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of the
@index(Global, Linear)fix to the 2.9 series, for KernelAbstractions 0.9 / GPUArrays 11 users (fixes #509;mainalready has the correct semantics through the KernelInterface back-end, #653).The KernelAbstractions back-end returned the hardware global id for
@index(Global, Linear). That only equals the linear index intondrangewhen the work-group size divides every dimension of it; otherwise KernelAbstractions pads the range, so kernels skipped elements and wrote out of bounds. GPUArrays'getindex,permutedimsandrmul!kernels all use this index, hencex[:, 1:2]on a 513×3 matrix returning zeros,x[:, 2, :, :]on a(64, 4, 500, B)array being wrong for everyB ≥ 2, andrmul!on a(64, 1000, 16)ComplexF32 array page-faulting (all reported in #509).The fix maps the id through the iteration space, as the CPU back-end and CUDA.jl do. Regression tests cover padded 1-D to 4-D ranges with automatic and explicit work-group sizes (direct comparison against
LinearIndices), plus the reportedgetindex,permutedimsandrmul!cases.Analysis and patch by @wilkieolin.
Verified on Aurora (PVC, NEO 25.18 LTS, Julia 1.12.7, GPUArrays 11.5.16, KernelAbstractions 0.9.45): on v2.9.2 the reported cases reproduce (
x[:, 2, :, :]andx[2, :, :, :]wrong with ~1500 device-side out-of-bounds messages,rmul!page-faults and bans the context, and the direct@index(Global, Linear)check page-faults as well); with this change the new testset passes (24/24) and thekernelabstractions(2251 pass / 7 broken) andindexingtest files pass.Targets
release-2.9(cut from v2.9.2); av2.9.3release follows the merge.