Skip to content

Commit 4255902

Browse files
committed
cuda.core: preserve memory pool CUDA errors
1 parent 8869a26 commit 4255902

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎cuda_core/cuda/core/_memory/_device_memory_resource.pyx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from cuda.core._memory._ipc cimport IPCAllocationHandle
1313
from cuda.core._resource_handles cimport (
1414
as_cu,
1515
get_device_mempool,
16+
get_last_error,
1617
)
1718
from cuda.core._utils.cuda_utils cimport (
1819
check_or_create_options,
@@ -262,6 +263,9 @@ cdef inline _DMR_init(DeviceMemoryResource self, device_id, options):
262263

263264
if opts is None:
264265
self._h_pool = get_device_mempool(dev_id)
266+
if not self._h_pool:
267+
HANDLE_RETURN(get_last_error())
268+
raise RuntimeError("Expected CUDA error was not recorded after get_device_mempool returned an empty handle")
265269
self._mempool_owned = False
266270
MP_raise_release_threshold(self)
267271
else:

‎cuda_core/cuda/core/_memory/_graph_memory_resource.pyx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from cuda.core._memory._buffer cimport Buffer, Buffer_from_deviceptr_handle, Mem
1111
from cuda.core._resource_handles cimport (
1212
DevicePtrHandle,
1313
deviceptr_alloc_async,
14+
get_last_error,
1415
as_cu,
1516
)
1617

@@ -194,7 +195,8 @@ cdef inline Buffer GMR_allocate(cyGraphMemoryResource self, size_t size, Stream
194195
check_capturing(s)
195196
h_ptr = deviceptr_alloc_async(size, stream._h_stream)
196197
if not h_ptr:
197-
raise RuntimeError("Failed to allocate memory asynchronously")
198+
HANDLE_RETURN(get_last_error())
199+
raise RuntimeError("Expected CUDA error was not recorded after deviceptr_alloc_async returned an empty handle")
198200
return Buffer_from_deviceptr_handle(h_ptr, size, self, None)
199201

200202

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ cdef _MemPool MP_from_allocation_handle(cls, alloc_handle):
211211
cdef int ipc_fd = int(alloc_handle)
212212
self._h_pool = create_mempool_handle_ipc(ipc_fd, IPC_HANDLE_TYPE)
213213
if not self._h_pool:
214-
raise RuntimeError("Failed to import memory pool from IPC handle")
214+
HANDLE_RETURN(get_last_error())
215+
raise RuntimeError("Expected CUDA error was not recorded after create_mempool_handle_ipc returned an empty handle")
215216
self._ipc_data = IPCDataForMR(alloc_handle, True)
216217

217218
# Register it.

‎cuda_core/cuda/core/_memory/_memory_pool.pyx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ from cuda.core._resource_handles cimport (
1717
DevicePtrHandle,
1818
create_mempool_handle,
1919
deviceptr_alloc_from_pool,
20+
get_last_error,
2021
as_cu,
2122
as_py,
2223
)
@@ -228,6 +229,9 @@ cdef int MP_init_create_pool(
228229

229230
self._mempool_owned = True
230231
self._h_pool = create_mempool_handle(properties)
232+
if not self._h_pool:
233+
HANDLE_RETURN(get_last_error())
234+
raise RuntimeError("Expected CUDA error was not recorded after create_mempool_handle returned an empty handle")
231235

232236
if ipc_enabled:
233237
alloc_handle = _ipc.MP_export_mempool(self)
@@ -307,7 +311,8 @@ cdef inline Buffer _MP_allocate(_MemPool self, size_t size, Stream stream):
307311
check_not_capturing(s)
308312
h_ptr = deviceptr_alloc_from_pool(size, self._h_pool, stream._h_stream)
309313
if not h_ptr:
310-
raise RuntimeError("Failed to allocate memory from pool")
314+
HANDLE_RETURN(get_last_error())
315+
raise RuntimeError("Expected CUDA error was not recorded after deviceptr_alloc_from_pool returned an empty handle")
311316
return Buffer_from_deviceptr_handle(h_ptr, size, self, None)
312317

313318

0 commit comments

Comments
 (0)