From 9d5264a78e4f96e667a2ff975f77e3da6f3ad481 Mon Sep 17 00:00:00 2001 From: gaopan12 Date: Wed, 16 Mar 2022 21:24:27 +0800 Subject: [PATCH] [misc] [assistant] remove unused code --- mindspore/core/ops/arg_max.cc | 33 ------- mindspore/core/ops/arg_min.cc | 26 ------ mindspore/core/ops/assert.cc | 45 ---------- mindspore/core/ops/avg_pool.cc | 57 ------------ mindspore/core/ops/batch_norm.cc | 65 -------------- mindspore/core/ops/batch_to_space.cc | 37 -------- mindspore/core/ops/broadcast.cc | 21 +---- mindspore/core/ops/concat.cc | 46 ---------- mindspore/core/ops/constant_of_shape.cc | 23 +---- mindspore/core/ops/crop.cc | 16 +--- mindspore/core/ops/cumsum.cc | 16 +--- mindspore/core/ops/custom_extract_features.cc | 23 ----- mindspore/core/ops/custom_normalize.cc | 35 -------- mindspore/core/ops/custom_predict.cc | 14 --- mindspore/core/ops/detection_post_process.cc | 46 ---------- mindspore/core/ops/div.cc | 23 ----- mindspore/core/ops/dropout.cc | 20 ----- mindspore/core/ops/dynamic_quant.cc | 18 +--- mindspore/core/ops/embedding_lookup.cc | 44 ---------- mindspore/core/ops/expand_dims.cc | 25 ------ .../core/ops/fake_quant_with_min_max_vars.cc | 41 +-------- ...ake_quant_with_min_max_vars_per_channel.cc | 27 ------ mindspore/core/ops/fft_imag.cc | 17 ---- mindspore/core/ops/fft_real.cc | 13 --- mindspore/core/ops/fill.cc | 40 --------- mindspore/core/ops/fusion/add_fusion.cc | 24 ----- mindspore/core/ops/fusion/avg_pool_fusion.cc | 60 ------------- mindspore/core/ops/fusion/full_connection.cc | 60 +------------ mindspore/core/ops/fusion/max_pool_fusion.cc | 56 ------------ mindspore/core/ops/fusion/pow_fusion.cc | 28 ------ mindspore/core/ops/fusion/slice_fusion.cc | 34 -------- mindspore/core/ops/grad/avg_pool_grad.cc | 10 --- .../ops/grad/binary_cross_entropy_grad.cc | 41 --------- mindspore/core/ops/grad/einsum_grad.cc | 24 ----- mindspore/core/ops/grad/flatten_grad.cc | 18 ---- .../core/ops/grad/group_conv2d_grad_input.cc | 22 ----- mindspore/core/ops/grad/lstm_grad.cc | 15 ---- mindspore/core/ops/grad/lstm_grad_data.cc | 15 ---- mindspore/core/ops/grad/lstm_grad_weight.cc | 15 ---- mindspore/core/ops/grad/max_pool_grad.cc | 9 -- mindspore/core/ops/hashtable_lookup.cc | 22 ----- mindspore/core/ops/l2_normalize.cc | 18 ---- mindspore/core/ops/leaky_relu.cc | 25 ------ mindspore/core/ops/lrn.cc | 29 ------- mindspore/core/ops/lsh_projection.cc | 35 -------- mindspore/core/ops/mat_mul.cc | 87 ------------------- mindspore/core/ops/max_pool.cc | 68 --------------- mindspore/core/ops/mfcc.cc | 31 ------- mindspore/core/ops/minimum.cc | 28 ------ mindspore/core/ops/non_max_suppression.cc | 5 -- mindspore/core/ops/pack.cc | 43 --------- mindspore/core/ops/pad.cc | 40 +-------- mindspore/core/ops/prelu.cc | 36 -------- mindspore/core/ops/prior_box.cc | 24 ----- mindspore/core/ops/quant_dtype_cast.cc | 18 +--- mindspore/core/ops/range.cc | 45 ---------- mindspore/core/ops/rank.cc | 15 ---- mindspore/core/ops/reduce.cc | 67 -------------- mindspore/core/ops/reshape.cc | 74 ---------------- mindspore/core/ops/resize_bilinear.cc | 18 ---- mindspore/core/ops/reverse_sequence.cc | 33 +------ mindspore/core/ops/reverse_v2.cc | 23 ----- mindspore/core/ops/rfft.cc | 24 ----- mindspore/core/ops/roi_pooling.cc | 24 ----- mindspore/core/ops/scatter_nd.cc | 33 ------- mindspore/core/ops/skip_gram.cc | 26 ------ mindspore/core/ops/space_to_batch.cc | 39 +-------- mindspore/core/ops/space_to_batch_nd.cc | 41 --------- ...parse_softmax_cross_entropy_with_logits.cc | 23 ----- mindspore/core/ops/sparse_to_dense.cc | 15 ---- mindspore/core/ops/stack.cc | 51 ----------- mindspore/core/ops/tensor_list_from_tensor.cc | 30 ------- mindspore/core/ops/tensor_list_stack.cc | 18 ---- mindspore/core/ops/topk.cc | 28 ------ mindspore/core/ops/unpack.cc | 29 ------- mindspore/core/ops/unsorted_segment_sum.cc | 39 --------- mindspore/core/ops/unsqueeze.cc | 39 --------- mindspore/core/ops/unstack.cc | 28 +----- mindspore/core/ops/where.cc | 43 --------- 79 files changed, 12 insertions(+), 2504 deletions(-) diff --git a/mindspore/core/ops/arg_max.cc b/mindspore/core/ops/arg_max.cc index 69e904271b7..110a4ba40ff 100644 --- a/mindspore/core/ops/arg_max.cc +++ b/mindspore/core/ops/arg_max.cc @@ -18,34 +18,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr ArgMaxInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - auto axis = GetValue(primitive->GetAttr(kAxis)); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto x_rank = SizeToLong(x_shape.size()); - CheckAndConvertUtils::CheckInRange("argmax axis", axis, kIncludeLeft, {-x_rank, x_rank}, prim_name); - axis = axis < 0 ? axis + x_rank : axis; - std::vector out_shape; - for (size_t i = 0; i < x_shape.size(); ++i) { - if (SizeToLong(i) != axis) { - (void)out_shape.emplace_back(x_shape[i]); - } - } - return std::make_shared(out_shape); -} - -TypePtr ArgMaxInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 1, prim->name()); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - return kInt32; -} -} // namespace - void ArgMax::Init(const int64_t axis, const TypeId output_type) { set_axis(axis); set_output_type(output_type); @@ -60,11 +32,6 @@ TypeId ArgMax::get_output_type() const { return type_ptr->type_id(); } -AbstractBasePtr ArgMaxInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(ArgMaxInferType(primitive, input_args), - ArgMaxInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameArgMax, ArgMax); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/arg_min.cc b/mindspore/core/ops/arg_min.cc index d46a3076fd7..1b97e51febf 100644 --- a/mindspore/core/ops/arg_min.cc +++ b/mindspore/core/ops/arg_min.cc @@ -34,32 +34,6 @@ TypeId ArgMin::get_output_type() const { return type_ptr->type_id(); } -AbstractBasePtr ArgMinInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("arg_min_infer", SizeToLong(input_args.size()), kEqual, 1, prim_name); - - // Infer shape - auto axis = GetValue(primitive->GetAttr(kAxis)); - MS_EXCEPTION_IF_NULL(input_args[0]); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto x_rank = SizeToLong(x_shape.size()); - CheckAndConvertUtils::CheckInRange("axis", axis, kIncludeLeft, {-x_rank, x_rank}, prim_name); - if (axis < 0) { - axis += x_rank; - } - std::vector out_shape; - for (int64_t i = 0; i < x_rank; i++) { - if (i != axis) { - out_shape.push_back(x_shape[LongToSize(i)]); - } - } - - // Infer type - auto x_dtype = input_args[0]->BuildType()->cast()->element(); - return std::make_shared(x_dtype, std::make_shared(out_shape)); -} REGISTER_PRIMITIVE_C(kNameArgMin, ArgMin); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/assert.cc b/mindspore/core/ops/assert.cc index 3012d11c842..f65247e6643 100644 --- a/mindspore/core/ops/assert.cc +++ b/mindspore/core/ops/assert.cc @@ -34,51 +34,6 @@ int64_t Assert::get_summarize() const { return GetValue(value_ptr); } -AbstractBasePtr AssertInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto op_name = primitive->name(); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - TypePtr condition; - if (!(input_args[0]->BuildType()->type_id() == kObjectTypeTensorType)) { - auto condition_values = GetValue>(input_args[0]->BuildValue()); - (void)CheckAndConvertUtils::CheckInteger("condition's rank", SizeToLong(condition_values.size()), kLessEqual, 1, - op_name); - if (condition_values.size() == 1) { - if (!condition_values[0]) { - MS_EXCEPTION(ValueError) << "For '" << op_name - << "', condition value must be `true` when only one value contained, but got " - << !condition_values[0]; - } - } - condition = TypeIdToType(kNumberTypeBool); - } else { - auto condition_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("condition's rank", condition_shape[0], kLessEqual, 1, op_name); - if (condition_shape[0] == 1) { - auto condition_value = reinterpret_cast(input_args[0]->BuildValue()->cast()->data_c()); - MS_EXCEPTION_IF_NULL(condition_value); - if (!*condition_value) { - MS_EXCEPTION(ValueError) << "For '" << op_name - << "', condition value must be `true` when only one value contained, but got " - << !*condition_value; - } - } - condition = input_args[0]->BuildType(); - } - std::vector output_shape = {1}; - std::set local_bool = {kBool}; - std::map args = {{"condition", condition}}; - (void)CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args, local_bool, op_name); - auto inputs_type = input_args[1]->BuildType()->cast()->elements(); - for (auto dtype : inputs_type) { - std::set template_types = {kTensorType}; - (void)CheckAndConvertUtils::CheckSubClass("input", dtype, template_types, op_name); - } - return std::make_shared(kInt32, output_shape); -} REGISTER_PRIMITIVE_C(kNameAssert, Assert); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/avg_pool.cc b/mindspore/core/ops/avg_pool.cc index 6dbe3044b44..5b5a509da41 100644 --- a/mindspore/core/ops/avg_pool.cc +++ b/mindspore/core/ops/avg_pool.cc @@ -78,63 +78,6 @@ void AvgPool::Init(const std::vector &kernel_size, const std::vectorset_round_mode(round_mode); } -namespace { -abstract::ShapePtr AvgPoolInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - auto op_name = primitive->name(); - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - auto format = Format(GetValue(primitive->GetAttr(kFormat))); - const int64_t x_size = 4; - const int64_t attr_size = 4; - (void)CheckAndConvertUtils::CheckInteger("x_rank", SizeToLong(in_shape.size()), kEqual, x_size, op_name); - if (format == NHWC) { - in_shape = {in_shape[0], in_shape[3], in_shape[1], in_shape[2]}; - } - auto kernel_size = GetValue>(primitive->GetAttr(kKernelSize)); - auto pad_mode = PadMode(GetValue(primitive->GetAttr(kPadMode))); - auto batch = in_shape[0]; - auto channel = in_shape[1]; - auto in_h = in_shape[2]; - auto in_w = in_shape[3]; - auto strides = GetValue>(primitive->GetAttr(kStrides)); - (void)CheckAndConvertUtils::CheckInteger("kernel size", SizeToLong(kernel_size.size()), kEqual, attr_size, op_name); - (void)CheckAndConvertUtils::CheckInteger("strides size", SizeToLong(strides.size()), kEqual, attr_size, op_name); - if (std::any_of(strides.begin(), strides.end(), [](int64_t stride) { return stride <= 0; })) { - MS_LOG(EXCEPTION) << "For '" << op_name << "', strides must be positive, but it's " << strides << "."; - } - if (std::any_of(kernel_size.begin(), kernel_size.end(), [](int64_t size) { return size <= 0; })) { - MS_LOG(EXCEPTION) << "For '" << op_name << "', Kernel size must be positive, but it's " << kernel_size << "."; - } - 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 = abstract::Shape::SHP_ANY; - int64_t out_w = abstract::Shape::SHP_ANY; - if (pad_mode == VALID) { - out_h = static_cast(std::ceil((in_h - (kernel_h - 1)) / static_cast(stride_h))); - out_w = static_cast(std::ceil((in_w - (kernel_w - 1)) / static_cast(stride_w))); - } else if (pad_mode == SAME) { - out_h = static_cast(std::ceil(in_h / static_cast(stride_h))); - out_w = static_cast(std::ceil(in_w / static_cast(stride_w))); - } - std::vector out_shape = {batch, channel, out_h, out_w}; - if (format == NHWC) { - out_shape = {batch, out_h, out_w, channel}; - } - return std::make_shared(out_shape); -} - -TypePtr AvgPoolInferType(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(AvgPoolInferType(input_args), - AvgPoolInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameAvgPool, AvgPool); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/batch_norm.cc b/mindspore/core/ops/batch_norm.cc index bab5f10e6cd..2d48d8129e1 100644 --- a/mindspore/core/ops/batch_norm.cc +++ b/mindspore/core/ops/batch_norm.cc @@ -68,71 +68,6 @@ Format BatchNorm::get_format() const { return Format(GetValue(value_ptr)); } -AbstractBasePtr BatchNormInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - // Infer shape - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 5; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - - auto input_x = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto format = Format(GetValue(primitive->GetAttr(kFormat))); - if (format == NHWC) { - input_x = {input_x[0], input_x[3], input_x[1], input_x[2]}; - } - auto scale = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex1]->BuildShape())[kShape]; - auto bias = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex2]->BuildShape())[kShape]; - auto mean = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex3]->BuildShape())[kShape]; - auto variance = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex4]->BuildShape())[kShape]; - - std::vector input_shape_norm; - if (format == NCHW) { - input_shape_norm = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - } else { - input_shape_norm.push_back(input_x[0]); - input_shape_norm.push_back(input_x[3]); - input_shape_norm.push_back(input_x[1]); - input_shape_norm.push_back(input_x[2]); - } - (void)CheckAndConvertUtils::CheckInteger("scale rank", SizeToLong(scale.size()), kEqual, 1, prim_name); - CheckAndConvertUtils::Check("scale shape", scale, kEqual, bias, prim_name, TypeError); - CheckAndConvertUtils::Check("scale shape[0]", scale[0], kEqual, input_shape_norm[1], prim_name, TypeError); - - if (!GetValue(primitive->GetAttr(kIsTraining))) { - (void)CheckAndConvertUtils::CheckInteger("mean rank", SizeToLong(mean.size()), kEqual, 1, prim_name); - CheckAndConvertUtils::Check("mean shape", mean, kEqual, variance, prim_name, TypeError); - CheckAndConvertUtils::Check("mean shape", mean, kEqual, scale, prim_name, TypeError); - } - - // Infer type - auto scale_type = input_args[kInputIndex1]->BuildType()->cast()->element(); - auto bias_type = input_args[kInputIndex2]->BuildType()->cast()->element(); - - const std::set valid_types = {kFloat16, kFloat32}; - auto input_x_type = - CheckAndConvertUtils::CheckTensorTypeValid("x", input_args[kInputIndex0]->BuildType(), valid_types, prim_name); - std::map args; - (void)args.emplace("scale", input_args[kInputIndex1]->BuildType()); - (void)args.emplace("bias", input_args[kInputIndex2]->BuildType()); - (void)CheckAndConvertUtils::CheckTensorTypeSame(args, valid_types, prim_name); - std::map args_moving; - (void)args_moving.emplace("scale", input_args[kInputIndex2]->BuildType()); - (void)args_moving.emplace("bias", input_args[kInputIndex3]->BuildType()); - (void)CheckAndConvertUtils::CheckTensorTypeSame(args_moving, valid_types, prim_name); - - auto output0 = std::make_shared(input_x_type, input_x); - auto output1 = std::make_shared(scale_type, scale); - auto output2 = std::make_shared(bias_type, scale); - auto output3 = std::make_shared(input_x_type, scale); - if (format == NHWC) { - output2 = std::make_shared(scale_type, scale); - output3 = std::make_shared(bias_type, scale); - output1 = std::make_shared(input_x_type, scale); - } - AbstractBasePtrList output = {output0, output1, output2, output3, output3}; - return std::make_shared(output); -} REGISTER_PRIMITIVE_C(kNameBatchNorm, BatchNorm); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/batch_to_space.cc b/mindspore/core/ops/batch_to_space.cc index c2106914d02..86899bac3a0 100644 --- a/mindspore/core/ops/batch_to_space.cc +++ b/mindspore/core/ops/batch_to_space.cc @@ -44,43 +44,6 @@ std::vector> BatchToSpace::get_crops() const { return GetValue>>(value_ptr); } -AbstractBasePtr BatchToSpaceInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 1, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - (void)CheckAndConvertUtils::CheckTensorTypeValid("input_x", input_args[0]->BuildType(), common_valid_types, - prim_name); - - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto block_size = GetValue>(primitive->GetAttr(kBlockSize)); - auto crops = GetValue>>(primitive->GetAttr(kCrops)); - auto out_shape = x_shape; - const int64_t attr_size = 4; - const int64_t x_rank = 4; - (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kEqual, x_rank, prim_name); - (void)CheckAndConvertUtils::CheckInteger("block_size size", SizeToLong(block_size.size()), kEqual, attr_size, - prim_name); - (void)CheckAndConvertUtils::CheckInteger("crops size", SizeToLong(crops.size()), kEqual, attr_size, prim_name); - (void)CheckAndConvertUtils::CheckInteger("crops[0] size", SizeToLong(crops[0].size()), kEqual, attr_size, prim_name); - (void)CheckAndConvertUtils::CheckInteger("crops[1] size", SizeToLong(crops[1].size()), kEqual, attr_size, 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]; - CheckAndConvertUtils::Check("x block shape prod", x_block_prod, kGreaterThan, attr_size, prim_name); - out_shape[i + 2] = x_block_prod - crops_sum; - } - (void)CheckAndConvertUtils::CheckInteger("x_shape[0] % (block_size[0]*block_size[1])", - out_shape[0] % (block_size[0] * block_size[1]), kEqual, 0, prim_name); - out_shape[0] /= block_size[0] * block_size[1]; - - auto ret = input_args[0]->Broaden(); - ret->set_shape(std::make_shared(out_shape)); - return ret; -} REGISTER_PRIMITIVE_C(kNameBatchToSpace, BatchToSpace); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/broadcast.cc b/mindspore/core/ops/broadcast.cc index 3cc4d119947..6ba0a6fe0eb 100644 --- a/mindspore/core/ops/broadcast.cc +++ b/mindspore/core/ops/broadcast.cc @@ -42,26 +42,7 @@ std::string Broadcast::get_group() const { auto value_ptr = this->GetAttr(kGroup); return GetValue(value_ptr); } -AbstractBasePtr BroadcastInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - // infer shape - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - // infer type - auto x_type = input_args[0]->BuildType()->cast()->element(); - std::vector output_types; - const std::set valid_types = {kInt8, kInt32, kFloat16, kFloat32}; - for (size_t i = 0; i < input_args.size(); i++) { - auto out_type = input_args[i]->BuildType()->cast()->element(); - output_types.push_back(out_type); - (void)CheckAndConvertUtils::CheckTensorTypeValid("index_type", out_type, valid_types, prim_name); - } - return std::make_shared(x_type, in_shape); -} + REGISTER_PRIMITIVE_C(kNameBroadcast, Broadcast); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/concat.cc b/mindspore/core/ops/concat.cc index aabeeda2f0e..e2e3524126e 100644 --- a/mindspore/core/ops/concat.cc +++ b/mindspore/core/ops/concat.cc @@ -29,52 +29,6 @@ int64_t Concat::get_axis() const { void Concat::set_axis(const int64_t axis) { (void)this->AddAttr(kAxis, MakeValue(axis)); } -AbstractBasePtr ConcatInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 1, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto input_tuple = input_args[0]->cast(); - MS_EXCEPTION_IF_NULL(input_tuple); - auto elements = input_tuple->elements(); - const int64_t kOneNum = 1; - (void)CheckAndConvertUtils::CheckInteger("concat element num", SizeToLong(elements.size()), kGreaterEqual, kOneNum, - prim_name); - auto element0 = elements[0]->cast(); - MS_EXCEPTION_IF_NULL(element0); - auto element0_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(element0->BuildShape())[kShape]; - auto element0_rank = element0_shape.size(); - auto axis_temp = GetValue(primitive->GetAttr(kAxis)); - CheckAndConvertUtils::CheckInRange("Concat axis", axis_temp, kIncludeBoth, - {-SizeToLong(element0_rank) - kOneNum, SizeToLong(element0_rank)}, - prim_name); - auto axis = axis_temp < 0 ? LongToSize(axis_temp) + element0_rank : LongToSize(axis_temp); - - std::map types; - (void)types.emplace("element0", element0->BuildType()); - int64_t all_shp = element0_shape[axis]; - for (size_t i = 1; i < elements.size(); ++i) { - std::string elementi = "element" + std::to_string(i); - auto elementi_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(elements[i]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger(elementi + " shape rank", SizeToLong(elementi_shape.size()), kEqual, - SizeToLong(element0_shape.size()), prim_name); - for (size_t j = 0; j < element0_rank; ++j) { - if (j != axis && elementi_shape[j] != element0_shape[j]) { - MS_LOG(EXCEPTION) << "For '" << prim_name << "', element " << i - << " shape in input should concat with first element, but it can not."; - } - } - all_shp = all_shp == -1 || elementi_shape[axis] == -1 ? -1 : all_shp + elementi_shape[axis]; - (void)types.emplace(elementi, elements[i]->BuildType()); - } - auto infer_type = CheckAndConvertUtils::CheckTensorTypeSame(types, all_types, prim_name); - auto ret_shape = element0_shape; - ret_shape[axis] = all_shp; - return std::make_shared(infer_type, std::make_shared(ret_shape)); -} REGISTER_PRIMITIVE_C(kNameConcat, Concat); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/constant_of_shape.cc b/mindspore/core/ops/constant_of_shape.cc index 3e36814a07f..7dc0d6bb654 100644 --- a/mindspore/core/ops/constant_of_shape.cc +++ b/mindspore/core/ops/constant_of_shape.cc @@ -21,23 +21,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr ConstantOfShapeInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - (void)CheckAndConvertUtils::CheckInteger("input args size", SizeToLong(input_args.size()), kEqual, 1, - "ConstantOfShape"); - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - return std::make_shared(input_shape); -} - -TypePtr ConstantOfShapeInferType(const PrimitivePtr &primitive) { - MS_EXCEPTION_IF_NULL(primitive); - auto data_type = TypeId(GetValue(primitive->GetAttr(kDataType))); - return TypeIdToType(data_type); -} -} // namespace - void ConstantOfShape::Init(int64_t data_type, const std::vector &value) { this->set_data_type(data_type); this->set_value(value); @@ -56,11 +39,7 @@ std::vector ConstantOfShape::get_value() const { auto value_ptr = this->GetAttr(kValue); return GetValue>(value_ptr); } -AbstractBasePtr ConstantOfShapeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(ConstantOfShapeInferType(primitive), - ConstantOfShapeInferShape(primitive, input_args)->shape()); -} + REGISTER_PRIMITIVE_C(kNameConstantOfShape, ConstantOfShape); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/crop.cc b/mindspore/core/ops/crop.cc index b0a9d426672..123ca821c0d 100644 --- a/mindspore/core/ops/crop.cc +++ b/mindspore/core/ops/crop.cc @@ -40,21 +40,7 @@ std::vector Crop::get_offsets() const { auto value_ptr = this->GetAttr(kOffsets); return GetValue>(value_ptr); } -AbstractBasePtr CropInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - // infer shape - auto out_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - // infer type - auto x_type = input_args[0]->BuildType()->cast()->element(); - return std::make_shared(x_type, out_shape); -} + REGISTER_PRIMITIVE_C(kNameCrop, Crop); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/cumsum.cc b/mindspore/core/ops/cumsum.cc index 485fd4b37e9..9ea4dd17d70 100644 --- a/mindspore/core/ops/cumsum.cc +++ b/mindspore/core/ops/cumsum.cc @@ -40,21 +40,7 @@ bool CumSum::get_reverse() const { auto value_ptr = this->GetAttr(kReverse); return GetValue(value_ptr); } -AbstractBasePtr CumSumInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - // infer shape - auto out_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - // infer type - auto x_type = input_args[0]->BuildType()->cast()->element(); - return std::make_shared(x_type, out_shape); -} + REGISTER_PRIMITIVE_C(kNameCumSum, CumSum); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/custom_extract_features.cc b/mindspore/core/ops/custom_extract_features.cc index 43e88ea5bdc..ada6ea6ff16 100644 --- a/mindspore/core/ops/custom_extract_features.cc +++ b/mindspore/core/ops/custom_extract_features.cc @@ -21,29 +21,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr CustomExtractFeaturesInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - MS_EXCEPTION_IF_NULL(input_args[0]); - // Infer type - auto output0_type = kInt32; - auto output1_type = kFloat32; - - // Infer shape - std::vector out_shape; - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto string_num = input_shape[0]; - if (string_num == 0) { - out_shape.push_back(1); - } else { - out_shape.push_back(string_num); - } - - auto output0 = std::make_shared(output0_type, out_shape); - auto output1 = std::make_shared(output1_type, out_shape); - AbstractBasePtrList output = {output0, output1}; - return std::make_shared(output); -} REGISTER_PRIMITIVE_C(kNameCustomExtractFeatures, CustomExtractFeatures); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/custom_normalize.cc b/mindspore/core/ops/custom_normalize.cc index fd4d703d0a5..eb89a3eee8c 100644 --- a/mindspore/core/ops/custom_normalize.cc +++ b/mindspore/core/ops/custom_normalize.cc @@ -20,41 +20,6 @@ namespace mindspore { namespace ops { -namespace { -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(tensor_value->data_c()); - if (*string_num == 0) { - infer_shape.push_back(1); - } else { - infer_shape.push_back(*string_num); - } - return std::make_shared(infer_shape); -} - -TypePtr CustomNormalizeInferType(const std::vector &input_args) { - 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; -} -} // namespace - -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(input_args), - CustomNormalizeInferShape(input_args)); -} REGISTER_PRIMITIVE_C(kNameCustomNormalize, CustomNormalize); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/custom_predict.cc b/mindspore/core/ops/custom_predict.cc index 8a3911208a6..f17d1a59d0d 100644 --- a/mindspore/core/ops/custom_predict.cc +++ b/mindspore/core/ops/custom_predict.cc @@ -42,20 +42,6 @@ float CustomPredict::get_weight_threshold() const { return GetValue(value_ptr); } -AbstractBasePtr CustomPredictInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &input : input_args) { - MS_EXCEPTION_IF_NULL(input); - } - std::vector shape; - shape.push_back(GetValue(primitive->GetAttr(kOutputNum))); - - auto output0 = std::make_shared(kInt32, shape); - auto output1 = std::make_shared(kFloat32, shape); - AbstractBasePtrList output = {output0, output1}; - return std::make_shared(output); -} REGISTER_PRIMITIVE_C(kNameCustomPredict, CustomPredict); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/detection_post_process.cc b/mindspore/core/ops/detection_post_process.cc index a26a4b96f75..3ebf4e05a70 100644 --- a/mindspore/core/ops/detection_post_process.cc +++ b/mindspore/core/ops/detection_post_process.cc @@ -113,53 +113,7 @@ void DetectionPostProcess::set_format(const Format &format) { (void)this->AddAttr(kFormat, MakeValue(f)); } Format DetectionPostProcess::get_format() const { return Format(GetValue(GetAttr(kFormat))); } -AbstractBasePtr DetectionPostProcessInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 3; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - MS_EXCEPTION_IF_NULL(input_args[kInputIndex0]); - MS_EXCEPTION_IF_NULL(input_args[kInputIndex1]); - MS_EXCEPTION_IF_NULL(input_args[kInputIndex2]); - auto boxes = input_args[kInputIndex0]; - auto scores = input_args[kInputIndex1]; - auto anchors = input_args[kInputIndex2]; - auto boxes_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(boxes->BuildShape())[kShape]; - auto scores_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(scores->BuildShape())[kShape]; - auto anchors_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(anchors->BuildShape())[kShape]; - auto format = Format(GetValue(primitive->GetAttr(kFormat))); - if (format == NHWC) { - boxes_shape = {boxes_shape[0], boxes_shape[3], boxes_shape[1], boxes_shape[2]}; - scores_shape = {scores_shape[0], scores_shape[3], scores_shape[1], scores_shape[2]}; - anchors_shape = {anchors_shape[0], anchors_shape[3], anchors_shape[1], anchors_shape[2]}; - } - auto num_classes = GetValue(primitive->GetAttr(kNumClasses)); - CheckAndConvertUtils::CheckInRange("scores_shape[2]", scores_shape[2], kIncludeBoth, {num_classes, num_classes + 1}, - prim_name); - CheckAndConvertUtils::Check("boxes_shape[1]", boxes_shape[1], kEqual, scores_shape[1], prim_name, ValueError); - CheckAndConvertUtils::Check("boxes_shape[1]", boxes_shape[1], kEqual, anchors_shape[0], prim_name, ValueError); - // Infer shape - auto max_detections = GetValue(primitive->GetAttr(kMaxDetections)); - auto max_classes_per_detection = GetValue(primitive->GetAttr(kMaxClassesPerDetection)); - auto num_detected_boxes = max_detections * max_classes_per_detection; - std::vector output_boxes_shape = {1, num_detected_boxes, 4}; - std::vector output_class_shape = {1, num_detected_boxes}; - std::vector output_num_shape = {1}; - - // Infer type - auto output_type = kFloat32; - - auto output0 = std::make_shared(output_type, output_boxes_shape); - auto output1 = std::make_shared(output_type, output_class_shape); - auto output2 = std::make_shared(output_type, output_num_shape); - AbstractBasePtrList output = {output0, output1, output1, output2}; - if (format == NHWC) { - output = {output0, output1, output2, output1}; - } - return std::make_shared(output); -} REGISTER_PRIMITIVE_C(kNameDetectionPostProcess, DetectionPostProcess); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/div.cc b/mindspore/core/ops/div.cc index ade72d50e08..8cb5aa93c1b 100644 --- a/mindspore/core/ops/div.cc +++ b/mindspore/core/ops/div.cc @@ -25,29 +25,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr DivInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - return BroadCastInferShape(prim_name, input_args); -} - -TypePtr DivInferType(const PrimitivePtr &prim, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - std::map types; - (void)types.emplace("x", input_args[0]->BuildType()); - (void)types.emplace("y", input_args[1]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name()); -} -} // namespace - -AbstractBasePtr DivInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(DivInferType(primitive, input_args), - DivInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameDiv, Div); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/dropout.cc b/mindspore/core/ops/dropout.cc index 79748c4a5cb..9621d32846e 100644 --- a/mindspore/core/ops/dropout.cc +++ b/mindspore/core/ops/dropout.cc @@ -36,26 +36,6 @@ float Dropout::get_keep_prob() const { return GetValue(value_ptr); } -AbstractBasePtr DropoutInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->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]; - (void)CheckAndConvertUtils::CheckInteger("x_shape", SizeToLong(x_shape.size()), kGreaterEqual, 1, prim_name); - std::vector out_shape; - (void)out_shape.insert(out_shape.end(), x_shape.begin(), x_shape.end()); - (void)out_shape.insert(out_shape.end(), x_shape.begin(), x_shape.end()); - auto infer_shape = std::make_shared(out_shape); - - // Infer type - const std::set valid_types = {kFloat16, kFloat32}; - auto infer_type = - CheckAndConvertUtils::CheckTensorTypeValid("x_dtype", input_args[0]->BuildType(), valid_types, prim_name); - return std::make_shared(infer_type, infer_shape->shape()); -} REGISTER_PRIMITIVE_C(kNameDropout, Dropout); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/dynamic_quant.cc b/mindspore/core/ops/dynamic_quant.cc index 5677573d599..4907dca9e9a 100644 --- a/mindspore/core/ops/dynamic_quant.cc +++ b/mindspore/core/ops/dynamic_quant.cc @@ -29,23 +29,7 @@ void DynamicQuant::Init(const bool symmetric, const int64_t dst_type) { this->set_symmetric(symmetric); this->set_dst_type(dst_type); } -AbstractBasePtr DynamicQuantInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - const int64_t input_num = 1; - const size_t x_index = 0; - CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, primitive->name()); - auto input_type = CheckAndConvertUtils::GetTensorInputType(primitive->name(), input_args, x_index); - auto dst_type = TypeIdToType(TypeId(GetValue(primitive->GetAttr(kDstType)))); - MS_EXCEPTION_IF_NULL(dst_type); - if (input_type->type_id() != kNumberTypeFloat16 && input_type->type_id() != kNumberTypeFloat32) { - MS_EXCEPTION(TypeError) << "For '" << primitive->name() - << "', Input type should be kNumberTypeFloat16 or kNumberTypeFloat32" - << ", but " << input_type->ToString(); - } - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - return std::make_shared(dst_type, input_shape); -} + REGISTER_PRIMITIVE_C(kNameDynamicQuant, DynamicQuant); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/embedding_lookup.cc b/mindspore/core/ops/embedding_lookup.cc index bd5172de906..2fea8ff7266 100644 --- a/mindspore/core/ops/embedding_lookup.cc +++ b/mindspore/core/ops/embedding_lookup.cc @@ -33,50 +33,6 @@ bool EmbeddingLookup::get_setattr_flag() const { return GetValue(value_ptr); } -AbstractBasePtr EmbeddingLookupInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 3; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto params = input_args[0]->cast(); - MS_EXCEPTION_IF_NULL(params); - auto indices = input_args[1]->cast(); - MS_EXCEPTION_IF_NULL(indices); - const std::set int_valid_types = {kInt8, kInt16, kInt32, kInt64}; - (void)CheckAndConvertUtils::CheckTensorTypeValid("indices type", indices->BuildType(), int_valid_types, prim_name); - (void)CheckAndConvertUtils::CheckTensorTypeValid("offset", input_args[kInputIndex2]->BuildType(), int_valid_types, - prim_name); - MS_EXCEPTION_IF_NULL(params->shape()); - auto params_shp = params->shape()->shape(); - MS_EXCEPTION_IF_NULL(indices->shape()); - auto indices_shp = indices->shape()->shape(); - ShapeVector shape; - (void)shape.insert(shape.end(), indices_shp.begin(), indices_shp.end()); - (void)shape.insert(shape.end(), params_shp.begin() + 1, params_shp.end()); - auto indices_max_shape = indices->shape()->max_shape(); - ShapeVector max_shape; - if (!indices_max_shape.empty()) { - (void)max_shape.insert(max_shape.end(), indices_max_shape.begin(), indices_max_shape.end()); - (void)max_shape.insert(max_shape.end(), params_shp.begin() + 1, params_shp.end()); - } else { - max_shape = shape; - } - auto indices_min_shape = indices->shape()->min_shape(); - ShapeVector min_shape; - if (!indices_min_shape.empty()) { - (void)min_shape.insert(min_shape.end(), indices_min_shape.begin(), indices_min_shape.end()); - (void)min_shape.insert(min_shape.end(), params_shp.begin() + 1, params_shp.end()); - } else { - min_shape = shape; - } - - return std::make_shared(params->element(), - std::make_shared(shape, min_shape, max_shape)); -} REGISTER_PRIMITIVE_C(kNameEmbeddingLookup, EmbeddingLookup); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/expand_dims.cc b/mindspore/core/ops/expand_dims.cc index b53f489b1f8..275d95c2ba0 100644 --- a/mindspore/core/ops/expand_dims.cc +++ b/mindspore/core/ops/expand_dims.cc @@ -27,31 +27,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr ExpandDimsInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - // Infer shape - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto dim_val = GetValue(input_args[1]->BuildValue()); - auto rank = x_shape.size(); - (void)CheckAndConvertUtils::CheckInRange("axis", dim_val, kIncludeBoth, {-rank - 1, rank}, prim_name); - if (dim_val < 0) { - dim_val += SizeToLong(x_shape.size()) + 1; - } - auto out_shape = x_shape; - (void)out_shape.insert(out_shape.begin() + dim_val, 1, 1); - - // Infer type - const size_t x_index = 0; - auto x_type = CheckAndConvertUtils::GetTensorInputType(prim_name, input_args, x_index); - return std::make_shared(x_type, out_shape); -} REGISTER_PRIMITIVE_C(kNameExpandDims, ExpandDims); } // namespace ops } // namespace mindspore 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 ae23af9f9ae..93b68fce432 100644 --- a/mindspore/core/ops/fake_quant_with_min_max_vars.cc +++ b/mindspore/core/ops/fake_quant_with_min_max_vars.cc @@ -25,41 +25,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr FakeQuantWithMinMaxVarsInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape())[kShape]; - auto min_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex1]->BuildShape())[kShape]; - auto max_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex2]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("x_rank", SizeToLong(in_shape.size()), kGreaterEqual, 1, prim_name); - CheckAndConvertUtils::Check("min_shape", min_shape, kEqual, max_shape, prim_name); - (void)CheckAndConvertUtils::CheckInteger("min_shape", SizeToLong(min_shape.size()), kEqual, 1, prim_name); - int64_t shape_val = 1; - for (size_t i = 0; i < in_shape.size(); i++) { - shape_val = shape_val * in_shape[i]; - if (min_shape[0] > 1 && min_shape[0] != shape_val) { - MS_EXCEPTION(ValueError) << "For '" << prim_name - << "', the shape of \'min\' cannot broadcast to the shape of \'x\'"; - } - } - return std::make_shared(in_shape); -} - -TypePtr FakeQuantWithMinMaxVarsInferType(const PrimitivePtr &prim, const std::vector &input_args) { - const std::set valid_types = {kFloat16, kFloat32}; - if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr arg) { return arg == nullptr; })) { - MS_LOG(EXCEPTION) << "For '" << prim->name() - << "', the input args userd for infer shape and type, can not be a nullptr."; - } - std::map types; - (void)types.emplace("x", input_args[kInputIndex0]->BuildType()); - (void)types.emplace("min", input_args[kInputIndex1]->BuildType()); - (void)types.emplace("max", input_args[kInputIndex2]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name()); -} -} // namespace void FakeQuantWithMinMaxVars::Init(const bool narrow_range, const int64_t num_bits) { this->set_narrow_range(narrow_range); this->set_num_bits(num_bits); @@ -82,11 +47,7 @@ int64_t FakeQuantWithMinMaxVars::get_num_bits() const { auto value_ptr = this->GetAttr(kNumBits); return GetValue(value_ptr); } -AbstractBasePtr FakeQuantWithMinMaxVarsInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(FakeQuantWithMinMaxVarsInferType(primitive, input_args), - FakeQuantWithMinMaxVarsInferShape(primitive, input_args)->shape()); -} + REGISTER_PRIMITIVE_C(kNameFakeQuantWithMinMaxVars, FakeQuantWithMinMaxVars); } // namespace ops } // namespace mindspore 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 8ad34d5cd67..231299fc906 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 @@ -39,33 +39,6 @@ bool FakeQuantWithMinMaxVarsPerChannel::get_narrow_range() const { return GetValue(value_ptr); } -AbstractBasePtr FakeQuantWithMinMaxVarsPerChannelInfer(const abstract::AnalysisEnginePtr &, - const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto op_name = primitive->name(); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape())[kShape]; - auto min_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex1]->BuildShape())[kShape]; - auto max_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex2]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("x rank", (int64_t)x_shape.size(), kGreaterThan, 1, op_name); - CheckAndConvertUtils::Check("min shape", min_shape, kEqual, max_shape, 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.size() - 1], op_name); - - auto x_type = input_args[kInputIndex0]->BuildType(); - auto min_type = input_args[kInputIndex1]->BuildType(); - auto max_type = input_args[kInputIndex2]->BuildType(); - std::vector type_name = {"x", "min", "max"}; - std::vector type = {x_type, min_type, max_type}; - for (size_t i = 0; i < 3; i++) { - (void)CheckAndConvertUtils::CheckTensorTypeValid(type_name[i], type[i], {kFloat16, kFloat32}, op_name); - } - auto tensor_type = x_type->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto data_type = tensor_type->element(); - MS_EXCEPTION_IF_NULL(data_type); - return std::make_shared(data_type, x_shape); -} REGISTER_PRIMITIVE_C(kNameFakeQuantWithMinMaxVarsPerChannel, FakeQuantWithMinMaxVarsPerChannel); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fft_imag.cc b/mindspore/core/ops/fft_imag.cc index 5fcd8462423..e8d81548272 100644 --- a/mindspore/core/ops/fft_imag.cc +++ b/mindspore/core/ops/fft_imag.cc @@ -21,23 +21,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr FftImagInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - auto name = primitive->name(); - MS_LOG(DEBUG) << "Infer shape for " << name; - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - in_shape.pop_back(); - return std::make_shared(in_shape); -} -} // namespace - -AbstractBasePtr FftImagInfer(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(kFloat32, FftImagInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameFftImag, FftImag); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fft_real.cc b/mindspore/core/ops/fft_real.cc index bc22d8f2904..fcfd76eb951 100644 --- a/mindspore/core/ops/fft_real.cc +++ b/mindspore/core/ops/fft_real.cc @@ -24,19 +24,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr FftRealInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 1, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto out_dtype = kFloat32; - auto out_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - out_shape.pop_back(); - return std::make_shared(out_dtype, std::make_shared(out_shape)); -} REGISTER_PRIMITIVE_C(kNameFftReal, FftReal); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fill.cc b/mindspore/core/ops/fill.cc index 976ec9f33d4..680804f2262 100644 --- a/mindspore/core/ops/fill.cc +++ b/mindspore/core/ops/fill.cc @@ -22,46 +22,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr FillInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 3; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto input_dtype = input_args[kInputIndex0]->cast(); - MS_EXCEPTION_IF_NULL(input_dtype); - auto dtype_value = input_dtype->BuildValue(); - MS_EXCEPTION_IF_NULL(dtype_value); - auto dtype = dtype_value->cast(); - MS_EXCEPTION_IF_NULL(dtype); - auto valid_types = common_valid_types; - valid_types.insert(kBool); - (void)CheckAndConvertUtils::CheckTypeValid("output datatype", dtype, valid_types, prim_name); - auto out_shape = GetValue>(input_args[kInputIndex1]->BuildValue()); - auto x_type = input_args[kInputIndex2]->BuildType(); - auto x_type_id = x_type->type_id(); - auto x_value = input_args[kInputIndex2]->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); - SetTensorData(tensor->data_c(), int_value, mem_size); - } else if (x_type_id == kNumberTypeFloat || x_type_id == kNumberTypeFloat32) { - auto float_value = GetValue(x_value); - SetTensorData(tensor->data_c(), float_value, mem_size); - } else { - MS_LOG(ERROR) << "For '" << prim_name - << "', value's supported constant type is ['int', 'float', 'float64'], but got " - << input_args[kInputIndex2]->ToString() << "."; - } - abs->set_value(tensor); - return abs; -} REGISTER_PRIMITIVE_C(kNameFill, Fill); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fusion/add_fusion.cc b/mindspore/core/ops/fusion/add_fusion.cc index 528995c278a..d28343f9ac6 100644 --- a/mindspore/core/ops/fusion/add_fusion.cc +++ b/mindspore/core/ops/fusion/add_fusion.cc @@ -35,30 +35,6 @@ ActivationType AddFusion::get_activation_type() const { } void AddFusion::Init(const ActivationType activation_type) { this->set_activation_type(activation_type); } -namespace { -abstract::ShapePtr AddFusionInferShape(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 AddFusionInferType(const PrimitivePtr &prim, const std::vector &input_args) { - if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr &a) { return a == nullptr; })) { - MS_LOG(EXCEPTION) << "For '" << prim->name() - << ", the input args userd for infer shape and type, can not be a nullptr."; - } - std::map types; - (void)types.emplace("x", input_args[kInputIndex0]->BuildType()); - (void)types.emplace("y", input_args[kInputIndex1]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name()); -} -} // namespace - -AbstractBasePtr AddFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(AddFusionInferType(primitive, input_args), - AddFusionInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameAddFusion, AddFusion); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fusion/avg_pool_fusion.cc b/mindspore/core/ops/fusion/avg_pool_fusion.cc index 765cc708570..db4d69bcdd8 100644 --- a/mindspore/core/ops/fusion/avg_pool_fusion.cc +++ b/mindspore/core/ops/fusion/avg_pool_fusion.cc @@ -50,66 +50,6 @@ ActivationType AvgPoolFusion::get_activation_type() const { return ActivationType(GetValue(value_ptr)); } -namespace { -abstract::ShapePtr AvgPoolFusionInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (auto item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto op_name = primitive->name(); - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - auto format = Format(GetValue(primitive->GetAttr(kFormat))); - if (format == NHWC) { - in_shape = {in_shape[0], in_shape[3], in_shape[1], in_shape[2]}; - } - const int64_t x_rank = 4; - (void)CheckAndConvertUtils::CheckInteger("x_rank", SizeToLong(in_shape.size()), kEqual, x_rank, op_name); - auto kernel_size = GetValue>(primitive->GetAttr(kKernelSize)); - auto pad_mode = PadMode(GetValue(primitive->GetAttr(kPadMode))); - auto batch = in_shape[0]; - auto channel = in_shape[1]; - auto in_h = in_shape[2]; - auto in_w = in_shape[3]; - - auto strides = GetValue>(primitive->GetAttr(kStrides)); - (void)CheckAndConvertUtils::CheckPositiveVector(kStride, strides, op_name); - 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 = abstract::Shape::SHP_ANY; - int64_t out_w = abstract::Shape::SHP_ANY; - if (pad_mode == VALID) { - out_h = static_cast(ceil((in_h - (kernel_h - 1)) / static_cast(stride_h))); - out_w = static_cast(ceil((in_w - (kernel_w - 1)) / static_cast(stride_w))); - } else if (pad_mode == SAME) { - out_h = static_cast(ceil(in_h / static_cast(stride_h))); - out_w = static_cast(ceil(in_w / static_cast(stride_w))); - } - std::vector out_shape = {batch, channel, out_h, out_w}; - if (format == NHWC) { - out_shape = {batch, out_h, out_w, channel}; - } - if (std::any_of(out_shape.begin(), out_shape.end(), [](int64_t a) { return a <= 0; })) { - MS_LOG(EXCEPTION) << "For '" << op_name << "', Kernel size should be positive, but got not valid."; - } - return std::make_shared(out_shape); -} - -TypePtr AvgPoolFusionInferType(const std::vector &input_args) { - for (auto item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - return input_args[0]->BuildType(); -} -} // namespace - -AbstractBasePtr AvgPoolFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(AvgPoolFusionInferType(input_args), - AvgPoolFusionInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameAvgPoolFusion, AvgPoolFusion); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fusion/full_connection.cc b/mindspore/core/ops/fusion/full_connection.cc index 3c83a3fc841..61a000985b2 100644 --- a/mindspore/core/ops/fusion/full_connection.cc +++ b/mindspore/core/ops/fusion/full_connection.cc @@ -58,65 +58,7 @@ void FullConnection::Init(const bool has_bias, const int64_t axis, const bool us this->set_use_axis(use_axis); this->set_activation_type(activation_type); } -AbstractBasePtr FullConnectionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - MS_EXCEPTION_IF_NULL(input_args[kInputIndex0]); - MS_EXCEPTION_IF_NULL(input_args[kInputIndex1]); - auto input0 = input_args[0]; - auto input1 = input_args[1]; - auto input0_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input0->BuildShape())[kShape]; - auto input1_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input1->BuildShape())[kShape]; - auto prim_axis = GetValue(primitive->GetAttr(kAxis)); - auto has_bias = GetValue(primitive->GetAttr(kHasBias)); - const int64_t input_num_bias = 3; - const int64_t input_num = 2; - if (has_bias) { - (void)CheckAndConvertUtils::CheckInteger("input_args.size()", SizeToLong(input_args.size()), kEqual, input_num_bias, - prim_name); - } else { - (void)CheckAndConvertUtils::CheckInteger("input_args.size()", SizeToLong(input_args.size()), kEqual, input_num, - prim_name); - } - auto use_axis = GetValue(primitive->GetAttr(kUseAxis)); - if (use_axis && (prim_axis < 1 || prim_axis > (int64_t)input0_shape.size())) { - MS_EXCEPTION(ValueError) << "Full Connection axis is invalid"; - } - int64_t new_k = 1; - if (use_axis) { - for (size_t t = LongToSize(prim_axis); t < input0_shape.size(); t++) { - new_k *= input0_shape[t]; - } - if (new_k != input1_shape[1]) { - MS_EXCEPTION(ValueError) << "Input1 size is invalid"; - } - } else { - new_k = input1_shape[1]; - } - if (has_bias) { - auto input2_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex2]->BuildShape())[kShape]; - if (input2_shape[0] != input1_shape[0]) { - MS_EXCEPTION(ValueError) << "Bias size is invalid"; - } - } - std::vector out_shape = {(int64_t)input0_shape.size()}; - if (use_axis) { - out_shape.resize(LongToSize(prim_axis) + 1); - out_shape[LongToSize(prim_axis)] = input1_shape[0]; - } else { - int64_t total = 1; - for (size_t i = 0; i < input0_shape.size(); i++) { - total *= input0_shape[i]; - } - out_shape.resize(2); - auto batch_size = total / new_k; - out_shape[0] = batch_size; - out_shape[1] = input1_shape[0]; - } - auto input0_type = input_args[0]->BuildType()->cast()->element(); - return std::make_shared(input0_type, out_shape); -} + REGISTER_PRIMITIVE_C(kNameFullConnection, FullConnection); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fusion/max_pool_fusion.cc b/mindspore/core/ops/fusion/max_pool_fusion.cc index cae1b5a1882..2531661105e 100644 --- a/mindspore/core/ops/fusion/max_pool_fusion.cc +++ b/mindspore/core/ops/fusion/max_pool_fusion.cc @@ -50,62 +50,6 @@ ActivationType MaxPoolFusion::get_activation_type() const { return ActivationType(GetValue(value_ptr)); } -namespace { -abstract::ShapePtr MaxPoolFusionInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - MS_EXCEPTION_IF_NULL(input_args[0]); - auto op_name = primitive->name(); - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - auto format = Format(GetValue(primitive->GetAttr(kFormat))); - if (format == NHWC) { - in_shape = {in_shape[0], in_shape[3], in_shape[1], in_shape[2]}; - } - const int64_t in_shape_size = 4; - (void)CheckAndConvertUtils::CheckInteger("x_rank", SizeToLong(in_shape.size()), kEqual, in_shape_size, op_name); - auto kernel_size = GetValue>(primitive->GetAttr(kKernelSize)); - auto pad_mode = PadMode(GetValue(primitive->GetAttr(kPadMode))); - auto batch = in_shape[0]; - auto channel = in_shape[1]; - auto in_h = in_shape[2]; - auto in_w = in_shape[3]; - - auto strides = GetValue>(primitive->GetAttr(kStrides)); - 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 = abstract::Shape::SHP_ANY; - int64_t out_w = abstract::Shape::SHP_ANY; - if (pad_mode == VALID) { - out_h = static_cast(ceil((in_h - (kernel_h - 1)) / static_cast(stride_h))); - out_w = static_cast(ceil((in_w - (kernel_w - 1)) / static_cast(stride_w))); - } else if (pad_mode == SAME) { - out_h = static_cast(ceil(in_h / static_cast(stride_h))); - out_w = static_cast(ceil(in_w / static_cast(stride_w))); - } - std::vector out_shape = {batch, channel, out_h, out_w}; - if (format == NHWC) { - out_shape = {batch, out_h, out_w, channel}; - } - if (std::any_of(out_shape.begin(), out_shape.end(), [](int64_t a) { return a <= 0; })) { - MS_LOG(EXCEPTION) << "For '" << op_name << "', Kernel size must be positive, but got invalid."; - } - return std::make_shared(out_shape); -} - -TypePtr MaxPoolFusionInferType(const std::vector &input_args) { return input_args[0]->BuildType(); } -} // namespace - -AbstractBasePtr MaxPoolFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (auto item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - return std::make_shared(MaxPoolFusionInferType(input_args), - MaxPoolFusionInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameMaxPoolFusion, MaxPoolFusion); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fusion/pow_fusion.cc b/mindspore/core/ops/fusion/pow_fusion.cc index e9b618ce08a..03a39c8d48c 100644 --- a/mindspore/core/ops/fusion/pow_fusion.cc +++ b/mindspore/core/ops/fusion/pow_fusion.cc @@ -34,34 +34,6 @@ void PowFusion::set_shift(const float &shift) { (void)this->AddAttr(kShift, Make float PowFusion::get_scale() const { return GetValue(GetAttr(kScale)); } float PowFusion::get_shift() const { return GetValue(GetAttr(kShift)); } -namespace { -abstract::ShapePtr PowFusionInferShape(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 PowFusionInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - std::map types; - (void)types.emplace("x", input_args[0]->BuildType()); - (void)types.emplace("y", input_args[1]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name()); -} -} // namespace - -AbstractBasePtr PowFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("PowFusion infer", SizeToLong(input_args.size()), kGreaterEqual, input_num, - primitive->name()); - return std::make_shared(PowFusionInferType(primitive, input_args), - PowFusionInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNamePowFusion, PowFusion); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/fusion/slice_fusion.cc b/mindspore/core/ops/fusion/slice_fusion.cc index f5bc315b9d7..dfb5be4bbb8 100644 --- a/mindspore/core/ops/fusion/slice_fusion.cc +++ b/mindspore/core/ops/fusion/slice_fusion.cc @@ -30,40 +30,6 @@ std::vector SliceFusion::get_axes() const { return GetValue>(value_ptr); } -AbstractBasePtr SliceFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto op_name = primitive->name(); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto x_shape_len = x_shape.size(); - auto begin_v = input_args[kInputIndex1]->BuildValue(); - auto size_v = input_args[kInputIndex2]->BuildValue(); - auto x_type = input_args[kInputIndex0]->BuildType(); - MS_EXCEPTION_IF_NULL(x_type); - MS_EXCEPTION_IF_NULL(begin_v); - MS_EXCEPTION_IF_NULL(size_v); - auto tensor_type = x_type->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto data_type = tensor_type->element(); - MS_EXCEPTION_IF_NULL(data_type); - if (begin_v == kAnyValue || size_v == kAnyValue) { - return std::make_shared(data_type, std::vector{}); - } - auto begin = GetValue>(begin_v); - auto size = GetValue>(size_v); - CheckAndConvertUtils::Check("len of begin", (int64_t)begin.size(), kEqual, SizeToLong(x_shape_len)); - CheckAndConvertUtils::Check("len of size", (int64_t)size.size(), kEqual, SizeToLong(x_shape_len)); - - for (size_t i = 0; i < x_shape_len; i++) { - (void)CheckAndConvertUtils::CheckInteger("input size[" + std::to_string(i) + "]", size[i], kGreaterThan, 0, ""); - if (x_shape[i] < (begin[i] + size[i])) { - auto y = begin[i] + size[i]; - MS_EXCEPTION(ValueError) << "For " + op_name + "slice shape can't bigger than origin shape " + - std::to_string(x_shape[i]) + "," + std::to_string(y); - } - } - return std::make_shared(data_type, size); -} REGISTER_PRIMITIVE_C(kNameSliceFusion, SliceFusion); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/avg_pool_grad.cc b/mindspore/core/ops/grad/avg_pool_grad.cc index b30f50a16cc..9f02152bb5c 100644 --- a/mindspore/core/ops/grad/avg_pool_grad.cc +++ b/mindspore/core/ops/grad/avg_pool_grad.cc @@ -19,16 +19,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr AvgPoolGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - MS_EXCEPTION_IF_NULL(input_args[0]->BuildValue()); - auto origin_input_shape = GetValue>(input_args[0]->BuildValue()); - auto tensor_type = input_args[1]->BuildType()->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto element = tensor_type->element(); - return std::make_shared(element, origin_input_shape); -} REGISTER_PRIMITIVE_C(kNameAvgPoolGrad, AvgPoolGrad); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/binary_cross_entropy_grad.cc b/mindspore/core/ops/grad/binary_cross_entropy_grad.cc index f056b5158bd..36a38c7fbeb 100644 --- a/mindspore/core/ops/grad/binary_cross_entropy_grad.cc +++ b/mindspore/core/ops/grad/binary_cross_entropy_grad.cc @@ -22,35 +22,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr BinaryCrossEntroyGradInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape())[kShape]; - auto y_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex1]->BuildShape())[kShape]; - auto weight_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex2]->BuildShape())[kShape]; - CheckAndConvertUtils::Check("x shape", x_shape, kEqual, y_shape, prim_name); - if (weight_shape.size() < 1) { - CheckAndConvertUtils::Check("y shape", y_shape, kEqual, weight_shape, prim_name); - } - return std::make_shared(x_shape); -} - -TypePtr BinaryCrossEntroyGradInferType(const PrimitivePtr &prim, const std::vector &input_args) { - const std::set valid_types = {kFloat16, kFloat32}; - std::map types; - (void)types.emplace("x_shape", input_args[kInputIndex0]->BuildType()); - (void)types.emplace("y_shape", input_args[kInputIndex1]->BuildType()); - auto infer_type = CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name()); - if (input_args[kInputIndex3]->BuildType() != nullptr) { - (void)types.emplace("x_shape", input_args[kInputIndex0]->BuildType()); - (void)types.emplace("weight_shape", input_args[kInputIndex2]->BuildType()); - infer_type = CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name()); - } - return infer_type; -} -} // namespace void BinaryCrossEntropyGrad::Init(const Reduction &reduction) { set_reduction(reduction); } void BinaryCrossEntropyGrad::set_reduction(const Reduction &reduction) { @@ -62,18 +33,6 @@ Reduction BinaryCrossEntropyGrad::get_reduction() const { return Reduction(GetValue(value_ptr)); } -AbstractBasePtr BinaryCrossEntropyGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - const int64_t input_num = 4; - (void)CheckAndConvertUtils::CheckInteger("BinaryCrossEntropyGrad infer", SizeToLong(input_args.size()), kGreaterEqual, - input_num, primitive->name()); - return std::make_shared(BinaryCrossEntroyGradInferType(primitive, input_args), - BinaryCrossEntroyGradInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameBinaryCrossEntropyGrad, BinaryCrossEntropyGrad); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/einsum_grad.cc b/mindspore/core/ops/grad/einsum_grad.cc index 9209dbb461d..a1c7cbbd986 100644 --- a/mindspore/core/ops/grad/einsum_grad.cc +++ b/mindspore/core/ops/grad/einsum_grad.cc @@ -30,30 +30,6 @@ std::string EinsumGrad::get_equation() const { auto value_ptr = this->GetAttr(kEquation); return GetValue(value_ptr); } -AbstractBasePtr EinsumGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (auto item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto elements = input_args[0]->isa() - ? input_args[0]->cast()->elements() - : input_args[0]->cast()->elements(); - AbstractBasePtrList rets; - std::vector> input_shapes; - std::vector cur_shape; - for (size_t idx = 0; idx < elements.size(); ++idx) { - auto dx = elements[idx]->Broaden(); - rets.emplace_back(dx); - auto shape = elements[idx]->BuildShape(); - auto &shape_int = shape->cast()->shape(); - std::transform(shape_int.begin(), shape_int.end(), std::back_inserter(cur_shape), SizeToLong); - input_shapes.emplace_back(cur_shape); - cur_shape.clear(); - } - (void)primitive->AddAttr("input_shape_vec", MakeValue>>(input_shapes)); - return std::make_shared(rets); -} // REGISTER_PRIMITIVE_EVAL_IMPL(EinsumGrad, prim::kPrimEinsumGrad, EinsumGradInfer, nullptr, true); REGISTER_PRIMITIVE_C(kNameEinsumGrad, EinsumGrad); } // namespace ops diff --git a/mindspore/core/ops/grad/flatten_grad.cc b/mindspore/core/ops/grad/flatten_grad.cc index a60d31ffe92..016fc45a49a 100644 --- a/mindspore/core/ops/grad/flatten_grad.cc +++ b/mindspore/core/ops/grad/flatten_grad.cc @@ -18,24 +18,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr FlattenGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto input_x = input_args[0]->cast(); - MS_EXCEPTION_IF_NULL(input_x); - auto input_shape = input_args[1]->cast(); - MS_EXCEPTION_IF_NULL(input_shape); - auto out_shape = GetValue>(input_shape->BuildValue()); - auto ret = input_x->Broaden(); - ret->set_shape(std::make_shared(out_shape)); - return ret; -} REGISTER_PRIMITIVE_C(kNameFlattenGrad, FlattenGrad); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/group_conv2d_grad_input.cc b/mindspore/core/ops/grad/group_conv2d_grad_input.cc index 42231f066dd..0a409eb682f 100644 --- a/mindspore/core/ops/grad/group_conv2d_grad_input.cc +++ b/mindspore/core/ops/grad/group_conv2d_grad_input.cc @@ -158,28 +158,6 @@ bool GroupConv2DGradInput::get_has_bias() const { MS_EXCEPTION_IF_NULL(value_ptr); return GetValue(value_ptr); } -AbstractBasePtr GroupConv2DGradInputInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("group_conv_2D_infer", SizeToLong(input_args.size()), kGreaterEqual, - input_num, prim_name); - MS_EXCEPTION_IF_NULL(input_args[0]); - - // Infer shape - auto shape_ptr = primitive->GetAttr(kInputShape); - MS_EXCEPTION_IF_NULL(shape_ptr); - auto shape = GetValue>(shape_ptr); - - // Infer type - auto type_ptr = input_args[0]->BuildType(); - MS_EXCEPTION_IF_NULL(type_ptr); - auto type_tensor_ptr = type_ptr->cast(); - MS_EXCEPTION_IF_NULL(type_tensor_ptr); - auto type = type_tensor_ptr->element(); - return std::make_shared(type, shape); -} REGISTER_PRIMITIVE_C(kNameGroupConv2DGradInput, GroupConv2DGradInput); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/lstm_grad.cc b/mindspore/core/ops/grad/lstm_grad.cc index 2440ad2016d..3dd6ec2d064 100644 --- a/mindspore/core/ops/grad/lstm_grad.cc +++ b/mindspore/core/ops/grad/lstm_grad.cc @@ -20,17 +20,6 @@ namespace mindspore { namespace ops { -namespace { -AbstractBasePtr LstmGradInfer(const PrimitivePtr &primitive, const std::vector &input_args) { - // infer shape - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &input : input_args) { - MS_EXCEPTION_IF_NULL(input); - } - return nullptr; -} -} // namespace - void LSTMGrad::set_input_size(const int64_t input_size) { (void)CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name()); (void)AddAttr(kInput_size, MakeValue(input_size)); @@ -95,10 +84,6 @@ void LSTMGrad::Init(const int64_t input_size, const int64_t hidden_size, const i this->set_zoneout_hidden(zoneout_hidden); } -AbstractBasePtr LstmGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(LstmGradInfer(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameLSTMGrad, LSTMGrad); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/lstm_grad_data.cc b/mindspore/core/ops/grad/lstm_grad_data.cc index 471fa0d1518..f5f26a85139 100644 --- a/mindspore/core/ops/grad/lstm_grad_data.cc +++ b/mindspore/core/ops/grad/lstm_grad_data.cc @@ -20,17 +20,6 @@ namespace mindspore { namespace ops { -namespace { -AbstractBasePtr LstmGradDataInfer(const PrimitivePtr &primitive, const std::vector &input_args) { - // infer shape - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &input : input_args) { - MS_EXCEPTION_IF_NULL(input); - } - return nullptr; -} -} // namespace - void LSTMGradData::set_input_size(const int64_t input_size) { (void)CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name()); (void)AddAttr(kInput_size, MakeValue(input_size)); @@ -99,10 +88,6 @@ void LSTMGradData::Init(const int64_t input_size, const int64_t hidden_size, con this->set_zoneout_hidden(zoneout_hidden); } -AbstractBasePtr LstmGradDataInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(LstmGradDataInfer(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameLSTMGradData, LSTMGradData); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/lstm_grad_weight.cc b/mindspore/core/ops/grad/lstm_grad_weight.cc index dc520df35ec..6794ce0ba19 100644 --- a/mindspore/core/ops/grad/lstm_grad_weight.cc +++ b/mindspore/core/ops/grad/lstm_grad_weight.cc @@ -20,17 +20,6 @@ namespace mindspore { namespace ops { -namespace { -AbstractBasePtr LstmGradWeightInfer(const PrimitivePtr &primitive, const std::vector &input_args) { - // infer shape - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &input : input_args) { - MS_EXCEPTION_IF_NULL(input); - } - return nullptr; -} -} // namespace - void LSTMGradWeight::set_input_size(const int64_t input_size) { (void)CheckAndConvertUtils::CheckInteger(kInput_size, input_size, kGreaterThan, 0, this->name()); (void)AddAttr(kInput_size, MakeValue(input_size)); @@ -99,10 +88,6 @@ void LSTMGradWeight::Init(const int64_t input_size, const int64_t hidden_size, c this->set_zoneout_hidden(zoneout_hidden); } -AbstractBasePtr LstmGradWeightInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(LstmGradWeightInfer(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameLSTMGradWeight, LSTMGradWeight); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/grad/max_pool_grad.cc b/mindspore/core/ops/grad/max_pool_grad.cc index 461ba1e7da4..68da0b008b2 100644 --- a/mindspore/core/ops/grad/max_pool_grad.cc +++ b/mindspore/core/ops/grad/max_pool_grad.cc @@ -19,15 +19,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr MaxPoolGradInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(input_args[0]->BuildValue()); - auto x1_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto tensor_type = input_args[0]->BuildType()->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto element = tensor_type->element(); - return std::make_shared(element, x1_shape); -} REGISTER_PRIMITIVE_C(kNameMaxPoolGrad, MaxPoolGrad); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/hashtable_lookup.cc b/mindspore/core/ops/hashtable_lookup.cc index 18a42d8f7c8..3bcf6964894 100644 --- a/mindspore/core/ops/hashtable_lookup.cc +++ b/mindspore/core/ops/hashtable_lookup.cc @@ -22,28 +22,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr HashtableLookupInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - 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[kInputIndex2]->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(); - std::vector value_shape; - auto output = std::make_shared(data_type, value_shape); - auto hits = std::make_shared(kInt8, hits_shape); - AbstractBasePtrList output1 = {output, hits}; - return std::make_shared(output1); -} REGISTER_PRIMITIVE_C(kNameHashtableLookup, HashtableLookup); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/l2_normalize.cc b/mindspore/core/ops/l2_normalize.cc index 2baa5d23d03..7e8d757a5c1 100644 --- a/mindspore/core/ops/l2_normalize.cc +++ b/mindspore/core/ops/l2_normalize.cc @@ -36,24 +36,6 @@ float L2Normalize::get_epsilon() const { return GetValue(value_ptr); } -AbstractBasePtr L2NormalizeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->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); - } - const std::set valid_types = {kFloat16, kFloat32}; - (void)CheckAndConvertUtils::CheckTensorTypeValid("input_x", input_args[0]->BuildType(), valid_types, prim_name); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto x_rank = SizeToLong(x_shape.size()); - auto axiss = GetValue>(primitive->GetAttr(kAxis)); - for (auto &axis : axiss) { - CheckAndConvertUtils::CheckInRange("axis", axis, kIncludeLeft, {-x_rank, x_rank}, prim_name); - } - return input_args[0]->Broaden(); -} REGISTER_PRIMITIVE_C(kNameL2Normalize, L2Normalize); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/leaky_relu.cc b/mindspore/core/ops/leaky_relu.cc index 9a834b4dbcf..90f895f0900 100644 --- a/mindspore/core/ops/leaky_relu.cc +++ b/mindspore/core/ops/leaky_relu.cc @@ -18,26 +18,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr LeakyReluInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto x = input_args[0]->BuildShape(); - auto shape_element = x->cast(); - MS_EXCEPTION_IF_NULL(shape_element); - return shape_element; -} - -TypePtr LeakyReluInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 1, prim->name()); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - std::map types; - (void)types.emplace("x", input_args[0]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name()); -} -} // namespace void LeakyRelu::Init(const float negative_slope) { this->set_negative_slope(negative_slope); } void LeakyRelu::set_negative_slope(const float negative_slope) { @@ -45,11 +25,6 @@ void LeakyRelu::set_negative_slope(const float negative_slope) { } float LeakyRelu::get_negative_slope() const { return GetValue(GetAttr(kNegativeSlope)); } -AbstractBasePtr LeakyReluInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(LeakyReluInferType(primitive, input_args), - LeakyReluInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameLeakyRelu, LeakyRelu); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/lrn.cc b/mindspore/core/ops/lrn.cc index b462a18b5fa..2ae3d22fd9a 100644 --- a/mindspore/core/ops/lrn.cc +++ b/mindspore/core/ops/lrn.cc @@ -74,35 +74,6 @@ void LRN::Init(const int64_t depth_radius, const float bias, const float alpha, this->set_norm_region(norm_region); } -namespace { -abstract::ShapePtr LRNInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t x_size = 4; - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(in_shape.size()), kEqual, x_size, prim_name); - - return std::make_shared(in_shape); -} - -TypePtr LRNInferType(const PrimitivePtr &prim, const std::vector &input_args) { - const std::set valid_types = {kFloat16, kFloat32}; - if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr arg) { return arg == nullptr; })) { - MS_LOG(EXCEPTION) << "For '" << prim->name() - << "', the input args userd for infer shape and type, can not be a nullptr."; - } - std::map types; - MS_EXCEPTION_IF_NULL(input_args[0]); - (void)types.emplace("x", input_args[0]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name()); -} -} // namespace - -AbstractBasePtr LrnInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(LRNInferType(primitive, input_args), - LRNInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameLRN, LRN); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/lsh_projection.cc b/mindspore/core/ops/lsh_projection.cc index e7ae8d90236..7ea717a4692 100644 --- a/mindspore/core/ops/lsh_projection.cc +++ b/mindspore/core/ops/lsh_projection.cc @@ -28,41 +28,6 @@ void LshProjection::set_type(const LshProjectionType &type) { LshProjectionType LshProjection::get_type() const { return LshProjectionType(GetValue(GetAttr(kType))); } -AbstractBasePtr LshProjectionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto op_name = primitive->name(); - const int64_t input_num = 2; - const int64_t input0_size = 2; - const int64_t input0_last_dim = 32; - CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, op_name); - auto input0 = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape())[kShape]; - auto input1 = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex1]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("input0 rank", SizeToLong(input0.size()), kEqual, input0_size, op_name); - (void)CheckAndConvertUtils::CheckInteger("input0_shape_dimen_1", input0[1], kLessEqual, input0_last_dim, 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[kInputIndex2]->BuildShape())[kShape]; - (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); - } - - std::vector out_shape; - auto attr_value = GetValue(primitive->GetAttr(kType)); - switch ((int64_t)LshProjectionType(attr_value)) { - case (int64_t)LshProjectionType::SPARSE: - out_shape.push_back(input0[0]); - break; - case (int64_t)LshProjectionType::DENSE: - out_shape.push_back(input0[0] * input0[1]); - break; - default: - MS_LOG(ERROR) << "For '" << op_name << "', type: " << (int64_t)LshProjectionType(attr_value) - << " is unsupported."; - } - return std::make_shared(kInt32, out_shape); -} REGISTER_PRIMITIVE_C(kNameLshProjection, LshProjection); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/mat_mul.cc b/mindspore/core/ops/mat_mul.cc index 151b9e2308d..aaef5abf8eb 100644 --- a/mindspore/core/ops/mat_mul.cc +++ b/mindspore/core/ops/mat_mul.cc @@ -21,85 +21,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr MatMulInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - auto x_shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape()); - auto y_shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape()); - auto x_shp = x_shape_map[kShape]; - auto y_shp = y_shape_map[kShape]; - constexpr size_t dim_limit = 2; - if (x_shp.size() != dim_limit || y_shp.size() != dim_limit) { - MS_EXCEPTION(ValueError) << "For MatMul, input x, y should have the same dimension size and should be greater" - << "or equal to 3, while x size = " << x_shp.size() << ", y size = " << y_shp.size(); - } - constexpr size_t offset = 2; - std::vector x_last(x_shp.end() - offset, x_shp.end()); - std::vector y_last(y_shp.end() - offset, y_shp.end()); - ValuePtr transpose_a_ptr = primitive->GetAttr("transpose_a"); - ValuePtr transpose_b_ptr = primitive->GetAttr("transpose_b"); - bool transpose_a = GetValue(transpose_a_ptr); - bool transpose_b = GetValue(transpose_b_ptr); - int64_t x_col = x_last[static_cast(!transpose_a)]; - int64_t y_row = y_last[static_cast(transpose_b)]; - if (std::find(x_shp.begin(), x_shp.end(), -1) == x_shp.end() && - std::find(y_shp.begin(), y_shp.end(), -1) == y_shp.end()) { - if (x_col != y_row) { - MS_EXCEPTION(ValueError) << "For " << prim_name << " evaluator shapes of inputs can not do this operator, " - << "got " << x_col << " and " << y_row << " , with x1 shape " << x_shp - << "(transpose_a=" << transpose_a << "})" - << ", x2 shape " << y_shp << "(transpose_b=" << transpose_b << "})"; - } - } - (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]; - ShapeVector y_max_shape = y_shape_map[kMaxShape]; - CheckAndConvertUtils::CheckMinMaxShape(x_shp, &x_min_shape, &x_max_shape); - CheckAndConvertUtils::CheckMinMaxShape(y_shp, &y_min_shape, &y_max_shape); - // Additional check for dynamic shape - // Last infer will be real shape values - bool x_not_dyn = - std::all_of(x_shp.begin(), x_shp.end(), [](int64_t value) { return value != abstract::Shape::SHP_ANY; }); - bool y_not_dyn = - std::all_of(y_shp.begin(), y_shp.end(), [](int64_t value) { return value != abstract::Shape::SHP_ANY; }); - if (x_not_dyn && y_not_dyn) { - auto x_c = x_shp[(transpose_a ? 0 : 1)]; - auto y_r = y_shp[(transpose_b ? 1 : 0)]; - if (x_c != y_r) { - MS_LOG(EXCEPTION) << "MatMul shape error, got x_col: " << x_c << ", y_row: " << y_r - << ". In MatMul x_col and y_row should be equal."; - } - } - ShapeVector ret_shape; - ShapeVector ret_min_shape; - ShapeVector ret_max_shape; - auto make_shape = [&transpose_a, &transpose_b](ShapeVector &output, const ShapeVector xshp, - const ShapeVector yshp) -> void { - output.push_back(xshp[(transpose_a ? 1 : 0)]); - output.push_back(yshp[(transpose_b ? 0 : 1)]); - return; - }; - make_shape(ret_shape, x_shp, y_shp); - make_shape(ret_min_shape, x_min_shape, y_min_shape); - make_shape(ret_max_shape, x_max_shape, y_max_shape); - return std::make_shared(ret_shape, ret_min_shape, ret_max_shape); -} - -TypePtr MatMulInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - const std::set valid_types = {kInt8, kInt16, kInt32, kInt64, kFloat16, kFloat32, kFloat64}; - std::map types; - (void)types.emplace("x", input_args[0]->BuildType()); - (void)types.emplace("w", input_args[1]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name()); -} -} // namespace - void MatMul::Init(bool transpose_a, bool transpose_b) { set_transpose_a(transpose_a); set_transpose_b(transpose_b); @@ -119,14 +40,6 @@ bool MatMul::get_transpose_b() const { return GetValue(value_ptr); } -AbstractBasePtr MatMulInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("MatMul infer", SizeToLong(input_args.size()), kGreaterEqual, input_num, - primitive->name()); - return abstract::MakeAbstract(MatMulInferShape(primitive, input_args), MatMulInferType(primitive, input_args)); -} -// Add REGISTER_PRIMITIVE_C(kNameMatMul, MatMul); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/max_pool.cc b/mindspore/core/ops/max_pool.cc index 7e162c3ecd1..80e253aabe2 100644 --- a/mindspore/core/ops/max_pool.cc +++ b/mindspore/core/ops/max_pool.cc @@ -78,74 +78,6 @@ void MaxPool::Init(const std::vector &kernel_size, const std::vectorset_round_mode(round_mode); } -namespace { -abstract::ShapePtr MaxPoolInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto op_name = primitive->name(); - MS_EXCEPTION_IF_NULL(input_args[0]); - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->GetShapeTrack())[kShape]; - auto format = Format(GetValue(primitive->GetAttr(kFormat))); - if (format == NHWC) { - in_shape = {in_shape[0], in_shape[3], in_shape[1], in_shape[2]}; - } - const int64_t x_rank = 4; - (void)CheckAndConvertUtils::CheckInteger("x_rank", SizeToLong(in_shape.size()), kEqual, x_rank, op_name); - - auto kernel_size = GetValue>(primitive->GetAttr(kKernelSize)); - auto pad_mode_value = (primitive->GetAttr(kPadMode)); - auto pad_mode = PadMode(GetValue(pad_mode_value)); - auto batch = in_shape[0]; - auto channel = in_shape[1]; - auto in_h = in_shape[2]; - auto in_w = in_shape[3]; - auto strides = GetValue>(primitive->GetAttr(kStrides)); - 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 = abstract::Shape::SHP_ANY; - int64_t out_w = abstract::Shape::SHP_ANY; - if (pad_mode == VALID) { - out_h = static_cast(ceil((in_h - (kernel_h - 1)) + static_cast(stride_h) - 1) / - static_cast(stride_h)); - out_w = static_cast(ceil((in_w - (kernel_w - 1)) + static_cast(stride_w) - 1) / - static_cast(stride_w)); - } else if (pad_mode == SAME) { - out_h = static_cast(ceil(in_h / static_cast(stride_h))); - out_w = static_cast(ceil(in_w / static_cast(stride_w))); - } - std::vector out_shape = {batch, channel, out_h, out_w}; - if (format == NHWC) { - out_shape = {batch, out_h, out_w, channel}; - } - if (std::any_of(out_shape.begin(), out_shape.end(), [](int64_t a) { return a <= 0; })) { - MS_LOG(EXCEPTION) << "For '" << op_name << "', Kernel size must be positive, but it's " << kernel_size << "."; - } - return std::make_shared(out_shape); -} - -TypePtr MaxPoolInferType(const PrimitivePtr &prim, const std::vector &input_args) { - if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr arg) { return arg == nullptr; })) { - MS_LOG(EXCEPTION) << "For '" << prim->name() - << "', the input args userd for infer shape and type, can not be a nullptr."; - } - auto name = prim->name(); - MS_LOG(DEBUG) << "Infer data type for : " << name; - auto input_type = input_args[0]->BuildType(); - MS_EXCEPTION_IF_NULL(input_type); - auto input_tensor_type = input_type->cast(); - if (input_tensor_type == nullptr) { - MS_LOG_EXCEPTION << "For '" << name << "', the input must be a tensor but got " << input_type->ToString(); - } - return input_tensor_type->element(); -} -} // namespace - -AbstractBasePtr MaxPoolInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(MaxPoolInferType(primitive, input_args), - MaxPoolInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameMaxPool, MaxPool); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/mfcc.cc b/mindspore/core/ops/mfcc.cc index 14d83fc511e..5580c522fa7 100644 --- a/mindspore/core/ops/mfcc.cc +++ b/mindspore/core/ops/mfcc.cc @@ -21,32 +21,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr MfccInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input0_size = 3; - const int64_t input1_size = 1; - auto first_input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto second_input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("input 0 rank", SizeToLong(first_input_shape.size()), kEqual, input0_size, - prim_name); - (void)CheckAndConvertUtils::CheckInteger("input 1 rank", SizeToLong(second_input_shape.size()), kEqual, input1_size, - prim_name); - std::vector out_shape = {first_input_shape[0], first_input_shape[1], - GetValue(primitive->GetAttr(kDctCoeffNum))}; - return std::make_shared(out_shape); -} - -TypePtr MfccInferType(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; -} -} // namespace - void Mfcc::Init(const float freq_upper_limit, const float freq_lower_limit, const int64_t filter_bank_channel_num, const int64_t dct_coeff_num) { this->set_freq_upper_limit(freq_upper_limit); @@ -88,11 +62,6 @@ void Mfcc::set_dct_coeff_num(const int64_t dct_coeff_num) { int64_t Mfcc::get_dct_coeff_num() const { return GetValue(GetAttr(kDctCoeffNum)); } -AbstractBasePtr MfccInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(MfccInferType(input_args), - MfccInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameMfcc, Mfcc); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/minimum.cc b/mindspore/core/ops/minimum.cc index eacd33b5715..5bb91e7f5b6 100644 --- a/mindspore/core/ops/minimum.cc +++ b/mindspore/core/ops/minimum.cc @@ -26,34 +26,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr MinimumInferShape(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 MinimumInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - auto op_name = prim->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, op_name); - if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr &a) { return a == nullptr; })) { - MS_LOG(EXCEPTION) << "For '" << prim->name() - << ", the input args userd for infer shape and type, can not be a nullptr."; - } - std::map types; - (void)types.emplace("x", input_args[0]->BuildType()); - (void)types.emplace("y", input_args[1]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, op_name); -} -} // namespace - -AbstractBasePtr MinimumInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(MinimumInferType(primitive, input_args), - MinimumInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameMinimum, Minimum); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/non_max_suppression.cc b/mindspore/core/ops/non_max_suppression.cc index 8b6b2785a7e..132cbbc71a9 100644 --- a/mindspore/core/ops/non_max_suppression.cc +++ b/mindspore/core/ops/non_max_suppression.cc @@ -29,11 +29,6 @@ int64_t NonMaxSuppression::get_center_point_box() const { } void NonMaxSuppression::Init(const int64_t center_point_box) { this->set_center_point_box(center_point_box); } -AbstractBasePtr NonMaxSuppressionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_LOG(INFO) << "NonMaxSuppression infer shape in runtime."; - return std::make_shared(kInt32, std::vector{}); -} REGISTER_PRIMITIVE_C(kNameNonMaxSuppression, NonMaxSuppression); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/pack.cc b/mindspore/core/ops/pack.cc index e69c1052021..6ddb26ca162 100644 --- a/mindspore/core/ops/pack.cc +++ b/mindspore/core/ops/pack.cc @@ -18,55 +18,12 @@ namespace mindspore { namespace ops { -namespace { -std::vector _get_pack_shape(std::vector x_shapes, std::vector x_types, int64_t axis, - const std::string &name) { - (void)CheckAndConvertUtils::CheckInteger("len of input_x", (int64_t)x_shapes.size(), kGreaterEqual, 1, name); - (void)CheckAndConvertUtils::CheckSubClass("input_x[0]", x_types[0], {TypeIdToType(kObjectTypeTensorType)}, name); - auto output_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(x_shapes[0])[kShape]; - int64_t rank_base = SizeToLong(output_shape.size()); - int64_t N = SizeToLong(x_shapes.size()); - if (axis < 0) { - axis = axis + rank_base + 1; - } - for (int64_t i = 1; i < N; i++) { - auto type = x_types[LongToSize(i)]->cast()->element(); - MS_EXCEPTION_IF_NULL(type); - auto type0 = x_types[0]->cast()->element(); - MS_EXCEPTION_IF_NULL(type0); - CheckAndConvertUtils::Check("x_type[" + std::to_string(i) + "]", type->type_id(), kEqual, type0->type_id(), name); - auto shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(x_shapes[LongToSize(i)])[kShape]; - if (shape != output_shape) { - MS_EXCEPTION(ValueError) << "For '" + name + "' element " + std::to_string(i) + - "shape in input can't pack with first element."; - } - } - (void)output_shape.insert(output_shape.begin() + axis, N); - return output_shape; -} -} // namespace - void Pack::set_axis(const int64_t &axis) { (void)AddAttr(kAxis, MakeValue(axis)); } int64_t Pack::get_axis() const { return GetValue(GetAttr(kAxis)); } void Pack::Init(const int64_t &axis) { this->set_axis(axis); } -AbstractBasePtr PackInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - - MS_EXCEPTION_IF_NULL(input_args[0]); - auto x_shapes = input_args[0]->BuildShape()->cast()->shape(); - auto x_types = input_args[0]->BuildType()->cast()->elements(); - auto all_shape = _get_pack_shape(x_shapes, x_types, GetValue(primitive->GetAttr(kAxis)), prim_name); - auto tensor_type = x_types[0]->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto data_type = tensor_type->element(); - MS_EXCEPTION_IF_NULL(data_type); - return std::make_shared(data_type, all_shape); -} REGISTER_PRIMITIVE_C(kNamePack, Pack); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/pad.cc b/mindspore/core/ops/pad.cc index fd51f0e652a..a457a3f17a3 100644 --- a/mindspore/core/ops/pad.cc +++ b/mindspore/core/ops/pad.cc @@ -20,40 +20,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr PadInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - auto paddings_attr = GetValue>>(primitive->GetAttr(kPaddings)); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - (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++) { - if (paddings_attr[LongToSize(i)][LongToSize(j)] < 0) { - MS_LOG_ERROR << "For '" << prim_name << "', All elements of paddings must be >= 0, but got " - << paddings_attr[LongToSize(i)][LongToSize(j)]; - } - } - } - std::vector out_shape; - for (int64_t i = 0; i < int64_t(paddings_attr.size() / 2); i++) { - (void)out_shape.emplace_back(x_shape[LongToSize(i)] + paddings_attr[LongToSize(i)][0] + - paddings_attr[LongToSize(i)][1]); - } - return std::make_shared(out_shape); -} - -TypePtr PadInferType(const PrimitivePtr &prim, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - const std::set valid_types = {kTensorType}; - return CheckAndConvertUtils::CheckSubClass("infer type", input_args[0]->BuildType(), valid_types, prim->name()); -} -} // namespace - void Pad::Init(const std::vector> &paddings) { this->set_paddings(paddings); } void Pad::set_paddings(const std::vector> &paddings) { (void)this->AddAttr(kPaddings, MakeValue(paddings)); @@ -61,11 +27,7 @@ void Pad::set_paddings(const std::vector> &paddings) { std::vector> Pad::get_paddings() const { return GetValue>>(GetAttr(kPaddings)); } -AbstractBasePtr PadInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(PadInferType(primitive, input_args), - PadInferShape(primitive, input_args)->shape()); -} + REGISTER_PRIMITIVE_C(kNamePad, Pad); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/prelu.cc b/mindspore/core/ops/prelu.cc index 53e1e3cef95..4be4d004540 100644 --- a/mindspore/core/ops/prelu.cc +++ b/mindspore/core/ops/prelu.cc @@ -19,42 +19,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr PReLUInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - 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]; - const int64_t x_rank = 2; - const int64_t w_rank = 1; - (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(x_shape.size()), kGreaterEqual, x_rank, prim_name); - (void)CheckAndConvertUtils::CheckInteger("weight rank", SizeToLong(w_shape.size()), kEqual, w_rank, 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 PReLUInferType(const PrimitivePtr &prim, const std::vector &input_args) { - const std::set valid_types = {kFloat16, kFloat32}; - std::map check_map = {{"input_x", input_args[0]->BuildType()}, - {"weight", input_args[1]->BuildType()}}; - return CheckAndConvertUtils::CheckTensorTypeSame(check_map, valid_types, prim->name()); -} -} // 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(PReLUInferType(primitive, input_args), - PReLUInferShape(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNamePReLU, PReLU); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/prior_box.cc b/mindspore/core/ops/prior_box.cc index 1f2afa57b21..c3b45c539b5 100644 --- a/mindspore/core/ops/prior_box.cc +++ b/mindspore/core/ops/prior_box.cc @@ -119,30 +119,6 @@ void PriorBox::Init(const std::vector &min_sizes, const std::vectorset_offset(offset); } -AbstractBasePtr PriorBoxInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - MS_EXCEPTION_IF_NULL(input_args[0]); - std::vector different_aspect_ratios{1.0f}; - auto aspect_ratios = GetValue>(primitive->GetAttr(kAspectRatios)); - for (size_t i = 0; i < aspect_ratios.size(); i++) { - float ratio = aspect_ratios[i]; - bool exist = std::any_of(different_aspect_ratios.begin(), different_aspect_ratios.end(), - [&](float v) { return abs(ratio - v) < 1e-6; }); - if (!exist) { - (void)different_aspect_ratios.emplace_back(ratio); - if (GetValue(primitive->GetAttr(kFlip))) { - (void)different_aspect_ratios.emplace_back(1.0f / ratio); - } - } - } - auto min_sizes = GetValue>(primitive->GetAttr(kMinSizes)); - int64_t num_priors_box = SizeToLong(min_sizes.size() * different_aspect_ratios.size() + min_sizes.size()); - auto input = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - int64_t h = input[0] * input[1] * num_priors_box * 4; - std::vector output_shape{1, h, 1, 2}; - return std::make_shared(kFloat32, output_shape); -} REGISTER_PRIMITIVE_C(kNamePriorBox, PriorBox); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/quant_dtype_cast.cc b/mindspore/core/ops/quant_dtype_cast.cc index 9f6713b41ad..83fcf9ccd6f 100644 --- a/mindspore/core/ops/quant_dtype_cast.cc +++ b/mindspore/core/ops/quant_dtype_cast.cc @@ -29,23 +29,7 @@ void QuantDTypeCast::Init(const int64_t src_t, const int64_t dst_t) { this->set_src_t(src_t); this->set_dst_t(dst_t); } -AbstractBasePtr QuantDTypeCastInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - const int64_t input_num = 1; - const size_t x_index = 0; - CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, primitive->name()); - auto input_type = CheckAndConvertUtils::GetTensorInputType(primitive->name(), input_args, x_index); - auto dst_type = TypeIdToType(TypeId(GetValue(primitive->GetAttr(kDstT)))); - MS_EXCEPTION_IF_NULL(dst_type); - if (input_type != dst_type) { - MS_EXCEPTION(TypeError) << "For '" << primitive->name() << "', Input type should be " << dst_type->ToString() - << ", but got " << input_type->ToString(); - input_type->ToString(); - } - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - return std::make_shared(dst_type, input_shape); -} + REGISTER_PRIMITIVE_C(kNameQuantDTypeCast, QuantDTypeCast); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/range.cc b/mindspore/core/ops/range.cc index 910aabb8d2a..749ef7950d3 100644 --- a/mindspore/core/ops/range.cc +++ b/mindspore/core/ops/range.cc @@ -57,51 +57,6 @@ void Range::Init(const int64_t d_type, const int64_t start, const int64_t limit, this->set_delta(delta); } -AbstractBasePtr RangeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - int64_t shape_size = 0; - const size_t max_input_num = 3; - if (input_args.size() == max_input_num) { - MS_EXCEPTION_IF_NULL(input_args[kInputIndex0]->BuildValue()); - MS_EXCEPTION_IF_NULL(input_args[kInputIndex1]->BuildValue()); - MS_EXCEPTION_IF_NULL(input_args[kInputIndex2]->BuildValue()); - auto start_tensor = input_args[kInputIndex0]->BuildValue()->cast(); - auto limit_tensor = input_args[kInputIndex1]->BuildValue()->cast(); - auto delta_tensor = input_args[kInputIndex2]->BuildValue()->cast(); - auto dtype = start_tensor->data_type(); - switch (dtype) { - case kNumberTypeInt: - case kNumberTypeInt32: { - auto start = *reinterpret_cast(start_tensor->data_c()); - auto limit = *reinterpret_cast(limit_tensor->data_c()); - auto delta = *reinterpret_cast(delta_tensor->data_c()); - shape_size = - std::max(static_cast(std::ceil(static_cast(limit - start) / delta)), static_cast(0)); - } break; - case kNumberTypeFloat32: - case kNumberTypeFloat: { - auto start = *reinterpret_cast(start_tensor->data_c()); - auto limit = *reinterpret_cast(limit_tensor->data_c()); - auto delta = *reinterpret_cast(delta_tensor->data_c()); - shape_size = - std::max(static_cast(std::ceil(static_cast(limit - start) / delta)), static_cast(0)); - } break; - default: { - MS_LOG(EXCEPTION) << "For '" << primitive->name() - << "', the supported dataType is ['int32', 'float32'], but got " << dtype; - } - } - } else { - int64_t start = GetValue(primitive->GetAttr(kStart)); - int64_t limit = GetValue(primitive->GetAttr(kLimit)); - int64_t delta = GetValue(primitive->GetAttr(kDelta)); - shape_size = - std::max(static_cast(std::ceil(LongToDouble(limit - start) / delta)), static_cast(0)); - } - return std::make_shared( - kInt32, std::make_shared(std::vector{shape_size})); -} REGISTER_PRIMITIVE_C(kNameRange, Range); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/rank.cc b/mindspore/core/ops/rank.cc index 1881538971b..2f211476326 100644 --- a/mindspore/core/ops/rank.cc +++ b/mindspore/core/ops/rank.cc @@ -18,21 +18,6 @@ namespace mindspore { namespace ops { -namespace { -TypePtr RankInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - auto op_name = prim->name(); - MS_EXCEPTION_IF_NULL(input_args[0]); - auto infer_dtype = input_args[0]->BuildType(); - (void)CheckAndConvertUtils::CheckTensorTypeValid("x", infer_dtype, {kTensorType}, op_name); - return kTypeNone; -} -} // namespace -AbstractBasePtr RankInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - std::vector infer_shape; - return std::make_shared(RankInferType(primitive, input_args), infer_shape); -} REGISTER_PRIMITIVE_C(kNameRank, Rank); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/reduce.cc b/mindspore/core/ops/reduce.cc index 34190fbc196..462b73d5b2c 100644 --- a/mindspore/core/ops/reduce.cc +++ b/mindspore/core/ops/reduce.cc @@ -25,79 +25,12 @@ namespace mindspore { namespace ops { -namespace { -void reduce_one_axis(const int64_t one_axis, const int64_t dim, std::set axis_reduce) { - CheckAndConvertUtils::CheckInRange("axis", one_axis, kIncludeLeft, {-dim, dim}, "Reduce"); - if (one_axis < 0) { - axis_reduce.insert(one_axis); - } -} - -std::vector infer_shape_reduce(std::vector input_x_shape, const ValuePtr axis_value, - const bool keep_dims) { - int64_t dim = SizeToLong(input_x_shape.size()); - std::set axis_reduce; - if (axis_value == nullptr) { - std::vector vec; - if (keep_dims) { - return std::vector(dim, 1); - } - return vec; - } - auto axis_value_elem = GetValue>(axis_value); - if (axis_value_elem.size() == 1) { - reduce_one_axis(axis_value_elem[0], dim, axis_reduce); - } else { - size_t size = axis_value_elem.size(); - for (size_t i = 0; i < size; i++) { - reduce_one_axis(axis_value_elem[i], dim, axis_reduce); - } - } - std::vector out_shape; - for (int64_t i = 0; i < dim; i++) { - if (axis_reduce.find(i) != axis_reduce.end()) { - if (keep_dims) { - (void)out_shape.emplace_back(1); - } - } else { - (void)out_shape.emplace_back(input_x_shape[LongToSize(i)]); - } - } - return out_shape; -} - -abstract::ShapePtr ReduceInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - auto axis_value = input_args[1]->BuildValue(); - - MS_EXCEPTION_IF_NULL(primitive); - auto input_x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - - auto keep_dims = GetValue(primitive->GetAttr(kKeepDims)); - auto out_shape = infer_shape_reduce(input_x_shape, axis_value, keep_dims); - - return std::make_shared(out_shape); -} - -TypePtr ReduceInferType(const PrimitivePtr &prim, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - return CheckAndConvertUtils::CheckTensorTypeValid("input_x", input_args[0]->BuildType(), common_valid_types, - prim->name()); -} -} // namespace - 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)); } void Reduce::Init(const bool keep_dims) { this->set_keep_dims(keep_dims); } -AbstractBasePtr ReduceInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(ReduceInferType(primitive, input_args), - ReduceInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameReduce, Reduce); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/reshape.cc b/mindspore/core/ops/reshape.cc index fe7c6c988e0..fdb06857067 100644 --- a/mindspore/core/ops/reshape.cc +++ b/mindspore/core/ops/reshape.cc @@ -27,80 +27,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr ReshapeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto x = input_args[0]->cast(); - MS_EXCEPTION_IF_NULL(x); - auto shape = input_args[1]->cast(); - MS_EXCEPTION_IF_NULL(shape); - auto shape_v = GetValue>(shape->BuildValue()); - int64_t neg_index = -1; - int64_t dim_prod = 1; - for (size_t i = 0; i < shape_v.size(); ++i) { - if (shape_v[i] == -1) { - if (neg_index != -1) { - MS_LOG(EXCEPTION) << "For '" << prim_name << "', The Reshape's shape input can only has one -1 at most."; - } - neg_index = SizeToLong(i); - } else { - dim_prod *= shape_v[i]; - } - } - MS_EXCEPTION_IF_NULL(x->shape()); - auto x_shape = x->shape()->shape(); - int64_t arr_prod = - std::accumulate(x_shape.begin(), x_shape.end(), static_cast(1), std::multiplies()); - if (arr_prod <= 0) { - ShapeVector x_max_shape = x->shape()->max_shape(); - ShapeVector x_min_shape = x->shape()->min_shape(); - if (x_max_shape.empty()) { - x_max_shape = x_shape; - } - if (x_min_shape.empty()) { - x_min_shape = x_shape; - } - int64_t max_arr_prod = - std::accumulate(x_max_shape.begin(), x_max_shape.end(), static_cast(1), std::multiplies()); - int64_t min_arr_prod = - std::accumulate(x_min_shape.begin(), x_min_shape.end(), static_cast(1), std::multiplies()); - ShapeVector max_shape = shape_v; - ShapeVector min_shape = shape_v; - if (neg_index != -1) { - max_shape[LongToSize(neg_index)] = max_arr_prod / dim_prod; - min_shape[LongToSize(neg_index)] = min_arr_prod / dim_prod; - } else { - MS_LOG(EXCEPTION) << "For dynamic shape, Reshape's shape input must have neg index"; - } - return std::make_shared(x->element(), - std::make_shared(shape_v, min_shape, max_shape)); - } else { - if (dim_prod <= 0 || arr_prod % dim_prod != 0) { - MS_LOG(EXCEPTION) - << "For '" << prim_name - << "', The product of input_x's shape should > 0, and can be divided by product of input_shape, " - "but product of input_x's shape is " - << arr_prod << ", product of input_shape is" << dim_prod; - } - if (neg_index != -1) { - shape_v[LongToSize(neg_index)] = arr_prod / dim_prod; - dim_prod *= shape_v[LongToSize(neg_index)]; - } - if (arr_prod != dim_prod) { - MS_LOG(EXCEPTION) << "For '" << prim_name - << "',The product of input_x's shape should be equal to product of input_shape, " - "but product of input_x's shape is " - << arr_prod << ", product of input_shape is" << dim_prod; - } - return std::make_shared(x->element(), std::make_shared(shape_v)); - } -} REGISTER_PRIMITIVE_C(kNameReshape, Reshape); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/resize_bilinear.cc b/mindspore/core/ops/resize_bilinear.cc index 8817d4bd994..ed0f340bbc8 100644 --- a/mindspore/core/ops/resize_bilinear.cc +++ b/mindspore/core/ops/resize_bilinear.cc @@ -42,25 +42,7 @@ void ResizeBilinear::Init(const std::vector &size, const bool align_cor this->set_size(size); this->set_align_corners(align_corners); } -AbstractBasePtr ResizeBilinearInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("infer", SizeToLong(input_args.size()), kEqual, 1, prim_name); - // Infer shape - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - const int64_t shape_size = 4; - (void)CheckAndConvertUtils::CheckInteger("input rank", SizeToLong(input_shape.size()), kEqual, shape_size, prim_name); - std::vector out_shape = {input_shape[0], input_shape[1]}; - auto size = GetValue>(primitive->GetAttr(kSize)); - (void)out_shape.insert(out_shape.end(), size.begin(), size.end()); - - // Infer type - const std::set valid_types = {kFloat16, kFloat32}; - (void)CheckAndConvertUtils::CheckTensorTypeValid("input_type", input_args[0]->BuildType(), valid_types, prim_name); - return std::make_shared(input_args[0]->BuildType(), out_shape); -} REGISTER_PRIMITIVE_C(kNameResizeBilinear, ResizeBilinear); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/reverse_sequence.cc b/mindspore/core/ops/reverse_sequence.cc index 05fe1302dcf..f449e697f9a 100644 --- a/mindspore/core/ops/reverse_sequence.cc +++ b/mindspore/core/ops/reverse_sequence.cc @@ -35,38 +35,7 @@ int64_t ReverseSequence::get_batch_dim() const { auto value_ptr = this->GetAttr(kBatchDim); return GetValue(value_ptr); } -AbstractBasePtr ReverseSequenceInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num, - prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - // infer shape - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto seq_lengths = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - auto seq_dim = GetValue(primitive->GetAttr(kSeqDim)); - auto batch_dim = GetValue(primitive->GetAttr(kBatchDim)); - (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); - (void)valid_x_types.emplace(kBool); - const std::set valid_seq_types = {kInt32, kInt64}; - auto x_type = input_args[0]->BuildType()->cast()->element(); - auto seq_type = input_args[1]->BuildType()->cast()->element(); - auto infered_type = CheckAndConvertUtils::CheckTensorTypeValid("x_type", x_type, valid_x_types, prim_name); - (void)CheckAndConvertUtils::CheckTensorTypeValid("seq_type", seq_type, valid_seq_types, prim_name); - return std::make_shared(infered_type, input_shape); -} + REGISTER_PRIMITIVE_C(kNameReverseSequence, ReverseSequence); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/reverse_v2.cc b/mindspore/core/ops/reverse_v2.cc index 7a6f2af907e..4b5fa0b4e5e 100644 --- a/mindspore/core/ops/reverse_v2.cc +++ b/mindspore/core/ops/reverse_v2.cc @@ -21,24 +21,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr ReverseV2InferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - return std::make_shared(x_shape); -} - -TypePtr ReverseV2InferType(const PrimitivePtr &prim, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - const std::set valid_types = {kInt8, kInt16, kInt32, kInt64, kUInt8, kUInt16, - kUInt32, kUInt64, kFloat16, kFloat32, kFloat64, kBool}; - auto infer_type = input_args[0]->BuildType(); - return CheckAndConvertUtils::CheckTensorTypeValid("x type", infer_type, valid_types, prim->name()); -} -} // namespace - void ReverseV2::Init(const std::vector &axis) { this->set_axis(axis); } void ReverseV2::set_axis(const std::vector &axis) { (void)this->AddAttr(kAxis, MakeValue(axis)); } std::vector ReverseV2::get_axis() const { @@ -46,11 +28,6 @@ std::vector ReverseV2::get_axis() const { return GetValue>(value_ptr); } -AbstractBasePtr ReverseV2Infer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(ReverseV2InferType(primitive, input_args), - ReverseV2InferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameReverseV2, ReverseV2); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/rfft.cc b/mindspore/core/ops/rfft.cc index 90d76f71b0b..9ec37bd4794 100644 --- a/mindspore/core/ops/rfft.cc +++ b/mindspore/core/ops/rfft.cc @@ -21,36 +21,12 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr RfftInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto first_input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto out_shape = first_input_shape; - out_shape[out_shape.size() - 1] = GetValue(primitive->GetAttr(kFftLength)) / 2 + 1; - out_shape.push_back(2); - return std::make_shared(out_shape); -} - -TypePtr RfftInferType(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 kComplex64; -} -} // namespace - void Rfft::Init(const int64_t fft_length) { this->set_fft_length(fft_length); } void Rfft::set_fft_length(const int64_t fft_length) { (void)this->AddAttr(kFftLength, MakeValue(fft_length)); } int64_t Rfft::get_fft_length() const { return GetValue(GetAttr(kFftLength)); } -AbstractBasePtr RfftInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(RfftInferType(primitive, input_args), - RfftInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameRfft, Rfft); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/roi_pooling.cc b/mindspore/core/ops/roi_pooling.cc index 8964896fe80..1b0f2e522f1 100644 --- a/mindspore/core/ops/roi_pooling.cc +++ b/mindspore/core/ops/roi_pooling.cc @@ -48,31 +48,7 @@ void ROIPooling::Init(const int64_t pooled_h, const int64_t pooled_w, const floa this->set_pooled_w(pooled_w); this->set_scale(scale); } -AbstractBasePtr ROIPoolingInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("infer", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - MS_EXCEPTION_IF_NULL(input_args[0]); - MS_EXCEPTION_IF_NULL(input_args[1]); - // Infer type - auto output_data_type = input_args[0]->BuildType()->cast()->element(); - - // Infer shape - auto new_h = GetValue(primitive->GetAttr(kPooledH)); - auto new_w = GetValue(primitive->GetAttr(kPooledW)); - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto roi_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - std::vector output_shape; - output_shape.push_back(roi_shape[0]); - output_shape.push_back(new_h); - output_shape.push_back(new_w); - output_shape.push_back(input_shape[1]); - - return std::make_shared(output_data_type, std::make_shared(output_shape)); -} REGISTER_PRIMITIVE_C(kNameROIPooling, ROIPooling); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/scatter_nd.cc b/mindspore/core/ops/scatter_nd.cc index b84b69dee39..543b48601ae 100644 --- a/mindspore/core/ops/scatter_nd.cc +++ b/mindspore/core/ops/scatter_nd.cc @@ -22,39 +22,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr ScatterNdInferShape(const std::vector &input_args) { - auto shape_value = input_args[kInputIndex2]->BuildValue(); - auto shape_value_element = GetValue>(shape_value); - for (const auto &shape : shape_value_element) { - (void)CheckAndConvertUtils::CheckInteger("shape value", shape, kGreaterThan, 0, "ScatterNd"); - } - auto indices_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape())[kShape]; - auto update_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex1]->BuildShape())[kShape]; - (void)CheckAndConvertUtils::CheckInteger("indices_shape[0] and update_shape[0]", indices_shape[0], kEqual, - update_shape[0], "ScatterNd"); - return std::make_shared(shape_value_element); -} - -TypePtr ScatterNdInferType(const PrimitivePtr &prim, const std::vector &input_args) { - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - const std::set indices_valid_types = {kInt32, kInt64}; - const std::set update_valid_types = {kTensorType}; - auto indices_type = input_args[0]->BuildType(); - auto update_type = input_args[1]->BuildType(); - (void)CheckAndConvertUtils::CheckTypeValid("update type", update_type, update_valid_types, prim->name()); - (void)CheckAndConvertUtils::CheckTensorTypeValid("indices type", indices_type, indices_valid_types, prim->name()); - return input_args[1]->BuildType(); -} -} // namespace - -AbstractBasePtr ScatterNdInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(ScatterNdInferType(primitive, input_args), - ScatterNdInferShape(input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameScatterNd, ScatterNd); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/skip_gram.cc b/mindspore/core/ops/skip_gram.cc index 6325542d531..1189a9592eb 100644 --- a/mindspore/core/ops/skip_gram.cc +++ b/mindspore/core/ops/skip_gram.cc @@ -20,27 +20,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr SkipGramInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - if (input_args.size() != 1) { - MS_LOG(ERROR) << "For " << primitive->name() << ", it should have one input, but got " << input_args.size() - << " input."; - } - auto infer_value = input_args[0]->BuildValue(); - if (infer_value == nullptr) { - MS_LOG(INFO) << " Do '" << primitive->name() << "' operator infer shape in runtime."; - } - auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - return std::make_shared(in_shape); -} - -TypePtr SkipGramInferType(const std::vector &input_args) { - auto infer_type = input_args[0]->BuildType(); - return infer_type; -} -} // namespace - void SkipGram::set_include_all_grams(const bool include_all_grams) { (void)AddAttr(kIncludeALLGrams, MakeValue(include_all_grams)); } @@ -64,11 +43,6 @@ void SkipGram::Init(const bool include_all_grams, const int64_t max_skip_size, c this->set_ngram_size(ngram_size); } -AbstractBasePtr SkipGramInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(SkipGramInferType(input_args), - SkipGramInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameSkipGram, SkipGram); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/space_to_batch.cc b/mindspore/core/ops/space_to_batch.cc index 075ebe2bb53..8c5d220742e 100644 --- a/mindspore/core/ops/space_to_batch.cc +++ b/mindspore/core/ops/space_to_batch.cc @@ -25,39 +25,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr SpaceToBatchInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - const int64_t x_rank = 4; - (void)CheckAndConvertUtils::CheckInteger("x rank", SizeToLong(input_shape.size()), kEqual, x_rank, prim_name); - std::vector output_shape(input_shape.size()); - auto block_shape_vector = GetValue>(primitive->GetAttr(kBlockSize)); - auto paddings = GetValue>>(primitive->GetAttr(kPaddings)); - const size_t kDimsOffset = 2; - for (size_t i = 0; i < kDimsOffset; i++) { - auto padded = output_shape[i + kDimsOffset] + paddings[i][0] + paddings[i][1]; - const int64_t input_num = 0; - (void)CheckAndConvertUtils::CheckInteger("padded shape", SizeToLong(padded % block_shape_vector.size()), kEqual, - input_num, prim_name); - output_shape[i + kDimsOffset] = padded / SizeToLong(block_shape_vector.size()); - } - output_shape[0] *= SizeToLong(block_shape_vector.size() * block_shape_vector.size()); - return std::make_shared(output_shape); -} - -TypePtr SpaceToBatchInferType(const PrimitivePtr &prim, const std::vector &input_args) { - if (std::any_of(input_args.begin(), input_args.end(), [](const AbstractBasePtr arg) { return arg == nullptr; })) { - MS_LOG(EXCEPTION) << "For '" << prim->name() - << ", the input args userd for infer shape and type, can not be a nullptr."; - } - std::map types; - (void)types.emplace("x", input_args[0]->BuildType()); - return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name()); -} -} // namespace void SpaceToBatch::set_paddings(const std::vector> &paddings) { (void)this->AddAttr(kPaddings, MakeValue(paddings)); int64_t h = SizeToLong(paddings.size()); @@ -87,11 +54,7 @@ void SpaceToBatch::Init(const std::vector block_size, const std::vector this->set_paddings(paddings); this->set_block_size(block_size); } -AbstractBasePtr SpaceToBatchInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(SpaceToBatchInferType(primitive, input_args), - SpaceToBatchInferShape(primitive, input_args)); -} + REGISTER_PRIMITIVE_C(kNameSpaceToBatch, SpaceToBatch); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/space_to_batch_nd.cc b/mindspore/core/ops/space_to_batch_nd.cc index 36783b38c76..0a3720f5cea 100644 --- a/mindspore/core/ops/space_to_batch_nd.cc +++ b/mindspore/core/ops/space_to_batch_nd.cc @@ -25,42 +25,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr SpaceToBatchNDInferShape(const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - const int64_t shape_size = 4; - (void)CheckAndConvertUtils::CheckInteger("input_x rank", SizeToLong(x_shape.size()), kEqual, shape_size, prim_name); - auto out_shape = x_shape; - int64_t block_shape_prod = 1; - const size_t offset = 2; - auto block_shape = GetValue>(primitive->GetAttr(kBlockShape)); - auto padding = GetValue>>(primitive->GetAttr(kPaddings)); - size_t size = block_shape.size(); - for (size_t i = 0; i < size; i++) { - int64_t padded = out_shape[i + offset] + padding[i][0] + padding[i][1]; - if (padded % block_shape[i] != 0) { - MS_EXCEPTION(ValueError) << prim_name << " padded[" << i << "]" << padded << "should be divisible by block_shape[" - << i << "]" << block_shape[i]; - } - out_shape[i + offset] = int64_t(floor(padded / static_cast(block_shape[i]))); - block_shape_prod = block_shape_prod * block_shape[i]; - } - out_shape[0] = out_shape[0] * block_shape_prod; - return std::make_shared(out_shape); -} - -TypePtr SpaceToBatchNDInferType(const PrimitivePtr &prim, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(prim); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - return input_args[0]->BuildType()->cast()->element(); -} -} // namespace - void SpaceToBatchND::set_paddings(std::vector> paddings) { const int64_t pad_size = 2; (void)CheckAndConvertUtils::CheckInteger(kPaddings, SizeToLong(paddings.size()), kEqual, pad_size, this->name()); @@ -99,11 +63,6 @@ void SpaceToBatchND::Init(const std::vector block_shape, const std::vec this->set_block_shape(block_shape); } -AbstractBasePtr SpaceToBatchNDInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(SpaceToBatchNDInferType(primitive, input_args), - SpaceToBatchNDInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameSpaceToBatchND, SpaceToBatchND); } // namespace ops } // namespace mindspore 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 fed08b55a7e..15591f60acd 100644 --- a/mindspore/core/ops/sparse_softmax_cross_entropy_with_logits.cc +++ b/mindspore/core/ops/sparse_softmax_cross_entropy_with_logits.cc @@ -33,29 +33,6 @@ void SparseSoftmaxCrossEntropyWithLogits::set_is_grad(const bool is_grad) { bool SparseSoftmaxCrossEntropyWithLogits::get_is_grad() const { return GetValue(GetAttr(kIsGrad)); } -AbstractBasePtr SparseSoftmaxCrossEntropyWithLogitsInfer(const abstract::AnalysisEnginePtr &, - const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, input_num, - prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - // infer shape - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - std::vector output_shape; - if (GetValue(primitive->GetAttr(kIsGrad)) != 0) { - output_shape = input_shape; - } else { - output_shape.push_back(1); - } - // infer type - auto output_type = input_args[0]->BuildType()->cast()->element(); - return std::make_shared(output_type, output_shape); -} REGISTER_PRIMITIVE_C(kNameSparseSoftmaxCrossEntropyWithLogits, SparseSoftmaxCrossEntropyWithLogits); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/sparse_to_dense.cc b/mindspore/core/ops/sparse_to_dense.cc index 4e9e87b4c30..7b756bb1145 100644 --- a/mindspore/core/ops/sparse_to_dense.cc +++ b/mindspore/core/ops/sparse_to_dense.cc @@ -24,21 +24,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr SparseToDenseInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 3; - (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - // infer shape - auto dense_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex3]->BuildShape())[kShape]; - // infer type - auto values_type = input_args[1]->BuildType()->cast()->element(); - return std::make_shared(values_type, dense_shape); -} REGISTER_PRIMITIVE_C(kNameSparseToDense, SparseToDense); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/stack.cc b/mindspore/core/ops/stack.cc index 8e90e0318a0..594943456af 100644 --- a/mindspore/core/ops/stack.cc +++ b/mindspore/core/ops/stack.cc @@ -18,63 +18,12 @@ namespace mindspore { namespace ops { -namespace { -abstract::AbstractBasePtr StackInfer(const PrimitivePtr &primitive, const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - - if (input_args.size() <= 1) { - MS_LOG(ERROR) << "For '" << primitive->name() - << "', input args size should be greater than 1, but got invalid input args size:" - << input_args.size(); - } - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - for (size_t i = 1; i < input_args.size(); ++i) { - auto input_shape_tmp = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[i]->BuildShape())[kShape]; - if (input_shape_tmp.size() != input_shape.size()) { - MS_LOG(ERROR) << "For '" << primitive->name() - << "', all input shape size should be the same, but got input[0] size = " << input_shape.size() - << ", input[" << i << "] size = " << input_shape_tmp.size(); - } - for (size_t j = 0; j < input_shape.size(); ++j) { - if (input_shape_tmp.at(j) != input_shape.at(j)) { - MS_LOG(ERROR) << "For '" << primitive->name() - << "', all input shape should be the same, but got input[0] shape = " << input_shape.at(j) - << ", input[" << i << "] shape = " << input_shape_tmp.at(j); - } - } - } - std::vector infer_shape = input_shape; - (void)infer_shape.insert(infer_shape.begin() + GetValue(primitive->GetAttr(kAxis)), input_args.size()); - - auto infer_type0 = input_args[0]->BuildType()->cast()->element(); - for (size_t i = 1; i < input_args.size(); i++) { - if (input_args[i]->BuildType()->cast()->element() == infer_type0) { - MS_LOG(ERROR) << "For '" << primitive->name() - << "', all input should have the same data type, but input[0] data type = " << infer_type0 - << ", input[" << i - << "] data type = " << input_args[i]->BuildType()->cast()->element(); - } - } - auto infer_type = input_args[0]->BuildType()->cast()->element(); - auto output0 = std::make_shared(infer_type, infer_shape); - AbstractBasePtrList output1 = {output0}; - return std::make_shared(output1); -} -} // namespace - void Stack::set_axis(const int64_t axis) { (void)AddAttr(kAxis, MakeValue(axis)); } int64_t Stack::get_axis() const { return GetValue(GetAttr(kAxis)); } void Stack::Init(const int64_t axis) { this->set_axis(axis); } -AbstractBasePtr StackInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(StackInfer(primitive, input_args)); -} REGISTER_PRIMITIVE_C(kNameStack, Stack); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/tensor_list_from_tensor.cc b/mindspore/core/ops/tensor_list_from_tensor.cc index 2bd80b56bfe..f8c4d972d67 100644 --- a/mindspore/core/ops/tensor_list_from_tensor.cc +++ b/mindspore/core/ops/tensor_list_from_tensor.cc @@ -20,31 +20,6 @@ namespace mindspore { namespace ops { -namespace { -abstract::ShapePtr TensorListFromTensorInferShape(const PrimitivePtr &primitive, - 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_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - if (input0_shape.size() < 1) { - MS_LOG(ERROR) << "For '" << op_name << "', input[0] shape size must be greater than 0, but got " - << input0_shape.size() << "."; - } - int64_t dim0 = input0_shape[0]; - if (dim0 < 0) { - MS_LOG(ERROR) << "For '" << op_name << "', input[0] dim must be greater than or equal to 0, but got " << dim0 - << "."; - } - std::vector infer_shape = {1, dim0}; - return std::make_shared(infer_shape); -} - -TypePtr TensorListFromTensorInferType() { return kTensorType; } -} // namespace - void TensorListFromTensor::Init(const int64_t element_dtype, const int64_t shape_type) { this->set_element_dtype(element_dtype); this->set_shape_type(shape_type); @@ -68,11 +43,6 @@ void TensorListFromTensor::set_shape_type(const int64_t shape_type) { (void)this->AddAttr(kShapeType, MakeValue(shape_type)); } -AbstractBasePtr TensorListFromTensorInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - return std::make_shared(TensorListFromTensorInferType(), - TensorListFromTensorInferShape(primitive, input_args)->shape()); -} REGISTER_PRIMITIVE_C(kNameTensorListFromTensor, TensorListFromTensor); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/tensor_list_stack.cc b/mindspore/core/ops/tensor_list_stack.cc index 29dc1695122..00edac45956 100644 --- a/mindspore/core/ops/tensor_list_stack.cc +++ b/mindspore/core/ops/tensor_list_stack.cc @@ -46,24 +46,6 @@ int64_t TensorListStack::get_element_dtype() const { return GetValue(value_ptr); } -AbstractBasePtr TensorListStackInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - for (const auto &input : input_args) { - MS_EXCEPTION_IF_NULL(input); - } - auto input0_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - int64_t num = std::accumulate(input0_shape.begin(), input0_shape.end(), 1LL, std::multiplies()); - if (num == 0) { - MS_LOG(ERROR) << "For '" << primitive->name() << "', Try to stack a empty tensorlist!"; - } - if (input_args[1]->BuildShape() == nullptr) { - MS_LOG(ERROR) << "For '" << primitive->name() << "', the seceond input data shape is nullptr"; - } - auto input1_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[1]->BuildShape())[kShape]; - (void)input1_shape.insert(input1_shape.begin(), 1); - return std::make_shared(input_args[0]->BuildType(), input1_shape); -} REGISTER_PRIMITIVE_C(kNameTensorListStack, TensorListStack); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/topk.cc b/mindspore/core/ops/topk.cc index 71d4e8a8e54..03db601089c 100644 --- a/mindspore/core/ops/topk.cc +++ b/mindspore/core/ops/topk.cc @@ -28,35 +28,7 @@ bool TopK::get_sorted() const { auto value_ptr = this->GetAttr(kSorted); return GetValue(value_ptr); } -AbstractBasePtr TopKInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - const int64_t input_num = 2; - (void)CheckAndConvertUtils::CheckInteger("top_k_infer", SizeToLong(input_args.size()), kEqual, input_num, prim_name); - // Infer dtype - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto output1_type = kInt32; - const std::set valid_types = {kFloat16, kFloat32}; - auto output0_type = - CheckAndConvertUtils::CheckTensorTypeValid("input_x", input_args[0]->BuildType(), valid_types, prim_name); - - // Infer shape - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - auto k_v = GetValue(input_args[1]->BuildValue()); - auto ndims = x_shape.size() - 1; - std::pair k_range(0, x_shape[ndims]); - CheckAndConvertUtils::CheckInRange("top_k_infer", static_cast(k_v), kIncludeRight, k_range, - prim_name); - x_shape[ndims] = k_v; - auto output0 = std::make_shared(output0_type, x_shape); - auto output1 = std::make_shared(output1_type, x_shape); - AbstractBasePtrList output = {output0, output1}; - return std::make_shared(output); -} REGISTER_PRIMITIVE_C(kNameTopK, TopK); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/unpack.cc b/mindspore/core/ops/unpack.cc index f3a45a0763e..d58fb6d25d1 100644 --- a/mindspore/core/ops/unpack.cc +++ b/mindspore/core/ops/unpack.cc @@ -22,35 +22,6 @@ void Unpack::Init(const int64_t axis) { this->set_axis(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, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - MS_EXCEPTION_IF_NULL(input_args[0]); - (void)CheckAndConvertUtils::CheckSubClass("x", input_args[0]->BuildType(), {TypeIdToType(kObjectTypeTensorType)}, - prim_name); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - int64_t dim = SizeToLong(x_shape.size()); - int64_t axis = GetValue(primitive->GetAttr(kAxis)); - if (axis < 0) { - axis = axis + dim; - } - auto output_num = x_shape[LongToSize(axis)]; - (void)CheckAndConvertUtils::CheckInteger("output_num", output_num, kGreaterThan, 0, prim_name); - auto output_valid_check = x_shape[LongToSize(axis)] - output_num; - (void)CheckAndConvertUtils::CheckInteger("The dimension which to unpack divides output_num", output_valid_check, - kEqual, 0, prim_name); - std::vector infer_shape(x_shape.begin(), x_shape.begin() + axis); - (void)infer_shape.insert(infer_shape.end(), x_shape.begin() + axis + 1, x_shape.end()); - AbstractBasePtrList output; - auto tensor_type = input_args[0]->BuildType()->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto element = tensor_type->element(); - for (int64_t i = 0; i != output_num; i++) { - output.push_back(std::make_shared(element, infer_shape)); - } - return std::make_shared(output); -} REGISTER_PRIMITIVE_C(kNameUnpack, Unpack); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/unsorted_segment_sum.cc b/mindspore/core/ops/unsorted_segment_sum.cc index ccf62bbb345..53723e88845 100644 --- a/mindspore/core/ops/unsorted_segment_sum.cc +++ b/mindspore/core/ops/unsorted_segment_sum.cc @@ -25,45 +25,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr UnsortedSegmentSumInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - - // Infer type - for (const auto &item : input_args) { - MS_EXCEPTION_IF_NULL(item); - } - auto x_type = input_args[0]->BuildType()->cast()->element(); - // Infer shape - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - (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, - prim_name); - CheckAndConvertUtils::Check("input_x", int64_t(x_shape.size()), kGreaterEqual, int64_t(segment_ids_shape.size()), - prim_name); - - if ((x_shape.end() != find(x_shape.begin(), x_shape.end(), -1)) && - (segment_ids_shape.end() != find(segment_ids_shape.begin(), segment_ids_shape.end(), -1))) { - size_t size = segment_ids_shape.size(); - for (size_t i = 0; i < size; ++i) { - CheckAndConvertUtils::Check("segment_ids_shp", segment_ids_shape[i], kEqual, x_shape[i], prim_name); - } - } - - const std::set valid_num_segments_types = {kInt32, kInt64}; - (void)CheckAndConvertUtils::CheckTensorTypeValid("num_segments", input_args[kInputIndex2]->BuildType(), - valid_num_segments_types, prim_name); - size_t size_segment_ids_shp = segment_ids_shape.size(); - size_t size_x_shape = x_shape.size(); - for (size_t i = size_segment_ids_shp; i < size_x_shape; ++i) { - (void)shp.emplace_back(x_shape[i]); - } - - return std::make_shared(x_type, shp); -} REGISTER_PRIMITIVE_C(kNameUnsortedSegmentSum, UnsortedSegmentSum); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/unsqueeze.cc b/mindspore/core/ops/unsqueeze.cc index 7fef97cbff4..92817d48319 100644 --- a/mindspore/core/ops/unsqueeze.cc +++ b/mindspore/core/ops/unsqueeze.cc @@ -26,46 +26,7 @@ void Unsqueeze::Init(const std::vector axis) { this->set_axis(axis); } void Unsqueeze::set_axis(const std::vector axis) { (void)this->AddAttr(kAxis, MakeValue(axis)); } std::vector Unsqueeze::get_axis() const { return GetValue>(GetAttr(kAxis)); } -AbstractBasePtr UnsqueezeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, - const std::vector &input_args) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("unsqueeze_infer", SizeToLong(input_args.size()), kEqual, 1, prim_name); - MS_EXCEPTION_IF_NULL(input_args[0]); - auto input = input_args[0]; - - // Infer type - auto input_type = input->BuildType()->cast()->element(); - - // Infer shape - auto dims = GetValue>(primitive->GetAttr(kAxis)); - auto input_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input->BuildShape())[kShape]; - auto input_rank = input_shape.size(); - auto dim_rank = dims.size(); - std::vector out_shape; - if (dim_rank == 0) { - (void)std::copy_if(input_shape.begin(), input_shape.end(), out_shape.begin(), - [](const auto item) { return item == 1; }); - } else { - auto sz = input_rank + dim_rank; - size_t in_itr = 0; - size_t ax_itr = 0; - for (size_t i = 0; i < sz; i++) { - if (ax_itr < dim_rank && dims[ax_itr] == (int64_t)i) { - (void)out_shape.emplace_back(1); - ax_itr++; - } else if (ax_itr < dim_rank && dims[ax_itr] + sz == LongToSize(i)) { - (void)out_shape.emplace_back(1); - ax_itr++; - } else { - (void)out_shape.emplace_back(input_shape[in_itr]); - in_itr++; - } - } - } - return std::make_shared(input_type, out_shape); -} REGISTER_PRIMITIVE_C(kNameUnsqueeze, Unsqueeze); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/unstack.cc b/mindspore/core/ops/unstack.cc index cbb5d4610f0..081cc6295a4 100644 --- a/mindspore/core/ops/unstack.cc +++ b/mindspore/core/ops/unstack.cc @@ -21,33 +21,7 @@ namespace ops { void Unstack::Init(const int64_t axis) { this->set_axis(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) { - MS_EXCEPTION_IF_NULL(primitive); - auto prim_name = primitive->name(); - MS_EXCEPTION_IF_NULL(input_args[0]); - auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape]; - int64_t dim = SizeToLong(x_shape.size()); - int64_t axis = GetValue(primitive->GetAttr(kAxis)); - if (axis < 0) { - axis = axis + dim; - } - auto output_num = x_shape[LongToSize(axis)]; - (void)CheckAndConvertUtils::CheckInteger("output_num", output_num, kGreaterThan, 0, prim_name); - auto output_valid_check = x_shape[LongToSize(axis)] - output_num; - (void)CheckAndConvertUtils::CheckInteger("The dimension which to unstack divides output_num", output_valid_check, - kEqual, 0, prim_name); - std::vector infer_shape(x_shape.begin(), x_shape.begin() + axis); - (void)infer_shape.insert(infer_shape.end(), x_shape.begin() + axis + 1, x_shape.end()); - AbstractBasePtrList output; - auto tensor_type = input_args[0]->BuildType()->cast(); - MS_EXCEPTION_IF_NULL(tensor_type); - auto element = tensor_type->element(); - for (int64_t i = 0; i != output_num; i++) { - output.push_back(std::make_shared(element, infer_shape)); - } - return std::make_shared(output); -} + REGISTER_PRIMITIVE_C(kNameUnstack, Unstack); } // namespace ops } // namespace mindspore diff --git a/mindspore/core/ops/where.cc b/mindspore/core/ops/where.cc index 724a48f6100..d01fb7b6f38 100644 --- a/mindspore/core/ops/where.cc +++ b/mindspore/core/ops/where.cc @@ -22,49 +22,6 @@ namespace mindspore { namespace ops { -AbstractBasePtr WhereInfer(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); - } - auto op_name = primitive->name(); - const int64_t input_num = 3; - (void)CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kGreaterEqual, input_num, - op_name); - auto input0_type_ = input_args[kInputIndex0]->BuildType()->cast(); - MS_EXCEPTION_IF_NULL(input0_type_); - auto input0_type = input0_type_->element(); - auto input0_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex0]->BuildShape())[kShape]; - auto num = input_args[kInputIndex0]->BuildValue()->cast()->ElementsNum(); - auto input1_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex1]->BuildShape())[kShape]; - auto num1 = input_args[kInputIndex1]->BuildValue()->cast()->ElementsNum(); - auto input2_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[kInputIndex2]->BuildShape())[kShape]; - auto num2 = input_args[kInputIndex2]->BuildValue()->cast()->ElementsNum(); - auto nummax = num > num1 ? num : (num1 > num2 ? num1 : num2); - size_t axisout = 0; - size_t temp = 0; - for (size_t j = 0; j < input0_shape.size(); j++) { - if (input0_shape[j] == input1_shape[j] && input0_shape[j] != input2_shape[j]) { - axisout = j; - break; - } - if (input0_shape[j] == input2_shape[j] && input0_shape[j] != input1_shape[j]) { - axisout = j; - break; - } - if (input1_shape[j] != input2_shape[j] && input0_shape[j] == input1_shape[j]) { - axisout = j; - break; - } - temp += 1; - if (temp == input0_shape.size()) { - return std::make_shared(input0_type, input0_shape); - } - } - input0_shape[axisout] = (int64_t)nummax; - return std::make_shared(input0_type, input0_shape); -} REGISTER_PRIMITIVE_C(kNameWhere, Where); } // namespace ops } // namespace mindspore