Skip to content

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

[NPU] Adding logging to the host mem allocator (#29603)

Bogdan Pereanu288c9fd6cf6e
diff --git a/src/plugins/intel_npu/src/backend/include/zero_memory.hpp b/src/plugins/intel_npu/src/backend/include/zero_memory.hpp
index ab6de0a35b3..77ba6fa5370 100644
--- a/src/plugins/intel_npu/src/backend/include/zero_memory.hpp
+++ b/src/plugins/intel_npu/src/backend/include/zero_memory.hpp
@@ -28,6 +28,7 @@ public:
explicit HostMemAllocator(const std::shared_ptr<ZeroInitStructsHolder>& initStructs,
ze_host_mem_alloc_flag_t flag = {})
: _initStructs(initStructs),
+ _logger("HostMemAllocator", Logger::global().level()),
_flag(flag) {}
/**
@@ -49,6 +50,8 @@ public:
private:
const std::shared_ptr<ZeroInitStructsHolder> _initStructs;
+ Logger _logger;
+
ze_host_mem_alloc_flag_t _flag;
static const std::size_t _alignment = STANDARD_PAGE_SIZE;
};
diff --git a/src/plugins/intel_npu/src/backend/src/zero_memory.cpp b/src/plugins/intel_npu/src/backend/src/zero_memory.cpp
index 74facb1c48d..ef37774aa69 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_memory.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_memory.cpp
@@ -5,6 +5,7 @@
#include "zero_memory.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
+#include "intel_npu/utils/zero/zero_result.hpp"
#include "intel_npu/utils/zero/zero_utils.hpp"
namespace intel_npu {
@@ -17,17 +18,25 @@ void* HostMemAllocator::allocate(const size_t bytes, const size_t /*alignment*/)
nullptr,
static_cast<ze_host_mem_alloc_flags_t>(_flag)};
void* data = nullptr;
- ze_result_t res = zeMemAllocHost(_initStructs->getContext(), &desc, size, _alignment, &data);
+ ze_result_t result = zeMemAllocHost(_initStructs->getContext(), &desc, size, _alignment, &data);
- if (res == ZE_RESULT_SUCCESS) {
+ if (result == ZE_RESULT_SUCCESS) {
return data;
} else {
+ _logger.error("L0 zeMemAllocHost result: %s, code %#X - %s",
+ ze_result_to_string(result).c_str(),
+ uint64_t(result),
+ ze_result_to_description(result).c_str());
return nullptr;
}
}
bool HostMemAllocator::deallocate(void* handle, const size_t /* bytes */, size_t /* alignment */) noexcept {
auto result = zeMemFree(_initStructs->getContext(), handle);
if (ZE_RESULT_SUCCESS != result) {
+ _logger.error("L0 zeMemAllocHost result: %s, code %#X - %s",
+ ze_result_to_string(result).c_str(),
+ uint64_t(result),
+ ze_result_to_description(result).c_str());
return false;
}