Skip to content

Commit f653355

Browse files
committed
Use compiled SM arch pattern
1 parent 757bdf0 commit f653355

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

cuda_pathfinder/cuda/pathfinder/_static_libs/find_bitcode_lib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class _BitcodeLibInfo(TypedDict):
6363
name for name, info in _SUPPORTED_BITCODE_LIBS_INFO.items() if not IS_WINDOWS or info["available_on_windows"]
6464
)
6565
)
66+
_SM_ARCH_PATTERN = re.compile(r"sm[0-9]+[a-z]?")
6667

6768

6869
def _no_such_file_in_dir(dir_path: str, filename: str, error_messages: list[str], attachments: list[str]) -> None:
@@ -79,8 +80,8 @@ def _filename_with_sm_arch(filename: str, sm_arch: str | None) -> str:
7980
if sm_arch is None:
8081
return filename
8182

82-
if not re.match(r"^sm[0-9]+[a-z]?$", sm_arch):
83-
raise ValueError(f"Invalid sm_arch: '{sm_arch}' must match 'sm[0-9]+[a-z]?'")
83+
if not _SM_ARCH_PATTERN.fullmatch(sm_arch):
84+
raise ValueError(f"Invalid sm_arch: {sm_arch!r} must match {_SM_ARCH_PATTERN.pattern!r}")
8485

8586
stem, ext = os.path.splitext(filename)
8687
return f"{stem}_{sm_arch}{ext}"

cuda_pathfinder/tests/test_find_bitcode_lib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,7 @@ def test_find_bitcode_lib_invalid_name():
306306
],
307307
)
308308
def test_find_bitcode_lib_invalid_sm_arch(sm_arch):
309-
with pytest.raises(ValueError, match="must match"):
309+
expected_pattern = find_bitcode_lib_module._SM_ARCH_PATTERN.pattern
310+
with pytest.raises(ValueError) as exc_info:
310311
find_bitcode_lib_module.locate_bitcode_lib("device", sm_arch=sm_arch)
312+
assert f"must match {expected_pattern!r}" in str(exc_info.value)

0 commit comments

Comments
 (0)