Skip to content

[MLIR][NVVM] Align the PTX string for StMatrixOp with the docs #148250

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

Closed
wants to merge 3 commits into from

Conversation

Pecco-314
Copy link

@Pecco-314 Pecco-314 commented Jul 11, 2025

According to the PTX documents, the syntax of stmatrix should be:

stmatrix.sync.aligned.shape.num{.trans}{.ss}.type [p], r;

.shape  = {.m8n8, .m16n8};
.num    = {.x1, .x2, .x4};
.ss     = {.shared{::cta}};
.type   = {.b16, .b8};

However, the current code will generate the PTX like "stmatrix.sync.aligned.x4.m8n8.shared.b16".
Though the existing syntax works, it is cleaner to align the lowering with the docs.

@Pecco-314 Pecco-314 requested a review from grypp as a code owner July 11, 2025 15:00
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-llvm

Author: Pecco (Pecco-314)

Changes

According to the PTX documents, the syntax of stmatrix should be:

stmatrix.sync.aligned.shape.num{.trans}{.ss}.type [p], r;

.shape  = {.m8n8, .m16n8};
.num    = {.x1, .x2, .x4};
.ss     = {.shared{::cta}};
.type   = {.b16, .b8};

However, the current code will generate the PTX like "stmatrix.sync.aligned.x4.m8n8.shared.b16". It seems like a bug.


Full diff: https://github.com/llvm/llvm-project/pull/148250.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td (+4-4)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
index 6895e946b8a45..b27c03ec2c63f 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
@@ -2000,13 +2000,13 @@ def NVVM_StMatrixOp: NVVM_PTXBuilder_Op<"stmatrix">,
   let extraClassDefinition = [{
     std::string $cppClass::getPtx() {
       int d = getSources().size();
-      std::string ptx = "stmatrix.sync.aligned";
+      std::string ptx = "stmatrix.sync.aligned.m8n8";
       ptx += ".x" + std::to_string(d);
       if (getLayout() == NVVM::MMALayout::col)
         ptx += ".trans";
-      if(d == 1) ptx += ".m8n8.shared.b16 [%0], {%1};";
-      if(d == 2) ptx += ".m8n8.shared.b16 [%0], {%1, %2};";
-      if(d == 4) ptx += ".m8n8.shared.b16 [%0], {%1, %2, %3, %4};";
+      if(d == 1) ptx += ".shared.b16 [%0], {%1};";
+      if(d == 2) ptx += ".shared.b16 [%0], {%1, %2};";
+      if(d == 4) ptx += ".shared.b16 [%0], {%1, %2, %3, %4};";
       return ptx;
     }
   }];

@grypp grypp requested a review from durga4github July 11, 2025 15:11
@durga4github
Copy link
Contributor

LGTM,
It seems ptxas is happy with the existing syntax also. But, anyway, it is nicer to align with the docs as shape.num

Copy link
Contributor

@durga4github durga4github left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly updated the commit message.
LGTM.

Thanks for the patch!

@durga4github durga4github changed the title [MLIR] Fix the PTX generation bug for StMatrixOp [MLIR][NVVM] Align the PTX string for StMatrixOp Jul 11, 2025
@durga4github durga4github changed the title [MLIR][NVVM] Align the PTX string for StMatrixOp [MLIR][NVVM] Align the PTX string for StMatrixOp with the docs Jul 11, 2025
@Pecco-314 Pecco-314 requested a review from durga4github July 12, 2025 00:34
@Pecco-314
Copy link
Author

This PR is covered by #148377 and can be closed.

@grypp grypp closed this Jul 14, 2025
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.

4 participants