From dc9a8eb1ccf67b5b6838194102d3dbfd7c2e6b4d Mon Sep 17 00:00:00 2001 From: yuchaojie Date: Wed, 31 Mar 2021 16:13:14 +0800 Subject: [PATCH] fix codedex warning --- .../optimizer/ascend/ir_fission/bn_split.cc | 3 +- .../mindir/avg_pool_grad_unify_mindir.cc | 31 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/bn_split.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/bn_split.cc index 245186ea47..470d808517 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/bn_split.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fission/bn_split.cc @@ -216,8 +216,9 @@ AnfNodePtr CreateAllReduceAndMul(const FuncGraphPtr &graph, const AnfNodePtr &al // use SyncBatchNorm's opid as AllReduce's fusion attr auto sync_bn_opname = sync_bn_cnode->fullname_with_scope(); auto opid_pos = sync_bn_opname.rfind("-op"); - if (opid_pos == std::string::npos) { + if (opid_pos == std::string::npos || opid_pos + 3 >= sync_bn_opname.size()) { MS_LOG(EXCEPTION) << "op[" << sync_bn_cnode->DebugString() << "] has no opid."; + return nullptr; } int64_t opid = std::stol(sync_bn_opname.substr(opid_pos + 3)); // user defined fusion should be greater than 1 diff --git a/mindspore/ccsrc/backend/optimizer/ascend/mindir/avg_pool_grad_unify_mindir.cc b/mindspore/ccsrc/backend/optimizer/ascend/mindir/avg_pool_grad_unify_mindir.cc index 3e099715e4..da52b478ae 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/mindir/avg_pool_grad_unify_mindir.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/mindir/avg_pool_grad_unify_mindir.cc @@ -67,19 +67,8 @@ int64_t windowed_output_size(int64_t input_size, int64_t ksize, int64_t stride, return output; } -ValueNodePtr CreateMeanMatrixValueNode(const FuncGraphPtr &func_graph, const std::vector &x_shape, - const std::vector &k_size, const std::vector &stride, - const PadMode pad_mode, const TypeId x_dtype) { - MS_EXCEPTION_IF_NULL(func_graph); - auto kernel_graph = func_graph->cast(); - MS_EXCEPTION_IF_NULL(kernel_graph); - if (x_shape.size() != kShapeDimNum || k_size.size() != kShapeDimNum || stride.size() != kShapeDimNum) { - MS_LOG(EXCEPTION) << "The dim of x_shape or kernel_size or strides of AvgPoolGrad should be 4."; - } - int64_t pad_top, pad_bottom, pad_left, pad_right; - int64_t h_output = windowed_output_size(x_shape[2], k_size[2], stride[2], pad_mode, &pad_top, &pad_bottom); - int64_t w_output = windowed_output_size(x_shape[3], k_size[3], stride[3], pad_mode, &pad_left, &pad_right); - +std::vector> GetAssistInputMatrix(const std::vector &x_shape, int64_t pad_top, + int64_t pad_bottom, int64_t pad_left, int64_t pad_right) { // `assist_input_matrix` is a 2d matrix with input_shape after padding, // the value of element which is padded is 0, else are 1. // For each element of output, it is mapped for slide window: `[h*h_stride : h*h_stride + h_ksize, @@ -102,6 +91,22 @@ ValueNodePtr CreateMeanMatrixValueNode(const FuncGraphPtr &func_graph, const std assist_input_matrix.emplace_back(tmp_one_vector); } } + return assist_input_matrix; +} + +ValueNodePtr CreateMeanMatrixValueNode(const FuncGraphPtr &func_graph, const std::vector &x_shape, + const std::vector &k_size, const std::vector &stride, + const PadMode pad_mode, const TypeId x_dtype) { + MS_EXCEPTION_IF_NULL(func_graph); + auto kernel_graph = func_graph->cast(); + MS_EXCEPTION_IF_NULL(kernel_graph); + if (x_shape.size() != kShapeDimNum || k_size.size() != kShapeDimNum || stride.size() != kShapeDimNum) { + MS_LOG(EXCEPTION) << "The dim of x_shape or kernel_size or strides of AvgPoolGrad should be 4."; + } + int64_t pad_top, pad_bottom, pad_left, pad_right; + int64_t h_output = windowed_output_size(x_shape[2], k_size[2], stride[2], pad_mode, &pad_top, &pad_bottom); + int64_t w_output = windowed_output_size(x_shape[3], k_size[3], stride[3], pad_mode, &pad_left, &pad_right); + auto assist_input_matrix = GetAssistInputMatrix(x_shape, pad_top, pad_bottom, pad_left, pad_right); // calculate output std::vector hw_output(h_output * w_output, 0.0);