diff --git a/ge/graph/load/new_model_manager/davinci_model.cc b/ge/graph/load/new_model_manager/davinci_model.cc index 37a39308..cc2bc9ed 100755 --- a/ge/graph/load/new_model_manager/davinci_model.cc +++ b/ge/graph/load/new_model_manager/davinci_model.cc @@ -1719,7 +1719,7 @@ Status DavinciModel::GetInputOutputDescInfo(vector &input_d GELOGI("data_op_list_ is empty or input_desc size is not 1."); } else { vector input_formats; - GE_CHK_STATUS_RET(GetInputDescInfo(input_desc, input_formats), "get input desc info failed."); + GE_CHK_STATUS_RET(GetInputDescInfo(input_desc, input_formats, false), "get input desc info failed."); } vector output_formats; @@ -1730,13 +1730,13 @@ Status DavinciModel::GetInputOutputDescInfo(vector &input_d Status DavinciModel::GetInputOutputDescInfo(vector &input_desc, vector &output_desc, vector &input_formats, - vector &output_formats) { + vector &output_formats, bool by_dims) { if (input_addrs_list_.empty() || input_addrs_list_[0].size() != 1) { GELOGE(FAILED, "OP List Pointer is null or input_desc size is not 1!"); return FAILED; } - GE_CHK_STATUS_RET(GetInputDescInfo(input_desc, input_formats), "get input desc info failed"); + GE_CHK_STATUS_RET(GetInputDescInfo(input_desc, input_formats, by_dims), "get input desc info failed"); GE_CHK_STATUS_RET(GetOutputDescInfo(output_desc, output_formats), "get output desc info failed"); return SUCCESS; @@ -1908,53 +1908,51 @@ void DavinciModel::GetModelAttr(vector &out_shape_info) const { out_shape_info.insert(out_shape_info.end(), dynamic_output_shape_info_.begin(), dynamic_output_shape_info_.end()); } -void DavinciModel::SetInputDimsInfo(const vector &model_input_dims, Format &format, - InputOutputDescInfo &input) { +void DavinciModel::SetInputDimsInfo(const vector &input_dims, Format &format, ShapeDescription &shape_info) { uint32_t n, c, h, w; n = format == FORMAT_NHWC ? NHWC_DIM_N : NCHW_DIM_N; c = format == FORMAT_NHWC ? NHWC_DIM_C : NCHW_DIM_C; h = format == FORMAT_NHWC ? NHWC_DIM_H : NCHW_DIM_H; w = format == FORMAT_NHWC ? NHWC_DIM_W : NCHW_DIM_W; - if (model_input_dims.size() == static_cast(NORMAL_TENSOR_SIZE)) { - input.shape_info.num = model_input_dims[n]; - input.shape_info.height = model_input_dims[h]; - input.shape_info.width = model_input_dims[w]; - input.shape_info.channel = model_input_dims[c]; + if (input_dims.size() == static_cast(NORMAL_TENSOR_SIZE)) { + shape_info.num = input_dims[n]; + shape_info.height = input_dims[h]; + shape_info.width = input_dims[w]; + shape_info.channel = input_dims[c]; } - for (size_t k = 0; k < model_input_dims.size(); ++k) { - input.shape_info.dims.push_back(model_input_dims[k]); + for (size_t k = 0; k < input_dims.size(); ++k) { + shape_info.dims.push_back(input_dims[k]); } - return; } -void DavinciModel::CreateInputDimsInfo(const OpDescPtr &op_desc, Format format, InputOutputDescInfo &input) { - if (is_new_model_desc_ && op_desc->HasAttr(ATTR_NAME_INPUT_DIMS)) { - // When static aipp is set, need to get the model input dims which processed by aipp - vector model_input_dims; - (void)AttrUtils::GetListInt(op_desc, ATTR_NAME_INPUT_DIMS, model_input_dims); - SetInputDimsInfo(model_input_dims, format, input); - return; - } +void DavinciModel::CreateInputDimsInfo(const OpDescPtr &op_desc, Format format, + ShapeDescription &shape_info, ShapeDescription &dims_info) { // judge if this data is linked dynamic aipp first, multiply batch has been considered if (op_desc->HasAttr(ATTR_DYNAMIC_AIPP_INPUT_DIMS)) { vector dynamic_aipp_input_dims; (void)AttrUtils::GetListInt(op_desc, ATTR_DYNAMIC_AIPP_INPUT_DIMS, dynamic_aipp_input_dims); - SetInputDimsInfo(dynamic_aipp_input_dims, format, input); - return; + SetInputDimsInfo(dynamic_aipp_input_dims, format, shape_info); } else { // judge if this data is multiply batch if (!op_desc->HasAttr(ATTR_MBATCH_ORIGIN_INPUT_DIMS)) { vector input_dims = op_desc->GetInputDescPtr(0)->GetShape().GetDims(); - SetInputDimsInfo(input_dims, format, input); - return; + SetInputDimsInfo(input_dims, format, shape_info); } else { vector origin_input_dims; (void)AttrUtils::GetListInt(op_desc, ATTR_MBATCH_ORIGIN_INPUT_DIMS, origin_input_dims); - SetInputDimsInfo(origin_input_dims, format, input); - return; + SetInputDimsInfo(origin_input_dims, format, shape_info); } } + + if (op_desc->HasAttr(ATTR_NAME_INPUT_DIMS)) { + // When static aipp is set, need to get the model input dims which processed by aipp + vector model_input_dims; + (void)AttrUtils::GetListInt(op_desc, ATTR_NAME_INPUT_DIMS, model_input_dims); + SetInputDimsInfo(model_input_dims, format, dims_info); + } else { + dims_info = shape_info; + } } Status DavinciModel::InitInputDescInfo(const map &data_by_index) { @@ -1963,8 +1961,9 @@ Status DavinciModel::InitInputDescInfo(const map &data_by_i GE_CHECK_NOTNULL(op_desc->GetInputDescPtr(0)); InputOutputDescInfo input; + ShapeDescription dims_info; Format format = op_desc->GetInputDescPtr(0)->GetFormat(); - CreateInputDimsInfo(op_desc, format, input); + CreateInputDimsInfo(op_desc, format, input.shape_info, dims_info); input.data_type = op_desc->GetInputDescPtr(0)->GetDataType(); input.name = op_desc->GetName(); @@ -1973,16 +1972,19 @@ Status DavinciModel::InitInputDescInfo(const map &data_by_i input.size = input_size; input_formats_.push_back(format); input_descs_.push_back(input); + + input.shape_info = dims_info; + input_descs_dims_.push_back(input); } return SUCCESS; } -Status DavinciModel::GetInputDescInfo(vector &input_descs, vector &input_formats) { - input_descs.insert(input_descs.end(), input_descs_.begin(), input_descs_.end()); +Status DavinciModel::GetInputDescInfo(vector &input_descs, + vector &input_formats, bool by_dims) const { + const vector &input_desc_info = by_dims ? input_descs_dims_ : input_descs_; + input_descs.insert(input_descs.end(), input_desc_info.begin(), input_desc_info.end()); input_formats.insert(input_formats.end(), input_formats_.begin(), input_formats_.end()); - // cause GetInputDescInfo called not only once, set is_new_model_desc_ to false after calc the model input dims - is_new_model_desc_ = false; return SUCCESS; } diff --git a/ge/graph/load/new_model_manager/davinci_model.h b/ge/graph/load/new_model_manager/davinci_model.h index 4d5d2252..4ec0ec62 100755 --- a/ge/graph/load/new_model_manager/davinci_model.h +++ b/ge/graph/load/new_model_manager/davinci_model.h @@ -319,7 +319,7 @@ class DavinciModel { Status GetInputOutputDescInfo(vector &input_desc, vector &output_desc); Status GetInputOutputDescInfo(vector &input_desc, vector &output_desc, - vector &input_formats, vector &output_formats); + vector &input_formats, vector &output_formats, bool by_dims); /// /// @ingroup ge @@ -523,7 +523,7 @@ class DavinciModel { Status GetOrigInputInfo(uint32_t index, OriginInputInfo &orig_input_info) const; Status GetAllAippInputOutputDims(uint32_t index, vector &input_dims, vector &output_dims) const; - void SetModelDescVersion(bool is_new_model_desc) { is_new_model_desc_ = is_new_model_desc; } + // om file name void SetOmName(string om_name) { om_name_ = om_name; } @@ -603,11 +603,11 @@ class DavinciModel { Status InitWeightMem(void *dev_ptr, void *weight_ptr, size_t weight_size); Status InitFeatureMapAndP2PMem(void *dev_ptr, size_t mem_size); - void CreateInputDimsInfo(const OpDescPtr &op_desc, Format format, InputOutputDescInfo &input); + void CreateInputDimsInfo(const OpDescPtr &op_desc, Format format, ShapeDescription &shape1, ShapeDescription &shape2); - void SetInputDimsInfo(const vector &model_input_dims, Format &format, InputOutputDescInfo &input); + void SetInputDimsInfo(const vector &model_input_dims, Format &format, ShapeDescription &shape_info); - Status GetInputDescInfo(vector &input_desc, vector &input_formats); + Status GetInputDescInfo(vector &input_desc, vector &input_formats, bool by_dims) const; Status GetOutputDescInfo(vector &output_desc, vector &output_formats) const; Status InitTaskInfo(domi::ModelTaskDef &modelTaskInfo); @@ -1006,7 +1006,6 @@ class DavinciModel { bool is_op_debug_reg_ = false; void *op_debug_addr_ = nullptr; void *p2p_debug_addr_ = nullptr; - bool is_new_model_desc_{false}; bool is_online_infer_dynamic_ = false; bool is_getnext_sink_dynamic_ = false; vector cur_dynamic_dims_; @@ -1040,6 +1039,7 @@ class DavinciModel { map, vector>> aipp_dims_info_; vector input_descs_; + vector input_descs_dims_; vector input_formats_; vector output_descs_; vector output_formats_; diff --git a/ge/graph/load/new_model_manager/model_manager.cc b/ge/graph/load/new_model_manager/model_manager.cc index 22fddf86..60302dce 100755 --- a/ge/graph/load/new_model_manager/model_manager.cc +++ b/ge/graph/load/new_model_manager/model_manager.cc @@ -909,9 +909,7 @@ Status ModelManager::GetInputOutputDescInfo(const uint32_t model_id, vectorSetModelDescVersion(new_model_desc); - - return davinci_model->GetInputOutputDescInfo(input_desc, output_desc, inputFormats, outputFormats); + return davinci_model->GetInputOutputDescInfo(input_desc, output_desc, inputFormats, outputFormats, new_model_desc); } ///