Skip to content

Commit 8a8700a

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 1df700b commit 8a8700a

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
@@ -231,7 +231,13 @@ ur_result_t ur_usm_pool_handle_t_::allocate(
231231
}
232232

233233
ur_result_t ur_usm_pool_handle_t_::free(void *ptr) {
234-
return umf::umf2urResult(umfFree(ptr));
234+
auto umfPool = umfPoolByPtr(ptr);
235+
if (umfPool) {
236+
return umf::umf2urResult(umfPoolFree(umfPool, ptr));
237+
} else {
238+
logger::error("Failed to find pool for pointer: {}", ptr);
239+
return UR_RESULT_ERROR_INVALID_VALUE;
240+
}
235241
}
236242

237243
namespace ur::level_zero {

0 commit comments

Comments
 (0)