|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
| 5 | +import inspect |
| 6 | + |
5 | 7 | import pytest |
6 | 8 |
|
7 | 9 | from cuda.core import Device, Linker, LinkerOptions, Program, ProgramOptions, _linker |
@@ -92,7 +94,7 @@ def test_linker_init(compile_ptx_functions, options): |
92 | 94 | linker = Linker(*compile_ptx_functions, options=options) |
93 | 95 | object_code = linker.link("cubin") |
94 | 96 | assert isinstance(object_code, ObjectCode) |
95 | | - assert linker.backend == ("driver" if is_culink_backend else "nvJitLink") |
| 97 | + assert Linker.which_backend() == ("driver" if is_culink_backend else "nvJitLink") |
96 | 98 |
|
97 | 99 |
|
98 | 100 | def test_linker_init_invalid_arch(compile_ptx_functions): |
@@ -242,3 +244,39 @@ def test_linker_options_nvjitlink_options_as_str(): |
242 | 244 | assert f"-arch={ARCH}" in options |
243 | 245 | assert "-g" in options |
244 | 246 | assert "-lineinfo" in options |
| 247 | + |
| 248 | + |
| 249 | +class TestWhichBackendClassmethod: |
| 250 | + def test_which_backend_returns_nvjitlink(self, monkeypatch): |
| 251 | + monkeypatch.setattr(_linker, "_use_nvjitlink_backend", True) |
| 252 | + assert Linker.which_backend() == "nvJitLink" |
| 253 | + |
| 254 | + def test_which_backend_returns_driver(self, monkeypatch): |
| 255 | + monkeypatch.setattr(_linker, "_use_nvjitlink_backend", False) |
| 256 | + assert Linker.which_backend() == "driver" |
| 257 | + |
| 258 | + def test_which_backend_invokes_probe_when_not_memoised(self, monkeypatch): |
| 259 | + monkeypatch.setattr(_linker, "_use_nvjitlink_backend", None) |
| 260 | + called = [] |
| 261 | + |
| 262 | + def fake_decide(): |
| 263 | + called.append(True) |
| 264 | + return False # False = not falling back to driver = nvJitLink |
| 265 | + |
| 266 | + monkeypatch.setattr(_linker, "_decide_nvjitlink_or_driver", fake_decide) |
| 267 | + result = Linker.which_backend() |
| 268 | + assert result == "nvJitLink" |
| 269 | + assert called, "_decide_nvjitlink_or_driver was not called" |
| 270 | + |
| 271 | + def test_which_backend_is_classmethod(self): |
| 272 | + attr = inspect.getattr_static(Linker, "which_backend") |
| 273 | + assert isinstance(attr, classmethod) |
| 274 | + |
| 275 | + def test_which_backend_is_not_property(self): |
| 276 | + """which_backend is a classmethod, not a property. |
| 277 | +
|
| 278 | + This is an intentional breaking change from the prior ``backend`` property API. |
| 279 | + All call sites must use parens: ``Linker.which_backend()``. |
| 280 | + """ |
| 281 | + attr = inspect.getattr_static(Linker, "which_backend") |
| 282 | + assert not isinstance(attr, property) |
0 commit comments