1/*
2 * Copyright (c) 2024 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 *
23 * @since 3.2
24 * @version 2.1
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 2.1
34 */
35
36/**
37 * @brief Defines the package path of the NNRt module.
38 *
39 * @since 3.2
40 * @version 2.1
41 */
42package ohos.hdi.nnrt.v2_1;
43
44/**
45 * @brief Defines the shared memory data structure.
46 *
47 * @since 3.2
48 * @version 2.1
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 2.1
66 */
67enum DeviceType: int {
68    /** Other types. */
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 2.1
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 2.1
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 2.1
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 2.1
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    /** Custom attributes of the underlying hardware. They stored in the format of name:binary value
145      * and parsed by the HDI service.
146      */
147    Map<String, byte[]> extensions;
148};
149
150/**
151 * @brief Enumerates the operator data formats. This parameter must be used together with {@link Tensor}.
152 *
153 * @since 3.2
154 * @version 2.1
155 */
156enum Format : byte {
157    /** Format initial value. */
158    FORMAT_NONE = -1,
159    /** NCHW, which indicates the number of data samples, image channels, image height, and image width in sequence. */
160    FORMAT_NCHW = 0,
161    /** NHWC. */
162    FORMAT_NHWC = 1
163};
164
165/**
166 * @brief Defines the quantization parameter structure.
167 *
168 * In the following formula, <b>q</b> is a quantized parameter, <b>r</b> is a real parameter, <b>\f$ r_{max} \f$</b>\n
169 * is the maximum value of the data to be quantized, <b>\f$ r_{min} \f$</b> is the minimum value of the data
170 * to be quantized, and <b>round(x)</b> means to round off <b>x</b> to an integer.
171 \f[
172  \text{clamp}(x,min,max) =
173  \begin{cases}
174       \text{max} & \text{ if } x > \text{ max } \\
175       \text{min} & \text{ if } x < \text{ min } \\
176       x & \text{ otherwise } \\
177   \end{cases}
178 \f]
179 * Formula for transforming a real number from a floating-point representation to a fixed-point representation:
180 \f[
181    \text{q}(x_i) = clamp(round(\frac{r}{scale}+zeroPoint), min , max)
182 \f]
183 * Formula for transforming a real number from a fixed-point representation to a floating-point representation:
184 \f[
185    \text{r}= (q-zeroPoint)*scale
186 \f]
187 * <b>scale</b> is calculated by using the following formula:
188 \f[
189    scale = \frac{r_{max}-r_{min}}{q_{max}-q_{min}}
190 \f]
191  * <b>zeroPoint</b> is calculated by using the following formula:
192 \f[
193    zeroPoint = round(q_{min}-\frac{r_{min}}{scale})
194 \f]
195  * <b>\f$ q_{min},q_{max} \f$</b> is calculated by using the following formula:
196 \f[
197    q_{min} = -(1<<(numBits-1))
198 \f]
199 \f[
200    q_{max} = (1<<(numBits-1))-1
201 \f]
202 * 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>.
203 *
204 * @since 3.2
205 * @version 2.1
206 */
207struct QuantParam {
208    /** Number of quantized bits. */
209    int numBits;
210    /** Zero value. */
211    int zeroPoint;
212    /** Step of the quantizer. */
213    double scale;
214};
215
216/**
217 * @brief Enumerates the tensor data types. This parameter must be used together with {@link Tensor}.
218 *
219 * @since 3.2
220 * @version 2.1
221 */
222enum DataType : byte {
223    /** Unknown type. */
224    DATA_TYPE_UNKNOWN = 0,
225    /** Boolean. */
226    DATA_TYPE_BOOL = 30,
227    /** INT8. */
228    DATA_TYPE_INT8 = 32,
229    /** INT16. */
230    DATA_TYPE_INT16 = 33,
231    /** INT32. */
232    DATA_TYPE_INT32 = 34,
233    /** INT64. */
234    DATA_TYPE_INT64 = 35,
235    /** UINT8. */
236    DATA_TYPE_UINT8 = 37,
237    /** UINT16. */
238    DATA_TYPE_UINT16 = 38,
239    /** UINT32. */
240    DATA_TYPE_UINT32 = 39,
241    /** UINT64. */
242    DATA_TYPE_UINT64 = 40,
243    /** FLOAT16. */
244    DATA_TYPE_FLOAT16 = 42,
245    /** FLOAT32. */
246    DATA_TYPE_FLOAT32 = 43,
247    /** FLOAT64. */
248    DATA_TYPE_FLOAT64 = 44,
249};
250
251/**
252 * @brief Defines the input and output tensors of an AI model.
253 *
254 * @since 3.2
255 * @version 2.1
256 */
257struct IOTensor {
258    /** Tensor name. */
259    String name;
260    /** Data type of the tensor. For details, see {@link DataType}. */
261    enum DataType dataType;
262    /** Dimensions of the tensor. */
263    int[] dimensions;
264    /** Format of the tensor. For details, see {@link Format}. */
265    enum Format format;
266    /** Tensor data, which is stored in the shared memory. For details about the shared memory,\n
267      * see {@link SharedBuffer}.
268      */
269    struct SharedBuffer data;
270};
271
272/**
273 * @brief Enumerates the quantization types. This parameter must be used together with {@link Node}.
274 *
275 * @since 3.2
276 * @version 2.1
277 */
278enum QuantType: byte {
279    /** Do not use quantification. */
280    QUANT_TYPE_NONE,
281    /** INT8 quantization. */
282    QUANT_TYPE_ALL,
283};
284
285/**
286 * @brief Enumerates the operator types.
287 *
288 * @since 3.2
289 * @version 2.1
290 */
291enum NodeType : unsigned int {
292    /** None. */
293    NODE_TYPE_NONE = 0,
294    /** Abs operator. */
295    NODE_TYPE_ABS = 1,
296    /** Activation function. */
297    NODE_TYPE_ACTIVATION = 2,
298    /** ADD operator. */
299    NODE_TYPE_ADD_FUSION = 5,
300    /** ALL operator. */
301    NODE_TYPE_ALL = 9,
302    /** ArgMax operator. */
303    NODE_TYPE_ARGMAX_FUSION = 11,
304    /** Assert operator. */
305    NODE_TYPE_ASSERT = 13,
306    /** AVGPOOL operator. */
307    NODE_TYPE_AVGPOOL_FUSION = 17,
308    /** BatchToSpaceND operator. */
309    NODE_TYPE_BATCH_TO_SPACE_ND = 22,
310    /** BiasAdd operator. */
311    NODE_TYPE_BIAS_ADD = 23,
312    /** BroadCastTo operator. */
313    NODE_TYPE_BROADCAST_TO = 27,
314    /** Cast operator. */
315    NODE_TYPE_CAST = 28,
316    /** Ceil operator. */
317    NODE_TYPE_CEIL = 29,
318    /** Clip operator. */
319    NODE_TYPE_CLIP = 30,
320    /** Concat operator. */
321    NODE_TYPE_CONCAT = 31,
322    /** Conv2D operator, including common convolution, separable convolution, and group convolution. */
323    NODE_TYPE_CONV2D_FUSION = 35,
324    /** Two-dimensional deconvolution operator. */
325    NODE_TYPE_CONV2D_TRANSPOSE_FUSION = 36,
326    /** Cos operator. */
327    NODE_TYPE_COS = 37,
328    /** ConstantOfShape operator. */
329    NODE_TYPE_CONSTANT_OF_SHAPE = 38,
330    /** Crop operator. */
331    NODE_TYPE_CROP = 39,
332    /** DepthToSpace operator. */
333    NODE_TYPE_DEPTH_TO_SPACE = 45,
334    /** DetectionPostProcess operator. */
335    NODE_TYPE_DETECTION_POST_PROCESS = 46,
336    /** Div operator. */
337    NODE_TYPE_DIV_FUSION = 47,
338    /** Element-level operator. */
339    NODE_TYPE_ELTWISE = 52,
340    /** Equal operator. */
341    NODE_TYPE_EQUAL = 53,
342    /** Exp operator. */
343    NODE_TYPE_EXPFUSION = 55,
344    /** ExpandDims operator. */
345    NODE_TYPE_EXPAND_DIMS = 56,
346    /** Flatten operator. */
347    NODE_TYPE_FLATTEN = 61,
348    /** Floor operator. */
349    NODE_TYPE_FLOOR = 63,
350    /** Fill operator. */
351    NODE_TYPE_FILL = 66,
352    /** FullConnection operator. */
353    NODE_TYPE_FULL_CONNECTION = 67,
354    /** BatchNorm operator. */
355    NODE_TYPE_FUSED_BATCH_NORM = 68,
356    /** Gather operator. */
357    NODE_TYPE_GATHER = 69,
358    /** GatherNd operator. */
359    NODE_TYPE_GATHER_ND = 70,
360    /** Greater operator. */
361    NODE_TYPE_GREATER = 71,
362    /** GreaterEqual operator. */
363    NODE_TYPE_GREATER_EQUAL = 72,
364    /** InstanceNorm operator. */
365    NODE_TYPE_INSTANCE_NORM = 74,
366    /** LayerNorm operator. */
367    NODE_TYPE_LAYER_NORM_FUSION = 75,
368    /** LeakyReLU operator. */
369    NODE_TYPE_LEAKY_RELU = 76,
370    /** Less operator. */
371    NODE_TYPE_LESS = 77,
372    /** LessEqual operator. */
373    NODE_TYPE_LESS_EQUAL = 78,
374    /** Log operator. */
375    NODE_TYPE_LOG = 79,
376    /** LogicalAnd operator. */
377    NODE_TYPE_LOGICAL_AND = 81,
378    /** LogicalNot operator. */
379    NODE_TYPE_LOGICAL_NOT = 82,
380    /** LogicalOr operator. */
381    NODE_TYPE_LOGICAL_OR = 83,
382    /** LRN operator. */
383    NODE_TYPE_LRN = 85,
384    /** LSTM operator. */
385    NODE_TYPE_LSTM = 87,
386    /** L2NormalizeFusion operator. */
387    NODE_TYPE_L2_NORMALIZE_FUSION = 88,
388    /** MatMul operator. */
389    NODE_TYPE_MATMUL_FUSION = 89,
390    /** Maximum operator. */
391    NODE_TYPE_MAXIMUM = 90,
392    /** MaxPool operator. */
393    NODE_TYPE_MAX_POOL_FUSION = 92,
394    /** Minimum operator. */
395    NODE_TYPE_MINIMUM = 96,
396    /** Mod operator. */
397    NODE_TYPE_MOD = 98,
398    /** Mul operator. */
399    NODE_TYPE_MUL_FUSION = 99,
400    /** Neg operator. */
401    NODE_TYPE_NEG = 101,
402    /** NotEqual operator. */
403    NODE_TYPE_NOT_EQUAL = 103,
404    /** OneHot operator. */
405    NODE_TYPE_ONE_HOT = 105,
406    /** Pad operator. */
407    NODE_TYPE_PAD_FUSION = 107,
408    /** Pow operator. */
409    NODE_TYPE_POW_FUSION = 110,
410    /** PReLU operator. */
411    NODE_TYPE_PRELU_FUSION = 112,
412    /** QuantDTypeCast operator. */
413    NODE_TYPE_QUANT_DTYPE_CAST = 113,
414    /** Rank operator. */
415    NODE_TYPE_RANK = 114,
416    /** Range operator. */
417    NODE_TYPE_RANGE = 115,
418    /** Reciprocal operator. */
419    NODE_TYPE_RECIPROCAL = 116,
420    /** RealDiv operator. */
421    NODE_TYPE_REAL_DIV = 117,
422    /** Reduce operator. */
423    NODE_TYPE_REDUCE_FUSION = 118,
424    /** Reshape operator. */
425    NODE_TYPE_RESHAPE = 119,
426    /** Resize operator. */
427    NODE_TYPE_RESIZE = 120,
428    /** Round operator. */
429    NODE_TYPE_ROUND = 125,
430    /** Rsqrt operator. */
431    NODE_TYPE_RSQRT = 126,
432    /** Scale operator. */
433    NODE_TYPE_SCALE_FUSION = 127,
434    /** ScatterNd operator. */
435    NODE_TYPE_SCATTER_ND = 128,
436    /** Shape operator. */
437    NODE_TYPE_SHAPE = 130,
438    /** Sin operator. */
439    NODE_TYPE_SIN = 133,
440    /** Slice operator. */
441    NODE_TYPE_SLICE_FUSION = 135,
442    /** Softmax operator. */
443    NODE_TYPE_SOFTMAX = 138,
444    /** SpaceToBatchND operator. */
445    NODE_TYPE_SPACE_TO_BATCH_ND = 141,
446    /** SpaceToDepth operator. */
447    NODE_TYPE_SPACE_TO_DEPTH = 142,
448    /** SparseToDense operator. */
449    NODE_TYPE_SPARSE_TO_DENSE = 144,
450    /** Split operator. */
451    NODE_TYPE_SPLIT = 145,
452    /** Sqrt operator. */
453    NODE_TYPE_SQRT = 146,
454    /** Squeeze operator. */
455    NODE_TYPE_SQUEEZE = 147,
456    /** Square operator. */
457    NODE_TYPE_SQUARE = 148,
458    /** SquaredDifference operator. */
459    NODE_TYPE_SQUARED_DIFFERENCE = 149,
460    /** Stack operator. */
461    NODE_TYPE_STACK = 150,
462    /** StridedSlice operator. */
463    NODE_TYPE_STRIDED_SLICE = 151,
464    /** Sub operator. */
465    NODE_TYPE_SUB_FUSION = 152,
466    /** Tile operator. */
467    NODE_TYPE_TILE_FUSION = 160,
468    /** TopK operator. */
469    NODE_TYPE_TOPK_FUSION = 161,
470    /** Transpose operator. */
471    NODE_TYPE_TRANSPOSE = 162,
472    /** Unsqueeze operator. */
473    NODE_TYPE_UNSQUEEZE = 165,
474    /** Unstack operator. */
475    NODE_TYPE_UNSTACK = 166,
476    /** Where operator. */
477    NODE_TYPE_WHERE = 168,
478    /** Select operator. */
479    NODE_TYPE_SELECT = 170,
480    /** Erf operator. */
481    NODE_TYPE_ERF = 178,
482    /** LogSoftmax operator. */
483    NODE_TYPE_LOG_SOFTMAX = 189,
484    /** QuantDTypeCastV2 operator. */
485    NODE_TYPE_QUANT_DTYPE_CAST_V2 = 999,
486};
487
488/**
489 * @brief Enumerates the resize methods. It must be used together with the {@link Resize} operator.
490 *
491 * @since 3.2
492 * @version 2.1
493 */
494enum ResizeMethod : byte {
495    /** Unknown. This is the default value. */
496    RESIZE_METHOD_UNKNOWN = -1,
497    /** Bilinear interpolation.
498     * For example, calculate the value of an unknown function <b>f</b> at point \f$ (x,y) \f$, where\n
499     * \f$ x_1< x < x_2, y_1< y < y_2 \f$.
500     * 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),\n
501     * and Q_{22} = (x_2, y_2) \f$.
502     * \f$f(Q_{11}), f(Q_{12}), f(Q_{21}), and f(Q_{22}) \f$ represent the values of the four points.\n
503     * The value of \f$ f(x,y) \f$ can be calculated by using the following formula:
504      \f[
505         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})
506      \f]
507
508      \f[
509         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})
510      \f]
511
512      \f[
513         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)
514      \f]
515     */
516    RESIZE_METHOD_LINEAR = 0,
517    /** Nearest neighbor interpolation.
518     * For example, calculate the value of an unknown function <b>f</b> at point \f$ (x,y) \f$, where\n
519     * \f$ x_1< x < x_2, y_1< y < y_2 \f$.
520     * The values of the four coordinate points are \f$ Q_{11} = (x_1, y_1), Q_{12} = (x1, y2),\n
521     * Q_{21} = (x_2, y_1), and Q_{22} = (x_2, y_2) \f$.
522     * Then, the value of the point closest to the point \f$(x,y) \f$ is the value of \f$ f(x,y) \f$.
523     */
524    RESIZE_METHOD_NEAREST = 1,
525    /** Bicubic interpolation.
526     * Bicubic interpolation obtains the value of a sampling point by calculating the weighted average of the\n
527     * values of 16 points around the sampling point. This parameter must be used together with <b>cubicCoeff</b>\n
528     * and <b>coordinateTransformMode</b> of {@link Resize}.
529     * When coordinateTransformMode==COORDINATE_TRANSFORM_MODE_HALF_PIXEL, <b>cubicCoeff</b> is <b>-0.5</b>.\n
530     * In other cases, cubicCoeff is <b>-0.75</b>. The weight function of the interpolation is as follows:
531      \f[
532         W(x) =
533         \begin{cases}
534            (cubicCoeff+2)|x|^3 - (cubicCoeff+3)|x|^2 +1 , &\text{if } |x| \leq 1; \cr
535            cubicCoeff|x|^3 - 5cubicCoeff|x|^2 + 8cubicCoeff|x| - 4a, &\text{if } 1 \lt |x| \leq 2; \cr
536            0, &\text{otherwise.}
537        \end{cases}
538      \f]
539     */
540    RESIZE_METHOD_CUBIC = 2
541};
542
543/**
544 * @brief Enumerates the coordinate transformation modes. Only the {@link Resize} operator uses this parameter.
545 * For example, the width coordinates are transformed, where:
546 * <b>new_i</b> is the ith coordinate of the resized tensor along the x axis.
547 * <b>old_i</b> is the coordinate of the input tensor along the x axis.
548 * <b>newWidth</b> is the length of the resized tensor along the x axis.
549 * <b>oldWidth</b> is the length of the input tensor along the x axis.
550 * <b>old_i</b> can be calculated by using the following formula:
551 *
552 * COORDINATE_TRANSFORM_MODE_ASYMMETRIC: \f$ old_i = newWidth != 0 ? new_i * oldWidth / newWidth : 0 \f$ <br>
553 * COORDINATE_TRANSFORM_MODE_ALIGN_CORNERS: \f$ old_i = newWidth != 1 ? new_i * (oldWidth - 1) / (newWidth - 1) \f$<br>
554 * COORDINATE_TRANSFORM_MODE_HALF_PIXEL: \f$ old_i = newWidth > 1 ? (new_x + 0.5) * oldWidth / newWidth - 0.5 : 0 \f$<br>
555 *
556 * @since 3.2
557 * @version 2.1
558 */
559enum CoordinateTransformMode : byte {
560    /** Scale based on the ratio without alignment. */
561    COORDINATE_TRANSFORM_MODE_ASYMMETRIC = 0,
562    /** Align the four corners of the image. */
563    COORDINATE_TRANSFORM_MODE_ALIGN_CORNERS = 1,
564    /** Align with the pixel center. */
565    COORDINATE_TRANSFORM_MODE_HALF_PIXEL = 2
566};
567
568/**
569 * @brief Enumerates the nearest neighbor interpolation types. It must be used together with the
570 * {@link Resize} operator.
571 *
572 * @since 3.2
573 * @version 2.1
574 */
575enum NearestMode : byte {
576    /** Round off. */
577    NEAREST_MODE_NORMAL = 0,
578    /** Round toward negative infinity. For example, 23.5 is rounded to 23, and −23.5 is rounded to −24. */
579    NEAREST_MODE_ROUND_HALF_DOWN = 1,
580    /** Round toward positive infinity. For example, 23.5 is rounded to 24, and −23.5 is rounded to −23. */
581    NEAREST_MODE_ROUND_HALF_UP = 2,
582    /** Round down to the nearest integer. For example, 23.5 is rounded down to 23, and −23.5 is rounded down
583      * to −24.
584      */
585    NEAREST_MODE_FLOOR = 3,
586    /** Round up to the nearest integer. For example, 23.5 is rounded up to 24, and −23.5 is rounded up to −23. */
587    NEAREST_MODE_CEIL = 4
588};
589
590/**
591 * @brief Enumerates the activation function types. Activation functions introduce nonlinearity to neural networks.\n
592 * This allows the use of neural network models in nonlinear models.
593 * If an operator in the {@link NodeAttrTypes.idl} file has <b>ActivationType</b> parameters,\n
594 * the corresponding activation function will be called after the operator calculation is complete.
595 *
596 * @since 3.2
597 * @version 2.1
598 */
599enum ActivationType : byte {
600    /** No activation function. */
601    ACTIVATION_TYPE_NO_ACTIVATION = 0,
602    /**
603     * ReLU activation function.
604     * ReLU calculates \f$ max(x_i, 0) \f$ element by element. It outputs the value directly if it is positive;\n
605     * otherwise, it outputs <b>0</b>.
606     \f[
607        \text{ReLU}(x_i) = (x_i)^+ = \max(x_i, 0),
608     \f]
609     * <b>\f$ x_i \f$</b> is the input element.
610     */
611    ACTIVATION_TYPE_RELU = 1,
612    /**
613     * Sigmoid activation function.
614     * Execute the sigmoid activation function element-wise.
615     * The sigmoid function is defined as follows:
616     \f[
617        \text{Sigmoid}(x_i) = \frac{1}{1 + \exp(-x_i)}
618     \f]
619     * <b>\f$ x_i \f$</b> is the input element.
620     */
621    ACTIVATION_TYPE_SIGMOID = 2,
622    /**
623     * ReLU6 activation function.
624     * ReLU6 is similar to ReLU. The difference is ReLU6 has an upper limit of <b>6</b>. If the input is greater than 6,\n
625     * the output is limited to <b>6</b>.
626     * The ReLU6 function is defined as follows:
627     \f[
628        \text{ReLU6}(x_i) = \min(\max(0, x_i), 6)
629     \f]
630     * <b>\f$ x_i \f$</b> is the input element.
631     */
632    ACTIVATION_TYPE_RELU6 = 3,
633    /**
634     * Exponential Linear Unit (ELU) activation function.
635     * ELU calculates the ELU for each input element.
636     * The ELU function is defined as follows:
637     \f[
638        ELU(x_{i}) =
639        \begin{cases}
640        x_i, &\text{if } x_i \geq 0; \cr
641        \alpha * (\exp(x_i) - 1), &\text{otherwise.}
642        \end{cases}
643     \f]
644     * <b>\f$ x_i \f$</b> indicates the input element, and <b>\f$ \alpha \f$</b> indicates the alpha parameter,\n
645     * which is set by {@link Activation}.
646     */
647    ACTIVATION_TYPE_ELU = 4,
648    /**
649     * LeakyReLU activation function.
650     * The LeakyReLU function is defined as follows:
651     \f[
652        \text{LeakyReLU}(x_i) =
653        \begin{cases}
654            x_i, &\text{if } x_i \geq 0; \cr
655            {\alpha} * x_i, &\text{otherwise.}
656        \end{cases}
657     \f]
658     * <b>\f$ x_i \f$</b> indicates the input element, and <b>\f$ \alpha \f$</b> indicates the alpha parameter,\n
659     * which is set by {@link Activation}.
660     */
661    ACTIVATION_TYPE_LEAKY_RELU = 5,
662    /**
663     * Activation function for calculating the absolute value.
664     * The function is defined as follows:
665     \f[
666        \text{abs}(x_i) = |x_i|
667     \f]
668     * <b>\f$ x_i \f$</b> is the input element.
669     */
670    ACTIVATION_TYPE_ABS = 6,
671    /**
672     * ReLU1 activation function.
673     * The ReLU1 function is defined as follows:
674     \f[
675        \text{ReLU1}(x_i)= \min(\max(0, x_i), 1)
676     \f]
677     * <b>\f$ x_i \f$</b> is the input element.
678     */
679    ACTIVATION_TYPE_RELU1 = 7,
680    /**
681     * SoftSign activation function.
682     * The SoftSign function is defined as follows:
683     \f[
684        \text{SoftSign}(x_i) = \frac{x_i}{1 + |x_i|}
685     \f]
686     * <b>\f$ x_i \f$</b> is the input.
687     */
688    ACTIVATION_TYPE_SOFTSIGN = 8,
689    /**
690     * Softplus activation function.
691     * Softplus is a smooth approximation to ReLU. It can be used to constrain the output to always be positive.
692     * The Softplus function is defined as follows:
693     \f[
694        \text{Softplus}(x_i) = \log(1 + \exp(x_i))
695     \f]
696     * <b>\f$ x_i \f$</b> is the input element.
697     */
698    ACTIVATION_TYPE_SOFTPLUS = 9,
699    /**
700     * Tanh activation function.
701     * The Tanh function is defined as follows:
702     \f[
703        tanh(x) = \frac{\exp(x_i) - \exp(-x_i)}{\exp(x_i) + \exp(-x_i)} = \frac{\exp(2x_i) - 1}{\exp(2x_i) + 1}
704     \f]
705     * <b>\f$ x_i \f$</b> is the input element.
706     */
707    ACTIVATION_TYPE_TANH = 10,
708    /**
709     * Scaled exponential Linear Unit (SELU) activation function.
710     * The SELU function is defined as follows:
711     \f[
712        SELU(x_{i}) =
713        scale *
714        \begin{cases}
715        x_{i}, &\text{if } x_{i} \geq 0; \cr
716        \text{alpha} * (\exp(x_i) - 1), &\text{otherwise.}
717        \end{cases}
718     \f]
719     * <b>\f$ x_i \f$</b> is the input element, and <b>\f$ \alpha \f$</b> and <b>\f$ scale \f$</b> are predefined\n
720     * constants (\f$ \alpha = 1.67326324 \f$, \f$ scale = 1.05070098 \f$).
721     */
722    ACTIVATION_TYPE_SELU = 11,
723    /**
724     * Hard Swish activation function.
725     *
726     \f[
727        \text{Hardswish}(x_{i}) = x_{i} * \frac{ReLU6(x_{i} + 3)}{6}
728     \f]
729     * <b>\f$ x_i \f$</b> is the input element.
730     */
731    ACTIVATION_TYPE_HSWISH = 12,
732    /**
733     * Hard sigmoid activation function.
734     * The hard sigmoid function is defined as follows:
735     \f[
736        \text{Hardsigmoid}(x_{i}) = max(0, min(1, \frac{x_{i} + 3}{6}))
737     \f]
738     * <b>\f$ x_i \f$</b> is the input element.
739     */
740    ACTIVATION_TYPE_HSIGMOID = 13,
741    /**
742     * ThresholdedReLU activation function.
743     * ThresholdedReLU is similar to ReLU. The <b>ThresholdedReLU</b> function is defined as follows:
744     \f[
745        \text{ThresholdedReLU}(x_i) = \min(\max(0, x_i), t)
746     \f]
747     * <b>\f$ x_i \f$</b> is the input element, and <b>\f$ t \f$</b> is the maximum value.
748     */
749    ACTIVATION_TYPE_THRESHOLDRELU = 14,
750    /**
751     * Linear activation function.
752     * The Linear function is defined as follows:
753     \f[
754        \text{Linear}(x_i) = x_i
755     \f]
756     * <b>\f$ x_i \f$</b> is the input element.
757     */
758    ACTIVATION_TYPE_LINEAR = 15,
759    /**
760     * HardTanh activation function.
761     * The HardTanh function is defined as follows:
762     \f[
763       \text{HardTanh}(x_i) =
764       \begin{cases}
765            \text{max_val} & \text{ if } x_i > \text{ max_val } \\
766            \text{min_val} & \text{ if } x_i < \text{ min_val } \\
767            x_i & \text{ otherwise } \\
768        \end{cases}
769     \f]
770     * <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>\n
771     * is the minimum value. The two parameters are set by {@link Activation}.
772     */
773    ACTIVATION_TYPE_HARD_TANH = 16,
774    /**
775     * Sign activation function.
776     * The Sign function is defined as follows:
777     \f[
778        Sign(x_i) = \begin{cases} -1, &if\ x_i < 0 \cr
779        0, &if\ x_i = 0 \cr
780        1, &if\ x_i > 0\end{cases}
781     \f]
782     * <b>\f$ x_i \f$</b> is the input.
783     */
784    ACTIVATION_TYPE_SIGN = 17,
785    /**
786     * Swish activation function.
787     * The Swish function is defined as follows:
788     \f[
789        \text{Swish}(x_i) = x_i * Sigmoid(x_i)
790     \f]
791     * <b>\f$ x_i \f$</b> is the input.
792     */
793    ACTIVATION_TYPE_SWISH = 18,
794    /**
795     * Gaussian error linear unit (GELU) activation function.
796     * The GELU function is defined as follows:
797     \f[
798        GELU(x_i) = x_i*P(X < x_i)
799     \f]
800     * <b>\f$ x_i \f$</b> is the input element, and <b>\f$ P \f$</b> is a cumulative distribution function of\n
801     * the standard Gaussian distribution.
802     * You need to use the <b>approximate</b> parameter of {@link Activation} to specify whether to use approximation.
803     */
804    ACTIVATION_TYPE_GELU = 19,
805    /** Unknown. */
806    ACTIVATION_TYPE_UNKNOWN = 20
807};
808
809/**
810 * @brief Enumerates the modes for removing dimensions. It must be used together with the {@link ReduceFusion} operator.
811 *
812 * @since 3.2
813 * @version 2.1
814 */
815enum ReduceMode : byte {
816    /** Use the average value of all elements of a dimension to replace other elements of the dimension. */
817    REDUCE_MODE_MEAN = 0,
818    /** Use the maximum value of all elements of a dimension to replace other elements of the dimension. */
819    REDUCE_MODE_MAX = 1,
820    /** Use the minimum value of all elements of a dimension to replace other elements of the dimension. */
821    REDUCE_MODE_MIN = 2,
822    /** Use the product of all elements of a dimension to replace other elements of the dimension. */
823    REDUCE_MODE_PROD = 3,
824    /** Use the sum of all elements of a dimension to replace other elements of the dimension. */
825    REDUCE_MODE_SUM = 4,
826    /** Use the sum of squares of all elements of a dimension to replace other elements of the dimension. */
827    REDUCE_MODE_SUM_SQUARE = 5,
828    /** Use the sum of absolute values of all elements of a dimension to replace other elements of the dimension. */
829    REDUCE_MODE_ASUM = 6,
830    /** Use the logical AND of all elements of a dimension to replace other elements of the dimension. */
831    REDUCE_MODE_ALL = 7,
832    /** Use the L2-Normalization of all elements of a dimension to replace other elements of the dimension. */
833    REDUCE_MODE_L2 = 8
834};
835
836/**
837 * @brief Enumerates the calculation types supported by elements. It must be used together with the\n
838 * {@link Eltwise} operator.
839 *
840 * @since 3.2
841 * @version 2.1
842 */
843enum EltwiseMode : byte {
844    /** Product of the elements of two tensors */
845    ELTWISE_MODE_PROD = 0,
846    /** Difference between the elements of two tensors */
847    ELTWISE_MODE_SUM = 1,
848    /** Maximum value of the elements of two tensors */
849    ELTWISE_MODE_MAXIMUM = 2,
850    /** Unknown type. */
851    ELTWISE_MODE_UNKNOWN = 3
852};
853
854/**
855 * @brief Enumerates the padding types. It must be used together with {@link AvgPoolFusion}, {@link AvgPoolFusion},\n
856 * {@link Conv2DFusion}, and {@link MaxPoolFusion}.
857 *
858 * @since 3.2
859 * @version 2.1
860 */
861enum PadMode : byte {
862    /**
863     * Adds 0s in the input height and width directions.
864     * If this mode is used, the padding parameter of the operator must be greater than or equal to 0.
865     */
866    PAD_MODE_PAD = 0,
867    /**
868     * The output height and width are obtained by dividing the input height and width by a stride and rounding off\n
869     * the quotient to an integer.
870     * If this mode is used, the padding parameter of the operator must be <b>0</b>.
871     */
872    PAD_MODE_SAME = 1,
873    /**
874     * Return the output of a valid calculation without padding. Pixels that do not meet the calculation requirements\n
875     * will be discarded.
876     * If this mode is used, the padding parameter of the operator must be <b>0</b>.
877     */
878    PAD_MODE_VALID = 2,
879};
880
881/**
882 * @brief Enumerates the algorithms for rounding off decimals. It must be used together with the\n
883 * {@link AvgPoolFusion} operator.
884 *
885 * @since 3.2
886 * @version 2.1
887 */
888enum RoundMode : byte {
889    /** Round down to the nearest integer. For example, 23.5 is rounded down to 23, and −23.5 is rounded down to −24. */
890    ROUND_MODE_FLOOR = 0,
891    /** Round up to the nearest integer. For example, 23.5 is rounded up to 24, and −23.5 is rounded up to −23. */
892    ROUND_MODE_CEIL = 1
893};
894
895/**
896 * @brief Enumerates the padding modes. It must be used together with the {@link PadFusion} operator.
897 *
898 * 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$,\n
899 * the effect is as follows: <br>
900 * If paddingMode==PADDING_MODE_CONSTANT and constantValue = 0, the output is as follows:
901 *
902      \f$[[0. 0. 0. 0. 0. 0. 0.],\\
903          [0. 0. 0. 0. 0. 0. 0.],\\
904          [0. 0. 1. 2. 3. 0. 0.],\\
905          [0. 0. 4. 5. 6. 0. 0.],\\
906          [0. 0. 7. 8. 9. 0. 0.],\\
907          [0. 0. 0. 0. 0. 0. 0.],\\
908          [0. 0. 0. 0. 0. 0. 0.]]\\ \f$
909 *
910 * If paddingMode==PADDING_MODE_REFLECT, the output is as follows:
911 *
912      \f$[[9. 8. 7. 8. 9. 8. 7.],\\
913          [6. 5. 4. 5. 6. 5. 4.],\\
914          [3. 2. 1. 2. 3. 2. 1.],\\
915          [6. 5. 4. 5. 6. 5. 4.],\\
916          [9. 8. 7. 8. 9. 8. 7.],\\
917          [6. 5. 4. 5. 6. 5. 4.],\\
918          [3. 2. 1. 2. 3. 2. 1.]]\\ \f$
919 *
920 * If paddingMode==PADDING_MODE_SYMMETRIC, the output is as follows:
921 *
922      \f$[[5. 4. 4. 5. 6. 6. 5.],\\
923          [2. 1. 1. 2. 3. 3. 2.],\\
924          [2. 1. 1. 2. 3. 3. 2.],\\
925          [5. 4. 4. 5. 6. 6. 5.],\\
926          [8. 7. 7. 8. 9. 9. 8.],\\
927          [8. 7. 7. 8. 9. 9. 8.],\\
928          [5. 4. 4. 5. 6. 6. 5.]]\\ \f$
929 *
930 * @since 3.2
931 * @version 2.1
932 */
933enum PaddingMode : byte {
934    /** Constant (0 by default) padding. */
935    PADDING_MODE_CONSTANT = 0,
936    /** Reflection padding, which uses the content next to the input data to pad the values directly next to it. */
937    PADDING_MODE_REFLECT = 1,
938    /** Symmetric padding, which is similar to {@link PADDING_MODE_REFLECT}. Symmetric padding makes a copy of the input. */
939    PADDING_MODE_SYMMETRIC = 2,
940    /** Reserved. */
941    PADDING_MODE_RESERVED = 3
942};
943
944/**
945 * @brief Dedicated error codes defined by NNRt. They are used as the return values of HDIs.
946 *
947 * @since 4.0
948 * @version 2.1
949 */
950enum NNRT_ReturnCode : unsigned int {
951    /** Success. */
952    NNRT_SUCCESS = 0,
953    /** Failed. */
954    NNRT_FAILED = 1,
955    /** Null pointer. */
956    NNRT_NULL_PTR = 2,
957    /** Invalid parameter. */
958    NNRT_INVALID_PARAMETER = 3,
959    /** Memory error. */
960    NNRT_MEMORY_ERROR = 4,
961    /** Insufficient memory. */
962    NNRT_OUT_OF_MEMORY = 5,
963    /** Forbidden operation. */
964    NNRT_OPERATION_FORBIDDEN = 6,
965    /** Invalid file. */
966    NNRT_INVALID_FILE = 7,
967    /** Invalid path. */
968    NNRT_INVALID_PATH = 8,
969    /** Insufficient cache. */
970    NNRT_INSUFFICIENT_BUFFER = 9,
971    /** No change. */
972    NNRT_NO_CHANGE = 10,
973    /** Not supported. */
974    NNRT_NOT_SUPPORT = 11,
975    /** Service error. */
976    NNRT_SERVICE_ERROR = 12,
977    /** Device error. */
978    NNRT_DEVICE_ERROR = 13,
979    /** Device busy. */
980    NNRT_DEVICE_BUSY = 14,
981    /** Operation canceled. */
982    NNRT_CANCELLED = 15,
983    /** Access denied. */
984    NNRT_PERMISSION_DENIED = 16,
985    /** Timeout. */
986    NNRT_TIME_OUT = 17,
987    /** Invalid tensor. */
988    NNRT_INVALID_TENSOR = 18,
989    /** Invalid node. */
990    NNRT_INVALID_NODE = 19,
991    /** Invalid input. */
992    NNRT_INVALID_INPUT = 20,
993    /** Invalid output. */
994    NNRT_INVALID_OUTPUT = 21,
995    /** Invalid data type. */
996    NNRT_INVALID_DATATYPE = 22,
997    /** Invalid data layout. */
998    NNRT_INVALID_FORMAT = 23,
999    /** Invalid tensor name. */
1000    NNRT_INVALID_TENSOR_NAME = 24,
1001    /** Invalid shape. */
1002    NNRT_INVALID_SHAPE = 25,
1003    /** Dimension range exceeded. */
1004    NNRT_OUT_OF_DIMENTION_RANGES = 26,
1005    /** Invalid cache. */
1006    NNRT_INVALID_BUFFER = 27,
1007    /** Invalid cache size. */
1008    NNRT_INVALID_BUFFER_SIZE = 28,
1009    /** Invalid performance mode. */
1010    NNRT_INVALID_PERFORMANCE_MODE = 29,
1011    /** Invalid priority. */
1012    NNRT_INVALID_PRIORITY = 30,
1013    /** Invalid model. */
1014    NNRT_INVALID_MODEL = 31,
1015    /** Invalid model cache. */
1016    NNRT_INVALID_MODEL_CACHE = 32,
1017    /** Operator not supported. */
1018    NNRT_UNSUPPORTED_OP = 33
1019};
1020/** @} */
1021