Skip to content

Commit fe9db0e

Browse files
cpcloudclaude
andcommitted
feat(core): convert Linker.backend from property to classmethod
Make `Linker.backend` callable without instantiation, allowing downstream libraries (e.g., numba-cuda) to query which linking backend will be used before constructing a Linker. The classmethod calls `_decide_nvjitlink_or_driver()` and maps its return value to "nvJitLink" or "driver". Existing call sites updated to use parens (`linker.backend()` instead of `linker.backend`). Breaking change: attribute-style access `linker.backend` now returns a bound method, not a string. Only two in-repo call sites affected; both updated. Refs #714 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 82e6bb8 commit fe9db0e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

cuda_core/cuda/core/_linker.pyx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,22 @@ cdef class Linker:
167167
else:
168168
return as_py(self._culink_handle)
169169

170-
@property
171-
def backend(self) -> str:
172-
"""Return this Linker instance's underlying backend."""
173-
return "nvJitLink" if self._use_nvjitlink else "driver"
170+
@classmethod
171+
def backend(cls) -> str:
172+
"""Return which linking backend will be used.
173+
174+
Returns ``"nvJitLink"`` when the nvJitLink library is available
175+
and meets the minimum version requirement, otherwise ``"driver"``.
176+
177+
.. note::
178+
179+
Prefer letting :class:`Linker` decide. Query ``backend()``
180+
only when you need to dispatch based on input format (for
181+
example: choose PTX vs. LTOIR before constructing a
182+
``Linker``). The returned string names an implementation
183+
detail whose support matrix may shift across CTK releases.
184+
"""
185+
return "driver" if _decide_nvjitlink_or_driver() else "nvJitLink"
174186

175187

176188
# =============================================================================

cuda_core/cuda/core/_program.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ cdef inline int Program_init(Program self, object code, str code_type, object op
649649
self._linker = Linker(
650650
ObjectCode._init(code.encode(), code_type), options=_translate_program_options(options)
651651
)
652-
self._backend = self._linker.backend
652+
self._backend = self._linker.backend()
653653

654654
elif code_type == "nvvm":
655655
_get_nvvm_module() # Validate NVVM availability

cuda_core/tests/test_linker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_linker_init(compile_ptx_functions, options):
9292
linker = Linker(*compile_ptx_functions, options=options)
9393
object_code = linker.link("cubin")
9494
assert isinstance(object_code, ObjectCode)
95-
assert linker.backend == ("driver" if is_culink_backend else "nvJitLink")
95+
assert linker.backend() == ("driver" if is_culink_backend else "nvJitLink")
9696

9797

9898
def test_linker_init_invalid_arch(compile_ptx_functions):

0 commit comments

Comments
 (0)