Skip to content

Commit 02cd045

Browse files
authored
[doc-only] cuda.core: add docstrings to Host properties and public StrEnum types (#2134)
* cuda.core: add docstrings to all public StrEnum types in typing.py Each StrEnum class in cuda.core.typing now has a class-level docstring that states its purpose and briefly describes every member value. Sphinx and help() now show meaningful descriptions for CompilerBackendType, GraphConditionalType, GraphMemoryType, ManagedMemoryLocationType, ObjectCodeFormatType, PCHStatusType, SourceCodeType, VirtualMemory*. No logic changes. * cuda.core: add property docstrings to Host.numa_id and Host.is_numa_current Host is a new 1.1.0 API. The class-level docstring is complete but the two public properties had no docstrings, leaving them blank in generated API docs and in help(). * cuda.core: fix is_numa_current phrasing and WIN32_KMT description - is_numa_current: lead with return type (``True`` if ...) to match bool-property docstring convention; keep :meth:`numa_current` cross-ref - WIN32_KMT: drop "D3DKMT" (DirectX-specific); CU_MEM_HANDLE_TYPE_WIN32_KMT maps to a general WDDM kernel-mode handle, not a D3D handle * docs(typing): fix RST bullet format, accuracy issues, and version notes in StrEnum docstrings - Convert all enum member descriptions to RST bullet list format (* ``MEMBER`` -- description) so Sphinx renders them as a list rather than a run-on paragraph - Fix VirtualMemoryAllocationType.PINNED: remove incorrect "page-locked host memory" wording; backing location is device by default and controlled by VirtualMemoryLocationType - Fix CompilerBackendType class summary: backend is inferred from Program.code_type and exposed on Program.backend, not selected via ProgramOptions - Move CUDA 13+ version note from ManagedMemoryLocationType.HOST_NUMA to VirtualMemoryAllocationType.MANAGED (the actual 13+-gated member; ManagedMemoryResource already requires CUDA 13 so the HOST_NUMA note was misleading) - Fix ObjectCodeFormatType summary to mention Linker.link and Program.as_bytes alongside Program.compile
1 parent 6b81b50 commit 02cd045

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

cuda_core/cuda/core/_host.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ def _get_or_create(cls, numa_id: int | None, is_numa_current: bool) -> Host:
6262

6363
@property
6464
def numa_id(self) -> int | None:
65+
"""NUMA node ID, or ``None`` if not pinned to a specific NUMA node."""
6566
return self._numa_id
6667

6768
@property
6869
def is_numa_current(self) -> bool:
70+
"""``True`` if this ``Host`` represents the calling thread's NUMA node (constructed via :meth:`numa_current`)."""
6971
return self._is_numa_current
7072

7173
@classmethod

cuda_core/cuda/core/typing.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,29 @@
4343

4444

4545
class SourceCodeType(StrEnum):
46+
"""Source language passed to :class:`~cuda.core.Program`.
47+
48+
* ``CXX`` — CUDA C++ source.
49+
* ``PTX`` — PTX assembly text.
50+
* ``NVVM`` — NVVM IR (LLVM bitcode).
51+
"""
52+
4653
CXX = "c++"
4754
PTX = "ptx"
4855
NVVM = "nvvm"
4956

5057

5158
class ObjectCodeFormatType(StrEnum):
59+
"""Output format for :meth:`~cuda.core.Program.compile`, :meth:`~cuda.core.Linker.link`, and :meth:`~cuda.core.Program.as_bytes`.
60+
61+
* ``PTX`` — PTX assembly text.
62+
* ``CUBIN`` — device-native CUDA binary.
63+
* ``LTOIR`` — LTO (link-time optimization) IR for later linking.
64+
* ``FATBIN`` — fat binary bundling multiple device images.
65+
* ``OBJECT`` — relocatable device object.
66+
* ``LIBRARY`` — device code library.
67+
"""
68+
5269
PTX = "ptx"
5370
CUBIN = "cubin"
5471
LTOIR = "ltoir"
@@ -58,60 +75,129 @@ class ObjectCodeFormatType(StrEnum):
5875

5976

6077
class CompilerBackendType(StrEnum):
78+
"""Compiler backend inferred from the program's code type and exposed on :attr:`~cuda.core.Program.backend`.
79+
80+
* ``NVRTC`` — NVIDIA Runtime Compilation.
81+
* ``NVVM`` — NVVM LLVM backend.
82+
* ``NVJITLINK`` — nvJitLink device-side linker.
83+
* ``DRIVER`` — CUDA driver PTX JIT compiler.
84+
"""
85+
6186
NVRTC = "NVRTC"
6287
NVVM = "NVVM"
6388
NVJITLINK = "nvJitLink"
6489
DRIVER = "driver"
6590

6691

6792
class PCHStatusType(StrEnum):
93+
"""Precompiled-header (PCH) outcome reported by :meth:`~cuda.core.Program.compile`.
94+
95+
* ``CREATED`` — PCH was successfully written.
96+
* ``NOT_ATTEMPTED`` — PCH creation was skipped (backend does not support it or the option was not requested).
97+
* ``FAILED`` — PCH creation was attempted but failed.
98+
"""
99+
68100
CREATED = "created"
69101
NOT_ATTEMPTED = "not_attempted"
70102
FAILED = "failed"
71103

72104

73105
class GraphConditionalType(StrEnum):
106+
"""Conditional node flavor for :class:`~cuda.core.graph.GraphBuilder`.
107+
108+
* ``IF`` — body graph executes at most once based on a condition.
109+
* ``WHILE`` — body graph loops while the condition is true.
110+
* ``SWITCH`` — selects one child graph by an integer index.
111+
"""
112+
74113
IF = "if"
75114
WHILE = "while"
76115
SWITCH = "switch"
77116

78117

79118
class GraphMemoryType(StrEnum):
119+
"""Memory space for a graph memory-allocation or free node.
120+
121+
* ``DEVICE`` — GPU device memory.
122+
* ``HOST`` — pinned host memory.
123+
* ``MANAGED`` — CUDA managed (unified) memory.
124+
"""
125+
80126
DEVICE = "device"
81127
HOST = "host"
82128
MANAGED = "managed"
83129

84130

85131
class ManagedMemoryLocationType(StrEnum):
132+
"""Destination type for managed-memory prefetch and advise operations.
133+
134+
* ``DEVICE`` — target a GPU device.
135+
* ``HOST`` — target the CPU host (any NUMA node).
136+
* ``HOST_NUMA`` — target a specific host NUMA node.
137+
"""
138+
86139
DEVICE = "device"
87140
HOST = "host"
88141
HOST_NUMA = "host_numa"
89142

90143

91144
class VirtualMemoryHandleType(StrEnum):
145+
"""OS handle type for exporting virtual memory allocations across processes.
146+
147+
* ``POSIX_FD`` — POSIX file descriptor (Linux).
148+
* ``WIN32_KMT`` — Win32 kernel-mode handle (Windows).
149+
* ``FABRIC`` — NVLink/NVSwitch fabric handle for multi-node topologies.
150+
"""
151+
92152
POSIX_FD = "posix_fd"
93153
WIN32_KMT = "win32_kmt"
94154
FABRIC = "fabric"
95155

96156

97157
class VirtualMemoryLocationType(StrEnum):
158+
"""Physical backing location for a virtual memory allocation.
159+
160+
* ``DEVICE`` — GPU device memory.
161+
* ``HOST`` — pinned host memory.
162+
* ``HOST_NUMA`` — host memory pinned to a specific NUMA node.
163+
* ``HOST_NUMA_CURRENT`` — host memory on the calling thread's NUMA node.
164+
"""
165+
98166
DEVICE = "device"
99167
HOST = "host"
100168
HOST_NUMA = "host_numa"
101169
HOST_NUMA_CURRENT = "host_numa_current"
102170

103171

104172
class VirtualMemoryGranularityType(StrEnum):
173+
"""Granularity query type for virtual memory allocations.
174+
175+
* ``MINIMUM`` — smallest allocation size supported by the device.
176+
* ``RECOMMENDED`` — granularity that yields best performance on the device.
177+
"""
178+
105179
MINIMUM = "minimum"
106180
RECOMMENDED = "recommended"
107181

108182

109183
class VirtualMemoryAccessType(StrEnum):
184+
"""Access permissions for a virtual memory mapping.
185+
186+
* ``READ_WRITE`` — both read and write access.
187+
* ``READ`` — read-only access.
188+
"""
189+
110190
READ_WRITE = "rw"
111191
READ = "r"
112192

113193

114194
class VirtualMemoryAllocationType(StrEnum):
195+
"""Physical memory type for a virtual memory backing allocation.
196+
197+
* ``PINNED`` — pinned/non-migratable physical allocation (placement via :class:`VirtualMemoryLocationType`).
198+
* ``MANAGED`` — CUDA managed (unified) memory (CUDA 13+ only).
199+
"""
200+
115201
PINNED = "pinned"
116202
MANAGED = "managed"
117203

0 commit comments

Comments
 (0)