Skip to content

Fold grid.y/z into permute cap_grid_dim_x to fix HIP 2^32 overflow - #6082

Closed
q10 wants to merge 1 commit into
pytorch:mainfrom
q10:export-D113884728
Closed

Fold grid.y/z into permute cap_grid_dim_x to fix HIP 2^32 overflow#6082
q10 wants to merge 1 commit into
pytorch:mainfrom
q10:export-D113884728

Conversation

@q10

@q10 q10 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary:
The permute embedding kernel launches cap grid.x via cap_grid_dim_x but
passed only the per-block thread count (kMaxThreads) as the threshold
argument, omitting the y/z batch dimensions. cap_grid_dim_x bounds the
total launch and requires all other launch dims folded into that
argument, so with a large batch the launch still exceeded HIP's 2^32
thread-per-launch limit even though grid.x alone fit, tripping
KernelLauncher::checkThreadCountNotExceeded on ROCm. The kernel-side
grid-stride + repro tests already landed (D105353645, D105354406,
D105355306) but these host call sites under-counted.

Fold block-threads * grid.y * grid.z into the cap so grid.x is clamped
against the full launch; the kernels already grid-stride over their
saturating dimension so a clamped grid.x still covers all work. Fixed at
all three host launch sites:

  • permute_multi_embedding_ops.cu (permute_multi_embs_kernel)
  • permute_pooled_embedding_ops.cu (permute_pooled_embs_kernel)
  • permute_pooled_embedding_ops_split.cu (split frontend)

Differential Revision: D113884728

@meta-cla meta-cla Bot added the cla signed label Jul 28, 2026
@meta-codesync

meta-codesync Bot commented Jul 28, 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 D113884728.

Summary:
The permute embedding kernel launches cap grid.x via cap_grid_dim_x but
passed only the per-block thread count (kMaxThreads) as the threshold
argument, omitting the y/z batch dimensions. cap_grid_dim_x bounds the
*total* launch and requires all other launch dims folded into that
argument, so with a large batch the launch still exceeded HIP's 2^32
thread-per-launch limit even though grid.x alone fit, tripping
KernelLauncher::checkThreadCountNotExceeded on ROCm. The kernel-side
grid-stride + repro tests already landed (D105353645, D105354406,
D105355306) but these host call sites under-counted.

Fold block-threads * grid.y * grid.z into the cap so grid.x is clamped
against the full launch; the kernels already grid-stride over their
saturating dimension so a clamped grid.x still covers all work. Fixed at
all three host launch sites:
- permute_multi_embedding_ops.cu (permute_multi_embs_kernel)
- permute_pooled_embedding_ops.cu (permute_pooled_embs_kernel)
- permute_pooled_embedding_ops_split.cu (split frontend)

Differential Revision: D113884728
@meta-codesync meta-codesync Bot changed the title Fold grid.y/z into permute_multi_embs cap_grid_dim_x to fix HIP 2^32 overflow Fold grid.y/z into permute cap_grid_dim_x to fix HIP 2^32 overflow Jul 28, 2026
@q10
q10 force-pushed the export-D113884728 branch from e2497f1 to 68c51d0 Compare July 28, 2026 17:41
@meta-codesync meta-codesync Bot closed this in 5fc44e4 Jul 28, 2026
@meta-codesync meta-codesync Bot added the Merged label Jul 28, 2026
@meta-codesync

meta-codesync Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 5fc44e4.

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