1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @addtogroup NNRt
18 * @{
19 *
20 * @brief Provides a unified interface for AI chip drivers to access OpenHarmony. 
21 * Neural Network Runtime (NNRt) is a cross-chip inference computing runtime environment oriented to the AI field.
22 * It serves as a bridge between the upper-layer AI inference framework and the underlying acceleration chip to implement cross-chip inference computing of AI models.
23 * @since 3.2
24 * @version 1.0
25 */
26
27/**
28 * @file NnrtTypes.idl
29 *
30 * @brief Defines the types used in the HDI methods.
31 *
32 * @since 3.2
33 * @version 1.0
34 */
35
36/**
37 * @brief Defines the package path of the NNRt module.
38 *
39 * @since 3.2
40 * @version 1.0
41 */
42package ohos.hdi.nnrt.v1_0;
43
44/**
45 * @brief Defines the shared memory data structure.
46 *
47 * @since 3.2
48 * @version 1.0
49 */
50struct SharedBuffer {
51    /** File descriptor of the shared memory. */
52    FileDescriptor fd;
53    /** Size of the shared memory, in bytes. */
54    unsigned int bufferSize;
55    /** Offset of the start address of the valid data in the shared memory. */
56    unsigned int offset;
57    /** Space occupied by the valid data, in bytes. */
58    unsigned int dataSize;
59};
60
61/**
62 * @brief Enumerates the AI chip types.
63 *
64 * @since 3.2
65 * @version 1.0
66 */
67enum DeviceType: int {
68    /** Other type */
69    OTHER,
70    /** CPU chip */
71    CPU,
72    /** GPU chip */
73    GPU,
74    /** AI acceleration chip, such as NPU chip and DSP chip */
75    ACCELERATOR
76};
77
78/**
79 * @brief Enumerates the AI chip states.
80 *
81 * @since 3.2
82 * @version 1.0
83 */
84enum DeviceStatus: int {
85    /** Available. */
86    AVAILABLE,
87    /** Busy. The chip in this state may not respond to computing tasks in a timely manner. */
88    BUSY,
89    /** Offline. The chip in this state cannot respond to computing tasks. */
90    OFFLINE,
91    /** Unknown state. */
92    UNKNOWN
93};
94
95/**
96 * @brief Enumerates the performance modes for a chip to perform AI computing.
97 *
98 * @since 3.2
99 * @version 1.0
100 */
101enum PerformanceMode: int {
102    /** No performance mode is specified. The specific running mode is defined by the chip. */
103    PERFORMANCE_NONE,
104    /** Low-performance mode, which provides slow AI computing but low power consumption. */
105    PERFORMANCE_LOW,
106    /** Medium-performance mode, which provides moderate computing speed and power consumption. */
107    PERFORMANCE_MEDIUM,
108    /** High-performance mode, which provides fast AI computing but high power consumption. */
109    PERFORMANCE_HIGH,
110    /** Extreme-performance mode, which provides the fastest AI computing but highest power consumption. */
111    PERFORMANCE_EXTREME
112};
113
114/**
115 * @brief Enumerates the AI computing task priorities.
116 *
117 * @since 3.2
118 * @version 1.0
119 */
120enum Priority: int {
121    /** No task priority is specified. The specific execution policy is defined by the chip. */
122    PRIORITY_NONE,
123    /** Low priority. A task with a higher priority will be executed first. */
124    PRIORITY_LOW,
125    /** Medium priority. A task with a higher priority will be executed first. */
126    PRIORITY_MEDIUM,
127    /** High priority. High-priority tasks are executed first. */
128    PRIORITY_HIGH
129};
130
131/**
132 * @brief Defines the parameters required for model building.
133 *
134 * @since 3.2
135 * @version 1.0
136 */
137struct ModelConfig {
138    /** Whether to run a Float32 model in Float16 precision. */
139    boolean enableFloat16;
140    /** Performance mode of the computing task. For details, see {@link PerformanceMode}. */
141    enum PerformanceMode mode;
142    /** Priority of the computing task. For details, see {@link Priority}. */
143    enum Priority priority;
144};
145
146/**
147 * @brief Enumerates the operator data formats. This parameter must be used together with {@link Tensor}.
148 *
149 * @since 3.2
150 * @version 1.0
151 */
152enum Format : byte {
153    /** Format initial value. */
154    FORMAT_NONE = -1,
155    /** NCHW, which indicates the number of data samples, image channels, image height, and image width in sequence. */
156    FORMAT_NCHW = 0,
157    /** NHWC. */
158    FORMAT_NHWC = 1
159};
160
161/**
162 * @brief Defines the quantization parameter structure.
163 *
164 * In the following formula, <b>q</b> is a quantized parameter, <b>r</b> is a real parameter, <b>\f$ r_{max} \f$</b> is the maximum value of the data to be quantized, <b>\f$ r_{min} \f$</b> is the minimum value of the data to be quantized, and <b>round(x)</b> means to round off <b>x</b> to an integer.
165 \f[
166  \text{clamp}(x,min,max) =
167  \begin{cases}
168       \text{max} & \text{ if } x > \text{ max } \\
169       \text{min} & \text{ if } x < \text{ min } \\
170       x & \text{ otherwise } \\
171   \end{cases}
172 \f]
173 * Formula for transforming a real number from a floating-point representation to a fixed-point representation:
174 \f[
175    \text{q}(x_i) = clamp(round(\frac{r}{scale}+zeroPoint), min , max)
176 \f]
177 * Formula for transforming a real number from a fixed-point representation to a floating-point representation:
178 \f[
179    \text{r}= (q-zeroPoint)*scale
180 \f]
181 * <b>scale</b> is calculated by using the following formula:
182 \f[
183    scale = \frac{r_{max}-r_{min}}{q_{max}-q_{min}}
184 \f]
185  * <b>zeroPoint</b> is calculated by using the following formula:
186 \f[
187    zeroPoint = round(q_{min}-\frac{r_{min}}{scale})
188 \f]
189  * <b>\f$ q_{min},q_{max} \f$</b> is calculated by using the following formula:
190 \f[
191    q_{min} = -(1<<(numBits-1))
192 \f]
193 \f[
194    q_{max} = (1<<(numBits-1))-1
195 \f]
196 * When \f$ r_{min} \f$ and \f$ r_{max} \f$ are <b>0</b>, <b>scale</b> and <b>zeroPoint</b> must be <b>0</b>.
197 *
198 * @since 3.2
199 * @version 1.0
200 */
201struct QuantParam {
202    /** Number of quantized bits */
203    int numBits;
204    /** Zero value */
205    int zeroPoint;
206    /** Step of the quantizer. */
207    double scale;
208};
209
210/**
211 * @brief Enumerates the tensor data types. This parameter must be used together with {@link Tensor}.
212 *
213 * @since 3.2
214 * @version 1.0
215 */
216enum DataType : byte {
217    /** Unknown type. */
218    DATA_TYPE_UNKNOWN = 0,
219    /** Boolean. */
220    DATA_TYPE_BOOL = 30,
221    /** INT8. */
222    DATA_TYPE_INT8 = 32,
223    /** INT16. */
224    DATA_TYPE_INT16 = 33,
225    /** INT32. */
226    DATA_TYPE_INT32 = 34,
227    /** INT64. */
228    DATA_TYPE_INT64 = 35,
229    /** UINT8. */
230    DATA_TYPE_UINT8 = 37,
231    /** UINT16. */
232    DATA_TYPE_UINT16 = 38,
233    /** UINT32. */
234    DATA_TYPE_UINT32 = 39,
235    /** UINT64. */
236    DATA_TYPE_UINT64 = 40,
237    /** FLOAT16. */
238    DATA_TYPE_FLOAT16 = 42,
239    /** FLOAT32. */
240    DATA_TYPE_FLOAT32 = 43,
241    /** FLOAT64. */
242    DATA_TYPE_FLOAT64 = 44,
243};
244
245/**
246 * @brief Defines the input and output tensors of an AI model.
247 *
248 * @since 3.2
249 * @version 1.0
250 */
251struct IOTensor {
252    /** Tensor name. */
253    String name;
254    /** Data type of the tensor. For details, see {@link DataType}. */
255    enum DataType dataType;
256    /** Dimensions of the tensor. */
257    int[] dimensions;
258    /** Format of the tensor. For details, see {@link Format}. */
259    enum Format format;
260    /** Tensor data, which is stored in the shared memory. For details about the shared memory, see {@link SharedBuffer}. */
261    struct SharedBuffer data;
262};
263
264/**
265 * @brief Enumerates the quantization types. This parameter must be used together with {@link Node}.
266 *
267 * @since 3.2
268 * @version 1.0
269 */
270enum QuantType: byte {
271    /** Do not use quantification. */
272    QUANT_TYPE_NONE,
273    /** INT8 quantization. */
274    QUANT_TYPE_ALL,
275};
276
277/**
278 * @brief Enumerates the operator types.
279 *
280 * @since 3.2
281 * @version 1.0
282 */
283enum NodeType : unsigned int {
284    /** None. */
285    NODE_TYPE_NONE = 0,
286    /** Activation function */
287    NODE_TYPE_ACTIVATION = 2,
288    /** ADD operator */
289    NODE_TYPE_ADD_FUSION = 5,
290    /** ArgMax operator */
291    NODE_TYPE_ARGMAX_FUSION = 11,
292    /** AVGPOOL operator */
293    NODE_TYPE_AVGPOOL_FUSION = 17,
294    /** BatchToSpaceND operator */
295    NODE_TYPE_BATCH_TO_SPACE_ND = 22,
296    /** BiasAdd operator */
297    NODE_TYPE_BIAS_ADD = 23,
298    /** Cast operator */
299    NODE_TYPE_CAST = 28,
300    /** Concat operator */
301    NODE_TYPE_CONCAT = 31,
302    /** Conv2D operator, including common convolution, separable convolution, and group convolution */
303    NODE_TYPE_CONV2D_FUSION = 35,
304    /** Two-dimensional deconvolution operator */
305    NODE_TYPE_CONV2D_TRANSPOSE_FUSION = 36,
306    /** Div operator */
307    NODE_TYPE_DIV_FUSION = 47,
308    /** Element-level operator */
309    NODE_TYPE_ELTWISE = 52,
310    /** ExpandDims operator */
311    NODE_TYPE_EXPAND_DIMS = 56,
312    /** Fill operator */
313    NODE_TYPE_FILL = 66,
314    /** FullConnection operator */
315    NODE_TYPE_FULL_CONNECTION = 67,
316    /** BatchNorm operator */
317    NODE_TYPE_FUSED_BATCH_NORM = 68,
318    /** Gather operator */
319    NODE_TYPE_GATHER = 69,
320    /** LayerNorm operator */
321    NODE_TYPE_LAYER_NORM_FUSION = 75,
322    /** LessEqual operator */
323    NODE_TYPE_LESS_EQUAL = 78,
324    /** MatMul operator */
325    NODE_TYPE_MATMUL_FUSION = 89,
326    /** Maximum operator */
327    NODE_TYPE_MAXIMUM = 90,
328    /** MaxPool operator */
329    NODE_TYPE_MAX_POOL_FUSION = 92,
330    /** Mul operator */
331    NODE_TYPE_MUL_FUSION = 99,
332    /** OneHot operator */
333    NODE_TYPE_ONE_HOT = 105,
334    /** Pad operator */
335    NODE_TYPE_PAD_FUSION = 107,
336    /** Pow operator */
337    NODE_TYPE_POW_FUSION = 110,
338    /** PReLU operator */
339    NODE_TYPE_PRELU_FUSION = 112,
340    /** QuantDTypeCast operator */
341    NODE_TYPE_QUANT_DTYPE_CAST = 113,
342    /** Reduce operator */
343    NODE_TYPE_REDUCE_FUSION = 118,
344    /** Reshape operator */
345    NODE_TYPE_RESHAPE = 119,
346    /** Resize operator */
347    NODE_TYPE_RESIZE = 120,
348    /** Rsqrt operator */
349    NODE_TYPE_RSQRT = 126,
350    /** Scale operator */
351    NODE_TYPE_SCALE_FUSION = 127,
352    /** Shape operator */
353    NODE_TYPE_SHAPE = 130,
354    /** Slice operator */
355    NODE_TYPE_SLICE_FUSION = 135,
356    /** Softmax operator */
357    NODE_TYPE_SOFTMAX = 138,
358    /** SpaceToBatchND operator */
359    NODE_TYPE_SPACE_TO_BATCH_ND = 141,
360    /** Split operator */
361    NODE_TYPE_SPLIT = 145,
362    /** Sqrt operator */
363    NODE_TYPE_SQRT = 146,
364    /** Squeeze operator */
365    NODE_TYPE_SQUEEZE = 147,
366    /** SquaredDifference operator */
367    NODE_TYPE_SQUARED_DIFFERENCE = 149,
368    /** Stack operator */
369    NODE_TYPE_STACK = 150,
370    /** StridedSlice operator */
371    NODE_TYPE_STRIDED_SLICE = 151,
372    /** Sub operator */
373    NODE_TYPE_SUB_FUSION = 152,
374    /** Tile operator */
375    NODE_TYPE_TILE_FUSION = 160,
376    /** TopK operator */
377    NODE_TYPE_TOPK_FUSION = 161,
378    /** Transpose operator */
379    NODE_TYPE_TRANSPOSE = 162,
380    /** Unsqueeze operator */
381    NODE_TYPE_UNSQUEEZE = 165,
382};
383
384/**
385 * @brief Enumerates the resize methods. It must be used together with the {@link Resize} operator.
386 *
387 * @since 3.2
388 * @version 1.0
389 */
390enum ResizeMethod : byte {
391    /** Unknown. This is the default value. */
392    RESIZE_METHOD_UNKNOWN = -1,
393    /** Bilinear interpolation.
394     * For example, calculate the value of an unknown function <b>f</b> at point \f$ (x,y) \f$, where \f$ x_1< x < x_2, y_1< y < y_2 \f$.
395     * The values of the four coordinate points are \f$ Q_{11} = (x_1, y_1), Q_{12} = (x1, y2), Q_{21} = (x_2, y_1), and Q_{22} = (x_2, y_2) \f$.
396     * \f$f(Q_{11}), f(Q_{12}), f(Q_{21}), and f(Q_{22}) \f$ represent the values of the four points. The value of \f$ f(x,y) \f$ can be calculated by using the following formula:
397      \f[
398         f(x,y_1) = \frac{x_2-x}{x_2-x_1}f(Q_{11})+\frac{x-x_1}{x_2-x_1}f(Q_{21})
399      \f]
400
401      \f[
402         f(x,y_2) = \frac{x_2-x}{x_2-x_1}f(Q_{12})+\frac{x-x_1}{x_2-x_1}f(Q_{22})
403      \f]
404
405      \f[
406         f(x,y) = \frac{y_2-y}{y_2-y_1}f(x,y_1)+\frac{y-y_1}{y_2-y_1}f(x,y_2)
407      \f]
408     */
409    RESIZE_METHOD_LINEAR = 0,
410    /** Nearest neighbor interpolation.
411     * For example, calculate the value of an unknown function <b>f</b> at point \f$ (x,y) \f$, where \f$ x_1< x < x_2, y_1< y < y_2 \f$.
412     * The values of the four coordinate points are \f$ Q_{11} = (x_1, y_1), Q_{12} = (x1, y2), Q_{21} = (x_2, y_1), and Q_{22} = (x_2, y_2) \f$.
413     * Then, the value of the point closest to the point \f$(x,y) \f$ is the value of \f$ f(x,y) \f$.
414     */
415    RESIZE_METHOD_NEAREST = 1,
416    /** Bicubic interpolation.
417     * Bicubic interpolation obtains the value of a sampling point by calculating the weighted average of the values of 16 points around the sampling point. This parameter must be used together with <b>cubicCoeff</b> and <b>coordinateTransformMode</b> of {@link Resize}.
418     * When coordinateTransformMode==COORDINATE_TRANSFORM_MODE_HALF_PIXEL, <b>cubicCoeff</b> is <b>-0.5</b>. In other cases, cubicCoeff is <b>-0.75</b>. The weight function of the interpolation is as follows:
419      \f[
420         W(x) =
421         \begin{cases}
422            (cubicCoeff+2)|x|^3 - (cubicCoeff+3)|x|^2 +1 , &\text{if } |x| \leq 1; \cr
423            cubicCoeff|x|^3 - 5cubicCoeff|x|^2 + 8cubicCoeff|x| - 4a, &\text{if } 1 \lt |x| \leq 2; \cr
424            0, &\text{otherwise.}
425        \end{cases}
426      \f]
427     */
428    RESIZE_METHOD_CUBIC = 2
429};
430
431/**
432 * @brief Enumerates the coordinate transformation modes. Only the {@link Resize} operator uses this parameter.
433 * For example, the width coordinates are transformed, where:
434 * <b>new_i</b> is the ith coordinate of the resized tensor along the x axis.
435 * <b>old_i</b> is the coordinate of the input tensor along the x axis.
436 * <b>newWidth</b> is the length of the resized tensor along the x axis.
437 * <b>oldWidth</b> is the length of the input tensor along the x axis.
438 * <b>old_i</b> can be calculated by using the following formula:
439 *
440 * COORDINATE_TRANSFORM_MODE_ASYMMETRIC: \f$ old_i = newWidth != 0 ? new_i * oldWidth / newWidth : 0 \f$ <br>
441 * COORDINATE_TRANSFORM_MODE_ALIGN_CORNERS: \f$ old_i = newWidth != 1 ? new_i * (oldWidth - 1) / (newWidth - 1) \f$<br>
442 * COORDINATE_TRANSFORM_MODE_HALF_PIXEL: \f$ old_i = newWidth > 1 ? (new_x + 0.5) * oldWidth / newWidth - 0.5 : 0 \f$<br>
443 *
444 * @since 3.2
445 * @version 1.0
446 */
447enum CoordinateTransformMode : byte {
448    /** Scale based on the ratio without alignment. */
449    COORDINATE_TRANSFORM_MODE_ASYMMETRIC = 0,
450    /** Align the four corners of the image. */
451    COORDINATE_TRANSFORM_MODE_ALIGN_CORNERS = 1,
452    /** Align with the pixel center. */
453    COORDINATE_TRANSFORM_MODE_HALF_PIXEL = 2
454};
455
456/**
457 * @brief Enumerates the nearest neighbor interpolation types. It must be used together with the {@link Resize} operator.
458 *
459 * @since 3.2
460 * @version 1.0
461 */
462enum NearestMode : byte {
463    /** Round off. */
464    NEAREST_MODE_NORMAL = 0,
465    /** Round toward negative infinity. For example, 23.5 is rounded to 23, and −23.5 is rounded to −24. */
466    NEAREST_MODE_ROUND_HALF_DOWN = 1,
467    /** Round toward positive infinity. For example, 23.5 is rounded to 24, and −23.5 is rounded to −23. */
468    NEAREST_MODE_ROUND_HALF_UP = 2,
469    /** Round down to the nearest integer. For example, 23.5 is rounded down to 23, and −23.5 is rounded down to −24. */
470    NEAREST_MODE_FLOOR = 3,
471    /** Round up to the nearest integer. For example, 23.5 is rounded up to 24, and −23.5 is rounded up to −23. */
472    NEAREST_MODE_CEIL = 4
473};
474
475/**
476 * @brief Enumerates the activation function types. Activation functions introduce nonlinearity to neural networks. This allows the use of neural network models in nonlinear models.
477 * If an operator in the {@link NodeAttrTypes.idl} file has <b>ActivationType</b> parameters, the corresponding activation function will be called after the operator calculation is complete.
478 *
479 * @since 3.2
480 * @version 1.0
481 */
482enum ActivationType : byte {
483    /** No activation function. */
484    ACTIVATION_TYPE_NO_ACTIVATION = 0,
485    /**
486     * ReLU activation function.
487     * ReLU calculates \f$ max(x_i, 0) \f$ element by element. It outputs the value directly if it is positive; otherwise, it outputs <b>0</b>.
488     \f[
489        \text{ReLU}(x_i) = (x_i)^+ = \max(x_i, 0),
490     \f]
491     * <b>\f$ x_i \f$</b> is the input element.
492     */
493    ACTIVATION_TYPE_RELU = 1,
494    /**
495     * Sigmoid activation function.
496     * Execute the sigmoid activation function element-wise.
497     * The sigmoid function is defined as follows:
498     \f[
499        \text{Sigmoid}(x_i) = \frac{1}{1 + \exp(-x_i)}
500     \f]
501     * <b>\f$ x_i \f$</b> is the input element.
502     */
503    ACTIVATION_TYPE_SIGMOID = 2,
504    /**
505     * ReLU6 activation function.
506     * ReLU6 is similar to ReLU. The difference is ReLU6 has an upper limit of <b>6</b>. If the input is greater than 6, the output is limited to <b>6</b>.
507     * The ReLU6 function is defined as follows:
508     \f[
509        \text{ReLU6}(x_i) = \min(\max(0, x_i), 6)
510     \f]
511     * <b>\f$ x_i \f$</b> is the input element.
512     */
513    ACTIVATION_TYPE_RELU6 = 3,
514    /**
515     * Exponential Linear Unit (ELU) activation function.
516     * ELU calculates the ELU for each input element.
517     * The ELU function is defined as follows:
518     \f[
519        ELU(x_{i}) =
520        \begin{cases}
521        x_i, &\text{if } x_i \geq 0; \cr
522        \alpha * (\exp(x_i) - 1), &\text{otherwise.}
523        \end{cases}
524     \f]
525     * <b>\f$ x_i \f$</b> indicates the input element, and <b>\f$ \alpha \f$</b> indicates the alpha parameter, which is set by {@link Activation}.
526     */
527    ACTIVATION_TYPE_ELU = 4,
528    /**
529     * LeakyReLU activation function.
530     * The LeakyReLU function is defined as follows:
531     \f[
532        \text{LeakyReLU}(x_i) =
533        \begin{cases}
534            x_i, &\text{if } x_i \geq 0; \cr
535            {\alpha} * x_i, &\text{otherwise.}
536        \end{cases}
537     \f]
538     * <b>\f$ x_i \f$</b> indicates the input element, and <b>\f$ \alpha \f$</b> indicates the alpha parameter, which is set by {@link Activation}.
539     */
540    ACTIVATION_TYPE_LEAKY_RELU = 5,
541    /**
542     * Activation function for calculating the absolute value.
543     * The function is defined as follows:
544     \f[
545        \text{abs}(x_i) = |x_i|
546     \f]
547     * <b>\f$ x_i \f$</b> is the input element.
548     */
549    ACTIVATION_TYPE_ABS = 6,
550    /**
551     * ReLU1 activation function.
552     * The ReLU1 function is defined as follows:
553     \f[
554        \text{ReLU1}(x_i)= \min(\max(0, x_i), 1)
555     \f]
556     * <b>\f$ x_i \f$</b> is the input element.
557     */
558    ACTIVATION_TYPE_RELU1 = 7,
559    /**
560     * SoftSign activation function.
561     * The SoftSign function is defined as follows:
562     \f[
563        \text{SoftSign}(x_i) = \frac{x_i}{1 + |x_i|}
564     \f]
565     * <b>\f$ x_i \f$</b> is the input.
566     */
567    ACTIVATION_TYPE_SOFTSIGN = 8,
568    /**
569     * Softplus activation function.
570     * Softplus is a smooth approximation to ReLU. It can be used to constrain the output to always be positive.
571     * The Softplus function is defined as follows:
572     \f[
573        \text{Softplus}(x_i) = \log(1 + \exp(x_i))
574     \f]
575     * <b>\f$ x_i \f$</b> is the input element.
576     */
577    ACTIVATION_TYPE_SOFTPLUS = 9,
578    /**
579     * Tanh activation function.
580     * The Tanh function is defined as follows:
581     \f[
582        tanh(x) = \frac{\exp(x_i) - \exp(-x_i)}{\exp(x_i) + \exp(-x_i)} = \frac{\exp(2x_i) - 1}{\exp(2x_i) + 1}
583     \f]
584     * <b>\f$ x_i \f$</b> is the input element.
585     */
586    ACTIVATION_TYPE_TANH = 10,
587    /**
588     * Scaled exponential Linear Unit (SELU) activation function.
589     * The SELU function is defined as follows:
590     \f[
591        SELU(x_{i}) =
592        scale *
593        \begin{cases}
594        x_{i}, &\text{if } x_{i} \geq 0; \cr
595        \text{alpha} * (\exp(x_i) - 1), &\text{otherwise.}
596        \end{cases}
597     \f]
598     * <b>\f$ x_i \f$</b> is the input element, and <b>\f$ \alpha \f$</b> and <b>\f$ scale \f$</b> are predefined constants (\f$ \alpha = 1.67326324 \f$, \f$ scale = 1.05070098 \f$).
599     */
600    ACTIVATION_TYPE_SELU = 11,
601    /**
602     * Hard Swish activation function.
603     *
604     \f[
605        \text{Hardswish}(x_{i}) = x_{i} * \frac{ReLU6(x_{i} + 3)}{6}
606     \f]
607     * <b>\f$ x_i \f$</b> is the input element.
608     */
609    ACTIVATION_TYPE_HSWISH = 12,
610    /**
611     * Hard sigmoid activation function.
612     * The hard sigmoid function is defined as follows:
613     \f[
614        \text{Hardsigmoid}(x_{i}) = max(0, min(1, \frac{x_{i} + 3}{6}))
615     \f]
616     * <b>\f$ x_i \f$</b> is the input element.
617     */
618    ACTIVATION_TYPE_HSIGMOID = 13,
619    /**
620     * ThresholdedReLU activation function.
621     * ThresholdedReLU is similar to ReLU. The <b>ThresholdedReLU</b> function is defined as follows:
622     \f[
623        \text{ThresholdedReLU}(x_i) = \min(\max(0, x_i), t)
624     \f]
625     * <b>\f$ x_i \f$</b> is the input element, and <b>\f$ t \f$</b> is the maximum value.
626     */
627    ACTIVATION_TYPE_THRESHOLDRELU = 14,
628    /**
629     * Linear activation function.
630     * The Linear function is defined as follows:
631     \f[
632        \text{Linear}(x_i) = x_i
633     \f]
634     * <b>\f$ x_i \f$</b> is the input element.
635     */
636    ACTIVATION_TYPE_LINEAR = 15,
637    /**
638     * HardTanh activation function.
639     * The HardTanh function is defined as follows:
640     \f[
641       \text{HardTanh}(x_i) =
642       \begin{cases}
643            \text{max_val} & \text{ if } x_i > \text{ max_val } \\
644            \text{min_val} & \text{ if } x_i < \text{ min_val } \\
645            x_i & \text{ otherwise } \\
646        \end{cases}
647     \f]
648     * <b>\f$ x_i \f$</b> is the input, <b>\f$ max\_val \f$</b> is the maximum value, and <b>\f$ min\_val \f$</b> is the minimum value. The two parameters are set by {@link Activation}.
649     */
650    ACTIVATION_TYPE_HARD_TANH = 16,
651    /**
652     * Sign activation function.
653     * The Sign function is defined as follows:
654     \f[
655        Sign(x_i) = \begin{cases} -1, &if\ x_i < 0 \cr
656        0, &if\ x_i = 0 \cr
657        1, &if\ x_i > 0\end{cases}
658     \f]
659     * <b>\f$ x_i \f$</b> is the input.
660     */
661    ACTIVATION_TYPE_SIGN = 17,
662    /**
663     * Swish activation function.
664     * The Swish function is defined as follows:
665     \f[
666        \text{Swish}(x_i) = x_i * Sigmoid(x_i)
667     \f]
668     * <b>\f$ x_i \f$</b> is the input.
669     */
670    ACTIVATION_TYPE_SWISH = 18,
671    /**
672     * Gaussian error linear unit (GELU) activation function.
673     * The GELU function is defined as follows:
674     \f[
675        GELU(x_i) = x_i*P(X < x_i)
676     \f]
677     * <b>\f$ x_i \f$</b> is the input element, and <b>\f$ P \f$</b> is a cumulative distribution function of the standard Gaussian distribution.
678     * You need to use the <b>approximate</b> parameter of {@link Activation} to specify whether to use approximation.
679     */
680    ACTIVATION_TYPE_GELU = 19,
681    /** Unknown */
682    ACTIVATION_TYPE_UNKNOWN = 20
683};
684
685/**
686 * @brief Enumerates the modes for removing dimensions. It must be used together with the {@link ReduceFusion} operator.
687 *
688 * @since 3.2
689 * @version 1.0
690 */
691enum ReduceMode : byte {
692    /** Use the average value of all elements of a dimension to replace other elements of the dimension. */
693    REDUCE_MODE_MEAN = 0,
694    /** Use the maximum value of all elements of a dimension to replace other elements of the dimension. */
695    REDUCE_MODE_MAX = 1,
696    /** Use the minimum value of all elements of a dimension to replace other elements of the dimension. */
697    REDUCE_MODE_MIN = 2,
698    /** Use the product of all elements of a dimension to replace other elements of the dimension. */
699    REDUCE_MODE_PROD = 3,
700    /** Use the sum of all elements of a dimension to replace other elements of the dimension. */
701    REDUCE_MODE_SUM = 4,
702    /** Use the sum of squares of all elements of a dimension to replace other elements of the dimension. */
703    REDUCE_MODE_SUM_SQUARE = 5,
704    /** Use the sum of absolute values of all elements of a dimension to replace other elements of the dimension. */
705    REDUCE_MODE_ASUM = 6,
706    /** Use the logical AND of all elements of a dimension to replace other elements of the dimension. */
707    REDUCE_MODE_ALL = 7
708};
709
710/**
711 * @brief Enumerates the calculation types supported by elements. It must be used together with the {@link Eltwise} operator.
712 *
713 * @since 3.2
714 * @version 1.0
715 */
716enum EltwiseMode : byte {
717    /** Product of the elements of two tensors */
718    ELTWISE_MODE_PROD = 0,
719    /** Difference between the elements of two tensors */
720    ELTWISE_MODE_SUM = 1,
721    /** Maximum value of the elements of two tensors */
722    ELTWISE_MODE_MAXIMUM = 2,
723    /** Unknown type */
724    ELTWISE_MODE_UNKNOWN = 3
725};
726
727/**
728 * @brief Enumerates the padding types. It must be used together with {@link AvgPoolFusion}, {@link AvgPoolFusion}, {@link Conv2DFusion}, and {@link MaxPoolFusion}.
729 *
730 * @since 3.2
731 * @version 1.0
732 */
733enum PadMode : byte {
734    /**
735     * Adds 0s in the input height and width directions.
736     * If this mode is used, the padding parameter of the operator must be greater than or equal to 0.
737     */
738    PAD_MODE_PAD = 0,
739    /**
740     * The output height and width are obtained by dividing the input height and width by a stride and rounding off the quotient to an integer.
741     * If this mode is used, the padding parameter of the operator must be <b>0</b>.
742     */
743    PAD_MODE_SAME = 1,
744    /**
745     * Return the output of a valid calculation without padding. Pixels that do not meet the calculation requirements will be discarded.
746     * If this mode is used, the padding parameter of the operator must be <b>0</b>.
747     */
748    PAD_MODE_VALID = 2,
749};
750
751/**
752 * @brief Enumerates the algorithms for rounding off decimals. It must be used together with the {@link AvgPoolFusion} operator.
753 *
754 * @since 3.2
755 * @version 1.0
756 */
757enum RoundMode : byte {
758    /** Round down to the nearest integer. For example, 23.5 is rounded down to 23, and −23.5 is rounded down to −24. */
759    ROUND_MODE_FLOOR = 0,
760    /** Round up to the nearest integer. For example, 23.5 is rounded up to 24, and −23.5 is rounded up to −23. */
761    ROUND_MODE_CEIL = 1
762};
763
764/**
765 * @brief Enumerates the padding modes. It must be used together with the {@link PadFusion} operator.
766 *
767 * When <b>x</b> is \f$[[1,2,3],[4,5,6],[7,8,9]]\f$ and <b>paddings</b>is \f$[[2,2], [2,2]] \f$, the effect is as follows: <br>
768 * If paddingMode==PADDING_MODE_CONSTANT and constantValue = 0, the output is as follows:
769 *
770      \f$[[0. 0. 0. 0. 0. 0. 0.],\\
771          [0. 0. 0. 0. 0. 0. 0.],\\
772          [0. 0. 1. 2. 3. 0. 0.],\\
773          [0. 0. 4. 5. 6. 0. 0.],\\
774          [0. 0. 7. 8. 9. 0. 0.],\\
775          [0. 0. 0. 0. 0. 0. 0.],\\
776          [0. 0. 0. 0. 0. 0. 0.]]\\ \f$
777 *
778 * If paddingMode==PADDING_MODE_REFLECT, the output is as follows:
779 *
780      \f$[[9. 8. 7. 8. 9. 8. 7.],\\
781          [6. 5. 4. 5. 6. 5. 4.],\\
782          [3. 2. 1. 2. 3. 2. 1.],\\
783          [6. 5. 4. 5. 6. 5. 4.],\\
784          [9. 8. 7. 8. 9. 8. 7.],\\
785          [6. 5. 4. 5. 6. 5. 4.],\\
786          [3. 2. 1. 2. 3. 2. 1.]]\\ \f$
787 *
788 * If paddingMode==PADDING_MODE_SYMMETRIC, the output is as follows:
789 *
790      \f$[[5. 4. 4. 5. 6. 6. 5.],\\
791          [2. 1. 1. 2. 3. 3. 2.],\\
792          [2. 1. 1. 2. 3. 3. 2.],\\
793          [5. 4. 4. 5. 6. 6. 5.],\\
794          [8. 7. 7. 8. 9. 9. 8.],\\
795          [8. 7. 7. 8. 9. 9. 8.],\\
796          [5. 4. 4. 5. 6. 6. 5.]]\\ \f$
797 *
798 * @since 3.2
799 * @version 1.0
800 */
801enum PaddingMode : byte {
802    /** Constant (0 by default) padding. */
803    PADDING_MODE_CONSTANT = 0,
804    /** Reflection padding, which uses the content next to the input data to pad the values directly next to it. */
805    PADDING_MODE_REFLECT = 1,
806    /** Symmetric padding, which is similar to {@link PADDING_MODE_REFLECT}. Symmetric padding makes a copy of the input. */
807    PADDING_MODE_SYMMETRIC = 2,
808    /** Reserved. */
809    PADDING_MODE_RESERVED = 3
810};
811
812/** @} */
813