From 17c11622b846a2fffdaebba3417d23bcca839711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8D=97?= Date: Tue, 27 Jul 2021 18:37:58 +0800 Subject: [PATCH] ops code review --- .../core/ops/LayerNormBetaGammaBackprop.cc | 4 +- mindspore/core/ops/LayerNormXBackprop.cc | 4 +- mindspore/core/ops/abs.cc | 14 +++--- mindspore/core/ops/abs.h | 2 +- mindspore/core/ops/adam.cc | 8 ++-- mindspore/core/ops/adder.cc | 6 +-- mindspore/core/ops/addn.cc | 2 +- mindspore/core/ops/affine.cc | 12 ++--- mindspore/core/ops/all.cc | 2 +- mindspore/core/ops/apply_momentum.cc | 12 +++-- mindspore/core/ops/arg_min.cc | 2 +- mindspore/core/ops/assert.cc | 7 +-- mindspore/core/ops/audio_spectrogram.cc | 21 ++++----- mindspore/core/ops/avg_pool.cc | 44 +++++++++--------- mindspore/core/ops/avg_pool_3d.cc | 6 +-- mindspore/core/ops/batch_matmul.cc | 10 ++--- mindspore/core/ops/batch_norm.cc | 12 ++--- mindspore/core/ops/batch_to_space.cc | 12 +++-- mindspore/core/ops/batch_to_space_nd.cc | 8 ++-- mindspore/core/ops/bias_add.cc | 8 ++-- mindspore/core/ops/binary_cross_entropy.cc | 4 +- mindspore/core/ops/broadcast.cc | 4 +- mindspore/core/ops/broadcast_to.cc | 6 +-- mindspore/core/ops/ceil.cc | 8 ++-- mindspore/core/ops/control_depend.cc | 2 +- mindspore/core/ops/conv2d.cc | 28 ++++++------ mindspore/core/ops/conv2d_transpose.cc | 35 ++++++++------- mindspore/core/ops/crop_and_resize.cc | 4 +- mindspore/core/ops/ctc_loss_v2.cc | 3 +- mindspore/core/ops/ctc_loss_v2_grad.cc | 3 +- mindspore/core/ops/ctcloss.cc | 12 ++--- mindspore/core/ops/cumsum.cc | 6 +-- mindspore/core/ops/custom.cc | 2 +- mindspore/core/ops/custom_normalize.cc | 25 +++++------ mindspore/core/ops/custom_predict.cc | 2 +- mindspore/core/ops/depth_to_space.cc | 12 ++--- mindspore/core/ops/detection_post_process.cc | 24 +++++----- mindspore/core/ops/diag.cc | 4 +- mindspore/core/ops/diag_part.cc | 2 +- mindspore/core/ops/dropout.cc | 6 +-- mindspore/core/ops/dropout_do_mask.cc | 2 +- mindspore/core/ops/dropout_gen_mask.cc | 2 +- mindspore/core/ops/dtype.cc | 2 +- mindspore/core/ops/eltwise.cc | 2 +- mindspore/core/ops/elu.cc | 2 +- mindspore/core/ops/embedding_lookup.cc | 4 +- mindspore/core/ops/exp.cc | 2 +- mindspore/core/ops/expand_dims.cc | 5 ++- .../core/ops/fake_quant_with_min_max_vars.cc | 6 ++- ...ake_quant_with_min_max_vars_per_channel.cc | 10 ++--- mindspore/core/ops/fft_imag.cc | 17 +++---- mindspore/core/ops/fill.cc | 1 + mindspore/core/ops/floor.cc | 14 +++--- mindspore/core/ops/fusion/activation.cc | 2 +- mindspore/core/ops/fusion/add_fusion.cc | 2 +- mindspore/core/ops/fusion/avg_pool_fusion.cc | 6 +-- mindspore/core/ops/fusion/max_pool_fusion.cc | 6 +-- mindspore/core/ops/fusion/pow_fusion.cc | 2 +- mindspore/core/ops/glu.cc | 2 +- mindspore/core/ops/grad/avg_pool_3d_grad.cc | 6 +-- mindspore/core/ops/grad/batch_norm_grad.cc | 4 +- .../ops/grad/binary_cross_entropy_grad.cc | 2 +- .../core/ops/grad/conv2d_backprop_filter.cc | 10 +++-- mindspore/core/ops/grad/dropout_grad.cc | 2 +- .../core/ops/grad/group_conv2d_grad_input.cc | 22 ++++----- mindspore/core/ops/grad/hsigmoid_grad.cc | 4 +- mindspore/core/ops/grad/pool_grad.cc | 8 ++-- mindspore/core/ops/grad/pooling_grad.cc | 12 ++--- mindspore/core/ops/grad/relu_grad.cc | 4 +- mindspore/core/ops/grad/relu_grad_v2.cc | 4 +- mindspore/core/ops/grad/soft_shrink_grad.cc | 2 +- mindspore/core/ops/hashtable_lookup.cc | 14 +++--- mindspore/core/ops/instance_norm.cc | 2 +- mindspore/core/ops/l2_normalize.cc | 6 +-- mindspore/core/ops/layer_norm.cc | 28 +++++++----- mindspore/core/ops/leaky_relu.cc | 2 +- mindspore/core/ops/log_softmax.cc | 6 +-- mindspore/core/ops/logical_or.cc | 8 ++-- mindspore/core/ops/lp_normalization.cc | 4 +- mindspore/core/ops/lrn.cc | 10 ++--- mindspore/core/ops/lsh_projection.cc | 10 +++-- mindspore/core/ops/lstm.cc | 34 +++++++------- mindspore/core/ops/mat_mul.cc | 8 ++-- mindspore/core/ops/max_pool.cc | 18 ++++---- mindspore/core/ops/mfcc.cc | 10 +++-- mindspore/core/ops/minimum.cc | 4 +- mindspore/core/ops/mul.cc | 4 +- mindspore/core/ops/neg.cc | 4 +- mindspore/core/ops/neighborexchange.cc | 5 ++- mindspore/core/ops/non_max_suppression.cc | 2 +- mindspore/core/ops/one_hot.cc | 10 ++--- mindspore/core/ops/ones_like.cc | 2 +- mindspore/core/ops/op_utils.cc | 6 +-- mindspore/core/ops/pack.cc | 2 +- mindspore/core/ops/pad.cc | 6 +-- mindspore/core/ops/prelu.cc | 17 +++---- mindspore/core/ops/prior_box.cc | 28 ++++++++---- mindspore/core/ops/proposal.cc | 20 +++++---- mindspore/core/ops/quant_dtype_cast.cc | 22 +++++---- mindspore/core/ops/random_standard_normal.cc | 4 +- mindspore/core/ops/reciprocal.cc | 4 +- mindspore/core/ops/reduce.cc | 2 +- mindspore/core/ops/reluv2.cc | 4 +- mindspore/core/ops/reshape.cc | 2 +- mindspore/core/ops/resize.cc | 20 ++++----- mindspore/core/ops/resize_bilinear.cc | 6 +-- mindspore/core/ops/resize_nearest_neighbor.cc | 4 +- mindspore/core/ops/reverse_sequence.cc | 15 ++++--- mindspore/core/ops/reverse_v2.cc | 2 +- mindspore/core/ops/roi_pooling.cc | 8 ++-- mindspore/core/ops/rsqrt.cc | 4 +- mindspore/core/ops/scalar_summary.cc | 4 +- mindspore/core/ops/sgd.cc | 6 +-- mindspore/core/ops/shape.cc | 4 +- mindspore/core/ops/skip_gram.cc | 6 +-- mindspore/core/ops/smooth_l1_loss.cc | 3 +- mindspore/core/ops/soft_shrink.cc | 4 +- .../ops/softmax_cross_entropy_with_logits.cc | 5 +-- mindspore/core/ops/space_to_batch.cc | 4 +- mindspore/core/ops/space_to_batch_nd.cc | 4 +- mindspore/core/ops/space_to_depth.cc | 4 +- ...parse_softmax_cross_entropy_with_logits.cc | 4 +- mindspore/core/ops/splice.cc | 12 ++--- mindspore/core/ops/split.cc | 6 +-- mindspore/core/ops/split_with_overlap.cc | 20 +++++---- mindspore/core/ops/squared_difference.cc | 9 ++-- mindspore/core/ops/squeeze.cc | 2 +- mindspore/core/ops/stack.cc | 2 +- mindspore/core/ops/strided_slice.cc | 45 ++++++++++++------- mindspore/core/ops/tensor_array.cc | 8 ++-- mindspore/core/ops/tensor_list_from_tensor.cc | 6 +-- mindspore/core/ops/tensor_list_get_item.cc | 2 +- mindspore/core/ops/tensor_list_reserve.cc | 8 ++-- mindspore/core/ops/tensor_list_set_item.cc | 2 +- mindspore/core/ops/tensor_list_stack.cc | 4 +- mindspore/core/ops/tensor_summary.cc | 4 +- mindspore/core/ops/tile.cc | 4 +- mindspore/core/ops/to_format.cc | 4 +- mindspore/core/ops/unpack.cc | 2 +- mindspore/core/ops/unsorted_segment_sum.cc | 2 +- mindspore/core/ops/unstack.cc | 2 +- mindspore/core/ops/where.cc | 2 +- mindspore/core/ops/zeros_like.cc | 4 +- mindspore/core/utils/check_convert_utils.cc | 33 ++++++++++++++ mindspore/core/utils/check_convert_utils.h | 4 ++ mindspore/nn/optim/ada_grad.py | 3 +- mindspore/nn/optim/adam.py | 4 +- mindspore/nn/optim/ftrl.py | 2 +- mindspore/nn/optim/lars.py | 2 +- mindspore/nn/optim/momentum.py | 2 +- mindspore/nn/optim/optimizer.py | 16 ++++--- 151 files changed, 644 insertions(+), 544 deletions(-) diff --git a/mindspore/core/ops/LayerNormBetaGammaBackprop.cc b/mindspore/core/ops/LayerNormBetaGammaBackprop.cc index d4ce568be16..ec5e7e64e2e 100644 --- a/mindspore/core/ops/LayerNormBetaGammaBackprop.cc +++ b/mindspore/core/ops/LayerNormBetaGammaBackprop.cc @@ -55,8 +55,8 @@ AbstractBasePtr LayerNormBetaGammaBackpropInfer(const abstract::AnalysisEnginePt const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); const int64_t input_num = 4; - CheckAndConvertUtils::CheckInteger("LayerNormBetaGammaBackprop infer", SizeToLong(input_args.size()), kGreaterEqual, - input_num, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("LayerNormBetaGammaBackprop infer", SizeToLong(input_args.size()), + kGreaterEqual, input_num, primitive->name()); return abstract::MakeAbstract(LayerNormBetaGammaBackpropInferShape(primitive, input_args), LayerNormBetaGammaBackpropInferType(primitive, input_args)); } diff --git a/mindspore/core/ops/LayerNormXBackprop.cc b/mindspore/core/ops/LayerNormXBackprop.cc index 953bde88aba..d5111809da1 100644 --- a/mindspore/core/ops/LayerNormXBackprop.cc +++ b/mindspore/core/ops/LayerNormXBackprop.cc @@ -48,8 +48,8 @@ AbstractBasePtr LayerNormXBackpropInfer(const abstract::AnalysisEnginePtr &, con const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); const int64_t input_num = 5; - CheckAndConvertUtils::CheckInteger("LayerNormXBackprop infer", SizeToLong(input_args.size()), kGreaterEqual, - input_num, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("LayerNormXBackprop infer", SizeToLong(input_args.size()), kGreaterEqual, + input_num, primitive->name()); return abstract::MakeAbstract(LayerNormXBackpropInferShape(primitive, input_args), LayerNormXBackpropInferType(primitive, input_args)); } diff --git a/mindspore/core/ops/abs.cc b/mindspore/core/ops/abs.cc index f30467168b9..4fb7e209846 100644 --- a/mindspore/core/ops/abs.cc +++ b/mindspore/core/ops/abs.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,18 +29,11 @@ namespace mindspore { namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; return std::make_shared(in_shape); } TypePtr InferType(const PrimitivePtr &prim, const std::vector &input_args) { - if (std::any_of(input_args.begin(), input_args.end(), [](AbstractBasePtr a) { return a == nullptr; })) { - MS_LOG(EXCEPTION) << "nullptr"; - } std::map types; types.emplace("input_x", input_args[0]->BuildType()); return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name()); @@ -49,8 +42,11 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr AbsInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameAbs, Abs); } // namespace ops diff --git a/mindspore/core/ops/abs.h b/mindspore/core/ops/abs.h index 1dae00eb525..1e8a1683d02 100644 --- a/mindspore/core/ops/abs.h +++ b/mindspore/core/ops/abs.h @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/mindspore/core/ops/adam.cc b/mindspore/core/ops/adam.cc index e696e7c676f..cd7e43a6868 100644 --- a/mindspore/core/ops/adam.cc +++ b/mindspore/core/ops/adam.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,8 @@ namespace { abstract::AbstractBasePtr AdamInfer(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); + const int64_t input_num = 10; + CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, prim_name); // infer shape auto var_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; @@ -55,9 +57,9 @@ void Adam::Init(const bool use_locking, const bool use_nesterov) { this->set_use_nesterov(use_nesterov); } -void Adam::set_use_locking(const bool use_locking) { this->AddAttr(kUseLocking, MakeValue(use_locking)); } +void Adam::set_use_locking(const bool use_locking) { (void)this->AddAttr(kUseLocking, MakeValue(use_locking)); } -void Adam::set_use_nesterov(const bool use_nesterov) { this->AddAttr(kUseNesterov, MakeValue(use_nesterov)); } +void Adam::set_use_nesterov(const bool use_nesterov) { (void)this->AddAttr(kUseNesterov, MakeValue(use_nesterov)); } bool Adam::get_use_locking() const { auto value_ptr = GetAttr(kUseLocking); diff --git a/mindspore/core/ops/adder.cc b/mindspore/core/ops/adder.cc index 54e38414280..9285713c457 100644 --- a/mindspore/core/ops/adder.cc +++ b/mindspore/core/ops/adder.cc @@ -48,7 +48,7 @@ int64_t Adder::get_out_channel() const { } void Adder::set_kernel_size(const std::vector &kernel_size) { - this->AddAttr(kKernelSize, MakeValue(kernel_size)); + (void)this->AddAttr(kKernelSize, MakeValue(kernel_size)); } std::vector Adder::get_kernel_size() const { @@ -58,7 +58,7 @@ std::vector Adder::get_kernel_size() const { void Adder::set_pad_mode(const PadMode &pad_mode) { int64_t swi = pad_mode; - this->AddAttr(kPadMode, MakeValue(swi)); + (void)this->AddAttr(kPadMode, MakeValue(swi)); } PadMode Adder::get_pad_mode() const { @@ -96,7 +96,7 @@ int64_t Adder::get_group() const { void Adder::set_format(const Format &format) { int64_t swi = format; - this->AddAttr(kFormat, MakeValue(swi)); + (void)this->AddAttr(kFormat, MakeValue(swi)); } Format Adder::get_format() const { diff --git a/mindspore/core/ops/addn.cc b/mindspore/core/ops/addn.cc index 7962b20912d..3f3536c2708 100644 --- a/mindspore/core/ops/addn.cc +++ b/mindspore/core/ops/addn.cc @@ -35,7 +35,7 @@ abstract::ShapePtr AddNInferShape(const PrimitivePtr &primitive, const std::vect : input_args[0]->cast()->elements(); (void)CheckAndConvertUtils::CheckInteger("concat element num", SizeToLong(elements.size()), kGreaterEqual, 1, primitive->name()); - primitive->AddAttr("n", MakeValue(SizeToLong(elements.size()))); + (void)primitive->AddAttr("n", MakeValue(SizeToLong(elements.size()))); auto shape_0 = elements[0]->BuildShape(); auto element0_shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(shape_0); for (size_t i = 0; i < elements.size(); ++i) { diff --git a/mindspore/core/ops/affine.cc b/mindspore/core/ops/affine.cc index 92255ddb2d2..dd0bf463a05 100644 --- a/mindspore/core/ops/affine.cc +++ b/mindspore/core/ops/affine.cc @@ -26,16 +26,18 @@ void Affine::Init(const std::vector &contexts, int64_t output_dim, bool this->set_transpose_b(transpose_b); } -void Affine::set_context(const std::vector &context) { this->AddAttr(kAffineContext, MakeValue(context)); } +void Affine::set_context(const std::vector &context) { + (void)this->AddAttr(kAffineContext, MakeValue(context)); +} -void Affine::set_output_dim(int64_t output_dim) { this->AddAttr(kAffineOutputDim, MakeValue(output_dim)); } +void Affine::set_output_dim(int64_t output_dim) { (void)this->AddAttr(kAffineOutputDim, MakeValue(output_dim)); } -void Affine::set_transpose_a(bool transpose_a) { AddAttr(kTransposeA, MakeValue(transpose_a)); } +void Affine::set_transpose_a(bool transpose_a) { (void)AddAttr(kTransposeA, MakeValue(transpose_a)); } -void Affine::set_transpose_b(bool transpose_b) { AddAttr(kTransposeB, MakeValue(transpose_b)); } +void Affine::set_transpose_b(bool transpose_b) { (void)AddAttr(kTransposeB, MakeValue(transpose_b)); } void Affine::set_activation_type(const ActivationType &activation_type) { - this->AddAttr(kActivationType, MakeValue(static_cast(activation_type))); + (void)this->AddAttr(kActivationType, MakeValue(static_cast(activation_type))); } bool Affine::get_transpose_a() const { diff --git a/mindspore/core/ops/all.cc b/mindspore/core/ops/all.cc index 14b1cd18980..702438701ea 100644 --- a/mindspore/core/ops/all.cc +++ b/mindspore/core/ops/all.cc @@ -22,7 +22,7 @@ namespace mindspore { namespace ops { void All::Init(const int64_t keep_dims) { this->set_keep_dims(keep_dims); } -void All::set_keep_dims(const int64_t keep_dims) { this->AddAttr(kKeepDims, MakeValue(keep_dims)); } +void All::set_keep_dims(const int64_t keep_dims) { (void)this->AddAttr(kKeepDims, MakeValue(keep_dims)); } int64_t All::get_keep_dims() const { auto value_ptr = GetAttr(kKeepDims); diff --git a/mindspore/core/ops/apply_momentum.cc b/mindspore/core/ops/apply_momentum.cc index 24fb40b1af0..1d1c38c319f 100644 --- a/mindspore/core/ops/apply_momentum.cc +++ b/mindspore/core/ops/apply_momentum.cc @@ -31,12 +31,16 @@ void ApplyMomentum::Init(const bool use_nesterov, const bool use_locking, const this->set_gradient_scale(gradient_scale); } -void ApplyMomentum::set_use_nesterov(const bool use_nesterov) { this->AddAttr(kUseNesterov, MakeValue(use_nesterov)); } +void ApplyMomentum::set_use_nesterov(const bool use_nesterov) { + (void)this->AddAttr(kUseNesterov, MakeValue(use_nesterov)); +} -void ApplyMomentum::set_use_locking(const bool use_locking) { this->AddAttr(kUseLocking, MakeValue(use_locking)); } +void ApplyMomentum::set_use_locking(const bool use_locking) { + (void)this->AddAttr(kUseLocking, MakeValue(use_locking)); +} void ApplyMomentum::set_gradient_scale(const float gradient_scale) { - this->AddAttr(kGradientScale, MakeValue(gradient_scale)); + (void)this->AddAttr(kGradientScale, MakeValue(gradient_scale)); } bool ApplyMomentum::get_use_nesterov() const { @@ -57,7 +61,7 @@ AbstractBasePtr ApplyMomentumInfer(const abstract::AnalysisEnginePtr &, const Pr const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("apply_momentum_infer", SizeToLong(input_args.size()), kEqual, 5, prim_name); + (void)CheckAndConvertUtils::CheckInteger("apply_momentum_infer", SizeToLong(input_args.size()), kEqual, 5, prim_name); // Infer shape auto v_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; diff --git a/mindspore/core/ops/arg_min.cc b/mindspore/core/ops/arg_min.cc index c54efb7f26c..532a2f9b6e6 100644 --- a/mindspore/core/ops/arg_min.cc +++ b/mindspore/core/ops/arg_min.cc @@ -38,7 +38,7 @@ AbstractBasePtr ArgMinInfer(const abstract::AnalysisEnginePtr &, const Primitive const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("arg_min_infer", input_args.size(), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("arg_min_infer", input_args.size(), kEqual, 1, prim_name); // Infer shape auto axis = GetValue(primitive->GetAttr(kAxis)); diff --git a/mindspore/core/ops/assert.cc b/mindspore/core/ops/assert.cc index 9f9cafaa1c2..1900e484c09 100644 --- a/mindspore/core/ops/assert.cc +++ b/mindspore/core/ops/assert.cc @@ -27,7 +27,7 @@ namespace mindspore { namespace ops { void Assert::Init(const int64_t summarize) { set_summarize(summarize); } -void Assert::set_summarize(const int64_t summarize) { this->AddAttr(kSummarize, MakeValue(summarize)); } +void Assert::set_summarize(const int64_t summarize) { (void)this->AddAttr(kSummarize, MakeValue(summarize)); } int64_t Assert::get_summarize() const { auto value_ptr = GetAttr(kSummarize); @@ -41,9 +41,10 @@ AbstractBasePtr AssertInfer(const abstract::AnalysisEnginePtr &, const Primitive TypePtr condition; if (!(input_args[0]->BuildType()->type_id() == kObjectTypeTensorType)) { auto condition_values = GetValue>(input_args[0]->BuildValue()); - CheckAndConvertUtils::CheckInteger("condition's rank", SizeToLong(condition_values.size()), kLessEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("condition's rank", SizeToLong(condition_values.size()), kLessEqual, 1, + op_name); if (condition_values.size() == 1) { - CheckAndConvertUtils::CheckInteger("condition[0]", SizeToLong(condition_values[0]), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("condition[0]", SizeToLong(condition_values[0]), kEqual, 1, op_name); } condition = TypeIdToType(kNumberTypeBool); } else { diff --git a/mindspore/core/ops/audio_spectrogram.cc b/mindspore/core/ops/audio_spectrogram.cc index 21e46affe3e..e93de2a17ce 100644 --- a/mindspore/core/ops/audio_spectrogram.cc +++ b/mindspore/core/ops/audio_spectrogram.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ namespace ops { namespace { abstract::ShapePtr AudioSpectrogramInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; if (input_shape.size() != 2) { MS_LOG(ERROR) << "input shape is error, which need to be 2 dimensions"; @@ -53,20 +52,13 @@ abstract::ShapePtr AudioSpectrogramInferShape(const PrimitivePtr &primitive, } TypePtr AudioSpectrogramInferType(const PrimitivePtr &prim, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto infer_type = input_args[0]->BuildType(); - auto tensor_type = infer_type->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto data_type = tensor_type->element(); - MS_EXCEPTION_IF_NULL(data_type); - return data_type; + const int64_t x_index = 0; + return CheckAndConvertUtils::GetInputTensorType(input_args, x_index, prim->name()); } } // namespace void AudioSpectrogram::set_window_size(const int64_t window_size) { - this->AddAttr(kWindowSize, MakeValue(window_size)); + (void)this->AddAttr(kWindowSize, MakeValue(window_size)); } int64_t AudioSpectrogram::get_window_size() const { auto value_ptr = GetAttr(kWindowSize); @@ -113,8 +105,11 @@ void AudioSpectrogram::Init(const int64_t window_size, const int64_t stride, con AbstractBasePtr AudioSpectrogramInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, primitive->name()); return std::make_shared(AudioSpectrogramInferType(primitive, input_args), - AudioSpectrogramInferShape(primitive, input_args)->shape()); + AudioSpectrogramInferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameAudioSpectrogram, AudioSpectrogram); } // namespace ops diff --git a/mindspore/core/ops/avg_pool.cc b/mindspore/core/ops/avg_pool.cc index c0118136695..d6af8a467b4 100644 --- a/mindspore/core/ops/avg_pool.cc +++ b/mindspore/core/ops/avg_pool.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,30 +28,30 @@ namespace mindspore { namespace ops { void AvgPool::set_pad_mode(const PadMode &pad_mode) { int64_t swi = pad_mode; - this->AddAttr(kPadMode, MakeValue(swi)); + (void)this->AddAttr(kPadMode, MakeValue(swi)); } PadMode AvgPool::get_pad_mode() const { return PadMode(GetValue(GetAttr(kPadMode))); } void AvgPool::set_kernel_size(const std::vector &kernel_size) { - this->AddAttr(kKernelSize, - MakeValue(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, this->name()))); + (void)this->AddAttr(kKernelSize, + MakeValue(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, this->name()))); } std::vector AvgPool::get_kernel_size() const { return GetValue>(GetAttr(kKernelSize)); } void AvgPool::set_strides(const std::vector &strides) { - this->AddAttr(kStrides, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kStrides, strides, this->name()))); + (void)this->AddAttr(kStrides, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kStrides, strides, this->name()))); } std::vector AvgPool::get_strides() const { return GetValue>(GetAttr(kStrides)); } void AvgPool::set_format(const Format &format) { int64_t f = format; - this->AddAttr(kFormat, MakeValue(f)); + (void)this->AddAttr(kFormat, MakeValue(f)); } Format AvgPool::get_format() const { return Format(GetValue(GetAttr(kFormat))); } -void AvgPool::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } +void AvgPool::set_pad(const std::vector &pad) { (void)this->AddAttr(kPad, MakeValue(pad)); } std::vector AvgPool::get_pad() const { auto value_ptr = GetAttr(kPad); @@ -60,7 +60,7 @@ std::vector AvgPool::get_pad() const { void AvgPool::set_round_mode(const RoundMode &round_mode) { int64_t swi = round_mode; - this->AddAttr(kRoundMode, MakeValue(swi)); + (void)this->AddAttr(kRoundMode, MakeValue(swi)); } RoundMode AvgPool::get_round_mode() const { @@ -80,14 +80,13 @@ void AvgPool::Init(const std::vector &kernel_size, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; auto format = Format(GetValue(primitive->GetAttr(kFormat))); + (void)CheckAndConvertUtils::CheckInteger("x_rank", SizeToLong(in_shape.size()), kEqual, 4, op_name); if (format == NHWC) { in_shape = {in_shape[0], in_shape[3], in_shape[1], in_shape[2]}; } - CheckAndConvertUtils::CheckInteger("x_rank", SizeToLong(in_shape.size()), kEqual, 4, op_name); auto kernel_size = GetValue>(primitive->GetAttr(kKernelSize)); auto pad_mode = PadMode(GetValue(primitive->GetAttr(kPadMode))); auto batch = in_shape[0]; @@ -95,12 +94,20 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector>(primitive->GetAttr(kStrides)); + (void)CheckAndConvertUtils::CheckInteger("kernel size", SizeToLong(kernel_size.size()), kEqual, 4, op_name); + (void)CheckAndConvertUtils::CheckInteger("strides size", SizeToLong(strides.size()), kEqual, 4, op_name); + if (std::any_of(strides.begin(), strides.end(), [](int64_t stride) { return stride <= 0; })) { + MS_LOG(EXCEPTION) << "Strides is not valid, strides must be positive."; + } + if (std::any_of(kernel_size.begin(), kernel_size.end(), [](int64_t size) { return size <= 0; })) { + MS_LOG(EXCEPTION) << "Kernel size is not valid, kernel size must be positive."; + } auto kernel_h = kernel_size[2]; auto kernel_w = kernel_size[3]; auto stride_h = strides[2]; auto stride_w = strides[3]; - int64_t out_h = -1; - int64_t out_w = -1; + int64_t out_h = abstract::Shape::SHP_ANY; + int64_t out_w = abstract::Shape::SHP_ANY; if (pad_mode == VALID) { out_h = ceil((in_h - (kernel_h - 1)) / stride_h); out_w = ceil((in_w - (kernel_w - 1)) / stride_w); @@ -112,22 +119,17 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(out_shape); } -TypePtr InferType(const std::vector &input_args) { - if (std::any_of(input_args.begin(), input_args.end(), [](AbstractBasePtr arg) { return arg == nullptr; })) { - MS_LOG(EXCEPTION) << "nullptr"; - } - return input_args[0]->BuildType(); -} +TypePtr InferType(const std::vector &input_args) { return input_args[0]->BuildType(); } } // namespace AbstractBasePtr AvgPoolInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); return std::make_shared(InferType(input_args), InferShape(primitive, input_args)->shape()); } REGISTER_PRIMITIVE_C(kNameAvgPool, AvgPool); diff --git a/mindspore/core/ops/avg_pool_3d.cc b/mindspore/core/ops/avg_pool_3d.cc index 31f65304fb9..a2ea0e2435e 100644 --- a/mindspore/core/ops/avg_pool_3d.cc +++ b/mindspore/core/ops/avg_pool_3d.cc @@ -114,12 +114,12 @@ void GetPadsByPadding(int64_t in_d, int64_t in_h, int64_t in_w, int64_t kernel_d abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 1, op_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - CheckAndConvertUtils::CheckInteger("x_rank", in_shape.size(), kEqual, k5DInputDims, op_name); + (void)CheckAndConvertUtils::CheckInteger("x_rank", in_shape.size(), kEqual, k5DInputDims, op_name); std::vector kernel_size; std::vector strides; @@ -157,7 +157,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 1, op_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/batch_matmul.cc b/mindspore/core/ops/batch_matmul.cc index b73d895a29b..597af3f0a93 100644 --- a/mindspore/core/ops/batch_matmul.cc +++ b/mindspore/core/ops/batch_matmul.cc @@ -63,8 +63,8 @@ abstract::ShapePtr BatchMatmulInferShape(const PrimitivePtr &primitive, << ", x2 shape " << y_shp << "(transpose_b=" << transpose_b << "})"; } } - primitive->AddAttr("transpose_x1", transpose_a_ptr); - primitive->AddAttr("transpose_x2", transpose_b_ptr); + (void)primitive->AddAttr("transpose_x1", transpose_a_ptr); + (void)primitive->AddAttr("transpose_x2", transpose_b_ptr); ShapeVector x_min_shape = x_shape_map[kMinShape]; ShapeVector x_max_shape = x_shape_map[kMaxShape]; ShapeVector y_min_shape = y_shape_map[kMinShape]; @@ -127,9 +127,9 @@ void BatchMatmul::Init(bool transpose_a, bool transpose_b) { set_transpose_b(transpose_b); } -void BatchMatmul::set_transpose_a(bool transpose_a) { AddAttr(kTransposeA, MakeValue(transpose_a)); } +void BatchMatmul::set_transpose_a(bool transpose_a) { (void)AddAttr(kTransposeA, MakeValue(transpose_a)); } -void BatchMatmul::set_transpose_b(bool transpose_b) { AddAttr(kTransposeB, MakeValue(transpose_b)); } +void BatchMatmul::set_transpose_b(bool transpose_b) { (void)AddAttr(kTransposeB, MakeValue(transpose_b)); } bool BatchMatmul::get_transpose_a() const { auto value_ptr = GetAttr(kTransposeA); @@ -144,7 +144,7 @@ bool BatchMatmul::get_transpose_b() const { AbstractBasePtr BatchMatmulInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - CheckAndConvertUtils::CheckInteger("BatchMatmul infer", input_args.size(), kGreaterEqual, 2, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("BatchMatmul infer", input_args.size(), kGreaterEqual, 2, primitive->name()); return abstract::MakeAbstract(BatchMatmulInferShape(primitive, input_args), BatchMatmulInferType(primitive, input_args)); } diff --git a/mindspore/core/ops/batch_norm.cc b/mindspore/core/ops/batch_norm.cc index 78ae7bc6899..38508570b0c 100644 --- a/mindspore/core/ops/batch_norm.cc +++ b/mindspore/core/ops/batch_norm.cc @@ -31,21 +31,21 @@ void BatchNorm::Init(const bool is_training, const float epsilon, const float mo set_momentum(momentum); } -void BatchNorm::set_is_training(const bool is_training) { this->AddAttr(kIsTraining, MakeValue(is_training)); } +void BatchNorm::set_is_training(const bool is_training) { (void)this->AddAttr(kIsTraining, MakeValue(is_training)); } void BatchNorm::set_epsilon(const float epsilon) { CheckAndConvertUtils::CheckInRange(kEpsilon, epsilon, kIncludeBoth, {0.0, 1.0}, this->name()); - this->AddAttr(kEpsilon, MakeValue(epsilon)); + (void)this->AddAttr(kEpsilon, MakeValue(epsilon)); } void BatchNorm::set_format(const Format &format) { int64_t f = format; - this->AddAttr(kFormat, MakeValue(f)); + (void)this->AddAttr(kFormat, MakeValue(f)); } void BatchNorm::set_momentum(const float momentun) { CheckAndConvertUtils::CheckInRange(kMomentum, SizeToLong(momentun), kIncludeBoth, {0.0, 1.0}, this->name()); - this->AddAttr(kMomentum, MakeValue(momentun)); + (void)this->AddAttr(kMomentum, MakeValue(momentun)); } float BatchNorm::get_momentum() const { @@ -73,7 +73,7 @@ AbstractBasePtr BatchNormInfer(const abstract::AnalysisEnginePtr &, const Primit // Infer shape MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("batch_norm_infer", SizeToLong(input_args.size()), kEqual, 5, prim_name); + (void)CheckAndConvertUtils::CheckInteger("batch_norm_infer", SizeToLong(input_args.size()), kEqual, 5, prim_name); auto input_x = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; auto format = Format(GetValue(primitive->GetAttr(kFormat))); @@ -94,7 +94,7 @@ AbstractBasePtr BatchNormInfer(const abstract::AnalysisEnginePtr &, const Primit input_shape_norm.push_back(input_x[1]); input_shape_norm.push_back(input_x[2]); } - CheckAndConvertUtils::CheckInteger("scale rank", SizeToLong(scale.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("scale rank", SizeToLong(scale.size()), kEqual, 1, prim_name); CheckAndConvertUtils::Check("scale shape", scale, kEqual, "bias shape", bias, prim_name, TypeError); CheckAndConvertUtils::Check("scale shape[0]", scale[0], kEqual, "input_x channel", input_shape_norm[1], prim_name, TypeError); diff --git a/mindspore/core/ops/batch_to_space.cc b/mindspore/core/ops/batch_to_space.cc index 180f59abb50..5130606555a 100644 --- a/mindspore/core/ops/batch_to_space.cc +++ b/mindspore/core/ops/batch_to_space.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ void BatchToSpace::Init(const std::vector &block_size, const std::vecto } void BatchToSpace::set_block_size(const std::vector &block_size) { - this->AddAttr(kBlockSize, MakeValue(block_size)); + (void)this->AddAttr(kBlockSize, MakeValue(block_size)); } std::vector BatchToSpace::get_block_size() const { @@ -36,7 +36,7 @@ std::vector BatchToSpace::get_block_size() const { } void BatchToSpace::set_crops(const std::vector> &crops) { - this->AddAttr(kCrops, MakeValue(crops)); + (void)this->AddAttr(kCrops, MakeValue(crops)); } std::vector> BatchToSpace::get_crops() const { @@ -56,10 +56,14 @@ AbstractBasePtr BatchToSpaceInfer(const abstract::AnalysisEnginePtr &, const Pri prim_name); auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kEqual, 4, prim_name); auto block_size = GetValue>(primitive->GetAttr(kBlockSize)); auto crops = GetValue>>(primitive->GetAttr(kCrops)); auto out_shape = x_shape; + (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("block_size size", SizeToLong(block_size.size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("crops size", SizeToLong(crops.size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("crops[0] size", SizeToLong(crops[0].size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("crops[1] size", SizeToLong(crops[1].size()), kEqual, 4, prim_name); for (size_t i = 0; i < 2; ++i) { auto x_block_prod = out_shape[i + 2] * block_size[i]; auto crops_sum = crops[i][0] + crops[i][1]; diff --git a/mindspore/core/ops/batch_to_space_nd.cc b/mindspore/core/ops/batch_to_space_nd.cc index 70db427ffb3..2ba2a24a106 100644 --- a/mindspore/core/ops/batch_to_space_nd.cc +++ b/mindspore/core/ops/batch_to_space_nd.cc @@ -30,7 +30,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorname(); auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("input_x rank", SizeToLong(x_shape.size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input_x rank", SizeToLong(x_shape.size()), kEqual, 4, prim_name); auto out_shape = x_shape; int64_t block_shape_prod = 1; size_t offset = 2; @@ -72,7 +72,7 @@ void BatchToSpaceND::set_crops(std::vector> crops) { (void)CheckAndConvertUtils::CheckInteger(kCrops, crops[i][j], kGreaterEqual, 0, this->name()); } } - this->AddAttr(kCrops, MakeValue(crops)); + (void)this->AddAttr(kCrops, MakeValue(crops)); } std::vector> BatchToSpaceND::get_crops() const { @@ -80,11 +80,11 @@ std::vector> BatchToSpaceND::get_crops() const { return GetValue>>(value_ptr); } void BatchToSpaceND::set_block_shape(std::vector block_shape) { - CheckAndConvertUtils::CheckInteger(kBlockShape, SizeToLong(block_shape.size()), kEqual, 2, this->name()); + (void)CheckAndConvertUtils::CheckInteger(kBlockShape, SizeToLong(block_shape.size()), kEqual, 2, this->name()); for (size_t i = 0; i < block_shape.size(); i++) { (void)CheckAndConvertUtils::CheckInteger(kBlockShape, block_shape[i], kGreaterEqual, 1, this->name()); } - this->AddAttr(kBlockShape, MakeValue(block_shape)); + (void)this->AddAttr(kBlockShape, MakeValue(block_shape)); } std::vector BatchToSpaceND::get_block_shape() const { diff --git a/mindspore/core/ops/bias_add.cc b/mindspore/core/ops/bias_add.cc index df4daa0b252..d1ab16e54da 100644 --- a/mindspore/core/ops/bias_add.cc +++ b/mindspore/core/ops/bias_add.cc @@ -35,15 +35,15 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(prim_name, input_args, 1); MS_EXCEPTION_IF_NULL(x); MS_EXCEPTION_IF_NULL(bias); - CheckAndConvertUtils::CheckInteger("arg size", SizeToLong(input_args.size()), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("arg size", SizeToLong(input_args.size()), kEqual, 2, prim_name); auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape()); auto input_shape = shape_map[kShape]; auto min_shape = shape_map[kMinShape]; auto max_shape = shape_map[kMaxShape]; CheckAndConvertUtils::CheckInRange("bias_add_infer", input_shape.size(), kIncludeBoth, {2, 5}, prim_name); auto bias_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("bias rank", SizeToLong(bias_shape.size()), kEqual, 1, prim_name); - CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(input_shape.size()), kGreaterEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("bias rank", SizeToLong(bias_shape.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(input_shape.size()), kGreaterEqual, 2, prim_name); auto data_format_ptr = primitive->GetAttr("format"); int64_t data_format = Format::NCHW; if (data_format_ptr != nullptr) { @@ -71,7 +71,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto prim_name = prim->name(); - CheckAndConvertUtils::CheckInteger("biasadd_infer", SizeToLong(input_args.size()), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("biasadd_infer", SizeToLong(input_args.size()), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/binary_cross_entropy.cc b/mindspore/core/ops/binary_cross_entropy.cc index 0a33426862e..1781d7902db 100644 --- a/mindspore/core/ops/binary_cross_entropy.cc +++ b/mindspore/core/ops/binary_cross_entropy.cc @@ -71,7 +71,7 @@ TypePtr BinaryCrossEntroyInferType(const PrimitivePtr &prim, const std::vectorAddAttr(kReduction, MakeValue(swi)); + (void)this->AddAttr(kReduction, MakeValue(swi)); } Reduction BinaryCrossEntropy::get_reduction() const { @@ -83,7 +83,7 @@ void BinaryCrossEntropy::Init(const Reduction &reduction) { this->set_reduction( AbstractBasePtr BinaryCrossEntropyInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(BinaryCrossEntroyInferType(primitive, input_args), - BinaryCrossEntroyInferShape(primitive, input_args)->shape()); + BinaryCrossEntroyInferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameBinaryCrossEntropy, BinaryCrossEntropy); } // namespace ops diff --git a/mindspore/core/ops/broadcast.cc b/mindspore/core/ops/broadcast.cc index 322586d2cfc..7250e631835 100644 --- a/mindspore/core/ops/broadcast.cc +++ b/mindspore/core/ops/broadcast.cc @@ -27,11 +27,11 @@ void Broadcast::Init(const int64_t root_rank, const std::string &group) { this->set_root_rank(root_rank); this->set_group(group); } -void Broadcast::set_root_rank(const int64_t root_rank) { this->AddAttr(kKeepProb, MakeValue(root_rank)); } +void Broadcast::set_root_rank(const int64_t root_rank) { (void)this->AddAttr(kKeepProb, MakeValue(root_rank)); } void Broadcast::set_group(const std::string &group) { CheckAndConvertUtils::CheckString(kGroup, group, {"hccl_world_group", "hccl_world_group"}, this->name()); - this->AddAttr(kGroup, MakeValue(group)); + (void)this->AddAttr(kGroup, MakeValue(group)); } int64_t Broadcast::get_root_rank() const { auto value_ptr = this->GetAttr(kRootRank); diff --git a/mindspore/core/ops/broadcast_to.cc b/mindspore/core/ops/broadcast_to.cc index fec49f67200..4f9f316b64a 100644 --- a/mindspore/core/ops/broadcast_to.cc +++ b/mindspore/core/ops/broadcast_to.cc @@ -50,7 +50,7 @@ abstract::ShapePtr BroadcastToInferShape(const PrimitivePtr &primitive, } } auto x_shape_ptr = std::make_shared(input_x); - primitive->AddAttr("shape", MakeValue(input_x)); + (void)primitive->AddAttr("shape", MakeValue(input_x)); for (size_t i = 0; i < x_shape.size(); i++) { if (input_x[i + outer_dim_offset] != x_shape[i] && x_shape[i] != 1) { MS_EXCEPTION(ValueError) << "Not support shapes for broadcast, x_shape: " @@ -75,8 +75,8 @@ TypePtr BroadcastToInferType(const PrimitivePtr &prim, const std::vector &shape) { set_shape(shape); } void BroadcastTo::set_shape(const std::vector &shape) { - CheckAndConvertUtils::CheckInteger(kShapeSize, SizeToLong(shape.size()), kGreaterThan, 0, name()); - AddAttr(kShape, MakeValue(shape)); + (void)CheckAndConvertUtils::CheckInteger(kShapeSize, SizeToLong(shape.size()), kGreaterThan, 0, name()); + (void)AddAttr(kShape, MakeValue(shape)); } std::vector BroadcastTo::get_shape() const { diff --git a/mindspore/core/ops/ceil.cc b/mindspore/core/ops/ceil.cc index a55077e3f16..e2f16d5590d 100644 --- a/mindspore/core/ops/ceil.cc +++ b/mindspore/core/ops/ceil.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,9 +28,9 @@ namespace mindspore { namespace ops { AbstractBasePtr CeilInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; const std::set valid_types = {kFloat16, kFloat32}; auto infer_type = input_args[0]->BuildType(); diff --git a/mindspore/core/ops/control_depend.cc b/mindspore/core/ops/control_depend.cc index 80d48930671..97822996a8a 100644 --- a/mindspore/core/ops/control_depend.cc +++ b/mindspore/core/ops/control_depend.cc @@ -22,7 +22,7 @@ void ControlDepend::Init(const int64_t depend_mode) { this->set_depend_mode(depe void ControlDepend::set_depend_mode(const int64_t depend_mode) { CheckAndConvertUtils::CheckInRange(kDependMode, depend_mode, kIncludeBoth, {0, 1}, name()); - AddAttr(kDependMode, MakeValue(depend_mode)); + (void)AddAttr(kDependMode, MakeValue(depend_mode)); } int64_t ControlDepend::get_depend_mode() const { diff --git a/mindspore/core/ops/conv2d.cc b/mindspore/core/ops/conv2d.cc index f2bab68a80a..c579f0ce6bb 100644 --- a/mindspore/core/ops/conv2d.cc +++ b/mindspore/core/ops/conv2d.cc @@ -148,8 +148,8 @@ abstract::ShapePtr Conv2dInferShape(const PrimitivePtr &primitive, const std::ve auto w_shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape()); auto x_shape = x_shape_map[kShape]; auto w_shape = w_shape_map[kShape]; - CheckAndConvertUtils::CheckInteger("x shape size", SizeToLong(x_shape.size()), kEqual, 4, primitive->name()); - CheckAndConvertUtils::CheckInteger("w shape size", SizeToLong(w_shape.size()), kEqual, 4, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("x shape size", SizeToLong(x_shape.size()), kEqual, 4, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("w shape size", SizeToLong(w_shape.size()), kEqual, 4, primitive->name()); auto x_min_shape = x_shape_map[kMinShape]; auto x_max_shape = x_shape_map[kMaxShape]; auto w_min_shape = w_shape_map[kMinShape]; @@ -251,20 +251,20 @@ void Conv2D::Init(int64_t out_channel, const std::vector &kernel_size, } void Conv2D::set_out_channel(int64_t out_channel) { - AddAttr(kOutChannel, - MakeValue(CheckAndConvertUtils::CheckInteger(kOutChannel, out_channel, kGreaterThan, 0, name()))); + (void)AddAttr(kOutChannel, + MakeValue(CheckAndConvertUtils::CheckInteger(kOutChannel, out_channel, kGreaterThan, 0, name()))); } void Conv2D::set_kernel_size(const std::vector &kernel_size) { - AddAttr(kKernelSize, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, name()))); + (void)AddAttr(kKernelSize, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, name()))); } void Conv2D::set_stride(const std::vector &stride) { - AddAttr(kStride, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kStride, stride, name()))); + (void)AddAttr(kStride, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kStride, stride, name()))); } void Conv2D::set_dilation(const std::vector &dilation) { - AddAttr(kDilation, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kDilation, dilation, name()))); + (void)AddAttr(kDilation, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kDilation, dilation, name()))); } void Conv2D::set_pad_mode(const PadMode &pad_mode) { @@ -277,25 +277,25 @@ void Conv2D::set_pad_mode(const PadMode &pad_mode) { CheckAndConvertUtils::Check(kPad, pad, kEqual, "zeros_list", {0, 0, 0, 0}, name()); } int64_t swi = pad_mode; - AddAttr(kPadMode, MakeValue(swi)); + (void)AddAttr(kPadMode, MakeValue(swi)); } void Conv2D::set_pad(const std::vector &pad) { (void)CheckAndConvertUtils::CheckInteger("pad_size", pad.size(), kEqual, 4, name()); - AddAttr(kPad, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kPad, pad, name()))); + (void)AddAttr(kPad, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kPad, pad, name()))); } void Conv2D::set_mode(int64_t mode) { - AddAttr(kMode, MakeValue(CheckAndConvertUtils::CheckInteger(kMode, mode, kEqual, 1, name()))); + (void)AddAttr(kMode, MakeValue(CheckAndConvertUtils::CheckInteger(kMode, mode, kEqual, 1, name()))); } void Conv2D::set_group(int64_t group) { - AddAttr(kGroup, MakeValue(CheckAndConvertUtils::CheckInteger(kGroup, group, kGreaterThan, 0, name()))); + (void)AddAttr(kGroup, MakeValue(CheckAndConvertUtils::CheckInteger(kGroup, group, kGreaterThan, 0, name()))); } void Conv2D::set_format(const Format &format) { int64_t f = format; - AddAttr(kFormat, MakeValue(f)); + (void)AddAttr(kFormat, MakeValue(f)); } int64_t Conv2D::get_out_channel() const { @@ -345,8 +345,8 @@ Format Conv2D::get_format() const { AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { - CheckAndConvertUtils::CheckInteger("Conv2d infer", SizeToLong(input_args.size()), kGreaterEqual, 2, - primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("Conv2d infer", SizeToLong(input_args.size()), kGreaterEqual, 2, + primitive->name()); const std::set valid_types = {kInt8, kInt32, kInt64, kFloat16, kFloat32}; std::map types; types.emplace("x", input_args[0]->BuildType()); diff --git a/mindspore/core/ops/conv2d_transpose.cc b/mindspore/core/ops/conv2d_transpose.cc index 9bc7d1cd0a1..29e8330b1cd 100644 --- a/mindspore/core/ops/conv2d_transpose.cc +++ b/mindspore/core/ops/conv2d_transpose.cc @@ -43,33 +43,34 @@ void Conv2DTranspose::Init(int64_t in_channel, int64_t out_channel, const std::v } void Conv2DTranspose::set_in_channel(int64_t in_channel) { - AddAttr(kInChannel, MakeValue(CheckAndConvertUtils::CheckInteger(kInChannel, in_channel, kGreaterThan, 0, name()))); + (void)AddAttr(kInChannel, + MakeValue(CheckAndConvertUtils::CheckInteger(kInChannel, in_channel, kGreaterThan, 0, name()))); } void Conv2DTranspose::set_out_channel(int64_t out_channel) { - AddAttr(kOutChannel, - MakeValue(CheckAndConvertUtils::CheckInteger(kOutChannel, out_channel, kGreaterThan, 0, name()))); + (void)AddAttr(kOutChannel, + MakeValue(CheckAndConvertUtils::CheckInteger(kOutChannel, out_channel, kGreaterThan, 0, name()))); } void Conv2DTranspose::set_kernel_size(const std::vector &kernel_size) { - CheckAndConvertUtils::CheckInteger(kKernelSize, SizeToLong(kernel_size.size()), kEqual, 2, name()); + (void)CheckAndConvertUtils::CheckInteger(kKernelSize, SizeToLong(kernel_size.size()), kEqual, 2, name()); for (int64_t item : kernel_size) { (void)CheckAndConvertUtils::CheckInteger(kKernelSize, item, kGreaterEqual, 1, name()); } - AddAttr(kKernelSize, MakeValue(kernel_size)); + (void)AddAttr(kKernelSize, MakeValue(kernel_size)); } void Conv2DTranspose::set_stride(const std::vector &stride) { - CheckAndConvertUtils::CheckInteger(kStride, SizeToLong(stride.size()), kEqual, 2, name()); + (void)CheckAndConvertUtils::CheckInteger(kStride, SizeToLong(stride.size()), kEqual, 2, name()); for (int64_t item : stride) { (void)CheckAndConvertUtils::CheckInteger(kStride, item, kGreaterEqual, 1, name()); } - AddAttr(kStride, MakeValue(stride)); + (void)AddAttr(kStride, MakeValue(stride)); } void Conv2DTranspose::set_dilation(const std::vector &dilation) { - CheckAndConvertUtils::CheckInteger(kDilation, SizeToLong(dilation.size()), kGreaterEqual, 2, name()); - AddAttr(kDilation, MakeValue(dilation)); + (void)CheckAndConvertUtils::CheckInteger(kDilation, SizeToLong(dilation.size()), kGreaterEqual, 2, name()); + (void)AddAttr(kDilation, MakeValue(dilation)); } void Conv2DTranspose::set_pad_mode(const PadMode &pad_mode) { @@ -82,30 +83,30 @@ void Conv2DTranspose::set_pad_mode(const PadMode &pad_mode) { CheckAndConvertUtils::Check(kPad, pad, kEqual, "zeros_list", {0, 0, 0, 0}, name()); } int64_t swi = pad_mode; - AddAttr(kPadMode, MakeValue(swi)); + (void)AddAttr(kPadMode, MakeValue(swi)); } void Conv2DTranspose::set_pad(const std::vector &pad) { - CheckAndConvertUtils::CheckInteger("pad_size", SizeToLong(pad.size()), kEqual, 4, name()); - AddAttr(kPad, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kPad, pad, name()))); + (void)CheckAndConvertUtils::CheckInteger("pad_size", SizeToLong(pad.size()), kEqual, 4, name()); + (void)AddAttr(kPad, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kPad, pad, name()))); } void Conv2DTranspose::set_mode(int64_t mode) { - AddAttr(kMode, MakeValue(CheckAndConvertUtils::CheckInteger(kMode, mode, kEqual, 1, name()))); + (void)AddAttr(kMode, MakeValue(CheckAndConvertUtils::CheckInteger(kMode, mode, kEqual, 1, name()))); } void Conv2DTranspose::set_group(int64_t group) { - AddAttr(kGroup, MakeValue(CheckAndConvertUtils::CheckInteger(kGroup, group, kGreaterThan, 0, name()))); + (void)AddAttr(kGroup, MakeValue(CheckAndConvertUtils::CheckInteger(kGroup, group, kGreaterThan, 0, name()))); } void Conv2DTranspose::set_format(const Format &format) { int64_t f = format; - AddAttr(kFormat, MakeValue(f)); + (void)AddAttr(kFormat, MakeValue(f)); } void Conv2DTranspose::set_pad_list(const std::vector &pad_list) { - CheckAndConvertUtils::CheckInteger(kPadList, SizeToLong(pad_list.size()), kEqual, 4, name()); - this->AddAttr(kPadList, MakeValue(pad_list)); + (void)CheckAndConvertUtils::CheckInteger(kPadList, SizeToLong(pad_list.size()), kEqual, 4, name()); + (void)this->AddAttr(kPadList, MakeValue(pad_list)); } int64_t Conv2DTranspose::get_in_channel() const { diff --git a/mindspore/core/ops/crop_and_resize.cc b/mindspore/core/ops/crop_and_resize.cc index c6d47ad6b26..b1e6ab9010f 100644 --- a/mindspore/core/ops/crop_and_resize.cc +++ b/mindspore/core/ops/crop_and_resize.cc @@ -29,11 +29,11 @@ void CropAndResize::Init(ResizeMethod method, float extrapolation_value) { void CropAndResize::set_method(ResizeMethod method) { auto swi = (int64_t)method; - this->AddAttr(kMethod, MakeValue(swi)); + (void)this->AddAttr(kMethod, MakeValue(swi)); } void CropAndResize::set_extrapolation_value(float extrapolation_value) { - this->AddAttr(kExtrapolationValue, MakeValue(extrapolation_value)); + (void)this->AddAttr(kExtrapolationValue, MakeValue(extrapolation_value)); } ResizeMethod CropAndResize::get_method() const { diff --git a/mindspore/core/ops/ctc_loss_v2.cc b/mindspore/core/ops/ctc_loss_v2.cc index a1375f68adf..09ae878de08 100644 --- a/mindspore/core/ops/ctc_loss_v2.cc +++ b/mindspore/core/ops/ctc_loss_v2.cc @@ -35,7 +35,8 @@ abstract::TupleShapePtr CTCLossV2InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, kInputSize, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, kInputSize, + prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/ctc_loss_v2_grad.cc b/mindspore/core/ops/ctc_loss_v2_grad.cc index 7b55301339d..6a1fcff59d7 100644 --- a/mindspore/core/ops/ctc_loss_v2_grad.cc +++ b/mindspore/core/ops/ctc_loss_v2_grad.cc @@ -33,7 +33,8 @@ abstract::ShapePtr CTCLossV2GradInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, kInputSize, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, kInputSize, + prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/ctcloss.cc b/mindspore/core/ops/ctcloss.cc index fe0b3621f30..907bc6bf064 100644 --- a/mindspore/core/ops/ctcloss.cc +++ b/mindspore/core/ops/ctcloss.cc @@ -29,7 +29,7 @@ namespace mindspore { namespace ops { namespace { void CheckCTCLossInputs(const std::vector &input_args, const std::string &op_name) { - CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kGreaterEqual, 4, op_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kGreaterEqual, 4, op_name); auto inputs = CheckAndConvertUtils::CheckArgs(op_name, input_args, 0); auto labels_indices = CheckAndConvertUtils::CheckArgs(op_name, input_args, 1); auto labels_values = CheckAndConvertUtils::CheckArgs(op_name, input_args, 2); @@ -40,11 +40,11 @@ void CheckCTCLossInputs(const std::vector &input_args, const st auto labels_values_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(labels_values->BuildShape())[kShape]; auto sequence_length_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(sequence_length->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("inputs rank", inputs_shape.size(), kEqual, 3, op_name); - CheckAndConvertUtils::CheckInteger("label_indices rank", labels_indices_shape.size(), kEqual, 2, op_name); - CheckAndConvertUtils::CheckInteger("label_indices second dim", labels_indices_shape[1], kEqual, 2, op_name); - CheckAndConvertUtils::CheckInteger("label_values rank", labels_values_shape.size(), kEqual, 1, op_name); - CheckAndConvertUtils::CheckInteger("sequence_length rank", sequence_length_shape.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("inputs rank", inputs_shape.size(), kEqual, 3, op_name); + (void)CheckAndConvertUtils::CheckInteger("label_indices rank", labels_indices_shape.size(), kEqual, 2, op_name); + (void)CheckAndConvertUtils::CheckInteger("label_indices second dim", labels_indices_shape[1], kEqual, 2, op_name); + (void)CheckAndConvertUtils::CheckInteger("label_values rank", labels_values_shape.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("sequence_length rank", sequence_length_shape.size(), kEqual, 1, op_name); if (labels_indices_shape[0] != labels_values_shape[0]) { MS_EXCEPTION(ValueError) << "For CTCLoss first dim of label_indices and label_value must be same, but got " diff --git a/mindspore/core/ops/cumsum.cc b/mindspore/core/ops/cumsum.cc index 8dc7db24ac9..4c0b48e92ce 100644 --- a/mindspore/core/ops/cumsum.cc +++ b/mindspore/core/ops/cumsum.cc @@ -27,14 +27,14 @@ void CumSum::Init(const bool exclusive, const bool reverse) { this->set_reverse(reverse); } -void CumSum::set_exclusive(const bool exclusive) { this->AddAttr(kExclusive, MakeValue(exclusive)); } +void CumSum::set_exclusive(const bool exclusive) { (void)this->AddAttr(kExclusive, MakeValue(exclusive)); } bool CumSum::get_exclusive() const { auto value_ptr = this->GetAttr(kExclusive); return GetValue(value_ptr); } -void CumSum::set_reverse(const bool reverse) { this->AddAttr(kReverse, MakeValue(reverse)); } +void CumSum::set_reverse(const bool reverse) { (void)this->AddAttr(kReverse, MakeValue(reverse)); } bool CumSum::get_reverse() const { auto value_ptr = this->GetAttr(kReverse); @@ -44,7 +44,7 @@ AbstractBasePtr CumSumInfer(const abstract::AnalysisEnginePtr &, const Primitive const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/custom.cc b/mindspore/core/ops/custom.cc index 3e4b7562fd1..ed4580b7805 100644 --- a/mindspore/core/ops/custom.cc +++ b/mindspore/core/ops/custom.cc @@ -25,7 +25,7 @@ void Custom::Init(const std::string &type, const std::mapset_attr(attrs); } -void Custom::set_type(const std::string &type) { this->AddAttr(kType, MakeValue(type)); } +void Custom::set_type(const std::string &type) { (void)this->AddAttr(kType, MakeValue(type)); } std::string Custom::get_type() const { auto value_ptr = this->GetAttr(kType); diff --git a/mindspore/core/ops/custom_normalize.cc b/mindspore/core/ops/custom_normalize.cc index 47d9fa66a4c..4d82d462ceb 100644 --- a/mindspore/core/ops/custom_normalize.cc +++ b/mindspore/core/ops/custom_normalize.cc @@ -21,16 +21,14 @@ namespace mindspore { namespace ops { namespace { -abstract::ShapePtr CustomNormalizeInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - MS_EXCEPTION_IF_NULL(input_args[0]); - MS_EXCEPTION_IF_NULL(input_args[0]->BuildShape()); - if (input_args[0]->BuildValue()->cast()->data_c() == nullptr) { - MS_LOG(ERROR) << "Do infer shape in runtime."; - } +abstract::ShapePtr CustomNormalizeInferShape(const std::vector &input_args) { + auto base_value = input_args[0]->BuildValue(); + MS_EXCEPTION_IF_NULL(base_value); + auto tensor_value = base_value->cast(); + MS_EXCEPTION_IF_NULL(tensor_value); + MS_EXCEPTION_IF_NULL(tensor_value->data_c()); std::vector infer_shape; - auto string_num = reinterpret_cast(input_args[0]->BuildValue()->cast()->data_c()); + auto string_num = reinterpret_cast(tensor_value->data_c()); if (*string_num == 0) { infer_shape.push_back(1); } else { @@ -40,10 +38,6 @@ abstract::ShapePtr CustomNormalizeInferShape(const PrimitivePtr &primitive, } TypePtr CustomNormalizeInferType(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } auto infer_type = input_args[0]->BuildType(); auto tensor_type = infer_type->cast(); MS_EXCEPTION_IF_NULL(tensor_type); @@ -55,8 +49,11 @@ TypePtr CustomNormalizeInferType(const PrimitivePtr &primitive, const std::vecto AbstractBasePtr CustomNormalizeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, primitive->name()); return std::make_shared(CustomNormalizeInferType(primitive, input_args), - CustomNormalizeInferShape(primitive, input_args)->shape()); + CustomNormalizeInferShape(input_args)); } REGISTER_PRIMITIVE_C(kNameCustomNormalize, CustomNormalize); } // namespace ops diff --git a/mindspore/core/ops/custom_predict.cc b/mindspore/core/ops/custom_predict.cc index c3a0079e4d4..8a3911208a6 100644 --- a/mindspore/core/ops/custom_predict.cc +++ b/mindspore/core/ops/custom_predict.cc @@ -34,7 +34,7 @@ int64_t CustomPredict::get_output_num() const { } void CustomPredict::set_weight_threshold(const float weight_threshold) { - this->AddAttr(kWeightThreshold, MakeValue(weight_threshold)); + (void)this->AddAttr(kWeightThreshold, MakeValue(weight_threshold)); } float CustomPredict::get_weight_threshold() const { diff --git a/mindspore/core/ops/depth_to_space.cc b/mindspore/core/ops/depth_to_space.cc index f952b6c2a35..ca4adf1fa92 100644 --- a/mindspore/core/ops/depth_to_space.cc +++ b/mindspore/core/ops/depth_to_space.cc @@ -27,13 +27,13 @@ namespace mindspore { namespace ops { void DepthToSpace::set_block_size(const int64_t block_size) { CheckAndConvertUtils::Check(kBlockSize, block_size, kGreaterEqual, "", 2, this->name()); - this->AddAttr(kBlockSize, MakeValue(block_size)); + (void)this->AddAttr(kBlockSize, MakeValue(block_size)); } int64_t DepthToSpace::get_block_size() const { return GetValue(GetAttr(kBlockSize)); } void DepthToSpace::set_format(const Format &format) { int64_t f = format; - this->AddAttr(kFormat, MakeValue(f)); + (void)this->AddAttr(kFormat, MakeValue(f)); } Format DepthToSpace::get_format() const { return Format(GetValue(GetAttr(kFormat))); } @@ -47,7 +47,7 @@ AbstractBasePtr DepthToSpaceInfer(const abstract::AnalysisEnginePtr &, const Pri const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input number", int64_t(input_args.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input number", int64_t(input_args.size()), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -59,10 +59,10 @@ AbstractBasePtr DepthToSpaceInfer(const abstract::AnalysisEnginePtr &, const Pri if (format == NHWC) { x_shape = {x_shape[0], x_shape[3], x_shape[1], x_shape[2]}; } - CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kEqual, 4, prim_name); int64_t block_size = GetValue(primitive->GetAttr(kBlockSize)); - CheckAndConvertUtils::CheckInteger("x_shape[1] % (block_size*block_size)", x_shape[1] % (block_size * block_size), - kEqual, 0, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x_shape[1] % (block_size*block_size)", + x_shape[1] % (block_size * block_size), kEqual, 0, prim_name); auto out_shape = x_shape; out_shape[1] /= block_size * block_size; out_shape[2] *= block_size; diff --git a/mindspore/core/ops/detection_post_process.cc b/mindspore/core/ops/detection_post_process.cc index 4a1b951d533..3c90483f838 100644 --- a/mindspore/core/ops/detection_post_process.cc +++ b/mindspore/core/ops/detection_post_process.cc @@ -37,7 +37,11 @@ void DetectionPostProcess::Init(const int64_t inputSize, const std::vectorAddAttr(kInputSize, MakeValue(inputSize)); } + +void DetectionPostProcess::set_input_size(const int64_t inputSize) { + (void)this->AddAttr(kInputSize, MakeValue(inputSize)); +} + int64_t DetectionPostProcess::get_input_size() const { auto value_ptr = this->GetAttr(kInputSize); return GetValue(value_ptr); @@ -50,7 +54,7 @@ std::vector DetectionPostProcess::get_scale() const { } void DetectionPostProcess::set_nms_iou_threshold(const float NmsIouThreshold) { - this->AddAttr(kNmsIouThreshold, MakeValue(NmsIouThreshold)); + (void)this->AddAttr(kNmsIouThreshold, MakeValue(NmsIouThreshold)); } float DetectionPostProcess::get_nms_iou_threshold() const { auto value_ptr = this->GetAttr(kNmsIouThreshold); @@ -58,7 +62,7 @@ float DetectionPostProcess::get_nms_iou_threshold() const { } void DetectionPostProcess::set_nms_score_threshold(const float NmsScoreThreshold) { - this->AddAttr(kNmsScoreThreshold, MakeValue(NmsScoreThreshold)); + (void)this->AddAttr(kNmsScoreThreshold, MakeValue(NmsScoreThreshold)); } float DetectionPostProcess::get_nms_score_threshold() const { auto value_ptr = this->GetAttr(kNmsScoreThreshold); @@ -66,12 +70,12 @@ float DetectionPostProcess::get_nms_score_threshold() const { } void DetectionPostProcess::set_max_detections(const int64_t MaxDetections) { - this->AddAttr(kMaxDetections, MakeValue(MaxDetections)); + (void)this->AddAttr(kMaxDetections, MakeValue(MaxDetections)); } int64_t DetectionPostProcess::get_max_detections() const { return GetValue(GetAttr(kMaxDetections)); } void DetectionPostProcess::set_detections_per_class(const int64_t DetectionsPerClass) { - this->AddAttr(kDetectionsPerClass, MakeValue(DetectionsPerClass)); + (void)this->AddAttr(kDetectionsPerClass, MakeValue(DetectionsPerClass)); } int64_t DetectionPostProcess::get_detections_per_class() const { auto value_ptr = this->GetAttr(kDetectionsPerClass); @@ -79,18 +83,18 @@ int64_t DetectionPostProcess::get_detections_per_class() const { } void DetectionPostProcess::set_max_classes_per_detection(const int64_t MaxClassesPerDetection) { - this->AddAttr(kMaxClassesPerDetection, MakeValue(MaxClassesPerDetection)); + (void)this->AddAttr(kMaxClassesPerDetection, MakeValue(MaxClassesPerDetection)); } int64_t DetectionPostProcess::get_max_classes_per_detection() const { return GetValue(GetAttr(kMaxClassesPerDetection)); } void DetectionPostProcess::set_num_classes(const int64_t NumClasses) { - this->AddAttr(kNumClasses, MakeValue(NumClasses)); + (void)this->AddAttr(kNumClasses, MakeValue(NumClasses)); } int64_t DetectionPostProcess::get_num_classes() const { return GetValue(GetAttr(kNumClasses)); } void DetectionPostProcess::set_use_regular_nms(const bool UseRegularNms) { - this->AddAttr(kUseRegularNms, MakeValue(UseRegularNms)); + (void)this->AddAttr(kUseRegularNms, MakeValue(UseRegularNms)); } bool DetectionPostProcess::get_use_regular_nms() const { auto value_ptr = this->GetAttr(kUseRegularNms); @@ -98,7 +102,7 @@ bool DetectionPostProcess::get_use_regular_nms() const { } void DetectionPostProcess::set_out_quantized(const bool OutQuantized) { - this->AddAttr(kOutQuantized, MakeValue(OutQuantized)); + (void)this->AddAttr(kOutQuantized, MakeValue(OutQuantized)); } bool DetectionPostProcess::get_out_quantized() const { auto value_ptr = this->GetAttr(kOutQuantized); @@ -106,7 +110,7 @@ bool DetectionPostProcess::get_out_quantized() const { } void DetectionPostProcess::set_format(const Format &format) { int64_t f = format; - this->AddAttr(kFormat, MakeValue(f)); + (void)this->AddAttr(kFormat, MakeValue(f)); } Format DetectionPostProcess::get_format() const { return Format(GetValue(GetAttr(kFormat))); } AbstractBasePtr DetectionPostProcessInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, diff --git a/mindspore/core/ops/diag.cc b/mindspore/core/ops/diag.cc index 29ead3c0b1c..3cd7308e335 100644 --- a/mindspore/core/ops/diag.cc +++ b/mindspore/core/ops/diag.cc @@ -27,7 +27,7 @@ namespace { abstract::ShapePtr DiagInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - CheckAndConvertUtils::CheckInteger("input rank", input_shape.size(), kGreaterEqual, 1, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("input rank", input_shape.size(), kGreaterEqual, 1, primitive->name()); std::vector out_shape(input_shape); out_shape.insert(out_shape.end(), input_shape.begin(), input_shape.end()); return std::make_shared(out_shape); @@ -43,7 +43,7 @@ AbstractBasePtr DiagInfer(const abstract::AnalysisEnginePtr &, const PrimitivePt const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/diag_part.cc b/mindspore/core/ops/diag_part.cc index 05cb75fed00..741b6269031 100644 --- a/mindspore/core/ops/diag_part.cc +++ b/mindspore/core/ops/diag_part.cc @@ -54,7 +54,7 @@ AbstractBasePtr DiagPartInfer(const abstract::AnalysisEnginePtr &, const Primiti const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/dropout.cc b/mindspore/core/ops/dropout.cc index da2e450ff3d..c2cecc11828 100644 --- a/mindspore/core/ops/dropout.cc +++ b/mindspore/core/ops/dropout.cc @@ -28,7 +28,7 @@ void Dropout::Init(const float keep_prob) { this->set_keep_prob(keep_prob); } void Dropout::set_keep_prob(const float keep_prob) { CheckAndConvertUtils::CheckInRange(kKeepProb, keep_prob, kIncludeRight, {0.0, 1.0}, this->name()); - this->AddAttr(kKeepProb, MakeValue(keep_prob)); + (void)this->AddAttr(kKeepProb, MakeValue(keep_prob)); } float Dropout::get_keep_prob() const { @@ -40,11 +40,11 @@ AbstractBasePtr DropoutInfer(const abstract::AnalysisEnginePtr &, const Primitiv const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("dropout_infer", SizeToLong(input_args.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("dropout_infer", SizeToLong(input_args.size()), kEqual, 1, prim_name); // Infer shape auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("x_shape", SizeToLong(x_shape.size()), kGreaterEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x_shape", SizeToLong(x_shape.size()), kGreaterEqual, 1, prim_name); std::vector out_shape; out_shape.insert(out_shape.end(), x_shape.begin(), x_shape.end()); out_shape.insert(out_shape.end(), x_shape.begin(), x_shape.end()); diff --git a/mindspore/core/ops/dropout_do_mask.cc b/mindspore/core/ops/dropout_do_mask.cc index 2548c92e948..76a3b99d438 100644 --- a/mindspore/core/ops/dropout_do_mask.cc +++ b/mindspore/core/ops/dropout_do_mask.cc @@ -115,7 +115,7 @@ TypePtr InferType(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - CheckAndConvertUtils::CheckInteger("infer shape", input_args.size(), kGreaterEqual, 3, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("infer shape", input_args.size(), kGreaterEqual, 3, primitive->name()); return abstract::MakeAbstract(InferShape(primitive, input_args), InferType(primitive, input_args)); } REGISTER_PRIMITIVE_EVAL_IMPL(DropoutDoMask, prim::kPrimDropoutDoMask, DropoutDoMaskInfer, nullptr, true); diff --git a/mindspore/core/ops/dropout_gen_mask.cc b/mindspore/core/ops/dropout_gen_mask.cc index 5681d4cd862..10f6335b0e4 100644 --- a/mindspore/core/ops/dropout_gen_mask.cc +++ b/mindspore/core/ops/dropout_gen_mask.cc @@ -94,7 +94,7 @@ ShapeVector CalOutputShape(const AbstractBasePtrList shape_list) { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("infer shape", input_args.size(), kGreaterEqual, 2, op_name); + (void)CheckAndConvertUtils::CheckInteger("infer shape", input_args.size(), kGreaterEqual, 2, op_name); AbstractBasePtr shape_args = input_args[0]; MS_EXCEPTION_IF_NULL(shape_args); diff --git a/mindspore/core/ops/dtype.cc b/mindspore/core/ops/dtype.cc index f8f598b182e..399ba7617ac 100644 --- a/mindspore/core/ops/dtype.cc +++ b/mindspore/core/ops/dtype.cc @@ -30,7 +30,7 @@ namespace ops { ValuePtr DTypeInferValue(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("dtype infer", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("dtype infer", input_args.size(), kEqual, 1, op_name); MS_EXCEPTION_IF_NULL(input_args[0]); const std::set valid_types = {kTensorType}; auto type = diff --git a/mindspore/core/ops/eltwise.cc b/mindspore/core/ops/eltwise.cc index cd76e85945b..c9e9421a753 100644 --- a/mindspore/core/ops/eltwise.cc +++ b/mindspore/core/ops/eltwise.cc @@ -23,7 +23,7 @@ namespace ops { void Eltwise::Init(const EltwiseMode &mode) { this->set_mode(mode); } void Eltwise::set_mode(const EltwiseMode &mode) { int64_t m = mode; - this->AddAttr(kMode, MakeValue(m)); + (void)this->AddAttr(kMode, MakeValue(m)); } EltwiseMode Eltwise::get_mode() const { auto value_ptr = this->GetAttr(kMode); diff --git a/mindspore/core/ops/elu.cc b/mindspore/core/ops/elu.cc index 888cbb5854e..8e7f89b4c63 100644 --- a/mindspore/core/ops/elu.cc +++ b/mindspore/core/ops/elu.cc @@ -51,7 +51,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & void Elu::Init(const float alpha) { this->set_alpha(alpha); } void Elu::set_alpha(const float alpha) { - AddAttr(kAlpha, MakeValue(CheckAndConvertUtils::CheckValue(kAlpha, alpha, kEqual, 1.0, name()))); + (void)AddAttr(kAlpha, MakeValue(CheckAndConvertUtils::CheckValue(kAlpha, alpha, kEqual, 1.0, name()))); } float Elu::get_alpha() const { diff --git a/mindspore/core/ops/embedding_lookup.cc b/mindspore/core/ops/embedding_lookup.cc index 5578a6376ea..9d3c69fd757 100644 --- a/mindspore/core/ops/embedding_lookup.cc +++ b/mindspore/core/ops/embedding_lookup.cc @@ -25,7 +25,7 @@ namespace ops { void EmbeddingLookup::Init(const bool setattr_flag) { this->set_setattr_flag(setattr_flag); } void EmbeddingLookup::set_setattr_flag(const bool setattr_flag) { - this->AddAttr(kSetattrFlag, MakeValue(setattr_flag)); + (void)this->AddAttr(kSetattrFlag, MakeValue(setattr_flag)); } bool EmbeddingLookup::get_setattr_flag() const { @@ -37,7 +37,7 @@ AbstractBasePtr EmbeddingLookupInfer(const abstract::AnalysisEnginePtr &, const const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 3, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 3, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/exp.cc b/mindspore/core/ops/exp.cc index 44aec9e1dc5..dd7ad8143ee 100644 --- a/mindspore/core/ops/exp.cc +++ b/mindspore/core/ops/exp.cc @@ -30,7 +30,7 @@ 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); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/expand_dims.cc b/mindspore/core/ops/expand_dims.cc index d37ad15e555..d8c502632ce 100644 --- a/mindspore/core/ops/expand_dims.cc +++ b/mindspore/core/ops/expand_dims.cc @@ -47,10 +47,11 @@ AbstractBasePtr ExpandDimsInfer(const abstract::AnalysisEnginePtr &, const Primi out_shape.insert(out_shape.begin() + dim_val, 1, 1); // Infer type - auto x_type = input_args[0]->BuildType()->cast(); + const int64_t x_index = 0; + auto x_type = CheckAndConvertUtils::GetInputTensorType(input_args, x_index, prim_name); std::set valid_x_type = {kTensorType}; CheckAndConvertUtils::CheckSubClass("x_type", x_type, valid_x_type, prim_name); - return std::make_shared(x_type->element(), out_shape); + return std::make_shared(x_type, out_shape); } REGISTER_PRIMITIVE_C(kNameExpandDims, ExpandDims); } // namespace ops diff --git a/mindspore/core/ops/fake_quant_with_min_max_vars.cc b/mindspore/core/ops/fake_quant_with_min_max_vars.cc index 11b6f409082..6c5fa3e8fd0 100644 --- a/mindspore/core/ops/fake_quant_with_min_max_vars.cc +++ b/mindspore/core/ops/fake_quant_with_min_max_vars.cc @@ -63,7 +63,7 @@ void FakeQuantWithMinMaxVars::Init(const bool narrow_range, const int64_t num_bi } void FakeQuantWithMinMaxVars::set_narrow_range(const bool narrow_range) { - this->AddAttr(kNarrowRange, MakeValue(narrow_range)); + (void)this->AddAttr(kNarrowRange, MakeValue(narrow_range)); } bool FakeQuantWithMinMaxVars::get_narrow_range() const { @@ -71,7 +71,9 @@ bool FakeQuantWithMinMaxVars::get_narrow_range() const { return GetValue(value_ptr); } -void FakeQuantWithMinMaxVars::set_num_bits(const int64_t num_bits) { this->AddAttr(kNumBits, MakeValue(num_bits)); } +void FakeQuantWithMinMaxVars::set_num_bits(const int64_t num_bits) { + (void)this->AddAttr(kNumBits, MakeValue(num_bits)); +} int64_t FakeQuantWithMinMaxVars::get_num_bits() const { auto value_ptr = this->GetAttr(kNumBits); diff --git a/mindspore/core/ops/fake_quant_with_min_max_vars_per_channel.cc b/mindspore/core/ops/fake_quant_with_min_max_vars_per_channel.cc index c712b5fc23b..cd79263c852 100644 --- a/mindspore/core/ops/fake_quant_with_min_max_vars_per_channel.cc +++ b/mindspore/core/ops/fake_quant_with_min_max_vars_per_channel.cc @@ -24,11 +24,11 @@ void FakeQuantWithMinMaxVarsPerChannel::Init(const int64_t num_bits, const bool this->set_narrow_range(narrow_range); } void FakeQuantWithMinMaxVarsPerChannel::set_num_bits(const int64_t num_bits) { - CheckAndConvertUtils::CheckInteger(kNumBits, num_bits, kGreaterThan, 0, this->name()); - this->AddAttr(kNumBits, MakeValue(num_bits)); + (void)CheckAndConvertUtils::CheckInteger(kNumBits, num_bits, kGreaterThan, 0, this->name()); + (void)this->AddAttr(kNumBits, MakeValue(num_bits)); } void FakeQuantWithMinMaxVarsPerChannel::set_narrow_range(const bool narrow_range) { - this->AddAttr(kNarrowRange, MakeValue(narrow_range)); + (void)this->AddAttr(kNarrowRange, MakeValue(narrow_range)); } int64_t FakeQuantWithMinMaxVarsPerChannel::get_num_bits() const { auto value_ptr = GetAttr(kNumBits); @@ -47,9 +47,9 @@ AbstractBasePtr FakeQuantWithMinMaxVarsPerChannelInfer(const abstract::AnalysisE auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; auto min_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; auto max_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[2]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("x rank", (int64_t)x_shape.size(), kGreaterThan, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("x rank", (int64_t)x_shape.size(), kGreaterThan, 1, op_name); CheckAndConvertUtils::Check("min shape", min_shape, kEqual, "max shape", max_shape, op_name); - CheckAndConvertUtils::CheckInteger("min shape", (int64_t)min_shape.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("min shape", (int64_t)min_shape.size(), kEqual, 1, op_name); CheckAndConvertUtils::Check("min shape", min_shape[0], kEqual, "x shape", x_shape[x_shape.size() - 1], op_name); auto x_type = input_args[0]->BuildType(); diff --git a/mindspore/core/ops/fft_imag.cc b/mindspore/core/ops/fft_imag.cc index 70c2959963d..cb5ebd07a7f 100644 --- a/mindspore/core/ops/fft_imag.cc +++ b/mindspore/core/ops/fft_imag.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,25 +23,18 @@ namespace mindspore { namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; in_shape.pop_back(); return std::make_shared(in_shape); } - -TypePtr InferType(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - return kFloat32; -} } // namespace AbstractBasePtr FftImagInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { - return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); + return std::make_shared(kFloat32, InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameFftImag, FftImag); } // namespace ops diff --git a/mindspore/core/ops/fill.cc b/mindspore/core/ops/fill.cc index 2eef2b63e39..5272c217754 100644 --- a/mindspore/core/ops/fill.cc +++ b/mindspore/core/ops/fill.cc @@ -45,6 +45,7 @@ AbstractBasePtr FillInfer(const abstract::AnalysisEnginePtr &, const PrimitivePt auto x_value = input_args[2]->BuildValue(); auto abs = std::make_shared(dtype, std::make_shared(out_shape)); tensor::TensorPtr tensor = std::make_shared(x_type_id, out_shape); + MS_EXCEPTION_IF_NULL(tensor); auto mem_size = IntToSize(tensor->ElementsNum()); if (x_type_id == kNumberTypeInt) { auto int_value = GetValue(x_value); diff --git a/mindspore/core/ops/floor.cc b/mindspore/core/ops/floor.cc index 3608e3e9822..1f4220e35fe 100644 --- a/mindspore/core/ops/floor.cc +++ b/mindspore/core/ops/floor.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,19 +27,12 @@ namespace mindspore { namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; return std::make_shared(in_shape); } TypePtr InferType(const PrimitivePtr &prim, const std::vector &input_args) { const std::set valid_types = {kFloat16, kFloat32, kFloat64}; - if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr &a) { return a == nullptr; })) { - MS_LOG(EXCEPTION) << "nullptr"; - } std::map types; types.emplace("x", input_args[0]->BuildType()); return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name()); @@ -47,8 +40,11 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & } // namespace AbstractBasePtr FloorInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameFloor, Floor); } // namespace ops diff --git a/mindspore/core/ops/fusion/activation.cc b/mindspore/core/ops/fusion/activation.cc index 83c250af065..7e0673e4f56 100644 --- a/mindspore/core/ops/fusion/activation.cc +++ b/mindspore/core/ops/fusion/activation.cc @@ -54,7 +54,7 @@ ActivationType Activation::get_activation_type() const { return ActivationType(GetValue(value_ptr)); } -void Activation::set_approximate(bool approximate) { this->AddAttr(kApproximate, MakeValue(approximate)); } +void Activation::set_approximate(bool approximate) { (void)this->AddAttr(kApproximate, MakeValue(approximate)); } bool Activation::get_approximate() const { auto value_ptr = this->GetAttr(kApproximate); diff --git a/mindspore/core/ops/fusion/add_fusion.cc b/mindspore/core/ops/fusion/add_fusion.cc index b510a5c3e4f..c2b82b81043 100644 --- a/mindspore/core/ops/fusion/add_fusion.cc +++ b/mindspore/core/ops/fusion/add_fusion.cc @@ -56,7 +56,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr AddFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameAddFusion, AddFusion); } // namespace ops diff --git a/mindspore/core/ops/fusion/avg_pool_fusion.cc b/mindspore/core/ops/fusion/avg_pool_fusion.cc index ce6535b6136..1350a3d4990 100644 --- a/mindspore/core/ops/fusion/avg_pool_fusion.cc +++ b/mindspore/core/ops/fusion/avg_pool_fusion.cc @@ -70,8 +70,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(ceil((in_h - (kernel_h - 1)) / static_cast(stride_h))); out_w = static_cast(ceil((in_w - (kernel_w - 1)) / static_cast(stride_w))); @@ -100,7 +100,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr AvgPoolFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameAvgPoolFusion, AvgPoolFusion); } // namespace ops diff --git a/mindspore/core/ops/fusion/max_pool_fusion.cc b/mindspore/core/ops/fusion/max_pool_fusion.cc index 9aafcb1391c..029d99ff299 100644 --- a/mindspore/core/ops/fusion/max_pool_fusion.cc +++ b/mindspore/core/ops/fusion/max_pool_fusion.cc @@ -70,8 +70,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(ceil((in_h - (kernel_h - 1)) / static_cast(stride_h))); out_w = static_cast(ceil((in_w - (kernel_w - 1)) / static_cast(stride_w))); @@ -100,7 +100,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr MaxPoolFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameMaxPoolFusion, MaxPoolFusion); } // namespace ops diff --git a/mindspore/core/ops/fusion/pow_fusion.cc b/mindspore/core/ops/fusion/pow_fusion.cc index 4a8abdd8122..a72836cc436 100644 --- a/mindspore/core/ops/fusion/pow_fusion.cc +++ b/mindspore/core/ops/fusion/pow_fusion.cc @@ -55,7 +55,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr PowFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNamePowFusion, PowFusion); } // namespace ops diff --git a/mindspore/core/ops/glu.cc b/mindspore/core/ops/glu.cc index 4d5702660be..07dcfdcce29 100644 --- a/mindspore/core/ops/glu.cc +++ b/mindspore/core/ops/glu.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace ops { void GLU::Init(int64_t axis) { set_axis(axis); } -void GLU::set_axis(int64_t axis) { AddAttr(kAxis, MakeValue(axis)); } +void GLU::set_axis(int64_t axis) { (void)AddAttr(kAxis, MakeValue(axis)); } int64_t GLU::get_axis() const { auto value_ptr = GetAttr(kAxis); diff --git a/mindspore/core/ops/grad/avg_pool_3d_grad.cc b/mindspore/core/ops/grad/avg_pool_3d_grad.cc index 5a7dec4634b..15f99c51be5 100644 --- a/mindspore/core/ops/grad/avg_pool_3d_grad.cc +++ b/mindspore/core/ops/grad/avg_pool_3d_grad.cc @@ -30,12 +30,12 @@ constexpr size_t k5DInputDims = 5; abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 2, op_name); + (void)CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 2, op_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } auto grad_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->GetShapeTrack())[kShape]; - CheckAndConvertUtils::CheckInteger("grad_rank", grad_shape.size(), kEqual, k5DInputDims, op_name); + (void)CheckAndConvertUtils::CheckInteger("grad_rank", grad_shape.size(), kEqual, k5DInputDims, op_name); std::vector origin_input_size; if (input_args[0]->isa()) { // origin_size is tuple origin_input_size = GetValue>(input_args[0]->BuildValue()); @@ -48,7 +48,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 2, op_name); + (void)CheckAndConvertUtils::CheckInteger("input size", input_args.size(), kEqual, 2, op_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/grad/batch_norm_grad.cc b/mindspore/core/ops/grad/batch_norm_grad.cc index 34bf4b0741e..b427489a998 100644 --- a/mindspore/core/ops/grad/batch_norm_grad.cc +++ b/mindspore/core/ops/grad/batch_norm_grad.cc @@ -34,7 +34,9 @@ float BatchNormGrad::get_epsilon() const { return GetValue(value_ptr); } -void BatchNormGrad::set_is_training(const bool is_training) { this->AddAttr(kIsTraining, MakeValue(is_training)); } +void BatchNormGrad::set_is_training(const bool is_training) { + (void)this->AddAttr(kIsTraining, MakeValue(is_training)); +} bool BatchNormGrad::get_is_training() const { auto value_ptr = this->GetAttr(kIsTraining); diff --git a/mindspore/core/ops/grad/binary_cross_entropy_grad.cc b/mindspore/core/ops/grad/binary_cross_entropy_grad.cc index c2384cccd17..ba498911386 100644 --- a/mindspore/core/ops/grad/binary_cross_entropy_grad.cc +++ b/mindspore/core/ops/grad/binary_cross_entropy_grad.cc @@ -68,7 +68,7 @@ Reduction BinaryCrossEntropyGrad::get_reduction() const { AbstractBasePtr BinaryCrossEntropyGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(BinaryCrossEntroyGradInferType(primitive, input_args), - BinaryCrossEntroyGradInferShape(primitive, input_args)->shape()); + BinaryCrossEntroyGradInferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameBinaryCrossEntropyGrad, BinaryCrossEntropyGrad); } // namespace ops diff --git a/mindspore/core/ops/grad/conv2d_backprop_filter.cc b/mindspore/core/ops/grad/conv2d_backprop_filter.cc index 428581d51bb..2d3f57e0cea 100644 --- a/mindspore/core/ops/grad/conv2d_backprop_filter.cc +++ b/mindspore/core/ops/grad/conv2d_backprop_filter.cc @@ -109,7 +109,9 @@ int64_t Conv2DBackpropFilter::get_mode() const { return GetValue(value_ptr); } -void Conv2DBackpropFilter::set_stride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } +void Conv2DBackpropFilter::set_stride(const std::vector &stride) { + (void)this->AddAttr(kStride, MakeValue(stride)); +} std::vector Conv2DBackpropFilter::get_stride() const { auto value_ptr = GetAttr(kStride); @@ -117,7 +119,7 @@ std::vector Conv2DBackpropFilter::get_stride() const { } void Conv2DBackpropFilter::set_dilation(const std::vector &dilation) { - this->AddAttr(kDilation, MakeValue(dilation)); + (void)this->AddAttr(kDilation, MakeValue(dilation)); } std::vector Conv2DBackpropFilter::get_dilation() const { @@ -134,7 +136,7 @@ int64_t Conv2DBackpropFilter::get_group() const { void Conv2DBackpropFilter::set_format(const Format &format) { int64_t swi = format; - this->AddAttr(kFormat, MakeValue(swi)); + (void)this->AddAttr(kFormat, MakeValue(swi)); } Format Conv2DBackpropFilter::get_format() const { @@ -152,7 +154,7 @@ AbstractBasePtr Conv2DBackpropFilterInfer(const abstract::AnalysisEnginePtr &, c MS_EXCEPTION_IF_NULL(item); } return std::make_shared(Conv2DBackpropFilterInferType(primitive, input_args), - Conv2DBackpropFilterInferShape(primitive, input_args)->shape()); + Conv2DBackpropFilterInferShape(primitive, input_args)); } REGISTER_PRIMITIVE_EVAL_IMPL(Conv2DBackpropFilter, prim::kPrimConv2DBackpropFilter, Conv2DBackpropFilterInfer, nullptr, true); diff --git a/mindspore/core/ops/grad/dropout_grad.cc b/mindspore/core/ops/grad/dropout_grad.cc index f9ebc951d4b..da3d359bd32 100644 --- a/mindspore/core/ops/grad/dropout_grad.cc +++ b/mindspore/core/ops/grad/dropout_grad.cc @@ -56,7 +56,7 @@ TypePtr DropoutGradInferType(const PrimitivePtr &prim, const std::vector &input_args) { return std::make_shared(DropoutGradInferType(primitive, input_args), - DropoutGradInferShape(primitive, input_args)->shape()); + DropoutGradInferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameDropoutGrad, DropoutGrad); } // namespace ops diff --git a/mindspore/core/ops/grad/group_conv2d_grad_input.cc b/mindspore/core/ops/grad/group_conv2d_grad_input.cc index 7bf56c2db05..66b1d2b6574 100644 --- a/mindspore/core/ops/grad/group_conv2d_grad_input.cc +++ b/mindspore/core/ops/grad/group_conv2d_grad_input.cc @@ -41,7 +41,7 @@ void GroupConv2DGradInput::Init(const int64_t &in_channel, const int64_t &out_ch } void GroupConv2DGradInput::set_in_channel(const int64_t &in_channel) { - this->AddAttr(kInChannel, MakeValue(in_channel)); + (void)this->AddAttr(kInChannel, MakeValue(in_channel)); } int64_t GroupConv2DGradInput::get_in_channel() const { @@ -50,7 +50,7 @@ int64_t GroupConv2DGradInput::get_in_channel() const { } void GroupConv2DGradInput::set_out_channel(const int64_t &out_channel) { - this->AddAttr(kOutChannel, MakeValue(out_channel)); + (void)this->AddAttr(kOutChannel, MakeValue(out_channel)); } int64_t GroupConv2DGradInput::get_out_channel() const { @@ -59,7 +59,7 @@ int64_t GroupConv2DGradInput::get_out_channel() const { } void GroupConv2DGradInput::set_kernel_size(const std::vector &kernel_size) { - this->AddAttr(kKernelSize, MakeValue(kernel_size)); + (void)this->AddAttr(kKernelSize, MakeValue(kernel_size)); } std::vector GroupConv2DGradInput::get_kernel_size() const { @@ -69,7 +69,7 @@ std::vector GroupConv2DGradInput::get_kernel_size() const { void GroupConv2DGradInput::set_pad_mode(const PadMode &pad_mode) { int64_t swi = pad_mode; - this->AddAttr(kPadMode, MakeValue(swi)); + (void)this->AddAttr(kPadMode, MakeValue(swi)); } PadMode GroupConv2DGradInput::get_pad_mode() const { @@ -78,7 +78,7 @@ PadMode GroupConv2DGradInput::get_pad_mode() const { } void GroupConv2DGradInput::set_pad_list(const std::vector &pad_list) { - this->AddAttr(kPadList, MakeValue(pad_list)); + (void)this->AddAttr(kPadList, MakeValue(pad_list)); } std::vector GroupConv2DGradInput::get_pad_list() const { @@ -86,7 +86,9 @@ std::vector GroupConv2DGradInput::get_pad_list() const { return GetValue>(value_ptr); } -void GroupConv2DGradInput::set_stride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } +void GroupConv2DGradInput::set_stride(const std::vector &stride) { + (void)this->AddAttr(kStride, MakeValue(stride)); +} std::vector GroupConv2DGradInput::get_stride() const { auto value_ptr = GetAttr(kStride); @@ -94,7 +96,7 @@ std::vector GroupConv2DGradInput::get_stride() const { } void GroupConv2DGradInput::set_dilation(const std::vector &dilation) { - this->AddAttr(kDilation, MakeValue(dilation)); + (void)this->AddAttr(kDilation, MakeValue(dilation)); } std::vector GroupConv2DGradInput::get_dilation() const { @@ -110,7 +112,7 @@ int64_t GroupConv2DGradInput::get_group() const { } void GroupConv2DGradInput::set_input_shape(const std::vector &input_shape) { - this->AddAttr(kInputShape, MakeValue(input_shape)); + (void)this->AddAttr(kInputShape, MakeValue(input_shape)); } std::vector GroupConv2DGradInput::get_input_shape() const { @@ -119,7 +121,7 @@ std::vector GroupConv2DGradInput::get_input_shape() const { void GroupConv2DGradInput::set_format(const Format &format) { int64_t swi = format; - this->AddAttr(kFormat, MakeValue(swi)); + (void)this->AddAttr(kFormat, MakeValue(swi)); } Format GroupConv2DGradInput::get_format() const { @@ -129,7 +131,7 @@ Format GroupConv2DGradInput::get_format() const { void GroupConv2DGradInput::set_activation_type(const ActivationType &activation_type) { int64_t swi = activation_type; - this->AddAttr(kActivationType, MakeValue(swi)); + (void)this->AddAttr(kActivationType, MakeValue(swi)); } ActivationType GroupConv2DGradInput::get_activation_type() const { diff --git a/mindspore/core/ops/grad/hsigmoid_grad.cc b/mindspore/core/ops/grad/hsigmoid_grad.cc index 657e99a1037..9aa7a9d5012 100644 --- a/mindspore/core/ops/grad/hsigmoid_grad.cc +++ b/mindspore/core/ops/grad/hsigmoid_grad.cc @@ -32,7 +32,7 @@ namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, primitive->name()); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -45,7 +45,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, prim->name()); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, prim->name()); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/grad/pool_grad.cc b/mindspore/core/ops/grad/pool_grad.cc index 59499c45e79..60e3ff92f8d 100644 --- a/mindspore/core/ops/grad/pool_grad.cc +++ b/mindspore/core/ops/grad/pool_grad.cc @@ -56,22 +56,22 @@ void PoolGrad::Init(const std::vector &kernel_size, const std::vector &kernel_size) { std::vector k_size = _grad_check_vector(kKernelSize, kernel_size, this->name()); - this->AddAttr(kKernelSize, MakeValue(k_size)); + (void)this->AddAttr(kKernelSize, MakeValue(k_size)); } void PoolGrad::set_strides(const std::vector &strides) { std::vector strides_ = _grad_check_vector(kStrides, strides, this->name()); - this->AddAttr(kStrides, MakeValue(strides_)); + (void)this->AddAttr(kStrides, MakeValue(strides_)); } void PoolGrad::set_pad_mode(const PadMode &pad_mode) { int64_t swi = pad_mode; - this->AddAttr(kPadMode, MakeValue(swi)); + (void)this->AddAttr(kPadMode, MakeValue(swi)); } void PoolGrad::set_format(const Format &format) { int64_t swi = format; - this->AddAttr(kFormat, MakeValue(swi)); + (void)this->AddAttr(kFormat, MakeValue(swi)); } std::vector PoolGrad::get_kernel_size() const { diff --git a/mindspore/core/ops/grad/pooling_grad.cc b/mindspore/core/ops/grad/pooling_grad.cc index a9664ca16fc..7f39ca95f48 100644 --- a/mindspore/core/ops/grad/pooling_grad.cc +++ b/mindspore/core/ops/grad/pooling_grad.cc @@ -35,7 +35,7 @@ void PoolingGrad::Init(const PoolMode &pool_mode, const std::vector &wi void PoolingGrad::set_pool_mode(const PoolMode &pool_mode) { int64_t swi = pool_mode; - this->AddAttr(kPoolMode, MakeValue(swi)); + (void)this->AddAttr(kPoolMode, MakeValue(swi)); } PoolMode PoolingGrad::get_pool_mode() const { @@ -59,7 +59,7 @@ std::vector PoolingGrad::get_stride() const { void PoolingGrad::set_pad_mode(const PadMode &pad_mode) { int64_t swi = pad_mode; - this->AddAttr(kPadMode, MakeValue(swi)); + (void)this->AddAttr(kPadMode, MakeValue(swi)); } PadMode PoolingGrad::get_pad_mode() const { @@ -67,7 +67,9 @@ PadMode PoolingGrad::get_pad_mode() const { return PadMode(GetValue(value_ptr)); } -void PoolingGrad::set_pad_list(const std::vector &pad_list) { this->AddAttr(kPadList, MakeValue(pad_list)); } +void PoolingGrad::set_pad_list(const std::vector &pad_list) { + (void)this->AddAttr(kPadList, MakeValue(pad_list)); +} std::vector PoolingGrad::get_pad_list() const { auto value_ptr = GetAttr(kPadList); @@ -76,7 +78,7 @@ std::vector PoolingGrad::get_pad_list() const { void PoolingGrad::set_round_mode(const RoundMode &round_mode) { int64_t swi = round_mode; - this->AddAttr(kRoundMode, MakeValue(swi)); + (void)this->AddAttr(kRoundMode, MakeValue(swi)); } RoundMode PoolingGrad::get_round_mode() const { @@ -86,7 +88,7 @@ RoundMode PoolingGrad::get_round_mode() const { void PoolingGrad::set_format(const Format &format) { int64_t swi = format; - this->AddAttr(kFormat, MakeValue(swi)); + (void)this->AddAttr(kFormat, MakeValue(swi)); } Format PoolingGrad::get_format() const { diff --git a/mindspore/core/ops/grad/relu_grad.cc b/mindspore/core/ops/grad/relu_grad.cc index 27a86619ca4..0ddf7e61d64 100644 --- a/mindspore/core/ops/grad/relu_grad.cc +++ b/mindspore/core/ops/grad/relu_grad.cc @@ -30,7 +30,7 @@ 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, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -47,7 +47,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto prim_name = prim->name(); - CheckAndConvertUtils::CheckInteger("ReLUGrad infer", SizeToLong(input_args.size()), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("ReLUGrad infer", SizeToLong(input_args.size()), kEqual, 2, prim_name); MS_EXCEPTION_IF_NULL(input_args[0]); auto dout = CheckAndConvertUtils::CheckArgs(prim_name, input_args, 0); auto out = CheckAndConvertUtils::CheckArgs(prim_name, input_args, 1); diff --git a/mindspore/core/ops/grad/relu_grad_v2.cc b/mindspore/core/ops/grad/relu_grad_v2.cc index 9f577d05ca9..395c56fe635 100644 --- a/mindspore/core/ops/grad/relu_grad_v2.cc +++ b/mindspore/core/ops/grad/relu_grad_v2.cc @@ -30,7 +30,7 @@ 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, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -43,7 +43,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto prim_name = prim->name(); - CheckAndConvertUtils::CheckInteger("ReLUGradV2 infer", input_args.size(), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("ReLUGradV2 infer", input_args.size(), kEqual, 2, prim_name); MS_EXCEPTION_IF_NULL(input_args[0]); auto x_type_map = input_args[0]->BuildType(); MS_EXCEPTION_IF_NULL(x_type_map); diff --git a/mindspore/core/ops/grad/soft_shrink_grad.cc b/mindspore/core/ops/grad/soft_shrink_grad.cc index 52508fab8e3..4317b689cb9 100644 --- a/mindspore/core/ops/grad/soft_shrink_grad.cc +++ b/mindspore/core/ops/grad/soft_shrink_grad.cc @@ -32,7 +32,7 @@ namespace { abstract::ShapePtr SoftShrinkGradInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 2, primitive->name()); auto input_grad_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; auto input_x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; auto prim_name = primitive->name(); diff --git a/mindspore/core/ops/hashtable_lookup.cc b/mindspore/core/ops/hashtable_lookup.cc index 883067296f5..e9231d284b0 100644 --- a/mindspore/core/ops/hashtable_lookup.cc +++ b/mindspore/core/ops/hashtable_lookup.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,14 +24,16 @@ namespace ops { AbstractBasePtr HashtableLookupInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - for (auto input : input_args) { - MS_EXCEPTION_IF_NULL(input); - } + const int64_t input_num = 3; + auto op_name = primitive->name(); + CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, op_name); std::vector hits_shape; auto input = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; + (void)CheckAndConvertUtils::CheckInteger("logits size", SizeToLong(input.size()), kGreaterEqual, 1, op_name); hits_shape.push_back(input[0]); auto value_type = input_args[2]->BuildType(); + MS_EXCEPTION_IF_NULL(value_type); auto tensor_type = value_type->cast(); MS_EXCEPTION_IF_NULL(tensor_type); auto data_type = tensor_type->element(); @@ -39,10 +41,6 @@ AbstractBasePtr HashtableLookupInfer(const abstract::AnalysisEnginePtr &, const auto output = std::make_shared(data_type, value_shape); auto hits = std::make_shared(kInt8, hits_shape); AbstractBasePtrList output1 = {output, hits}; - - if (input_args[0]->BuildValue()->cast()->data_c() == nullptr) { - MS_LOG(INFO) << "Do infer shape in runtime."; - } return std::make_shared(output1); } REGISTER_PRIMITIVE_C(kNameHashtableLookup, HashtableLookup); diff --git a/mindspore/core/ops/instance_norm.cc b/mindspore/core/ops/instance_norm.cc index 83d4fc96ca1..bb2bb111165 100644 --- a/mindspore/core/ops/instance_norm.cc +++ b/mindspore/core/ops/instance_norm.cc @@ -28,7 +28,7 @@ namespace mindspore { namespace ops { void InstanceNorm::Init(const float epsilon) { this->set_epsilon(epsilon); } -void InstanceNorm::set_epsilon(const float epsilon) { this->AddAttr(kEpsilon, MakeValue(epsilon)); } +void InstanceNorm::set_epsilon(const float epsilon) { (void)this->AddAttr(kEpsilon, MakeValue(epsilon)); } float InstanceNorm::get_epsilon() const { auto value_ptr = GetAttr(kEpsilon); return GetValue(value_ptr); diff --git a/mindspore/core/ops/l2_normalize.cc b/mindspore/core/ops/l2_normalize.cc index 86cd5e9405b..c35000b12ec 100644 --- a/mindspore/core/ops/l2_normalize.cc +++ b/mindspore/core/ops/l2_normalize.cc @@ -25,9 +25,9 @@ void L2Normalize::Init(const std::vector &axis, const float epsilon) { this->set_epsilon(epsilon); } -void L2Normalize::set_axis(const std::vector &axis) { AddAttr(kAxis, MakeValue(axis)); } +void L2Normalize::set_axis(const std::vector &axis) { (void)AddAttr(kAxis, MakeValue(axis)); } -void L2Normalize::set_epsilon(const float epsilon) { AddAttr(kEpsilon, MakeValue(epsilon)); } +void L2Normalize::set_epsilon(const float epsilon) { (void)AddAttr(kEpsilon, MakeValue(epsilon)); } std::vector L2Normalize::get_axis() const { return GetValue>(GetAttr(kAxis)); } @@ -40,7 +40,7 @@ AbstractBasePtr L2NormalizeInfer(const abstract::AnalysisEnginePtr &, const Prim const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/layer_norm.cc b/mindspore/core/ops/layer_norm.cc index f5590647fad..8f04263c69a 100644 --- a/mindspore/core/ops/layer_norm.cc +++ b/mindspore/core/ops/layer_norm.cc @@ -41,12 +41,18 @@ AbstractBasePtr LayerNormInfer(const abstract::AnalysisEnginePtr &, const Primit // outputs: y, mean, variance MS_EXCEPTION_IF_NULL(primitive); const std::string op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 3, op_name); - auto input_x = CheckAndConvertUtils::CheckArgs(op_name, input_args, 0); - auto gamma = CheckAndConvertUtils::CheckArgs(op_name, input_args, 1); - auto beta = CheckAndConvertUtils::CheckArgs(op_name, input_args, 2); + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 3; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, op_name); + const int64_t x_index = 0; + const int64_t gamma_index = 1; + const int64_t beta_index = 2; + auto input_x = CheckAndConvertUtils::CheckArgs(op_name, input_args, x_index); + auto gamma = CheckAndConvertUtils::CheckArgs(op_name, input_args, gamma_index); + auto beta = CheckAndConvertUtils::CheckArgs(op_name, input_args, beta_index); auto input_shape = input_x->shape(); + MS_EXCEPTION_IF_NULL(input_shape); auto const &input_shape_list = input_shape->shape(); const size_t input_rank = input_shape_list.size(); if (input_rank == 0) { @@ -63,9 +69,11 @@ AbstractBasePtr LayerNormInfer(const abstract::AnalysisEnginePtr &, const Primit // the beta and gama shape should be x_shape[begin_params_axis:] auto valid_types = {kFloat16, kFloat32}; - (void)CheckAndConvertUtils::CheckTensorTypeValid("x_dtype", input_args[0]->BuildType(), valid_types, op_name); - (void)CheckAndConvertUtils::CheckTensorTypeValid("gamma_dtype", input_args[1]->BuildType(), valid_types, op_name); - (void)CheckAndConvertUtils::CheckTensorTypeValid("beta_dtype", input_args[2]->BuildType(), valid_types, op_name); + (void)CheckAndConvertUtils::CheckTensorTypeValid("x_dtype", input_args[x_index]->BuildType(), valid_types, op_name); + (void)CheckAndConvertUtils::CheckTensorTypeValid("gamma_dtype", input_args[gamma_index]->BuildType(), valid_types, + op_name); + (void)CheckAndConvertUtils::CheckTensorTypeValid("beta_dtype", input_args[beta_index]->BuildType(), valid_types, + op_name); auto gamma_shape = dyn_cast(gamma->BuildShape()); auto beta_shape = dyn_cast(beta->BuildShape()); @@ -119,12 +127,12 @@ void LayerNorm::Init(const int64_t begin_norm_axis, const int64_t begin_params_a this->set_epsilon(epsilon); } void LayerNorm::set_begin_norm_axis(const int64_t begin_norm_axis) { - this->AddAttr(kBeginNormAxis, MakeValue(begin_norm_axis)); + (void)this->AddAttr(kBeginNormAxis, MakeValue(begin_norm_axis)); } void LayerNorm::set_begin_params_axis(const int64_t begin_params_axis) { - this->AddAttr(kBeginParamsAxis, MakeValue(begin_params_axis)); + (void)this->AddAttr(kBeginParamsAxis, MakeValue(begin_params_axis)); } -void LayerNorm::set_epsilon(const float epsilon) { this->AddAttr(kEpsilon, MakeValue(epsilon)); } +void LayerNorm::set_epsilon(const float epsilon) { (void)this->AddAttr(kEpsilon, MakeValue(epsilon)); } int64_t LayerNorm::get_begin_norm_axis() const { auto value_ptr = this->GetAttr(kBeginNormAxis); diff --git a/mindspore/core/ops/leaky_relu.cc b/mindspore/core/ops/leaky_relu.cc index b5750329844..e64c63b8461 100644 --- a/mindspore/core/ops/leaky_relu.cc +++ b/mindspore/core/ops/leaky_relu.cc @@ -41,7 +41,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & void LeakyRelu::Init(const float negative_slope) { this->set_negative_slope(negative_slope); } void LeakyRelu::set_negative_slope(const float negative_slope) { - this->AddAttr(kNegativeSlope, MakeValue(negative_slope)); + (void)this->AddAttr(kNegativeSlope, MakeValue(negative_slope)); } float LeakyRelu::get_negative_slope() const { return GetValue(GetAttr(kNegativeSlope)); } diff --git a/mindspore/core/ops/log_softmax.cc b/mindspore/core/ops/log_softmax.cc index 41784ea3a88..c3ea162774d 100644 --- a/mindspore/core/ops/log_softmax.cc +++ b/mindspore/core/ops/log_softmax.cc @@ -26,7 +26,7 @@ namespace mindspore { namespace ops { -void LogSoftmax::set_axis(const int64_t axis) { this->AddAttr(kAxis, MakeValue(axis)); } +void LogSoftmax::set_axis(const int64_t axis) { (void)this->AddAttr(kAxis, MakeValue(axis)); } int64_t LogSoftmax::get_axis() const { return GetValue(GetAttr(kAxis)); } @@ -36,7 +36,7 @@ abstract::ShapePtr LogSoftmaxInferShape(const PrimitivePtr &primitive, const std MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); auto axis = GetValue(primitive->GetAttr(kAxis)); - CheckAndConvertUtils::CheckInteger("log_softmax infer", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("log_softmax infer", input_args.size(), kEqual, 1, op_name); MS_EXCEPTION_IF_NULL(input_args[0]); auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape()); if (shape_map.empty()) { @@ -57,7 +57,7 @@ abstract::ShapePtr LogSoftmaxInferShape(const PrimitivePtr &primitive, const std TypePtr LogSoftmaxInferType(const PrimitivePtr &prim, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto op_name = prim->name(); - CheckAndConvertUtils::CheckInteger("log_softmax infer", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("log_softmax infer", input_args.size(), kEqual, 1, op_name); MS_EXCEPTION_IF_NULL(input_args[0]); const std::set valid_types = {kFloat16, kFloat32}; return CheckAndConvertUtils::CheckTensorTypeValid("x", input_args[0]->BuildType(), valid_types, op_name); diff --git a/mindspore/core/ops/logical_or.cc b/mindspore/core/ops/logical_or.cc index 732ad342ade..6e7aa0f7bb1 100644 --- a/mindspore/core/ops/logical_or.cc +++ b/mindspore/core/ops/logical_or.cc @@ -34,9 +34,6 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } std::map types; const std::set valid_types = {kBool}; types.emplace("x", input_args[0]->BuildType()); @@ -47,8 +44,11 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr LogicalOrInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 2; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameLogicalOr, LogicalOr); } // namespace ops diff --git a/mindspore/core/ops/lp_normalization.cc b/mindspore/core/ops/lp_normalization.cc index 935b88bf411..c9214f01dd6 100644 --- a/mindspore/core/ops/lp_normalization.cc +++ b/mindspore/core/ops/lp_normalization.cc @@ -25,14 +25,14 @@ void LpNormalization::Init(const int64_t axis, const int64_t p) { this->set_p(p); } -void LpNormalization::set_axis(const int64_t axis) { this->AddAttr(kAxis, MakeValue(axis)); } +void LpNormalization::set_axis(const int64_t axis) { (void)this->AddAttr(kAxis, MakeValue(axis)); } int64_t LpNormalization::get_axis() const { auto value_ptr = this->GetAttr(kAxis); return GetValue(value_ptr); } -void LpNormalization::set_p(const int64_t p) { this->AddAttr(kP, MakeValue(p)); } +void LpNormalization::set_p(const int64_t p) { (void)this->AddAttr(kP, MakeValue(p)); } int64_t LpNormalization::get_p() const { auto value_ptr = this->GetAttr(kP); diff --git a/mindspore/core/ops/lrn.cc b/mindspore/core/ops/lrn.cc index c498d4666bf..d7025310d65 100644 --- a/mindspore/core/ops/lrn.cc +++ b/mindspore/core/ops/lrn.cc @@ -28,7 +28,7 @@ namespace mindspore { namespace ops { void LRN::set_depth_radius(const int64_t depth_radius) { (void)CheckAndConvertUtils::CheckInteger(kDepthRadius, depth_radius, kGreaterEqual, 0, this->name()); - this->AddAttr(kDepthRadius, MakeValue(depth_radius)); + (void)this->AddAttr(kDepthRadius, MakeValue(depth_radius)); } int64_t LRN::get_depth_radius() const { @@ -36,21 +36,21 @@ int64_t LRN::get_depth_radius() const { return GetValue(value_ptr); } -void LRN::set_bias(const float bias) { this->AddAttr(kBias, MakeValue(bias)); } +void LRN::set_bias(const float bias) { (void)this->AddAttr(kBias, MakeValue(bias)); } float LRN::get_bias() const { auto value_ptr = GetAttr(kBias); return GetValue(value_ptr); } -void LRN::set_alpha(const float alpha) { this->AddAttr(kAlpha, MakeValue(alpha)); } +void LRN::set_alpha(const float alpha) { (void)this->AddAttr(kAlpha, MakeValue(alpha)); } float LRN::get_alpha() const { auto value_ptr = GetAttr(kAlpha); return GetValue(value_ptr); } -void LRN::set_beta(const float beta) { this->AddAttr(kBeta, MakeValue(beta)); } +void LRN::set_beta(const float beta) { (void)this->AddAttr(kBeta, MakeValue(beta)); } float LRN::get_beta() const { auto value_ptr = GetAttr(kBeta); @@ -58,7 +58,7 @@ float LRN::get_beta() const { } void LRN::set_norm_region(const std::string &norm_region) { CheckAndConvertUtils::CheckString(kNormRegion, norm_region, {"ACROSS_CHANNELS"}, this->name()); - this->AddAttr(kNormRegion, MakeValue(norm_region)); + (void)this->AddAttr(kNormRegion, MakeValue(norm_region)); } std::string LRN::get_norm_region() const { diff --git a/mindspore/core/ops/lsh_projection.cc b/mindspore/core/ops/lsh_projection.cc index 3f3670ec64c..04a0270f958 100644 --- a/mindspore/core/ops/lsh_projection.cc +++ b/mindspore/core/ops/lsh_projection.cc @@ -23,7 +23,7 @@ void LshProjection::Init(const LshProjectionType &type) { set_type(type); } void LshProjection::set_type(const LshProjectionType &type) { int64_t swi = (int64_t)type; - AddAttr(kType, MakeValue(swi)); + (void)AddAttr(kType, MakeValue(swi)); } LshProjectionType LshProjection::get_type() const { return LshProjectionType(GetValue(GetAttr(kType))); } @@ -32,15 +32,17 @@ AbstractBasePtr LshProjectionInfer(const abstract::AnalysisEnginePtr &, const Pr const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); + const int64_t input_num = 2; + CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, op_name); auto input0 = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; auto input1 = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("input0_shape", SizeToLong(input0.size()), kEqual, 2, op_name); + (void)CheckAndConvertUtils::CheckInteger("input0 rank", SizeToLong(input0.size()), kEqual, 2, op_name); (void)CheckAndConvertUtils::CheckInteger("input0_shape_dimen_1", input0[1], kLessEqual, 32, op_name); - (void)CheckAndConvertUtils::CheckInteger("input1_shape", SizeToLong(input1.size()), kGreaterEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("input1 rank", SizeToLong(input1.size()), kGreaterEqual, 1, op_name); if (input_args.size() == 3) { auto input2 = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[2]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("input2_shape", SizeToLong(input2.size()), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("input2 rank", SizeToLong(input2.size()), kEqual, 1, op_name); (void)CheckAndConvertUtils::CheckInteger("input2_shape_dimen_0", input2[0], kEqual, input1[0], op_name); } diff --git a/mindspore/core/ops/lstm.cc b/mindspore/core/ops/lstm.cc index 1a2275181d8..667b095f596 100644 --- a/mindspore/core/ops/lstm.cc +++ b/mindspore/core/ops/lstm.cc @@ -38,10 +38,10 @@ AbstractBasePtr LstmInfer(const PrimitivePtr &primitive, const std::vectorBuildShape())[kShape]; int64_t input_x_size = GetValue(primitive->GetAttr(kInput_size)); - CheckAndConvertUtils::CheckInteger("x_shape.size()", SizeToLong(x_input_shape.size()), kEqual, 3, prim_name); - CheckAndConvertUtils::CheckInteger("x_shape[2]", x_input_shape[2], kEqual, input_x_size, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x_shape.size()", SizeToLong(x_input_shape.size()), kEqual, 3, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x_shape[2]", x_input_shape[2], kEqual, input_x_size, prim_name); - CheckAndConvertUtils::CheckInteger("h_shape.size()", SizeToLong(h_input_shape.size()), kEqual, 3, prim_name); + (void)CheckAndConvertUtils::CheckInteger("h_shape.size()", SizeToLong(h_input_shape.size()), kEqual, 3, prim_name); CheckAndConvertUtils::Check("h_shape", h_input_shape, kEqual, "c_shape", c_input_shape, prim_name); int64_t num_layers = GetValue(primitive->GetAttr(kNumLayers)); @@ -81,7 +81,7 @@ AbstractBasePtr LstmInfer(const PrimitivePtr &primitive, const std::vector state_shape = {1, 1}; // infer type - CheckAndConvertUtils::CheckInteger("lstm_prim_infer", SizeToLong(input_args.size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("lstm_prim_infer", SizeToLong(input_args.size()), kEqual, 4, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -101,45 +101,47 @@ AbstractBasePtr LstmInfer(const PrimitivePtr &primitive, const std::vectorname()); - 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 LSTM::get_input_size() const { return GetValue(GetAttr(kInput_size)); } void LSTM::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 LSTM::get_hidden_size() const { return GetValue(GetAttr(kHidden_size)); } void LSTM::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 LSTM::get_num_layers() const { return GetValue(GetAttr(kNumLayers)); } -void LSTM::set_has_bias(const bool has_bias) { AddAttr(kHasBias, MakeValue(has_bias)); } +void LSTM::set_has_bias(const bool has_bias) { (void)AddAttr(kHasBias, MakeValue(has_bias)); } bool LSTM::get_has_bias() const { auto value_ptr = this->GetAttr(kHasBias); return GetValue(value_ptr); } void LSTM::set_dropout(const float dropout) { CheckAndConvertUtils::CheckInRange(kDropout, dropout, kIncludeBoth, {0.0, 1.0}, this->name()); - AddAttr(kDropout, MakeValue(dropout)); + (void)AddAttr(kDropout, MakeValue(dropout)); } float LSTM::get_dropout() const { auto value_ptr = this->GetAttr(kDropout); return GetValue(value_ptr); } -void LSTM::set_bidirectional(const bool bidirectional) { AddAttr(kBidirectional, MakeValue(bidirectional)); } +void LSTM::set_bidirectional(const bool bidirectional) { (void)AddAttr(kBidirectional, MakeValue(bidirectional)); } bool LSTM::get_bidirectional() const { auto value_ptr = this->GetAttr(kBidirectional); return GetValue(value_ptr); } -void LSTM::set_num_directions(const int64_t num_directions) { AddAttr(kNumDirections, MakeValue(num_directions)); } +void LSTM::set_num_directions(const int64_t num_directions) { + (void)AddAttr(kNumDirections, MakeValue(num_directions)); +} int64_t LSTM::get_num_directions() const { return GetValue(GetAttr(kNumDirections)); } -void LSTM::set_zoneout_cell(float zoneout_cell) { AddAttr(kZoneoutCell, MakeValue(zoneout_cell)); } +void LSTM::set_zoneout_cell(float zoneout_cell) { (void)AddAttr(kZoneoutCell, MakeValue(zoneout_cell)); } float LSTM::get_zoneout_cell() const { return GetValue(this->GetAttr(kZoneoutCell)); } -void LSTM::set_zoneout_hidden(float zoneout_hidden) { AddAttr(kZoneoutHidden, MakeValue(zoneout_hidden)); } +void LSTM::set_zoneout_hidden(float zoneout_hidden) { (void)AddAttr(kZoneoutHidden, MakeValue(zoneout_hidden)); } float LSTM::get_zoneout_hidden() const { return GetValue(this->GetAttr(kZoneoutHidden)); } diff --git a/mindspore/core/ops/mat_mul.cc b/mindspore/core/ops/mat_mul.cc index 1ca4a83ead3..0ead5ccdd93 100644 --- a/mindspore/core/ops/mat_mul.cc +++ b/mindspore/core/ops/mat_mul.cc @@ -56,8 +56,8 @@ abstract::ShapePtr MatMulInferShape(const PrimitivePtr &primitive, const std::ve << ", x2 shape " << y_shp << "(transpose_b=" << transpose_b << "})"; } } - primitive->AddAttr("transpose_x1", transpose_a_ptr); - primitive->AddAttr("transpose_x2", transpose_b_ptr); + (void)primitive->AddAttr("transpose_x1", transpose_a_ptr); + (void)primitive->AddAttr("transpose_x2", transpose_b_ptr); ShapeVector x_min_shape = x_shape_map[kMinShape]; ShapeVector x_max_shape = x_shape_map[kMaxShape]; @@ -109,9 +109,9 @@ void MatMul::Init(bool transpose_a, bool transpose_b) { set_transpose_b(transpose_b); } -void MatMul::set_transpose_a(bool transpose_a) { AddAttr(kTransposeA, MakeValue(transpose_a)); } +void MatMul::set_transpose_a(bool transpose_a) { (void)AddAttr(kTransposeA, MakeValue(transpose_a)); } -void MatMul::set_transpose_b(bool transpose_b) { AddAttr(kTransposeB, MakeValue(transpose_b)); } +void MatMul::set_transpose_b(bool transpose_b) { (void)AddAttr(kTransposeB, MakeValue(transpose_b)); } bool MatMul::get_transpose_a() const { auto value_ptr = GetAttr(kTransposeA); diff --git a/mindspore/core/ops/max_pool.cc b/mindspore/core/ops/max_pool.cc index a3f9c88a97f..c7e1618c459 100644 --- a/mindspore/core/ops/max_pool.cc +++ b/mindspore/core/ops/max_pool.cc @@ -28,30 +28,30 @@ namespace mindspore { namespace ops { void MaxPool::set_pad_mode(const PadMode &pad_mode) { int64_t swi = pad_mode; - this->AddAttr(kPadMode, MakeValue(swi)); + (void)this->AddAttr(kPadMode, MakeValue(swi)); } PadMode MaxPool::get_pad_mode() const { return PadMode(GetValue(GetAttr(kPadMode))); } void MaxPool::set_kernel_size(const std::vector &kernel_size) { - this->AddAttr(kKernelSize, - MakeValue(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, this->name()))); + (void)this->AddAttr(kKernelSize, + MakeValue(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, this->name()))); } std::vector MaxPool::get_kernel_size() const { return GetValue>(GetAttr(kKernelSize)); } void MaxPool::set_strides(const std::vector &strides) { - this->AddAttr(kStrides, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kStrides, strides, this->name()))); + (void)this->AddAttr(kStrides, MakeValue(CheckAndConvertUtils::CheckPositiveVector(kStrides, strides, this->name()))); } std::vector MaxPool::get_strides() const { return GetValue>(GetAttr(kStrides)); } void MaxPool::set_format(const Format &format) { int64_t f = format; - this->AddAttr(kFormat, MakeValue(f)); + (void)this->AddAttr(kFormat, MakeValue(f)); } Format MaxPool::get_format() const { return Format(GetValue(GetAttr(kFormat))); } -void MaxPool::set_pad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } +void MaxPool::set_pad(const std::vector &pad) { (void)this->AddAttr(kPad, MakeValue(pad)); } std::vector MaxPool::get_pad() const { auto value_ptr = GetAttr(kPad); @@ -60,7 +60,7 @@ std::vector MaxPool::get_pad() const { void MaxPool::set_round_mode(const RoundMode &round_mode) { int64_t swi = round_mode; - this->AddAttr(kRoundMode, MakeValue(swi)); + (void)this->AddAttr(kRoundMode, MakeValue(swi)); } RoundMode MaxPool::get_round_mode() const { @@ -101,8 +101,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector(ceil((in_h - (kernel_h - 1)) + static_cast(stride_h) - 1) / static_cast(stride_h)); diff --git a/mindspore/core/ops/mfcc.cc b/mindspore/core/ops/mfcc.cc index 9b9f2d324e0..efc006989a6 100644 --- a/mindspore/core/ops/mfcc.cc +++ b/mindspore/core/ops/mfcc.cc @@ -52,7 +52,7 @@ void Mfcc::Init(const float freq_upper_limit, const float freq_lower_limit, cons } void Mfcc::set_freq_upper_limit(const float freq_upper_limit) { - this->AddAttr(kFreqUpperLimit, MakeValue(freq_upper_limit)); + (void)this->AddAttr(kFreqUpperLimit, MakeValue(freq_upper_limit)); } float Mfcc::get_freq_upper_limit() const { @@ -61,7 +61,7 @@ float Mfcc::get_freq_upper_limit() const { } void Mfcc::set_freq_lower_limit(const float freq_lower_limit) { - this->AddAttr(kFreqLowerLimit, MakeValue(freq_lower_limit)); + (void)this->AddAttr(kFreqLowerLimit, MakeValue(freq_lower_limit)); } float Mfcc::get_freq_lower_limit() const { @@ -70,7 +70,7 @@ float Mfcc::get_freq_lower_limit() const { } void Mfcc::set_filter_bank_channel_num(const int64_t filter_bank_channel_num) { - this->AddAttr(kFilterBankChannelNum, MakeValue(filter_bank_channel_num)); + (void)this->AddAttr(kFilterBankChannelNum, MakeValue(filter_bank_channel_num)); } int64_t Mfcc::get_filter_bank_channel_num() const { @@ -78,7 +78,9 @@ int64_t Mfcc::get_filter_bank_channel_num() const { return GetValue(value_ptr); } -void Mfcc::set_dct_coeff_num(const int64_t dct_coeff_num) { this->AddAttr(kDctCoeffNum, MakeValue(dct_coeff_num)); } +void Mfcc::set_dct_coeff_num(const int64_t dct_coeff_num) { + (void)this->AddAttr(kDctCoeffNum, MakeValue(dct_coeff_num)); +} int64_t Mfcc::get_dct_coeff_num() const { return GetValue(GetAttr(kDctCoeffNum)); } diff --git a/mindspore/core/ops/minimum.cc b/mindspore/core/ops/minimum.cc index 7637879de22..a60989dcd22 100644 --- a/mindspore/core/ops/minimum.cc +++ b/mindspore/core/ops/minimum.cc @@ -35,7 +35,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); - CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 2, prim->name()); + (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 2, prim->name()); if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr &a) { return a == nullptr; })) { MS_LOG(EXCEPTION) << "nullptr"; } @@ -49,7 +49,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr MinimumInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameMinimum, Minimum); } // namespace ops diff --git a/mindspore/core/ops/mul.cc b/mindspore/core/ops/mul.cc index 3b72774ae5e..f6fd05dd523 100644 --- a/mindspore/core/ops/mul.cc +++ b/mindspore/core/ops/mul.cc @@ -30,7 +30,7 @@ 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, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -42,7 +42,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & MS_EXCEPTION_IF_NULL(item); } auto op_name = prim->name(); - CheckAndConvertUtils::CheckInteger("Mul infer", input_args.size(), kGreaterEqual, 2, op_name); + (void)CheckAndConvertUtils::CheckInteger("Mul infer", input_args.size(), kGreaterEqual, 2, op_name); std::map types; types.emplace("x", input_args[0]->BuildType()); types.emplace("y", input_args[1]->BuildType()); diff --git a/mindspore/core/ops/neg.cc b/mindspore/core/ops/neg.cc index f292c2df928..b28a5449da7 100644 --- a/mindspore/core/ops/neg.cc +++ b/mindspore/core/ops/neg.cc @@ -30,7 +30,7 @@ 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", SizeToLong(input_args.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -47,7 +47,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto op_name = prim->name(); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, op_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/neighborexchange.cc b/mindspore/core/ops/neighborexchange.cc index ebb872f4a53..b4c47454bc5 100644 --- a/mindspore/core/ops/neighborexchange.cc +++ b/mindspore/core/ops/neighborexchange.cc @@ -24,7 +24,7 @@ namespace ops { abstract::TupleShapePtr 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); + (void)CheckAndConvertUtils::CheckInteger("input_numbers", input_args.size(), kEqual, 1, prim_name); CheckAndConvertUtils::CheckArgs(prim_name, input_args, 0); auto recv_shapes = primitive->GetAttr(RecvShapes); MS_EXCEPTION_IF_NULL(recv_shapes); @@ -46,7 +46,8 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec TypePtr InferType(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("NeighborExchange infer", input_args.size(), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("NeighborExchange infer", SizeToLong(input_args.size()), kEqual, 1, + prim_name); MS_EXCEPTION_IF_NULL(input_args[0]); auto recv_shapes = primitive->GetAttr(RecvShapes); MS_EXCEPTION_IF_NULL(recv_shapes); diff --git a/mindspore/core/ops/non_max_suppression.cc b/mindspore/core/ops/non_max_suppression.cc index cd7ad92c842..1fd225bbd39 100644 --- a/mindspore/core/ops/non_max_suppression.cc +++ b/mindspore/core/ops/non_max_suppression.cc @@ -21,7 +21,7 @@ namespace mindspore { namespace ops { void NonMaxSuppression::set_center_point_box(const int64_t center_point_box) { - AddAttr(kCenterPointBox, MakeValue(center_point_box)); + (void)AddAttr(kCenterPointBox, MakeValue(center_point_box)); } int64_t NonMaxSuppression::get_center_point_box() const { auto value_ptr = this->GetAttr(kCenterPointBox); diff --git a/mindspore/core/ops/one_hot.cc b/mindspore/core/ops/one_hot.cc index 620d891bd47..793aa782746 100644 --- a/mindspore/core/ops/one_hot.cc +++ b/mindspore/core/ops/one_hot.cc @@ -28,19 +28,15 @@ void OneHot::set_axis(const int64_t axis) { (void)this->AddAttr(kAxis, MakeValue int64_t OneHot::get_axis() const { return GetValue(GetAttr(kAxis)); } namespace { abstract::ShapePtr OneHotInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); int64_t axis = GetValue(primitive->GetAttr(kAxis)); - (void)CheckAndConvertUtils::CheckInteger("one_hot infer", SizeToLong(input_args.size()), kEqual, 4, op_name); - MS_EXCEPTION_IF_NULL(input_args[0]); auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape()); auto in_shape = shape_map[kShape]; auto max_shape = shape_map[kMinShape]; auto min_shape = shape_map[kMaxShape]; CheckAndConvertUtils::CheckInRange("axis", axis, kIncludeBoth, {-1, SizeToLong(in_shape.size())}, op_name); - MS_EXCEPTION_IF_NULL(input_args[1]); auto depth_val = GetValue(input_args[1]->BuildValue()); - (void)CheckAndConvertUtils::CheckInteger("depth", depth_val, kGreaterEqual, 0, op_name); + (void)CheckAndConvertUtils::CheckInteger("depth value", depth_val, kGreaterEqual, 0, op_name); if (min_shape.size() == 0 || max_shape.size() == 0) { if (axis >= 0) { in_shape.insert(in_shape.begin() + axis, depth_val); @@ -62,7 +58,6 @@ abstract::ShapePtr OneHotInferShape(const PrimitivePtr &primitive, const std::ve } TypePtr OneHotInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); auto op_name = prim->name(); CheckAndConvertUtils::CheckTensorTypeValid("indices", input_args[0]->BuildType(), {kInt32, kInt64}, op_name); CheckAndConvertUtils::CheckTypeValid("depth", input_args[1]->BuildType(), {kInt8, kInt16, kInt32, kInt64}, op_name); @@ -73,6 +68,9 @@ TypePtr OneHotInferType(const PrimitivePtr &prim, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 4; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); auto infer_type = OneHotInferType(primitive, input_args); auto infer_shape = OneHotInferShape(primitive, input_args); return abstract::MakeAbstract(infer_shape, infer_type); diff --git a/mindspore/core/ops/ones_like.cc b/mindspore/core/ops/ones_like.cc index 0d3c3e1b63f..90e07ae6e88 100644 --- a/mindspore/core/ops/ones_like.cc +++ b/mindspore/core/ops/ones_like.cc @@ -29,7 +29,7 @@ namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("infer_shape", input_args.size(), kGreaterEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("infer_shape", input_args.size(), kGreaterEqual, 1, op_name); return CheckAndConvertUtils::GetTensorInputShape(op_name, input_args, 0); } diff --git a/mindspore/core/ops/op_utils.cc b/mindspore/core/ops/op_utils.cc index 05abcf43b4b..bcd2d23ff23 100644 --- a/mindspore/core/ops/op_utils.cc +++ b/mindspore/core/ops/op_utils.cc @@ -54,10 +54,8 @@ std::vector CalBroadCastShape(std::vector x_shape, std::vector } abstract::ShapePtr BroadCastInferShape(const std::string &op_name, const std::vector &input_args) { MS_LOG(INFO) << "Do infer shape for op " << op_name; - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kGreaterEqual, 2, op_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } + const int64_t input_num = 2; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, op_name); auto x_shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack()); auto y_shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->GetShapeTrack()); auto x_shape = x_shape_map[kShape]; diff --git a/mindspore/core/ops/pack.cc b/mindspore/core/ops/pack.cc index 3e97de5a0bd..6bb6ce9a577 100644 --- a/mindspore/core/ops/pack.cc +++ b/mindspore/core/ops/pack.cc @@ -47,7 +47,7 @@ std::vector _get_pack_shape(std::vector x_shapes, std::ve } } // namespace -void Pack::set_axis(const int64_t &axis) { AddAttr(kAxis, MakeValue(axis)); } +void Pack::set_axis(const int64_t &axis) { (void)AddAttr(kAxis, MakeValue(axis)); } int64_t Pack::get_axis() const { return GetValue(GetAttr(kAxis)); } diff --git a/mindspore/core/ops/pad.cc b/mindspore/core/ops/pad.cc index 33c5e674fcd..59ab04b8d76 100644 --- a/mindspore/core/ops/pad.cc +++ b/mindspore/core/ops/pad.cc @@ -26,8 +26,8 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vectorname(); auto paddings_attr = GetValue>>(primitive->GetAttr(kPaddings)); auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("paddings_size", SizeToLong(paddings_attr.size()), kEqual, - int64_t(2 * x_shape.size()), prim_name); + (void)CheckAndConvertUtils::CheckInteger("paddings_size", SizeToLong(paddings_attr.size()), kEqual, + int64_t(2 * x_shape.size()), prim_name); int64_t size = SizeToLong(paddings_attr.size()); for (int64_t i = 0; i < size; i++) { for (int64_t j = 0; j < 2; j++) { @@ -55,7 +55,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & void Pad::Init(const std::vector> &paddings) { this->set_paddings(paddings); } void Pad::set_paddings(const std::vector> &paddings) { - this->AddAttr(kPaddings, MakeValue(paddings)); + (void)this->AddAttr(kPaddings, MakeValue(paddings)); } std::vector> Pad::get_paddings() const { return GetValue>>(GetAttr(kPaddings)); diff --git a/mindspore/core/ops/prelu.cc b/mindspore/core/ops/prelu.cc index a724be22ea1..9ba562bf558 100644 --- a/mindspore/core/ops/prelu.cc +++ b/mindspore/core/ops/prelu.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,31 +21,25 @@ namespace mindspore { namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); auto x = input_args[0]->BuildShape(); auto w = input_args[1]->BuildShape(); auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(x)[kShape]; auto w_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(w)[kShape]; - (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kNotEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kGreaterEqual, 2, prim_name); (void)CheckAndConvertUtils::CheckInteger("weight rank", SizeToLong(w_shape.size()), kEqual, 1, prim_name); if (w_shape[0] != x_shape[1] && w_shape[0] != 1) { MS_LOG(EXCEPTION) << "For " << prim_name << ", channel of input_x and weight must be matched, " << "while channel of input_x is " << x_shape[1] << ", weight_shape[0] is " << w_shape[0]; } - + MS_EXCEPTION_IF_NULL(x); auto shape_element = x->cast(); MS_EXCEPTION_IF_NULL(shape_element); return shape_element; } TypePtr InferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 2, prim->name()); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } const std::set valid_types = {kFloat16, kFloat32}; std::map check_map = {{"input_x", input_args[0]->BuildType()}, {"weight", input_args[1]->BuildType()}}; @@ -54,8 +48,11 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & } // namespace AbstractBasePtr PReLUInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 2; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNamePReLU, PReLU); } // namespace ops diff --git a/mindspore/core/ops/prior_box.cc b/mindspore/core/ops/prior_box.cc index 3c26756303d..fdf3f944730 100644 --- a/mindspore/core/ops/prior_box.cc +++ b/mindspore/core/ops/prior_box.cc @@ -22,11 +22,15 @@ namespace mindspore { namespace ops { -void PriorBox::set_min_sizes(const std::vector &min_sizes) { this->AddAttr(kMinSizes, MakeValue(min_sizes)); } +void PriorBox::set_min_sizes(const std::vector &min_sizes) { + (void)this->AddAttr(kMinSizes, MakeValue(min_sizes)); +} std::vector PriorBox::get_min_sizes() const { return GetValue>(GetAttr(kMinSizes)); } -void PriorBox::set_max_sizes(const std::vector &max_sizes) { this->AddAttr(kMaxSizes, MakeValue(max_sizes)); } +void PriorBox::set_max_sizes(const std::vector &max_sizes) { + (void)this->AddAttr(kMaxSizes, MakeValue(max_sizes)); +} std::vector PriorBox::get_max_sizes() const { auto value_ptr = GetAttr(kMaxSizes); @@ -34,26 +38,32 @@ std::vector PriorBox::get_max_sizes() const { } void PriorBox::set_aspect_ratios(const std::vector &aspect_ratios) { - this->AddAttr(kAspectRatios, MakeValue(aspect_ratios)); + (void)this->AddAttr(kAspectRatios, MakeValue(aspect_ratios)); } std::vector PriorBox::get_aspect_ratios() const { return GetValue>(GetAttr(kAspectRatios)); } -void PriorBox::set_variances(const std::vector &variances) { this->AddAttr(kVariances, MakeValue(variances)); } +void PriorBox::set_variances(const std::vector &variances) { + (void)this->AddAttr(kVariances, MakeValue(variances)); +} std::vector PriorBox::get_variances() const { auto value_ptr = GetAttr(kVariances); return GetValue>(value_ptr); } -void PriorBox::set_image_size_w(const int64_t image_size_w) { this->AddAttr(kImageSizeW, MakeValue(image_size_w)); } +void PriorBox::set_image_size_w(const int64_t image_size_w) { + (void)this->AddAttr(kImageSizeW, MakeValue(image_size_w)); +} int64_t PriorBox::get_image_size_w() const { auto value_ptr = GetAttr(kImageSizeW); return GetValue(value_ptr); } -void PriorBox::set_image_size_h(const int64_t image_size_h) { this->AddAttr(kImageSizeH, MakeValue(image_size_h)); } +void PriorBox::set_image_size_h(const int64_t image_size_h) { + (void)this->AddAttr(kImageSizeH, MakeValue(image_size_h)); +} int64_t PriorBox::get_image_size_h() const { auto value_ptr = GetAttr(kImageSizeH); @@ -74,18 +84,18 @@ float PriorBox::get_step_h() const { return GetValue(value_ptr); } -void PriorBox::set_clip(const bool clip) { this->AddAttr(kClip, MakeValue(clip)); } +void PriorBox::set_clip(const bool clip) { (void)this->AddAttr(kClip, MakeValue(clip)); } bool PriorBox::get_clip() const { auto value_ptr = GetAttr(kClip); return GetValue(value_ptr); } -void PriorBox::set_flip(const bool flip) { this->AddAttr(kFlip, MakeValue(flip)); } +void PriorBox::set_flip(const bool flip) { (void)this->AddAttr(kFlip, MakeValue(flip)); } bool PriorBox::get_flip() const { return GetValue(GetAttr(kFlip)); } -void PriorBox::set_offset(const float offset) { this->AddAttr(kOffset, MakeValue(offset)); } +void PriorBox::set_offset(const float offset) { (void)this->AddAttr(kOffset, MakeValue(offset)); } float PriorBox::get_offset() const { auto value_ptr = GetAttr(kOffset); diff --git a/mindspore/core/ops/proposal.cc b/mindspore/core/ops/proposal.cc index 81981f21444..427de07be30 100644 --- a/mindspore/core/ops/proposal.cc +++ b/mindspore/core/ops/proposal.cc @@ -23,56 +23,60 @@ namespace mindspore { namespace ops { -void Proposal::set_feat_stride(const float feat_stride) { this->AddAttr(kFeatStride, MakeValue(feat_stride)); } +void Proposal::set_feat_stride(const float feat_stride) { (void)this->AddAttr(kFeatStride, MakeValue(feat_stride)); } float Proposal::get_feat_stride() const { auto value_ptr = GetAttr(kFeatStride); return GetValue(value_ptr); } -void Proposal::set_base_size(const float base_size) { this->AddAttr(kBaseSize, MakeValue(base_size)); } +void Proposal::set_base_size(const float base_size) { (void)this->AddAttr(kBaseSize, MakeValue(base_size)); } float Proposal::get_base_size() const { auto value_ptr = GetAttr(kBaseSize); return GetValue(value_ptr); } -void Proposal::set_min_size(const float min_size) { this->AddAttr(kMinSize, MakeValue(min_size)); } +void Proposal::set_min_size(const float min_size) { (void)this->AddAttr(kMinSize, MakeValue(min_size)); } float Proposal::get_min_size() const { auto value_ptr = GetAttr(kMinSize); return GetValue(value_ptr); } -void Proposal::set_ratio(const std::vector &ratio) { this->AddAttr(kRatio, MakeValue(ratio)); } +void Proposal::set_ratio(const std::vector &ratio) { (void)this->AddAttr(kRatio, MakeValue(ratio)); } std::vector Proposal::get_ratio() const { auto value_ptr = GetAttr(kRatio); return GetValue>(value_ptr); } -void Proposal::set_scale(const std::vector &scale) { this->AddAttr(kScale, MakeValue(scale)); } +void Proposal::set_scale(const std::vector &scale) { (void)this->AddAttr(kScale, MakeValue(scale)); } std::vector Proposal::get_scale() const { auto value_ptr = GetAttr(kScale); return GetValue>(value_ptr); } -void Proposal::set_pre_nms_topn(const int64_t pre_nms_topn) { this->AddAttr(kPreNmsTopn, MakeValue(pre_nms_topn)); } +void Proposal::set_pre_nms_topn(const int64_t pre_nms_topn) { + (void)this->AddAttr(kPreNmsTopn, MakeValue(pre_nms_topn)); +} int64_t Proposal::get_pre_nms_topn() const { auto value_ptr = GetAttr(kPreNmsTopn); return GetValue(value_ptr); } -void Proposal::set_post_nms_topn(const int64_t post_nms_topn) { this->AddAttr(kPostNmsTopn, MakeValue(post_nms_topn)); } +void Proposal::set_post_nms_topn(const int64_t post_nms_topn) { + (void)this->AddAttr(kPostNmsTopn, MakeValue(post_nms_topn)); +} int64_t Proposal::get_post_nms_topn() const { auto value_ptr = GetAttr(kPostNmsTopn); return GetValue(value_ptr); } -void Proposal::set_nms_thresh(const float nms_thresh) { this->AddAttr(kNmsThresh, MakeValue(nms_thresh)); } +void Proposal::set_nms_thresh(const float nms_thresh) { (void)this->AddAttr(kNmsThresh, MakeValue(nms_thresh)); } float Proposal::get_nms_thresh() const { auto value_ptr = GetAttr(kNmsThresh); diff --git a/mindspore/core/ops/quant_dtype_cast.cc b/mindspore/core/ops/quant_dtype_cast.cc index 9a0e8bd2414..91f9decbc4d 100644 --- a/mindspore/core/ops/quant_dtype_cast.cc +++ b/mindspore/core/ops/quant_dtype_cast.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,12 @@ namespace mindspore { namespace ops { -void QuantDTypeCast::set_src_t(const int64_t src_t) { AddAttr(kSrcT, MakeValue(src_t)); } +void QuantDTypeCast::set_src_t(const int64_t src_t) { (void)AddAttr(kSrcT, MakeValue(src_t)); } int64_t QuantDTypeCast::get_src_t() const { auto value_ptr = this->GetAttr(kSrcT); return GetValue(value_ptr); } -void QuantDTypeCast::set_dst_t(const int64_t dst_t) { AddAttr(kDstT, MakeValue(dst_t)); } +void QuantDTypeCast::set_dst_t(const int64_t dst_t) { (void)AddAttr(kDstT, MakeValue(dst_t)); } int64_t QuantDTypeCast::get_dst_t() const { return GetValue(GetAttr(kDstT)); } void QuantDTypeCast::Init(const int64_t src_t, const int64_t dst_t) { this->set_src_t(src_t); @@ -32,13 +32,17 @@ void QuantDTypeCast::Init(const int64_t src_t, const int64_t dst_t) { AbstractBasePtr QuantDTypeCastInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - MS_EXCEPTION_IF_NULL(input_args[0]); - auto input_type = input_args[0]->BuildType()->cast(); - MS_EXCEPTION_IF_NULL(input_type); - auto dst_type = GetValue(primitive->GetAttr(kDstT)); - MS_ASSERT(input_type->element() == TypeIdToType(TypeId(dst_type))); + const int64_t input_num = 1; + const int64_t x_index = 0; + CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, primitive->name()); + auto input_type = CheckAndConvertUtils::GetInputTensorType(input_args, x_index, primitive->name()); + auto dst_type = TypeIdToType(TypeId(GetValue(primitive->GetAttr(kDstT)))); + MS_EXCEPTION_IF_NULL(dst_type); + if (input_type != dst_type) { + MS_EXCEPTION(TypeError) << "Input type should be " << dst_type->ToString() << ", but " << input_type->ToString(); + } auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - return std::make_shared(TypeIdToType(TypeId(dst_type)), input_shape); + return std::make_shared(dst_type, input_shape); } REGISTER_PRIMITIVE_C(kNameQuantDTypeCast, QuantDTypeCast); } // namespace ops diff --git a/mindspore/core/ops/random_standard_normal.cc b/mindspore/core/ops/random_standard_normal.cc index c8893bcff81..b769402969e 100644 --- a/mindspore/core/ops/random_standard_normal.cc +++ b/mindspore/core/ops/random_standard_normal.cc @@ -26,9 +26,9 @@ void RandomStandardNormal::Init(const int64_t seed, const int64_t seed2) { this->set_seed2(seed2); } -void RandomStandardNormal::set_seed(int64_t seed) { this->AddAttr(kSeed, MakeValue(seed)); } +void RandomStandardNormal::set_seed(int64_t seed) { (void)this->AddAttr(kSeed, MakeValue(seed)); } -void RandomStandardNormal::set_seed2(int64_t seed2) { this->AddAttr(kSeed2, MakeValue(seed2)); } +void RandomStandardNormal::set_seed2(int64_t seed2) { (void)this->AddAttr(kSeed2, MakeValue(seed2)); } int64_t RandomStandardNormal::get_seed() const { auto value_ptr = GetAttr(kSeed); diff --git a/mindspore/core/ops/reciprocal.cc b/mindspore/core/ops/reciprocal.cc index 7887efbdeac..1b428490893 100644 --- a/mindspore/core/ops/reciprocal.cc +++ b/mindspore/core/ops/reciprocal.cc @@ -30,7 +30,7 @@ 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", SizeToLong(input_args.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -47,7 +47,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto op_name = prim->name(); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, op_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/reduce.cc b/mindspore/core/ops/reduce.cc index 331dcd7ae3a..56fdbeffd36 100644 --- a/mindspore/core/ops/reduce.cc +++ b/mindspore/core/ops/reduce.cc @@ -87,7 +87,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & } } // namespace -void Reduce::set_keep_dims(const bool keep_dims) { this->AddAttr(kKeepDims, MakeValue(keep_dims)); } +void Reduce::set_keep_dims(const bool keep_dims) { (void)this->AddAttr(kKeepDims, MakeValue(keep_dims)); } bool Reduce::get_keep_dims() const { return GetValue(GetAttr(kKeepDims)); } diff --git a/mindspore/core/ops/reluv2.cc b/mindspore/core/ops/reluv2.cc index 2c7c7014f03..f04913dc41f 100644 --- a/mindspore/core/ops/reluv2.cc +++ b/mindspore/core/ops/reluv2.cc @@ -54,7 +54,7 @@ std::vector GetOutputMaskShape(const std::vector &input_shape, abstract::TupleShapePtr 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); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 1, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -85,7 +85,7 @@ abstract::TupleShapePtr InferShape(const PrimitivePtr &primitive, const std::vec TypePtr InferType(const PrimitivePtr &prim, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto prim_name = prim->name(); - CheckAndConvertUtils::CheckInteger("ReLUV2 infer", input_args.size(), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("ReLUV2 infer", input_args.size(), kEqual, 1, prim_name); MS_EXCEPTION_IF_NULL(input_args[0]); auto x_type = input_args[0]->BuildType(); MS_EXCEPTION_IF_NULL(x_type); diff --git a/mindspore/core/ops/reshape.cc b/mindspore/core/ops/reshape.cc index 9c6ca38d2e6..bc709f8a36f 100644 --- a/mindspore/core/ops/reshape.cc +++ b/mindspore/core/ops/reshape.cc @@ -31,7 +31,7 @@ AbstractBasePtr ReshapeInfer(const abstract::AnalysisEnginePtr &, const Primitiv const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/resize.cc b/mindspore/core/ops/resize.cc index f49acd71a17..46fcabce21e 100644 --- a/mindspore/core/ops/resize.cc +++ b/mindspore/core/ops/resize.cc @@ -42,40 +42,40 @@ void Resize::Init(const Format format, const ResizeMethod method, const int64_t } void Resize::set_format(const Format format) { int64_t swi = format; - this->AddAttr(kFormat, MakeValue(swi)); + (void)this->AddAttr(kFormat, MakeValue(swi)); } void Resize::set_method(const ResizeMethod method) { auto swi = (int64_t)method; - this->AddAttr(kMethod, MakeValue(swi)); + (void)this->AddAttr(kMethod, MakeValue(swi)); } -void Resize::set_new_height(const int64_t new_height) { this->AddAttr(kNewHeight, MakeValue(new_height)); } +void Resize::set_new_height(const int64_t new_height) { (void)this->AddAttr(kNewHeight, MakeValue(new_height)); } -void Resize::set_new_width(const int64_t new_width) { this->AddAttr(kNewWidth, MakeValue(new_width)); } +void Resize::set_new_width(const int64_t new_width) { (void)this->AddAttr(kNewWidth, MakeValue(new_width)); } void Resize::set_preserve_aspect_ratio(const bool preserve_aspect_ratio) { - this->AddAttr(kPreserveAspectRatio, MakeValue(preserve_aspect_ratio)); + (void)this->AddAttr(kPreserveAspectRatio, MakeValue(preserve_aspect_ratio)); } void Resize::set_coordinate_transform_mode(const CoordinateTransformMode coordinate_transform_mode) { int64_t swi = coordinate_transform_mode; - this->AddAttr(kCoordinateTransformMode, MakeValue(swi)); + (void)this->AddAttr(kCoordinateTransformMode, MakeValue(swi)); } -void Resize::set_cubic_coeff(const float cubic_coeff) { this->AddAttr(kCubicCoeff, MakeValue(cubic_coeff)); } +void Resize::set_cubic_coeff(const float cubic_coeff) { (void)this->AddAttr(kCubicCoeff, MakeValue(cubic_coeff)); } void Resize::set_exclude_outside(const int64_t exclude_outside) { - this->AddAttr(kExcludeOutside, MakeValue(exclude_outside)); + (void)this->AddAttr(kExcludeOutside, MakeValue(exclude_outside)); } void Resize::set_extrapolation_value(const float extrapolation_value) { - this->AddAttr(kExtrapolationValue, MakeValue(extrapolation_value)); + (void)this->AddAttr(kExtrapolationValue, MakeValue(extrapolation_value)); } void Resize::set_nearest_mode(const NearestMode nearest_mode) { int64_t swi = (int64_t)nearest_mode; - this->AddAttr(kNearestMode, MakeValue(swi)); + (void)this->AddAttr(kNearestMode, MakeValue(swi)); } Format Resize::get_format() const { diff --git a/mindspore/core/ops/resize_bilinear.cc b/mindspore/core/ops/resize_bilinear.cc index b4d6a50ccad..c60b7e9d65a 100644 --- a/mindspore/core/ops/resize_bilinear.cc +++ b/mindspore/core/ops/resize_bilinear.cc @@ -25,12 +25,12 @@ namespace mindspore { namespace ops { -void ResizeBilinear::set_size(const std::vector &size) { this->AddAttr(kSize, MakeValue(size)); } +void ResizeBilinear::set_size(const std::vector &size) { (void)this->AddAttr(kSize, MakeValue(size)); } std::vector ResizeBilinear::get_size() const { return GetValue>(GetAttr(kSize)); } void ResizeBilinear::set_align_corners(const bool align_corners) { - this->AddAttr(kAlignCorners, MakeValue(align_corners)); + (void)this->AddAttr(kAlignCorners, MakeValue(align_corners)); } bool ResizeBilinear::get_align_corners() const { @@ -50,7 +50,7 @@ AbstractBasePtr ResizeBilinearInfer(const abstract::AnalysisEnginePtr &, const P // Infer shape auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("input_shape_rank", SizeToLong(input_shape.size()), kEqual, 4, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input_shape_rank", SizeToLong(input_shape.size()), kEqual, 4, prim_name); std::vector out_shape = {input_shape[0], input_shape[1]}; auto size = GetValue>(primitive->GetAttr(kSize)); out_shape.insert(out_shape.end(), size.begin(), size.end()); diff --git a/mindspore/core/ops/resize_nearest_neighbor.cc b/mindspore/core/ops/resize_nearest_neighbor.cc index d5af129c240..f3efe3a31a6 100644 --- a/mindspore/core/ops/resize_nearest_neighbor.cc +++ b/mindspore/core/ops/resize_nearest_neighbor.cc @@ -30,9 +30,9 @@ void ResizeNearestNeighbor::Init(const std::vector &size, const bool al this->set_size(size); this->set_align_corners(align_corners); } -void ResizeNearestNeighbor::set_size(const std::vector &size) { this->AddAttr(kSize, MakeValue(size)); } +void ResizeNearestNeighbor::set_size(const std::vector &size) { (void)this->AddAttr(kSize, MakeValue(size)); } void ResizeNearestNeighbor::set_align_corners(const bool align_corners) { - this->AddAttr(kAlignCorners, MakeValue(align_corners)); + (void)this->AddAttr(kAlignCorners, MakeValue(align_corners)); } std::vector ResizeNearestNeighbor::get_size() const { auto value_ptr = GetAttr(kSize); diff --git a/mindspore/core/ops/reverse_sequence.cc b/mindspore/core/ops/reverse_sequence.cc index d735e94423b..f955cdf486a 100644 --- a/mindspore/core/ops/reverse_sequence.cc +++ b/mindspore/core/ops/reverse_sequence.cc @@ -39,7 +39,7 @@ AbstractBasePtr ReverseSequenceInfer(const abstract::AnalysisEnginePtr &, const const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -48,12 +48,13 @@ AbstractBasePtr ReverseSequenceInfer(const abstract::AnalysisEnginePtr &, const auto seq_lengths = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; auto seq_dim = GetValue(primitive->GetAttr(kSeqDim)); auto batch_dim = GetValue(primitive->GetAttr(kBatchDim)); - CheckAndConvertUtils::CheckInteger("seq_dim", seq_dim, kLessEqual, SizeToLong(input_shape.size()), prim_name); - CheckAndConvertUtils::CheckInteger("batch_dim", batch_dim, kLessEqual, SizeToLong(input_shape.size()), prim_name); - CheckAndConvertUtils::CheckInteger("batch_dim", batch_dim, kNotEqual, seq_dim, prim_name); - CheckAndConvertUtils::CheckInteger("seq_lengths rank", SizeToLong(seq_lengths.size()), kEqual, 1, prim_name); - CheckAndConvertUtils::CheckInteger("seq_lengths vector size", seq_lengths[0], kEqual, - input_shape[LongToSize(batch_dim)], prim_name); + (void)CheckAndConvertUtils::CheckInteger("seq_dim", seq_dim, kLessEqual, SizeToLong(input_shape.size()), prim_name); + (void)CheckAndConvertUtils::CheckInteger("batch_dim", batch_dim, kLessEqual, SizeToLong(input_shape.size()), + prim_name); + (void)CheckAndConvertUtils::CheckInteger("batch_dim", batch_dim, kNotEqual, seq_dim, prim_name); + (void)CheckAndConvertUtils::CheckInteger("seq_lengths rank", SizeToLong(seq_lengths.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("seq_lengths vector size", seq_lengths[0], kEqual, + input_shape[LongToSize(batch_dim)], prim_name); // infer type std::set valid_x_types(common_valid_types); valid_x_types.emplace(kBool); diff --git a/mindspore/core/ops/reverse_v2.cc b/mindspore/core/ops/reverse_v2.cc index 24d3394cbe4..1dd8c645a2c 100644 --- a/mindspore/core/ops/reverse_v2.cc +++ b/mindspore/core/ops/reverse_v2.cc @@ -40,7 +40,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & } // namespace void ReverseV2::Init(const std::vector &axis) { this->set_axis(axis); } -void ReverseV2::set_axis(const std::vector &axis) { this->AddAttr(kAxis, MakeValue(axis)); } +void ReverseV2::set_axis(const std::vector &axis) { (void)this->AddAttr(kAxis, MakeValue(axis)); } std::vector ReverseV2::get_axis() const { auto value_ptr = GetAttr(kAxis); return GetValue>(value_ptr); diff --git a/mindspore/core/ops/roi_pooling.cc b/mindspore/core/ops/roi_pooling.cc index bcb5faf7b63..34aefa8a506 100644 --- a/mindspore/core/ops/roi_pooling.cc +++ b/mindspore/core/ops/roi_pooling.cc @@ -25,18 +25,18 @@ namespace mindspore { namespace ops { -void ROIPooling::set_pooled_h(const int64_t pooled_h) { this->AddAttr(kPooledH, MakeValue(pooled_h)); } +void ROIPooling::set_pooled_h(const int64_t pooled_h) { (void)this->AddAttr(kPooledH, MakeValue(pooled_h)); } int64_t ROIPooling::get_pooled_h() const { return GetValue(GetAttr(kPooledH)); } -void ROIPooling::set_pooled_w(const int64_t pooled_w) { this->AddAttr(kPooledW, MakeValue(pooled_w)); } +void ROIPooling::set_pooled_w(const int64_t pooled_w) { (void)this->AddAttr(kPooledW, MakeValue(pooled_w)); } int64_t ROIPooling::get_pooled_w() const { auto value_ptr = GetAttr(kPooledW); return GetValue(value_ptr); } -void ROIPooling::set_scale(const float scale) { this->AddAttr(kScale, MakeValue(scale)); } +void ROIPooling::set_scale(const float scale) { (void)this->AddAttr(kScale, MakeValue(scale)); } float ROIPooling::get_scale() const { auto value_ptr = GetAttr(kScale); @@ -52,7 +52,7 @@ AbstractBasePtr ROIPoolingInfer(const abstract::AnalysisEnginePtr &, const Primi const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("roi_pooling_infer", SizeToLong(input_args.size()), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("roi_pooling_infer", SizeToLong(input_args.size()), kEqual, 2, prim_name); MS_EXCEPTION_IF_NULL(input_args[0]); MS_EXCEPTION_IF_NULL(input_args[1]); diff --git a/mindspore/core/ops/rsqrt.cc b/mindspore/core/ops/rsqrt.cc index e38eb548d03..c3391a3c327 100644 --- a/mindspore/core/ops/rsqrt.cc +++ b/mindspore/core/ops/rsqrt.cc @@ -30,8 +30,10 @@ namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, prim_name); auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - CheckAndConvertUtils::CheckInteger("input shape", SizeToLong(in_shape.size()), kEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input shape", SizeToLong(in_shape.size()), kEqual, 1, prim_name); return std::make_shared(in_shape); } diff --git a/mindspore/core/ops/scalar_summary.cc b/mindspore/core/ops/scalar_summary.cc index 2b061dd0a15..0e82bade057 100644 --- a/mindspore/core/ops/scalar_summary.cc +++ b/mindspore/core/ops/scalar_summary.cc @@ -30,11 +30,11 @@ abstract::ShapePtr ScalarSummaryInferShape(const PrimitivePtr &primitive, auto prim_name = primitive->name(); // check auto v_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("v rank", v_shape.size(), kLessEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("v rank", v_shape.size(), kLessEqual, 1, prim_name); return std::make_shared(ShapeVector(1)); } } // namespace -void ScalarSummary::set_side_effect_io() { this->AddAttr(kSideEffectIO, MakeValue(true)); } +void ScalarSummary::set_side_effect_io() { (void)this->AddAttr(kSideEffectIO, MakeValue(true)); } bool ScalarSummary::get_side_effect_io() const { auto value_ptr = GetAttr(kSideEffectIO); diff --git a/mindspore/core/ops/sgd.cc b/mindspore/core/ops/sgd.cc index 6cc7ebfc38a..50497df5fb3 100644 --- a/mindspore/core/ops/sgd.cc +++ b/mindspore/core/ops/sgd.cc @@ -26,12 +26,12 @@ void SGD::Init(const float dampening, const float weight_decay, const bool neste void SGD::set_dampening(const float dampening) { if (get_nesterov()) CheckAndConvertUtils::CheckValue(kDampening, dampening, kEqual, 0.0, name()); - AddAttr(kDampening, MakeValue(dampening)); + (void)AddAttr(kDampening, MakeValue(dampening)); } -void SGD::set_weight_decay(const float weight_decay) { AddAttr(kWeightDecay, MakeValue(weight_decay)); } +void SGD::set_weight_decay(const float weight_decay) { (void)AddAttr(kWeightDecay, MakeValue(weight_decay)); } -void SGD::set_nesterov(const bool nesterov) { AddAttr(kNesterov, MakeValue(nesterov)); } +void SGD::set_nesterov(const bool nesterov) { (void)AddAttr(kNesterov, MakeValue(nesterov)); } float SGD::get_dampening() const { auto value_ptr = GetAttr(kDampening); diff --git a/mindspore/core/ops/shape.cc b/mindspore/core/ops/shape.cc index 764eda50075..9b88099efaf 100644 --- a/mindspore/core/ops/shape.cc +++ b/mindspore/core/ops/shape.cc @@ -31,7 +31,7 @@ AbstractBasePtr ShapeInfer(const abstract::AnalysisEnginePtr &, const PrimitiveP // infer shape MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("shape infer", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("shape infer", input_args.size(), kEqual, 1, op_name); MS_EXCEPTION_IF_NULL(input_args[0]); auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape()); auto in_shape = shape_map[kShape]; @@ -50,7 +50,7 @@ AbstractBasePtr ShapeInfer(const abstract::AnalysisEnginePtr &, const PrimitiveP ValuePtr ShapeInferValue(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("shape infer", input_args.size(), kEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("shape infer", input_args.size(), kEqual, 1, op_name); MS_EXCEPTION_IF_NULL(input_args[0]); std::set valid_params_types = {kTensorType}; CheckAndConvertUtils::CheckSubClass("shape type", input_args[0]->BuildType(), valid_params_types, op_name); diff --git a/mindspore/core/ops/skip_gram.cc b/mindspore/core/ops/skip_gram.cc index 825b9e65447..7399889f97f 100644 --- a/mindspore/core/ops/skip_gram.cc +++ b/mindspore/core/ops/skip_gram.cc @@ -41,18 +41,18 @@ TypePtr InferType(const std::vector &input_args) { } // namespace void SkipGram::set_include_all_grams(const bool include_all_grams) { - AddAttr(kIncludeALLGrams, MakeValue(include_all_grams)); + (void)AddAttr(kIncludeALLGrams, MakeValue(include_all_grams)); } bool SkipGram::get_include_all_grams() const { auto value_ptr = this->GetAttr(kIncludeALLGrams); return GetValue(value_ptr); } -void SkipGram::set_max_skip_size(const int64_t max_skip_size) { AddAttr(kMaxSkipSize, MakeValue(max_skip_size)); } +void SkipGram::set_max_skip_size(const int64_t max_skip_size) { (void)AddAttr(kMaxSkipSize, MakeValue(max_skip_size)); } int64_t SkipGram::get_max_skip_size() const { auto value_ptr = this->GetAttr(kMaxSkipSize); return GetValue(value_ptr); } -void SkipGram::set_ngram_size(const int64_t ngram_size) { AddAttr(kNgramSize, MakeValue(ngram_size)); } +void SkipGram::set_ngram_size(const int64_t ngram_size) { (void)AddAttr(kNgramSize, MakeValue(ngram_size)); } int64_t SkipGram::get_ngram_size() const { auto value_ptr = this->GetAttr(kNgramSize); return GetValue(value_ptr); diff --git a/mindspore/core/ops/smooth_l1_loss.cc b/mindspore/core/ops/smooth_l1_loss.cc index 3926b7b87d6..27f555efe2b 100644 --- a/mindspore/core/ops/smooth_l1_loss.cc +++ b/mindspore/core/ops/smooth_l1_loss.cc @@ -37,7 +37,8 @@ AbstractBasePtr SmoothL1LossInfer(const abstract::AnalysisEnginePtr &, const Pri const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("smooth_l1_loss_infer", SizeToLong(input_args.size()), kEqual, 2, prim_name); + const int64_t input_num = 2; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, prim_name); // Infer shape auto prediction = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; diff --git a/mindspore/core/ops/soft_shrink.cc b/mindspore/core/ops/soft_shrink.cc index 5d8c4350668..864c9d9869e 100644 --- a/mindspore/core/ops/soft_shrink.cc +++ b/mindspore/core/ops/soft_shrink.cc @@ -31,7 +31,7 @@ namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, primitive->name()); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -40,7 +40,7 @@ abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); - CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, prim->name()); + (void)CheckAndConvertUtils::CheckInteger("input number", input_args.size(), kEqual, 1, 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/softmax_cross_entropy_with_logits.cc b/mindspore/core/ops/softmax_cross_entropy_with_logits.cc index a49dec12a7e..607bf8e1a6b 100644 --- a/mindspore/core/ops/softmax_cross_entropy_with_logits.cc +++ b/mindspore/core/ops/softmax_cross_entropy_with_logits.cc @@ -30,9 +30,8 @@ AbstractBasePtr SoftmaxCrossEntropyWithLogitsInfer(const abstract::AnalysisEngin const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("softmax_cross_entropy_with_logics_infer", SizeToLong(input_args.size()), - kEqual, 2, prim_name); - + const int64_t input_num = 2; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, prim_name); // Infer shape auto logits_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; auto labels_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; diff --git a/mindspore/core/ops/space_to_batch.cc b/mindspore/core/ops/space_to_batch.cc index 946666ddb7d..0597f02cb2a 100644 --- a/mindspore/core/ops/space_to_batch.cc +++ b/mindspore/core/ops/space_to_batch.cc @@ -53,7 +53,7 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & } } // namespace void SpaceToBatch::set_paddings(const std::vector> &paddings) { - this->AddAttr(kPaddings, MakeValue(paddings)); + (void)this->AddAttr(kPaddings, MakeValue(paddings)); int64_t h = SizeToLong(paddings.size()); int64_t w = SizeToLong(paddings[0].size()); std::vector temp_w = {2, 2}; @@ -70,7 +70,7 @@ std::vector> SpaceToBatch::get_paddings() const { return GetValue>>(value_ptr); } void SpaceToBatch::set_block_size(const std::vector block_size) { - this->AddAttr(kBlockSize, MakeValue(block_size)); + (void)this->AddAttr(kBlockSize, MakeValue(block_size)); } std::vector SpaceToBatch::get_block_size() const { diff --git a/mindspore/core/ops/space_to_batch_nd.cc b/mindspore/core/ops/space_to_batch_nd.cc index bdb222e5b1e..98efcf0a5b6 100644 --- a/mindspore/core/ops/space_to_batch_nd.cc +++ b/mindspore/core/ops/space_to_batch_nd.cc @@ -70,7 +70,7 @@ void SpaceToBatchND::set_paddings(std::vector> paddings) { (void)CheckAndConvertUtils::CheckInteger(kPaddings, SizeToLong(paddings[i][j]), kGreaterEqual, 0, this->name()); } } - this->AddAttr(kPaddings, MakeValue(paddings)); + (void)this->AddAttr(kPaddings, MakeValue(paddings)); } std::vector> SpaceToBatchND::get_paddings() const { @@ -82,7 +82,7 @@ void SpaceToBatchND::set_block_shape(std::vector block_shape) { for (size_t i = 0; i < block_shape.size(); i++) { (void)CheckAndConvertUtils::CheckInteger(kBlockShape, SizeToLong(block_shape[i]), kGreaterEqual, 1, this->name()); } - this->AddAttr(kBlockShape, MakeValue(block_shape)); + (void)this->AddAttr(kBlockShape, MakeValue(block_shape)); } std::vector SpaceToBatchND::get_block_shape() const { diff --git a/mindspore/core/ops/space_to_depth.cc b/mindspore/core/ops/space_to_depth.cc index bc66c2f2cbe..a72206e6f2c 100644 --- a/mindspore/core/ops/space_to_depth.cc +++ b/mindspore/core/ops/space_to_depth.cc @@ -25,7 +25,7 @@ void SpaceToDepth::Init(const int64_t block_size, const Format &format) { void SpaceToDepth::set_block_size(const int64_t block_size) { (void)CheckAndConvertUtils::Check(kBlockSize, block_size, kGreaterEqual, "", 2, this->name()); - AddAttr(kBlockSize, MakeValue(block_size)); + (void)AddAttr(kBlockSize, MakeValue(block_size)); } int64_t SpaceToDepth::get_block_size() const { @@ -35,7 +35,7 @@ int64_t SpaceToDepth::get_block_size() const { void SpaceToDepth::set_format(const Format &format) { int64_t f = format; - this->AddAttr(kFormat, MakeValue(f)); + (void)this->AddAttr(kFormat, MakeValue(f)); } Format SpaceToDepth::get_format() const { diff --git a/mindspore/core/ops/sparse_softmax_cross_entropy_with_logits.cc b/mindspore/core/ops/sparse_softmax_cross_entropy_with_logits.cc index 3294517ae40..413067a73d2 100644 --- a/mindspore/core/ops/sparse_softmax_cross_entropy_with_logits.cc +++ b/mindspore/core/ops/sparse_softmax_cross_entropy_with_logits.cc @@ -28,7 +28,7 @@ namespace ops { void SparseSoftmaxCrossEntropyWithLogits::Init(const bool is_grad) { this->set_is_grad(is_grad); } void SparseSoftmaxCrossEntropyWithLogits::set_is_grad(const bool is_grad) { - this->AddAttr(kIsGrad, MakeValue(is_grad)); + (void)this->AddAttr(kIsGrad, MakeValue(is_grad)); } bool SparseSoftmaxCrossEntropyWithLogits::get_is_grad() const { return GetValue(GetAttr(kIsGrad)); } @@ -38,7 +38,7 @@ AbstractBasePtr SparseSoftmaxCrossEntropyWithLogitsInfer(const abstract::Analysi const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/splice.cc b/mindspore/core/ops/splice.cc index d5b8c302f1f..1f5cda842ea 100644 --- a/mindspore/core/ops/splice.cc +++ b/mindspore/core/ops/splice.cc @@ -26,13 +26,15 @@ void Splice::Init(const std::vector &contexts, const std::vectorset_output_dim(output_dims); } -void Splice::set_context(const std::vector &contexts) { this->AddAttr(kSpliceContext, MakeValue(contexts)); } - -void Splice::set_forward_indexes(const std::vector &forward_indexes) { - this->AddAttr(kSpliceForwardIndexes, MakeValue(forward_indexes)); +void Splice::set_context(const std::vector &contexts) { + (void)this->AddAttr(kSpliceContext, MakeValue(contexts)); } -void Splice::set_output_dim(int64_t output_dim) { this->AddAttr(kSpliceOutputDims, MakeValue(output_dim)); } +void Splice::set_forward_indexes(const std::vector &forward_indexes) { + (void)this->AddAttr(kSpliceForwardIndexes, MakeValue(forward_indexes)); +} + +void Splice::set_output_dim(int64_t output_dim) { (void)this->AddAttr(kSpliceOutputDims, MakeValue(output_dim)); } std::vector Splice::get_context() const { auto value_ptr = GetAttr(kSpliceContext); diff --git a/mindspore/core/ops/split.cc b/mindspore/core/ops/split.cc index cd8d21775df..2d13b879865 100644 --- a/mindspore/core/ops/split.cc +++ b/mindspore/core/ops/split.cc @@ -27,10 +27,10 @@ void Split::Init(const std::vector &size_splits, const int64_t axis, co } void Split::set_size_splits(const std::vector &size_splits) { - this->AddAttr(kSizeSplits, MakeValue(size_splits)); + (void)this->AddAttr(kSizeSplits, MakeValue(size_splits)); } -void Split::set_axis(const int64_t axis) { this->AddAttr(kAxis, MakeValue(axis)); } -void Split::set_output_num(const int64_t output_num) { this->AddAttr(kOutputNum, MakeValue(output_num)); } +void Split::set_axis(const int64_t axis) { (void)this->AddAttr(kAxis, MakeValue(axis)); } +void Split::set_output_num(const int64_t output_num) { (void)this->AddAttr(kOutputNum, MakeValue(output_num)); } std::vector Split::get_size_splits() const { auto value_ptr = GetAttr(kSizeSplits); diff --git a/mindspore/core/ops/split_with_overlap.cc b/mindspore/core/ops/split_with_overlap.cc index a7d1efa1c84..d81863de741 100644 --- a/mindspore/core/ops/split_with_overlap.cc +++ b/mindspore/core/ops/split_with_overlap.cc @@ -31,25 +31,29 @@ void SplitWithOverlap::Init(int64_t number_split, const std::vector &ra this->set_trans_format(trans_format); } -void SplitWithOverlap::set_ratio(const std::vector &ratio) { this->AddAttr(kRatio, MakeValue(ratio)); } +void SplitWithOverlap::set_ratio(const std::vector &ratio) { (void)this->AddAttr(kRatio, MakeValue(ratio)); } void SplitWithOverlap::set_extend_top(const std::vector &extend_top) { - this->AddAttr(kExtendTop, MakeValue(extend_top)); + (void)this->AddAttr(kExtendTop, MakeValue(extend_top)); } void SplitWithOverlap::set_extend_bottom(const std::vector &extend_bottom) { - this->AddAttr(kExtendBottom, MakeValue(extend_bottom)); + (void)this->AddAttr(kExtendBottom, MakeValue(extend_bottom)); } -void SplitWithOverlap::set_number_split(int64_t number_split) { this->AddAttr(kNumberSplit, MakeValue(number_split)); } +void SplitWithOverlap::set_number_split(int64_t number_split) { + (void)this->AddAttr(kNumberSplit, MakeValue(number_split)); +} -void SplitWithOverlap::set_split_dim(int64_t split_dim) { this->AddAttr(kSplitDim, MakeValue(split_dim)); } +void SplitWithOverlap::set_split_dim(int64_t split_dim) { (void)this->AddAttr(kSplitDim, MakeValue(split_dim)); } -void SplitWithOverlap::set_split_stride(int64_t stride) { this->AddAttr(kSplitStride, MakeValue(stride)); } +void SplitWithOverlap::set_split_stride(int64_t stride) { (void)this->AddAttr(kSplitStride, MakeValue(stride)); } -void SplitWithOverlap::set_pad_top(int64_t pad_top) { this->AddAttr(kPadTop, MakeValue(pad_top)); } +void SplitWithOverlap::set_pad_top(int64_t pad_top) { (void)this->AddAttr(kPadTop, MakeValue(pad_top)); } -void SplitWithOverlap::set_trans_format(bool trans_format) { this->AddAttr(kTransFormat, MakeValue(trans_format)); } +void SplitWithOverlap::set_trans_format(bool trans_format) { + (void)this->AddAttr(kTransFormat, MakeValue(trans_format)); +} std::vector SplitWithOverlap::get_ratio() const { auto value_ptr = GetAttr(kRatio); diff --git a/mindspore/core/ops/squared_difference.cc b/mindspore/core/ops/squared_difference.cc index f7a9531181e..732d2fb4886 100644 --- a/mindspore/core/ops/squared_difference.cc +++ b/mindspore/core/ops/squared_difference.cc @@ -26,15 +26,11 @@ namespace mindspore { namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); auto op_name = primitive->name(); return BroadCastInferShape(op_name, input_args); } TypePtr InferType(const PrimitivePtr &prim, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } const std::set valid_types = {kInt32, kFloat16, kFloat32}; std::map types; types.emplace("x", input_args[0]->BuildType()); @@ -45,8 +41,11 @@ TypePtr InferType(const PrimitivePtr &prim, const std::vector & AbstractBasePtr SquaredDifferenceInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 2; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); return std::make_shared(InferType(primitive, input_args), - InferShape(primitive, input_args)->shape()); + InferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameSquaredDifference, SquaredDifference); } // namespace ops diff --git a/mindspore/core/ops/squeeze.cc b/mindspore/core/ops/squeeze.cc index f8ca859c8c1..fd0139d8599 100644 --- a/mindspore/core/ops/squeeze.cc +++ b/mindspore/core/ops/squeeze.cc @@ -19,7 +19,7 @@ namespace mindspore { namespace ops { void Squeeze::Init(const std::vector &axis) { set_axis(axis); } -void Squeeze::set_axis(const std::vector &axis) { AddAttr(kAxis, MakeValue(axis)); } +void Squeeze::set_axis(const std::vector &axis) { (void)AddAttr(kAxis, MakeValue(axis)); } std::vector Squeeze::get_axis() const { return GetValue>(GetAttr(kAxis)); } namespace { diff --git a/mindspore/core/ops/stack.cc b/mindspore/core/ops/stack.cc index 0e219cce612..9740a757ed7 100644 --- a/mindspore/core/ops/stack.cc +++ b/mindspore/core/ops/stack.cc @@ -57,7 +57,7 @@ abstract::AbstractBasePtr StackInfer(const PrimitivePtr &primitive, const std::v } } // namespace -void Stack::set_axis(const int64_t axis) { AddAttr(kAxis, MakeValue(axis)); } +void Stack::set_axis(const int64_t axis) { (void)AddAttr(kAxis, MakeValue(axis)); } int64_t Stack::get_axis() const { return GetValue(GetAttr(kAxis)); } diff --git a/mindspore/core/ops/strided_slice.cc b/mindspore/core/ops/strided_slice.cc index cd338595e8b..bc7d459e41e 100644 --- a/mindspore/core/ops/strided_slice.cc +++ b/mindspore/core/ops/strided_slice.cc @@ -35,13 +35,17 @@ void EllipsisInferShape(const PrimitivePtr &primitive, const std::vectorcast(); + MS_EXCEPTION_IF_NULL(strided_slice_prim); size_t x_rank = x_shape.size(); size_t slice_len = begin_v.size(); std::vector begin_pos = strided_slice_prim->TenToTwo(strided_slice_prim->get_begin_mask()); std::vector end_pos = strided_slice_prim->TenToTwo(strided_slice_prim->get_end_mask()); std::vector new_axis_pos = strided_slice_prim->TenToTwo(strided_slice_prim->get_new_axis_mask()); std::vector shrink_axis_pos = strided_slice_prim->TenToTwo(strided_slice_prim->get_shrink_axis_mask()); + (void)CheckAndConvertUtils::CheckInteger("infer", SizeToLong(new_axis_pos.size()), kGreaterEqual, + SizeToLong(slice_len), primitive->name()); size_t num = 0; for (size_t n = j + 1; n < slice_len; n++) { @@ -115,6 +119,10 @@ std::vector ComputeInferShape(const PrimitivePtr &primitive, const std: std::vector infer_shape; size_t slice_len = begin_v.size(); size_t x_rank = x_shape.size(); + (void)CheckAndConvertUtils::CheckInteger("end_v size", SizeToLong(end_v.size()), kGreaterEqual, SizeToLong(slice_len), + primitive->name()); + (void)CheckAndConvertUtils::CheckInteger("strides_v size", SizeToLong(strides_v.size()), kGreaterEqual, + SizeToLong(slice_len), primitive->name()); while (i < x_rank || j < slice_len) { int64_t x_dim_size = x_shape[i]; if (j < slice_len) { @@ -165,9 +173,16 @@ abstract::ShapePtr StridedSliceInferShape(const PrimitivePtr &primitive, MS_EXCEPTION_IF_NULL(primitive); auto strided_slice_prim = primitive->cast(); MS_EXCEPTION_IF_NULL(strided_slice_prim); - auto temp_begin_v = input_args[1]->cast()->BuildValue(); + auto tuple_begin_v = input_args[1]->cast(); + MS_EXCEPTION_IF_NULL(tuple_begin_v); + auto temp_begin_v = tuple_begin_v->BuildValue(); + MS_EXCEPTION_IF_NULL(temp_begin_v); auto begin_v = GetValue>(temp_begin_v); - auto temp_end_v = input_args[2]->cast()->BuildValue(); + + auto tuple_end_v = input_args[2]->cast(); + MS_EXCEPTION_IF_NULL(tuple_end_v); + auto temp_end_v = tuple_end_v->BuildValue(); + MS_EXCEPTION_IF_NULL(temp_end_v); auto end_v = GetValue>(temp_end_v); auto strides_v = CheckAndGetValidStrides(input_args[3]); @@ -191,18 +206,15 @@ abstract::ShapePtr StridedSliceInferShape(const PrimitivePtr &primitive, return std::make_shared(ret_in_shape, ret_min_shape, ret_max_shape); } -TypePtr StridedSliceInferType(const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto infer_type = input_args[0]->BuildType()->cast()->element(); - return infer_type; +TypePtr StridedSliceInferType(const PrimitivePtr &primitive, const std::vector &input_args) { + const int64_t x_index = 0; + return CheckAndConvertUtils::GetInputTensorType(input_args, x_index, primitive->name()); } } // namespace void StridedSlice::set_begin_mask(const int64_t begin_mask) { (void)CheckAndConvertUtils::CheckInteger(kBeginMask, begin_mask, kGreaterEqual, 0, this->name()); - this->AddAttr(kBeginMask, MakeValue(begin_mask)); + (void)this->AddAttr(kBeginMask, MakeValue(begin_mask)); } int64_t StridedSlice::get_begin_mask() const { auto value_ptr = GetAttr(kBeginMask); @@ -210,7 +222,7 @@ int64_t StridedSlice::get_begin_mask() const { } void StridedSlice::set_end_mask(const int64_t end_mask) { (void)CheckAndConvertUtils::CheckInteger(kEndMask, end_mask, kGreaterEqual, 0, this->name()); - this->AddAttr(kEndMask, MakeValue(end_mask)); + (void)this->AddAttr(kEndMask, MakeValue(end_mask)); } int64_t StridedSlice::get_end_mask() const { auto value_ptr = GetAttr(kEndMask); @@ -224,7 +236,7 @@ void StridedSlice::set_ellipsis_mask(const int64_t ellipsis_mask) { buffer << "For" << this->name() << ", only support one ellipsis in the index, but got " << this->get_end_mask(); MS_EXCEPTION(ValueError) << buffer.str(); } - this->AddAttr(kEllipsisMask, MakeValue(ellipsis_mask)); + (void)this->AddAttr(kEllipsisMask, MakeValue(ellipsis_mask)); } int64_t StridedSlice::get_ellipsis_mask() const { auto value_ptr = GetAttr(kEllipsisMask); @@ -232,7 +244,7 @@ int64_t StridedSlice::get_ellipsis_mask() const { } void StridedSlice::set_new_axis_mask(const int64_t new_axis_mask) { (void)CheckAndConvertUtils::CheckInteger(kNewAxisMask, new_axis_mask, kGreaterEqual, 0, this->name()); - this->AddAttr(kNewAxisMask, MakeValue(new_axis_mask)); + (void)this->AddAttr(kNewAxisMask, MakeValue(new_axis_mask)); } int64_t StridedSlice::get_new_axis_mask() const { auto value_ptr = GetAttr(kNewAxisMask); @@ -240,7 +252,7 @@ int64_t StridedSlice::get_new_axis_mask() const { } void StridedSlice::set_shrink_axis_mask(const int64_t shrink_axis_mask) { (void)CheckAndConvertUtils::CheckInteger(kShrinkAxisMask, shrink_axis_mask, kGreaterEqual, 0, this->name()); - this->AddAttr(kShrinkAxisMask, MakeValue(shrink_axis_mask)); + (void)this->AddAttr(kShrinkAxisMask, MakeValue(shrink_axis_mask)); } int64_t StridedSlice::get_shrink_axis_mask() const { auto value_ptr = GetAttr(kShrinkAxisMask); @@ -321,8 +333,11 @@ int64_t StridedSlice::compute_slicing_length(int64_t start_pos, int64_t end_pos, AbstractBasePtr StridedSliceInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { - return std::make_shared(StridedSliceInferType(input_args), - StridedSliceInferShape(primitive, input_args)->shape()); + MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 4; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); + return std::make_shared(StridedSliceInferType(primitive, input_args), + StridedSliceInferShape(primitive, input_args)); } REGISTER_PRIMITIVE_C(kNameStridedSlice, StridedSlice); } // namespace ops diff --git a/mindspore/core/ops/tensor_array.cc b/mindspore/core/ops/tensor_array.cc index fbfa2cde666..dcb000d70fd 100644 --- a/mindspore/core/ops/tensor_array.cc +++ b/mindspore/core/ops/tensor_array.cc @@ -40,18 +40,18 @@ void TensorArray::Init(bool dynamic_size, bool identical_element_shapes, const s } void TensorArray::set_dynamic_size(bool dynamic_size) { - this->AddAttr(kTensorArrayDynamicSize, MakeValue(dynamic_size)); + (void)this->AddAttr(kTensorArrayDynamicSize, MakeValue(dynamic_size)); } void TensorArray::set_identical_element_shapes(bool identical_element_shapes) { - this->AddAttr(kTensorArrayIdenticalElementShapes, MakeValue(identical_element_shapes)); + (void)this->AddAttr(kTensorArrayIdenticalElementShapes, MakeValue(identical_element_shapes)); } void TensorArray::set_element_shape(const std::vector &element_shape) { - this->AddAttr(kTensorArrayElementShape, MakeValue(element_shape)); + (void)this->AddAttr(kTensorArrayElementShape, MakeValue(element_shape)); } -void TensorArray::set_data_type(int data_type) { this->AddAttr(kTensorArrayDataType, MakeValue(data_type)); } +void TensorArray::set_data_type(int data_type) { (void)this->AddAttr(kTensorArrayDataType, MakeValue(data_type)); } bool TensorArray::get_dynamic_size() const { auto value_ptr = GetAttr(kTensorArrayDynamicSize); diff --git a/mindspore/core/ops/tensor_list_from_tensor.cc b/mindspore/core/ops/tensor_list_from_tensor.cc index 3d961720ea5..fc0a4f4d867 100644 --- a/mindspore/core/ops/tensor_list_from_tensor.cc +++ b/mindspore/core/ops/tensor_list_from_tensor.cc @@ -34,7 +34,7 @@ abstract::ShapePtr TensorListFromTensorInferShape(const PrimitivePtr &primitive, MS_LOG(ERROR) << "input[0] dim0:" << dim0 << " must be greater than or equal to 0!"; } auto input1 = &input1_shape[0]; - MS_ASSERT(input1 != nullptr); + MS_EXCEPTION_IF_NULL(input1); if (input1 == nullptr) { MS_LOG(ERROR) << "input1 is nullptr"; } @@ -63,11 +63,11 @@ int64_t TensorListFromTensor::get_shape_type() const { } void TensorListFromTensor::set_element_dtype(const int64_t element_dtype) { - this->AddAttr(kElement_dtype, MakeValue(element_dtype)); + (void)this->AddAttr(kElement_dtype, MakeValue(element_dtype)); } void TensorListFromTensor::set_shape_type(const int64_t shape_type) { - this->AddAttr(kShapeType, MakeValue(shape_type)); + (void)this->AddAttr(kShapeType, MakeValue(shape_type)); } AbstractBasePtr TensorListFromTensorInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, diff --git a/mindspore/core/ops/tensor_list_get_item.cc b/mindspore/core/ops/tensor_list_get_item.cc index 78c4743f7c8..2353ff76275 100644 --- a/mindspore/core/ops/tensor_list_get_item.cc +++ b/mindspore/core/ops/tensor_list_get_item.cc @@ -23,7 +23,7 @@ namespace ops { void TensorListGetItem::Init(const int64_t element_dtype) { this->set_element_dtype(element_dtype); } void TensorListGetItem::set_element_dtype(const int64_t element_dtype) { - this->AddAttr(kElement_dtype, MakeValue(element_dtype)); + (void)this->AddAttr(kElement_dtype, MakeValue(element_dtype)); } int64_t TensorListGetItem::get_element_dtype() const { diff --git a/mindspore/core/ops/tensor_list_reserve.cc b/mindspore/core/ops/tensor_list_reserve.cc index c1efa6f796c..a5fc1a5f71e 100644 --- a/mindspore/core/ops/tensor_list_reserve.cc +++ b/mindspore/core/ops/tensor_list_reserve.cc @@ -1,5 +1,5 @@ /** - * Copyright 2020 Huawei Technologies Co., Ltd + * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,12 @@ void TensorListReserve::Init(const int64_t element_dtype, const int64_t shape_ty } void TensorListReserve::set_element_dtype(const int64_t element_dtype) { - this->AddAttr(kElement_dtype, MakeValue(element_dtype)); + (void)this->AddAttr(kElement_dtype, MakeValue(element_dtype)); } -void TensorListReserve::set_shape_type(const int64_t shape_type) { this->AddAttr(kShapeType, MakeValue(shape_type)); } +void TensorListReserve::set_shape_type(const int64_t shape_type) { + (void)this->AddAttr(kShapeType, MakeValue(shape_type)); +} int64_t TensorListReserve::get_element_dtype() const { auto value_ptr = GetAttr(kElement_dtype); diff --git a/mindspore/core/ops/tensor_list_set_item.cc b/mindspore/core/ops/tensor_list_set_item.cc index a54b51c6fd1..d1653ad8f69 100644 --- a/mindspore/core/ops/tensor_list_set_item.cc +++ b/mindspore/core/ops/tensor_list_set_item.cc @@ -23,7 +23,7 @@ namespace ops { void TensorListSetItem::Init(const int64_t element_dtype) { this->set_element_dtype(element_dtype); } void TensorListSetItem::set_element_dtype(const int64_t element_dtype) { - this->AddAttr(kElement_dtype, MakeValue(element_dtype)); + (void)this->AddAttr(kElement_dtype, MakeValue(element_dtype)); } int64_t TensorListSetItem::get_element_dtype() const { diff --git a/mindspore/core/ops/tensor_list_stack.cc b/mindspore/core/ops/tensor_list_stack.cc index f22182b3315..390b3d576ed 100644 --- a/mindspore/core/ops/tensor_list_stack.cc +++ b/mindspore/core/ops/tensor_list_stack.cc @@ -29,11 +29,11 @@ void TensorListStack::Init(const int64_t num_elements, const int64_t element_dty } void TensorListStack::set_num_elements(const int64_t num_elements) { - this->AddAttr(kNumElements, MakeValue(num_elements)); + (void)this->AddAttr(kNumElements, MakeValue(num_elements)); } void TensorListStack::set_element_dtype(const int64_t element_dtype) { - this->AddAttr(kElement_dtype, MakeValue(element_dtype)); + (void)this->AddAttr(kElement_dtype, MakeValue(element_dtype)); } int64_t TensorListStack::get_num_elements() const { diff --git a/mindspore/core/ops/tensor_summary.cc b/mindspore/core/ops/tensor_summary.cc index 802b7966515..f8da6dadb3f 100644 --- a/mindspore/core/ops/tensor_summary.cc +++ b/mindspore/core/ops/tensor_summary.cc @@ -30,11 +30,11 @@ abstract::ShapePtr TensorSummaryInferShape(const PrimitivePtr &primitive, auto prim_name = primitive->name(); // check auto v_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("v rank", v_shape.size(), kGreaterEqual, 1, prim_name); + (void)CheckAndConvertUtils::CheckInteger("v rank", v_shape.size(), kGreaterEqual, 1, prim_name); return std::make_shared(ShapeVector(1)); } } // namespace -void TensorSummary::set_side_effect_io() { this->AddAttr(kSideEffectIO, MakeValue(true)); } +void TensorSummary::set_side_effect_io() { (void)this->AddAttr(kSideEffectIO, MakeValue(true)); } bool TensorSummary::get_side_effect_io() const { auto value_ptr = GetAttr(kSideEffectIO); diff --git a/mindspore/core/ops/tile.cc b/mindspore/core/ops/tile.cc index 2ef5d0d8d42..400267db814 100644 --- a/mindspore/core/ops/tile.cc +++ b/mindspore/core/ops/tile.cc @@ -53,7 +53,7 @@ abstract::ShapePtr TileInferShape(const PrimitivePtr &primitive, const std::vect MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); const int INDEX = 2; - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, INDEX, prim_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, INDEX, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } @@ -76,7 +76,7 @@ abstract::ShapePtr TileInferShape(const PrimitivePtr &primitive, const std::vect TypePtr TileInferType(const PrimitivePtr &prim, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(prim); auto prim_name = prim->name(); - CheckAndConvertUtils::CheckInteger("tile_prim_infer", input_args.size(), kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger("tile_prim_infer", input_args.size(), kEqual, 2, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); } diff --git a/mindspore/core/ops/to_format.cc b/mindspore/core/ops/to_format.cc index 78f4ac51ab3..d4501b07011 100644 --- a/mindspore/core/ops/to_format.cc +++ b/mindspore/core/ops/to_format.cc @@ -26,13 +26,13 @@ namespace mindspore { namespace ops { -void ToFormat::set_src_t(const int64_t src_t) { this->AddAttr(kSrcT, MakeValue(src_t)); } +void ToFormat::set_src_t(const int64_t src_t) { (void)this->AddAttr(kSrcT, MakeValue(src_t)); } int64_t ToFormat::get_src_t() const { auto value_ptr = GetAttr(kSrcT); return GetValue(value_ptr); } -void ToFormat::set_dst_t(const int64_t dst_t) { this->AddAttr(kDstT, MakeValue(dst_t)); } +void ToFormat::set_dst_t(const int64_t dst_t) { (void)this->AddAttr(kDstT, MakeValue(dst_t)); } int64_t ToFormat::get_dst_t() const { auto value_ptr = GetAttr(kDstT); return GetValue(value_ptr); diff --git a/mindspore/core/ops/unpack.cc b/mindspore/core/ops/unpack.cc index 2c5abf64f6b..2a7a19a7667 100644 --- a/mindspore/core/ops/unpack.cc +++ b/mindspore/core/ops/unpack.cc @@ -19,7 +19,7 @@ namespace mindspore { namespace ops { void Unpack::Init(const int64_t axis) { this->set_axis(axis); } -void Unpack::set_axis(const int64_t axis) { AddAttr(kAxis, MakeValue(axis)); } +void Unpack::set_axis(const int64_t axis) { (void)AddAttr(kAxis, MakeValue(axis)); } int64_t Unpack::get_axis() const { return GetValue(GetAttr(kAxis)); } AbstractBasePtr UnpackInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, diff --git a/mindspore/core/ops/unsorted_segment_sum.cc b/mindspore/core/ops/unsorted_segment_sum.cc index 670f8e57d36..8a6f914fd54 100644 --- a/mindspore/core/ops/unsorted_segment_sum.cc +++ b/mindspore/core/ops/unsorted_segment_sum.cc @@ -34,7 +34,7 @@ AbstractBasePtr UnsortedSegmentSumInfer(const abstract::AnalysisEnginePtr &, con auto x_type = input_args[0]->BuildType()->cast()->element(); // Infer shape auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - CheckAndConvertUtils::CheckInteger("x_shape", SizeToLong(x_shape.size()), kGreaterThan, 0, prim_name); + (void)CheckAndConvertUtils::CheckInteger("x_shape", SizeToLong(x_shape.size()), kGreaterThan, 0, prim_name); auto shp = x_shape; auto segment_ids_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; (void)CheckAndConvertUtils::CheckInteger("segment_ids_shape", SizeToLong(segment_ids_shape.size()), kGreaterThan, 0, diff --git a/mindspore/core/ops/unstack.cc b/mindspore/core/ops/unstack.cc index e1cdf20f4ed..29f4a8eca2d 100644 --- a/mindspore/core/ops/unstack.cc +++ b/mindspore/core/ops/unstack.cc @@ -19,7 +19,7 @@ namespace mindspore { namespace ops { void Unstack::Init(const int64_t axis) { this->set_axis(axis); } -void Unstack::set_axis(const int64_t axis) { AddAttr(kAxis, MakeValue(axis)); } +void Unstack::set_axis(const int64_t axis) { (void)AddAttr(kAxis, MakeValue(axis)); } int64_t Unstack::get_axis() const { return GetValue(GetAttr(kAxis)); } AbstractBasePtr UnstackInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, const std::vector &input_args) { diff --git a/mindspore/core/ops/where.cc b/mindspore/core/ops/where.cc index 67758a822f3..53996def932 100644 --- a/mindspore/core/ops/where.cc +++ b/mindspore/core/ops/where.cc @@ -29,7 +29,7 @@ AbstractBasePtr WhereInfer(const abstract::AnalysisEnginePtr &, const PrimitiveP MS_EXCEPTION_IF_NULL(input); } auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kGreaterEqual, 3, op_name); + (void)CheckAndConvertUtils::CheckInteger("input numbers", input_args.size(), kGreaterEqual, 3, op_name); auto input0_type_ = input_args[0]->BuildType()->cast(); MS_EXCEPTION_IF_NULL(input0_type_); auto input0_type = input0_type_->element(); diff --git a/mindspore/core/ops/zeros_like.cc b/mindspore/core/ops/zeros_like.cc index d0b54b2de71..1eca8b5a390 100644 --- a/mindspore/core/ops/zeros_like.cc +++ b/mindspore/core/ops/zeros_like.cc @@ -29,7 +29,7 @@ namespace ops { namespace { abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { auto op_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("infer_shape", SizeToLong(input_args.size()), kGreaterEqual, 1, op_name); + (void)CheckAndConvertUtils::CheckInteger("infer_shape", SizeToLong(input_args.size()), kGreaterEqual, 1, op_name); return CheckAndConvertUtils::GetTensorInputShape(op_name, input_args, 0); } @@ -45,6 +45,8 @@ TypePtr InferType(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); + const int64_t input_num = 1; + CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name()); return abstract::MakeAbstract(InferShape(primitive, input_args), InferType(primitive, input_args)); } REGISTER_PRIMITIVE_EVAL_IMPL(ZerosLike, prim::kPrimZerosLike, ZerosLikeInfer, nullptr, true); diff --git a/mindspore/core/utils/check_convert_utils.cc b/mindspore/core/utils/check_convert_utils.cc index a4ac0ebbabb..e5553cf2ab1 100644 --- a/mindspore/core/utils/check_convert_utils.cc +++ b/mindspore/core/utils/check_convert_utils.cc @@ -385,6 +385,39 @@ int64_t CheckAndConvertUtils::CheckInteger(const std::string &arg_name, int64_t MS_EXCEPTION(ValueError) << buffer.str(); } +void CheckAndConvertUtils::CheckInputArgs(const std::vector &input_args, + const CompareEnum compare_operator, const int64_t match_value, + const std::string &prim_name) { + (void)CheckInteger("input number", SizeToLong(input_args.size()), compare_operator, match_value, prim_name); + for (size_t index = 0; index < input_args.size(); index++) { + if (input_args[index] == nullptr) { + MS_EXCEPTION(ValueError) << "The " << index << "'s input of " << prim_name << " is nullptr."; + } + } +} + +TypePtr CheckAndConvertUtils::GetInputTensorType(const std::vector &input_args, const size_t index, + const std::string &prim_name) { + if (input_args.size() <= index) { + MS_EXCEPTION(ValueError) << "For " << prim_name << ", the index " << index << " is out of the input number " + << input_args.size(); + } + auto input_arg = input_args[index]; + if (input_arg == nullptr) { + MS_EXCEPTION(ValueError) << "The " << index << "'s input of " << prim_name << " is nullptr."; + } + auto base_type = input_arg->BuildType(); + MS_EXCEPTION_IF_NULL(base_type); + if (!base_type->isa()) { + MS_EXCEPTION(ValueError) << "The " << index << "'s input type of " << prim_name << " is not Tensor."; + } + auto tensor_type = base_type->cast(); + MS_EXCEPTION_IF_NULL(tensor_type); + auto type = tensor_type->element(); + MS_EXCEPTION_IF_NULL(type); + return type; +} + ShapeMap CheckAndConvertUtils::ConvertShapePtrToShapeMap(const BaseShapePtr &shape) { MS_EXCEPTION_IF_NULL(shape); if (!shape->isa()) { diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h index 435966c2c32..ac7aa08a8c0 100644 --- a/mindspore/core/utils/check_convert_utils.h +++ b/mindspore/core/utils/check_convert_utils.h @@ -308,6 +308,10 @@ class CheckAndConvertUtils { static void CheckMinMaxShape(const ShapeVector &shape, ShapeVector *min_shape, ShapeVector *max_shape); static int64_t GetAndCheckFormat(const ValuePtr &value); static size_t GetRemoveMonadAbsNum(const AbstractBasePtrList &abs_list); + static void CheckInputArgs(const std::vector &input_args, const CompareEnum compare_operator, + const int64_t match_value, const std::string &prim_name); + static TypePtr GetInputTensorType(const std::vector &input_args, const size_t index, + const std::string &prim_name); private: static bool IsEqualVector(const std::vector &vec_1, const std::vector &vec_2); diff --git a/mindspore/nn/optim/ada_grad.py b/mindspore/nn/optim/ada_grad.py index 663cbf6536f..bccc162dda8 100644 --- a/mindspore/nn/optim/ada_grad.py +++ b/mindspore/nn/optim/ada_grad.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2021 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -151,7 +151,6 @@ class Adagrad(Optimizer): super(Adagrad, self).__init__(learning_rate, params, weight_decay, loss_scale) _check_param_value(accum, update_slots, self.cls_name) self.accum = self.parameters.clone(prefix="accum", init=accum) - self.update_slots = update_slots self.opt = P.ApplyAdagrad(update_slots=update_slots) def construct(self, grads): diff --git a/mindspore/nn/optim/adam.py b/mindspore/nn/optim/adam.py index 008b1f92a50..7dcf7b3a7e2 100755 --- a/mindspore/nn/optim/adam.py +++ b/mindspore/nn/optim/adam.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2021 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -632,8 +632,6 @@ class AdamOffload(Optimizer): self.beta1_power = Parameter(initializer(1, [1], mstype.float32), name="beta1_power") self.beta2_power = Parameter(initializer(1, [1], mstype.float32), name="beta2_power") self.eps = Tensor(eps, mstype.float32) - self.use_nesterov = use_nesterov - self.use_locking = use_locking self.moment1 = self.parameters.clone(prefix="moment1", init='zeros') self.moment2 = self.parameters.clone(prefix="moment2", init='zeros') self.opt = P.AdamNoUpdateParam(use_locking, use_nesterov) diff --git a/mindspore/nn/optim/ftrl.py b/mindspore/nn/optim/ftrl.py index e3d118c9526..61c472893b4 100644 --- a/mindspore/nn/optim/ftrl.py +++ b/mindspore/nn/optim/ftrl.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2021 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/mindspore/nn/optim/lars.py b/mindspore/nn/optim/lars.py index fbd8a8c484a..f8336daf185 100755 --- a/mindspore/nn/optim/lars.py +++ b/mindspore/nn/optim/lars.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2021 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/mindspore/nn/optim/momentum.py b/mindspore/nn/optim/momentum.py index aacd32b9bec..39b40d4ac18 100755 --- a/mindspore/nn/optim/momentum.py +++ b/mindspore/nn/optim/momentum.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2021 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/mindspore/nn/optim/optimizer.py b/mindspore/nn/optim/optimizer.py index ad11699daa6..a5a83dc8d15 100644 --- a/mindspore/nn/optim/optimizer.py +++ b/mindspore/nn/optim/optimizer.py @@ -1,4 +1,4 @@ -# Copyright 2020 Huawei Technologies Co., Ltd +# Copyright 2020-2021 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -123,7 +123,7 @@ class Optimizer(Cell): ValueError: If `learning_rate` is a Tensor, but the dimension of tensor is greater than 1. Supported Platforms: - ``Ascend`` ``GPU`` + ``Ascend`` ``GPU`` ``CPU`` """ def __init__(self, learning_rate, parameters, weight_decay=0.0, loss_scale=1.0): @@ -272,11 +272,14 @@ class Optimizer(Cell): raise ValueError("The value must be 'CPU', 'Ascend' or 'GPU', but got value {}".format(value)) if self._target == "CPU" and value in ('Ascend', 'GPU'): - raise ValueError("In the CPU environment, target cannot be set to 'GPU' and 'Ascend'.") + raise ValueError("In the CPU environment, target cannot be set to 'GPU' or 'Ascend'.") if self._target == "Ascend" and value == 'GPU': raise ValueError("In the Ascend environment, target cannot be set to 'GPU'.") + if self._target == "GPU" and value == 'Ascend': + raise ValueError("In the GPU environment, target cannot be set to 'Ascend'.") + self._is_device = (value != 'CPU') self._target = value @@ -380,7 +383,7 @@ class Optimizer(Cell): f"but got {learning_rate.ndim}.") if learning_rate.ndim == 1 and learning_rate.size < 2: logger.warning("If use `Tensor` type dynamic learning rate, please make sure that the number" - "of elements in the tensor passed is greater than 1.") + "of elements in the tensor is greater than 1.") return learning_rate if isinstance(learning_rate, LearningRateSchedule): return learning_rate @@ -503,7 +506,8 @@ class Optimizer(Cell): for param in group_param['params']: validator.check_value_type("parameter", param, [Parameter], self.cls_name) if param.name in params_store: - raise RuntimeError(f"The {param.name} parameter has appeared in parameter groups.") + raise RuntimeError(f"The {param.name} parameter already exists in parameter groups, " + f"duplicate parameters are not supported.") params_store.append(param.name) self.group_lr.append(lr) @@ -767,7 +771,7 @@ class _IteratorLearningRate(LearningRateSchedule): super(_IteratorLearningRate, self).__init__() if isinstance(learning_rate, Tensor): if learning_rate.ndim != 1: - raise ValueError("The dim of `Tensor` type dynamic learning rate should be a 1," + raise ValueError("The dim of `Tensor` type dynamic learning rate should be 1, " f"but got {learning_rate.ndim}.") else: raise TypeError("Learning rate should be Tensor.")