Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions cuda_core/cuda/core/_linker.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ from dataclasses import dataclass
from typing import Union
from warnings import warn

from cuda.pathfinder import optional_cuda_import
from cuda.core._device import Device
from cuda.core._module import ObjectCode
from cuda.core._utils.clear_error_support import assert_type
Expand Down Expand Up @@ -649,23 +650,20 @@ def _decide_nvjitlink_or_driver() -> bool:
" For best results, consider upgrading to a recent version of"
)

try:
__import__("cuda.bindings.nvjitlink") # availability check
except ModuleNotFoundError:
nvjitlink_module = optional_cuda_import(
"cuda.bindings.nvjitlink",
probe_function=lambda module: module.version(), # probe triggers nvJitLink runtime load
)
if nvjitlink_module is None:
warn_txt = f"cuda.bindings.nvjitlink is not available, therefore {warn_txt_common} cuda-bindings."
else:
from cuda.bindings._internal import nvjitlink

try:
if _nvjitlink_has_version_symbol(nvjitlink):
_use_nvjitlink_backend = True
return False # Use nvjitlink
except RuntimeError:
warn_detail = "not available"
else:
warn_detail = "too old (<12.3)"
if _nvjitlink_has_version_symbol(nvjitlink):
_use_nvjitlink_backend = True
return False # Use nvjitlink
warn_txt = (
f"{'nvJitLink*.dll' if sys.platform == 'win32' else 'libnvJitLink.so*'} is {warn_detail}."
f"{'nvJitLink*.dll' if sys.platform == 'win32' else 'libnvJitLink.so*'} is too old (<12.3)."
f" Therefore cuda.bindings.nvjitlink is not usable and {warn_txt_common} nvJitLink."
)

Expand Down
22 changes: 13 additions & 9 deletions cuda_core/cuda/core/_program.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import threading
from warnings import warn

from cuda.bindings import driver, nvrtc
from cuda.pathfinder import optional_cuda_import

from libcpp.vector cimport vector

Expand Down Expand Up @@ -461,8 +462,8 @@ class ProgramOptions:
# =============================================================================

# Module-level state for NVVM lazy loading
cdef object_nvvm_module = None
cdef bint _nvvm_import_attempted = False
_nvvm_module = None
_nvvm_import_attempted = False
Comment on lines 464 to +466
Copy link
Member

Choose a reason for hiding this comment

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

Making them cdef helps us hide the objects from curious Python users.



def _get_nvvm_module():
Expand All @@ -484,18 +485,21 @@ def _get_nvvm_module():
"Please update cuda-bindings to use NVVM features."
)

from cuda.bindings import nvvm
from cuda.bindings._internal.nvvm import _inspect_function_pointer

if _inspect_function_pointer("__nvvmCreateProgram") == 0:
raise RuntimeError("NVVM library (libnvvm) is not available in this Python environment. ")
nvvm = optional_cuda_import(
"cuda.bindings.nvvm",
probe_function=lambda module: module.version(), # probe triggers libnvvm load
)
if nvvm is None:
raise RuntimeError(
"NVVM support is unavailable: cuda.bindings.nvvm is missing or libnvvm cannot be loaded."
)

_nvvm_module = nvvm
return _nvvm_module

except RuntimeError as e:
except RuntimeError:
_nvvm_module = None
raise e
raise

def _find_libdevice_path():
"""Find libdevice*.bc for NVVM compilation using cuda.pathfinder."""
Expand Down
3 changes: 3 additions & 0 deletions cuda_core/docs/source/release/0.7.x-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ Fixes and enhancements
linking operations to the C level and releasing the GIL during backend calls. This benefits
workloads that create many programs or linkers, and enables concurrent compilation in
multithreaded applications.
- Improved optional dependency handling for NVVM and nvJitLink imports so that only genuinely
missing optional modules are treated as unavailable; unrelated import failures now surface
normally, and ``cuda.core`` now depends directly on ``cuda-pathfinder``.
59 changes: 29 additions & 30 deletions cuda_core/pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cuda_core/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ numpy = "*"
# Using path dependency now that we've added .pth support for Cython .pxd files
# See build_hooks.py:_add_cython_include_paths_to_pth()
cuda-bindings = { path = "../cuda_bindings" }
cuda-pathfinder = { path = "../cuda_pathfinder" }

[target.linux.tasks.build-cython-tests]
cmd = ["$PIXI_PROJECT_ROOT/tests/cython/build_tests.sh"]
Expand Down
1 change: 1 addition & 0 deletions cuda_core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ classifiers = [
"Environment :: GPU :: NVIDIA CUDA :: 13",
]
dependencies = [
"cuda-pathfinder >=1.4.2",
"numpy",
]

Expand Down
Loading
Loading