Skip to content

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

Use new VM Runtime API (#34961)

Artemy Skrebkovb415dda11deb
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp
index 016e1b78f32..acaad6a9496 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/dynamic_graph.hpp
@@ -18,7 +18,7 @@ namespace intel_npu {
class DynamicGraph final : public IDynamicGraph {
public:
struct MemRefTypeImpl {
- npu_mlir_runtime_mem_ref_handle_t _memRef;
+ npu_vm_runtime_mem_ref_handle_t _memRef;
MemRefTypeImpl() : _memRef(nullptr) {}
@@ -31,14 +31,14 @@ public:
if (_memRef == nullptr) {
createMemRef(memref._dimsCount);
}
- auto result = npuMLIRRuntimeSetMemRef(_memRef,
- memref._basePtr,
- memref._data,
- memref._offset,
- memref._sizes.data(),
- memref._strides.data(),
- memref._dimsCount);
- if (result != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {
+ auto result = npuVMRuntimeSetMemRef(_memRef,
+ memref._basePtr,
+ memref._data,
+ memref._offset,
+ memref._sizes.data(),
+ memref._strides.data(),
+ memref._dimsCount);
+ if (result != NPU_VM_RUNTIME_RESULT_SUCCESS) {
throw std::runtime_error("Failed to update MemRef handle");
}
}
@@ -48,13 +48,13 @@ public:
return;
}
- if (npuMLIRRuntimeParseMemRef(_memRef,
- &memref._basePtr,
- &memref._data,
- &memref._offset,
- memref._sizes.data(),
- memref._strides.data(),
- &memref._dimsCount) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {
+ if (npuVMRuntimeParseMemRef(_memRef,
+ &memref._basePtr,
+ &memref._data,
+ &memref._offset,
+ memref._sizes.data(),
+ memref._strides.data(),
+ &memref._dimsCount) != NPU_VM_RUNTIME_RESULT_SUCCESS) {
throw std::runtime_error("Failed to parse MemRef handle");
}
}
@@ -62,8 +62,8 @@ public:
private:
void createMemRef(int64_t dimsCount) {
if (_memRef == nullptr) {
- auto result = npuMLIRRuntimeCreateMemRef(dimsCount, &_memRef);
- if (result != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {
+ auto result = npuVMRuntimeCreateMemRef(dimsCount, &_memRef);
+ if (result != NPU_VM_RUNTIME_RESULT_SUCCESS) {
OPENVINO_THROW("Failed to create MemRef handle");
}
}
@@ -71,16 +71,16 @@ public:
void destroyMemRef() {
if (_memRef != nullptr) {
- npuMLIRRuntimeDestroyMemRef(_memRef);
+ npuVMRuntimeDestroyMemRef(_memRef);
_memRef = nullptr;
}
}
};
struct GraphArgumentsImpl : public GraphArguments {
- std::vector<npu_mlir_runtime_mem_ref_handle_t> _inputMemRefs;
- std::vector<npu_mlir_runtime_mem_ref_handle_t> _outputMemRefs;
- npu_mlir_runtime_execute_params_t _executeParams = {};
+ std::vector<npu_vm_runtime_mem_ref_handle_t> _inputMemRefs;
+ std::vector<npu_vm_runtime_mem_ref_handle_t> _outputMemRefs;
+ npu_vm_runtime_execute_params_t _executeParams = {};
};
class Impl {
diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/npu_vm_runtime_api.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/npu_vm_runtime_api.hpp
index 5edd1d5bd0f..321ddfa6fb7 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/include/npu_vm_runtime_api.hpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/include/npu_vm_runtime_api.hpp
@@ -10,30 +10,10 @@
#include "intel_npu/runtime/npu_vm_runtime.hpp"
#include "openvino/core/except.hpp"
-// TODO: to be removed as soon as we are ready to use NPU VM Runtime API
-#include "intel_npu/npu_mlir_runtime.hpp"
-
namespace intel_npu {
// clang-format off
-#define nmr_symbols_list() \
- nmr_symbol_statement(npuMLIRRuntimeGetAPIVersion) \
- nmr_symbol_statement(npuMLIRRuntimeCreate) \
- nmr_symbol_statement(npuMLIRRuntimeDestroy) \
- nmr_symbol_statement(npuMLIRRuntimeGetMetadata) \
- nmr_symbol_statement(npuMLIRRuntimeExecute) \
- nmr_symbol_statement(npuMLIRRuntimePredictOutputShape) \
- nmr_symbol_statement(npuMLIRRuntimeCreateMemRef) \
- nmr_symbol_statement(npuMLIRRuntimeDestroyMemRef) \
- nmr_symbol_statement(npuMLIRRuntimeSetMemRef) \
- nmr_symbol_statement(npuMLIRRuntimeParseMemRef)
-
-
-//unsupported symbols with older runtime versions
-#define nmr_weak_symbols_list() \
- nmr_symbol_statement(npuMLIRRuntimeCreateExecutionContext) \
- nmr_symbol_statement(npuMLIRRuntimeDestroyExecutionContext) \
- nmr_symbol_statement(npuMLIRRuntimeUpdateMutableCommandList) \
+#define nmr_symbols_list() \
nmr_symbol_statement(npuVMRuntimeGetAPIVersion) \
nmr_symbol_statement(npuVMRuntimeCreate) \
nmr_symbol_statement(npuVMRuntimeDestroy) \
@@ -64,7 +44,6 @@ public:
#define nmr_symbol_statement(symbol) decltype(&::symbol) symbol;
nmr_symbols_list();
- nmr_weak_symbols_list();
#undef nmr_symbol_statement
private:
@@ -81,10 +60,8 @@ private:
return ptr->symbol(std::forward<Args>(args)...); \
}
nmr_symbols_list();
-nmr_weak_symbols_list();
#undef nmr_symbol_statement
#define nmr_symbol_statement(symbol) inline decltype(&::symbol) symbol = wrapped_##symbol;
nmr_symbols_list();
-nmr_weak_symbols_list();
#undef nmr_symbol_statement
} // namespace intel_npu
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
index 1e51009a2c8..9bb18370cfa 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/dynamic_graph.cpp
@@ -48,7 +48,7 @@ public:
void destroy() {
if (_engine != nullptr) {
- npuMLIRRuntimeDestroy(_engine);
+ npuVMRuntimeDestroy(_engine);
_engine = nullptr;
}
}
@@ -57,17 +57,17 @@ public:
std::vector<DynamicGraph::MemRefType>& outputDescriptors) override;
public:
- npu_mlir_runtime_handle_t _engine = nullptr;
- npu_mlir_runtime_properties_t _engineProperties;
+ npu_vm_runtime_handle_t _engine = nullptr;
+ npu_vm_runtime_properties_t _engineProperties;
DynamicGraph::GraphArguments _binding;
- bool _initializedMLIR = false;
+ bool _initialized = false;
Logger _logger;
};
void DynamicGraphImpl::initialize(std::optional<ov::Tensor>& blob, NetworkMetadata& metadata) {
- if (!_initializedMLIR) {
+ if (!_initialized) {
initializeDynamicGraphExecution(blob, metadata);
- _initializedMLIR = true;
+ _initialized = true;
}
_binding._inputs.resize(metadata.inputs.size());
@@ -112,12 +112,12 @@ void DynamicGraphImpl::initialize(std::optional<ov::Tensor>& blob, NetworkMetada
}
void DynamicGraphImpl::createExecutionEngine(std::optional<ov::Tensor>& blob) {
- _npu_mlir_runtime_blob_desc_t blobDesc;
+ npu_vm_runtime_blob_desc_t blobDesc;
blobDesc.pInput = reinterpret_cast<const uint8_t*>(blob.value().data());
blobDesc.inputSize = blob.value().get_byte_size();
- if (npuMLIRRuntimeCreate(&blobDesc, &_engine, &_engineProperties) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {
- OPENVINO_THROW("Failed to create MLIR runtime engine");
+ if (npuVMRuntimeCreate(&blobDesc, &_engine, &_engineProperties) != NPU_VM_RUNTIME_RESULT_SUCCESS) {
+ OPENVINO_THROW("Failed to create VM runtime engine");
}
}
@@ -220,8 +220,8 @@ void DynamicGraphImpl::prepareMetadata(NetworkMetadata& metadata) {
ze_graph_argument_metadata_t meta;
std::vector<int64_t> upperBound;
upperBound.reserve(ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE);
- if (npuMLIRRuntimeGetMetadata(_engine, i, &arg, &meta, upperBound.data()) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {
- OPENVINO_THROW("Failed to get MLIR runtime metadata");
+ if (npuVMRuntimeGetMetadata(_engine, i, &arg, &meta, upperBound.data()) != NPU_VM_RUNTIME_RESULT_SUCCESS) {
+ OPENVINO_THROW("Failed to get VM runtime metadata");
}
IODescriptor ioDesc = getIODescriptor(arg, meta);
// TODO: Once runtime returns right value, can remove change on index and layout
@@ -309,7 +309,7 @@ void DynamicGraphImpl::executeGraph(const std::shared_ptr<ZeroInitStructsHolder>
args._impl ? std::static_pointer_cast<DynamicGraph::GraphArgumentsImpl>(args._impl)
: std::make_shared<DynamicGraph::GraphArgumentsImpl>();
- npu_mlir_runtime_execute_params_t* params = &argsImpl->_executeParams;
+ npu_vm_runtime_execute_params_t* params = &argsImpl->_executeParams;
for (auto& in : args._inputs) {
std::shared_ptr<DynamicGraph::MemRefTypeImpl> inImpl =
@@ -349,8 +349,8 @@ void DynamicGraphImpl::executeGraph(const std::shared_ptr<ZeroInitStructsHolder>
params->inferenceFence = fence;
params->event = event;
- if (npuMLIRRuntimeExecute(_engine, params) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {
- OPENVINO_THROW("Failed to execute MLIR runtime engine");
+ if (npuVMRuntimeExecute(_engine, params) != NPU_VM_RUNTIME_RESULT_SUCCESS) {
+ OPENVINO_THROW("Failed to execute VM runtime engine");
}
if (args._impl == nullptr) {
@@ -360,7 +360,7 @@ void DynamicGraphImpl::executeGraph(const std::shared_ptr<ZeroInitStructsHolder>
void DynamicGraphImpl::predictOutputShape(std::vector<MemRefType>& inputDescriptors,
std::vector<MemRefType>& outputDescriptors) {
- std::vector<npu_mlir_runtime_mem_ref_handle_t> inputs;
+ std::vector<npu_vm_runtime_mem_ref_handle_t> inputs;
for (auto& in : inputDescriptors) {
std::shared_ptr<DynamicGraph::MemRefTypeImpl> inImpl =
std::static_pointer_cast<DynamicGraph::MemRefTypeImpl>(in._impl);
@@ -371,7 +371,7 @@ void DynamicGraphImpl::predictOutputShape(std::vector<MemRefType>& inputDescript
inImpl->UpdateMemRefHandleStatus(in);
inputs.push_back(inImpl->_memRef);
}
- std::vector<npu_mlir_runtime_mem_ref_handle_t> outputs;
+ std::vector<npu_vm_runtime_mem_ref_handle_t> outputs;
for (auto& out : outputDescriptors) {
std::shared_ptr<DynamicGraph::MemRefTypeImpl> outImpl =
std::static_pointer_cast<DynamicGraph::MemRefTypeImpl>(out._impl);
@@ -383,14 +383,14 @@ void DynamicGraphImpl::predictOutputShape(std::vector<MemRefType>& inputDescript
outputs.push_back(outImpl->_memRef);
}
- npu_mlir_runtime_predict_output_shape_params_t params;
+ npu_vm_runtime_predict_output_shape_params_t params;
params.pInputs = inputs.data();
params.numOfInputs = static_cast<uint32_t>(inputs.size());
params.pOutputs = outputs.data();
params.numOfOutputs = static_cast<uint32_t>(outputs.size());
- if (npuMLIRRuntimePredictOutputShape(_engine, &params) != NPU_MLIR_RUNTIME_RESULT_SUCCESS) {
- OPENVINO_THROW("Failed to execute MLIR runtime engine");
+ if (npuVMRuntimePredictOutputShape(_engine, &params) != NPU_VM_RUNTIME_RESULT_SUCCESS) {
+ OPENVINO_THROW("Failed to execute VM runtime engine");
} else {
for (auto& out : outputDescriptors) {
std::shared_ptr<DynamicGraph::MemRefTypeImpl> outImpl =
@@ -419,7 +419,7 @@ DynamicGraph::DynamicGraph(const std::shared_ptr<ZeroInitStructsHolder>& zeroIni
_impl = std::make_unique<DynamicGraphImpl>();
// TODO: metadata needs to be parsed even when CREATE_EXECUTOR is 0 or DEFER_WEIGHTS_LOAD is YES, keep here to
- // support pure compilation without mlir runtime initialize MLIR execution engine, metadata, input&output
+ // support pure compilation without vm runtime initialize VM execution engine, metadata, input&output
// descriptors
_impl->initialize(_blob, _metadata);
@@ -542,7 +542,7 @@ void DynamicGraph::initialize_impl(const FilteredConfig& config) {
if (!_impl) {
_impl = std::make_unique<DynamicGraphImpl>();
- // initialize MLIR execution engine, metadata, input&output descriptors
+ // initialize VM execution engine, metadata, input&output descriptors
_impl->initialize(_blob, _metadata);
_num_of_subgraphs = _impl->getNumSubgraphs();
}
diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/npu_vm_runtime_api.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/npu_vm_runtime_api.cpp
index 16191d09818..4ae9f6dccff 100644
--- a/src/plugins/intel_npu/src/compiler_adapter/src/npu_vm_runtime_api.cpp
+++ b/src/plugins/intel_npu/src/compiler_adapter/src/npu_vm_runtime_api.cpp
@@ -33,12 +33,10 @@ NPUVMRuntimeApi::NPUVMRuntimeApi(std::string_view libName) {
} catch (const std::runtime_error&) { \
this->symbol = nullptr; \
}
- nmr_weak_symbols_list();
#undef nmr_symbol_statement
#define nmr_symbol_statement(symbol) symbol = this->symbol;
nmr_symbols_list();
- nmr_weak_symbols_list();
#undef nmr_symbol_statement
}
diff --git a/src/plugins/intel_npu/src/vm/runtime/include/intel_npu/runtime/npu_vm_runtime.hpp b/src/plugins/intel_npu/src/vm/runtime/include/intel_npu/runtime/npu_vm_runtime.hpp
index bc4e410e64b..089a94c60e9 100644
--- a/src/plugins/intel_npu/src/vm/runtime/include/intel_npu/runtime/npu_vm_runtime.hpp
+++ b/src/plugins/intel_npu/src/vm/runtime/include/intel_npu/runtime/npu_vm_runtime.hpp
@@ -69,9 +69,8 @@ extern "C" {
/// - VM runtime versions contain major and minor attributes, use
/// ::NPU_VM_RUNTIME_MAJOR_VERSION and ::NPU_VM_RUNTIME_MINOR_VERSION
typedef enum _npu_vm_runtime_version_t {
- NPU_VM_RUNTIME_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0
- NPU_VM_RUNTIME_VERSION_1_1 = ZE_MAKE_VERSION(1, 1), ///< version 1.1
- NPU_VM_RUNTIME_VERSION_CURRENT = NPU_VM_RUNTIME_VERSION_1_1, ///< latest known version
+ NPU_VM_RUNTIME_VERSION_1_0 = ZE_MAKE_VERSION(1, 0), ///< version 1.0
+ NPU_VM_RUNTIME_VERSION_CURRENT = NPU_VM_RUNTIME_VERSION_1_0, ///< latest known version
NPU_VM_RUNTIME_VERSION_FORCE_UINT32 = 0x7fffffff,
} npu_vm_runtime_version_t;
@@ -215,8 +214,6 @@ npuVMRuntimeParseMemRef(npu_vm_runtime_mem_ref_handle_t hMemRef, ///< [in] hand
int64_t* pStrides, ///< [out] pointer to tensor strides
int64_t* pDimsCount); ///< [out] value of tensor rank
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// @brief Extension version 1.1
///////////////////////////////////////////////////////////////////////////////
/// @brief Init VM runtime instance and return handle