• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "ops/tensor_copy.h"
18 #include <map>
19 #include <set>
20 #include <string>
21 #include "abstract/ops/primitive_infer_map.h"
22 #include "mindapi/src/helper.h"
23 #include "mindspore/core/ops/framework_ops.h"
24 #include "ops/op_utils.h"
25 #include "utils/check_convert_utils.h"
26 
27 namespace mindspore {
28 namespace ops {
29 namespace {
TensorMoveInferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)30 abstract::ShapePtr TensorMoveInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
31   auto input_shape_ptr = input_args[kInputIndex0]->GetShape();
32   MS_EXCEPTION_IF_NULL(input_shape_ptr);
33   return input_shape_ptr->cast<abstract::ShapePtr>();
34 }
35 
TensorMoveInferType(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)36 TypePtr TensorMoveInferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
37   auto prim_name = primitive->name();
38   std::map<std::string, TypePtr> type_dict;
39   (void)type_dict.emplace("input", input_args[kInputIndex0]->GetType());
40   std::set<TypePtr> check_list(all_types);
41   (void)check_list.insert(kBool);
42   return CheckAndConvertUtils::CheckTensorTypeSame(type_dict, check_list, prim_name);
43 }
44 }  // namespace
45 
46 MIND_API_OPERATOR_IMPL(TensorMove, BaseOperator);
TensorMoveInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)47 AbstractBasePtr TensorMoveInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
48                                 const std::vector<AbstractBasePtr> &input_args) {
49   MS_EXCEPTION_IF_NULL(primitive);
50   const int64_t input_num = 1;
51   CheckAndConvertUtils::CheckInputArgs(input_args, kGreaterEqual, input_num, primitive->name());
52   // Just check dtype is tensor, shape is not change.
53   (void)TensorMoveInferType(primitive, input_args);
54   return input_args[kIndex0]->Clone();
55 }
56 
57 // AG means auto generated
58 class MIND_API AGTensorMoveInfer : public abstract::OpInferBase {
59  public:
InferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args) const60   BaseShapePtr InferShape(const PrimitivePtr &primitive,
61                           const std::vector<AbstractBasePtr> &input_args) const override {
62     return TensorMoveInferShape(primitive, input_args);
63   }
64 
InferType(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args) const65   TypePtr InferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) const override {
66     return TensorMoveInferType(primitive, input_args);
67   }
InferShapeAndType(const abstract::AnalysisEnginePtr & engine,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args) const68   AbstractBasePtr InferShapeAndType(const abstract::AnalysisEnginePtr &engine, const PrimitivePtr &primitive,
69                                     const std::vector<AbstractBasePtr> &input_args) const override {
70     return TensorMoveInfer(engine, primitive, input_args);
71   }
72 };
73 
74 REGISTER_PRIMITIVE_OP_INFER_IMPL(TensorMove, prim::kPrimTensorMove, AGTensorMoveInfer, false);
75 }  // namespace ops
76 }  // namespace mindspore
77