Skip to content

[Inductor][NVGEMM] Match heuristic tiles per CTA - #198293

Closed
mlazos wants to merge 1 commit into
gh/mlazos/322/basefrom
gh/mlazos/322/head
Closed

mlazos wants to merge 1 commit into
gh/mlazos/322/basefrom
gh/mlazos/322/head

Conversation

@mlazos

@mlazos mlazos commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Human commentary: Fixes a bug where 2-CTA kernels weren't considered.

AI-generated draft:

Issue

Fixes #196313

Summary

nvMatmulHeuristics reports tile M per CTA, while CUTLASS reports a pair-wide M tile for true 2-CTA kernels. Comparing those values directly prevented recommended dense 2-CTA kernels from entering NVGEMM autotuning.

Normalize heuristic-matching keys using the implementation's use_2cta_instrs metadata, with a guarded design-metadata fallback for older kernels. The design flag alone is insufficient because block-scaled operators can set it for 1-CTA kernels. Supplemental configs continue to use raw design coordinates, preserving distinct 128-row and 256-row candidates.

For example, a dense pair-wide (256, 128, 2, 1) design now matches the heuristic's per-CTA (128, 128, 2, 1) recommendation, while a block-scaled 1-CTA (128, 128, 2, 1) design remains unchanged.

Checklist

Tests

The focused source-loaded filtering suite passed 6 tests covering dense 2-CTA normalization, block-scaled 1-CTA preservation, metadata fallback and absence, ordering, and supplemental raw-key collisions.

lintrunner -a --skip PYREFLY torch/_inductor/heuristics/template/nv_universal_gemm.py test/inductor/test_nv_universal_gemm.py passed with no lint issues. Full lintrunner -a exited successfully but emitted unrelated repo-wide Pyrefly diagnostics because the refreshed worktree has no lintrunner initialization and the editable build targets an older checkout.

B300 performance was not available locally; the issue contains the reporter's B300 timings for the same key correction.

BC-breaking?

No. This corrects internal matching of equivalent kernel metadata and preserves existing supplemental-key behavior.

Authored with assistance from an AI coding agent.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

nvMatmulHeuristics reports tile M per CTA, while CUTLASS reports the
pair-wide tile for true 2-CTA kernels. Comparing those values directly
prevented the recommended 2-CTA dense kernels from entering autotuning.

Normalize true pair kernels using the implementation's use_2cta_instrs
metadata, with a guarded design fallback for older kernels. The design flag
alone was not used because block-scaled operators set it for some 1-CTA
kernels. Keep the hand-tuned supplement table in raw design coordinates so
distinct 128- and 256-row candidates remain selectable.

Test Plan:

```
PYTHONDONTWRITEBYTECODE=1 python -c 'import importlib.util,runpy,sys; from pathlib import Path; import torch.utils._triton as t; setattr(t,"has_triton_reduction_ordering",getattr(t,"has_triton_reduction_ordering",lambda: False)); n="torch._inductor.heuristics.template.nv_universal_gemm"; s=importlib.util.spec_from_file_location(n,Path("torch/_inductor/heuristics/template/nv_universal_gemm.py").resolve()); m=importlib.util.module_from_spec(s); sys.modules[n]=m; s.loader.exec_module(m); sys.argv=["test/inductor/test_nv_universal_gemm.py","-k","filter_kernels","-k","supplement_configs"]; runpy.run_path("test/inductor/test_nv_universal_gemm.py",run_name="__main__")'
```

Passed 6 tests. B300 performance validation was not available on the H100 host.

```
lintrunner -a
```

Exited successfully; the uninitialized refreshed worktree emitted unrelated
repo-wide Pyrefly environment diagnostics.

```
lintrunner -a --skip PYREFLY torch/_inductor/heuristics/template/nv_universal_gemm.py test/inductor/test_nv_universal_gemm.py
```

Passed with no lint issues.

Fixes #196313

Authored with assistance from an AI coding agent.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198293

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (2 Unrelated Failures)

As of commit a00a136 with merge base 6a895d1 (image):

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@mlazos

mlazos commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

AI-Review

Automated multi-agent review (architecture, correctness, simplification, generalization, and GPT-5.6 final approval). This is AI-generated — please verify findings manually.


No verified issues found.

@mlazos
mlazos marked this pull request as ready for review September 23, 2026 22:44
@mlazos

mlazos commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 24, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
github-actions Bot deleted the gh/mlazos/322/head branch November 29, 2026 01:50
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.

3 participants