Skip to content

Commit

Permalink
[L0 v2] do not use usm pool free for native handles
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
igchor committed Jan 17, 2025
1 parent f629ee7 commit 868233c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 6 additions & 9 deletions source/adapters/level_zero/v2/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ ur_integrated_mem_handle_t::ur_integrated_mem_handle_t(
if (!ownHostPtr) {
return;
}
auto ret = hContext->getDefaultUSMPool()->free(ptr);
if (ret != UR_RESULT_SUCCESS) {
logger::error("Failed to free host memory: {}", ret);
}
ZE_CALL_NOCHECK(zeMemFree, (hContext->getZeHandle(), ptr));
});
}

Expand Down Expand Up @@ -234,10 +231,7 @@ ur_discrete_mem_handle_t::ur_discrete_mem_handle_t(
if (!ownZePtr) {
return;
}
auto ret = hContext->getDefaultUSMPool()->free(ptr);
if (ret != UR_RESULT_SUCCESS) {
logger::error("Failed to free device memory: {}", ret);
}
ZE_CALL_NOCHECK(zeMemFree, (hContext->getZeHandle(), ptr));
});
}
}
Expand Down Expand Up @@ -310,7 +304,10 @@ void *ur_discrete_mem_handle_t::mapHostPtr(
usm_unique_ptr_t mappedPtr =
usm_unique_ptr_t(ptr, [ownsAlloc = bool(mapToPtr), this](void *p) {
if (ownsAlloc) {
UR_CALL_THROWS(hContext->getDefaultUSMPool()->free(p));
auto ret = hContext->getDefaultUSMPool()->free(p);
if (ret != UR_RESULT_SUCCESS) {
logger::error("Failed to mapped memory: {}", ret);
}
}
});

Expand Down
8 changes: 7 additions & 1 deletion source/adapters/level_zero/v2/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,13 @@ ur_result_t ur_usm_pool_handle_t_::allocate(
}

ur_result_t ur_usm_pool_handle_t_::free(void *ptr) {
return umf::umf2urResult(umfFree(ptr));
auto umfPool = umfPoolByPtr(ptr);
if (umfPool) {
return umf::umf2urResult(umfPoolFree(umfPool, ptr));
} else {
logger::error("Failed to find pool for pointer: {}", ptr);
return UR_RESULT_ERROR_INVALID_VALUE;
}
}

namespace ur::level_zero {
Expand Down

0 comments on commit 868233c

Please sign in to comment.