• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2023 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_CCSRC_PLUGIN_DEVICE_CPU_KERNEL_NNACL_OP_BASE_H_
18 #define MINDSPORE_CCSRC_PLUGIN_DEVICE_CPU_KERNEL_NNACL_OP_BASE_H_
19 #include "logging.h"
20 #include <stdarg.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <stdbool.h>
24 #include <string.h>
25 #include <limits.h>
26 #ifdef ENABLE_ARM
27 #include <arm_neon.h>
28 #endif
29 
30 #define C0NUM 0
31 #define C1NUM 1
32 #define C2NUM 2
33 #define C3NUM 3
34 #define C4NUM 4
35 #define C5NUM 5
36 #define C6NUM 6
37 #define C7NUM 7
38 #define C8NUM 8
39 #define C9NUM 9
40 #define C10NUM 10
41 #define C11NUM 11
42 #define C12NUM 12
43 #define C13NUM 13
44 #define C14NUM 14
45 #define C15NUM 15
46 #define C16NUM 16
47 #define C17NUM 17
48 #define C18NUM 18
49 #define C19NUM 19
50 #define C20NUM 20
51 #define C21NUM 21
52 #define C22NUM 22
53 #define C23NUM 23
54 #define C24NUM 24
55 #define C28NUM 28
56 #define C32NUM 32
57 #define C36NUM 36
58 #define C40NUM 40
59 #define C44NUM 44
60 #define C48NUM 48
61 #define C56NUM 56
62 #define C64NUM 64
63 #define C128NUM 128
64 #define C150NUM 150
65 #define C256NUM 256
66 #define C512NUM 512
67 #define C1500NUM 1500
68 #define TILE_NUM 8
69 #define MAX_SPLIT_NUM 2048
70 
71 #define FP16_DATA_TYPE_LEN 2
72 
73 #ifndef MS_UNLIKELY
74 #ifdef _MSC_VER
75 #define MS_UNLIKELY(x) (x)
76 #else
77 #define MS_UNLIKELY(x) __builtin_expect(!!(x), 0)
78 #endif
79 #endif
80 
81 #ifndef MS_LIKELY
82 #ifdef _MSC_VER
83 #define MS_LIKELY(x) (x)
84 #else
85 #define MS_LIKELY(x) __builtin_expect(!!(x), 1)
86 #endif
87 #endif
88 
89 #define NNACL_MIN(x, y) ((x) < (y) ? (x) : (y))
90 #define NNACL_MAX(x, y) ((x) > (y) ? (x) : (y))
91 
92 #define MSMIN(x, y) ((x) < (y) ? (x) : (y))
93 #define MSMAX(x, y) ((x) > (y) ? (x) : (y))
94 #define MSCEIL(x) (int)((x) + (((x) - (int)(x)) > 0 ? 1 : 0))
95 
96 #define UP_DIV(x, y) (((x) + (y) - (1)) / (y))
97 #define UP_ROUND(x, y) (((x) + (y) - (1)) / (y) * (y))
98 #define DOWN_DIV(x, y) ((x) / (y))
99 #define DOWN_ROUND(x, y) ((x) / (y) * (y))
100 
101 #define MSVALID(left, x, right) (MSMIN((MSMAX(left, x)), right))
102 #define SIZE_MUL_OVERFLOW(x, y) (((x) == 0) ? false : (SIZE_MAX / (x)) < (y))
103 #define INT_MUL_OVERFLOW(x, y)                                                                 \
104   (((x) == 0) ? false                                                                          \
105               : ((x) > 0 ? (((y) >= 0) ? (INT_MAX / (x)) < (y) : (INT_MAX / (x)) < (-1 * (y))) \
106                          : (((y) >= 0) ? (INT_MAX / (x)) > (-1 * (y)) : (INT_MAX / (x)) > (y))))
107 
108 #define INT_MUL_OVERFLOW_THRESHOLD(x, y, threshold)                                                    \
109   (((x) == 0) ? false                                                                                  \
110               : ((x) > 0 ? (((y) >= 0) ? ((threshold) / (x)) < (y) : ((threshold) / (x)) < (-1 * (y))) \
111                          : (((y) >= 0) ? ((threshold) / (x)) > (-1 * (y)) : ((threshold) / (x)) > (y))))
112 
113 #define INT_ADD_OVERFLOW(x, y) (INT_MAX - (x)) < (y)
114 
115 #define INT_ADD_OVERFLOW_THRESHOLD(x, y, threshold) ((threshold) - (x)) < (y)
116 
117 #define MALLOC_MAX_SIZE (2000 * 1024 * 1024)
118 
119 #define COMM_SHAPE_SIZE 4
120 #define MAX_SHAPE_SIZE 8
121 
122 #define OUTPUT_INDEX 0
123 #define FIRST_INPUT 0
124 #define SECOND_INPUT 1
125 #define THIRD_INPUT 2
126 #define FOURTH_INPUT 3
127 #define FIFTH_INPUT 4
128 #define SIXTH_INPUT 5
129 #define SEVENTH_INPUT 6
130 #define EIGHTH_INPUT 7
131 #define NINTH_INPUT 8
132 
133 #define ONE_TENSOR 1
134 #define TWO_TENSOR 2
135 #define THREE_TENSOR 3
136 #define FOUR_TENSOR 4
137 #define FIVE_TENSOR 5
138 
139 #define Index0 0
140 #define Index1 1
141 #define Index2 2
142 #define Index3 3
143 #define Index4 4
144 #define Index5 5
145 #define Index6 6
146 #define Index7 7
147 #define Index8 8
148 #define Index9 9
149 
150 #define Num0 0
151 #define Num1 1
152 #define Num2 2
153 #define Num3 3
154 #define Num4 4
155 #define Num5 5
156 #define Num6 6
157 #define Num7 7
158 #define Num8 8
159 #define Num9 9
160 
161 #define DIMENSION_0D 0
162 #define DIMENSION_1D 1
163 #define DIMENSION_2D 2
164 #define DIMENSION_3D 3
165 #define DIMENSION_4D 4
166 #define DIMENSION_5D 5
167 #define DIMENSION_6D 6
168 #define DIMENSION_7D 7
169 #define DIMENSION_8D 8
170 #define DIMENSION_9D 9
171 #define DIMENSION_10D 10
172 #define DIMENSION_11D 11
173 #define kInputIndex 0
174 #define kWeightIndex 1
175 #define kBiasIndex 2
176 #define kOutputIndex 0
177 #define kNHWC_N 0
178 #define kNHWC_H 1
179 #define kNHWC_W 2
180 #define kNHWC_C 3
181 #define kNCHW_N 0
182 #define kNCHW_C 1
183 #define kNCHW_H 2
184 #define kNCHW_W 3
185 #define kHWCN_C 2
186 #define kHWNC_N 2
187 #define kHWCN_N 3
188 #define kNDHWC_N 0
189 #define kNDHWC_D 1
190 #define kNDHWC_H 2
191 #define kNDHWC_W 3
192 #define kNDHWC_C 4
193 #define kInputSize1 2
194 #define kInputSize2 3
195 #define MAX_AXIS_SIZE 6
196 #define MAX_LEN 256
197 #define MAX_THREAD_NUM 64
198 #define FLT16_MAX 65504
199 #define kDefaulLiteMaxSpinCount 300000
200 #define kDefaulLiteMinSpinCount 1
201 #define kDefaulLiteIosSpinCount 1
202 #define DEFAULT_GROUP_NAME_LEN 101
203 #define kValueThreshold6 6
204 
205 #define INVALID_SHAPE -1
206 
207 #define CLARGSINDEX0 0
208 #define CLARGSINDEX1 1
209 #define CLARGSINDEX2 2
210 #define CLARGSINDEX3 3
211 #define CLARGSINDEX4 4
212 #define CLARGSINDEX5 5
213 #define CLARGSINDEX6 6
214 #define CLARGSINDEX7 7
215 #define CLARGSINDEX8 8
216 #define CLARGSINDEX9 9
217 
218 #define CLIDX_X 0
219 #define CLIDX_Y 1
220 #define CLIDX_Z 2
221 #define CLIDX_W 3
222 
223 #define RELU6_MIN_VAL 0
224 #define RELU6_MAX_VAL 6
225 
226 /* index for primitive_type & activation_type */
227 #define TC_PTYPE(primitive_type) (primitive_type << 16)
228 #define TC_ATYPE(activation_type) (activation_type)
229 #define TC_TYPE(primitive_type, activation_type) (TC_PTYPE(primitive_type) + TC_ATYPE(activation_type))
230 
231 #define NNACL_MALLOC_CHECK_NULL_RETURN_ERR(ptr) \
232   do {                                          \
233     if ((ptr) == NULL) {                        \
234       return NNACL_NULL_PTR;                    \
235     }                                           \
236   } while (0)
237 
238 #define NNACL_MALLOC_CHECK_NULL_RETURN_NULL(ptr) \
239   do {                                           \
240     if ((ptr) == NULL) {                         \
241       return NULL;                               \
242     }                                            \
243   } while (0)
244 
245 #if ENABLE_HIGH_PERFORMANCE
246 #define NNACL_CHECK_TRUE_RET(value, errcode)
247 #define NNACL_CHECK_TRUE_RET_VOID(value)
248 #define NNACL_CHECK_FALSE(value, errcode)
249 #define NNACL_CHECK_INT_MUL_NOT_OVERFLOW(value1, value2, errcode)
250 #define NNACL_CHECK_INT_ADD_NOT_OVERFLOW(value1, value2, errcode)
251 
252 #define NNACL_CHECK_ZERO_RETURN_ERR(val)
253 #define NNACL_CHECK_ZERO_RETURN(val)
254 #define NNACL_CHECK_NULL_RETURN_ERR(ptr)
255 #define NNACL_CHECK_NULL_RETURN_VOID(ptr)
256 #define NNACL_CHECK_NULL_RETURN_NULL(ptr)
257 #define NNACL_CHECK_MALLOC_SIZE(val)
258 #else
259 #define NNACL_CHECK_TRUE_RET(value, errcode) \
260   do {                                       \
261     if (!(value)) {                          \
262       return errcode;                        \
263     }                                        \
264   } while (0)
265 
266 #define NNACL_CHECK_TRUE_RET_VOID(value) \
267   do {                                   \
268     if (!(value)) {                      \
269       return;                            \
270     }                                    \
271   } while (0)
272 
273 // Check whether value is false, if not return 'errcode'
274 #define NNACL_CHECK_FALSE(value, errcode) \
275   do {                                    \
276     if ((value)) {                        \
277       return errcode;                     \
278     }                                     \
279   } while (0)
280 
281 #define NNACL_CHECK_INT_MUL_NOT_OVERFLOW(value1, value2, errcode) \
282   NNACL_CHECK_TRUE_RET(!(INT_MUL_OVERFLOW(value1, value2)), errcode)
283 #define NNACL_CHECK_INT_ADD_NOT_OVERFLOW(value1, value2, errcode) \
284   NNACL_CHECK_TRUE_RET(!(INT_ADD_OVERFLOW(value1, value2)), errcode)
285 #define NNACL_CHECK_MALLOC_SIZE(malloc_size) \
286   NNACL_CHECK_FALSE((malloc_size) > MALLOC_MAX_SIZE, NNACL_MALLOC_SIZE_INVALID)
287 
288 #define NNACL_CHECK_ZERO_RETURN_ERR(val) \
289   do {                                   \
290     if ((val) == 0) {                    \
291       return NNACL_ERR;                  \
292     }                                    \
293   } while (0)
294 
295 #define NNACL_CHECK_ZERO_RETURN(val) \
296   do {                               \
297     if ((val) == 0) {                \
298       return;                        \
299     }                                \
300   } while (0)
301 
302 #define NNACL_CHECK_NULL_RETURN_ERR(ptr) \
303   do {                                   \
304     if ((ptr) == NULL) {                 \
305       return NNACL_NULL_PTR;             \
306     }                                    \
307   } while (0)
308 
309 #define NNACL_CHECK_NULL_RETURN_VOID(ptr) \
310   do {                                    \
311     if ((ptr) == NULL) {                  \
312       return;                             \
313     }                                     \
314   } while (0)
315 
316 #define NNACL_CHECK_NULL_RETURN_NULL(ptr) \
317   do {                                    \
318     if ((ptr) == NULL) {                  \
319       return NULL;                        \
320     }                                     \
321   } while (0)
322 #endif
323 
324 enum PrimType {
325   PrimType_NONE = 0,
326   PrimType_Abs = 1,
327   PrimType_Activation = 2,
328   PrimType_ActivationGrad = 3,
329   PrimType_Adam = 4,
330   PrimType_AddFusion = 5,
331   PrimType_AdderFusion = 6,
332   PrimType_AddGrad = 7,
333   PrimType_AddN = 8,
334   PrimType_All = 9,
335   PrimType_ApplyMomentum = 10,
336   PrimType_ArgMaxFusion = 11,
337   PrimType_ArgMinFusion = 12,
338   PrimType_Assert = 13,
339   PrimType_Assign = 14,
340   PrimType_AssignAdd = 15,
341   PrimType_AudioSpectrogram = 16,
342   PrimType_AvgPoolFusion = 17,
343   PrimType_AvgPoolGrad = 18,
344   PrimType_BatchNorm = 19,
345   PrimType_BatchNormGrad = 20,
346   PrimType_BatchToSpace = 21,
347   PrimType_BatchToSpaceND = 22,
348   PrimType_BiasAdd = 23,
349   PrimType_BinaryCrossEntropy = 24,
350   PrimType_BinaryCrossEntropyGrad = 25,
351   PrimType_BiasAddGrad = 26,
352   PrimType_BroadcastTo = 27,
353   PrimType_Cast = 28,
354   PrimType_Ceil = 29,
355   PrimType_Clip = 30,
356   PrimType_Concat = 31,
357   PrimType_Attention = 32,
358   PrimType_Conv2DBackpropFilterFusion = 33,
359   PrimType_Conv2DBackpropInputFusion = 34,
360   PrimType_Conv2DFusion = 35,
361   PrimType_Conv2dTransposeFusion = 36,
362   PrimType_Cos = 37,
363   PrimType_ConstantOfShape = 38,
364   PrimType_Crop = 39,
365   PrimType_CustomExtractFeatures = 40,
366   PrimType_CustomNormalize = 41,
367   PrimType_CustomPredict = 42,
368   PrimType_DeConv2DGradFilter = 43,
369   PrimType_Depend = 44,
370   PrimType_DepthToSpace = 45,
371   PrimType_DetectionPostProcess = 46,
372   PrimType_DivFusion = 47,
373   PrimType_DivGrad = 48,
374   PrimType_Dropout = 49,
375   PrimType_DropoutGrad = 50,
376   PrimType_Elu = 51,
377   PrimType_Eltwise = 52,
378   PrimType_Equal = 53,
379   PrimType_EmbeddingLookupFusion = 54,
380   PrimType_ExpFusion = 55,
381   PrimType_ExpandDims = 56,
382   PrimType_FakeQuantWithMinMaxVars = 57,
383   PrimType_FakeQuantWithMinMaxVarsPerChannel = 58,
384   PrimType_FftReal = 59,
385   PrimType_FftImag = 60,
386   PrimType_Flatten = 61,
387   PrimType_FlattenGrad = 62,
388   PrimType_Floor = 63,
389   PrimType_FloorDiv = 64,
390   PrimType_FloorMod = 65,
391   PrimType_Fill = 66,
392   PrimType_FullConnection = 67,
393   PrimType_FusedBatchNorm = 68,
394   PrimType_Gather = 69,
395   PrimType_GatherNd = 70,
396   PrimType_Greater = 71,
397   PrimType_GreaterEqual = 72,
398   PrimType_HashtableLookup = 73,
399   PrimType_InstanceNorm = 74,
400   PrimType_LayerNormFusion = 75,
401   PrimType_LeakyRelu = 76,
402   PrimType_Less = 77,
403   PrimType_LessEqual = 78,
404   PrimType_Log = 79,
405   PrimType_LogGrad = 80,
406   PrimType_LogicalAnd = 81,
407   PrimType_LogicalNot = 82,
408   PrimType_LogicalOr = 83,
409   PrimType_LpNormalization = 84,
410   PrimType_LRN = 85,
411   PrimType_LshProjection = 86,
412   PrimType_LSTM = 87,
413   PrimType_L2NormalizeFusion = 88,
414   PrimType_MatMulFusion = 89,
415   PrimType_Maximum = 90,
416   PrimType_MaximumGrad = 91,
417   PrimType_MaxPoolFusion = 92,
418   PrimType_MaxPoolGrad = 93,
419   PrimType_SwitchLayer = 94,
420   PrimType_Mfcc = 95,
421   PrimType_Minimum = 96,
422   PrimType_MinimumGrad = 97,
423   PrimType_Mod = 98,
424   PrimType_MulFusion = 99,
425   PrimType_MulGrad = 100,
426   PrimType_Neg = 101,
427   PrimType_NegGrad = 102,
428   PrimType_NotEqual = 103,
429   PrimType_NonMaxSuppression = 104,
430   PrimType_OneHot = 105,
431   PrimType_OnesLike = 106,
432   PrimType_PadFusion = 107,
433   PrimType_PartialFusion = 108,
434   PrimType_PowerGrad = 109,
435   PrimType_PowFusion = 110,
436   PrimType_PriorBox = 111,
437   PrimType_PReLUFusion = 112,
438   PrimType_QuantDTypeCast = 113,
439   PrimType_Rank = 114,
440   PrimType_Range = 115,
441   PrimType_Reciprocal = 116,
442   PrimType_RealDiv = 117,
443   PrimType_ReduceFusion = 118,
444   PrimType_Reshape = 119,
445   PrimType_Resize = 120,
446   PrimType_ReverseSequence = 121,
447   PrimType_ReverseV2 = 122,
448   PrimType_Rfft = 123,
449   PrimType_ROIPooling = 124,
450   PrimType_Round = 125,
451   PrimType_Rsqrt = 126,
452   PrimType_ScaleFusion = 127,
453   PrimType_ScatterNd = 128,
454   PrimType_SGD = 129,
455   PrimType_Shape = 130,
456   PrimType_SigmoidCrossEntropyWithLogits = 131,
457   PrimType_SigmoidCrossEntropyWithLogitsGrad = 132,
458   PrimType_Sin = 133,
459   PrimType_SkipGram = 134,
460   PrimType_SliceFusion = 135,
461   PrimType_SmoothL1Loss = 136,
462   PrimType_SmoothL1LossGrad = 137,
463   PrimType_Softmax = 138,
464   PrimType_SoftmaxCrossEntropyWithLogits = 139,
465   PrimType_SpaceToBatch = 140,
466   PrimType_SpaceToBatchND = 141,
467   PrimType_SpaceToDepth = 142,
468   PrimType_SparseSoftmaxCrossEntropyWithLogits = 143,
469   PrimType_SparseToDense = 144,
470   PrimType_Split = 145,
471   PrimType_Sqrt = 146,
472   PrimType_Squeeze = 147,
473   PrimType_Square = 148,
474   PrimType_SquaredDifference = 149,
475   PrimType_Stack = 150,
476   PrimType_StridedSlice = 151,
477   PrimType_SubFusion = 152,
478   PrimType_SubGrad = 153,
479   PrimType_Switch = 154,
480   PrimType_TensorListFromTensor = 155,
481   PrimType_TensorListGetItem = 156,
482   PrimType_TensorListReserve = 157,
483   PrimType_TensorListSetItem = 158,
484   PrimType_TensorListStack = 159,
485   PrimType_TileFusion = 160,
486   PrimType_TopKFusion = 161,
487   PrimType_Transpose = 162,
488   PrimType_Unique = 163,
489   PrimType_UnsortedSegmentSum = 164,
490   PrimType_Unsqueeze = 165,
491   PrimType_Unstack = 166,
492   PrimType_LSTMGrad = 167,
493   PrimType_Where = 168,
494   PrimType_ZerosLike = 169,
495   PrimType_Select = 170,
496   PrimType_ScatterNdUpdate = 171,
497   PrimType_GRU = 172,
498   PrimType_NonZero = 173,
499   PrimType_InvertPermutation = 174,
500   PrimType_Size = 175,
501   PrimType_RandomStandardNormal = 176,
502   PrimType_CropAndResize = 177,
503   PrimType_Erf = 178,
504   PrimType_StridedSliceGrad = 179,
505   PrimType_IsFinite = 180,
506   PrimType_LinSpace = 181,
507   PrimType_UniformReal = 182,
508   PrimType_AbsGrad = 183,
509   PrimType_RsqrtGrad = 184,
510   PrimType_SqrtGrad = 185,
511   PrimType_LayerNormGrad = 186,
512   PrimType_ResizeGrad = 187,
513   PrimType_Splice = 188,
514   PrimType_LogSoftmax = 189,
515   PrimType_Call = 190,
516   PrimType_Custom = 191,
517   PrimType_CumSum = 192,
518   PrimType_SplitWithOverlap = 193,
519   PrimType_GenOP = 194,
520   PrimType_RaggedRange = 195,
521   PrimType_GLU = 196,
522   PrimType_TensorArray = 197,
523   PrimType_TensorArrayRead = 198,
524   PrimType_TensorArrayWrite = 199,
525   PrimType_Affine = 200,
526   PrimType_AllGather = 201,
527   PrimType_ReduceScatter = 202,
528   PrimType_DynamicQuant = 203,
529   PrimType_LSTMGradData = 204,
530   PrimType_LSTMGradWeight = 205,
531   PrimType_RandomNormal = 206,
532   PrimType_NLLLoss = 207,
533   PrimType_NLLLossGrad = 208,
534   PrimType_FormatTranspose = 209,
535   PrimType_GatherD = 210,
536   PrimType_GroupNormFusion = 211,
537   PrimType_Log1p = 212,
538   PrimType_TensorScatterAdd = 213,
539   PrimType_SparseFillEmptyRows = 214,
540   PrimType_SparseReshape = 215,
541   PrimType_SparseSegmentSum = 216,
542   PrimType_ScatterElements = 217,
543   PrimType_Triu = 218,
544   PrimType_Tril = 219,
545   PrimType_AdamWeightDecay = 220,
546   PrimType_FillV2 = 221,
547   PrimType_MIN = PrimType_NONE,
548   PrimType_MAX = PrimType_FillV2 + 1,
549 
550   // inner operators.
551   PrimType_Inner_ToFormat = 10000,
552   PrimType_Inner_GltextureToOpencl = 10001,
553   PrimType_Inner_Identity = 10002,
554   PrimType_Inner_ShapeFusion = 10003,
555   PrimType_Inner_GraphKernel = 10004,
556   PrimType_Inner_SplitReduceConcatFusion = 10005,
557   PrimType_Inner_EncoderLayer = 10006,
558   PrimType_Inner_FseDecode = 10007,
559   PrimType_Inner_DecoderLayer = 10008,
560   PrimType_Inner_UsePastEmbedding = 10009,
561   PrimType_Inner_CustomGru = 10010,
562   PrimType_Inner_CastGatherReduceFusion = 10011,
563   PrimType_Inner_ReduceConcatFusion = 10012,
564   PrimType_Inner_AclCustomOp = 10013,
565   PrimType_Inner_CustomMaskedFill = 10014,
566   PrimType_Inner_CustomTensorScatterMax = 10015,
567   PrimType_Inner_CustomIsInf = 10016,
568   PrimType_Inner_CustomGatherDGradV2 = 10017,
569   PrimType_Inner_ThirdPartyModel = 10018,
570   PrimType_InnerOpMax,
571   PrimType_InnerOpMin = PrimType_Inner_ToFormat
572 };
573 
574 typedef enum FormatC {
575   DEFAULT_FORMAT = -1,
576   Format_NCHW = 0,
577   Format_NHWC = 1,
578   Format_NHWC4 = 2,
579   Format_HWKC = 3,
580   Format_HWCK = 4,
581   Format_KCHW = 5,
582   Format_CKHW = 6,
583   Format_KHWC = 7,
584   Format_CHWK = 8,
585   Format_HW = 9,
586   Format_HW4 = 10,
587   Format_NC = 11,
588   Format_NC4 = 12,
589   Format_NC4HW4 = 13,
590   Format_NONE = 14,  // The origin Format_NUM_OF_FORMAT can't be used.
591   Format_NCDHW = 15,
592   Format_NWC = 16,
593   Format_NCW = 17,
594   Format_NDHWC = 18,
595   Format_NC8HW8 = 19,
596   Format_NC16HW16 = 20,
597   Format_MAX,
598   Format_MIN = Format_NCHW
599 } FormatC;
600 
601 typedef enum TypeIdC {
602   kTypeUnknown = 0,
603   kMetaTypeBegin = kTypeUnknown,
604   kMetaTypeType,  // Type
605   kMetaTypeAny,
606   kMetaTypeObject,
607   kMetaTypeTypeType,  // TypeType
608   kMetaTypeProblem,
609   kMetaTypeExternal,
610   kMetaTypeNone,
611   kMetaTypeNull,
612   kMetaTypeEllipsis,
613   kMetaTypeEnd,
614   //
615   // Object types
616   //
617   kObjectTypeBegin = kMetaTypeEnd,
618   kObjectTypeNumber,
619   kObjectTypeString,
620   kObjectTypeList,
621   kObjectTypeTuple,
622   kObjectTypeSlice,
623   kObjectTypeKeyword,
624   kObjectTypeTensorType,
625   kObjectTypeRowTensorType,
626   kObjectTypeCOOTensorType,
627   kObjectTypeUndeterminedType,
628   kObjectTypeClass,
629   kObjectTypeDictionary,
630   kObjectTypeFunction,
631   kObjectTypeJTagged,
632   kObjectTypeSymbolicKeyType,
633   kObjectTypeEnvType,
634   kObjectTypeRefKey,
635   kObjectTypeRef,
636   kObjectTypeEnd,
637   //
638   // Number Types
639   //
640   kNumberTypeBegin = kObjectTypeEnd,
641   kNumberTypeBool,
642   kNumberTypeInt,
643   kNumberTypeInt8,
644   kNumberTypeInt16,
645   kNumberTypeInt32,
646   kNumberTypeInt64,
647   kNumberTypeUInt,
648   kNumberTypeUInt8,
649   kNumberTypeUInt16,
650   kNumberTypeUInt32,
651   kNumberTypeUInt64,
652   kNumberTypeFloat,
653   kNumberTypeFloat16,
654   kNumberTypeFloat32,
655   kNumberTypeFloat64,
656   kNumberTypeDouble,
657   kNumberTypeComplex,
658   kNumberTypeComplex64,
659   kNumberTypeComplex128,
660   kNumberTypeInt4,
661   kNumberTypeGLUInt,
662   kNumberTypeEnd,
663 } TypeIdC;
664 
665 typedef enum DataOrder {
666   RowMajor,
667   ColMajor,
668 } DataOrder;
669 
670 typedef struct OpParameter {
671   char name_[100];
672   int type_;
673   int thread_num_;
674   int quant_type_;
675   bool is_train_session_;
676   bool is_zero_shape_;
677   void (*destroy_func_)(struct OpParameter *param);
678 } OpParameter;
679 
680 typedef struct QuantArg {
681   float scale_;
682   int32_t zp_;
683 } QuantArg;
684 
685 typedef struct QuantMulArg {
686   int32_t multiplier_;
687   int left_shift_;
688   int right_shift_;
689 } QuantMulArg;
690 
691 typedef enum ReductionType { Reduction_Sum, Reduction_Mean, Reduction_None } ReductionType;
692 typedef enum ActType {
693   ActType_No = 0,
694   ActType_Relu = 1,
695   ActType_Sigmoid = 2,
696   ActType_Relu6 = 3,
697   ActType_Elu = 4,
698   ActType_LeakyRelu = 5,
699   ActType_Abs = 6,
700   ActType_Relu1 = 7,
701   ActType_Softsign = 8,
702   ActType_Softplus = 9,
703   ActType_Tanh = 10,
704   ActType_Selu = 11,
705   ActType_HSwish = 12,
706   ActType_HSigmoid = 13,
707   ActType_ThresholdRelu = 14,
708   ActType_Linear = 15,
709   ActType_HardTanh = 16,
710   ActType_Sign = 17,
711   ActType_Swish = 18,
712   ActType_Gelu = 19,
713   ActType_FastGelu = 20,
714   ActType_Unknown = 21
715 } ActType;
716 typedef enum PadType { Pad_pad, Pad_same, Pad_valid } PadType;
717 typedef enum EltwiseType { Eltwise_PROD, Eltwise_SUM, Eltwise_MAXIMUM, Eltwise_UNKNOWN } EltwiseType;
718 typedef enum RoundingMode { Rounding_No, Rounding_Away_from_zero, Rounding_Up } RoundingMode;
719 
720 typedef enum PaddingModeC {
721   PaddingMode_Constant,
722   PaddingMode_Reflect,
723   PaddingMode_Symmetric,
724   PaddingMode_Mode_Reserved,
725 } PaddingModeC;
726 
727 typedef enum ElementwiseModeC {
728   Elementwise_Not = 0,
729   Elementwise_Per_Channel = 1,
730   Elementwise_Per_Num = 2
731 } ElementwiseModeC;
732 
733 typedef enum QuantTypeC {
734   Quant_None = 0,
735   Quant_AwareTraining = 1,
736   Quant_WeightQuant = 2,
737   Quant_PostTraining = 3,
738   Quant_QuantWeight = 4,
739   Quant_QuantAll = 5,
740   Quant_QuantDynamic = 6,
741   Quant_Min = Quant_None,
742   Quant_Max = Quant_QuantDynamic
743 } QuantTypeC;
744 
745 typedef enum TensorCategoryC {
746   VarTensor,    // common tensor
747   ConstTensor,  // const tensor
748   ConstScalar,  // const scalar
749   GraphInput,
750   GraphOutput
751 } TensorCategoryC;
752 
753 typedef enum ReduceModeC {
754   Reduce_Mean = 0,
755   Reduce_Max = 1,
756   Reduce_Min = 2,
757   Reduce_Prod = 3,
758   Reduce_Sum = 4,
759   Reduce_SumSquare = 5,
760   Reduce_ASum = 6,
761   Reduce_All = 7,
762   Reduce_L2 = 8,
763   Reduce_MIN = Reduce_Mean,
764   Reduce_MAX = Reduce_L2
765 } ReduceModeC;
766 
767 typedef enum CalFixedMultiplierMode {
768   Method_No,
769   Method_SinglePrecision,
770   Method_DoublePrecision
771 } CalFixedMultiplierMode;
772 
773 #define VA_ARG_TUPLE_LEN 2
offset_to_index_init(int offset,int cnt,...)774 static inline void offset_to_index_init(int offset, int cnt, ...) {
775   va_list valist;
776   va_start(valist, cnt);
777   int start = offset;
778   for (int i = 0; i < cnt; i += VA_ARG_TUPLE_LEN) {
779     int *x = va_arg(valist, int *);
780     int X = va_arg(valist, int);
781 
782     *x = start % X;
783     start = start / X;
784   }
785   va_end(valist);
786 }
787 
offset_to_index_step(int cnt,...)788 static inline void offset_to_index_step(int cnt, ...) {
789   va_list valist;
790   int flag = 1;
791   va_start(valist, cnt);
792   for (int i = 0; i < cnt; i += VA_ARG_TUPLE_LEN) {
793     int *x = va_arg(valist, int *);
794     int X = va_arg(valist, int);
795     if (flag) {
796       *x = (++*x != X) ? (flag = 0, *x) : (flag = 1, 0);
797     }
798   }
799   va_end(valist);
800 }
801 
802 #endif  // MINDSPORE_CCSRC_PLUGIN_DEVICE_CPU_KERNEL_NNACL_OP_BASE_H_
803