[PATCH] D121727: [NVPTX] Integrate ptxas to LIT tests

Andrew Savonichev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 12:23:51 PDT 2022


asavonic updated this revision to Diff 415934.
asavonic added a comment.

- Added `ptxas`and `ptxas-X.Y` features.
- Added `ptxas-verify` substitution that gets replaced to either `ptxas` or `true`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121727/new/

https://reviews.llvm.org/D121727

Files:
  llvm/test/CodeGen/NVPTX/access-non-generic.ll
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in


Index: llvm/test/lit.site.cfg.py.in
===================================================================
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -23,6 +23,7 @@
 config.ocaml_flags = "@OCAMLFLAGS@"
 config.include_go_tests = @LLVM_INCLUDE_GO_TESTS@
 config.go_executable = "@GO_EXECUTABLE@"
+config.ptxas_executable = "@PXTAS_EXECUTABLE@"
 config.enable_shared = @ENABLE_SHARED@
 config.enable_assertions = @ENABLE_ASSERTIONS@
 config.targets_to_build = "@TARGETS_TO_BUILD@"
Index: llvm/test/lit.cfg.py
===================================================================
--- llvm/test/lit.cfg.py
+++ llvm/test/lit.cfg.py
@@ -191,6 +191,39 @@
     ToolSubst('OrcV2CBindingsLazy', unresolved='ignore'),
     ToolSubst('OrcV2CBindingsVeryLazy', unresolved='ignore')])
 
+# Find (major, minor) version of ptxas
+def ptxas_version(ptxas):
+    ptxas_cmd = subprocess.Popen([ptxas, '--version'], stdout=subprocess.PIPE)
+    ptxas_out = ptxas_cmd.stdout.read().decode('ascii')
+    ptxas_cmd.wait()
+    match = re.search('release (\d+)\.(\d+)', ptxas_out)
+    if match:
+        return (int(match.group(1)), int(match.group(2)))
+    print('couldn\'t determine ptxas version')
+    return None
+
+ptxas_executable = 'true'
+ptxas_known_versions = [(11, 4)]
+if config.ptxas_executable:
+    ptxas_executable = config.ptxas_executable
+    version = ptxas_version(ptxas_executable)
+    if version:
+        # ptxas is supposed to be backward compatible with previous
+        # versions, so add a feature for every known version prior to
+        # the current one.
+        for known_major, known_minor in ptxas_known_versions:
+            if known_major <= version[0] and known_minor <= version[1]:
+                config.available_features.add(
+                    'ptxas-{}.{}'.format(known_major, known_minor))
+
+    config.available_features.add("ptxas")
+    tools.extend([ToolSubst('ptxas', ptxas_executable)])
+
+# verify PTX with ptxas, or substitute to 'true' if it is not
+# available
+tools.extend([
+    ToolSubst('ptxas-verify', '{} -c -o /dev/null'.format(ptxas_executable))])
+
 llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir)
 
 # Targets
Index: llvm/test/CodeGen/NVPTX/access-non-generic.ll
===================================================================
--- llvm/test/CodeGen/NVPTX/access-non-generic.ll
+++ llvm/test/CodeGen/NVPTX/access-non-generic.ll
@@ -1,5 +1,11 @@
-; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s --check-prefix PTX
-; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix PTX
+; RUN: llc < %s -march=nvptx -mcpu=sm_20 -o %t-nvptx.ptx
+; RUN: FileCheck %s --input-file %t-nvptx.ptx --check-prefix PTX
+; RUN: ptxas-verify %t-nvptx.ptx
+
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -o %t-nvptx64.ptx
+; RUN: FileCheck %s --input-file %t-nvptx64.ptx --check-prefix PTX
+; RUN: ptxas-verify %t-nvptx64.ptx
+
 ; RUN: opt -mtriple=nvptx-- < %s -S -infer-address-spaces | FileCheck %s --check-prefix IR
 ; RUN: opt -mtriple=nvptx64-- < %s -S -infer-address-spaces | FileCheck %s --check-prefix IR
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121727.415934.patch
Type: text/x-patch
Size: 3109 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220316/8d0cacfd/attachment.bin>


More information about the llvm-commits mailing list