diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp index 6f422c5b3ba00c..b66c94933ee1ee 100644 --- a/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp +++ b/src/plugins/intel_npu/src/al/include/intel_npu/al/icompiler.hpp @@ -216,7 +216,9 @@ class ICompiler : public std::enable_shared_from_this { virtual void release([[maybe_unused]] std::shared_ptr networkDescription){}; virtual CompiledNetwork getCompiledNetwork(std::shared_ptr networkDescription) { - return CompiledNetwork{networkDescription->compiledNetwork.data(), networkDescription->compiledNetwork.size(), networkDescription->compiledNetwork}; + return CompiledNetwork{networkDescription->compiledNetwork.data(), + networkDescription->compiledNetwork.size(), + networkDescription->compiledNetwork}; } protected: diff --git a/src/plugins/intel_npu/src/backend/include/zero_types.hpp b/src/plugins/intel_npu/src/backend/include/zero_types.hpp index 9fbd86302db96b..5a75c89cd06678 100644 --- a/src/plugins/intel_npu/src/backend/include/zero_types.hpp +++ b/src/plugins/intel_npu/src/backend/include/zero_types.hpp @@ -134,8 +134,7 @@ struct ze_graph_dditable_ext_decorator final { } // version 1.7 - ze_result_t ZE_APICALL pfnGetNativeBinary2(ze_graph_handle_t hGraph, - size_t* pSize, uint8_t** pGraphNativeBinary) { + ze_result_t ZE_APICALL pfnGetNativeBinary2(ze_graph_handle_t hGraph, size_t* pSize, uint8_t** pGraphNativeBinary) { throwWhenUnsupported("pfnGetNativeBinary2", ZE_GRAPH_EXT_VERSION_1_7); return _impl->pfnGetNativeBinary2(hGraph, pSize, pGraphNativeBinary); } diff --git a/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp b/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp index b3512e3217e426..db5ecc3606ee4a 100644 --- a/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp +++ b/src/plugins/intel_npu/src/compiler/include/zero_compiler_in_driver.hpp @@ -130,13 +130,17 @@ class LevelZeroCompilerInDriver final : public ICompiler { template = true> void getNativeBinary(TableExtension* graphDdiTableExt, - ze_graph_handle_t graphHandle, std::vector& blob, - uint8_t** blobPtr, size_t* blobSize) const; + ze_graph_handle_t graphHandle, + std::vector& blob, + uint8_t** blobPtr, + size_t* blobSize) const; template = true> void getNativeBinary(TableExtension* graphDdiTableExt, - ze_graph_handle_t graphHandle, std::vector& /* unusedBlob */, - uint8_t** blobPtr, size_t* blobSize) const; + ze_graph_handle_t graphHandle, + std::vector& /* unusedBlob */, + uint8_t** blobPtr, + size_t* blobSize) const; template = true> ze_result_t seriazlideIRModelAndQueryNetworkCreateV2(const std::shared_ptr& model, diff --git a/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp b/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp index e29f2e61eb36a9..21c3059155861b 100644 --- a/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp +++ b/src/plugins/intel_npu/src/compiler/src/zero_compiler_in_driver.cpp @@ -367,35 +367,36 @@ template > void LevelZeroCompilerInDriver::getNativeBinary(TableExtension* graphDdiTableExt, ze_graph_handle_t graphHandle, std::vector& blob, - uint8_t** blobPtr, size_t* blobSize) const { - // Get blob size first - auto result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, blobSize, nullptr); - blob.resize(*blobSize); - - OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, - "Failed to compile network. L0 pfnGetNativeBinary get blob size", - " result: ", - ze_result_to_string(result), - ", code 0x", - std::hex, - uint64_t(result), - ". ", - getLatestBuildError()); - - // Get blob data - result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, blobSize, blob.data()); - - OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, - "Failed to compile network. L0 pfnGetNativeBinary get blob data", - " result: ", - ze_result_to_string(result), - ", code 0x", - std::hex, - uint64_t(result), - ". ", - getLatestBuildError()); - - *blobPtr = blob.data(); + uint8_t** blobPtr, + size_t* blobSize) const { + // Get blob size first + auto result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, blobSize, nullptr); + blob.resize(*blobSize); + + OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, + "Failed to compile network. L0 pfnGetNativeBinary get blob size", + " result: ", + ze_result_to_string(result), + ", code 0x", + std::hex, + uint64_t(result), + ". ", + getLatestBuildError()); + + // Get blob data + result = _graphDdiTableExt->pfnGetNativeBinary(graphHandle, blobSize, blob.data()); + + OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, + "Failed to compile network. L0 pfnGetNativeBinary get blob data", + " result: ", + ze_result_to_string(result), + ", code 0x", + std::hex, + uint64_t(result), + ". ", + getLatestBuildError()); + + *blobPtr = blob.data(); } template @@ -403,19 +404,20 @@ template > void LevelZeroCompilerInDriver::getNativeBinary(TableExtension* graphDdiTableExt, ze_graph_handle_t graphHandle, std::vector& /* unusedBlob */, - uint8_t** blobPtr, size_t* blobSize) const { - // Get blob ptr and size - auto result = _graphDdiTableExt->pfnGetNativeBinary2(graphHandle, blobSize, blobPtr); - - OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, - "Failed to compile network. L0 pfnGetNativeBinary get blob size", - " result: ", - ze_result_to_string(result), - ", code 0x", - std::hex, - uint64_t(result), - ". ", - getLatestBuildError()); + uint8_t** blobPtr, + size_t* blobSize) const { + // Get blob ptr and size + auto result = _graphDdiTableExt->pfnGetNativeBinary2(graphHandle, blobSize, blobPtr); + + OPENVINO_ASSERT(result == ZE_RESULT_SUCCESS, + "Failed to compile network. L0 pfnGetNativeBinary get blob size", + " result: ", + ze_result_to_string(result), + ", code 0x", + std::hex, + uint64_t(result), + ". ", + getLatestBuildError()); } template @@ -433,10 +435,11 @@ CompiledNetwork LevelZeroCompilerInDriver::getCompiledNetwork( _logger.info("LevelZeroCompilerInDriver getCompiledNetwork returning blob"); return CompiledNetwork{blobPtr, blobSize, std::move(blob)}; - } else { - _logger.info("return the blob from network description"); - return CompiledNetwork{networkDescription->compiledNetwork.data(), networkDescription->compiledNetwork.size(), networkDescription->compiledNetwork}; } + _logger.info("return the blob from network description"); + return CompiledNetwork{networkDescription->compiledNetwork.data(), + networkDescription->compiledNetwork.size(), + networkDescription->compiledNetwork}; } template diff --git a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp index 14cf6f91c06d7d..d96a40bfba3052 100644 --- a/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp +++ b/src/plugins/intel_npu/src/plugin/src/compiled_model.cpp @@ -143,16 +143,16 @@ void CompiledModel::export_model(std::ostream& stream) const { const auto&& blob = _compiler->getCompiledNetwork(_networkPtr); stream.write(reinterpret_cast(blob.data), blob.size); + if (!stream) { + _logger.error("Write blob to stream failed. Blob is broken!"); + } else { + _logger.info("Write blob to stream successfully."); + } + if (_logger.level() == ov::log::Level::INFO) { std::stringstream str; str << "Blob size: " << blob.size << ", hash: " << std::hex << hash(blob); _logger.info(str.str().c_str()); - - if (!stream) { - _logger.error("Write blob to stream failed. Blob is broken!"); - } else { - _logger.info("Write blob to stream successfully."); - } } }