Skip to content

[inductor][NVGEMM] Chain dependent NVFP4 launches into Triton consumers - #197485

Closed
mlazos wants to merge 23 commits into
gh/mlazos/319/basefrom
gh/mlazos/319/head
Closed

mlazos wants to merge 23 commits into
gh/mlazos/319/basefrom
gh/mlazos/319/head

Conversation

@mlazos

@mlazos mlazos commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Human commentary: Adds provider-side PDL for NVGEMM.

AI-assisted content:

Problem

Fixes #198174
Fixes #198175

NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.

Summary

Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.

Architecture

The NVGEMM heuristics module owns the complete shape policy. In "auto" mode it generates PDL-capable operators only for NVFP4 1x16 problems with 0 < M <= 256 and logical N and K in [1024, 65536], excluding the measured regression band 32 < M <= 64 and 2048 < min(N, K) < 4096. "0" disables PDL, while "1" forces it for experiments. The policy receives packed FP4 K from MMKernelInputs and performs the packed-to-logical conversion internally.

The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.

Inside the CuTeDSL provider, an NVGEMM kernel that depends on an earlier launch calls cute.arch.griddepcontrol_wait() before consuming dependency-produced inputs. The producer calls cute.arch.griddepcontrol_launch_dependents() after issuing its output stores, allowing the dependent grid to begin launch setup while those stores drain. A direct Triton consumer launches with launch_pdl and calls tl.extra.cuda.gdc_wait() before reading the producer output, preserving completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.

Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.

Examples

  • An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with launch_pdl and waits through gdc_wait.
  • A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.

Performance

Standard vllm bench latency runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, -O2, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant nvfp4_w4a4 linear backend changed; unrelated linears, attention, and sampling remained matched.

These are cumulative complete-stack results, not isolated attribution to this PR:

  • Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
  • Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
  • Nemotron-Nano-9B-v2 NVFP4 revalidation: Torch/NVGEMM was 4.83% faster at batch 32 (5.59% in the adjacent warmed pair), 6.29% faster at batch 64, and within 0.16% at batch 128, which is treated as parity.
  • A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.

Test Plan

python test/inductor/test_nv_universal_gemm.py -k pdl
lintrunner -a
git diff --check

A focused PDL-chain run passed 11 cases, and the broader heuristic/PDL-metadata run collected 95 cases: 94 passed and 1 skipped. Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.

Checklist

  • Passes lint
  • Added or updated tests
  • Updated documentation where applicable
  • Included benchmark results

BC-breaking?

No. Automatic PDL is shape-scoped; TORCHINDUCTOR_NVGEMM_PDL=0 and =1 remain explicit overrides.

PR prepared with assistance from an AI tool.

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

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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 5468aa4 with merge base ee0d01e (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 18, 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.

[ghstack-poisoned]
@mlazos
mlazos marked this pull request as ready for review September 22, 2026 10:00
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 22, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> Enable shape-selective NVFP4 programmatic dependent launch in generated NVGEMM kernels, specialize generation and artifact caches by logical shape and PDL mode, and propagate selected-provider metadata into direct same-stream Triton consumers. Only real read-after-write dependencies and standalone supported launches participate; combo, workspace, multi-kernel, reduction, cross-stream, and unrelated consumers remain on the ordinary path.

> Examples: a small NVGEMM projection followed directly by a Triton pointwise kernel can overlap launch setup; a workspace-backed or side-stream consumer cannot. Tests cover policy boundaries, generated-kernel wait/release placement, cache identity, CPU-safe choice generation, selected-template metadata, same-stream dependencies, reductions, copies, combo kernels, and workspaces.

> PR prepared with assistance from an AI tool.

ghstack-source-id: 3939c41

Pull-Request: #197485
@mlazos mlazos changed the title [inductor][NVGEMM] Support dependent launch for NVFP4 GEMMs [inductor][NVGEMM] Chain dependent NVFP4 launches into Triton consumers Sep 22, 2026
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 22, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> Enable shape-selective NVFP4 programmatic dependent launch in generated NVGEMM kernels, specialize generation and artifact caches by logical shape and PDL mode, and propagate selected-provider metadata into direct same-stream Triton consumers. Only real read-after-write dependencies and standalone supported launches participate; combo, workspace, multi-kernel, reduction, cross-stream, and unrelated consumers remain on the ordinary path.

> Examples: a small NVGEMM projection followed directly by a Triton pointwise kernel can overlap launch setup; a workspace-backed or side-stream consumer cannot. Tests cover policy boundaries, generated-kernel wait/release placement, cache identity, CPU-safe choice generation, selected-template metadata, same-stream dependencies, reductions, copies, combo kernels, and workspaces.

> PR prepared with assistance from an AI tool.

ghstack-source-id: 5308b3f

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 22, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> Enable shape-selective NVFP4 programmatic dependent launch in generated NVGEMM kernels, specialize generation and artifact caches by logical shape and PDL mode, and propagate selected-provider metadata into direct same-stream Triton consumers. Only real read-after-write dependencies and standalone supported launches participate; combo, workspace, multi-kernel, reduction, cross-stream, and unrelated consumers remain on the ordinary path.

> Examples: a small NVGEMM projection followed directly by a Triton pointwise kernel can overlap launch setup; a workspace-backed or side-stream consumer cannot. Tests cover policy boundaries, generated-kernel wait/release placement, cache identity, CPU-safe choice generation, selected-template metadata, same-stream dependencies, reductions, copies, combo kernels, and workspaces.

> PR prepared with assistance from an AI tool.

ghstack-source-id: cde5281

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 24, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> Enable programmatic dependent launch automatically for the measured NVFP4 decode envelope and carry that decision through generated operators, subprocess precompile, runtime metadata, and artifact caches. The automatic policy covers M up to 256 with both logical widths between 1024 and 65536, while excluding the measured batch-33-to-64 intermediate-width regression band. The existing setting still supports explicit off and force-on modes.

> Propagate the selected producer metadata to direct same-stream Triton consumers. Only real read-after-write dependencies and supported single launches continue the chain; combo kernels, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream work, and unrelated consumers remain on the ordinary path. Tests cover policy boundaries, wait/release placement, logical-shape cache specialization, pointer refresh, same-stream dependencies, reductions, deferred copies, and excluded launch forms.

> PR prepared with assistance from an AI tool.

ghstack-source-id: 328f617

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 24, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> Enable programmatic dependent launch automatically for the measured NVFP4 decode envelope and carry that decision through generated operators, subprocess precompile, runtime metadata, and artifact caches. The automatic policy covers M up to 256 with both logical widths between 1024 and 65536, while excluding the measured batch-33-to-64 intermediate-width regression band. The existing setting still supports explicit off and force-on modes.

> Propagate the selected producer metadata to direct same-stream Triton consumers. Only real read-after-write dependencies and supported single launches continue the chain; combo kernels, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream work, and unrelated consumers remain on the ordinary path. Tests cover policy boundaries, wait/release placement, logical-shape cache specialization, pointer refresh, same-stream dependencies, reductions, deferred copies, and excluded launch forms.

> PR prepared with assistance from an AI tool.

ghstack-source-id: 1260e0c

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 24, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> Enable programmatic dependent launch automatically for the measured NVFP4 decode envelope and carry that decision through generated operators, subprocess precompile, runtime metadata, and artifact caches. The automatic policy covers M up to 256 with both logical widths between 1024 and 65536, while excluding the measured batch-33-to-64 intermediate-width regression band. The existing setting still supports explicit off and force-on modes.

> Propagate the selected producer metadata to direct same-stream Triton consumers. Only real read-after-write dependencies and supported single launches continue the chain; combo kernels, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream work, and unrelated consumers remain on the ordinary path. Tests cover policy boundaries, wait/release placement, logical-shape cache specialization, pointer refresh, same-stream dependencies, reductions, deferred copies, and excluded launch forms.

> PR prepared with assistance from an AI tool.

ghstack-source-id: 36a4635

Pull-Request: #197485
[ghstack-poisoned]
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 25, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: 39e5720

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 25, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: 7bf9087

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 25, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: ddef8f7

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 28, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: 5d92841

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 28, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: 6e045a0

Pull-Request: #197485
@mlazos
mlazos requested a review from karthickai September 29, 2026 01:25
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 29, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: ebb3c59

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Sep 29, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: e48d4ec

Pull-Request: #197485
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Oct 1, 2026
Human commentary: Provider-side dependent launch only helps when the direct consumer participates, so I want one reviewable change that carries the protocol across the complete launch chain.

AI-assisted content:

> ## Problem
>
> Fixes #198174
> Fixes #198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, PDL waits before consuming dependency-produced inputs and releases dependent grids while its output stores drain; the consumer wait prevents dependent reads until completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4: Torch/NVGEMM was 3.81% and 2.04% faster at batches 32 and 64, and nominally 0.46% faster at batch 128, which is treated as parity/a close result.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

ghstack-source-id: 8ea1466

Pull-Request: #197485
@mlazos mlazos added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 2, 2026
@mlazos

mlazos commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@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

cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
…rs (pytorch#197485)

Human commentary: Adds provider-side PDL for NVGEMM.

AI-assisted content:

> ## Problem
>
> Fixes pytorch#198174
> Fixes pytorch#198175
>
> NVGEMM kernels could not participate in CUDA programmatic dependent launch (PDL), so direct Triton consumers waited for ordinary kernel completion instead of overlapping their launch setup with the producer tail.
>
> ## Summary
>
> Add selective PDL for measured NVFP4 decode shapes and connect eligible NVGEMM providers to direct same-stream Triton consumers.
>
> ## Architecture
>
> The NVGEMM heuristics module owns the complete shape policy. In `"auto"` mode it generates PDL-capable operators only for NVFP4 1x16 problems with `0 < M <= 256` and logical `N` and `K` in `[1024, 65536]`, excluding the measured regression band `32 < M <= 64` and `2048 < min(N, K) < 4096`. `"0"` disables PDL, while `"1"` forces it for experiments. The policy receives packed FP4 K from `MMKernelInputs` and performs the packed-to-logical conversion internally.
>
> The selected policy is represented in operator metadata and included in generated-precompile, runtime, and persistent-artifact cache identities. Original logical M is also part of specialization when swap-AB changes the physical orientation.
>
> Inside the CuTeDSL provider, an NVGEMM kernel that depends on an earlier launch calls `cute.arch.griddepcontrol_wait()` before consuming dependency-produced inputs. The producer calls `cute.arch.griddepcontrol_launch_dependents()` after issuing its output stores, allowing the dependent grid to begin launch setup while those stores drain. A direct Triton consumer launches with `launch_pdl` and calls `tl.extra.cuda.gdc_wait()` before reading the producer output, preserving completion and visibility. For measured small-K decode shapes, descriptor and layout setup is moved before the wait so independent prologue work overlaps; other shapes retain the conservative early wait.
>
> Scheduler code generation tracks the previous concrete scheduler node independently per device and stream. A Triton launch opts into PDL only when the immediately preceding same-stream node resolves to a selected PDL-capable NVGEMM and the consumer has a true read-after-write dependency on its output. Composite launches, multi-kernel wrappers, workspaces, unsupported reductions, cross-stream consumers, and unrelated nodes retain ordinary launch behavior.
>
> ## Examples
>
> - An eligible NVFP4 decode projection followed directly on the same stream by a Triton cast or add launches the consumer with `launch_pdl` and waits through `gdc_wait`.
> - A consumer on another stream behind an event, or one separated by an unrelated same-stream kernel, uses ordinary stream/event ordering and receives no PDL launch attribute.
>
> ## Performance
>
> Standard `vllm bench latency` runs on GB200 used 32 input tokens, 128 output tokens, 10 warmups, 30 samples, `-O2`, static compilation/CUDA graphs, dummy weights, and tuned FlashInfer 0.6.18.post1 as control. Only vLLM's per-quant `nvfp4_w4a4` linear backend changed; unrelated linears, attention, and sampling remained matched.
>
> These are cumulative complete-stack results, not isolated attribution to this PR:
>
> - Llama-3.1-8B NVFP4: Torch/NVGEMM was 7.81%, 7.42%, 8.29%, and 7.83% faster than tuned FlashInfer at batches 8, 32, 64, and 128.
> - Qwen3-14B NVFP4: Torch/NVGEMM was 5.15%, 5.67%, 7.87%, and 5.23% faster at batches 8, 32, 64, and 128.
> - Nemotron-Nano-9B-v2 NVFP4 revalidation: Torch/NVGEMM was 4.83% faster at batch 32 (5.59% in the adjacent warmed pair), 6.29% faster at batch 64, and within 0.16% at batch 128, which is treated as parity.
> - A Llama batch-64 PDL ablation improved the midpoint of two PDL medians by 7.27% over the intervening no-PDL run. Forced PDL improved four isolated Nemotron decode GEMMs by 11.1%--13.2%; automatic policy excludes the nearby end-to-end regression band.
>
> ## Test Plan
>
> ```bash
> python test/inductor/test_nv_universal_gemm.py -k pdl
> lintrunner -a
> git diff --check
> ```
>
> A focused PDL-chain run passed 11 cases, and the broader heuristic/PDL-metadata run collected 95 cases: 94 passed and 1 skipped. Tests cover policy boundaries, PDL candidate preference and fallback, provider wait/release placement, logical-shape cache specialization, pointer refresh, direct same-stream dependencies, cross-stream event ordering, reductions, deferred copies, composite launches, multi-kernel wrappers, and workspaces.
>
> ## Checklist
>
> - [x] Passes lint
> - [x] Added or updated tests
> - [x] Updated documentation where applicable
> - [x] Included benchmark results
>
> ## BC-breaking?
>
> No. Automatic PDL is shape-scoped; `TORCHINDUCTOR_NVGEMM_PDL=0` and `=1` remain explicit overrides.
>
> PR prepared with assistance from an AI tool.

Pull Request resolved: pytorch#197485
Approved by: https://github.com/karthickai
ghstack dependencies: pytorch#194649, pytorch#194652, pytorch#194651
@github-actions
github-actions Bot deleted the gh/mlazos/319/head branch December 4, 2026 01:53
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