Skip to content

fix(rocm): strided copy kernels refuse arrays of 2^32 elements or more #2184

Closed

Description

@inureyes

Problem

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.

Related: #2153

Activity

  1. added
    type:bug
    priority:low
    status:ready
    area:core
    on Oct 6, 2026
  2. added
    status:in-progress
    status:done
    and removed
    status:ready
    status:in-progress
    on Oct 8, 2026
  3. added a commit that references this issue on Oct 8, 2026
    a18d3d7
  4. added this to the 0.8 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corepriority:lowstatus:donetype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions