Skip to content

Commit ec7982b

Browse files
authored
Merge pull request #1022 from 0x12CC/l0_usm_error_checking_2
[UR][L0] Propagate OOM errors from `USMAllocationMakeResident`
2 parents 62e6d2f + 5fb8292 commit ec7982b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

source/adapters/level_zero/usm.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,14 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr,
192192
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0,
193193
UR_RESULT_ERROR_INVALID_VALUE);
194194

195-
USMAllocationMakeResident(USMDeviceAllocationForceResidency, Context, Device,
196-
*ResultPtr, Size);
195+
// TODO: Return any non-success result from USMAllocationMakeResident once
196+
// oneapi-src/level-zero-spec#240 is resolved.
197+
auto Result = USMAllocationMakeResident(USMDeviceAllocationForceResidency,
198+
Context, Device, *ResultPtr, Size);
199+
if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY ||
200+
Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) {
201+
return Result;
202+
}
197203
return UR_RESULT_SUCCESS;
198204
}
199205

@@ -225,8 +231,14 @@ static ur_result_t USMSharedAllocImpl(void **ResultPtr,
225231
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0,
226232
UR_RESULT_ERROR_INVALID_VALUE);
227233

228-
USMAllocationMakeResident(USMSharedAllocationForceResidency, Context, Device,
229-
*ResultPtr, Size);
234+
// TODO: Return any non-success result from USMAllocationMakeResident once
235+
// oneapi-src/level-zero-spec#240 is resolved.
236+
auto Result = USMAllocationMakeResident(USMSharedAllocationForceResidency,
237+
Context, Device, *ResultPtr, Size);
238+
if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY ||
239+
Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) {
240+
return Result;
241+
}
230242

231243
// TODO: Handle PI_MEM_ALLOC_DEVICE_READ_ONLY.
232244
return UR_RESULT_SUCCESS;
@@ -247,8 +259,14 @@ static ur_result_t USMHostAllocImpl(void **ResultPtr,
247259
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0,
248260
UR_RESULT_ERROR_INVALID_VALUE);
249261

250-
USMAllocationMakeResident(USMHostAllocationForceResidency, Context, nullptr,
251-
*ResultPtr, Size);
262+
// TODO: Return any non-success result from USMAllocationMakeResident once
263+
// oneapi-src/level-zero-spec#240 is resolved.
264+
auto Result = USMAllocationMakeResident(USMHostAllocationForceResidency,
265+
Context, nullptr, *ResultPtr, Size);
266+
if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY ||
267+
Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) {
268+
return Result;
269+
}
252270
return UR_RESULT_SUCCESS;
253271
}
254272

0 commit comments

Comments
 (0)