From 4ba15f6ec1826b2e0f8005f58764574b2104e854 Mon Sep 17 00:00:00 2001 From: MirceaDan99 Date: Thu, 14 Nov 2024 17:23:37 +0200 Subject: [PATCH] Refactor compiler type selection --- .../intel_npu/src/common/include/intel_npu/common/npu.hpp | 5 +---- .../compiler_adapter/include/driver_compiler_adapter.hpp | 8 ++++++-- .../compiler_adapter/include/plugin_compiler_adapter.hpp | 6 +++++- .../src/compiler_adapter/src/driver_compiler_adapter.cpp | 5 ++--- .../src/compiler_adapter/src/plugin_compiler_adapter.cpp | 5 ++--- src/plugins/intel_npu/src/plugin/src/plugin.cpp | 8 ++++---- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp b/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp index 0ea654bbce4bff..8a21df4cd27cc4 100644 --- a/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp +++ b/src/plugins/intel_npu/src/common/include/intel_npu/common/npu.hpp @@ -56,18 +56,15 @@ class IEngineBackend : public std::enable_shared_from_this { class ICompilerAdapter { public: - ICompilerAdapter(ov::intel_npu::CompilerType compilerType) : _compilerType(compilerType) {} virtual std::shared_ptr compile(const std::shared_ptr& model, const Config& config) const = 0; virtual std::shared_ptr parse(std::vector network, const Config& config) const = 0; virtual std::shared_ptr parse(const std::shared_ptr& mmapNetwork, const Config& config) const = 0; virtual ov::SupportedOpsMap query(const std::shared_ptr& model, const Config& config) const = 0; + virtual ov::intel_npu::CompilerType getCompilerType() const = 0; virtual ~ICompilerAdapter() = default; - ov::intel_npu::CompilerType getCompilerType() { - return _compilerType; - } private: ov::intel_npu::CompilerType _compilerType; }; diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hpp index 161433a882beec..e23c882f4b6905 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hpp +++ b/src/plugins/intel_npu/src/compiler_adapter/include/driver_compiler_adapter.hpp @@ -22,16 +22,20 @@ namespace intel_npu { class DriverCompilerAdapter final : public ICompilerAdapter { public: - DriverCompilerAdapter(const std::shared_ptr& zeroInitStruct, ov::intel_npu::CompilerType compilerType); + DriverCompilerAdapter(const std::shared_ptr& zeroInitStruct); std::shared_ptr compile(const std::shared_ptr& model, const Config& config) const override; std::shared_ptr parse(std::vector network, const Config& config) const override; - std::shared_ptr parse(const std::shared_ptr& mmapNetwork, const Config& config) const; + std::shared_ptr parse(const std::shared_ptr& mmapNetwork, const Config& config) const override; ov::SupportedOpsMap query(const std::shared_ptr& model, const Config& config) const override; + ov::intel_npu::CompilerType getCompilerType() const override { + return ov::intel_npu::CompilerType::DRIVER; + } + private: /** * @brief Serialize input / output information to string format. diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp index a39932b9eda928..05ae2b392eb90b 100644 --- a/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp +++ b/src/plugins/intel_npu/src/compiler_adapter/include/plugin_compiler_adapter.hpp @@ -17,7 +17,7 @@ namespace intel_npu { class PluginCompilerAdapter final : public ICompilerAdapter { public: - PluginCompilerAdapter(const std::shared_ptr& zeroInitStruct, ov::intel_npu::CompilerType compilerType); + PluginCompilerAdapter(const std::shared_ptr& zeroInitStruct); std::shared_ptr compile(const std::shared_ptr& model, const Config& config) const override; @@ -29,6 +29,10 @@ class PluginCompilerAdapter final : public ICompilerAdapter { ov::SupportedOpsMap query(const std::shared_ptr& model, const Config& config) const override; + ov::intel_npu::CompilerType getCompilerType() const override { + return ov::intel_npu::CompilerType::MLIR; + } + private: std::shared_ptr _zeroInitStruct; 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 a30134a004af06..5668dd47c2755a 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 @@ -141,10 +141,9 @@ std::string rankToLegacyLayoutString(const size_t rank) { namespace intel_npu { -DriverCompilerAdapter::DriverCompilerAdapter(const std::shared_ptr& zeroInitStruct, ov::intel_npu::CompilerType compilerType) +DriverCompilerAdapter::DriverCompilerAdapter(const std::shared_ptr& zeroInitStruct) : _zeroInitStruct(zeroInitStruct), - _logger("DriverCompilerAdapter", Logger::global().level()), - ICompilerAdapter(compilerType) { + _logger("DriverCompilerAdapter", Logger::global().level()) { _logger.debug("initialize DriverCompilerAdapter start"); uint32_t graphExtVersion = _zeroInitStruct->getGraphDdiTable().version(); 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 ae31ce3decfabb..06d71fd1126c17 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 @@ -52,10 +52,9 @@ ov::SoPtr loadCompiler(const std::string& libpath) { namespace intel_npu { -PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr& zeroInitStruct, ov::intel_npu::CompilerType compilerType) +PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr& zeroInitStruct) : _zeroInitStruct(zeroInitStruct), - _logger("PluginCompilerAdapter", Logger::global().level()), - ICompilerAdapter(compilerType) { + _logger("PluginCompilerAdapter", Logger::global().level()) { _logger.debug("initialize PluginCompilerAdapter start"); _logger.info("MLIR compiler will be used."); diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp index fe171293fe76d8..be4236871153a1 100644 --- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp +++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp @@ -847,15 +847,15 @@ std::unique_ptr Plugin::getCompiler(const Config& config) cons switch (compilerType) { case ov::intel_npu::CompilerType::MLIR: { if (_backends->getBackendName() != "LEVEL0") { - return std::make_unique(nullptr, compilerType); + return std::make_unique(nullptr); } auto zeroBackend = std::dynamic_pointer_cast(_backends->getIEngineBackend()._ptr); if (zeroBackend == nullptr) { - return std::make_unique(nullptr, compilerType); + return std::make_unique(nullptr); } - return std::make_unique(zeroBackend->getInitStruct(), compilerType); + return std::make_unique(zeroBackend->getInitStruct()); } case ov::intel_npu::CompilerType::DRIVER: { if (_backends->getBackendName() != "LEVEL0") { @@ -867,7 +867,7 @@ std::unique_ptr Plugin::getCompiler(const Config& config) cons OPENVINO_THROW("Failed to cast zeroBackend, zeroBackend is a nullptr"); } - return std::make_unique(zeroBackend->getInitStruct(), compilerType); + return std::make_unique(zeroBackend->getInitStruct()); } default: OPENVINO_THROW("Invalid NPU_COMPILER_TYPE");