Skip to content

Add grid-stride + ROCm cap to generate_vbe_metadata kernel - #6108

Open
q10 wants to merge 1 commit into
pytorch:mainfrom
q10:export-D113351683
Open

Add grid-stride + ROCm cap to generate_vbe_metadata kernel#6108
q10 wants to merge 1 commit into
pytorch:mainfrom
q10:export-D113351683

Conversation

@q10

@q10 q10 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary:
generate_vbe_metadata_foreach_sample_kernel launches a 3-D grid
dim3(div_round_up(max_B_feature_rank, kMaxThreads), num_ranks, T) with
block = kMaxThreads, so total threads ~= max_B_feature_rank * num_ranks * T
exceeds the HIP 2^32 threads-per-launch limit on ROCm once num_ranks * T is
large (the existing TORCH_CHECK only guarded grid.x <= maxGridSize, not the
2^32 total-thread product).

Cap grid.x with utils::cuda::cap_grid_dim_x, factoring grid.y (num_ranks) and
grid.z (T) into the per-x-block thread count (kMaxThreads * num_ranks * T) for
the overflow check, and add a ROCm grid-stride loop over b. No-op on CUDA.
Added the cuda_utilities.cuh include.

Reviewed By: henrylhtsang

Differential Revision: D113351683

Summary:
generate_vbe_metadata_foreach_sample_kernel launches a 3-D grid
dim3(div_round_up(max_B_feature_rank, kMaxThreads), num_ranks, T) with
block = kMaxThreads, so total threads ~= max_B_feature_rank * num_ranks * T
exceeds the HIP 2^32 threads-per-launch limit on ROCm once num_ranks * T is
large (the existing TORCH_CHECK only guarded grid.x <= maxGridSize, not the
2^32 total-thread product).

Cap grid.x with utils::cuda::cap_grid_dim_x, factoring grid.y (num_ranks) and
grid.z (T) into the per-x-block thread count (kMaxThreads * num_ranks * T) for
the overflow check, and add a ROCm grid-stride loop over b. No-op on CUDA.
Added the cuda_utilities.cuh include.

Reviewed By: henrylhtsang

Differential Revision: D113351683
@meta-codesync

meta-codesync Bot commented Aug 4, 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 D113351683.

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