Skip to content

Commit 1c7728d

Browse files
committed
Complete type annotations on all public API
1 parent d296dbb commit 1c7728d

76 files changed

Lines changed: 1041 additions & 493 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
3+
4+
# This code was automatically generated with version 13.2.0, generator version 0.3.1.dev1422+gf4812259e.d20260318. Do not modify it directly.
5+
from cuda.bindings.cynvrtc cimport *
6+
7+
cdef const char* _nvrtcGetErrorString(nvrtcResult result) except ?NULL nogil
8+
9+
cdef nvrtcResult _nvrtcVersion(int* major, int* minor) except ?NVRTC_ERROR_INVALID_INPUT nogil
10+
11+
cdef nvrtcResult _nvrtcGetNumSupportedArchs(int* numArchs) except ?NVRTC_ERROR_INVALID_INPUT nogil
12+
13+
cdef nvrtcResult _nvrtcGetSupportedArchs(int* supportedArchs) except ?NVRTC_ERROR_INVALID_INPUT nogil
14+
15+
cdef nvrtcResult _nvrtcCreateProgram(nvrtcProgram* prog, const char* src, const char* name, int numHeaders, const char** headers, const char** includeNames) except ?NVRTC_ERROR_INVALID_INPUT nogil
16+
17+
cdef nvrtcResult _nvrtcDestroyProgram(nvrtcProgram* prog) except ?NVRTC_ERROR_INVALID_INPUT nogil
18+
19+
cdef nvrtcResult _nvrtcCompileProgram(nvrtcProgram prog, int numOptions, const char** options) except ?NVRTC_ERROR_INVALID_INPUT nogil
20+
21+
cdef nvrtcResult _nvrtcGetPTXSize(nvrtcProgram prog, size_t* ptxSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
22+
23+
cdef nvrtcResult _nvrtcGetPTX(nvrtcProgram prog, char* ptx) except ?NVRTC_ERROR_INVALID_INPUT nogil
24+
25+
cdef nvrtcResult _nvrtcGetCUBINSize(nvrtcProgram prog, size_t* cubinSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
26+
27+
cdef nvrtcResult _nvrtcGetCUBIN(nvrtcProgram prog, char* cubin) except ?NVRTC_ERROR_INVALID_INPUT nogil
28+
29+
cdef nvrtcResult _nvrtcGetLTOIRSize(nvrtcProgram prog, size_t* LTOIRSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
30+
31+
cdef nvrtcResult _nvrtcGetLTOIR(nvrtcProgram prog, char* LTOIR) except ?NVRTC_ERROR_INVALID_INPUT nogil
32+
33+
cdef nvrtcResult _nvrtcGetOptiXIRSize(nvrtcProgram prog, size_t* optixirSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
34+
35+
cdef nvrtcResult _nvrtcGetOptiXIR(nvrtcProgram prog, char* optixir) except ?NVRTC_ERROR_INVALID_INPUT nogil
36+
37+
cdef nvrtcResult _nvrtcGetProgramLogSize(nvrtcProgram prog, size_t* logSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
38+
39+
cdef nvrtcResult _nvrtcGetProgramLog(nvrtcProgram prog, char* log) except ?NVRTC_ERROR_INVALID_INPUT nogil
40+
41+
cdef nvrtcResult _nvrtcAddNameExpression(nvrtcProgram prog, const char* name_expression) except ?NVRTC_ERROR_INVALID_INPUT nogil
42+
43+
cdef nvrtcResult _nvrtcGetLoweredName(nvrtcProgram prog, const char* name_expression, const char** lowered_name) except ?NVRTC_ERROR_INVALID_INPUT nogil
44+
45+
cdef nvrtcResult _nvrtcGetPCHHeapSize(size_t* ret) except ?NVRTC_ERROR_INVALID_INPUT nogil
46+
47+
cdef nvrtcResult _nvrtcSetPCHHeapSize(size_t size) except ?NVRTC_ERROR_INVALID_INPUT nogil
48+
49+
cdef nvrtcResult _nvrtcGetPCHCreateStatus(nvrtcProgram prog) except ?NVRTC_ERROR_INVALID_INPUT nogil
50+
51+
cdef nvrtcResult _nvrtcGetPCHHeapSizeRequired(nvrtcProgram prog, size_t* size) except ?NVRTC_ERROR_INVALID_INPUT nogil
52+
53+
cdef nvrtcResult _nvrtcSetFlowCallback(nvrtcProgram prog, void* callback, void* payload) except ?NVRTC_ERROR_INVALID_INPUT nogil

cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx

Lines changed: 389 additions & 0 deletions
Large diffs are not rendered by default.

cuda_core/cuda/core/_context.pyi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ from __future__ import annotations
55
from collections.abc import Sequence
66
from dataclasses import dataclass
77

8+
import cuda.bindings.driver
89
from cuda.core._device_resources import (DeviceResources, SMResource,
910
WorkqueueResource)
10-
from cuda.core._stream import StreamOptions
11+
from cuda.core._stream import Stream, StreamOptions
1112

1213

1314
class Context:
@@ -20,15 +21,15 @@ class Context:
2021
def close(self):
2122
"""Release this context wrapper's underlying CUDA handles."""
2223

23-
def __init__(self, *args, **kwargs):
24+
def __init__(self, *args, **kwargs) -> None:
2425
...
2526

2627
@property
27-
def handle(self):
28+
def handle(self) -> cuda.bindings.driver.CUcontext | None:
2829
"""Return the underlying CUcontext handle."""
2930

3031
@property
31-
def _handle(self):
32+
def _handle(self) -> cuda.bindings.driver.CUcontext | None:
3233
...
3334

3435
@property
@@ -46,7 +47,7 @@ class Context:
4647
Raises :class:`RuntimeError` if the context has been closed.
4748
"""
4849

49-
def create_stream(self, options: StreamOptions | None=None):
50+
def create_stream(self, options: StreamOptions | None=None) -> Stream:
5051
"""Create a new stream bound to this green context.
5152
5253
This method is only available on green contexts. For primary
@@ -63,7 +64,7 @@ class Context:
6364
Newly created stream object.
6465
"""
6566

66-
def __eq__(self, other):
67+
def __eq__(self, other: object) -> bool:
6768
...
6869

6970
def __hash__(self) -> int:

cuda_core/cuda/core/_context.pyx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from __future__ import annotations
66

77
from collections.abc import Sequence
88
from dataclasses import dataclass
9+
from typing import TYPE_CHECKING
910

1011
from cuda.bindings cimport cydriver
1112
from cuda.core._device_resources cimport DeviceResources, SMResource, WorkqueueResource
@@ -23,6 +24,9 @@ from cuda.core._resource_handles cimport (
2324
from cuda.core._stream import Stream, StreamOptions
2425
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN
2526

27+
if TYPE_CHECKING:
28+
import cuda.bindings.driver # no-cython-lint
29+
2630

2731
__all__ = ['Context', 'ContextOptions']
2832

@@ -37,7 +41,7 @@ cdef class Context:
3741
Use Device or Stream APIs to obtain context objects.
3842
"""
3943

40-
def __init__(self, *args, **kwargs):
44+
def __init__(self, *args, **kwargs) -> None:
4145
raise RuntimeError("Context objects cannot be instantiated directly. Please use Device or Stream APIs.")
4246

4347
@staticmethod
@@ -58,7 +62,7 @@ cdef class Context:
5862
return Context._from_handle(cls, h_context, device_id)
5963

6064
@property
61-
def handle(self):
65+
def handle(self) -> cuda.bindings.driver.CUcontext | None:
6266
"""Return the underlying CUcontext handle."""
6367
if not self._h_context:
6468
return None
@@ -67,7 +71,7 @@ cdef class Context:
6771
return as_py(self._h_context)
6872

6973
@property
70-
def _handle(self):
74+
def _handle(self) -> cuda.bindings.driver.CUcontext | None:
7175
return self.handle
7276

7377
@property
@@ -91,7 +95,7 @@ cdef class Context:
9195
raise RuntimeError("Cannot query resources on a closed context")
9296
return DeviceResources._init_from_ctx(self._h_context, self._device_id)
9397

94-
def create_stream(self, options: StreamOptions | None = None):
98+
def create_stream(self, options: StreamOptions | None = None) -> Stream:
9599
"""Create a new stream bound to this green context.
96100

97101
This method is only available on green contexts. For primary
@@ -130,7 +134,7 @@ cdef class Context:
130134
)
131135
self._h_context.reset()
132136

133-
def __eq__(self, other):
137+
def __eq__(self, other: object) -> bool:
134138
if not isinstance(other, Context):
135139
return NotImplemented
136140
cdef Context _other = <Context>other

cuda_core/cuda/core/_device.pyi

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class DeviceProperties:
2121
Attributes are read-only and provide information about the device.
2222
"""
2323

24-
def __init__(self, *args, **kwargs):
24+
def __init__(self, *args, **kwargs) -> None:
2525
...
2626

2727
@classmethod
28-
def _init(cls, handle):
28+
def _init(cls, handle: int) -> DeviceProperties:
2929
...
3030

3131
@property
@@ -634,14 +634,14 @@ class Device:
634634
"""
635635
__slots__ = ('_device_id', '_memory_resource', '_has_inited', '_properties', '_resources', '_uuid', '_context', '__weakref__')
636636

637-
def __new__(cls, device_id: Device | int | None=None):
637+
def __new__(cls, device_id: Device | int | None=None) -> Device:
638638
...
639639

640640
def _check_context_initialized(self):
641641
...
642642

643643
@classmethod
644-
def get_all_devices(cls):
644+
def get_all_devices(cls) -> tuple[Device, ...]:
645645
"""
646646
Query the available device instances.
647647
@@ -737,7 +737,7 @@ class Device:
737737
"""Return :obj:`~_memory.MemoryResource` associated with this device."""
738738

739739
@memory_resource.setter
740-
def memory_resource(self, mr):
740+
def memory_resource(self, mr: MemoryResource) -> None:
741741
...
742742

743743
@property
@@ -752,19 +752,19 @@ class Device:
752752
753753
"""
754754

755-
def __int__(self):
755+
def __int__(self) -> int:
756756
"""Return device_id."""
757757

758-
def __repr__(self):
758+
def __repr__(self) -> str:
759759
...
760760

761761
def __hash__(self) -> int:
762762
...
763763

764-
def __eq__(self, other) -> bool:
764+
def __eq__(self, other: object) -> bool:
765765
...
766766

767-
def __reduce__(self):
767+
def __reduce__(self) -> tuple:
768768
...
769769

770770
def set_current(self, ctx: Context | None=None) -> Context | None:
@@ -865,7 +865,7 @@ class Device:
865865
866866
"""
867867

868-
def allocate(self, size, *, stream: Stream | GraphBuilder) -> Buffer:
868+
def allocate(self, size: int, *, stream: Stream | GraphBuilder) -> Buffer:
869869
"""Allocate device memory from a specified stream.
870870
871871
Allocates device memory of `size` bytes on the specified `stream`
@@ -891,7 +891,7 @@ class Device:
891891
892892
"""
893893

894-
def sync(self):
894+
def sync(self) -> None:
895895
"""Synchronize the device.
896896
897897
Note

cuda_core/cuda/core/_device.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ cdef class DeviceProperties:
6262
int _handle
6363
dict _cache
6464

65-
def __init__(self, *args, **kwargs):
65+
def __init__(self, *args, **kwargs) -> None:
6666
raise RuntimeError("DeviceProperties cannot be instantiated directly. Please use Device APIs.")
6767

6868
@classmethod
69-
def _init(cls, handle):
69+
def _init(cls, handle: int) -> DeviceProperties:
7070
cdef DeviceProperties self = DeviceProperties.__new__(cls)
7171
self._handle = handle
7272
self._cache = {}
@@ -976,7 +976,7 @@ class Device:
976976
"__weakref__",
977977
)
978978

979-
def __new__(cls, device_id: Device | int | None = None):
979+
def __new__(cls, device_id: Device | int | None = None) -> Device:
980980
if isinstance(device_id, Device):
981981
return device_id
982982

@@ -997,7 +997,7 @@ class Device:
997997

998998

999999
@classmethod
1000-
def get_all_devices(cls):
1000+
def get_all_devices(cls) -> tuple[Device, ...]:
10011001
"""
10021002
Query the available device instances.
10031003

@@ -1178,7 +1178,7 @@ class Device:
11781178
return self._memory_resource
11791179

11801180
@memory_resource.setter
1181-
def memory_resource(self, mr):
1181+
def memory_resource(self, mr: MemoryResource) -> None:
11821182
from cuda.core._memory import MemoryResource
11831183
assert_type(mr, MemoryResource)
11841184
self._memory_resource = mr
@@ -1196,22 +1196,22 @@ class Device:
11961196
"""
11971197
return default_stream()
11981198

1199-
def __int__(self):
1199+
def __int__(self) -> int:
12001200
"""Return device_id."""
12011201
return self._device_id
12021202

1203-
def __repr__(self):
1203+
def __repr__(self) -> str:
12041204
return f"<Device {self._device_id} ({self.name})>"
12051205

12061206
def __hash__(self) -> int:
12071207
return hash(self.uuid)
12081208

1209-
def __eq__(self, other) -> bool:
1209+
def __eq__(self, other: object) -> bool:
12101210
if not isinstance(other, Device):
12111211
return NotImplemented
12121212
return self._device_id == other._device_id
12131213

1214-
def __reduce__(self):
1214+
def __reduce__(self) -> tuple:
12151215
return Device, (self.device_id,)
12161216

12171217
def set_current(self, ctx: Context | None = None) -> Context | None:
@@ -1400,7 +1400,7 @@ class Device:
14001400
cdef Context ctx = self._context
14011401
return cyEvent._init(cyEvent, self._device_id, ctx._h_context, options, True)
14021402

1403-
def allocate(self, size, *, stream: Stream | GraphBuilder) -> Buffer:
1403+
def allocate(self, size: int, *, stream: Stream | GraphBuilder) -> Buffer:
14041404
"""Allocate device memory from a specified stream.
14051405

14061406
Allocates device memory of `size` bytes on the specified `stream`
@@ -1428,7 +1428,7 @@ class Device:
14281428
self._check_context_initialized()
14291429
return self.memory_resource.allocate(size, stream=stream)
14301430

1431-
def sync(self):
1431+
def sync(self) -> None:
14321432
"""Synchronize the device.
14331433

14341434
Note

cuda_core/cuda/core/_device_resources.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class SMResource:
8080
def flags(self) -> int:
8181
"""Raw flags from the underlying SM resource."""
8282

83-
def split(self, options, *, dry_run: bool=False):
83+
def split(self, options: SMResourceOptions, *, dry_run: bool=False) -> tuple[list[SMResource], SMResource]:
8484
"""Split this SM resource into groups and a remainder.
8585
8686
Parameters
@@ -107,14 +107,14 @@ class WorkqueueResource:
107107
cannot be instantiated directly.
108108
"""
109109

110-
def __init__(self, *args, **kwargs):
110+
def __init__(self, *args, **kwargs) -> None:
111111
...
112112

113113
@property
114114
def handle(self) -> int:
115115
"""Return the address of the underlying config ``CUdevResource`` struct."""
116116

117-
def configure(self, options):
117+
def configure(self, options: WorkqueueResourceOptions) -> None:
118118
"""Configure the workqueue resource in place.
119119
120120
Parameters
@@ -134,7 +134,7 @@ class DeviceResources:
134134
This class cannot be instantiated directly.
135135
"""
136136

137-
def __init__(self, *args, **kwargs):
137+
def __init__(self, *args, **kwargs) -> None:
138138
...
139139

140140
@property

0 commit comments

Comments
 (0)