From b9f9c3d661e34959629d9c6c430ce9c074608e92 Mon Sep 17 00:00:00 2001 From: MirceaDan99 Date: Thu, 12 Dec 2024 11:40:40 +0200 Subject: [PATCH] Add suggested changes --- .../intel_npu/common/blob_container.hpp | 70 +++++++++++++++++++ .../include/intel_npu/common/igraph.hpp | 66 +---------------- .../intel_npu/src/common/src/igraph.cpp | 9 +-- .../compiler_adapter/include/driver_graph.hpp | 2 +- .../include/ze_graph_ext_wrappers.hpp | 2 +- .../src/driver_compiler_adapter.cpp | 6 +- .../src/compiler_adapter/src/driver_graph.cpp | 2 +- .../src/plugin_compiler_adapter.cpp | 4 +- .../src/compiler_adapter/src/plugin_graph.cpp | 5 +- .../src/ze_graph_ext_wrappers.cpp | 6 +- .../intel_npu/src/plugin/src/plugin.cpp | 2 +- 11 files changed, 88 insertions(+), 86 deletions(-) create mode 100644 src/plugins/intel_npu/src/common/include/intel_npu/common/blob_container.hpp diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/blob_container.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/blob_container.hpp new file mode 100644 index 00000000000000..27d2040583feaf --- /dev/null +++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/blob_container.hpp @@ -0,0 +1,70 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "openvino/runtime/shared_buffer.hpp" + +namespace intel_npu { + +class BlobContainer { +public: + virtual void* get_ptr() = 0; + + virtual size_t size() const = 0; + + virtual bool release_from_memory() = 0; + + virtual ~BlobContainer() = default; +}; + +class BlobContainerVector : public BlobContainer { +public: + BlobContainerVector(std::vector blob) : _ownershipBlob(std::move(blob)) {} + + void* get_ptr() override { + return reinterpret_cast(_ownershipBlob.data()); + } + + size_t size() const override { + return _ownershipBlob.size(); + } + + bool release_from_memory() override { + _ownershipBlob.clear(); + _ownershipBlob.shrink_to_fit(); + return true; + } + +private: + std::vector _ownershipBlob; +}; + +class BlobContainerAlignedBuffer : public BlobContainer { +public: + BlobContainerAlignedBuffer(const std::shared_ptr& blobSO, size_t offset) + : _ownershipBlob(blobSO), + _offset(offset) {} + + void* get_ptr() override { + return _ownershipBlob->get_ptr(_offset); + } + + size_t size() const override { + return _ownershipBlob->size(); + } + + bool release_from_memory() override { + return false; + } + +private: + std::shared_ptr _ownershipBlob; + size_t _offset; +}; + +} // namespace intel_npu \ No newline at end of file diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp index e64380021544fd..37447859e42b27 100644 --- a/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp +++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/igraph.hpp @@ -8,83 +8,21 @@ #include #include +#include "intel_npu/common/blob_container.hpp" #include "intel_npu/network_metadata.hpp" #include "intel_npu/utils/zero/zero_init.hpp" #include "intel_npu/utils/zero/zero_utils.hpp" #include "intel_npu/utils/zero/zero_wrappers.hpp" #include "openvino/runtime/profiling_info.hpp" -#include "openvino/runtime/shared_buffer.hpp" namespace intel_npu { -class BlobContainer { -public: - virtual void* get_ptr() { - OPENVINO_THROW("const BlobContainer::get_ptr() method is not implemented!"); - } - - virtual size_t size() const { - OPENVINO_THROW("BlobContainer::size() method is not implemented!"); - } - - virtual bool release_from_memory() { - OPENVINO_THROW("BlobContainer::release_from_memory() method is not implemented!"); - } - - virtual ~BlobContainer() = default; -}; - -class BlobContainerVector : public BlobContainer { -public: - BlobContainerVector(std::vector blob) : _ownershipBlob(std::move(blob)) {} - - void* get_ptr() override { - return reinterpret_cast(_ownershipBlob.data()); - } - - size_t size() const override { - return _ownershipBlob.size(); - } - - bool release_from_memory() override { - _ownershipBlob.clear(); - _ownershipBlob.shrink_to_fit(); - return true; - } - -private: - std::vector _ownershipBlob; -}; - -class BlobContainerAlignedBuffer : public BlobContainer { -public: - BlobContainerAlignedBuffer(const std::shared_ptr& blobSO, size_t offset) - : _ownershipBlob(blobSO), - _offset(offset) {} - - void* get_ptr() override { - return _ownershipBlob->get_ptr(_offset); - } - - size_t size() const override { - return _ownershipBlob->size(); - } - - bool release_from_memory() override { - return false; - } - -private: - std::shared_ptr _ownershipBlob; - size_t _offset; -}; - class IGraph : public std::enable_shared_from_this { public: IGraph(ze_graph_handle_t handle, NetworkMetadata metadata, const Config& config, - std::optional> blobPtr); + std::unique_ptr blobPtr); virtual void export_blob(std::ostream& stream) const = 0; diff --git a/src/plugins/intel_npu/src/common/src/igraph.cpp b/src/plugins/intel_npu/src/common/src/igraph.cpp index 3f04bb0ce8e5ff..e4d2830217c5d0 100644 --- a/src/plugins/intel_npu/src/common/src/igraph.cpp +++ b/src/plugins/intel_npu/src/common/src/igraph.cpp @@ -17,14 +17,11 @@ namespace intel_npu { IGraph::IGraph(ze_graph_handle_t handle, NetworkMetadata metadata, const Config& config, - std::optional> blobPtr) + std::unique_ptr blobPtr) : _handle(handle), _metadata(std::move(metadata)), - _logger("IGraph", config.get()) { - if (blobPtr.has_value()) { - _blobPtr = std::move(*blobPtr); - } -} + _logger("IGraph", config.get()), + _blobPtr(std::move(blobPtr)) {} const NetworkMetadata& IGraph::get_metadata() const { return _metadata; diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/driver_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/driver_graph.hpp index ef70ae01cc62af..25af83a82f2490 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/include/driver_graph.hpp +++ b/src/plugins/intel_npu/src/compiler_adapter/include/driver_graph.hpp @@ -21,7 +21,7 @@ class DriverGraph final : public IGraph { ze_graph_handle_t graphHandle, NetworkMetadata metadata, const Config& config, - std::optional> blob); + std::unique_ptr blob); void export_blob(std::ostream& stream) const override; diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp index d6ba89472663a2..88f2da0c3f1266 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp +++ b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp @@ -35,7 +35,7 @@ class ZeGraphExtWrappers { const std::string& buildFlags, const uint32_t& flags) const; - ze_graph_handle_t getGraphHandle(const uint8_t* data, size_t size) const; + ze_graph_handle_t getGraphHandle(const uint8_t& data, size_t size) const; NetworkMetadata getNetworkMeta(ze_graph_handle_t graphHandle) const; diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp index eb05a90f4037a5..e1068d6d61ba52 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp +++ b/src/plugins/intel_npu/src/compiler_adapter/src/driver_compiler_adapter.cpp @@ -200,7 +200,7 @@ std::shared_ptr DriverCompilerAdapter::compile(const std::shared_ptr DriverCompilerAdapter::parse(std::unique_ptr blobPtr, @@ -209,7 +209,7 @@ std::shared_ptr DriverCompilerAdapter::parse(std::unique_ptrgetGraphHandle(reinterpret_cast(blobPtr->get_ptr()), blobPtr->size()); + _zeGraphExt->getGraphHandle(*reinterpret_cast(blobPtr->get_ptr()), blobPtr->size()); _logger.debug("parse end"); OV_ITT_TASK_NEXT(PARSE_BLOB, "getNetworkMeta"); @@ -220,7 +220,7 @@ std::shared_ptr DriverCompilerAdapter::parse(std::unique_ptr>(std::move(blobPtr))); + std::move(blobPtr)); } ov::SupportedOpsMap DriverCompilerAdapter::query(const std::shared_ptr& model, diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp index 3ce216c255f0e4..5ce5cc9f1b39ff 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp +++ b/src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp @@ -15,7 +15,7 @@ DriverGraph::DriverGraph(const std::shared_ptr& zeGraphExt, ze_graph_handle_t graphHandle, NetworkMetadata metadata, const Config& config, - std::optional> blobPtr) + std::unique_ptr blobPtr) : IGraph(graphHandle, std::move(metadata), config, std::move(blobPtr)), _zeGraphExt(zeGraphExt), _zeroInitStruct(zeroInitStruct), diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp index 719950533289ff..64c9d9f9de280d 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp +++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp @@ -89,7 +89,7 @@ std::shared_ptr PluginCompilerAdapter::compile(const std::shared_ptrgetGraphHandle(reinterpret_cast(blobPtr->get_ptr()), blobPtr->size()); + _zeGraphExt->getGraphHandle(*reinterpret_cast(blobPtr->get_ptr()), blobPtr->size()); } catch (...) { _logger.info("Failed to obtain the level zero graph handle. Inference requests for this model are not " "allowed. Only exports are available"); @@ -122,7 +122,7 @@ std::shared_ptr PluginCompilerAdapter::parse(std::unique_ptrgetGraphHandle(reinterpret_cast(blobPtr->get_ptr()), blobPtr->size()); + _zeGraphExt->getGraphHandle(*reinterpret_cast(blobPtr->get_ptr()), blobPtr->size()); } return std::make_shared(_zeGraphExt, diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp index 87d530a4086817..4d48dbe89efaa3 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp +++ b/src/plugins/intel_npu/src/compiler_adapter/src/plugin_graph.cpp @@ -17,10 +17,7 @@ PluginGraph::PluginGraph(const std::shared_ptr& zeGraphExt, NetworkMetadata metadata, std::unique_ptr blobPtr, const Config& config) - : IGraph(graphHandle, - std::move(metadata), - config, - std::optional>(std::move(blobPtr))), + : IGraph(graphHandle, std::move(metadata), config, std::move(blobPtr)), _zeGraphExt(zeGraphExt), _zeroInitStruct(zeroInitStruct), _compiler(compiler), diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp index 5efb973351c55f..2f80fc10b9e675 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp +++ b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp @@ -363,15 +363,15 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(std::pairgetGraphDdiTable().pfnCreate(_zeroInitStruct->getContext(), diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp index 798164403bbbbb..a721f7b55914b5 100644 --- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp +++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp @@ -759,7 +759,7 @@ std::shared_ptr Plugin::import_model(std::istream& stream, c _properties.erase(ov::internal::cached_model_buffer.name()); } - const std::map propertiesMap = any_copy(_properties); + const auto propertiesMap = any_copy(_properties); auto localConfig = merge_configs(_globalConfig, propertiesMap, OptionMode::RunTime); _logger.setLevel(localConfig.get()); const auto platform = _backends->getCompilationPlatform(localConfig.get(), localConfig.get());