From 9c3f29c23aa0db119937b31d5d2dfd8b3710107d Mon Sep 17 00:00:00 2001 From: zhaizhiqiang Date: Tue, 13 Apr 2021 19:33:12 +0800 Subject: [PATCH] prepare data when getting inputs --- mindspore/lite/src/cxx_api/model/model_impl.cc | 1 + mindspore/lite/tools/benchmark/benchmark.cc | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/mindspore/lite/src/cxx_api/model/model_impl.cc b/mindspore/lite/src/cxx_api/model/model_impl.cc index e01b9f6d08..1ced137344 100644 --- a/mindspore/lite/src/cxx_api/model/model_impl.cc +++ b/mindspore/lite/src/cxx_api/model/model_impl.cc @@ -213,6 +213,7 @@ std::vector ModelImpl::GetInputs() { } res.resize(inputs.size()); for (size_t i = 0; i < inputs.size(); i++) { + inputs[i]->MutableData(); // prepare data auto impl = std::shared_ptr(new (std::nothrow) MSTensor::Impl(inputs[i])); if (impl == nullptr || impl->lite_tensor() == nullptr) { MS_LOG(ERROR) << "Create tensor failed."; diff --git a/mindspore/lite/tools/benchmark/benchmark.cc b/mindspore/lite/tools/benchmark/benchmark.cc index 8eabdf1cb4..b5e9d0c233 100644 --- a/mindspore/lite/tools/benchmark/benchmark.cc +++ b/mindspore/lite/tools/benchmark/benchmark.cc @@ -410,6 +410,10 @@ int Benchmark::MarkPerformance() { uint64_t time_avg = 0; for (int i = 0; i < flags_->loop_count_; i++) { + auto inputs = session_->GetInputs(); + for (auto tensor : inputs) { + tensor->MutableData(); // prepare data + } session_->BindThread(true); auto start = GetTimeUs(); auto status = session_->RunGraph(before_call_back_, after_call_back_);