Repository navigation
fix(rocm): clamp the remaining element-count HIP launch grids - #2309
Merged
Merged
Conversation
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
force-pushed
the
fix/issue-2234-hip-grid-clamp
branch
from
October 14, 2026 04:06
e268a38 to
28989f6
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.
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