Skip to content

Commit 0e2d8ea

Browse files
committed
[L0 v2] do not use usm pool free for native handles
as they can be allocated by the user using L0 API directly (and then UMF will not know about those pointers and umfFree will do nothing).
1 parent c6a3b6d commit 0e2d8ea

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

source/adapters/level_zero/v2/memory.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ ur_integrated_mem_handle_t::ur_integrated_mem_handle_t(
115115
if (!ownHostPtr) {
116116
return;
117117
}
118-
auto ret = hContext->getDefaultUSMPool()->free(ptr);
119-
if (ret != UR_RESULT_SUCCESS) {
120-
logger::error("Failed to free host memory: {}", ret);
121-
}
118+
ZE_CALL_NOCHECK(zeMemFree, (hContext->getZeHandle(), ptr));
122119
});
123120
}
124121

@@ -234,10 +231,7 @@ ur_discrete_mem_handle_t::ur_discrete_mem_handle_t(
234231
if (!ownZePtr) {
235232
return;
236233
}
237-
auto ret = hContext->getDefaultUSMPool()->free(ptr);
238-
if (ret != UR_RESULT_SUCCESS) {
239-
logger::error("Failed to free device memory: {}", ret);
240-
}
234+
ZE_CALL_NOCHECK(zeMemFree, (hContext->getZeHandle(), ptr));
241235
});
242236
}
243237
}
@@ -310,7 +304,10 @@ void *ur_discrete_mem_handle_t::mapHostPtr(
310304
usm_unique_ptr_t mappedPtr =
311305
usm_unique_ptr_t(ptr, [ownsAlloc = bool(mapToPtr), this](void *p) {
312306
if (ownsAlloc) {
313-
UR_CALL_THROWS(hContext->getDefaultUSMPool()->free(p));
307+
auto ret = hContext->getDefaultUSMPool()->free(p);
308+
if (ret != UR_RESULT_SUCCESS) {
309+
logger::error("Failed to mapped memory: {}", ret);
310+
}
314311
}
315312
});
316313

source/adapters/level_zero/v2/usm.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,13 @@ ur_result_t ur_usm_pool_handle_t_::allocate(
291291
}
292292

293293
ur_result_t ur_usm_pool_handle_t_::free(void *ptr) {
294-
return umf::umf2urResult(umfFree(ptr));
294+
auto umfPool = umfPoolByPtr(ptr);
295+
if (umfPool) {
296+
return umf::umf2urResult(umfPoolFree(umfPool, ptr));
297+
} else {
298+
logger::error("Failed to find pool for pointer: {}", ptr);
299+
return UR_RESULT_ERROR_INVALID_VALUE;
300+
}
295301
}
296302

297303
namespace ur::level_zero {

0 commit comments

Comments
 (0)