From bfb75c7ece00a702eb28af8559eccefe961d9936 Mon Sep 17 00:00:00 2001 From: shen_jingxing Date: Fri, 8 Oct 2021 10:22:42 +0800 Subject: [PATCH] clear the alarm information of 1.5 branch --- .../core/ops/LayerNormBetaGammaBackprop.cc | 3 ++ mindspore/core/ops/abs.cc | 25 +++++++------ mindspore/core/ops/apply_adagrad_d_a.cc | 35 ++++++++++--------- mindspore/core/ops/apply_momentum.cc | 6 ++-- mindspore/core/ops/audio_spectrogram.cc | 2 +- mindspore/core/ops/avg_pool.cc | 8 ++--- mindspore/core/ops/avg_pool_3d.cc | 25 +++++++------ mindspore/core/ops/cdist.cc | 4 +-- mindspore/core/ops/conv2d.cc | 14 ++++---- mindspore/core/ops/ctc_loss_v2.cc | 2 +- mindspore/core/ops/ctc_loss_v2_grad.cc | 2 +- mindspore/core/ops/diag_part.cc | 2 +- .../ops/dynamic_broadcast_gradient_args.cc | 6 ++-- mindspore/core/ops/erfinv.cc | 9 +++-- mindspore/core/ops/expand_dims.cc | 2 +- mindspore/core/ops/flatten.cc | 4 +-- .../ops/fusion/conv2d_transpose_fusion.cc | 4 +-- mindspore/core/ops/grad/avg_pool_3d_grad.cc | 2 +- mindspore/core/ops/grad/cdist_grad.cc | 8 ++--- .../core/ops/grad/conv2d_backprop_filter.cc | 7 ++-- .../core/ops/grad/conv2d_backprop_input.cc | 2 +- mindspore/core/ops/grad/lstm_grad.cc | 31 +++++++++------- .../core/ops/grad/soft_margin_loss_grad.cc | 2 +- mindspore/core/ops/index_add.cc | 15 ++++---- mindspore/core/ops/lerp.cc | 8 ++--- mindspore/core/ops/masked_fill.cc | 2 +- mindspore/core/ops/merge.cc | 2 +- mindspore/core/ops/neighborexchange.cc | 8 +++-- mindspore/core/ops/ones.cc | 2 +- mindspore/core/ops/op_utils.cc | 12 +++---- mindspore/core/ops/reduce_sum.cc | 8 +++-- mindspore/core/ops/roll.cc | 4 ++- mindspore/core/ops/smooth_l1_loss.cc | 2 +- mindspore/core/ops/soft_margin_loss.cc | 2 +- mindspore/core/ops/soft_shrink.cc | 8 +++-- mindspore/core/ops/space_to_batch.cc | 7 ++-- mindspore/core/ops/sparse_apply_r_m_s_prop.cc | 28 ++++++++------- mindspore/core/ops/split.cc | 2 +- mindspore/core/ops/split.h | 2 +- mindspore/core/ops/split_v.cc | 26 +++++++------- mindspore/core/ops/square.cc | 25 +++++++------ mindspore/core/ops/strided_slice.cc | 3 +- mindspore/core/ops/unsqueeze.cc | 2 +- 43 files changed, 200 insertions(+), 173 deletions(-) diff --git a/mindspore/core/ops/LayerNormBetaGammaBackprop.cc b/mindspore/core/ops/LayerNormBetaGammaBackprop.cc index f325459b10f..8084d2778dd 100644 --- a/mindspore/core/ops/LayerNormBetaGammaBackprop.cc +++ b/mindspore/core/ops/LayerNormBetaGammaBackprop.cc @@ -28,6 +28,9 @@ namespace { abstract::TupleShapePtr LayerNormBetaGammaBackpropInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); + for (const auto &item : input_args) { + MS_EXCEPTION_IF_NULL(item); + } ValuePtr gamma_value_ptr = primitive->GetAttr("shape_gamma"); MS_EXCEPTION_IF_NULL(gamma_value_ptr); auto gamma_shape = GetValue(gamma_value_ptr); diff --git a/mindspore/core/ops/abs.cc b/mindspore/core/ops/abs.cc index 2f9b470e185..f5ab0da1986 100644 --- a/mindspore/core/ops/abs.cc +++ b/mindspore/core/ops/abs.cc @@ -32,8 +32,6 @@ void ImpleAbs(void *origin, void *target, size_t size) { MS_EXCEPTION_IF_NULL(target); auto origin_data = reinterpret_cast(origin); auto target_data = reinterpret_cast(target); - MS_EXCEPTION_IF_NULL(origin_data); - MS_EXCEPTION_IF_NULL(target_data); auto zero_val = static_cast(0); for (size_t i = 0; i < size; ++i) { target_data[i] = origin_data[i] >= zero_val ? origin_data[i] : -origin_data[i]; @@ -41,6 +39,7 @@ void ImpleAbs(void *origin, void *target, size_t size) { } abstract::ShapePtr AbsInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; return std::make_shared(in_shape); } @@ -83,47 +82,47 @@ ValuePtr AbsInferValue(const PrimitivePtr &prim, const std::vectordata_c(); switch (dtype) { case kNumberTypeInt8: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeInt16: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeInt32: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeInt64: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt8: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt16: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt32: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt64: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeFloat16: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeFloat32: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeFloat64: { - ImpleAbs(x_datac, result_datac, data_size); + ImpleAbs(x_datac, result_datac, IntToSize(data_size)); break; } default: { diff --git a/mindspore/core/ops/apply_adagrad_d_a.cc b/mindspore/core/ops/apply_adagrad_d_a.cc index 348684a6274..e449c8062e5 100644 --- a/mindspore/core/ops/apply_adagrad_d_a.cc +++ b/mindspore/core/ops/apply_adagrad_d_a.cc @@ -44,10 +44,11 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec auto l2_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex6]->BuildShape())[kShape]; auto global_step_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex7]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("lr_shape size", lr_shape.size(), kEqual, 0, primitive->name()); - (void)CheckAndConvertUtils::CheckInteger("l1_shape size", l1_shape.size(), kEqual, 0, primitive->name()); - (void)CheckAndConvertUtils::CheckInteger("l2_shape size", l2_shape.size(), kEqual, 0, primitive->name()); - (void)CheckAndConvertUtils::CheckInteger("global_step_shape size", global_step_shape.size(), kEqual, 0, + const int64_t input_nums = 0; + (void)CheckAndConvertUtils::CheckInteger("lr_shape size", lr_shape.size(), kEqual, input_nums, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("l1_shape size", l1_shape.size(), kEqual, input_nums, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("l2_shape size", l2_shape.size(), kEqual, input_nums, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("global_step_shape size", global_step_shape.size(), kEqual, input_nums, primitive->name()); return std::make_shared( std::vector{var_shape, gradient_accumulator_shape, gradient_squared_accumulator_shape}); @@ -72,25 +73,25 @@ TuplePtr InferType(const PrimitivePtr &prim, const std::vector const std::set valid_types = {kFloat16, kFloat32}; // gradient_accumulator、gradient_squared_accumulator、grad must have the same type as var std::map args; - args.insert({"var_type", var_type}); - args.insert({"gradient_accumulator_type", gradient_accumulator_type}); - args.insert({"gradient_squared_accumulator_type", gradient_squared_accumulator_type}); - args.insert({"grad_type", grad_type}); - CheckAndConvertUtils::CheckTensorTypeSame(args, valid_types, prim_name); + (void)args.insert({"var_type", var_type}); + (void)args.insert({"gradient_accumulator_type", gradient_accumulator_type}); + (void)args.insert({"gradient_squared_accumulator_type", gradient_squared_accumulator_type}); + (void)args.insert({"grad_type", grad_type}); + (void)CheckAndConvertUtils::CheckTensorTypeSame(args, valid_types, prim_name); // lr、l1、l2、global_step_type must be a scalar type std::map args_lr; std::map args_l1; std::map args_l2; std::map args_global_step; - args_lr.insert({"lr_type", lr_type}); - CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_lr, valid_types, prim_name); - args_l1.insert({"l1_type", l1_type}); - CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l1, valid_types, prim_name); - args_l2.insert({"l2_type", l2_type}); - CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l2, valid_types, prim_name); - args_global_step.insert({"global_step_type", global_step_type}); + (void)args_lr.insert({"lr_type", lr_type}); + (void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_lr, valid_types, prim_name); + (void)args_l1.insert({"l1_type", l1_type}); + (void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l1, valid_types, prim_name); + (void)args_l2.insert({"l2_type", l2_type}); + (void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_l2, valid_types, prim_name); + (void)args_global_step.insert({"global_step_type", global_step_type}); const std::set valid_types1 = {kInt32, kInt64}; - CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_global_step, valid_types1, prim_name); + (void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args_global_step, valid_types1, prim_name); return std::make_shared( std::vector{var_type, gradient_accumulator_type, gradient_squared_accumulator_type}); } diff --git a/mindspore/core/ops/apply_momentum.cc b/mindspore/core/ops/apply_momentum.cc index bb8db04ef14..e53567e7098 100644 --- a/mindspore/core/ops/apply_momentum.cc +++ b/mindspore/core/ops/apply_momentum.cc @@ -80,9 +80,9 @@ AbstractBasePtr ApplyMomentumInfer(const abstract::AnalysisEnginePtr &, const Pr (void)CheckAndConvertUtils::CheckTensorTypeValid("v_type", v_tensor_type, valid_types, prim_name); (void)CheckAndConvertUtils::CheckTensorTypeValid("a_type", a_tensor_type, valid_types, prim_name); std::map args; - args.insert(std::make_pair("l_type", l_type)); - args.insert(std::make_pair("g_type", g_type)); - args.insert(std::make_pair("m_type", m_type)); + (void)args.insert(std::make_pair("l_type", l_type)); + (void)args.insert(std::make_pair("g_type", g_type)); + (void)args.insert(std::make_pair("m_type", m_type)); CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args, valid_types, prim_name); auto g_type_tensor = g_type->cast(); auto element = g_type_tensor->element(); diff --git a/mindspore/core/ops/audio_spectrogram.cc b/mindspore/core/ops/audio_spectrogram.cc index 4a76dcbbd1e..d4b4145c3dc 100644 --- a/mindspore/core/ops/audio_spectrogram.cc +++ b/mindspore/core/ops/audio_spectrogram.cc @@ -78,7 +78,7 @@ int64_t Log2Ceil(int64_t length) { int64_t floor = 0; for (int64_t i = 4; i >= 0; --i) { const int64_t shift = static_cast(1UL << static_cast(i)); - int64_t tmp = SizeToLong(length >> shift); + int64_t tmp = SizeToLong(static_cast(length) >> static_cast(shift)); if (tmp != 0) { length = tmp; floor += shift; diff --git a/mindspore/core/ops/avg_pool.cc b/mindspore/core/ops/avg_pool.cc index ee1bfefd7e2..5d2873e5623 100644 --- a/mindspore/core/ops/avg_pool.cc +++ b/mindspore/core/ops/avg_pool.cc @@ -111,11 +111,11 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(ceil((in_h - (kernel_h - 1)) / stride_h)); - out_w = static_cast(ceil((in_w - (kernel_w - 1)) / stride_w)); + out_h = static_cast(std::ceil((in_h - (kernel_h - 1)) / static_cast(stride_h))); + out_w = static_cast(std::ceil((in_w - (kernel_w - 1)) / static_cast(stride_w))); } else if (pad_mode == SAME) { - out_h = static_cast(ceil(in_h / stride_h)); - out_w = static_cast(ceil(in_w / stride_w)); + out_h = static_cast(std::ceil(in_h / static_cast(stride_h))); + out_w = static_cast(std::ceil(in_w / static_cast(stride_w))); } std::vector out_shape = {batch, channel, out_h, out_w}; if (format == NHWC) { diff --git a/mindspore/core/ops/avg_pool_3d.cc b/mindspore/core/ops/avg_pool_3d.cc index 03e14eb82d5..1aa55e0defc 100644 --- a/mindspore/core/ops/avg_pool_3d.cc +++ b/mindspore/core/ops/avg_pool_3d.cc @@ -26,14 +26,13 @@ namespace mindspore { namespace ops { namespace { -constexpr size_t k5DInputDims = 5; +constexpr int64_t k5DInputDims = 5; constexpr size_t kKernelDims = 3; constexpr size_t kStridesDims = 3; constexpr size_t kPadDims = 6; void GetAttrs(const PrimitivePtr &primitive, std::vector *kernel_size, std::vector *strides, - int64_t *pad_mode, std::vector *pad_list, bool *ceil_mode, bool *count_include_pad, - int64_t *divisor_override) { + int64_t *pad_mode, std::vector *pad_list, bool *ceil_mode, bool *count_include_pad) { MS_EXCEPTION_IF_NULL(primitive); // attr kernel size *kernel_size = GetValue>(primitive->GetAttr(kKernelSize)); @@ -56,8 +55,6 @@ void GetAttrs(const PrimitivePtr &primitive, std::vector *kernel_size, CheckAndConvertUtils::GetPadModEnumValue(primitive->GetAttr(kPadMode), pad_mode, true); // attr ceil mode *ceil_mode = GetValue(primitive->GetAttr(kCeilMode)); - // attr divisor override - *divisor_override = GetValue(primitive->GetAttr(kDivisorOverride)); } std::vector GetOutputShape(const std::vector &in_shape, int64_t kernel_d, int64_t kernel_h, @@ -70,9 +67,12 @@ std::vector GetOutputShape(const std::vector &in_shape, int64_ int64_t out_h = 0; int64_t out_w = 0; if (ceil_mode) { - out_d = std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d + stride_d - 1) / stride_d + 1); - out_h = std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h + stride_h - 1) / stride_h + 1); - out_w = std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w + stride_w - 1) / stride_w + 1); + out_d = + static_cast(std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d + stride_d - 1) / stride_d + 1)); + out_h = + static_cast(std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h + stride_h - 1) / stride_h + 1)); + out_w = + static_cast(std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w + stride_w - 1) / stride_w + 1)); if ((out_d - 1) * stride_d >= in_d + pad_list[0]) { out_d--; } @@ -83,9 +83,9 @@ std::vector GetOutputShape(const std::vector &in_shape, int64_ out_w--; } } else { - out_d = std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d) / stride_d + 1); - out_h = std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h) / stride_h + 1); - out_w = std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w) / stride_w + 1); + out_d = static_cast(std::floor((in_d + pad_list[0] + pad_list[1] - kernel_d) / stride_d + 1)); + out_h = static_cast(std::floor((in_h + pad_list[2] + pad_list[3] - kernel_h) / stride_h + 1)); + out_w = static_cast(std::floor((in_w + pad_list[4] + pad_list[5] - kernel_w) / stride_w + 1)); } std::vector output_shape = {in_shape[0], in_shape[1], out_d, out_h, out_w}; return output_shape; @@ -130,8 +130,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector valid_types = {kFloat32, kFloat16}; std::map types; - types.emplace("input_x", input_args[0]->BuildType()); - types.emplace("input_y", input_args[1]->BuildType()); + (void)types.emplace("input_x", input_args[0]->BuildType()); + (void)types.emplace("input_y", input_args[1]->BuildType()); return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, primitive->name()); } } // namespace diff --git a/mindspore/core/ops/conv2d.cc b/mindspore/core/ops/conv2d.cc index 74a42e61882..422a8e61180 100644 --- a/mindspore/core/ops/conv2d.cc +++ b/mindspore/core/ops/conv2d.cc @@ -77,13 +77,15 @@ void Conv2DPadFunction(std::vector *output_hw, std::vector *pa int64_t out_h = -1; int64_t out_w = -1; if (x_h != Shape::SHP_ANY) { - out_h = static_cast(std::ceil(((x_h * 1.0) - dilation[0] * (kernel[0] - 1)) / stride[0])); + out_h = + static_cast(std::ceil(((x_h * 1.0) - static_cast(dilation[0] * (kernel[0] - 1))) / stride[0])); if (is_min_shape && out_h < 1) { out_h = 1L; } } if (x_w != Shape::SHP_ANY) { - out_w = static_cast(std::ceil(((x_w * 1.0) - dilation[1] * (kernel[1] - 1)) / stride[1])); + out_w = + static_cast(std::ceil(((x_w * 1.0) - static_cast(dilation[1] * (kernel[1] - 1))) / stride[1])); if (is_min_shape && out_w < 1) { out_w = 1L; } @@ -120,9 +122,9 @@ void Conv2DPadFunction(std::vector *output_hw, std::vector *pa int64_t out_h = -1; int64_t out_w = -1; if (x_h != Shape::SHP_ANY) { - out_h = static_cast(std::floor( - 1 + ((x_h * 1.0) + pad_list->at(0) + pad_list->at(1) - kernel[0] - (kernel[0] - 1) * (dilation[0] - 1)) / - stride[0])); + out_h = static_cast(std::floor(1 + ((x_h * 1.0) + pad_list->at(0) + pad_list->at(1) - kernel[0] - + static_cast((kernel[0] - 1) * (dilation[0] - 1))) / + stride[0])); if (is_min_shape && out_h < 1) { out_h = 1L; } @@ -130,7 +132,7 @@ void Conv2DPadFunction(std::vector *output_hw, std::vector *pa if (x_w != Shape::SHP_ANY) { out_w = static_cast(std::floor(1 + ((x_w * 1.0) + pad_list->at(kInputIndex2) + pad_list->at(kInputIndex3) - - kernel[1] - (kernel[1] - 1) * (dilation[1] - 1)) / + kernel[1] - static_cast((kernel[1] - 1) * (dilation[1] - 1))) / stride[1])); if (is_min_shape && out_w < 1) { out_w = 1L; diff --git a/mindspore/core/ops/ctc_loss_v2.cc b/mindspore/core/ops/ctc_loss_v2.cc index a8e7b4371a2..89985a66403 100644 --- a/mindspore/core/ops/ctc_loss_v2.cc +++ b/mindspore/core/ops/ctc_loss_v2.cc @@ -30,7 +30,7 @@ namespace { constexpr size_t kLenLogProbs = 3; constexpr size_t kLenTarget = 2; constexpr int64_t kMulti = 2; -constexpr size_t kInputSize = 4; +constexpr int64_t kInputSize = 4; abstract::TupleShapePtr CTCLossV2InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); diff --git a/mindspore/core/ops/ctc_loss_v2_grad.cc b/mindspore/core/ops/ctc_loss_v2_grad.cc index 5289fe028c3..0d867a419bc 100644 --- a/mindspore/core/ops/ctc_loss_v2_grad.cc +++ b/mindspore/core/ops/ctc_loss_v2_grad.cc @@ -27,7 +27,7 @@ namespace mindspore { namespace ops { namespace { constexpr size_t kLenLogProbs = 3; -constexpr size_t kInputSize = 7; +constexpr int64_t kInputSize = 7; constexpr size_t kIdx2 = 2; abstract::ShapePtr CTCLossV2GradInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { diff --git a/mindspore/core/ops/diag_part.cc b/mindspore/core/ops/diag_part.cc index 741b6269031..60d1faefcea 100644 --- a/mindspore/core/ops/diag_part.cc +++ b/mindspore/core/ops/diag_part.cc @@ -39,7 +39,7 @@ abstract::ShapePtr DiagPartInferShape(const PrimitivePtr &primitive, const std:: for (size_t i = 0; i < length; i++) { CheckAndConvertUtils::Check("input_shape[i + rank(input_shape) / 2]", input_shape[i + length], kEqual, "input_shape[i]", input_shape[i], op_name, ValueError); - out_shape.emplace_back(input_shape[i]); + (void)out_shape.emplace_back(input_shape[i]); } return std::make_shared(out_shape); } diff --git a/mindspore/core/ops/dynamic_broadcast_gradient_args.cc b/mindspore/core/ops/dynamic_broadcast_gradient_args.cc index 4b22a5b49c0..beb14436825 100644 --- a/mindspore/core/ops/dynamic_broadcast_gradient_args.cc +++ b/mindspore/core/ops/dynamic_broadcast_gradient_args.cc @@ -40,13 +40,13 @@ int64_t CheckInputsAndGetShape(const AbstractBasePtr &input_arg, const string &p if (max_shape.empty()) { MS_LOG(EXCEPTION) << prim_name << " input shape is dynamic, but max shape is empty."; } - return static_cast(max_shape[0]); + return max_shape[0]; } - return static_cast(input_shape[0]); + return input_shape[0]; } else if (input_arg->isa()) { auto x_shape = dyn_cast(input_arg); auto x_shape_data = x_shape->elements(); - return x_shape_data.size(); + return SizeToLong(x_shape_data.size()); } else { MS_EXCEPTION(TypeError) << prim_name << " input must be a tuple or Tensor."; } diff --git a/mindspore/core/ops/erfinv.cc b/mindspore/core/ops/erfinv.cc index ca36a043fd4..8668baa063b 100644 --- a/mindspore/core/ops/erfinv.cc +++ b/mindspore/core/ops/erfinv.cc @@ -27,7 +27,9 @@ namespace { abstract::ShapePtr ErfinvInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input_x numbers", input_args.size(), kEqual, 1, prim_name); + const int64_t input_num = 1; + (void)CheckAndConvertUtils::CheckInteger("input_x numbers", SizeToLong(input_args.size()), kEqual, input_num, + prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -39,13 +41,14 @@ abstract::ShapePtr ErfinvInferShape(const PrimitivePtr &primitive, const std::ve TypePtr ErfinvInferType(const PrimitivePtr &prim, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto op_name = prim->name(); - CheckAndConvertUtils::CheckInteger("input_x number", input_args.size(), kEqual, 1, op_name); + const int64_t input_num = 1; + (void)CheckAndConvertUtils::CheckInteger("input_x number", SizeToLong(input_args.size()), kEqual, input_num, op_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } const std::set valid_types = {kFloat16, kFloat32}; auto infer_type = input_args[0]->BuildType(); - CheckAndConvertUtils::CheckTensorTypeValid("input_x", infer_type, valid_types, prim->name()); + (void)CheckAndConvertUtils::CheckTensorTypeValid("input_x", infer_type, valid_types, prim->name()); return infer_type; } } // namespace diff --git a/mindspore/core/ops/expand_dims.cc b/mindspore/core/ops/expand_dims.cc index 575c9e5f45c..f05a982ee63 100644 --- a/mindspore/core/ops/expand_dims.cc +++ b/mindspore/core/ops/expand_dims.cc @@ -40,7 +40,7 @@ AbstractBasePtr ExpandDimsInfer(const abstract::AnalysisEnginePtr &, const Primi auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; auto dim_val = GetValue(input_args[1]->BuildValue()); auto rank = x_shape.size(); - CheckAndConvertUtils::CheckInRange("axis", dim_val, kIncludeBoth, {-rank - 1, rank}, prim_name); + (void)CheckAndConvertUtils::CheckInRange("axis", dim_val, kIncludeBoth, {-rank - 1, rank}, prim_name); if (dim_val < 0) { dim_val += SizeToLong(x_shape.size()) + 1; } diff --git a/mindspore/core/ops/flatten.cc b/mindspore/core/ops/flatten.cc index 8bc7b5ee9aa..640be01967c 100644 --- a/mindspore/core/ops/flatten.cc +++ b/mindspore/core/ops/flatten.cc @@ -27,12 +27,12 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorBuildShape())[kShape]; - size_t prod = 1; + int64_t prod = 1; size_t size = x_shape.size(); for (size_t i = 1; i < size; i++) { prod = prod * x_shape[i]; } - std::vector out_shape = {x_shape[0], SizeToLong(prod)}; + std::vector out_shape = {x_shape[0], prod}; return std::make_shared(out_shape); } diff --git a/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc b/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc index 5d3d4ef9d13..f7ddcd87979 100644 --- a/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc +++ b/mindspore/core/ops/fusion/conv2d_transpose_fusion.cc @@ -40,7 +40,7 @@ void Conv2dTransposeFusion::Init(int64_t in_channel, int64_t out_channel, const } void Conv2dTransposeFusion::set_kernel_size(const std::vector &kernel_size) { - const size_t kernel_len = 2; + const int64_t kernel_len = 2; (void)CheckAndConvertUtils::CheckInteger(kKernelSize, SizeToLong(kernel_size.size()), kEqual, kernel_len, name()); for (int64_t item : kernel_size) { (void)CheckAndConvertUtils::CheckInteger(kKernelSize, item, kGreaterEqual, 1, name()); @@ -49,7 +49,7 @@ void Conv2dTransposeFusion::set_kernel_size(const std::vector &kernel_s } void Conv2dTransposeFusion::set_dilation(const std::vector &dilation) { - const size_t dilation_size = 2; + const int64_t dilation_size = 2; (void)CheckAndConvertUtils::CheckInteger(kDilation, SizeToLong(dilation.size()), kEqual, dilation_size, name()); for (int64_t item : dilation) { (void)CheckAndConvertUtils::CheckInteger(kDilation, item, kGreaterEqual, 1, name()); diff --git a/mindspore/core/ops/grad/avg_pool_3d_grad.cc b/mindspore/core/ops/grad/avg_pool_3d_grad.cc index b7299b05d96..582c0c3a33b 100644 --- a/mindspore/core/ops/grad/avg_pool_3d_grad.cc +++ b/mindspore/core/ops/grad/avg_pool_3d_grad.cc @@ -25,7 +25,7 @@ namespace mindspore { namespace ops { namespace { -constexpr size_t k5DInputDims = 5; +constexpr int64_t k5DInputDims = 5; abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); diff --git a/mindspore/core/ops/grad/cdist_grad.cc b/mindspore/core/ops/grad/cdist_grad.cc index 92588c7d5ea..d884ce212e6 100644 --- a/mindspore/core/ops/grad/cdist_grad.cc +++ b/mindspore/core/ops/grad/cdist_grad.cc @@ -50,10 +50,10 @@ TypePtr InferType(const PrimitivePtr &primitive, const std::vector valid_types = {kFloat32, kFloat16}; std::map types; - types.emplace("grad", input_args[0]->BuildType()); - types.emplace("input_x", input_args[1]->BuildType()); - types.emplace("input_y", input_args[2]->BuildType()); - types.emplace("cdist", input_args[3]->BuildType()); + (void)types.emplace("grad", input_args[0]->BuildType()); + (void)types.emplace("input_x", input_args[1]->BuildType()); + (void)types.emplace("input_y", input_args[2]->BuildType()); + (void)types.emplace("cdist", input_args[3]->BuildType()); return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, primitive->name()); } } // namespace diff --git a/mindspore/core/ops/grad/conv2d_backprop_filter.cc b/mindspore/core/ops/grad/conv2d_backprop_filter.cc index 7baedbafac1..234ec61af55 100644 --- a/mindspore/core/ops/grad/conv2d_backprop_filter.cc +++ b/mindspore/core/ops/grad/conv2d_backprop_filter.cc @@ -24,9 +24,9 @@ namespace mindspore { namespace ops { namespace { -constexpr size_t kDoutIndex = 0; -constexpr size_t kInputIndex = 1; -constexpr size_t kFilterSizeIdex = 2; +constexpr int64_t kDoutIndex = 0; +constexpr int64_t kInputIndex = 1; +constexpr int64_t kFilterSizeIdex = 2; constexpr size_t kStride2dSize = 2; constexpr size_t kStride4dSize = 4; @@ -56,7 +56,6 @@ abstract::ShapePtr Conv2DBackpropFilterInferShape(const PrimitivePtr &primitive, std::vector out_shape; abstract::ShapePtr ret_shape; TransStrideTo4D(primitive, input_args); - auto filter_size = input_args[kFilterSizeIdex]; auto filter_size_v = filter_size->BuildValue(); MS_EXCEPTION_IF_NULL(filter_size_v); diff --git a/mindspore/core/ops/grad/conv2d_backprop_input.cc b/mindspore/core/ops/grad/conv2d_backprop_input.cc index a2fb8dbea2d..5885441a48c 100644 --- a/mindspore/core/ops/grad/conv2d_backprop_input.cc +++ b/mindspore/core/ops/grad/conv2d_backprop_input.cc @@ -27,7 +27,7 @@ namespace ops { namespace { constexpr size_t kDoutIndex = 0; constexpr size_t kInputIndex = 1; -constexpr size_t kSizeIndex = 2; +constexpr int64_t kSizeIndex = 2; void SetPadList(const PrimitivePtr &primitive, const std::vector &dout_shape_norm, const std::vector &x_size_v) { diff --git a/mindspore/core/ops/grad/lstm_grad.cc b/mindspore/core/ops/grad/lstm_grad.cc index f85f684612c..ae10495a376 100644 --- a/mindspore/core/ops/grad/lstm_grad.cc +++ b/mindspore/core/ops/grad/lstm_grad.cc @@ -24,50 +24,55 @@ namespace { AbstractBasePtr LstmGradInfer(const PrimitivePtr &primitive, const std::vector &input_args) { // infer shape MS_EXCEPTION_IF_NULL(primitive); + for (const auto &item : input_args) { + MS_EXCEPTION_IF_NULL(item); + } return nullptr; } } // namespace void LSTMGrad::set_input_size(const int64_t input_size) { - CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name()); - AddAttr(kInput_size, MakeValue(input_size)); + (void)CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name()); + (void)AddAttr(kInput_size, MakeValue(input_size)); } int64_t LSTMGrad::get_input_size() const { return GetValue(GetAttr(kInput_size)); } void LSTMGrad::set_hidden_size(const int64_t hidden_size) { - CheckAndConvertUtils::CheckInteger(kHidden_size, hidden_size, kGreaterThan, 0, this->name()); - AddAttr(kHidden_size, MakeValue(hidden_size)); + (void)CheckAndConvertUtils::CheckInteger(kHidden_size, hidden_size, kGreaterThan, 0, this->name()); + (void)AddAttr(kHidden_size, MakeValue(hidden_size)); } int64_t LSTMGrad::get_hidden_size() const { return GetValue(GetAttr(kHidden_size)); } void LSTMGrad::set_num_layers(const int64_t num_layers) { - CheckAndConvertUtils::CheckInteger(kNumLayers, num_layers, kGreaterThan, 0, this->name()); - AddAttr(kNumLayers, MakeValue(num_layers)); + (void)CheckAndConvertUtils::CheckInteger(kNumLayers, num_layers, kGreaterThan, 0, this->name()); + (void)AddAttr(kNumLayers, MakeValue(num_layers)); } int64_t LSTMGrad::get_num_layers() const { return GetValue(GetAttr(kNumLayers)); } -void LSTMGrad::set_has_bias(const bool has_bias) { AddAttr(kHasBias, MakeValue(has_bias)); } +void LSTMGrad::set_has_bias(const bool has_bias) { (void)AddAttr(kHasBias, MakeValue(has_bias)); } bool LSTMGrad::get_has_bias() const { auto value_ptr = this->GetAttr(kHasBias); return GetValue(value_ptr); } void LSTMGrad::set_dropout(const float dropout) { - CheckAndConvertUtils::CheckInRange(kDropout, dropout, kIncludeBoth, {0.0, 1.0}, this->name()); - AddAttr(kDropout, MakeValue(dropout)); + (void)CheckAndConvertUtils::CheckInRange(kDropout, dropout, kIncludeBoth, {0.0, 1.0}, this->name()); + (void)AddAttr(kDropout, MakeValue(dropout)); } float LSTMGrad::get_dropout() const { auto value_ptr = this->GetAttr(kDropout); return GetValue(value_ptr); } -void LSTMGrad::set_bidirectional(const bool bidirectional) { AddAttr(kBidirectional, MakeValue(bidirectional)); } +void LSTMGrad::set_bidirectional(const bool bidirectional) { (void)AddAttr(kBidirectional, MakeValue(bidirectional)); } bool LSTMGrad::get_bidirectional() const { auto value_ptr = this->GetAttr(kBidirectional); return GetValue(value_ptr); } -void LSTMGrad::set_num_directions(const int64_t num_directions) { AddAttr(kNumDirections, MakeValue(num_directions)); } +void LSTMGrad::set_num_directions(const int64_t num_directions) { + (void)AddAttr(kNumDirections, MakeValue(num_directions)); +} int64_t LSTMGrad::get_num_directions() const { return GetValue(GetAttr(kNumDirections)); } -void LSTMGrad::set_zoneout_cell(float zoneout_cell) { AddAttr(kZoneoutCell, MakeValue(zoneout_cell)); } +void LSTMGrad::set_zoneout_cell(float zoneout_cell) { (void)AddAttr(kZoneoutCell, MakeValue(zoneout_cell)); } float LSTMGrad::get_zoneout_cell() const { return GetValue(this->GetAttr(kZoneoutCell)); } -void LSTMGrad::set_zoneout_hidden(float zoneout_hidden) { AddAttr(kZoneoutHidden, MakeValue(zoneout_hidden)); } +void LSTMGrad::set_zoneout_hidden(float zoneout_hidden) { (void)AddAttr(kZoneoutHidden, MakeValue(zoneout_hidden)); } float LSTMGrad::get_zoneout_hidden() const { return GetValue(this->GetAttr(kZoneoutHidden)); } diff --git a/mindspore/core/ops/grad/soft_margin_loss_grad.cc b/mindspore/core/ops/grad/soft_margin_loss_grad.cc index 6e3a16bf9f7..219a5648635 100644 --- a/mindspore/core/ops/grad/soft_margin_loss_grad.cc +++ b/mindspore/core/ops/grad/soft_margin_loss_grad.cc @@ -23,7 +23,7 @@ namespace mindspore { namespace ops { namespace { -constexpr size_t kInputSize = 3; +constexpr int64_t kInputSize = 3; abstract::ShapePtr SoftMarginLossGradInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); diff --git a/mindspore/core/ops/index_add.cc b/mindspore/core/ops/index_add.cc index fe50668b538..f27034475c1 100644 --- a/mindspore/core/ops/index_add.cc +++ b/mindspore/core/ops/index_add.cc @@ -26,7 +26,8 @@ abstract::ShapePtr IndexAddInferShape(const PrimitivePtr &primitive, const std:: MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); const int64_t input_num = 3; - (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, input_num, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num, + prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -39,16 +40,16 @@ abstract::ShapePtr IndexAddInferShape(const PrimitivePtr &primitive, const std:: CheckAndConvertUtils::CheckInRange("axis", axis, kIncludeNeither, {-x_rank - 1, x_rank}, prim_name); auto idx_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; auto idx_rank = SizeToLong(idx_shape.size()); - CheckAndConvertUtils::CheckInteger("idx size", idx_rank, kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("idx size", idx_rank, kEqual, 1, prim_name); auto axis_rank = axis; if (axis < 0) { axis_rank = axis + x_rank; } - CheckAndConvertUtils::Check("size of indices", idx_shape[0], kEqual, "dimension of y[axis]", y_shape[axis_rank], - prim_name); + (void)CheckAndConvertUtils::Check("size of indices", idx_shape[0], kEqual, "dimension of y[axis]", y_shape[axis_rank], + prim_name); for (int dim = 0; dim < x_rank; dim = dim + 1) { if (dim != axis_rank) { - CheckAndConvertUtils::Check("x dim", x_shape[dim], kEqual, "y dim", y_shape[dim], prim_name); + (void)CheckAndConvertUtils::Check("x dim", x_shape[dim], kEqual, "y dim", y_shape[dim], prim_name); } } return std::make_shared(x_shape); @@ -66,8 +67,8 @@ TypePtr IndexAddInferType(const PrimitivePtr &prim, const std::vectorBuildType(); auto indices_type = input_args[kInputIndex1]->BuildType(); auto updates_type = input_args[kInputIndex2]->BuildType(); - CheckAndConvertUtils::CheckTensorTypeValid("indices type", indices_type, indices_types, prim->name()); - CheckAndConvertUtils::CheckTensorTypeValid("input_y type", updates_type, valid_types, prim->name()); + (void)CheckAndConvertUtils::CheckTensorTypeValid("indices type", indices_type, indices_types, prim->name()); + (void)CheckAndConvertUtils::CheckTensorTypeValid("input_y type", updates_type, valid_types, prim->name()); return CheckAndConvertUtils::CheckTensorTypeValid("input_x type", var_type, valid_types, prim->name()); } } // namespace diff --git a/mindspore/core/ops/lerp.cc b/mindspore/core/ops/lerp.cc index de11a0ecb96..a453c79f0a8 100644 --- a/mindspore/core/ops/lerp.cc +++ b/mindspore/core/ops/lerp.cc @@ -41,8 +41,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorisa()) { - CalBroadCastShape(start_shape, weight_shape, op_name, "start", "weight"); - CalBroadCastShape(end_shape, weight_shape, op_name, "end", "weight"); + (void)CalBroadCastShape(start_shape, weight_shape, op_name, "start", "weight"); + (void)CalBroadCastShape(end_shape, weight_shape, op_name, "end", "weight"); broadcast_shape = CalBroadCastShape(broadcast_shape, weight_shape, op_name); } return std::make_shared(broadcast_shape); @@ -56,8 +56,8 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & const int64_t input_num = 3; (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, op_name); std::map types; - types.emplace("start", input_args[0]->BuildType()); - types.emplace("end", input_args[1]->BuildType()); + (void)types.emplace("start", input_args[0]->BuildType()); + (void)types.emplace("end", input_args[1]->BuildType()); if (input_args[kInputIndex2]->isa()) { (void)types.emplace("weight", input_args[kInputIndex2]->BuildType()); } else { diff --git a/mindspore/core/ops/masked_fill.cc b/mindspore/core/ops/masked_fill.cc index ed585b3c7b5..3564da72cc1 100644 --- a/mindspore/core/ops/masked_fill.cc +++ b/mindspore/core/ops/masked_fill.cc @@ -55,7 +55,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & auto op_name = prim->name(); const int64_t input_num = 3; (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num, op_name); - CheckAndConvertUtils::CheckTensorTypeValid("mask", input_args[1]->BuildType(), {kBool}, op_name); + (void)CheckAndConvertUtils::CheckTensorTypeValid("mask", input_args[1]->BuildType(), {kBool}, op_name); if (input_args[kInputIndex2]->isa()) { std::map types; (void)types.emplace("input", input_args[kInputIndex0]->BuildType()); diff --git a/mindspore/core/ops/merge.cc b/mindspore/core/ops/merge.cc index 04d6745c2ea..359d4408ff6 100644 --- a/mindspore/core/ops/merge.cc +++ b/mindspore/core/ops/merge.cc @@ -33,7 +33,7 @@ AbstractBasePtr MergeInfer(const abstract::AnalysisEnginePtr &, const PrimitiveP auto inputs_shape = input_args[0]->BuildShape()->cast()->shape(); std::map args; for (size_t i = 0; i != inputs_type.size(); i++) { - args.insert(std::make_pair("input[" + std::to_string(i) + "]", inputs_type[i])); + (void)args.insert(std::make_pair("input[" + std::to_string(i) + "]", inputs_type[i])); } std::set template_type = common_valid_types; (void)template_type.emplace(kBool); diff --git a/mindspore/core/ops/neighborexchange.cc b/mindspore/core/ops/neighborexchange.cc index 10a63669582..10ea858e032 100644 --- a/mindspore/core/ops/neighborexchange.cc +++ b/mindspore/core/ops/neighborexchange.cc @@ -100,11 +100,15 @@ void Check(const PrimitivePtr &primitive, const std::vector &in // check empty input auto send_rank_ids = GetValue>(primitive->GetAttr(kSendRankIds)); if (send_rank_ids.empty()) { - (void)CheckAndConvertUtils::CheckInteger("input_numbers", input_args.size(), kEqual, 0, prim_name); + const int64_t input_num = 0; + (void)CheckAndConvertUtils::CheckInteger("input_numbers", SizeToLong(input_args.size()), kEqual, input_num, + prim_name); return; } // check input shape & attr send shape - (void)CheckAndConvertUtils::CheckInteger("input_numbers", input_args.size(), kEqual, 1, prim_name); + const int64_t input_num_ = 1; + (void)CheckAndConvertUtils::CheckInteger("input_numbers", SizeToLong(input_args.size()), kEqual, input_num_, + prim_name); (void)CheckAndConvertUtils::CheckArgs(prim_name, input_args, 0); auto abstract_tuple = input_args[0]->cast(); MS_EXCEPTION_IF_NULL(abstract_tuple); diff --git a/mindspore/core/ops/ones.cc b/mindspore/core/ops/ones.cc index 3ce1a1730ba..4193115b04f 100644 --- a/mindspore/core/ops/ones.cc +++ b/mindspore/core/ops/ones.cc @@ -31,7 +31,7 @@ abstract::ShapePtr OnesInferShape(const PrimitivePtr &primitive, const std::vect // check auto shape_value = input_args[0]->BuildValue(); std::vector out_shape = CheckAndConvertUtils::CheckAttrIntOrTupleInt("shape", shape_value, prim_name); - CheckAndConvertUtils::CheckPositiveVector("shape", out_shape, prim_name); + (void)CheckAndConvertUtils::CheckPositiveVector("shape", out_shape, prim_name); return std::make_shared(out_shape); } diff --git a/mindspore/core/ops/op_utils.cc b/mindspore/core/ops/op_utils.cc index b793442225d..bdec2bad001 100644 --- a/mindspore/core/ops/op_utils.cc +++ b/mindspore/core/ops/op_utils.cc @@ -41,12 +41,12 @@ std::vector CalBroadCastShape(std::vector x_shape, std::vector (void)std::copy(x_shape.begin(), x_shape.end() - length, std::back_inserter(broadcast_shape)); } for (int64_t i = -length; i < 0; i++) { - if (x_shape[x_length + i] == 1) { - broadcast_shape.push_back(y_shape[y_length + i]); - } else if (y_shape[y_length + i] == 1) { - broadcast_shape.push_back(x_shape[x_length + i]); - } else if (x_shape[x_length + i] == y_shape[y_length + i]) { - broadcast_shape.push_back(x_shape[x_length + i]); + if (x_shape[LongToSize(x_length + i)] == 1) { + (void)broadcast_shape.push_back(y_shape[LongToSize(y_length + i)]); + } else if (y_shape[LongToSize(y_length + i)] == 1) { + (void)broadcast_shape.push_back(x_shape[LongToSize(x_length + i)]); + } else if (x_shape[x_length + i] == y_shape[LongToSize(y_length + i)]) { + (void)broadcast_shape.push_back(x_shape[LongToSize(x_length + i)]); } else { MS_EXCEPTION(ValueError) << "For op " << op_name << ", the two input '" << op_x_name << "' and '" << op_y_name << "' can not broadcast"; diff --git a/mindspore/core/ops/reduce_sum.cc b/mindspore/core/ops/reduce_sum.cc index 7bf3912b729..af89ec5188e 100644 --- a/mindspore/core/ops/reduce_sum.cc +++ b/mindspore/core/ops/reduce_sum.cc @@ -49,7 +49,7 @@ void InferImplReduceFuncCalShape(ShapeVector *shape, const ShapeVector &x_shape, if (keep_dims_value) { for (it = axis_items.begin(); it != axis_items.end(); ++it) { auto axis_value = GetValue(*it); - shape->at(axis_value) = 1; + shape->at(LongToSize(axis_value)) = 1; } } else { std::vector axis_value_list; @@ -70,7 +70,7 @@ void InferImplReduceFuncCalShape(ShapeVector *shape, const ShapeVector &x_shape, int64_t axis_value = GetValue(axis); axis_value = InferImplReduceFuncCheckAxis(axis_value, x_shape.size()); if (keep_dims_value) { - shape->at(axis_value) = 1; + shape->at(LongToSize(axis_value)) = 1; } else { (void)shape->erase(shape->begin() + axis_value); } @@ -185,7 +185,9 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr ReduceSumInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { - CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kGreaterEqual, 1, primitive->name()); + const int64_t input_num = 1; + (void)CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kGreaterEqual, input_num, + primitive->name()); return abstract::MakeAbstract(InferShape(primitive, input_args), InferType(primitive, input_args)); } } // namespace ops diff --git a/mindspore/core/ops/roll.cc b/mindspore/core/ops/roll.cc index 41fbd33b276..5d76b815898 100644 --- a/mindspore/core/ops/roll.cc +++ b/mindspore/core/ops/roll.cc @@ -28,7 +28,9 @@ namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 1, prim_name); + const int64_t input_num = 1; + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num, + prim_name); auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; auto axis = GetValue(primitive->GetAttr(kAxis)); auto x_rank = SizeToLong(x_shape.size()); diff --git a/mindspore/core/ops/smooth_l1_loss.cc b/mindspore/core/ops/smooth_l1_loss.cc index 5c39bd142e3..0a843686521 100644 --- a/mindspore/core/ops/smooth_l1_loss.cc +++ b/mindspore/core/ops/smooth_l1_loss.cc @@ -30,7 +30,7 @@ void SmoothL1Loss::set_beta(const float beta) { (void)this->AddAttr(kBeta, MakeV float SmoothL1Loss::get_beta() const { auto value_ptr = this->GetAttr(kBeta); - return GetValue(value_ptr); + return GetValue(value_ptr); } AbstractBasePtr SmoothL1LossInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, diff --git a/mindspore/core/ops/soft_margin_loss.cc b/mindspore/core/ops/soft_margin_loss.cc index 9f7c6019863..6918a2a34a1 100644 --- a/mindspore/core/ops/soft_margin_loss.cc +++ b/mindspore/core/ops/soft_margin_loss.cc @@ -23,7 +23,7 @@ namespace mindspore { namespace ops { namespace { -constexpr size_t kInputSize = 2; +constexpr int64_t kInputSize = 2; abstract::ShapePtr SoftMarginLossInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); diff --git a/mindspore/core/ops/soft_shrink.cc b/mindspore/core/ops/soft_shrink.cc index 5e69eb0f3a7..fc25b409d00 100644 --- a/mindspore/core/ops/soft_shrink.cc +++ b/mindspore/core/ops/soft_shrink.cc @@ -30,7 +30,9 @@ namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, primitive->name()); + const int64_t input_num = 1; + (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, + primitive->name()); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -39,7 +41,9 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); - (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, prim->name()); + const int64_t input_num = 1; + (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, + prim->name()); if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr &a) { return a == nullptr; })) { MS_LOG(EXCEPTION) << "nullptr"; } diff --git a/mindspore/core/ops/space_to_batch.cc b/mindspore/core/ops/space_to_batch.cc index e968182e177..f9326c0f7ad 100644 --- a/mindspore/core/ops/space_to_batch.cc +++ b/mindspore/core/ops/space_to_batch.cc @@ -38,9 +38,10 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(output_shape); diff --git a/mindspore/core/ops/sparse_apply_r_m_s_prop.cc b/mindspore/core/ops/sparse_apply_r_m_s_prop.cc index cfd593e332c..1ed2b7c0b57 100644 --- a/mindspore/core/ops/sparse_apply_r_m_s_prop.cc +++ b/mindspore/core/ops/sparse_apply_r_m_s_prop.cc @@ -43,19 +43,23 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec auto grad_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[4]->BuildShape())[kShape]; auto indices_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[5]->BuildShape())[kShape]; // Args lr must be scalar - (void)CheckAndConvertUtils::CheckInteger("size of lr_shape", lr_shape.size(), kEqual, 0, primitive->name()); + const int64_t input_num_ = 0; + (void)CheckAndConvertUtils::CheckInteger("size of lr_shape", lr_shape.size(), kEqual, input_num_, primitive->name()); // Shape of var、ms、mom、grad must be same std::map same_shape_args_map; - same_shape_args_map.insert({"shape of ms ", ms_shape}); - same_shape_args_map.insert({"shape of mom ", mom_shape}); - same_shape_args_map.insert({"shape of grad ", grad_shape}); + (void)same_shape_args_map.insert({"shape of ms ", ms_shape}); + (void)same_shape_args_map.insert({"shape of mom ", mom_shape}); + (void)same_shape_args_map.insert({"shape of grad ", grad_shape}); for (auto &elem : same_shape_args_map) { CheckAndConvertUtils::Check(elem.first, elem.second, kEqual, "var shape", var_shape, prim_name); } // Indices must be rank 1 - (void)CheckAndConvertUtils::CheckInteger("indices dim", indices_shape.size(), kEqual, 1, prim_name); + const int64_t input_num = 1; + (void)CheckAndConvertUtils::CheckInteger("indices dim", SizeToLong(indices_shape.size()), kEqual, input_num, + prim_name); // Dimension of var must be equal or greater than 1 - (void)CheckAndConvertUtils::CheckInteger("dimension of var", var_shape.size(), kGreaterEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("dimension of var", SizeToLong(var_shape.size()), kGreaterEqual, input_num, + prim_name); // Indices shape must be equal to the first dimension of var CheckAndConvertUtils::Check("indices shape", indices_shape[0], kEqual, "the first dimension of var", var_shape[0], prim_name); @@ -79,18 +83,18 @@ TuplePtr InferType(const PrimitivePtr &prim, const std::vector const std::set valid_types = {kFloat16, kFloat32}; // Args ms、mom、grad must have the same type as var std::map args; - args.insert({"var", var_type}); - args.insert({"ms", ms_type}); - args.insert({"mom", mom_type}); - args.insert({"grad", grad_type}); + (void)args.insert({"var", var_type}); + (void)args.insert({"ms", ms_type}); + (void)args.insert({"mom", mom_type}); + (void)args.insert({"grad", grad_type}); (void)CheckAndConvertUtils::CheckTensorTypeSame(args, valid_types, prim_name); // Args lr must be a scalar type std::map args2; - args2.insert({"lr", lr_type}); + (void)args2.insert({"lr", lr_type}); (void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args2, valid_types, prim_name); // Check indices type std::map args3; - args3.insert({"indices", indices_type}); + (void)args3.insert({"indices", indices_type}); const std::set valid_types1 = {kInt32, kInt64}; (void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args3, valid_types1, prim_name); return std::make_shared(std::vector{var_type, ms_type, mom_type}); diff --git a/mindspore/core/ops/split.cc b/mindspore/core/ops/split.cc index 2d13b879865..467927c5956 100644 --- a/mindspore/core/ops/split.cc +++ b/mindspore/core/ops/split.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace ops { -void Split::Init(const std::vector &size_splits, const int64_t axis, const int64_t output_num) { +void Split::Init(const int64_t axis, const int64_t output_num) { this->set_axis(axis); this->set_output_num(output_num); } diff --git a/mindspore/core/ops/split.h b/mindspore/core/ops/split.h index 7844eb195c9..a7baf5dba39 100644 --- a/mindspore/core/ops/split.h +++ b/mindspore/core/ops/split.h @@ -31,7 +31,7 @@ class MS_CORE_API Split : public PrimitiveC { Split() : PrimitiveC(kNameSplit) {} ~Split() = default; MS_DECLARE_PARENT(Split, PrimitiveC); - void Init(const std::vector &size_splits, const int64_t axis, const int64_t output_num); + void Init(const int64_t axis, const int64_t output_num); void set_size_splits(const std::vector &size_splits); void set_axis(const int64_t axis); void set_output_num(const int64_t output_num); diff --git a/mindspore/core/ops/split_v.cc b/mindspore/core/ops/split_v.cc index 7c57e3e66d5..bd62b4b2a79 100644 --- a/mindspore/core/ops/split_v.cc +++ b/mindspore/core/ops/split_v.cc @@ -36,42 +36,42 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec if (split_dim < 0) { split_dim += x_rank; } - auto shape_of_split_dim = x_shape[split_dim]; + auto shape_of_split_dim = x_shape[LongToSize(split_dim)]; auto num_split = GetValue(primitive->GetAttr("num_split")); - CheckAndConvertUtils::CheckInteger("num_split", num_split, kGreaterEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("num_split", num_split, kGreaterEqual, 1, prim_name); auto size_splits = GetValue>(primitive->GetAttr(kSizeSplits)); CheckAndConvertUtils::Check("num_split", num_split, kEqual, "rank of size_splits", SizeToLong(size_splits.size()), prim_name); auto default_idx = std::find(size_splits.begin(), size_splits.end(), -1); if (default_idx == size_splits.end()) { - int sum_of_size_splits = 0; + int64_t sum_of_size_splits = 0; for (int64_t i = 0; i < num_split; i++) { - CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth, - {0, shape_of_split_dim}, prim_name); - sum_of_size_splits += size_splits[i]; + (void)CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth, + {0, shape_of_split_dim}, prim_name); + sum_of_size_splits += size_splits[LongToSize(i)]; } CheckAndConvertUtils::Check("sum of size_splits", sum_of_size_splits, kEqual, "dimension of value along split_dim", shape_of_split_dim, prim_name); } else { - size_splits.erase(default_idx); + (void)size_splits.erase(default_idx); auto excessive_default_idx = std::find(size_splits.begin(), size_splits.end(), -1); if (excessive_default_idx != size_splits.end()) { MS_EXCEPTION(ValueError) << "Got more than one default value -1 in size_splits."; } else { - int sum_of_size_splits = 0; + int64_t sum_of_size_splits = 0; for (int64_t i = 0; i < num_split - 1; i++) { - CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth, - {0, shape_of_split_dim}, prim_name); - sum_of_size_splits += size_splits[i]; + (void)CheckAndConvertUtils::CheckInRange("elements of size_splits", size_splits[i], kIncludeBoth, + {0, shape_of_split_dim}, prim_name); + sum_of_size_splits += size_splits[LongToSize(i)]; } auto default_value = shape_of_split_dim - sum_of_size_splits; - size_splits.insert(default_idx, default_value); + (void)size_splits.insert(default_idx, default_value); } } std::vector shape_tuple; for (int64_t i = 0; i < num_split; i++) { auto shape = x_shape; - shape[split_dim] = size_splits[i]; + shape[split_dim] = size_splits[LongToSize(i)]; abstract::ShapePtr out_shape = std::make_shared(shape); shape_tuple.push_back(out_shape); } diff --git a/mindspore/core/ops/square.cc b/mindspore/core/ops/square.cc index 5cfdf209769..84bbf1ed19b 100644 --- a/mindspore/core/ops/square.cc +++ b/mindspore/core/ops/square.cc @@ -27,14 +27,13 @@ void ImpleSquare(void *origin, void *target, size_t size) { MS_EXCEPTION_IF_NULL(target); auto origin_data = reinterpret_cast(origin); auto target_data = reinterpret_cast(target); - MS_EXCEPTION_IF_NULL(origin_data); - MS_EXCEPTION_IF_NULL(target_data); for (size_t i = 0; i < size; ++i) { target_data[i] = origin_data[i] * origin_data[i]; } } abstract::ShapePtr SquareInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape()); auto in_shape = shape_map[kShape]; auto min_shape = shape_map[kMinShape]; @@ -80,47 +79,47 @@ ValuePtr SquareInferValue(const PrimitivePtr &prim, const std::vectordata_c(); switch (dtype) { case kNumberTypeInt8: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeInt16: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeInt32: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeInt64: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt8: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt16: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt32: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeUInt64: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeFloat16: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeFloat32: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } case kNumberTypeFloat64: { - ImpleSquare(x_datac, result_datac, data_size); + ImpleSquare(x_datac, result_datac, IntToSize(data_size)); break; } default: { diff --git a/mindspore/core/ops/strided_slice.cc b/mindspore/core/ops/strided_slice.cc index c5aba07421b..f674d02f8d6 100644 --- a/mindspore/core/ops/strided_slice.cc +++ b/mindspore/core/ops/strided_slice.cc @@ -66,7 +66,6 @@ void EllipsisInferShape(const PrimitivePtr &primitive, const std::vector begin_pos = TenToTwo(GetValue(primitive->GetAttr(kBeginMask))); std::vector end_pos = TenToTwo(GetValue(primitive->GetAttr(kEndMask))); - std::vector ellipsis_pos = TenToTwo(GetValue(primitive->GetAttr(kEllipsisMask))); std::vector new_axis_pos = TenToTwo(GetValue(primitive->GetAttr(kNewAxisMask))); std::vector shrink_axis_pos = TenToTwo(GetValue(primitive->GetAttr(kShrinkAxisMask))); (void)CheckAndConvertUtils::CheckInteger("infer", SizeToLong(new_axis_pos.size()), kGreaterEqual, @@ -80,7 +79,7 @@ void EllipsisInferShape(const PrimitivePtr &primitive, const std::vectorinsert(infer_shape->end(), x_shape.begin() + i, + (void)infer_shape->insert(infer_shape->end(), x_shape.begin() + LongToSize(i), x_shape.begin() + SizeToLong(i + ellipsis_occupied_dims)); j += 1; i += ellipsis_occupied_dims; diff --git a/mindspore/core/ops/unsqueeze.cc b/mindspore/core/ops/unsqueeze.cc index a25954335a8..7fef97cbff4 100644 --- a/mindspore/core/ops/unsqueeze.cc +++ b/mindspore/core/ops/unsqueeze.cc @@ -55,7 +55,7 @@ AbstractBasePtr UnsqueezeInfer(const abstract::AnalysisEnginePtr &, const Primit if (ax_itr < dim_rank && dims[ax_itr] == (int64_t)i) { (void)out_shape.emplace_back(1); ax_itr++; - } else if (ax_itr < dim_rank && dims[ax_itr] + sz == i) { + } else if (ax_itr < dim_rank && dims[ax_itr] + sz == LongToSize(i)) { (void)out_shape.emplace_back(1); ax_itr++; } else {