Skip to content

Commit

Permalink
Refactor compiler type selection
Browse files Browse the repository at this point in the history
  • Loading branch information
MirceaDan99 committed Nov 20, 2024
1 parent 5e09610 commit 4ba15f6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,15 @@ class IEngineBackend : public std::enable_shared_from_this<IEngineBackend> {

class ICompilerAdapter {
public:
ICompilerAdapter(ov::intel_npu::CompilerType compilerType) : _compilerType(compilerType) {}
virtual std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model,
const Config& config) const = 0;
virtual std::shared_ptr<IGraph> parse(std::vector<uint8_t> network, const Config& config) const = 0;
virtual std::shared_ptr<IGraph> parse(const std::shared_ptr<ov::AlignedBuffer>& mmapNetwork, const Config& config) const = 0;
virtual ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& 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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ namespace intel_npu {

class DriverCompilerAdapter final : public ICompilerAdapter {
public:
DriverCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct, ov::intel_npu::CompilerType compilerType);
DriverCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct);

std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;

std::shared_ptr<IGraph> parse(std::vector<uint8_t> network, const Config& config) const override;

std::shared_ptr<IGraph> parse(const std::shared_ptr<ov::AlignedBuffer>& mmapNetwork, const Config& config) const;
std::shared_ptr<IGraph> parse(const std::shared_ptr<ov::AlignedBuffer>& mmapNetwork, const Config& config) const override;

ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace intel_npu {

class PluginCompilerAdapter final : public ICompilerAdapter {
public:
PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct, ov::intel_npu::CompilerType compilerType);
PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct);

std::shared_ptr<IGraph> compile(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;

Expand All @@ -29,6 +29,10 @@ class PluginCompilerAdapter final : public ICompilerAdapter {

ov::SupportedOpsMap query(const std::shared_ptr<const ov::Model>& model, const Config& config) const override;

ov::intel_npu::CompilerType getCompilerType() const override {
return ov::intel_npu::CompilerType::MLIR;
}

private:
std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ std::string rankToLegacyLayoutString(const size_t rank) {

namespace intel_npu {

DriverCompilerAdapter::DriverCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct, ov::intel_npu::CompilerType compilerType)
DriverCompilerAdapter::DriverCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ ov::SoPtr<intel_npu::ICompiler> loadCompiler(const std::string& libpath) {

namespace intel_npu {

PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& zeroInitStruct, ov::intel_npu::CompilerType compilerType)
PluginCompilerAdapter::PluginCompilerAdapter(const std::shared_ptr<ZeroInitStructsHolder>& 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.");
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_npu/src/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,15 +847,15 @@ std::unique_ptr<ICompilerAdapter> Plugin::getCompiler(const Config& config) cons
switch (compilerType) {
case ov::intel_npu::CompilerType::MLIR: {
if (_backends->getBackendName() != "LEVEL0") {
return std::make_unique<PluginCompilerAdapter>(nullptr, compilerType);
return std::make_unique<PluginCompilerAdapter>(nullptr);
}

auto zeroBackend = std::dynamic_pointer_cast<ZeroEngineBackend>(_backends->getIEngineBackend()._ptr);
if (zeroBackend == nullptr) {
return std::make_unique<PluginCompilerAdapter>(nullptr, compilerType);
return std::make_unique<PluginCompilerAdapter>(nullptr);
}

return std::make_unique<PluginCompilerAdapter>(zeroBackend->getInitStruct(), compilerType);
return std::make_unique<PluginCompilerAdapter>(zeroBackend->getInitStruct());
}
case ov::intel_npu::CompilerType::DRIVER: {
if (_backends->getBackendName() != "LEVEL0") {
Expand All @@ -867,7 +867,7 @@ std::unique_ptr<ICompilerAdapter> Plugin::getCompiler(const Config& config) cons
OPENVINO_THROW("Failed to cast zeroBackend, zeroBackend is a nullptr");
}

return std::make_unique<DriverCompilerAdapter>(zeroBackend->getInitStruct(), compilerType);
return std::make_unique<DriverCompilerAdapter>(zeroBackend->getInitStruct());
}
default:
OPENVINO_THROW("Invalid NPU_COMPILER_TYPE");
Expand Down

0 comments on commit 4ba15f6

Please sign in to comment.