Coverage for cuda/core/__init__.py: 95.45%
66 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-03 02:41 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
5from cuda.core._version import __version__
8def _import_versioned_module() -> None:
9 import importlib
11 from cuda import bindings
13 cuda_major = bindings.__version__.split(".")[0]
14 if cuda_major not in ("12", "13"):
15 raise ImportError("cuda.bindings 12.x or 13.x must be installed")
17 subdir = f"cu{cuda_major}"
18 try:
19 versioned_mod = importlib.import_module(f".{subdir}", __package__)
20 # Import all symbols from the module
21 globals().update(versioned_mod.__dict__)
22 except ImportError:
23 # This is not a wheel build, but a conda or local build, do nothing
24 pass
27_import_versioned_module()
28del _import_versioned_module
31def _patch_rlcompleter_for_cython_properties() -> None:
32 # TODO: This can be removed when Python 3.13 is our minimum-supported version:
33 # https://github.com/python/cpython/pull/149577
35 # Cython @property on cdef class compiles to a C-level getset_descriptor,
36 # which rlcompleter's narrow isinstance(..., property) check misses; the
37 # fallback getattr() then invokes the descriptor and any non-AttributeError
38 # it raises kills tab completion. Extend that isinstance check to also
39 # match getset_descriptor / member_descriptor. Installed unconditionally
40 # (the patch is scoped to the rlcompleter module, so non-interactive users
41 # only pay for the import).
42 import os
44 raw_opt_out = os.environ.get("CUDA_CORE_DONT_FIX_TAB_COMPLETION", "").strip()
45 try:
46 opt_out = int(raw_opt_out) != 0
47 except ValueError:
48 opt_out = raw_opt_out != ""
49 if opt_out:
50 # Explicit opt-out for users who don't want the global rlcompleter
51 # side effect, even in an interactive session.
52 return
54 import rlcompleter
55 from types import GetSetDescriptorType, MemberDescriptorType
57 # This works by overriding the `property` built-in with a custom subclass of
58 # property, but only in the rlcompleter module. This subclass overrides the
59 # `__instancecheck__` method to also return True for getset_descriptor and
60 # member_descriptor types, which are what Cython uses for properties on cdef
61 # classes.
62 class _PatchedPropMeta(type):
63 def __instancecheck__(cls, inst: object) -> bool:
64 return isinstance(inst, (property, GetSetDescriptorType, MemberDescriptorType))
66 class _PatchedProperty(metaclass=_PatchedPropMeta):
67 pass
69 rlcompleter.property = _PatchedProperty # type: ignore[attr-defined]
72_patch_rlcompleter_for_cython_properties()
73del _patch_rlcompleter_for_cython_properties
76from cuda.core import checkpoint, system, utils
77from cuda.core._context import *
78from cuda.core._context import __all__ as _context_all
79from cuda.core._device import *
80from cuda.core._device import __all__ as _device_all
81from cuda.core._device_resources import *
82from cuda.core._device_resources import __all__ as _device_resources_all
83from cuda.core._event import *
84from cuda.core._event import __all__ as _event_all
85from cuda.core._graphics import *
86from cuda.core._graphics import __all__ as _graphics_all
87from cuda.core._host import *
88from cuda.core._host import __all__ as _host_all
89from cuda.core._launch_config import *
90from cuda.core._launch_config import __all__ as _launch_config_all
91from cuda.core._launcher import *
92from cuda.core._launcher import __all__ as _launcher_all
93from cuda.core._linker import *
94from cuda.core._linker import __all__ as _linker_all
95from cuda.core._memory import *
96from cuda.core._memory import __all__ as _memory_all
97from cuda.core._module import *
98from cuda.core._module import __all__ as _module_all
99from cuda.core._program import *
100from cuda.core._program import __all__ as _program_all
101from cuda.core._stream import *
102from cuda.core._stream import __all__ as _stream_all
103from cuda.core._tensor_map import *
104from cuda.core._tensor_map import __all__ as _tensor_map_all
106__all__ = [
107 *_context_all,
108 *_device_all,
109 *_device_resources_all,
110 *_event_all,
111 *_graphics_all,
112 *_host_all,
113 *_launch_config_all,
114 *_launcher_all,
115 *_linker_all,
116 *_memory_all,
117 *_module_all,
118 *_program_all,
119 *_stream_all,
120 *_tensor_map_all,
121]
123# isort: split
124# Texture/surface types live under the cuda.core.texture namespace (not the
125# flat cuda.core namespace); import the subpackage so it is available as
126# `cuda.core.texture` after `import cuda.core`.
127# Must come after the cuda.core._* extension imports above: loading graph
128# earlier interacts badly with the merged-wheel __path__ rewrite and leaves
129# Graph/GraphBuilder/GraphCompleteOptions/GraphDebugPrintOptions missing from
130# cuda.core.graph.
131import cuda.core.graph
132import cuda.core.texture