Skip to content

Commit 204f406

Browse files
tau233CarlosLeeGit
authored andcommitted
flowunit: add inference multi_batch_in_buffer config
1 parent 132e8b2 commit 204f406

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/drivers/inference_engine/mindspore/mindspore_inference.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ modelbox::Status MindSporeInference::Init(
223223
for (auto &input_tensor : model_->GetInputs()) {
224224
// check model info & whether padding
225225
if (!model_need_padding_ && input_tensor.Shape()[0] > 1) {
226-
model_need_padding_ = true;
226+
model_need_padding_ = !multi_batch_in_buffer_;
227227
auto max_batch_size = input_tensor.Shape()[0];
228228
if (config_batch_size_ > max_batch_size) {
229229
auto error_msg =
@@ -283,6 +283,9 @@ modelbox::Status MindSporeInference::Open(
283283
config_file_ = relpath + "/" + config_file_;
284284
}
285285

286+
multi_batch_in_buffer_ =
287+
merge_config->GetBool("config.multi_batch_in_buffer", false);
288+
286289
ret = Init(unit_desc->GetModelEntry(), merge_config,
287290
flowunit_device_->GetDeviceManager()->GetDrivers());
288291
if (ret != modelbox::STATUS_SUCCESS) {
@@ -384,7 +387,7 @@ void MindSporeInference::PrepareInputTensor(
384387
const_cast<void *>(input_buffer_list->ConstData()));
385388
}
386389
// set current batch size
387-
if (!model_need_padding_) {
390+
if (!multi_batch_in_buffer_ && !model_need_padding_) {
388391
input_shape[0] = input_buffer_list->Size();
389392
}
390393
MBLOG_DEBUG << "input name: " << name << " shape: ";
@@ -474,6 +477,10 @@ modelbox::Status MindSporeInference::PrepareOutputBufferList(
474477
size_t buffer_output_batch = tensor_output_batch - padding_batch_size_;
475478
size_t output_batch_bytes =
476479
ms_outputs[i].DataSize() / ms_outputs[i].Shape()[0];
480+
if (multi_batch_in_buffer_) {
481+
buffer_output_batch = 1;
482+
output_batch_bytes = ms_outputs[i].DataSize();
483+
}
477484
MBLOG_DEBUG << "tensor_output_batch:" << tensor_output_batch
478485
<< ", padding_batch_size:" << padding_batch_size_
479486
<< ", output_batch_size:" << buffer_output_batch;
@@ -491,7 +498,9 @@ modelbox::Status MindSporeInference::PrepareOutputBufferList(
491498

492499
auto tensor_shape = ms_outputs[i].Shape();
493500
std::vector<size_t> output_shape;
494-
tensor_shape[0] = 1;
501+
if (!multi_batch_in_buffer_) {
502+
tensor_shape[0] = 1;
503+
}
495504
MBLOG_DEBUG << "output shape: ";
496505
for (const auto &item : tensor_shape) {
497506
output_shape.push_back(item);

src/drivers/inference_engine/mindspore/mindspore_inference.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class MindSporeInference {
7676
struct MindSporeIOList io_list_;
7777
std::string config_file_;
7878
std::set<mindspore::DeviceType> device_type_;
79+
bool multi_batch_in_buffer_{false};
7980
bool model_need_padding_{false};
8081
size_t padding_batch_size_{0};
8182
uint32_t config_batch_size_{1};

0 commit comments

Comments
 (0)