Skip to content

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

[NPU] Update code related to batch mode property (#30172)

Bogdan Pereanu7a242a534227
diff --git a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp
index 8f40d1c147a..22870d32f42 100644
--- a/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp
+++ b/src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp
@@ -411,7 +411,7 @@ struct BATCH_MODE final : OptionBase<BATCH_MODE, ov::intel_npu::BatchMode> {
}
static OptionMode mode() {
- return OptionMode::Both;
+ return OptionMode::CompileTime;
}
static ov::intel_npu::BatchMode parse(std::string_view val) {
diff --git a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
index 6cb10003389..cac96c26ee2 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_backend.cpp
@@ -30,7 +30,7 @@ uint32_t ZeroEngineBackend::getGraphExtVersion() const {
}
bool ZeroEngineBackend::isBatchingSupported() const {
- return _initStruct->isExtensionSupported("ZE_extension_graph_1_6", ZE_MAKE_VERSION(1, 6));
+ OPENVINO_NOT_IMPLEMENTED;
}
bool ZeroEngineBackend::isCommandQueueExtSupported() const {
diff --git a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
index 550ceb60462..5a6fcd1c262 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
@@ -120,12 +120,22 @@ ZeroInferRequest::ZeroInferRequest(const std::shared_ptr<ZeroInitStructsHolder>&
void ZeroInferRequest::create_pipeline() {
for (size_t inputIndex = 0; inputIndex < _metadata.inputs.size(); ++inputIndex) {
- if (is_batched_input(inputIndex)) {
- if (_graph->get_batch_size().has_value()) {
+ if (is_batched_input(inputIndex) && _graph->get_batch_size().has_value()) {
+ if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
_logger.debug("ZeroInferRequest::create_pipeline - tensors %s were already allocated",
_metadata.inputs.at(inputIndex).nodeFriendlyName.c_str());
- continue;
+ } else {
+ for (size_t i = 0; i < get_user_inputs(inputIndex).size(); i++) {
+ get_level_zero_inputs(inputIndex).resize(get_user_inputs(inputIndex).size());
+
+ _logger.debug("ZeroInferRequest::create_pipeline - allocate new input tensor for batched input: %s",
+ _metadata.inputs.at(inputIndex).nodeFriendlyName.c_str());
+
+ get_level_zero_input(inputIndex, i) =
+ allocate_tensor(_metadata.inputs.at(inputIndex), inputIndex, true, *_inputAllocator);
+ }
}
+ continue;
}
if (get_level_zero_input(inputIndex)) {
@@ -327,14 +337,13 @@ void ZeroInferRequest::set_tensors(const ov::Output<const ov::Node>& port,
get_user_inputs(foundPort.idx).resize(tensors.size());
get_user_inputs(foundPort.idx) = tensors;
- void* data = nullptr;
-
if (_initStructs->getMutableCommandListExtVersion() >= ZE_MAKE_VERSION(1, 0)) {
if (_graph->get_batch_size().has_value()) {
for (size_t i = 0; i < tensors.size(); i++) {
auto remoteTensor = std::dynamic_pointer_cast<ZeroRemoteTensor>(tensors[i]._ptr);
get_level_zero_inputs(foundPort.idx).resize(tensors.size());
+ void* data = nullptr;
if (remoteTensor == nullptr) {
bool tensorHasSameL0Context = false;
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 fbcb73682be..630f0b5cb9e 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
@@ -125,9 +125,7 @@ void DriverGraph::initialize(const Config& config) {
// releasing it here to avoid unnecessary memory usage.
_blobIsReleased = release_blob(config);
- if (config.get<BATCH_MODE>() != ov::intel_npu::BatchMode::COMPILER) {
- _batch_size = get_batch_size(_metadata);
- }
+ _batch_size = get_batch_size(_metadata);
if (config.get<RUN_INFERENCES_SEQUENTIALLY>()) {
auto number_of_command_lists = _batch_size.has_value() ? *_batch_size : 1;
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 1a1e1e70e7a..a997e4e03e7 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
@@ -118,9 +118,7 @@ void PluginGraph::initialize(const Config& config) {
_zeGraphExt->initializeGraph(_handle, _command_queue_group_ordinal);
- if (config.get<BATCH_MODE>() != ov::intel_npu::BatchMode::COMPILER) {
- _batch_size = get_batch_size(_metadata);
- }
+ _batch_size = get_batch_size(_metadata);
if (config.get<RUN_INFERENCES_SEQUENTIALLY>()) {
auto number_of_command_lists = _batch_size.has_value() ? *_batch_size : 1;
diff --git a/src/plugins/intel_npu/src/plugin/src/plugin.cpp b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
index d6293697c94..a25a90ff045 100644
--- a/src/plugins/intel_npu/src/plugin/src/plugin.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/plugin.cpp
@@ -94,33 +94,6 @@ std::shared_ptr<ov::Model> create_dummy_model(const std::vector<IODescriptor>& i
return std::make_shared<ov::Model>(results, parameters);
}
-/**
- * @brief Setting batching mode
- * @details In the case of older drivers, we force batching to compiler mode since it is not
- * supported. Othwersie set it tu AUTO if this wasn't set by the user
- * @param isBatchingSupported Newer driver versions support batching mode on the plugin.
- * @param config A configuration map.
- */
-void set_batch_config(bool isBatchingSupported, FilteredConfig& config) {
- if (!isBatchingSupported) {
- if (config.has<BATCH_MODE>()) {
- if (config.get<BATCH_MODE>() == ov::intel_npu::BatchMode::PLUGIN) {
- OPENVINO_THROW("Batching on plugin is not supported with this driver version");
- }
- }
-
- std::stringstream strStream;
- strStream << ov::intel_npu::BatchMode::COMPILER;
- config.update({{ov::intel_npu::batch_mode.name(), strStream.str()}});
- }
-
- if (!config.has<BATCH_MODE>()) {
- std::stringstream strStream;
- strStream << ov::intel_npu::BatchMode::AUTO;
- config.update({{ov::intel_npu::batch_mode.name(), strStream.str()}});
- }
-}
-
std::map<std::string, std::string> any_copy(const ov::AnyMap& params) {
std::map<std::string, std::string> result;
for (auto&& value : params) {
@@ -459,15 +432,18 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
auto device = _backend == nullptr ? nullptr : _backend->getDevice(localConfig.get<DEVICE_ID>());
localConfig.update({{ov::intel_npu::platform.name(), platform}});
- set_batch_config(_backend == nullptr ? false : _backend->isBatchingSupported(), localConfig);
+ if (localConfig.isAvailable(ov::intel_npu::batch_mode.name()) &&
+ !localConfig.has(ov::intel_npu::batch_mode.name())) {
+ std::stringstream strStream;
+ strStream << ov::intel_npu::BatchMode::AUTO;
+ localConfig.update({{ov::intel_npu::batch_mode.name(), strStream.str()}});
+ }
- if (!model->get_variables().empty()) {
+ if (localConfig.isAvailable(ov::intel_npu::batch_mode.name()) && !model->get_variables().empty()) {
if (localConfig.get<BATCH_MODE>() == ov::intel_npu::BatchMode::PLUGIN) {
OPENVINO_THROW("This model contains states, thus it is not supported when handling batching on the plugin");
}
- _logger.info("The batching will be handled by the compiler due to states found inside the IR");
-
std::stringstream strStream;
strStream << ov::intel_npu::BatchMode::COMPILER;
localConfig.update({{ov::intel_npu::batch_mode.name(), strStream.str()}});
@@ -594,8 +570,6 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(std::istream& stream, c
localConfig.update({{ov::intel_npu::platform.name(), platform}});
auto device = _backend == nullptr ? nullptr : _backend->getDevice(localConfig.get<DEVICE_ID>());
- set_batch_config(_backend == nullptr ? false : _backend->isBatchingSupported(), localConfig);
-
const auto loadedFromCache = localConfig.get<LOADED_FROM_CACHE>();
if (!loadedFromCache) {
_logger.warning(