Skip to content

Commit eba7d22

Browse files
committed
add exception manager to handle options which aren't covered in all cuda CTK versions
1 parent 61ef224 commit eba7d22

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

cuda_core/tests/test_linker.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44

5+
from contextlib import contextmanager
6+
57
import pytest
68

79
from cuda.core.experimental import Linker, LinkerOptions, Program, _linker
@@ -18,6 +20,8 @@
1820
device_function_c = "__device__ int C(int a, int b) { return a + b; }"
1921

2022
culink_backend = _linker._decide_nvjitlink_or_driver()
23+
if not culink_backend:
24+
from cuda.bindings import nvjitlink
2125

2226

2327
@pytest.fixture(scope="function")
@@ -40,6 +44,19 @@ def compile_ltoir_functions(init_cuda):
4044
return object_code_a_ltoir, object_code_b_ltoir, object_code_c_ltoir
4145

4246

47+
@contextmanager
48+
def skip_version_specific_linker_options():
49+
if culink_backend:
50+
return
51+
try:
52+
yield
53+
except nvjitlink.nvJitLinkError as e:
54+
if e.status == nvjitlink.Result.ERROR_UNRECOGNIZED_OPTION:
55+
pytest.skip("current nvjitlink version does not support the option provided")
56+
except Exception as e:
57+
raise e
58+
59+
4360
culink_options = [
4461
LinkerOptions(arch=ARCH, verbose=True),
4562
LinkerOptions(arch=ARCH, max_register_count=32),
@@ -72,7 +89,9 @@ def compile_ltoir_functions(init_cuda):
7289
],
7390
)
7491
def test_linker_init(compile_ptx_functions, options):
75-
linker = Linker(*compile_ptx_functions, options=options)
92+
with skip_version_specific_linker_options():
93+
linker = Linker(*compile_ptx_functions, options=options)
94+
7695
object_code = linker.link("cubin")
7796
assert isinstance(object_code, ObjectCode)
7897

0 commit comments

Comments
 (0)