From fc022ea9be56387fba99aa38caa7a33d1fa271a1 Mon Sep 17 00:00:00 2001 From: zhaoxinxin Date: Mon, 11 Jan 2021 21:43:32 +0800 Subject: [PATCH] modified: ge/graph/preprocess/graph_preprocess.cc --- ge/graph/preprocess/graph_preprocess.cc | 26 +++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/ge/graph/preprocess/graph_preprocess.cc b/ge/graph/preprocess/graph_preprocess.cc index 95f67a2b..f0a8c1f3 100644 --- a/ge/graph/preprocess/graph_preprocess.cc +++ b/ge/graph/preprocess/graph_preprocess.cc @@ -935,7 +935,10 @@ Status ParseDynamicInputShapeRange(const std::string &shape_range, return PARAM_INVALID; } for (auto &shape_range_str : shape_range_set) { - if (shape_range_str.empty()) { + if (shape_range_str.size() < 3) { + // shape_range_str should be "[2~3,1" + // or ",[2~3,1". because we should trim '[' or ',[' + // so shape_range_str.size() < 3 is invalid continue; } // trim start bytes, after that, single input should be "1~20,3,3~6,-1" @@ -1017,16 +1020,27 @@ Status UpdateDynamicInputShapeRange(const ge::GeAttrValue::INT index, return PARAM_INVALID; } for (size_t i = 0; i < origin_shape.GetDimNum(); ++i) { - if (current_shape_range_vec.at(i).first == current_shape_range_vec.at(i).second) { + auto curr_dim = origin_shape.GetDim(i); + auto left_range = current_shape_range_vec.at(i).first; + auto right_range = current_shape_range_vec.at(i).second; + if (left_range == right_range) { // given shape_range is known dim, check is same as origin or not - if (origin_shape.GetDim(i) != current_shape_range_vec.at(i).first) { + if (curr_dim != left_range) { GELOGE(PARAM_INVALID, "Given shape range is %ld, current dim shape is %ld, not match.Pleace Check.", - current_shape_range_vec.at(i).first, origin_shape.GetDim(i)); + left_range, curr_dim); return PARAM_INVALID; } - origin_shape.SetDim(i, current_shape_range_vec.at(i).first); + origin_shape.SetDim(i, left_range); } else { - origin_shape.SetDim(i, -1); + // given shape_range is fix range, check input_shape is in this range or not + if (right_range != UNKNOWN_DIM) { + if ((curr_dim < left_range) || (curr_dim > right_range)) { + GELOGE(PARAM_INVALID, "Given shape range is [%ld~%ld], current dim shape is %ld, out of range.Pleace Check.", + left_range, right_range, curr_dim); + return PARAM_INVALID; + } + } + origin_shape.SetDim(i, UNKNOWN_DIM); } } desc.SetShape(origin_shape);