-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[TRTLLM-6898][feat] Add swapab, tileN64, cga sync support for cute dsl nvfp4 gemm #7764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TRTLLM-6898][feat] Add swapab, tileN64, cga sync support for cute dsl nvfp4 gemm #7764
Conversation
Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
|
/bot run |
|
PR_Github #18773 [ run ] triggered by Bot |
📝 WalkthroughWalkthroughIntroduces AB-swap awareness in tactic generation, kernel caching, and launch for NVFP4 GEMM; adds Blackwell-specific pipeline abstractions (TMA↔UMMA, UMMA↔Async); extends GEMM kernel to support 64-wide N tilers and exposes swap_ab in kernel entry points; updates docstrings; augments tests with a performance benchmark and centralizes pad_up. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant TorchOp as Torch Custom Op
participant Tactics as Tactic Generator
participant Cache as Kernel Cache
participant Kernel as Compiled GEMM
Caller->>TorchOp: cute_dsl_nvfp4_gemm_blackwell(A,B,SF_A,SF_B, swap_ab?)
TorchOp->>Tactics: enumerate(mma_tiler_mn × cluster_shape_mn × swap_ab)
Tactics-->>TorchOp: valid tactics (incl. swap_ab)
TorchOp->>Cache: lookup(key: mma, cluster, swap_ab, ...)
alt cache miss
TorchOp->>Kernel: compile with params (incl. swap_ab)
Kernel-->>Cache: store compiled kernel
end
opt swap_ab == True
Note over TorchOp: swap A/B pointers, M/N dims, SF dims
end
TorchOp->>Kernel: launch(A*,B*,SF_A*,SF_B*, M,N,SF_M,SF_N)
Kernel-->>TorchOp: C_out
opt swap_ab == True
TorchOp->>TorchOp: permute C_out to original orientation
end
TorchOp-->>Caller: C_out
sequenceDiagram
autonumber
participant TMA as TMA Producer
participant UMMA as UMMA Consumer
participant Barrier as Pipeline Sync
Note over TMA,UMMA: PipelineTmaUmma (multi-CTA optional)
rect rgba(230,245,255,0.5)
Note over Barrier: pipeline_init_wait
end
par Stage loop
TMA->>Barrier: producer_acquire (wait empty, signal full if leader)
UMMA->>Barrier: consumer_release (signal empty after consume)
end
sequenceDiagram
autonumber
participant UMMA as UMMA Producer
participant Async as AsyncThread Consumer
participant Barrier as Pipeline Sync
Note over UMMA,Async: PipelineUmmaAsync (2-CTA optional)
UMMA->>Barrier: producer_commit (signal full with mask)
Async-->>UMMA: consumes buffers (peer CTA if configured)
UMMA->>UMMA: producer_tail (advance to last useful, acquire if leader)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (11)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/utils.py (1)
160-172: Fix example import mismatch in docstringThe example imports Float32 directly but later uses cutlass.Float32. Make them consistent to avoid confusing users.
Apply this docstring-only tweak:
- from cutlass import Float32 + import cutlass ... - y = make_ptr(cutlass.Float32, ptr_address) + y = make_ptr(cutlass.Float32, ptr_address)tests/unittest/_torch/thop/parallel/test_fp4_linear.py (4)
316-317: Remove f-string without placeholdersPlain string is sufficient.
- print(f"PASSED") + print("PASSED")
336-346: Rename unused loop variableAvoid B007 warning: variable is unused.
- for i in range(iterations): + for _ in range(iterations):
349-350: Remove f-string without placeholdersSame as above.
- print(f"PASSED") + print("PASSED")
368-377: Rename unused loop variableMirror earlier nit.
- for i in range(iterations): + for _ in range(iterations):tensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.py (4)
21-26: Unused parameter in helpercta_layout_vmnk isn’t used; rename to _cta_layout_vmnk to silence linters or use it.
-def pipeline_init_wait(cta_layout_vmnk: Optional[cute.Layout] = None): +def pipeline_init_wait(_cta_layout_vmnk: Optional[cute.Layout] = None):
121-125: Prefer TypeError for invalid typeInvalid-typed argument should raise TypeError.
- if not isinstance(barrier_storage, cute.Pointer): - raise ValueError( + if not isinstance(barrier_storage, cute.Pointer): + raise TypeError( f"Expected barrier_storage to be a cute.Pointer, but got {type(barrier_storage)}" )
248-252: Prefer TypeError for invalid typeSame as above in PipelineUmmaAsync.create.
- if not isinstance(barrier_storage, cute.Pointer): - raise ValueError( + if not isinstance(barrier_storage, cute.Pointer): + raise TypeError( f"Expected barrier_storage to be a cute.Pointer, but got {type(barrier_storage)}" )
316-320: Rename unused loop variableMinor lint fix.
- for i in range(self.num_stages - 1): + for _ in range(self.num_stages - 1): state.advance()tensorrt_llm/_torch/custom_ops/torch_custom_ops.py (1)
1202-1206: Avoid creating-and-permuting C for swap_abAllocate C directly in (n, m) when swap_ab=True to avoid a non-contiguous view and extra permute pre-launch.
- c_tensor = torch.empty(*(m, n), dtype=self.output_dtype, device="cuda") - - if swap_ab: - c_tensor = c_tensor.permute(1, 0) + if swap_ab: + c_tensor = torch.empty(*(n, m), dtype=self.output_dtype, device="cuda") + else: + c_tensor = torch.empty(*(m, n), dtype=self.output_dtype, device="cuda")tensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py (1)
1758-1759: Style: membership testUse “not in” per Ruff E713.
- if not mma_tiler_mn[1] in [64, 128, 256]: + if mma_tiler_mn[1] not in [64, 128, 256]:
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
tensorrt_llm/_torch/custom_ops/torch_custom_ops.py(4 hunks)tensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.py(1 hunks)tensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py(11 hunks)tensorrt_llm/_torch/cute_dsl_kernels/blackwell/utils.py(2 hunks)tests/unittest/_torch/thop/parallel/test_fp4_linear.py(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use only spaces, no tabs; indent with 4 spaces.
Files:
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/utils.pytensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.pytests/unittest/_torch/thop/parallel/test_fp4_linear.pytensorrt_llm/_torch/custom_ops/torch_custom_ops.pytensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.
Files:
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/utils.pytensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.pytests/unittest/_torch/thop/parallel/test_fp4_linear.pytensorrt_llm/_torch/custom_ops/torch_custom_ops.pytensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).
Files:
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/utils.pytensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.pytests/unittest/_torch/thop/parallel/test_fp4_linear.pytensorrt_llm/_torch/custom_ops/torch_custom_ops.pytensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py
🧬 Code graph analysis (4)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.py (1)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/utils.py (1)
align(125-126)
tests/unittest/_torch/thop/parallel/test_fp4_linear.py (2)
tensorrt_llm/_torch/custom_ops/torch_custom_ops.py (12)
_(272-325)_(401-409)_(487-497)_(666-693)_(726-736)_(810-820)_(910-926)_(1006-1014)_(1047-1058)_(1347-1361)cute_dsl_nvfp4_gemm_blackwell(1318-1343)nvfp4_gemm(458-483)tensorrt_llm/_torch/autotuner.py (1)
autotune(204-215)
tensorrt_llm/_torch/custom_ops/torch_custom_ops.py (1)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py (2)
Sm100BlockScaledPersistentDenseGemmKernel(65-1877)can_implement(1821-1877)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py (1)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.py (4)
PipelineTmaUmma(34-193)PipelineUmmaAsync(197-320)create(94-165)create(227-291)
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.py
21-21: Unused function argument: cta_layout_vmnk
(ARG001)
122-124: Prefer TypeError exception for invalid type
(TRY004)
122-124: Avoid specifying long messages outside the exception class
(TRY003)
249-251: Prefer TypeError exception for invalid type
(TRY004)
249-251: Avoid specifying long messages outside the exception class
(TRY003)
316-316: Loop control variable i not used within loop body
Rename unused i to _i
(B007)
tests/unittest/_torch/thop/parallel/test_fp4_linear.py
316-316: f-string without any placeholders
Remove extraneous f prefix
(F541)
336-336: Loop control variable i not used within loop body
Rename unused i to _i
(B007)
349-349: f-string without any placeholders
Remove extraneous f prefix
(F541)
368-368: Loop control variable i not used within loop body
Rename unused i to _i
(B007)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py
1758-1758: Test for membership should be not in
Convert to not in
(E713)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
🔇 Additional comments (11)
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/utils.py (1)
56-72: Docstring rewrite LGTMThanks for switching to concise Google-style docstrings; no behavior change.
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/custom_pipeline.py (1)
1-10: License header deviates from repo guidelineRepo guideline says prepend NVIDIA Apache-2.0 header to .py files; this file uses LicenseRef-NvidiaProprietary (EULA). If intentional due to Cutlass DSL license, please confirm with legal/owners and document the exception.
tensorrt_llm/_torch/custom_ops/torch_custom_ops.py (2)
1257-1286: Include swap_ab in compile-time specialization (good), ensure consistent launchCACHE_KEY includes swap_ab and compile passes swap_ab as Constexpr — good. After fixing C allocation above, the rest of the launch path remains consistent.
Please run a quick sanity on both swap_ab=False/True to confirm output shape (m, n) and equality to the reference within tolerance.
1293-1311: Post-launch transpose back to (m, n) LGTMWith the allocation fix above, this becomes an inexpensive view.
tensorrt_llm/_torch/cute_dsl_kernels/blackwell/dense_blockscaled_gemm_persistent.py (7)
61-63: Direct import of custom pipelines LGTMSwitching to the new PipelineTmaUmma/PipelineUmmaAsync is clear and keeps dependencies explicit.
625-633: AB pipeline creation LGTMCorrect producer/consumer groups and tx_count wiring.
641-647: ACC pipeline creation LGTMProducer/consumer groups and layout propagation look right.
660-661: Use aligned cluster arrivePassing aligned=True is appropriate for post-init synchronization.
715-718: Use mma_tiler_sfb for SFB tilingGood catch; aligns SFB copy path with its widened tiler.
856-862: 64-wide N handling in SFB sliceHalving the N index for the 64 path makes sense for SFB tiling; comment is clear.
1031-1042: SFB tmem pointer offset for 64-wide NOffset-by-2 columns per odd tile is reasonable; please verify with a targeted unit to ensure no off-by-one across tile boundaries.
Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
|
/bot run |
|
PR_Github #18775 [ run ] triggered by Bot |
|
PR_Github #18773 [ run ] completed with state |
|
PR_Github #18775 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #18793 [ run ] triggered by Bot |
|
/bot run |
|
PR_Github #18799 [ run ] triggered by Bot |
|
PR_Github #18793 [ run ] completed with state |
|
PR_Github #18799 [ run ] completed with state |
Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
|
/bot run |
|
PR_Github #18909 [ run ] triggered by Bot |
|
PR_Github #18909 [ run ] completed with state |
…-dsl-nvfp4-linear-step-2 Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
…-dsl-nvfp4-linear-step-2 Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
|
/bot run |
|
PR_Github #19136 [ run ] triggered by Bot |
|
PR_Github #19136 [ run ] completed with state |
…l nvfp4 gemm (NVIDIA#7764) Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
…l nvfp4 gemm (NVIDIA#7764) Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
…l nvfp4 gemm (NVIDIA#7764) Signed-off-by: Mindy Li <11663212+limin2021@users.noreply.github.com>
Summary by CodeRabbit
New Features
Performance
Documentation
Tests
Description
[TRTLLM-6898][feat] Add swapab, tileN64, cga sync support for cute dsl nvfp4 gemm
previous MR: #7632
Test Coverage
op UT:

model UT:

Perf
https://nvidia-my.sharepoint.com/:x:/r/personal/lmin_nvidia_com/_layouts/15/doc.aspx?sourcedoc=%7B454d682b-8337-4117-b410-df896db5c108%7D&action=edit
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.