Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception manager to handle options which aren't covered in all CTK versions #371

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
21 changes: 20 additions & 1 deletion cuda_core/tests/test_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

from contextlib import contextmanager

import pytest

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

culink_backend = _linker._decide_nvjitlink_or_driver()
if not culink_backend:
from cuda.bindings import nvjitlink


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


@contextmanager
def skip_version_specific_linker_options():
if culink_backend:
return
ksimpson-work marked this conversation as resolved.
Show resolved Hide resolved
try:
yield
except nvjitlink.nvJitLinkError as e:
if e.status == nvjitlink.Result.ERROR_UNRECOGNIZED_OPTION:
pytest.skip("current nvjitlink version does not support the option provided")
ksimpson-work marked this conversation as resolved.
Show resolved Hide resolved
except Exception as e:
raise e
ksimpson-work marked this conversation as resolved.
Show resolved Hide resolved


culink_options = [
LinkerOptions(arch=ARCH, verbose=True),
LinkerOptions(arch=ARCH, max_register_count=32),
Expand Down Expand Up @@ -72,7 +89,9 @@ def compile_ltoir_functions(init_cuda):
],
)
def test_linker_init(compile_ptx_functions, options):
linker = Linker(*compile_ptx_functions, options=options)
with skip_version_specific_linker_options():
linker = Linker(*compile_ptx_functions, options=options)

object_code = linker.link("cubin")
assert isinstance(object_code, ObjectCode)

Expand Down
Loading