Skip to content

Commit 4a030f2

Browse files
committed
excempt some APIs cython annotation typing
1 parent c4bd0ce commit 4a030f2

6 files changed

Lines changed: 22 additions & 3 deletions

File tree

cuda_core/cuda/core/_context.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ from collections.abc import Sequence
88
from dataclasses import dataclass
99
from typing import TYPE_CHECKING
1010

11+
import cython
12+
1113
from cuda.bindings cimport cydriver
1214
from cuda.core._device_resources cimport DeviceResources, SMResource, WorkqueueResource
1315
from cuda.core._device_resources import SMResource, WorkqueueResource
@@ -99,6 +101,7 @@ cdef class Context:
99101
Context_check_open(self)
100102
return DeviceResources._init_from_ctx(self._h_context, self._device_id)
101103

104+
@cython.annotation_typing(False)
102105
def create_stream(self, options: StreamOptions | None = None) -> Stream:
103106
"""Create a new stream bound to this green context.
104107

cuda_core/cuda/core/_memory/_device_memory_resource.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ from cuda.core._utils.cuda_utils cimport (
2020
check_or_create_options,
2121
HANDLE_RETURN,
2222
)
23+
24+
import cython
2325
from dataclasses import dataclass
2426
import multiprocessing
2527
import platform # no-cython-lint
@@ -146,10 +148,11 @@ cdef class DeviceMemoryResource(_MemPool):
146148
def __cinit__(self, *args, **kwargs) -> None:
147149
self._dev_id = cydriver.CU_DEVICE_INVALID
148150

151+
@cython.annotation_typing(False)
149152
def __init__(
150153
self,
151154
device_id: Device | int,
152-
options=None
155+
options: DeviceMemoryResourceOptions | None = None
153156
) -> None:
154157
_DMR_init(self, device_id, options)
155158

cuda_core/cuda/core/_memory/_managed_memory_resource.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from cuda.core._utils.cuda_utils cimport HANDLE_RETURN
1313
from cuda.core._utils.cuda_utils cimport check_or_create_options # no-cython-lint
1414
from cuda.core._utils.cuda_utils import CUDAError # no-cython-lint
1515

16+
import cython
1617
from dataclasses import dataclass
1718
import threading
1819
from typing import TYPE_CHECKING
@@ -97,7 +98,8 @@ cdef class ManagedMemoryResource(_MemPool):
9798
memory pools.
9899
"""
99100

100-
def __init__(self, options=None) -> None:
101+
@cython.annotation_typing(False)
102+
def __init__(self, options: ManagedMemoryResourceOptions | None = None) -> None:
101103
_MMR_init(self, options)
102104

103105
def allocate(self, size_t size, *, stream: Stream | GraphBuilder) -> ManagedBuffer:

cuda_core/cuda/core/_memory/_pinned_memory_resource.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ from cuda.core._utils.cuda_utils cimport (
2121
HANDLE_RETURN,
2222
)
2323

24+
import cython
2425
from dataclasses import dataclass
2526
import multiprocessing
2627
import platform # no-cython-lint
@@ -109,7 +110,8 @@ cdef class PinnedMemoryResource(_MemPool):
109110
See :class:`DeviceMemoryResource` for more details on IPC usage patterns.
110111
"""
111112

112-
def __init__(self, options=None) -> None:
113+
@cython.annotation_typing(False)
114+
def __init__(self, options: PinnedMemoryResourceOptions | None = None) -> None:
113115
_PMR_init(self, options)
114116

115117
def allocate(self, size_t size, *, stream: Stream | GraphBuilder) -> Buffer:

cuda_core/cuda/core/_stream.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ cdef class Stream:
123123
return Stream._from_handle(cls, get_per_thread_stream())
124124

125125
@classmethod
126+
@cython.annotation_typing(False)
126127
def _init(cls, obj: IsStreamType | None = None, options: StreamOptions | None = None,
127128
device_id: int | None = None, ctx: Context | None = None) -> Stream:
128129
cdef StreamHandle h_stream

cuda_core/tests/test_stream.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ def test_stream_init_with_options(init_cuda):
2828
assert stream.priority == 0
2929

3030

31+
@pytest.mark.agent_authored(model="glm-5.2")
32+
def test_stream_init_with_dict_options(init_cuda):
33+
"""Device.create_stream accepts a plain dict for options (backward compat)."""
34+
stream = Device().create_stream(options={"nonblocking": True, "priority": 0})
35+
assert stream.is_nonblocking is True
36+
assert stream.priority == 0
37+
38+
3139
def test_stream_handle(init_cuda):
3240
stream = Device().create_stream(options=StreamOptions())
3341
assert isinstance(stream.handle, driver.CUstream)

0 commit comments

Comments
 (0)