Skip to content

Commit 528435d

Browse files
Investigate refactoring opportunities for batch management in Plugin and Compiler - review
1 parent 21eb1ef commit 528435d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/plugins/intel_npu/src/plugin/src/plugin.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,10 @@ bool validateModelBatch(const std::shared_ptr<const ov::Model>& model, Logger lo
590590
}
591591

592592
auto node_info_printer = [&logger](const auto& ov_node, std::string_view nodeType) {
593-
logger.info("%s: %s has shape value: %s", nodeType, ov_node.get_any_name(),
594-
ov_node.get_partial_shape().to_string());
593+
logger.info("%s: %s has shape value: %s",
594+
nodeType,
595+
ov_node.get_any_name(),
596+
ov_node.get_partial_shape().to_string());
595597
};
596598

597599
for (const auto& ov_node : batchedInputs) {
@@ -648,11 +650,15 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
648650
auto device = _backend == nullptr ? nullptr : _backend->getDevice(localConfig.get<DEVICE_ID>());
649651
localConfig.update({{ov::intel_npu::platform.name(), platform}});
650652

651-
if (localConfig.isAvailable(ov::intel_npu::batch_mode.name()) &&
652-
!localConfig.has(ov::intel_npu::batch_mode.name())) {
653+
auto updateBatchMode = [&localConfig](ov::intel_npu::BatchMode mode) {
653654
std::stringstream strStream;
654-
strStream << ov::intel_npu::BatchMode::AUTO;
655+
strStream << mode;
655656
localConfig.update({{ov::intel_npu::batch_mode.name(), strStream.str()}});
657+
};
658+
659+
if (localConfig.isAvailable(ov::intel_npu::batch_mode.name()) &&
660+
!localConfig.has(ov::intel_npu::batch_mode.name())) {
661+
updateBatchMode(ov::intel_npu::BatchMode::AUTO);
656662
}
657663

658664
bool modelDeBached = false;
@@ -670,6 +676,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
670676
} catch (const std::exception& ex) {
671677
_logger.info("Couldn't reshape the model. Batching will be handed by compiler.", ex.what());
672678
}
679+
// Setting batching mode to COMPILER to avoid the same actions in compiler
680+
updateBatchMode(ov::intel_npu::BatchMode::COMPILER);
673681
} else {
674682
_logger.info("Unable to manage batching on the plugin side, so the compiler will take care of it.");
675683
}
@@ -680,9 +688,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
680688
OPENVINO_THROW("This model contains states, thus it is not supported when handling batching on the plugin");
681689
}
682690

683-
std::stringstream strStream;
684-
strStream << ov::intel_npu::BatchMode::COMPILER;
685-
localConfig.update({{ov::intel_npu::batch_mode.name(), strStream.str()}});
691+
updateBatchMode(ov::intel_npu::BatchMode::COMPILER);
686692
}
687693

688694
// Update stepping w/ information from driver, unless provided by user or we are off-device

0 commit comments

Comments
 (0)