@@ -71,11 +71,22 @@ import numpy as np
7171__all__ = [
7272 " MemoryUSMShared" ,
7373 " MemoryUSMHost" ,
74- " MemoryUSMDevice"
74+ " MemoryUSMDevice" ,
75+ " USMAllocationError" ,
7576]
7677
7778include " _sycl_usm_array_interface_utils.pxi"
7879
80+ class USMAllocationError (Exception ):
81+ """
82+ An exception raised when Universal Shared Memory (USM) allocation
83+ call returns a null pointer, signaling a failure to perform the allocation.
84+ Some common reasons for allocation failure are:
85+ * insufficient free memory to perform the allocation request
86+ * allocation size exceeds the maximum supported by targeted backend
87+ """
88+ pass
89+
7990
8091cdef void copy_via_host(void * dest_ptr, SyclQueue dest_queue,
8192 void * src_ptr, SyclQueue src_queue, size_t nbytes):
@@ -177,7 +188,7 @@ cdef class _Memory:
177188 with nogil: p = DPCTLmalloc_device(nbytes, QRef)
178189 else :
179190 raise RuntimeError (
180- " Pointer type is unknown: {} " .format(
191+ " Pointer type '{}' is not recognized " .format(
181192 ptr_type.decode(" UTF-8" )
182193 )
183194 )
@@ -187,9 +198,13 @@ cdef class _Memory:
187198 self .nbytes = nbytes
188199 self .queue = queue
189200 else :
190- raise RuntimeError (" Null memory pointer returned" )
201+ raise USMAllocationError(
202+ " USM allocation failed"
203+ )
191204 else :
192- raise ValueError (" Non-positive number of bytes found." )
205+ raise ValueError (
206+ " Number of bytes of request allocation must be positive."
207+ )
193208
194209 cdef _cinit_other(self , object other):
195210 cdef _Memory other_mem
0 commit comments