@@ -71,11 +71,22 @@ import numpy as np
71
71
__all__ = [
72
72
" MemoryUSMShared" ,
73
73
" MemoryUSMHost" ,
74
- " MemoryUSMDevice"
74
+ " MemoryUSMDevice" ,
75
+ " USMAllocationError" ,
75
76
]
76
77
77
78
include " _sycl_usm_array_interface_utils.pxi"
78
79
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
+
79
90
80
91
cdef void copy_via_host(void * dest_ptr, SyclQueue dest_queue,
81
92
void * src_ptr, SyclQueue src_queue, size_t nbytes):
@@ -177,7 +188,7 @@ cdef class _Memory:
177
188
with nogil: p = DPCTLmalloc_device(nbytes, QRef)
178
189
else :
179
190
raise RuntimeError (
180
- " Pointer type is unknown: {} " .format(
191
+ " Pointer type '{}' is not recognized " .format(
181
192
ptr_type.decode(" UTF-8" )
182
193
)
183
194
)
@@ -187,9 +198,13 @@ cdef class _Memory:
187
198
self .nbytes = nbytes
188
199
self .queue = queue
189
200
else :
190
- raise RuntimeError (" Null memory pointer returned" )
201
+ raise USMAllocationError(
202
+ " USM allocation failed"
203
+ )
191
204
else :
192
- raise ValueError (" Non-positive number of bytes found." )
205
+ raise ValueError (
206
+ " Number of bytes of request allocation must be positive."
207
+ )
193
208
194
209
cdef _cinit_other(self , object other):
195
210
cdef _Memory other_mem
0 commit comments