Add grid-stride loop and ROCm cap to index_add_2d_with_unique_indices_kernel (#5934)#5934
Closed
q10 wants to merge 1 commit into
Closed
Add grid-stride loop and ROCm cap to index_add_2d_with_unique_indices_kernel (#5934)#5934q10 wants to merge 1 commit into
q10 wants to merge 1 commit into
Conversation
Contributor
|
@q10 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105029511. |
q10
added a commit
to q10/FBGEMM
that referenced
this pull request
Jun 21, 2026
…_kernel (pytorch#5934) Summary: X-link: facebookresearch/FBGEMM#2852 Tier-2 fix for HIP grid-overflow in `sparse_ops/sparse_index_add.cu`. `index_add_2d_with_unique_indices_kernel` previously used `blockIdx.x` directly to index unique indices. Capping the host-side grid without first adding a grid-stride loop would silently drop work. Changes: - Add `const int num_unique_indices` as a new kernel parameter. - Convert kernel to a grid-stride loop over `u = blockIdx.x; u < num_unique_indices; u += gridDim.x` (Pattern C). All `blockIdx.x` references replaced with `u`. Hoist `start_D` and `has_remainder` outside the loop since they depend only on `blockIdx.y` / `threadIdx.x`. - RESET per-iteration register state at the top of each iteration: `sum[MAX_ELEMENTS_PER_THREAD]` re-zeroed and `sum_remainder = 0`. - Apply standard `#ifdef USE_ROCM min(blocks_x_uncapped, get_max_thread_blocks(stream)) #else blocks_x_uncapped #endif` cap to the x-dim of the launch grid. y dim is bounded by D/stride_D and needs no cap. Stacked on top of D105029028 (Tier-2 Diff 5/7). Plan: `/home/bensonma415/.llms/plans/sparse_ops_rocm_grid_overflow_tier2_fix.plan.md` (Diff 6/7). Reviewed By: henrylhtsang Differential Revision: D105029511
…_kernel (pytorch#5934) Summary: X-link: facebookresearch/FBGEMM#2852 Tier-2 fix for HIP grid-overflow in `sparse_ops/sparse_index_add.cu`. `index_add_2d_with_unique_indices_kernel` previously used `blockIdx.x` directly to index unique indices. Capping the host-side grid without first adding a grid-stride loop would silently drop work. Changes: - Add `const int num_unique_indices` as a new kernel parameter. - Convert kernel to a grid-stride loop over `u = blockIdx.x; u < num_unique_indices; u += gridDim.x` (Pattern C). All `blockIdx.x` references replaced with `u`. Hoist `start_D` and `has_remainder` outside the loop since they depend only on `blockIdx.y` / `threadIdx.x`. - RESET per-iteration register state at the top of each iteration: `sum[MAX_ELEMENTS_PER_THREAD]` re-zeroed and `sum_remainder = 0`. - Apply standard `#ifdef USE_ROCM min(blocks_x_uncapped, get_max_thread_blocks(stream)) #else blocks_x_uncapped #endif` cap to the x-dim of the launch grid. y dim is bounded by D/stride_D and needs no cap. Stacked on top of D105029028 (Tier-2 Diff 5/7). Plan: `/home/bensonma415/.llms/plans/sparse_ops_rocm_grid_overflow_tier2_fix.plan.md` (Diff 6/7). Reviewed By: henrylhtsang Differential Revision: D105029511
Contributor
|
This pull request has been merged in fa211b0. |
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.
Summary:
X-link: https://github.com/facebookresearch/FBGEMM/pull/2852
Tier-2 fix for HIP grid-overflow in
sparse_ops/sparse_index_add.cu.index_add_2d_with_unique_indices_kernelpreviously usedblockIdx.xdirectly to index unique indices. Capping the host-side grid without first adding a grid-stride loop would silently drop work.Changes:
const int num_unique_indicesas a new kernel parameter.u = blockIdx.x; u < num_unique_indices; u += gridDim.x(Pattern C). AllblockIdx.xreferences replaced withu. Hoiststart_Dandhas_remainderoutside the loop since they depend only onblockIdx.y/threadIdx.x.sum[MAX_ELEMENTS_PER_THREAD]re-zeroed andsum_remainder = 0.#ifdef USE_ROCM min(blocks_x_uncapped, get_max_thread_blocks(stream)) #else blocks_x_uncapped #endifcap to the x-dim of the launch grid. y dim is bounded by D/stride_D and needs no cap.Stacked on top of D105029028 (Tier-2 Diff 5/7). Plan:
/home/bensonma415/.llms/plans/sparse_ops_rocm_grid_overflow_tier2_fix.plan.md(Diff 6/7).Reviewed By: henrylhtsang
Differential Revision: D105029511