Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUTO BATCH] Clean legacy name #22909

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/plugins/auto_batch/src/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,
const std::shared_ptr<const ov::IPlugin>& plugin,
const ov::AnyMap& config,
const DeviceInformation& device_info,
const std::set<std::string>& batched_inputs,
const std::set<std::string>& batched_outputs,
const std::set<std::size_t>& batched_inputs,
const std::set<std::size_t>& batched_outputs,
const ov::SoPtr<ov::ICompiledModel>& compiled_model_with_batch,
const ov::SoPtr<ov::ICompiledModel>& compiled_model_without_batch,
const ov::SoPtr<ov::IRemoteContext>& context)
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/auto_batch/src/compiled_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class CompiledModel : public ov::ICompiledModel {
const std::shared_ptr<const ov::IPlugin>& plugin,
const ov::AnyMap& config,
const DeviceInformation& device_info,
const std::set<std::string>& batched_inputs,
const std::set<std::string>& batched_outputs,
const std::set<std::size_t>& batched_inputs,
const std::set<std::size_t>& batched_outputs,
const ov::SoPtr<ov::ICompiledModel>& compiled_model_with_batch,
const ov::SoPtr<ov::ICompiledModel>& compiled_model_without_batch,
const ov::SoPtr<ov::IRemoteContext>& context);
Expand Down Expand Up @@ -73,8 +73,8 @@ class CompiledModel : public ov::ICompiledModel {
mutable std::atomic_size_t m_num_requests_created = {0};
std::atomic<std::uint32_t> m_time_out = {0}; // in ms

const std::set<std::string> m_batched_inputs;
const std::set<std::string> m_batched_outputs;
const std::set<std::size_t> m_batched_inputs;
const std::set<std::size_t> m_batched_outputs;

ov::SoPtr<ov::ICompiledModel> m_compiled_model_with_batch;
ov::SoPtr<ov::ICompiledModel> m_compiled_model_without_batch;
Expand Down
25 changes: 12 additions & 13 deletions src/plugins/auto_batch/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
// avoid recursive auto-batching
device_config_no_auto_batch[ov::hint::allow_auto_batching.name()] = false;

std::set<std::string> batched_inputs;
std::set<std::string> batched_outputs;
std::set<std::size_t> batched_inputs;
std::set<std::size_t> batched_outputs;
// check that the auto-batching is applicable in general
try {
// if applicable, the Auto-Batching is implicitly enabled via the performance hints
Expand Down Expand Up @@ -172,8 +172,7 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
const auto& static_shape = input->get_shape();
if (static_shape[0] != 1)
OPENVINO_THROW("Auto-batching does not reshape/re-batch originally batched networks!");
batched_inputs.insert(
ov::op::util::get_ie_output_name(params[input_id]->output(0))); // batched dim for the input
batched_inputs.insert(input_id); // batched dim for the input
} else {
// if the 0-th dim is not for the batch, then we support only the case when NONE dimension is batch
for (size_t s = 1; s < shape.size(); s++)
Expand All @@ -182,17 +181,17 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
"Auto-batching operates only networks with inputs/outputs batched by 0th dimension");
}
}
for (const auto& output : cloned_model->get_results()) {
const auto& results = cloned_model->get_results();
for (size_t output_id = 0; output_id < results.size(); output_id++) {
const auto& output = results[output_id];
const auto& shape = output->get_output_partial_shape(0);
if (shape.is_dynamic())
OPENVINO_THROW("Auto-batching does not support dynamic networks!");
// check the batch dim: either 0th (and the original batch size of 1) or none
if (shape.size() && ov::DimensionTracker::get_label(shape[0])) {
if (shape[0] != 1)
OPENVINO_THROW("Auto-batching does not reshape/re-batch originally batched networks!");
const auto& node = output->input_value(0);
batched_outputs.insert(
ov::op::util::get_ie_output_name(ov::Output<const ov::Node>(node.get_node(), node.get_index())));
batched_outputs.insert(output_id);
} else {
// if the 0-th dim is not for the batch, then we support only the case when NONE dimension is batch
for (size_t s = 1; s < shape.size(); s++)
Expand Down Expand Up @@ -266,13 +265,13 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model(const std::shared_ptr<
if (meta_device.device_batch_size > 1 && batched_inputs.size()) {
try {
auto inputs = reshaped->inputs();
std::map<ov::Output<ov::Node>, ov::PartialShape> partial_shapes;
for (auto& input : inputs) {
auto input_shape = input.get_shape();
if (batched_inputs.find(ov::op::util::get_ie_output_name(input)) != batched_inputs.end()) {
std::map<std::size_t, ov::PartialShape> partial_shapes;
for (size_t input_id = 0; input_id < inputs.size(); input_id++) {
auto input_shape = inputs[input_id].get_shape();
if (batched_inputs.find(input_id) != batched_inputs.end()) {
input_shape[0] = meta_device.device_batch_size;
}
partial_shapes.insert({input, ov::PartialShape(input_shape)});
partial_shapes.insert({input_id, ov::PartialShape(input_shape)});
}

reshaped->reshape(partial_shapes);
Expand Down
41 changes: 20 additions & 21 deletions src/plugins/auto_batch/src/sync_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace ov {
namespace autobatch_plugin {

inline ov::SoPtr<ov::ITensor> create_shared_tensor_on_batched_tensor(ov::SoPtr<ov::ITensor> batched_tensor,
std::string name,
const std::set<std::string>& batched_names,
std::size_t port,
const std::set<std::size_t>& batched_ports,
size_t batch_id,
size_t batch_num) {
auto ptr = static_cast<uint8_t*>(batched_tensor->data());
auto size_per_batch = batched_tensor->get_byte_size() / batch_num;
auto batched_shape = batched_tensor->get_shape();
// for performance reason (copy avoidance) current impl of the auto-batching supports only batching by 0th dim
if (batched_names.count(name)) {
if (batched_ports.count(port)) {
batched_shape[0] = 1;
return {ov::make_tensor(batched_tensor->get_element_type(), batched_shape, ptr + size_per_batch * batch_id),
batched_tensor._so};
Expand All @@ -35,8 +35,8 @@ SyncInferRequest::SyncInferRequest(
const std::shared_ptr<ov::autobatch_plugin::CompiledModel::WorkerInferRequest>& worker_request,
int batch_id,
int num_batch,
const std::set<std::string>& batched_inputs,
const std::set<std::string>& batched_outputs)
const std::set<std::size_t>& batched_inputs,
const std::set<std::size_t>& batched_outputs)
: ov::ISyncInferRequest(compiled_model),
m_batched_request_wrapper(worker_request),
m_batch_id(batch_id),
Expand All @@ -49,34 +49,33 @@ size_t SyncInferRequest::get_batch_size() const {
return m_batch_size;
}

void SyncInferRequest::share_tensors_with_batched_req(const std::set<std::string>& batched_inputs,
const std::set<std::string>& batched_outputs) {
for (const auto& it : get_inputs()) {
auto name = ov::op::util::get_ie_output_name(it);
void SyncInferRequest::share_tensors_with_batched_req(const std::set<std::size_t>& batched_inputs,
const std::set<std::size_t>& batched_outputs) {
const auto inputs = get_inputs();
for (size_t input_id = 0; input_id < inputs.size(); input_id++) {
const auto& input = inputs[input_id];
ov::SoPtr<ov::ITensor> res;
auto batched_tensor = m_batched_request_wrapper->_infer_request_batched->get_tensor(it);
auto batched_tensor = m_batched_request_wrapper->_infer_request_batched->get_tensor(input);
if (!batched_tensor._so)
batched_tensor._so = m_batched_request_wrapper->_infer_request_batched._so;
res = create_shared_tensor_on_batched_tensor(batched_tensor,
std::move(name),
batched_inputs,
m_batch_id,
m_batch_size);
set_tensor(it, res);
res =
create_shared_tensor_on_batched_tensor(batched_tensor, input_id, batched_inputs, m_batch_id, m_batch_size);
set_tensor(input, res);
}

for (const auto& it : get_outputs()) {
auto name = ov::op::util::get_ie_output_name(it.get_node_shared_ptr()->input_value(0));
const auto& outputs = get_outputs();
for (size_t output_id = 0; output_id < outputs.size(); output_id++) {
const auto& output = outputs[output_id];
ov::SoPtr<ov::ITensor> res;
auto batched_tensor = m_batched_request_wrapper->_infer_request_batched->get_tensor(it);
auto batched_tensor = m_batched_request_wrapper->_infer_request_batched->get_tensor(output);
if (!batched_tensor._so)
batched_tensor._so = m_batched_request_wrapper->_infer_request_batched._so;
res = create_shared_tensor_on_batched_tensor(batched_tensor,
std::move(name),
output_id,
batched_outputs,
m_batch_id,
m_batch_size);
set_tensor(it, res);
set_tensor(output, res);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/auto_batch/src/sync_infer_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SyncInferRequest : public ov::ISyncInferRequest {
const std::shared_ptr<ov::autobatch_plugin::CompiledModel::WorkerInferRequest>& worker_request,
int batch_id,
int num_batch,
const std::set<std::string>& batched_inputs = {},
const std::set<std::string>& batched_outputs = {});
const std::set<std::size_t>& batched_inputs = {},
const std::set<std::size_t>& batched_outputs = {});

// Batch-Device impl specific: sets the data (blobs from the device request to the batched device request)
void set_tensors_to_another_request(ov::SoPtr<ov::IAsyncInferRequest>& req);
Expand Down Expand Up @@ -48,8 +48,8 @@ class SyncInferRequest : public ov::ISyncInferRequest {
protected:
void copy_tensor_if_needed(const ov::SoPtr<ov::ITensor>& src, ov::SoPtr<ov::ITensor>& dst, const bool bInput);

void share_tensors_with_batched_req(const std::set<std::string>& batched_inputs,
const std::set<std::string>& batched_outputs);
void share_tensors_with_batched_req(const std::set<std::size_t>& batched_inputs,
const std::set<std::size_t>& batched_outputs);

size_t m_batch_id;

Expand Down
25 changes: 11 additions & 14 deletions src/plugins/auto_batch/tests/unit/async_infer_request_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class AutoBatchAsyncInferRequestTest : public ::testing::TestWithParam<AutoBatch

ov::AnyMap m_config;
DeviceInformation m_device_info;
std::set<std::string> m_batched_inputs;
std::set<std::string> m_batched_outputs;
std::set<std::size_t> m_batched_inputs;
std::set<std::size_t> m_batched_outputs;
ov::SoPtr<ov::IRemoteContext> m_remote_context;

std::shared_ptr<CompiledModel> m_auto_batch_compile_model;
Expand Down Expand Up @@ -121,13 +121,13 @@ class AutoBatchAsyncInferRequestTest : public ::testing::TestWithParam<AutoBatch

auto reshaped = m_model->clone();
auto inputs = reshaped->inputs();
std::map<ov::Output<ov::Node>, ov::PartialShape> partial_shapes;
for (auto& input : inputs) {
auto input_shape = input.get_shape();
if (m_batched_inputs.find(ov::op::util::get_ie_output_name(input)) != m_batched_inputs.end()) {
std::map<std::size_t, ov::PartialShape> partial_shapes;
for (size_t input_id = 0; input_id < inputs.size(); input_id++) {
auto input_shape = inputs[input_id].get_shape();
if (m_batched_inputs.find(input_id) != m_batched_inputs.end()) {
input_shape[0] = m_batch_size;
}
partial_shapes.insert({input, ov::PartialShape(input_shape)});
partial_shapes.insert({input_id, ov::PartialShape(input_shape)});
}

reshaped->reshape(partial_shapes);
Expand Down Expand Up @@ -228,15 +228,12 @@ class AutoBatchAsyncInferRequestTest : public ::testing::TestWithParam<AutoBatch

void prepare_input(std::shared_ptr<ov::Model>& model, int batch_size) {
const auto& params = model->get_parameters();
for (size_t i = 0; i < params.size(); i++) {
m_batched_inputs.insert(ov::op::util::get_ie_output_name(params[i]->output(0)));
for (size_t input_id = 0; input_id < params.size(); input_id++) {
m_batched_inputs.insert(input_id);
}
const auto& results = model->get_results();
for (size_t i = 0; i < results.size(); i++) {
const auto& output = results[i];
const auto& node = output->input_value(0);
m_batched_outputs.insert(
ov::op::util::get_ie_output_name(ov::Output<const ov::Node>(node.get_node(), node.get_index())));
for (size_t output_id = 0; output_id < results.size(); output_id++) {
m_batched_outputs.insert(output_id);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "common_test_utils/subgraph_builders/multi_single_conv.hpp"
#include "mock_common.hpp"
#include "openvino/runtime/threading/immediate_executor.hpp"
#include "unit_test_utils/mocks/openvino/runtime/mock_icore.hpp"
#include "common_test_utils/subgraph_builders/multi_single_conv.hpp"

using CreateInferRequestTestParams = std::tuple<int, // batch_size
int>; // inferReq number
Expand All @@ -24,8 +24,8 @@ class CompileModelCreateInferRequestTest : public ::testing::TestWithParam<Creat

ov::AnyMap m_config;
DeviceInformation m_device_info;
std::set<std::string> m_batched_inputs;
std::set<std::string> m_batched_outputs;
std::set<std::size_t> m_batched_inputs;
std::set<std::size_t> m_batched_outputs;
ov::SoPtr<ov::IRemoteContext> m_remote_context;

std::shared_ptr<MockAutoBatchCompileModel> m_auto_batch_compile_model;
Expand Down Expand Up @@ -77,8 +77,8 @@ class CompileModelCreateInferRequestTest : public ::testing::TestWithParam<Creat
m_config = {{ov::auto_batch_timeout(static_cast<uint32_t>(200))}};

m_device_info = {"CPU", {}, m_batch_size};
m_batched_inputs = {"Parameter_0"};
m_batched_outputs = {"Convolution_20"};
m_batched_inputs = {};
m_batched_outputs = {};

if (m_batch_size > 1) {
m_i_compile_model_with_batch = std::make_shared<NiceMock<MockICompiledModel>>(m_model, m_auto_batch_plugin);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/auto_batch/tests/unit/mock_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class MockAutoBatchCompileModel : public CompiledModel {
const std::shared_ptr<const ov::IPlugin>& plugin,
const ov::AnyMap& config,
const DeviceInformation& device_info,
const std::set<std::string>& batched_inputs,
const std::set<std::string>& batched_outputs,
const std::set<std::size_t>& batched_inputs,
const std::set<std::size_t>& batched_outputs,
const ov::SoPtr<ov::ICompiledModel>& compiled_model_with_batch,
const ov::SoPtr<ov::ICompiledModel>& compiled_model_without_batch,
const ov::SoPtr<ov::IRemoteContext>& context)
Expand Down
19 changes: 8 additions & 11 deletions src/plugins/auto_batch/tests/unit/sync_infer_request_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class AutoBatchRequestTest : public ::testing::TestWithParam<AutoBatchRequestTes

ov::AnyMap m_config;
DeviceInformation m_device_info;
std::set<std::string> m_batched_inputs;
std::set<std::string> m_batched_outputs;
std::set<std::size_t> m_batched_inputs;
std::set<std::size_t> m_batched_outputs;
ov::SoPtr<ov::IRemoteContext> m_remote_context;

std::shared_ptr<MockAutoBatchCompileModel> m_auto_batch_compile_model;
Expand Down Expand Up @@ -95,8 +95,8 @@ class AutoBatchRequestTest : public ::testing::TestWithParam<AutoBatchRequestTes
m_config = {{ov::auto_batch_timeout(static_cast<uint32_t>(200))}};

m_device_info = {"CPU", {}, m_batch_size};
m_batched_inputs = {"Parameter_0"};
m_batched_outputs = {"Convolution_20"};
m_batched_inputs = {};
m_batched_outputs = {};

m_i_compile_model_with_batch = std::make_shared<NiceMock<MockICompiledModel>>(m_model, m_auto_batch_plugin);
m_compile_model_with_batch = {m_i_compile_model_with_batch, {}};
Expand Down Expand Up @@ -147,15 +147,12 @@ class AutoBatchRequestTest : public ::testing::TestWithParam<AutoBatchRequestTes

void prepare_input(std::shared_ptr<ov::Model>& model, int batch_size) {
const auto& params = model->get_parameters();
for (size_t i = 0; i < params.size(); i++) {
m_batched_inputs.insert(ov::op::util::get_ie_output_name(params[i]->output(0)));
for (size_t input_id = 0; input_id < params.size(); input_id++) {
m_batched_inputs.insert(input_id);
}
const auto& results = model->get_results();
for (size_t i = 0; i < results.size(); i++) {
const auto& output = results[i];
const auto& node = output->input_value(0);
m_batched_outputs.insert(
ov::op::util::get_ie_output_name(ov::Output<const ov::Node>(node.get_node(), node.get_index())));
for (size_t output_id = 0; output_id < results.size(); output_id++) {
m_batched_outputs.insert(output_id);
}
}
};
Expand Down
Loading