Skip to content

fix(rocm): clamp the remaining element-count HIP launch grids - #2309

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-2234-hip-grid-clamp
Oct 14, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-2234-hip-grid-clamp

Conversation

@inureyes

Copy link
Copy Markdown
Member

fix(rocm): clamp the remaining element-count HIP launch grids

The remaining HIP launchers that size a grid from the element or group count computed an uncapped int block count and ran one index per thread. HIP refuses a launch of 2^32 threads or more with hipErrorInvalidConfiguration, grid dimensions y and z top out at 65535 blocks, and int num_blocks overflows earlier, so every op that large failed; the elementwise row grid and the transpose tile grid failed outright past 65535 blocks of grid y.

Each launcher now computes its block count with rocm::copy_grid_blocks (64-bit, clamped to [1, 65535], the item 42 helpers in copy/copy.hpp) and each kernel walks its elements with a grid-stride loop over an int64_t counter. unary_g and ternary_g stride their rows on a 64-bit counter past the y cap and copy_col_row caps its 2-D tile grid at the launch limit with 64-bit tile indices. col_reduce_small also advanced its function-parameter pointers inside the loop, so past the cap the advances compounded and the kernel read and wrote out of bounds; they are now per-iteration locals. The change also repairs a stray extra closing brace in indexing.hip that split the namespaces and failed the build.

Reproduction: tests/rocm_hip_grid_clamp.rs runs each launcher family at a size past the 65535-block cap and compares every element with a host reference, 13 tests in total: 9 fast (68.8M elementwise elements at 67200 y-blocks, 21.3M gather and 16.8M scatter elements, 67.1M column-reduce outputs, 2^24 + 1 arange, argsort and transpose-copy elements) plus 4 #[ignore]d tests past 2^32 elements (8 GiB f16 elementwise, about 10.9 GiB gather) that failed in try_eval with hipErrorInvalidConfiguration before the fix. On this branch all 9 fast tests pass in 1.9 s; without the overlay changes the row-grid, tile-grid and col-reduce tests fail outright and the 2^32 tests abort the launch. LOCAL_FIXES.md item 46 records the change.

Closes #2234

The remaining HIP launchers that size a grid from the element or group count computed an uncapped int block count and ran one index per thread. HIP refuses a launch of 2^32 threads or more with hipErrorInvalidConfiguration, grid dimensions y and z top out at 65535 blocks, and int num_blocks overflows earlier, so every op that large failed; the elementwise row grid and the transpose tile grid failed outright past 65535 blocks of grid y.

Each launcher now computes its block count with rocm::copy_grid_blocks (64-bit, clamped to [1, 65535], the item 42 helpers in copy/copy.hpp) and each kernel walks its elements with a grid-stride loop over an int64_t counter that also widens the group and byte indexing. unary_g and ternary_g keep one output row per pass and stride the rows on a 64-bit counter past the y cap, and copy_col_row caps its 2-D tile grid at the launch limit with 64-bit tile indices. col_reduce_small also advanced its function-parameter pointers inside the loop, so past the cap the advances compounded across iterations and the kernel read and wrote out of bounds; they are now per-iteration locals relative to the launch bases. Also fixes a stray extra closing brace the indexing.hip rewrite introduced after scatter_general_kernel, which split the namespaces and failed the build.

tests/rocm_hip_grid_clamp.rs runs each family at a size past the 65535-block cap and compares every element with a host reference (68.8M elements for the elementwise ops, 21.3M for the gather, 16.8M for the scatter, 67.1M for the column reduce, 2^24 + 1 for arange, argsort and the transpose copy), plus #[ignore]d tests past 2^32 elements (8 GiB f16 elementwise, ~10.9 GiB gather). LOCAL_FIXES.md item 46 records the change.

Refs #2234
@inureyes
inureyes force-pushed the fix/issue-2234-hip-grid-clamp branch from e268a38 to 28989f6 Compare October 14, 2026 04:06
@inureyes
inureyes merged commit f8ff6db into main Oct 14, 2026
26 of 27 checks passed
@inureyes
inureyes deleted the fix/issue-2234-hip-grid-clamp branch October 14, 2026 04:09
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.

fix(rocm): other HIP launchers size an uncapped int grid from the element count

1 participant