Skip to content

Commit f9df16f

Browse files
authored
Memory refactor (#1205)
* Resolve a Cython build warning. * Make memory module into a package. * Rename cyStream to _cyStream for consistency. * Move defs to memory.pxd header * Separate VMM. * Weaken dependencies from device to memory module. * Move LegacyPinnedMemoryResource to a submodule. * Move _SynchronousMemoryResource into a submodule. * Partly separates the IPC implementation. * Move IPC registry to ipc module. * Collect and reorder DeviceMemoryResource properties. * Move more IPC implementation out of DeviceMemoryResource. * Minor refactoring. * Move Buffer IPC implementation. * Simplify the class hierarchy (remove _cyBuffer and _cyMemoryResource). * Refactor to shrink Cython interface. * Simplify Buffer close. * Refactor DeviceMemoryResource.__init__. * Move Buffer into a separate module. * Refactors DeviceMemoryResource IPC implementation. * Removes superfluous _uuid member of DeviceMemoryResource. * Adds __all__ lists. * Prepend underscore to submodules, add a test for package contents. * Refactor IPC data of DMR into IPCData class. * General clean up. * Touch-ups * Cythonize DeviceMemoryResourceAttributes. * Restore previous behavior for DMR.from_allocation_handle when passed a file descriptor (caller closes the fd). * Rename _mr to _memory_resource. Change pointer types from intptr_t to uintptr_t. * Rename files _dmr.* and _vmm.py to avoid abbreviations.
1 parent 3e0d883 commit f9df16f

File tree

15 files changed

+1929
-1618
lines changed

15 files changed

+1929
-1618
lines changed

cuda_core/cuda/core/experimental/_device.pyx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ cimport cpython
66
from libc.stdint cimport uintptr_t
77

88
from cuda.bindings cimport cydriver
9-
109
from cuda.core.experimental._utils.cuda_utils cimport HANDLE_RETURN
1110

1211
import threading
13-
from typing import Union
12+
from typing import Union, TYPE_CHECKING
1413

1514
from cuda.core.experimental._context import Context, ContextOptions
1615
from cuda.core.experimental._event import Event, EventOptions
1716
from cuda.core.experimental._graph import GraphBuilder
18-
from cuda.core.experimental._memory import Buffer, DeviceMemoryResource, MemoryResource, _SynchronousMemoryResource
1917
from cuda.core.experimental._stream import IsStreamT, Stream, StreamOptions
2018
from cuda.core.experimental._utils.clear_error_support import assert_type
2119
from cuda.core.experimental._utils.cuda_utils import (
@@ -27,7 +25,8 @@ from cuda.core.experimental._utils.cuda_utils import (
2725
)
2826
from cuda.core.experimental._stream cimport default_stream
2927

30-
28+
if TYPE_CHECKING:
29+
from cuda.core.experimental._memory import Buffer, MemoryResource
3130

3231
# TODO: I prefer to type these as "cdef object" and avoid accessing them from within Python,
3332
# but it seems it is very convenient to expose them for testing purposes...
@@ -996,8 +995,10 @@ class Device:
996995
)
997996
)
998997
if attr == 1:
998+
from cuda.core.experimental._memory import DeviceMemoryResource
999999
device._mr = DeviceMemoryResource(dev_id)
10001000
else:
1001+
from cuda.core.experimental._memory import _SynchronousMemoryResource
10011002
device._mr = _SynchronousMemoryResource(dev_id)
10021003

10031004
device._has_inited = False
@@ -1131,6 +1132,7 @@ class Device:
11311132

11321133
@memory_resource.setter
11331134
def memory_resource(self, mr):
1135+
from cuda.core.experimental._memory import MemoryResource
11341136
assert_type(mr, MemoryResource)
11351137
self._mr = mr
11361138

cuda_core/cuda/core/experimental/_event.pyx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ from __future__ import annotations
77
cimport cpython
88
from libc.stdint cimport uintptr_t
99
from libc.string cimport memcpy
10-
1110
from cuda.bindings cimport cydriver
12-
1311
from cuda.core.experimental._utils.cuda_utils cimport (
1412
check_or_create_options,
1513
HANDLE_RETURN
1614
)
1715

16+
import cython
1817
from dataclasses import dataclass
1918
import multiprocessing
2019
from typing import TYPE_CHECKING, Optional
@@ -287,7 +286,7 @@ cdef class IPCEventDescriptor:
287286
raise RuntimeError("IPCEventDescriptor objects cannot be instantiated directly. Please use Event APIs.")
288287

289288
@classmethod
290-
def _init(cls, reserved: bytes, busy_waited: bint):
289+
def _init(cls, reserved: bytes, busy_waited: cython.bint):
291290
cdef IPCEventDescriptor self = IPCEventDescriptor.__new__(cls)
292291
self._reserved = reserved
293292
self._busy_waited = busy_waited

0 commit comments

Comments
 (0)