[llvm] [NVPTX] Add ptxas verification and kernel test to sm-version test (PR #139543)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 12 06:09:25 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-nvptx

Author: Puja Saha (puja2196)

<details>
<summary>Changes</summary>

Description:
This PR enhances the sm-version.ll test in the NVPTX backend with two key improvements:
1. PTXAS Verification: Added comprehensive ptxas verification for all supported SM architectures (from SM20 to SM121a) for both 32-bit and 64-bit targets. This ensures that the generated PTX code is syntactically correct and can be properly assembled by NVIDIA's ptxas tool when available.
2. Test Kernel Functions: Added basic kernel functions that tests fundamental operations across all SM versions.

Testing:
The test runs conditionally based on ptxas availability using the %if ptxas directive, so it will skip the verification step when ptxas is not installed, ensuring test compatibility across all environments.

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


1 Files Affected:

- (modified) llvm/test/CodeGen/NVPTX/sm-version.ll (+71) 


``````````diff
diff --git a/llvm/test/CodeGen/NVPTX/sm-version.ll b/llvm/test/CodeGen/NVPTX/sm-version.ll
index 9705a2f3ba730..1b820b2d9f7b8 100644
--- a/llvm/test/CodeGen/NVPTX/sm-version.ll
+++ b/llvm/test/CodeGen/NVPTX/sm-version.ll
@@ -56,6 +56,65 @@
 ; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_121 | FileCheck %s --check-prefix=SM121
 ; RUN: llc < %s -mtriple=nvptx64 -mcpu=sm_121a | FileCheck %s --check-prefix=SM121a
 
+; Also check if ptxas is available for the various SM versions
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_20 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_21 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_30 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_32 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_35 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_37 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_50 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_52 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_53 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_60 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_61 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_62 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_70 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_75 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_80 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_86 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_90 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_90a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_100 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_100a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_101 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_101a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_103 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_103a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_120 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_120a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_121 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx -mcpu=sm_121a | %ptxas-verify %}
+
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_20 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_21 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_30 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_32 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_35 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_37 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_50 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_52 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_53 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_60 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_61 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_62 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_70 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_75 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_80 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_86 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_90 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_90a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_100 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_100a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_101 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_101a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_103 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_103a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_120 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_120a | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_121 | %ptxas-verify %}
+; RUN: %if ptxas %{ llc < %s -mtriple=nvptx64 -mcpu=sm_121a | %ptxas-verify %}
+
 ; SM20: .version 3.2
 ; SM21: .version 3.2
 ; SM30: .version 6.0
@@ -113,3 +172,15 @@
 ; SM120a: .target sm_120a
 ; SM121: .target sm_121
 ; SM121a: .target sm_121a
+
+; Simple kernel function that does a basic operation that should work on all SM versions
+define void @test_kernel(ptr %out, i32 %val) {
+  store i32 %val, ptr %out, align 4
+  ret void
+}
+
+; Add a ptx_kernel for good measure
+define ptx_kernel void @test_ptx_kernel(ptr %out, i32 %val) {
+  store i32 %val, ptr %out, align 4
+  ret void
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/139543


More information about the llvm-commits mailing list