Skip to content

Commit 1086f40

Browse files
authored
Fix Cython compilation warnings in cuda.core (#1834)
- cimport Buffer and MemoryResource into _device.pyx to resolve unknown type annotations - Quote forward-reference annotations (Graph, LinkerOptions, DevicePointerT) that Cython cannot resolve at compile time - Remove duplicate MRDeallocCallback ctypedef from _resource_handles.pyx (already declared in .pxd) Made-with: Cursor
1 parent fce6c5c commit 1086f40

File tree

6 files changed

+6
-8
lines changed

6 files changed

+6
-8
lines changed

cuda_core/cuda/core/_device.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ from cuda.core._context cimport Context
1616
from cuda.core._context import ContextOptions
1717
from cuda.core._event cimport Event as cyEvent
1818
from cuda.core._event import Event, EventOptions
19+
from cuda.core._memory._buffer cimport Buffer, MemoryResource
1920
from cuda.core._resource_handles cimport (
2021
ContextHandle,
2122
create_context_handle_ref,

cuda_core/cuda/core/_graph/_graph_builder.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class GraphCompleteOptions:
140140
use_node_priority: bool = False
141141

142142

143-
def _instantiate_graph(h_graph, options: GraphCompleteOptions | None = None) -> Graph:
143+
def _instantiate_graph(h_graph, options: GraphCompleteOptions | None = None) -> "Graph":
144144
params = driver.CUDA_GRAPH_INSTANTIATE_PARAMS()
145145
if options:
146146
flags = 0
@@ -322,7 +322,7 @@ class GraphBuilder:
322322
self._building_ended = True
323323
return self
324324

325-
def complete(self, options: GraphCompleteOptions | None = None) -> Graph:
325+
def complete(self, options: GraphCompleteOptions | None = None) -> "Graph":
326326
"""Completes the graph builder and returns the built :obj:`~_graph.Graph` object.
327327

328328
Parameters

cuda_core/cuda/core/_linker.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ cdef class Linker:
6767
Options for the linker. If not provided, default options will be used.
6868
"""
6969

70-
def __init__(self, *object_codes: ObjectCode, options: LinkerOptions = None):
70+
def __init__(self, *object_codes: ObjectCode, options: "LinkerOptions" = None):
7171
Linker_init(self, object_codes, options)
7272

7373
def link(self, target_type) -> ObjectCode:

cuda_core/cuda/core/_memory/_graph_memory_resource.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ cdef class cyGraphMemoryResource(MemoryResource):
111111
stream = Stream_accept(stream) if stream is not None else default_stream()
112112
return GMR_allocate(self, size, <Stream> stream)
113113

114-
def deallocate(self, ptr: DevicePointerT, size_t size, stream: Stream | GraphBuilder | None = None):
114+
def deallocate(self, ptr: "DevicePointerT", size_t size, stream: Stream | GraphBuilder | None = None):
115115
"""
116116
Deallocate a buffer of the requested size. See documentation for :obj:`~_memory.MemoryResource`.
117117
"""

cuda_core/cuda/core/_memory/_memory_pool.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ cdef class _MemPool(MemoryResource):
144144
stream = Stream_accept(stream) if stream is not None else default_stream()
145145
return _MP_allocate(self, size, <Stream> stream)
146146

147-
def deallocate(self, ptr: DevicePointerT, size_t size, stream: Stream | GraphBuilder | None = None):
147+
def deallocate(self, ptr: "DevicePointerT", size_t size, stream: Stream | GraphBuilder | None = None):
148148
"""Deallocate a buffer previously allocated by this resource.
149149
150150
Parameters

cuda_core/cuda/core/_resource_handles.pyx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ cdef extern from "_cpp/resource_handles.hpp" namespace "cuda_core":
120120
const StreamHandle& h_stream) except+ nogil
121121

122122
# MR deallocation callback
123-
ctypedef void (*MRDeallocCallback)(
124-
object mr, cydriver.CUdeviceptr ptr, size_t size,
125-
const StreamHandle& stream) noexcept
126123
void register_mr_dealloc_callback "cuda_core::register_mr_dealloc_callback" (
127124
MRDeallocCallback cb) noexcept
128125
DevicePtrHandle deviceptr_create_with_mr "cuda_core::deviceptr_create_with_mr" (

0 commit comments

Comments
 (0)