• 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_TBE_JSON_UTILS_H
18 #define MINDSPORE_TBE_JSON_UTILS_H
19 #include <memory>
20 #include <map>
21 #include <list>
22 #include <algorithm>
23 #include <vector>
24 #include <string>
25 #include "base/core_ops.h"
26 #include "backend/session/anf_runtime_algorithm.h"
27 #include "backend/kernel_compiler/tbe/tbe_convert_utils.h"
28 #include "backend/kernel_compiler/tbe/tbe_dynaminc_shape_util.h"
29 #include "runtime/dev.h"
30 #include "utils/ms_utils.h"
31 namespace mindspore::kernel {
32 constexpr auto kJFusionOpList = "op_list";
33 constexpr auto kJFusionKernelNamePrefix = "te_fusion_";
34 constexpr auto kJOptional = "optional_";
35 constexpr auto kJOpFormat_FRACTAL_Z = "FRACTAL_Z";
36 constexpr auto kJFullName = "full_name";
37 constexpr auto kJDtype = "dtype";
38 constexpr auto kJName = "name";
39 constexpr auto kJOriShape = "ori_shape";
40 constexpr auto kJOriFormat = "ori_format";
41 constexpr auto kJShape = "shape";
42 constexpr auto kJFormat = "format";
43 constexpr auto kJValid = "valid";
44 constexpr auto kJParamType = "param_type";
45 constexpr auto kJParamDynamic = "dynamic";
46 constexpr auto kJParamRequred = "required";
47 constexpr auto kJParamOptional = "optional";
48 constexpr auto kJDataType = "data_type";
49 constexpr auto kJOutputIndex = "output_index";
50 constexpr auto kJOutputDataDesc = "output_data_desc";
51 constexpr auto kJOutputDesc = "output_desc";
52 constexpr auto kJInputDesc = "input_desc";
53 constexpr auto kJRange = "range";
54 constexpr auto kVTypeInt = "int";
55 constexpr auto kVTypeStr = "str";
56 constexpr auto kVTypeBool = "bool";
57 constexpr auto kVTypeFloat = "float";
58 constexpr auto kVTypeFloat32 = "float32";
59 constexpr auto kVTypeListInt = "listInt";
60 constexpr auto kVTypeInt32 = "Int32";
61 constexpr auto kVTypeInt64 = "Int64";
62 constexpr auto kVTypeListUInt64 = "listUInt64";
63 constexpr auto kVTypeListFloat = "listFloat";
64 constexpr auto kVTypeListListInt = "listListInt";
65 constexpr auto kJValue = "value";
66 constexpr auto kJDynIndex = "dyn_index";
67 constexpr auto kJFuncName = "func_name";
68 constexpr auto kJL1AddrOffset = "L1_addr_offset";
69 constexpr auto kJL1FusionType = "L1_fusion_type";
70 constexpr auto kJL1WorkspaceSize = "L1_workspace_size";
71 constexpr auto kJAddrType = "addr_type";
72 constexpr auto kJSliceOffset = "slice_offset";
73 constexpr auto kJSplitIndex = "split_index";
74 constexpr auto kJTotalShape = "total_shape";
75 constexpr auto kJDynamicCompileStatic = "dynamic_compile_static";
76 constexpr auto kJInt64Mode = "int64mode";
77 constexpr auto kJValidShape = "valid_shape";
78 constexpr auto kJModuleName = "module_name";
79 constexpr auto kJModuleNamePrefix = "impl.";
80 constexpr auto kJPattern = "pattern";
81 constexpr auto kJPyModulePath = "py_module_path";
82 constexpr auto kJAttrs = "attrs";
83 constexpr auto kJAttrDesc = "attr_desc";
84 constexpr auto kJSocInfo = "SocInfo";
85 constexpr auto kJFusionOpName = "fusion_op_name";
86 constexpr auto kJGraphID = "graph_id";
87 constexpr auto kJType = "type";
88 constexpr auto kJIsRef = "isRef";
89 constexpr auto kJL1Size = "l1_size";
90 constexpr auto kJScopeID = "scope_id";
91 constexpr auto kJGraphName = "graph_name";
92 constexpr auto kJOpList = "op_list";
93 constexpr auto kJNull = "NULL";
94 constexpr auto kJData = "Data";
95 constexpr auto kJOriName = "ori_name";
96 constexpr auto kJBuildType = "build_type";
97 constexpr auto kJMissSupportInfo = "miss_support_info";
98 constexpr auto kJMaxKernelID = "max_kernel_id";
99 constexpr auto kJOpName = "op_name";
100 constexpr auto kJUnknowShape = "unknown_shape";
101 constexpr auto kJListArgs = "list_args";
102 constexpr auto kAccuratelyBuild = "accurately_build";
103 constexpr auto kPyPath = "/usr/local/Ascend/opp/op_impl/built-in/ai_core/tbe";
104 constexpr auto kJMaxKernelIDValue = 10;
105 constexpr auto kJConstValue = "const_value";
106 constexpr auto kJConstValueDtype = "const_value_dtype";
107 
108 class TbeJsonUtils {
109  public:
110   static bool GetInputsRealNum(const AnfNodePtr &anf_node, const std::vector<OpIOInfoPtr> &inputs_ptr,
111                                std::vector<size_t> *inputs_num);
112   static bool GetOutputsRealNum(const AnfNodePtr &anf_node, const std::vector<OpIOInfoPtr> &outputs_ptr,
113                                 std::vector<size_t> *outputs_num);
114   static bool IsNeedChangeDefaultFormat(const AnfNodePtr &anf_node);
115   // just for generate json for ascend op build, it will be deleted after unify size_t and int64_t.
116   static std::vector<int64_t> GetInputOriShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
117   static std::vector<int64_t> GetInputDeviceShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
118   static std::vector<int64_t> GetOutputOriShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
119   static std::vector<int64_t> GetOutputDeviceShapeForTbeBuild(const AnfNodePtr &anf_node, size_t real_idx);
120 };
121 
122 }  // namespace mindspore::kernel
123 #endif  // MINDSPORE_TBE_JSON_UTILS_H
124