Skip to content

Commit 7315e28

Browse files
committed
Rename _mr to _memory_resource. Change pointer types from intptr_t to uintptr_t.
1 parent 567ea2c commit 7315e28

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

cuda_core/cuda/core/experimental/_memory/_buffer.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
from libc.stdint cimport intptr_t
5+
from libc.stdint cimport uintptr_t
66

77
from cuda.core.experimental._stream cimport Stream
88

99

1010
cdef class Buffer:
1111
cdef:
12-
intptr_t _ptr
12+
uintptr_t _ptr
1313
size_t _size
14-
MemoryResource _mr
14+
MemoryResource _memory_resource
1515
object _ptr_obj
1616
Stream _alloc_stream
1717

cuda_core/cuda/core/experimental/_memory/_buffer.pyx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from __future__ import annotations
66

7-
from libc.stdint cimport intptr_t
7+
from libc.stdint cimport uintptr_t
88

99
from cuda.core.experimental._memory._dmr cimport DeviceMemoryResource
1010
from cuda.core.experimental._memory._ipc cimport IPCBufferDescriptor
@@ -44,7 +44,7 @@ cdef class Buffer:
4444
def _clear(self):
4545
self._ptr = 0
4646
self._size = 0
47-
self._mr = None
47+
self._memory_resource = None
4848
self._ptr_obj = None
4949
self._alloc_stream = None
5050

@@ -58,10 +58,10 @@ cdef class Buffer:
5858
stream: Stream | None = None
5959
):
6060
cdef Buffer self = Buffer.__new__(cls)
61-
self._ptr = <intptr_t>(int(ptr))
61+
self._ptr = <uintptr_t>(int(ptr))
6262
self._ptr_obj = ptr
6363
self._size = size
64-
self._mr = mr
64+
self._memory_resource = mr
6565
self._alloc_stream = <Stream>(stream) if stream is not None else None
6666
return self
6767

@@ -138,10 +138,10 @@ cdef class Buffer:
138138
cdef size_t src_size = self._size
139139

140140
if dst is None:
141-
if self._mr is None:
141+
if self._memory_resource is None:
142142
raise ValueError("a destination buffer must be provided (this "
143143
"buffer does not have a memory_resource)")
144-
dst = self._mr.allocate(src_size, stream)
144+
dst = self._memory_resource.allocate(src_size, stream)
145145

146146
cdef size_t dst_size = dst._size
147147
if dst_size != src_size:
@@ -226,8 +226,8 @@ cdef class Buffer:
226226
@property
227227
def device_id(self) -> int:
228228
"""Return the device ordinal of this buffer."""
229-
if self._mr is not None:
230-
return self._mr.device_id
229+
if self._memory_resource is not None:
230+
return self._memory_resource.device_id
231231
raise NotImplementedError("WIP: Currently this property only supports buffers with associated MemoryResource")
232232

233233
@property
@@ -250,21 +250,21 @@ cdef class Buffer:
250250
@property
251251
def is_device_accessible(self) -> bool:
252252
"""Return True if this buffer can be accessed by the GPU, otherwise False."""
253-
if self._mr is not None:
254-
return self._mr.is_device_accessible
253+
if self._memory_resource is not None:
254+
return self._memory_resource.is_device_accessible
255255
raise NotImplementedError("WIP: Currently this property only supports buffers with associated MemoryResource")
256256

257257
@property
258258
def is_host_accessible(self) -> bool:
259259
"""Return True if this buffer can be accessed by the CPU, otherwise False."""
260-
if self._mr is not None:
261-
return self._mr.is_host_accessible
260+
if self._memory_resource is not None:
261+
return self._memory_resource.is_host_accessible
262262
raise NotImplementedError("WIP: Currently this property only supports buffers with associated MemoryResource")
263263

264264
@property
265265
def memory_resource(self) -> MemoryResource:
266266
"""Return the memory resource associated with this buffer."""
267-
return self._mr
267+
return self._memory_resource
268268

269269
@property
270270
def size(self) -> int:
@@ -276,7 +276,7 @@ cdef class Buffer:
276276
# ---------------------
277277
cdef Buffer_close(Buffer self, stream):
278278
cdef Stream s
279-
if self._ptr and self._mr is not None:
279+
if self._ptr and self._memory_resource is not None:
280280
if stream is None:
281281
if self._alloc_stream is not None:
282282
s = self._alloc_stream
@@ -285,9 +285,9 @@ cdef Buffer_close(Buffer self, stream):
285285
s = <Stream>(default_stream())
286286
else:
287287
s = <Stream>stream
288-
self._mr.deallocate(self._ptr, self._size, s)
288+
self._memory_resource.deallocate(self._ptr, self._size, s)
289289
self._ptr = 0
290-
self._mr = None
290+
self._memory_resource = None
291291
self._ptr_obj = None
292292
self._alloc_stream = None
293293

cuda_core/cuda/core/experimental/_memory/_dmr.pyx

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

77
from libc.limits cimport ULLONG_MAX
8-
from libc.stdint cimport uintptr_t, intptr_t
8+
from libc.stdint cimport uintptr_t
99
from libc.string cimport memset
1010

1111
from cuda.bindings cimport cydriver
@@ -339,7 +339,7 @@ cdef class DeviceMemoryResource(MemoryResource):
339339
If the buffer is deallocated without an explicit stream, the allocation stream
340340
is used.
341341
"""
342-
DMR_deallocate(self, <intptr_t>ptr, size, <Stream>stream)
342+
DMR_deallocate(self, <uintptr_t>ptr, size, <Stream>stream)
343343

344344
@property
345345
def attributes(self) -> DeviceMemoryResourceAttributes:
@@ -466,16 +466,16 @@ cdef Buffer DMR_allocate(DeviceMemoryResource self, size_t size, Stream stream):
466466
with nogil:
467467
HANDLE_RETURN(cydriver.cuMemAllocFromPoolAsync(&devptr, size, self._handle, s))
468468
cdef Buffer buf = Buffer.__new__(Buffer)
469-
buf._ptr = <intptr_t>(devptr)
469+
buf._ptr = <uintptr_t>(devptr)
470470
buf._ptr_obj = None
471471
buf._size = size
472-
buf._mr = self
472+
buf._memory_resource = self
473473
buf._alloc_stream = stream
474474
return buf
475475

476476

477477
cdef void DMR_deallocate(
478-
DeviceMemoryResource self, intptr_t ptr, size_t size, Stream stream
478+
DeviceMemoryResource self, uintptr_t ptr, size_t size, Stream stream
479479
) noexcept:
480480
cdef cydriver.CUstream s = stream._handle
481481
cdef cydriver.CUdeviceptr devptr = <cydriver.CUdeviceptr>ptr

cuda_core/cuda/core/experimental/_memory/_ipc.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
cimport cpython
6-
from libc.stdint cimport intptr_t
6+
from libc.stdint cimport uintptr_t
77
from libc.string cimport memcpy
88

99
from cuda.bindings cimport cydriver
@@ -142,7 +142,7 @@ multiprocessing.reduction.register(DeviceMemoryResource, _deep_reduce_device_mem
142142
# Buffer IPC Implementation
143143
# -------------------------
144144
cdef IPCBufferDescriptor Buffer_get_ipc_descriptor(Buffer self):
145-
if not self._mr.is_ipc_enabled:
145+
if not self.memory_resource.is_ipc_enabled:
146146
raise RuntimeError("Memory resource is not IPC-enabled")
147147
cdef cydriver.CUmemPoolPtrExportData data
148148
with nogil:
@@ -172,7 +172,7 @@ cdef Buffer Buffer_from_ipc_descriptor(
172172
cdef cydriver.CUdeviceptr ptr
173173
with nogil:
174174
HANDLE_RETURN(cydriver.cuMemPoolImportPointer(&ptr, mr._handle, &data))
175-
return Buffer._init(<intptr_t>ptr, ipc_buffer.size, mr, stream)
175+
return Buffer._init(<uintptr_t>ptr, ipc_buffer.size, mr, stream)
176176

177177

178178
# DeviceMemoryResource IPC Implementation
@@ -205,7 +205,7 @@ cdef DeviceMemoryResource DMR_from_allocation_handle(cls, device_id, alloc_handl
205205
cdef int handle = int(alloc_handle)
206206
with nogil:
207207
HANDLE_RETURN(cydriver.cuMemPoolImportFromShareableHandle(
208-
&(self._handle), <void*><intptr_t>(handle), IPC_HANDLE_TYPE, 0)
208+
&(self._handle), <void*><uintptr_t>(handle), IPC_HANDLE_TYPE, 0)
209209
)
210210

211211
# Register it.

0 commit comments

Comments
 (0)