From 9f1c44417822ab8e2a80f0e9a96181ddcd74780b Mon Sep 17 00:00:00 2001 From: zhengyuanhua Date: Thu, 25 Nov 2021 16:17:06 +0800 Subject: [PATCH] 310 ocr suport dynamic hw --- include/api/context.h | 6 ++---- .../src/runtime/kernel/ascend310/src/model_process.cc | 4 ++-- .../lite/tools/converter/adapter/acl/acl_pass_impl.cc | 8 ++++++++ .../lite/tools/converter/adapter/acl/acl_pass_impl.h | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/api/context.h b/include/api/context.h index a4506a590f8..4dc67879886 100644 --- a/include/api/context.h +++ b/include/api/context.h @@ -352,7 +352,7 @@ class MS_API Ascend310DeviceInfo : public DeviceInfoContext { /// \brief Set the dynamic image size of model inputs. /// - /// \param[in] image size e.g. "66,66;88,88". + /// \param[in] image size hw e.g. "66,88;32,64" means h1:66,w1:88; h2:32,w2:64. inline void SetDynamicImageSize(const std::string &dynamic_image_size); /// \brief Get dynamic image size of model inputs. @@ -444,9 +444,7 @@ void Ascend310DeviceInfo::SetDynamicImageSize(const std::string &dynamic_image_s SetDynamicImageSize(StringToChar(dynamic_image_size)); } -std::string Ascend310DeviceInfo::GetDynamicImageSize() const { - return CharToString(GetDynamicImageSizeChar()); -} +std::string Ascend310DeviceInfo::GetDynamicImageSize() const { return CharToString(GetDynamicImageSizeChar()); } void Ascend310DeviceInfo::SetPrecisionMode(const std::string &precision_mode) { SetPrecisionMode(StringToChar(precision_mode)); diff --git a/mindspore/lite/src/runtime/kernel/ascend310/src/model_process.cc b/mindspore/lite/src/runtime/kernel/ascend310/src/model_process.cc index 43abde1e778..53b45ea7e10 100644 --- a/mindspore/lite/src/runtime/kernel/ascend310/src/model_process.cc +++ b/mindspore/lite/src/runtime/kernel/ascend310/src/model_process.cc @@ -207,9 +207,9 @@ STATUS ModelProcess::CreateDataBuffer(void **data_mem_buffer, size_t buffer_size aclError ret; auto free_data_buffer = [this](void *dataMemBuffer) { if (!is_run_on_device_) { - aclrtFree(dataMemBuffer); + (void)aclrtFree(dataMemBuffer); } else { - aclrtFreeHost(dataMemBuffer); + (void)aclrtFreeHost(dataMemBuffer); } }; diff --git a/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc b/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc index fd331e6fce0..80df5aa21df 100644 --- a/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc +++ b/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.cc @@ -213,11 +213,19 @@ STATUS AclPassImpl::DeparseGraph(const FuncGraphPtr &func_graph, const FuncGraph return lite::RET_OK; } +bool AclPassImpl::IsDynamicInput() { + return !acl_model_option_cfg_.dynamic_image_size.empty() || !acl_model_option_cfg_.dynamic_batch_size.empty(); +} + STATUS AclPassImpl::CommonPass(const FuncGraphPtr &func_graph) { if (!lite::RunOptimizerPass(func_graph, {kRemoveRedundantOpPass})) { MS_LOG(ERROR) << "Remove redundant op pass failed."; return lite::RET_ERROR; } + if (IsDynamicInput()) { + MS_LOG(INFO) << "Dynamic input no need to run const fold pass."; + return lite::RET_OK; + } if (!lite::RunOptimizerPass(func_graph, {kConstFoldPass})) { MS_LOG(ERROR) << "Const fold pass failed."; return lite::RET_ERROR; diff --git a/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.h b/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.h index 997aa751672..33e5e2d881d 100644 --- a/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.h +++ b/mindspore/lite/tools/converter/adapter/acl/acl_pass_impl.h @@ -65,6 +65,7 @@ class AclPassImpl { void SetAclModelInitOptions(const std::shared_ptr &ascend310_info); void SetAclModelBuildOptions(const std::shared_ptr &ascend310_info); std::string AdjustCnodeName(const PrimitivePtr &prim); + bool IsDynamicInput(); std::string device_type_; FmkType fmk_type_;