• 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_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_TILING_OP_TILING_ADAPTER_H_
18 #define MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_TILING_OP_TILING_ADAPTER_H_
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 #include <tuple>
25 #include "backend/kernel_compiler/oplib/opinfo.h"
26 #include "register/op_tiling.h"
27 #include "external/graph/operator.h"
28 #include "graph/utils/graph_utils.h"
29 #include "abstract/primitive_infer_map.h"
30 
31 namespace mindspore {
32 namespace device {
33 namespace tiling {
34 class OpTilingCalculateAdapter {
35  public:
36   OpTilingCalculateAdapter() = default;
37   ~OpTilingCalculateAdapter() = default;
38 
39   ge::NodePtr AnfNodeToGeNodeAdapter(const CNodePtr &node, ge::ComputeGraphPtr *ge_graph,
40                                      const std::map<uint32_t, tensor::TensorPtr> &depend_tensor_map,
41                                      const std::string &op_compile_info);
42 
43  private:
44   void ConvertInputShapeAndType(const CNodePtr &node, ge::OpDescPtr *op_desc);
45   void ConvertOutputShapeAndType(const CNodePtr &node, ge::OpDescPtr *op_desc);
46   void ConvertCompileInfo(const CNodePtr &node, ge::OpDescPtr *op_desc);
47   void ConvertAttrs(const CNodePtr &node, ge::OpDescPtr *op_desc);
48   std::vector<std::tuple<std::size_t, ge::NodePtr>> ConvertDepends(
49     const CNodePtr &node, const std::map<uint32_t, tensor::TensorPtr> &depend_tensor_map, ge::OpDescPtr *op_desc,
50     ge::ComputeGraphPtr *ge_graph);
51   ge::NodePtr NewConstantOp(const CNodePtr &node, const std::string &name, const tensor::TensorPtr &tensor_data,
52                             ge::ComputeGraphPtr *ge_graph, size_t index);
53   void AddEdge(const ge::NodePtr &ge_node, const std::vector<std::tuple<std::size_t, ge::NodePtr>> &constant_ops);
54   std::string GetRealOpType(const std::string &op_type);
55   std::string GetInputName(const CNodePtr &node, size_t index);
56   std::string GetOutputName(const CNodePtr &node, size_t index);
57   void InitOpIoName(const CNodePtr &node);
58   std::string op_name_;
59   std::string op_compile_info_;
60   std::vector<std::string> input_names_;
61   std::vector<std::string> output_names_;
62 };
63 }  // namespace tiling
64 }  // namespace device
65 }  // namespace mindspore
66 
67 #endif  // MINDSPORE_MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_TILING_OP_TILING_ADAPTER_H_
68