Coverage for cuda / core / __init__.py: 91.11%
45 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-22 01:37 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-22 01:37 +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():
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():
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. Only installed in
40 # interactive mode so library users running scripts see no global
41 # rlcompleter side effect.
42 import os
44 if int(os.environ.get("CUDA_CORE_DONT_FIX_TAB_COMPLETION", "0")):
45 # Explicit opt-out for users who don't want the global rlcompleter
46 # side effect, even in an interactive session.
47 return
49 import rlcompleter
50 from types import GetSetDescriptorType, MemberDescriptorType
52 # This works by overriding the `property` built-in with a custom subclass of
53 # property, but only in the rlcompleter module. This subclass overrides the
54 # `__instancecheck__` method to also return True for getset_descriptor and
55 # member_descriptor types, which are what Cython uses for properties on cdef
56 # classes.
57 class _PatchedPropMeta(type):
58 def __instancecheck__(cls, inst):
59 return isinstance(inst, (property, GetSetDescriptorType, MemberDescriptorType))
61 class _PatchedProperty(metaclass=_PatchedPropMeta):
62 pass
64 rlcompleter.property = _PatchedProperty
67_patch_rlcompleter_for_cython_properties()
68del _patch_rlcompleter_for_cython_properties
71from cuda.core import checkpoint, system, utils
72from cuda.core._context import Context, ContextOptions
73from cuda.core._device import Device
74from cuda.core._device_resources import (
75 DeviceResources,
76 SMResource,
77 SMResourceOptions,
78 WorkqueueResource,
79 WorkqueueResourceOptions,
80)
81from cuda.core._event import Event, EventOptions
82from cuda.core._graphics import GraphicsResource
83from cuda.core._host import Host
84from cuda.core._launch_config import LaunchConfig
85from cuda.core._launcher import launch
86from cuda.core._linker import Linker, LinkerOptions
87from cuda.core._memory import (
88 Buffer,
89 DeviceMemoryResource,
90 DeviceMemoryResourceOptions,
91 GraphMemoryResource,
92 LegacyPinnedMemoryResource,
93 ManagedBuffer,
94 ManagedMemoryResource,
95 ManagedMemoryResourceOptions,
96 MemoryResource,
97 PinnedMemoryResource,
98 PinnedMemoryResourceOptions,
99 VirtualMemoryResource,
100 VirtualMemoryResourceOptions,
101)
102from cuda.core._module import Kernel, ObjectCode
103from cuda.core._program import Program, ProgramOptions
104from cuda.core._stream import (
105 LEGACY_DEFAULT_STREAM,
106 PER_THREAD_DEFAULT_STREAM,
107 Stream,
108 StreamOptions,
109)
110from cuda.core._tensor_map import TensorMapDescriptor, TensorMapDescriptorOptions
112# isort: split
113# Must come after the cuda.core._* extension imports above: loading graph
114# earlier interacts badly with the merged-wheel __path__ rewrite and leaves
115# Graph/GraphBuilder/GraphCompleteOptions/GraphDebugPrintOptions missing from
116# cuda.core.graph.
117import cuda.core.graph