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
fix(rocm): strided copy kernels refuse arrays of 2^32 elements or more #2184
The ROCm strided (general) copy kernels launch one thread per element with no grid-stride loop: int num_blocks = (size + block_size - 1) / block_size; with block size 256, in src/lib/mlx-cpp/patches-rocm/mlx/backend/rocm/copy/copy_general.hip:77, copy_general_input.hip:123 and copy_general_dynamic.hip:113. HIP rejects a launch whose total thread count (gridDim.x * blockDim.x) reaches 2^32, so any strided copy of 2^32 elements or more aborts with hipLaunchKernel ... failed: invalid configuration argument (hipErrorInvalidConfiguration). int num_blocks would also overflow past 2^31 * 256 elements. copy_contiguous.hip:76-77 instead caps the grid at 65535 blocks and loops.
Reproduced on gfx1151 at main b7116d1 while writing the #2153 test: concatenate of an f16 [131072, 32, 8, 128] zeros array (exactly 2^32 elements) with one more block launched grid {16777216,1,1} x block {256,1,1} (AMD_LOG_LEVEL=3) and failed. The #2153 test works around it by concatenating two 2^31-element halves.
Impact
A paged KV slab past 2^32 elements per side (supported after #2153) can hit this on any op that strided-copies the whole slab. The paged write path writes in place or via a contiguous slice_update copy, so no production path is known to hit it today (not verified exhaustively).
Proposed Fix
Add a grid-stride loop to the three kernels with the grid capped as copy_contiguous does (or use a 2-D grid), and compute block counts in 64-bit. Record it in src/lib/mlx-cpp/patches-rocm/LOCAL_FIXES.md per the fork policy (stays in mlxcelverse, not sent to NripeshN/mlx or ml-explore/mlx).
Acceptance Criteria
A ROCm test concatenates or strided-copies an f16 array of more than 2^32 elements and checks the last elements.
The three kernels no longer compute an uncapped int grid size, and LOCAL_FIXES.md has an entry.
Activity
fix(paged-attention): use 64-bit pool offsets in the fused kernels (#…
fix(rocm): loop the strided copy kernels past the launch grid cap (#2237