• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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 #ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_AICPU_AICPU_UTIL_H_
17 #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_AICPU_AICPU_UTIL_H_
18 
19 #include <cstdint>
20 #include <vector>
21 #include <map>
22 #include <set>
23 #include <string>
24 #include "backend/kernel_compiler/kernel.h"
25 namespace mindspore {
26 namespace kernel {
27 constexpr auto kInitDataSetQueue = "InitDataSetQueue";
28 constexpr auto kInitData = "InitData";
29 constexpr auto kGetNext = "GetNext";
30 constexpr auto kPrint = "Print";
31 constexpr auto kPack = "Pack";
32 constexpr auto kMeshgrid = "Meshgrid";
33 constexpr auto kOutputTypes = "output_types";
34 constexpr auto kOutputShapes = "output_shapes";
35 constexpr auto kChannelName = "channel_name";
36 constexpr auto kSharedName = "shared_name";
37 constexpr auto kShapes = "shapes";
38 constexpr auto kTypes = "types";
39 constexpr auto kQueueName = "queue_name";
40 constexpr auto kSeed = "seed";
41 constexpr auto kSeed0 = "Seed0";
42 constexpr auto kSeed1 = "Seed1";
43 constexpr auto kSeed2 = "seed2";
44 constexpr auto kTopK = "TopK";
45 constexpr auto kTopKV2 = "TopKV2";
46 constexpr auto kStack = "Stack";
47 constexpr auto kStackInit = "StackInit";
48 constexpr auto kStackPush = "StackPush";
49 constexpr auto kStackPop = "StackPop";
50 constexpr auto kStackDestroy = "StackDestroy";
51 constexpr auto kEditDistance = "EditDistance";
52 constexpr auto kGatherD = "GatherD";
53 constexpr auto kIdentity = "Identity";
54 constexpr auto kUpdateCache = "UpdateCache";
55 constexpr auto kCacheSwapTable = "CacheSwapTable";
56 constexpr auto kSubAndFilter = "SubAndFilter";
57 constexpr auto kPadAndShift = "PadAndShift";
58 constexpr auto kCustRunApi = "RunCpuKernel";
59 constexpr auto kDropout2D = "Dropout2D";
60 constexpr auto kDropout3D = "Dropout3D";
61 constexpr auto kMaskedSelect = "MaskedSelect";
62 constexpr auto kMaskedSelectGrad = "MaskedSelectGrad";
63 constexpr auto kDynamicStitch = "DynamicStitch";
64 constexpr auto kSearchSorted = "SearchSorted";
65 constexpr auto kResizeBilinear = "ResizeBilinear";
66 constexpr auto kResizeBilinearGrad = "ResizeBilinearGrad";
67 const std::set<std::string> kCustAiCpuKernelOps{kIdentity,     kMaskedSelect,   kMaskedSelectGrad,  kDynamicStitch,
68                                                 kSearchSorted, kResizeBilinear, kResizeBilinearGrad};
69 const std::set<std::string> kCacheKernelOps{kUpdateCache, kCacheSwapTable, kSubAndFilter,
70                                             kPadAndShift, kDropout3D,      kDropout2D};
71 const std::set<std::string> kDynamicInputOps{
72   kPrint, kPack, kMeshgrid, kStackInitOpName, kStackDestroyOpName, kStackPushOpName, kStackPopOpName, kDynamicStitch};
73 struct AicpuParamHead {
74   uint32_t length;         // Total length: include cunstom message
75   uint32_t ioAddrNum;      // Input and output address number
76   uint32_t extInfoLength;  // extInfo struct Length
77   uint64_t extInfoAddr;    // extInfo address
78 } __attribute__((packed));
79 
80 // Extent info ShapeAndType
81 const uint32_t kMaxShapeDims = 8;
82 struct ShapeAndType {
83   int32_t type;
84   int64_t dims[kMaxShapeDims];
85 } __attribute__((packed));
86 
87 // Extend info structure for extInfoAddr
88 const uint32_t kExtInfoHeadSize = 8;
89 struct ExtInfo {
90   int32_t infoType;  // extend type
91   uint32_t infoLen;  // length for infoMsg
92   char infoMsg[0];   // extend value
93 } __attribute__((packed));
94 
95 // Extend Info type for task
96 enum FWKTaskExtInfoType {
97   FWK_ADPT_EXT_SHAPE_TYPE = 0,
98   FWK_ADPT_EXT_INPUT_SHAPE,
99   FWK_ADPT_EXT_OUTPUT_SHAPE,
100   FWK_ADPT_EXT_INVALID
101 };
102 
103 // for unknown shape op type
104 enum UnknowShapeOpType {
105   DEPEND_IN_SHAPE = 1,     // op out shape get by input shape
106   DEPEND_CONST_VALUE = 2,  // op out shape get by const op value
107   DEPEND_SHAPE_RANGE = 3,  // op out shape get by range
108   DEPEND_COMPUTE = 4       // op out shape get by totally computing
109 };
110 
111 class AicpuOpUtil {
112  public:
113   static int MsTypeToProtoType(TypeId ms_type);
114   static int ProtoTypeToMsType(int proto_type);
115 
116  private:
117   // kernel id
118   static uint64_t KernelId_;
119 };
120 }  // namespace kernel
121 }  // namespace mindspore
122 
123 #endif  // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_AICPU_AICPU_UTIL_H_
124