Skip to content

Add grid-stride + ROCm cap to ssd_generate/update_row_addrs kernels - #6102

Closed
q10 wants to merge 2 commits into
pytorch:mainfrom
q10:export-D113351690
Closed

Add grid-stride + ROCm cap to ssd_generate/update_row_addrs kernels#6102
q10 wants to merge 2 commits into
pytorch:mainfrom
q10:export-D113351690

Conversation

@q10

@q10 q10 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary:
ssd_generate_row_addrs_kernel and ssd_update_row_addrs_kernel launch
grid = div_round_up(numel, kNumWarps) with block = dim3(kWarpSize, kNumWarps),
so total threads ~= numel * kWarpSize exceeds the HIP 2^32 threads-per-launch
limit on ROCm for large lxu_cache_locations / ssd_row_addrs counts.

Cap both launches with utils::cuda::cap_grid_dim_x(..., OverflowOnly) and add a
ROCm grid-stride loop over the warp index (n / n_curr). In the update kernel the
"row not used in both iterations" early-return (n_next < 0) becomes continue
under ROCm. Added the cuda_utilities.cuh include. No-op on CUDA.

Reviewed By: henrylhtsang

Differential Revision: D113351690

q10 added 2 commits August 1, 2026 18:02
…nels

Summary:
linearize_index_kernel and linearize_index_index_select_kernel launch
grid = div_round_up(total_B, kMaxThreads) with block = kMaxThreads
(total_B = B * T), so on ROCm total threads can exceed the HIP 2^32
threads-per-launch limit for very large total_B.

Both kernels are warp-collective (shfl_sync across all lanes), so a naive
grid-stride would desync the shuffles. Cap both launches with
utils::cuda::cap_grid_dim_x_from_workload(total_B, kMaxThreads, stream) and add
a WARP-ALIGNED grid-stride loop whose bound uses (b_t - lane_id) so whole warps
iterate together and every shfl_sync still has all lanes present. Per-lane
`valid` / `t < T` masking is unchanged.

The grid-stride loop is unconditional rather than #ifdef USE_ROCM. On CUDA the
grid already spans the workload, so the body executes exactly once per thread
and the kernel is behaviorally unchanged; keeping a single code path avoids
braces that straddle a preprocessor conditional, and keeps CUDA correct if the
grid is ever clamped.

Loop bounds are compared in 64 bits (no uint32 narrowing), and
transpose_embedding_input now TORCH_CHECKs that total_B fits in int32_t: b_t is
a 32-bit thread index handed to FixedDivisor::DivMod(int32_t), so an oversized
workload fails loudly instead of silently wrapping the grid-stride index.

NOTE: warp-collective transform -- validate carefully on MI300 in the per-diff
pass (shfl correctness under the strided loop).

Reviewed By: henrylhtsang

Differential Revision: D113351688
Summary:
ssd_generate_row_addrs_kernel and ssd_update_row_addrs_kernel launch
grid = div_round_up(numel, kNumWarps) with block = dim3(kWarpSize, kNumWarps),
so total threads ~= numel * kWarpSize exceeds the HIP 2^32 threads-per-launch
limit on ROCm for large lxu_cache_locations / ssd_row_addrs counts.

Cap both launches with utils::cuda::cap_grid_dim_x(..., OverflowOnly) and add a
ROCm grid-stride loop over the warp index (n / n_curr). In the update kernel the
"row not used in both iterations" early-return (n_next < 0) becomes `continue`
under ROCm. Added the cuda_utilities.cuh include. No-op on CUDA.

Reviewed By: henrylhtsang

Differential Revision: D113351690
@meta-codesync

meta-codesync Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

@q10 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D113351690.

@meta-codesync

meta-codesync Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in f6c66ba.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant