Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU] Protect shared ptr deleter from the new zero allocation for multithreading application (#32418)

Bogdan Pereanuf246af86c65b
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_mem.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_mem.cpp
index f39df59b437..0b340967557 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_mem.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_mem.cpp
@@ -70,12 +70,8 @@ ZeroMem::ZeroMem(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
auto result = zeMemAllocHost(_init_structs->getContext(), &desc, _size, utils::STANDARD_PAGE_SIZE, &_ptr);
if (result != ZE_RESULT_SUCCESS) {
- _logger.info("Importing memory through zeMemAllocHost failed, result: %s, code %#X - %s",
- ze_result_to_string(result).c_str(),
- uint64_t(result),
- ze_result_to_description(result).c_str());
-
- throw ZeroMemException("Importing memory failed");
+ throw ZeroMemException("Importing memory failed with result " + ze_result_to_string(result) + " - " +
+ ze_result_to_description(result).c_str());
}
} else {
OPENVINO_ASSERT(_init_structs->isExternalMemoryFdWin32Supported(),
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_mem_pool.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_mem_pool.cpp
index ee1a4cf6344..a59e7d5a990 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_mem_pool.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_mem_pool.cpp
@@ -26,7 +26,9 @@ std::shared_ptr<ZeroMem> ZeroMemPool::allocate_zero_memory(const std::shared_ptr
});
std::lock_guard<std::mutex> lock(_mutex);
+ std::unique_lock<std::mutex> deleter_lock(_deleter_mutex);
update_pool(zero_memory);
+ deleter_lock.unlock();
return zero_memory;
}
@@ -40,7 +42,9 @@ std::shared_ptr<ZeroMem> ZeroMemPool::import_shared_memory(const std::shared_ptr
});
std::lock_guard<std::mutex> lock(_mutex);
+ std::unique_lock<std::mutex> deleter_lock(_deleter_mutex);
update_pool(zero_memory);
+ deleter_lock.unlock();
return zero_memory;
}
diff --git a/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_mem_pool_tests.hpp b/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_mem_pool_tests.hpp
index 441440217b7..fa8965d13ce 100644
--- a/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_mem_pool_tests.hpp
+++ b/src/plugins/intel_npu/tests/functional/internal/utils/zero/zero_mem_pool_tests.hpp
@@ -177,7 +177,7 @@ TEST_P(ZeroMemPoolTests, MultiThreadingImportMemoryReUseAndDestroyIt) {
}
for (int i = 0; i < threads_no; ++i) {
- threads[i] = std::thread([this, &data, &threads_no, &no_of_buffers]() -> void {
+ threads[i] = std::thread([this, &data, threads_no, no_of_buffers]() -> void {
for (int j = 0; j < threads_no; j++) {
std::shared_ptr<::intel_npu::ZeroMem> zero_mem;
OV_ASSERT_NO_THROW(zero_mem =