• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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 #ifndef MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_PRIMITIVE_MAPPER_H_
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_PRIMITIVE_MAPPER_H_
19 
20 #include <string>
21 #include <memory>
22 #include <vector>
23 #include "base/base.h"
24 #include "include/errorcode.h"
25 #include "ir/anf.h"
26 #include "tools/optimizer/common/gllo_utils.h"
27 
28 namespace mindspore {
29 namespace lite {
30 class PrimitiveMapper {
31  public:
PrimitiveMapper(const std::string & name)32   explicit PrimitiveMapper(const std::string &name) : name_(name) {}
33 
34   virtual ~PrimitiveMapper() = default;
35 
36   virtual STATUS Mapper(const CNodePtr &cnode);
37 
38  protected:
39   STATUS AttrAdjust(const PrimitivePtr &prim, const std::string &name) const;
40 
41   STATUS MoveAttrMap(const CNodePtr &cnode, const PrimitivePtr &dst_prim) const;
42 
43   STATUS GetValueNodeAndPrimFromCnode(const CNodePtr &cnode, ValueNodePtr *value_node, PrimitivePtr *prim_ptr) const;
44 
45   STATUS AdjustPoolAttr(int fmk_type, const std::string &src_prim_name, const PrimitivePtr &dst_prim) const;
46 
47   STATUS AddFloatAttrToInput(const FuncGraphPtr &func_graph, const CNodePtr &cnode, const PrimitivePtr &dst_prim,
48                              const std::string &attr_name, bool empty_shape) const;
49 
50   STATUS AddIntVecAttrToInput(const FuncGraphPtr &func_graph, const CNodePtr &cnode, const PrimitivePtr &dst_prim,
51                               const std::string &attr_name) const;
52 
53   STATUS AddIntAttrToInput(const FuncGraphPtr &func_graph, const CNodePtr &cnode, const PrimitivePtr &dst_prim,
54                            const std::string &attr_name, bool empty_shape) const;
55 
56   STATUS AddAttrForDynInputPrimitive(const CNodePtr &cnode) const;
57 
58   STATUS AdjustAttrFormat(const PrimitivePtr &prim, const std::string &name) const;
59 
60   CNodePtr NewCNode(const CNodePtr &cnode, const PrimitivePtr &primitive, const std::vector<AnfNodePtr> &inputs,
61                     const abstract::AbstractBasePtr &abstract, const std::string &name) const;
62 
63   CNodePtr NewCNode(const CNodePtr &cnode, const PrimitivePtr &primitive, const std::vector<AnfNodePtr> &inputs,
64                     const ShapeVector &shape, TypeId type_id, const std::string &name) const;
65 
66  private:
67   void AdjustCaffePoolAttr(const std::string &src_prim_name, const PrimitivePtr &dst_prim) const;
68 
69   void AdjustOnnxPoolAttr(const std::string &src_prim_name, const PrimitivePtr &dst_prim) const;
70 
71   std::string name_;
72 };
73 
74 using PrimitiveMapperPtr = std::shared_ptr<PrimitiveMapper>;
75 }  // namespace lite
76 }  // namespace mindspore
77 #endif  // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_MAPPER_PRIMITIVE_MAPPER_H_
78