Skip to content

Make Linker.backend a classmethod#1910

Open
cpcloud wants to merge 3 commits intoNVIDIA:mainfrom
cpcloud:linker-backend-classmethod-714
Open

Make Linker.backend a classmethod#1910
cpcloud wants to merge 3 commits intoNVIDIA:mainfrom
cpcloud:linker-backend-classmethod-714

Conversation

@cpcloud
Copy link
Copy Markdown
Contributor

@cpcloud cpcloud commented Apr 14, 2026

Summary

  • Converts Linker.backend from an instance property to a classmethod so callers can query the linking backend without constructing a Linker
  • Classmethod calls _decide_nvjitlink_or_driver() (existing memoised probe) and maps the return value to "nvJitLink" or "driver"
  • Updates the one in-repo call site in _program.pyx and existing test assertion to use parens
  • Adds 6 GPU-free tests via monkeypatch (no Device() / cuInit required)
  • Adds 0.8.0-notes.rst documenting the breaking change

Breaking change: linker.backend (attribute access) now returns a bound method, not a string. All call sites must use Linker.backend(). Only 2 in-repo call sites affected; numba-cuda (the requester) will adopt Linker.backend() from day one.

Test plan

  • 6 GPU-free tests pass locally (monkeypatch on module globals)
  • CI: existing GPU test test_linker_init passes with updated paren call
  • CI: Cython compile succeeds

Closes #714

🤖 Generated with Claude Code

@cpcloud cpcloud added this to the cuda.core v1.0.0 milestone Apr 14, 2026
@cpcloud cpcloud added enhancement Any code-related improvements P0 High priority - Must do! cuda.core Everything related to the cuda.core module breaking Breaking changes are introduced labels Apr 14, 2026
@cpcloud cpcloud self-assigned this Apr 14, 2026
@github-actions
Copy link
Copy Markdown

@cpcloud cpcloud force-pushed the linker-backend-classmethod-714 branch 2 times, most recently from dbe6176 to 215418a Compare April 16, 2026 21:45
@cpcloud cpcloud requested a review from leofang April 17, 2026 12:58
Copy link
Copy Markdown
Member

@leofang leofang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Phillip! Implementation-wise LGTM. Left a few suggestions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we are shooting for 1.0.0, unless @mdboom concludes that a 0.8.0 is a must for RAPIDS adoption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to 1.0.0-notes.rst.

Comment thread cuda_core/tests/test_linker_backend.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's move the tests to the existing test_linker.py. There is no need for separate test files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into test_linker.py and deleted test_linker_backend.py.

Comment thread cuda_core/tests/test_linker_backend.py Outdated
Comment on lines +7 to +9
These live in a separate file from test_linker.py because that module calls
Device() at import time, which requires a GPU. These tests use monkeypatch
to set module-level flags and never touch CUDA devices.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense? Would the driver cuLink* APIs be functional when there is no GPU present? I don't think this is ever tested.

NVRTC/nvJitLink work without GPU or CUDA, but it is not something we want to guarantee to users without the compiler team onboarding. This is not documented AFAIK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — test_linker.py already calls Device() at module import (line 11), so the GPU-free framing was moot. Dropped the rationale and merged the tests in; they just sit alongside the existing ones now.

Comment on lines +13 to +17
- :meth:`Linker.backend` is now a classmethod instead of an instance property.
Call sites must use ``Linker.backend()`` (with parentheses) instead of
``linker.backend``. This allows querying the linking backend without
constructing a ``Linker`` instance — for example, to choose between PTX and
LTOIR input before linking.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

cpcloud added 3 commits April 21, 2026 11:14
Allows querying the linking backend without constructing a Linker
instance — useful for dispatching on input format (PTX vs. LTOIR)
before linking.

Updates existing call sites (Program init, test_linker) to use the
new invocation form Linker.backend().
Covers classmethod invocation (Linker.backend() without an instance),
memoisation flag handling, probe-on-first-use, and non-property
attribute semantics.
Breaking change: Linker.backend is now a classmethod, so call sites
must use parens: Linker.backend().
@cpcloud cpcloud force-pushed the linker-backend-classmethod-714 branch from 215418a to 12d291b Compare April 21, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking changes are introduced cuda.core Everything related to the cuda.core module enhancement Any code-related improvements P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA]: Make Linker.backend a classmethod

2 participants