Skip to content

Fix @index(Global, Linear) for padded ndranges (2.9 backport) - #738

Merged
michel2323 merged 1 commit into
release-2.9from
fix-global-linear-2.9
Oct 27, 2026
Merged

michel2323 merged 1 commit into
release-2.9from
fix-global-linear-2.9

Conversation

@michel2323

Copy link
Copy Markdown
Member

Backport of the @index(Global, Linear) fix to the 2.9 series, for KernelAbstractions 0.9 / GPUArrays 11 users (fixes #509; main already 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 into ndrange when 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, permutedims and rmul! kernels all use this index, hence x[:, 1:2] on a 513×3 matrix returning zeros, x[:, 2, :, :] on a (64, 4, 500, B) array being wrong for every B ≥ 2, and rmul! 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 reported getindex, permutedims and rmul! 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, :, :] and x[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 the kernelabstractions (2251 pass / 7 broken) and indexing test files pass.

Targets release-2.9 (cut from v2.9.2); a v2.9.3 release follows the merge.

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
michel2323 force-pushed the fix-global-linear-2.9 branch from 37ca0cf to e006c33 Compare October 27, 2026 13:39
@michel2323
michel2323 merged commit 37a8fdf into release-2.9 Oct 27, 2026
4 of 5 checks passed
@michel2323
michel2323 deleted the fix-global-linear-2.9 branch October 27, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant