[llvm] [lit] Refactor available `ptxas` features (PR #154439)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 26 12:49:18 PDT 2025
================
@@ -294,80 +294,146 @@ def get_asan_rtlib():
)
-# 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(r"release (\d+)\.(\d+)", ptxas_out)
- if match:
- return (int(match.group(1)), int(match.group(2)))
- print("couldn't determine ptxas version")
- return None
-
-
-# Enable %ptxas and %ptxas-verify tools.
-# %ptxas-verify defaults to sm_60 architecture. It can be overriden
-# by specifying required one, for instance: %ptxas-verify -arch=sm_80.
-def enable_ptxas(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.
- ptxas_known_versions = [
- (9, 0),
- (9, 1),
- (9, 2),
- (10, 0),
- (10, 1),
- (10, 2),
- (11, 0),
- (11, 1),
- (11, 2),
- (11, 3),
- (11, 4),
- (11, 5),
- (11, 6),
- (11, 7),
- (11, 8),
- (12, 0),
- (12, 1),
- (12, 2),
- (12, 3),
- (12, 4),
- (12, 5),
- (12, 6),
- (12, 8),
- ]
+ output = subprocess.check_output([ptxas, "--version"], text=True)
+ match = re.search(r"release (\d+)\.(\d+)", output)
+ if not match:
+ raise RuntimeError("Couldn't determine ptxas version")
+ return int(match.group(1)), int(match.group(2))
+
+
+def ptxas_supported_isa_versions(ptxas):
+ result = subprocess.run(
+ [ptxas, "--list-version"],
+ capture_output=True,
+ text=True,
+ )
+ versions = []
+ for line in result.stdout.splitlines():
+ match = re.match(r"(\d+)\.(\d+)", line)
+ if match:
+ versions.append((int(match.group(1)), int(match.group(2))))
+ return versions
+
+
+def ptxas_add_isa_features(major_version, minor_version):
+ supported_isa_versions = ptxas_supported_isa_versions(ptxas_executable)
+ if supported_isa_versions:
+ for major_version, minor_version in supported_isa_versions:
+ config.available_features.add(f"ptxas-isa-{major_version}.{minor_version}")
+ return
+ if major_version >= 13:
+ raise RuntimeError(
+ f"ptxas {ptxas_executable} does not support ISA version listing"
+ )
+ # Use a more pythonic approach: define a list of (major, minor, feature) tuples and iterate.
+ isa_features = [
+ (12, 9, "ptxas-isa-8.8"),
+ (12, 8, "ptxas-isa-8.7"),
+ (12, 7, "ptxas-isa-8.6"),
+ (12, 6, "ptxas-isa-8.5"),
----------------
AlexMaclean wrote:
Seems like we're hard coding the name of this feature "ptxas-isa-X.Y" unnecessarily here.
https://github.com/llvm/llvm-project/pull/154439
More information about the llvm-commits
mailing list