@@ -263,37 +263,36 @@ cdef int _raise_last_error() except -1:
263263 )
264264
265265
266- cdef inline int _attach_note(exc, str detail) except - 1 :
267- # PEP 678 notes (Python 3.11+) keep the detail separable from the message;
268- # older interpreters get it appended to the message instead.
269- add_note = getattr (exc, " add_note" , None )
270- if add_note is not None :
271- add_note(detail)
272- else :
273- exc.args = (f" {exc.args[0]} ({detail})" , * exc.args[1 :])
274- return 0
275-
276-
277266cdef int _raise_last_error_noting(str detail) except - 1 :
278267 """ Raise the status a handle factory recorded, with ``detail`` attached as a note."""
279268 try :
280269 _raise_last_error()
281270 except Exception as exc:
282- _attach_note( exc, detail)
271+ exc.add_note( detail)
283272 raise
284273 return 0
285274
286275
287- cdef int _raise_allocation_error(const cydriver.CUmemAllocationProp* prop) except - 1 :
288- """ Raise the status of a failed physical allocation; a fabric resource gets the IMEX note."""
289- if prop.requestedHandleTypes == cydriver.CU_MEM_HANDLE_TYPE_FABRIC:
290- _raise_last_error_noting(
276+ cdef int _raise_allocation_error(
277+ cydriver.CUresult status, cydriver.CUmemAllocationHandleType requested_handle_types
278+ ) except - 1 :
279+ """ Raise a physical-allocation failure, noting possible fabric configuration errors."""
280+ if (requested_handle_types == cydriver.CU_MEM_HANDLE_TYPE_FABRIC
281+ and status in (cydriver.CUDA_ERROR_NOT_PERMITTED,
282+ cydriver.CUDA_ERROR_NOT_SUPPORTED,
283+ cydriver.CUDA_ERROR_INVALID_VALUE)):
284+ _check_noting(
285+ status,
291286 " while creating a physical allocation with a fabric handle; fabric handles need an NVLink fabric "
292287 " and an accessible IMEX channel, and a device can report support while the allocation is refused "
293288 " (the attribute does not check for an NVLink fabric, and older drivers do not check for an IMEX "
294289 " channel)"
295290 )
296- return _raise_last_error()
291+ HANDLE_RETURN(status)
292+ raise RuntimeError (
293+ " internal cuda.core error, please report: a physical allocation factory "
294+ " returned an empty handle without recording a CUDA error"
295+ )
297296
298297
299298cdef int _check_noting(cydriver.CUresult status, str detail) except - 1 :
@@ -303,7 +302,7 @@ cdef int _check_noting(cydriver.CUresult status, str detail) except -1:
303302 try :
304303 HANDLE_RETURN(status)
305304 except Exception as exc:
306- _attach_note( exc, detail)
305+ exc.add_note( detail)
307306 raise
308307 return 0
309308
@@ -740,7 +739,7 @@ cdef class VirtualMemoryResource(MemoryResource):
740739 with nogil:
741740 h_alloc = create_mem_allocation_handle(aligned, prop, descs.data(), descs.size())
742741 if not h_alloc:
743- _raise_allocation_error(& prop)
742+ _raise_allocation_error(get_last_error(), prop.requestedHandleTypes )
744743 with nogil:
745744 h_res = create_va_reservation_handle(aligned, addr_align, hint)
746745 if not h_res:
@@ -893,7 +892,7 @@ cdef class VirtualMemoryResource(MemoryResource):
893892 with nogil:
894893 h_alloc = create_mem_allocation_handle(add, prop, descs.data(), descs.size())
895894 if not h_alloc:
896- _raise_allocation_error(& prop)
895+ _raise_allocation_error(get_last_error(), prop.requestedHandleTypes )
897896 with nogil:
898897 h_map = create_va_mapping_handle(base + total, h_alloc, h_res)
899898 if not h_map:
@@ -926,7 +925,7 @@ cdef class VirtualMemoryResource(MemoryResource):
926925 with nogil:
927926 h_alloc = create_mem_allocation_handle(add, prop, descs.data(), descs.size())
928927 if not h_alloc:
929- _raise_allocation_error(& prop)
928+ _raise_allocation_error(get_last_error(), prop.requestedHandleTypes )
930929 with nogil:
931930 m2 = create_va_mapping_handle(base_new + offset, h_alloc, h_res_new)
932931 if not m2:
@@ -1044,7 +1043,7 @@ cdef class VirtualMemoryResource(MemoryResource):
10441043 if not self.is_ipc_enabled:
10451044 raise RuntimeError("Memory resource is not IPC-enabled")
10461045 handle_type = int(VirtualMemoryResourceOptions._handle_type_to_driver(cfg.handle_type))
1047- if desc._handle_type != handle_type:
1046+ if desc.driver_handle_type() != handle_type:
10481047 raise ValueError(
10491048 "the descriptor's handle type does not match this resource's "
10501049 f"handle_type={str(cfg.handle_type)!r}; import it with a resource configured like the exporter's"
@@ -1282,4 +1281,4 @@ cdef _VirtualMemoryDescriptor _export_ipc_descriptor(Buffer buf):
12821281 if handle_type == < int > cydriver.CU_MEM_HANDLE_TYPE_FABRIC:
12831282 return VirtualMemoryFabricBufferDescriptor._from_exports(
12841283 tuple (sizes), tuple (handles), buf._size, mr.device.uuid)
1285- return VirtualMemoryFdBufferDescriptor._from_exports(handle_type, tuple (sizes), tuple (handles), buf._size)
1284+ return VirtualMemoryFdBufferDescriptor._from_exports(tuple (sizes), tuple (handles), buf._size)
0 commit comments