Skip to content

Add grid-stride + ROCm cap to linearize_cache_indices kernels - #6098

Open
q10 wants to merge 2 commits into
pytorch:mainfrom
q10:export-D113351691
Open

Add grid-stride + ROCm cap to linearize_cache_indices kernels#6098
q10 wants to merge 2 commits into
pytorch:mainfrom
q10:export-D113351691

Conversation

@q10

@q10 q10 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary:
linearize_cache_indices_kernel and linearize_cache_indices_from_row_idx_kernel
launch grid = div_round_up(num_indices, kMaxThreads) with block = kMaxThreads
and process one index per thread with an early-return guard, so on ROCm total
threads ~= num_indices can exceed the HIP 2^32 threads-per-launch limit for very
large index counts.

Cap both launches with utils::cuda::cap_grid_dim_x_from_workload(num_indices,
kMaxThreads, stream) and add a ROCm grid-stride loop over index to both kernels.
No-op on CUDA.

Reviewed By: cthi

Differential Revision: D113351691

@meta-codesync

meta-codesync Bot commented Jul 30, 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 D113351691.

q10 added 2 commits July 30, 2026 14:15
Summary:
lxu_cache_lookup_kernel (the sibling of the already-fixed
direct_mapped_lxu_cache_lookup_kernel) launched grid = div_round_up(N,
kMaxThreads) with block = dim3(kWarpSize, kMaxThreads / kWarpSize) (N =
linear_cache_indices.numel()) and did not grid-stride, so on ROCm total threads
~= N exceeds the HIP 2^32 threads-per-launch limit for large unique-index sets.

Cap the launch with utils::cuda::cap_grid_dim_x_from_workload(N, kMaxThreads,
stream) (mirroring the direct_mapped sibling) and add a ROCm grid-stride loop
over n0 (stride = gridDim.x * blockDim.y * blockDim.x). No-op on CUDA.

Reviewed By: cthi

Differential Revision: D113351696
Summary:
linearize_cache_indices_kernel and linearize_cache_indices_from_row_idx_kernel
launch grid = div_round_up(num_indices, kMaxThreads) with block = kMaxThreads
and process one index per thread with an early-return guard, so on ROCm total
threads ~= num_indices can exceed the HIP 2^32 threads-per-launch limit for very
large index counts.

Cap both launches with utils::cuda::cap_grid_dim_x_from_workload(num_indices,
kMaxThreads, stream) and add a ROCm grid-stride loop over index to both kernels.
No-op on CUDA.

Reviewed By: cthi

Differential Revision: D113351691
@q10
q10 force-pushed the export-D113351691 branch from ef6a09a to b1bb8c8 Compare July 30, 2026 21:15
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