310 ocr suport dynamic hw

This commit is contained in:
zhengyuanhua 2021-11-25 16:17:06 +08:00
parent c0332b4fc7
commit 9f1c444178
4 changed files with 13 additions and 6 deletions

View File

@ -352,7 +352,7 @@ class MS_API Ascend310DeviceInfo : public DeviceInfoContext {
/// \brief Set the dynamic image size of model inputs. /// \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); inline void SetDynamicImageSize(const std::string &dynamic_image_size);
/// \brief Get dynamic image size of model inputs. /// \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)); SetDynamicImageSize(StringToChar(dynamic_image_size));
} }
std::string Ascend310DeviceInfo::GetDynamicImageSize() const { std::string Ascend310DeviceInfo::GetDynamicImageSize() const { return CharToString(GetDynamicImageSizeChar()); }
return CharToString(GetDynamicImageSizeChar());
}
void Ascend310DeviceInfo::SetPrecisionMode(const std::string &precision_mode) { void Ascend310DeviceInfo::SetPrecisionMode(const std::string &precision_mode) {
SetPrecisionMode(StringToChar(precision_mode)); SetPrecisionMode(StringToChar(precision_mode));

View File

@ -207,9 +207,9 @@ STATUS ModelProcess::CreateDataBuffer(void **data_mem_buffer, size_t buffer_size
aclError ret; aclError ret;
auto free_data_buffer = [this](void *dataMemBuffer) { auto free_data_buffer = [this](void *dataMemBuffer) {
if (!is_run_on_device_) { if (!is_run_on_device_) {
aclrtFree(dataMemBuffer); (void)aclrtFree(dataMemBuffer);
} else { } else {
aclrtFreeHost(dataMemBuffer); (void)aclrtFreeHost(dataMemBuffer);
} }
}; };

View File

@ -213,11 +213,19 @@ STATUS AclPassImpl::DeparseGraph(const FuncGraphPtr &func_graph, const FuncGraph
return lite::RET_OK; 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) { STATUS AclPassImpl::CommonPass(const FuncGraphPtr &func_graph) {
if (!lite::RunOptimizerPass(func_graph, {kRemoveRedundantOpPass})) { if (!lite::RunOptimizerPass(func_graph, {kRemoveRedundantOpPass})) {
MS_LOG(ERROR) << "Remove redundant op pass failed."; MS_LOG(ERROR) << "Remove redundant op pass failed.";
return lite::RET_ERROR; 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})) { if (!lite::RunOptimizerPass(func_graph, {kConstFoldPass})) {
MS_LOG(ERROR) << "Const fold pass failed."; MS_LOG(ERROR) << "Const fold pass failed.";
return lite::RET_ERROR; return lite::RET_ERROR;

View File

@ -65,6 +65,7 @@ class AclPassImpl {
void SetAclModelInitOptions(const std::shared_ptr<Ascend310DeviceInfo> &ascend310_info); void SetAclModelInitOptions(const std::shared_ptr<Ascend310DeviceInfo> &ascend310_info);
void SetAclModelBuildOptions(const std::shared_ptr<Ascend310DeviceInfo> &ascend310_info); void SetAclModelBuildOptions(const std::shared_ptr<Ascend310DeviceInfo> &ascend310_info);
std::string AdjustCnodeName(const PrimitivePtr &prim); std::string AdjustCnodeName(const PrimitivePtr &prim);
bool IsDynamicInput();
std::string device_type_; std::string device_type_;
FmkType fmk_type_; FmkType fmk_type_;