• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# NeuralNeworkRuntime
2
3
4## Overview
5
6Provides APIs of Neural Network Runtime for accelerating the model inference.
7
8Provides APIs for accelerating the Neural Network Runtime model inference.
9
10\@Syscap SystemCapability.Ai.NeuralNetworkRuntime
11
12**Since:**
139
14
15
16## Summary
17
18
19### Files
20
21| Name | Description |
22| -------- | -------- |
23| [neural_network_runtime.h](neural__network__runtime_8h.md) | Defines the Neural Network Runtime APIs. The AI inference framework uses the Native APIs provided by Neural Network Runtime to construct and compile models and perform inference and computing on acceleration hardware. Note: Currently, the APIs of Neural Network Runtime do not support multi-thread calling. <br>File to Include: <neural_network_runtime/neural_network_runtime.h> |
24| [neural_network_runtime_type.h](neural__network__runtime__type_8h.md) | Defines the structure and enumeration for Neural Network Runtime. <br>File to Include: <neural_network_runtime/neural_network_runtime_type.h>  |
25
26
27### Structs
28
29| Name | Description |
30| -------- | -------- |
31| [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) | This structure is used to store a 32-bit unsigned integer array.  |
32| [OH_NN_QuantParam](_o_h___n_n___quant_param.md) | Quantization information.  |
33| [OH_NN_Tensor](_o_h___n_n___tensor.md) | Defines the tensor structure.  |
34| [OH_NN_Memory](_o_h___n_n___memory.md) | Defines the memory structure.  |
35
36
37### Types
38
39| Name | Description |
40| -------- | -------- |
41| [OH_NNModel](#oh_nnmodel) | Defines the handles of models for Neural Network Runtime.  |
42| [OH_NNCompilation](#oh_nncompilation) | Defines the compiler handle for Neural Network Runtime.  |
43| [OH_NNExecutor](#oh_nnexecutor) | Defines the executor handle for Neural Network Runtime.  |
44| [OH_NN_UInt32Array](#oh_nn_uint32array) | This structure is used to store a 32-bit unsigned integer array.  |
45| [OH_NN_QuantParam](#oh_nn_quantparam) | Quantization information.  |
46| [OH_NN_Tensor](#oh_nn_tensor) | Defines the tensor structure.  |
47| [OH_NN_Memory](#oh_nn_memory) | Defines the memory structure.  |
48
49
50### Enums
51
52| Name | Description |
53| -------- | -------- |
54| [OH_NN_PerformanceMode](#oh_nn_performancemode) {<br/>OH_NN_PERFORMANCE_NONE = 0, OH_NN_PERFORMANCE_LOW = 1, OH_NN_PERFORMANCE_MEDIUM = 2, OH_NN_PERFORMANCE_HIGH = 3,<br/>OH_NN_PERFORMANCE_EXTREME = 4<br/>} | Defines the hardware performance mode.  |
55| [OH_NN_Priority](#oh_nn_priority) { OH_NN_PRIORITY_NONE = 0, OH_NN_PRIORITY_LOW = 1, OH_NN_PRIORITY_MEDIUM = 2, OH_NN_PRIORITY_HIGH = 3 } | Defines the model inference task priority.  |
56| [OH_NN_ReturnCode](#oh_nn_returncode) {<br/>OH_NN_SUCCESS = 0, OH_NN_FAILED = 1, OH_NN_INVALID_PARAMETER = 2, OH_NN_MEMORY_ERROR = 3,<br/>OH_NN_OPERATION_FORBIDDEN = 4, OH_NN_NULL_PTR = 5, OH_NN_INVALID_FILE = 6, OH_NN_UNAVALIDABLE_DEVICE = 7,<br/>OH_NN_INVALID_PATH = 8<br/>} | Defines error codes for Neural Network Runtime.  |
57| [OH_NN_FuseType](#oh_nn_fusetype) : int8_t { OH_NN_FUSED_NONE = 0, OH_NN_FUSED_RELU = 1, OH_NN_FUSED_RELU6 = 2 } | Defines activation function types in the fusion operator for Neural Network Runtime.  |
58| [OH_NN_Format](#oh_nn_format) { OH_NN_FORMAT_NONE = 0, OH_NN_FORMAT_NCHW = 1, OH_NN_FORMAT_NHWC = 2 } | Defines the layout type of tensor data.  |
59| [OH_NN_DeviceType](#oh_nn_devicetype) { OH_NN_OTHERS = 0, OH_NN_CPU = 1, OH_NN_GPU = 2, OH_NN_ACCELERATOR = 3 } | Defines device types supported by Neural Network Runtime.  |
60| [OH_NN_DataType](#oh_nn_datatype) {<br/>OH_NN_UNKNOWN = 0, OH_NN_BOOL = 1, OH_NN_INT8 = 2, OH_NN_INT16 = 3,<br/>OH_NN_INT32 = 4, OH_NN_INT64 = 5, OH_NN_UINT8 = 6, OH_NN_UINT16 = 7,<br/>OH_NN_UINT32 = 8, OH_NN_UINT64 = 9, OH_NN_FLOAT16 = 10, OH_NN_FLOAT32 = 11,<br/>OH_NN_FLOAT64 = 12<br/>} | Defines tensor data types supported by Neural Network Runtime.  |
61| [OH_NN_OperationType](#oh_nn_operationtype) {<br/>OH_NN_OPS_ADD = 1, OH_NN_OPS_AVG_POOL = 2, OH_NN_OPS_BATCH_NORM = 3, OH_NN_OPS_BATCH_TO_SPACE_ND = 4,<br/>OH_NN_OPS_BIAS_ADD = 5, OH_NN_OPS_CAST = 6, OH_NN_OPS_CONCAT = 7, OH_NN_OPS_CONV2D = 8,<br/>OH_NN_OPS_CONV2D_TRANSPOSE = 9, OH_NN_OPS_DEPTHWISE_CONV2D_NATIVE = 10, OH_NN_OPS_DIV = 11, OH_NN_OPS_ELTWISE = 12,<br/>OH_NN_OPS_EXPAND_DIMS = 13, OH_NN_OPS_FILL = 14, OH_NN_OPS_FULL_CONNECTION = 15, OH_NN_OPS_GATHER = 16,<br/>OH_NN_OPS_HSWISH = 17, OH_NN_OPS_LESS_EQUAL = 18, OH_NN_OPS_MATMUL = 19, OH_NN_OPS_MAXIMUM = 20,<br/>OH_NN_OPS_MAX_POOL = 21, OH_NN_OPS_MUL = 22, OH_NN_OPS_ONE_HOT = 23, OH_NN_OPS_PAD = 24,<br/>OH_NN_OPS_POW = 25, OH_NN_OPS_SCALE = 26, OH_NN_OPS_SHAPE = 27, OH_NN_OPS_SIGMOID = 28,<br/>OH_NN_OPS_SLICE = 29, OH_NN_OPS_SOFTMAX = 30, OH_NN_OPS_SPACE_TO_BATCH_ND = 31, OH_NN_OPS_SPLIT = 32,<br/>OH_NN_OPS_SQRT = 33, OH_NN_OPS_SQUARED_DIFFERENCE = 34, OH_NN_OPS_SQUEEZE = 35, OH_NN_OPS_STACK = 36,<br/>OH_NN_OPS_STRIDED_SLICE = 37, OH_NN_OPS_SUB = 38, OH_NN_OPS_TANH = 39, OH_NN_OPS_TILE = 40,<br/>OH_NN_OPS_TRANSPOSE = 41, OH_NN_OPS_REDUCE_MEAN = 42, OH_NN_OPS_RESIZE_BILINEAR = 43, OH_NN_OPS_RSQRT = 44,<br/>OH_NN_OPS_RESHAPE = 45, OH_NN_OPS_PRELU = 46, OH_NN_OPS_RELU = 47, OH_NN_OPS_RELU6 = 48,<br/>OH_NN_OPS_LAYER_NORM = 49, OH_NN_OPS_REDUCE_PROD = 50, OH_NN_OPS_REDUCE_ALL = 51, OH_NN_OPS_QUANT_DTYPE_CAST = 52,<br/>OH_NN_OPS_TOP_K = 53, OH_NN_OPS_ARG_MAX = 54, OH_NN_OPS_UNSQUEEZE = 55, OH_NN_OPS_GELU = 56<br/>} | Defines operator types supported by Neural Network Runtime.  |
62| [OH_NN_TensorType](#oh_nn_tensortype) {<br/>OH_NN_TENSOR = 0, OH_NN_ADD_ACTIVATIONTYPE = 1, OH_NN_AVG_POOL_KERNEL_SIZE = 2, OH_NN_AVG_POOL_STRIDE = 3,<br/>OH_NN_AVG_POOL_PAD_MODE = 4, OH_NN_AVG_POOL_PAD = 5, OH_NN_AVG_POOL_ACTIVATION_TYPE = 6, OH_NN_BATCH_NORM_EPSILON = 7,<br/>OH_NN_BATCH_TO_SPACE_ND_BLOCKSIZE = 8, OH_NN_BATCH_TO_SPACE_ND_CROPS = 9, OH_NN_CONCAT_AXIS = 10, OH_NN_CONV2D_STRIDES = 11,<br/>OH_NN_CONV2D_PAD = 12, OH_NN_CONV2D_DILATION = 13, OH_NN_CONV2D_PAD_MODE = 14, OH_NN_CONV2D_ACTIVATION_TYPE = 15,<br/>OH_NN_CONV2D_GROUP = 16, OH_NN_CONV2D_TRANSPOSE_STRIDES = 17, OH_NN_CONV2D_TRANSPOSE_PAD = 18, OH_NN_CONV2D_TRANSPOSE_DILATION = 19,<br/>OH_NN_CONV2D_TRANSPOSE_OUTPUT_PADDINGS = 20, OH_NN_CONV2D_TRANSPOSE_PAD_MODE = 21, OH_NN_CONV2D_TRANSPOSE_ACTIVATION_TYPE = 22, OH_NN_CONV2D_TRANSPOSE_GROUP = 23,<br/>OH_NN_DEPTHWISE_CONV2D_NATIVE_STRIDES = 24, OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD = 25, OH_NN_DEPTHWISE_CONV2D_NATIVE_DILATION = 26, OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD_MODE = 27,<br/>OH_NN_DEPTHWISE_CONV2D_NATIVE_ACTIVATION_TYPE = 28, OH_NN_DIV_ACTIVATIONTYPE = 29, OH_NN_ELTWISE_MODE = 30, OH_NN_FULL_CONNECTION_AXIS = 31,<br/>OH_NN_FULL_CONNECTION_ACTIVATIONTYPE = 32, OH_NN_MATMUL_TRANSPOSE_A = 33, OH_NN_MATMUL_TRANSPOSE_B = 34, OH_NN_MATMUL_ACTIVATION_TYPE = 35,<br/>OH_NN_MAX_POOL_KERNEL_SIZE = 36, OH_NN_MAX_POOL_STRIDE = 37, OH_NN_MAX_POOL_PAD_MODE = 38, OH_NN_MAX_POOL_PAD = 39,<br/>OH_NN_MAX_POOL_ACTIVATION_TYPE = 40, OH_NN_MUL_ACTIVATION_TYPE = 41, OH_NN_ONE_HOT_AXIS = 42, OH_NN_PAD_CONSTANT_VALUE = 43,<br/>OH_NN_SCALE_ACTIVATIONTYPE = 44, OH_NN_SCALE_AXIS = 45, OH_NN_SOFTMAX_AXIS = 46, OH_NN_SPACE_TO_BATCH_ND_BLOCK_SHAPE = 47,<br/>OH_NN_SPACE_TO_BATCH_ND_PADDINGS = 48, OH_NN_SPLIT_AXIS = 49, OH_NN_SPLIT_OUTPUT_NUM = 50, OH_NN_SPLIT_SIZE_SPLITS = 51,<br/>OH_NN_SQUEEZE_AXIS = 52, OH_NN_STACK_AXIS = 53, OH_NN_STRIDED_SLICE_BEGIN_MASK = 54, OH_NN_STRIDED_SLICE_END_MASK = 55,<br/>OH_NN_STRIDED_SLICE_ELLIPSIS_MASK = 56, OH_NN_STRIDED_SLICE_NEW_AXIS_MASK = 57, OH_NN_STRIDED_SLICE_SHRINK_AXIS_MASK = 58, OH_NN_SUB_ACTIVATIONTYPE = 59,<br/>OH_NN_REDUCE_MEAN_KEEP_DIMS = 60, OH_NN_RESIZE_BILINEAR_NEW_HEIGHT = 61, OH_NN_RESIZE_BILINEAR_NEW_WIDTH = 62, OH_NN_RESIZE_BILINEAR_PRESERVE_ASPECT_RATIO = 63,<br/>OH_NN_RESIZE_BILINEAR_COORDINATE_TRANSFORM_MODE = 64, OH_NN_RESIZE_BILINEAR_EXCLUDE_OUTSIDE = 65, OH_NN_LAYER_NORM_BEGIN_NORM_AXIS = 66, OH_NN_LAYER_NORM_EPSILON = 67,<br/>OH_NN_LAYER_NORM_BEGIN_PARAM_AXIS = 68, OH_NN_LAYER_NORM_ELEMENTWISE_AFFINE = 69, OH_NN_REDUCE_PROD_KEEP_DIMS = 70, OH_NN_REDUCE_ALL_KEEP_DIMS = 71,<br/>OH_NN_QUANT_DTYPE_CAST_SRC_T = 72, OH_NN_QUANT_DTYPE_CAST_DST_T = 73, OH_NN_TOP_K_SORTED = 74, OH_NN_ARG_MAX_AXIS = 75,<br/>OH_NN_ARG_MAX_KEEPDIMS = 76, OH_NN_UNSQUEEZE_AXIS = 77<br/>} | Enumerates the tensor data types.  |
63
64
65### Functions
66
67| Name | Description |
68| -------- | -------- |
69| [OH_NNModel_Construct](#oh_nnmodel_construct) (void) | Creates a model instance of the [OH_NNModel](#oh_nnmodel) type and uses other APIs provided by OH_NNModel to construct the model instance.  |
70| [OH_NNModel_AddTensor](#oh_nnmodel_addtensor) ([OH_NNModel](#oh_nnmodel) \*model, const [OH_NN_Tensor](_o_h___n_n___tensor.md) \*tensor) | Adds a tensor to a model instance.  |
71| [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata) ([OH_NNModel](#oh_nnmodel) \*model, uint32_t index, const void \*dataBuffer, size_t length) | Sets the tensor value.  |
72| [OH_NNModel_AddOperation](#oh_nnmodel_addoperation) ([OH_NNModel](#oh_nnmodel) \*model, [OH_NN_OperationType](#oh_nn_operationtype) op, const [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) \*paramIndices, const [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) \*inputIndices, const [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) \*outputIndices) | Adds an operator to a model instance.  |
73| [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) ([OH_NNModel](#oh_nnmodel) \*model, const [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) \*inputIndices, const [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) \*outputIndices) | Specifies the inputs and outputs of a model.  |
74| [OH_NNModel_Finish](#oh_nnmodel_finish) ([OH_NNModel](#oh_nnmodel) \*model) | Completes model composition.  |
75| [OH_NNModel_Destroy](#oh_nnmodel_destroy) ([OH_NNModel](#oh_nnmodel) \*\*model) | Releases a model instance.  |
76| [OH_NNModel_GetAvailableOperations](#oh_nnmodel_getavailableoperations) ([OH_NNModel](#oh_nnmodel) \*model, size_t deviceID, const bool \*\*isSupported, uint32_t \*opCount) | Queries whether the device supports operators in the model. The support status is indicated by the Boolean value.  |
77| [OH_NNCompilation_Construct](#oh_nncompilation_construct) (const [OH_NNModel](#oh_nnmodel) \*model) | Creates a compilation instance of the [OH_NNCompilation](#oh_nncompilation) type.  |
78| [OH_NNCompilation_SetDevice](#oh_nncompilation_setdevice) ([OH_NNCompilation](#oh_nncompilation) \*compilation, size_t deviceID) | Specifies the device for model compilation and computing.  |
79| [OH_NNCompilation_SetCache](#oh_nncompilation_setcache) ([OH_NNCompilation](#oh_nncompilation) \*compilation, const char \*cachePath, uint32_t version) | Set the cache directory and version of the compiled model.  |
80| [OH_NNCompilation_SetPerformanceMode](#oh_nncompilation_setperformancemode) ([OH_NNCompilation](#oh_nncompilation) \*compilation, [OH_NN_PerformanceMode](#oh_nn_performancemode) performanceMode) | Sets the performance mode for model computing.  |
81| [OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority) ([OH_NNCompilation](#oh_nncompilation) \*compilation, [OH_NN_Priority](#oh_nn_priority) priority) | Sets the model computing priority.  |
82| [OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16) ([OH_NNCompilation](#oh_nncompilation) \*compilation, bool enableFloat16) | Enables float16 for computing.  |
83| [OH_NNCompilation_Build](#oh_nncompilation_build) ([OH_NNCompilation](#oh_nncompilation) \*compilation) | Compiles a model.  |
84| [OH_NNCompilation_Destroy](#oh_nncompilation_destroy) ([OH_NNCompilation](#oh_nncompilation) \*\*compilation) | Releases the **Compilation** object.  |
85| [OH_NNExecutor_Construct](#oh_nnexecutor_construct) ([OH_NNCompilation](#oh_nncompilation) \*compilation) | [OH_NNExecutor](#oh_nnexecutor) \*<br/>Creates an executor instance of the [OH_NNExecutor](#oh_nnexecutor) type.  |
86| [OH_NNExecutor_SetInput](#oh_nnexecutor_setinput) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, const [OH_NN_Tensor](_o_h___n_n___tensor.md) \*tensor, const void \*dataBuffer, size_t length) | Sets the single input data for a model.  |
87| [OH_NNExecutor_SetOutput](#oh_nnexecutor_setoutput) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, void \*dataBuffer, size_t length) | Sets the buffer for a single output of a model.  |
88| [OH_NNExecutor_GetOutputShape](#oh_nnexecutor_getoutputshape) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, int32_t \*\*shape, uint32_t \*shapeLength) | Obtains the dimension information about the output tensor.  |
89| [OH_NNExecutor_Run](#oh_nnexecutor_run) ([OH_NNExecutor](#oh_nnexecutor) \*executor) | Performs inference.  |
90| [OH_NNExecutor_AllocateInputMemory](#oh_nnexecutor_allocateinputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, size_t length) | Allocates shared memory to a single input on a device.  |
91| [OH_NNExecutor_AllocateOutputMemory](#oh_nnexecutor_allocateoutputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, size_t length) | Allocates shared memory to a single output on a device.  |
92| [OH_NNExecutor_DestroyInputMemory](#oh_nnexecutor_destroyinputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, [OH_NN_Memory](_o_h___n_n___memory.md) \*\*memory) | Releases the input memory to which the [OH_NN_Memory](_o_h___n_n___memory.md) instance points.  |
93| [OH_NNExecutor_DestroyOutputMemory](#oh_nnexecutor_destroyoutputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, [OH_NN_Memory](_o_h___n_n___memory.md) \*\*memory) | Releases the output memory to which the [OH_NN_Memory](_o_h___n_n___memory.md) instance points.  |
94| [OH_NNExecutor_SetInputWithMemory](#oh_nnexecutor_setinputwithmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, const [OH_NN_Tensor](_o_h___n_n___tensor.md) \*tensor, const [OH_NN_Memory](_o_h___n_n___memory.md) \*memory) | Specifies the hardware shared memory pointed to by the [OH_NN_Memory](_o_h___n_n___memory.md) instance as the shared memory used by a single input.  |
95| [OH_NNExecutor_SetOutputWithMemory](#oh_nnexecutor_setoutputwithmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, const [OH_NN_Memory](_o_h___n_n___memory.md) \*memory) | Specifies the hardware shared memory pointed to by the [OH_NN_Memory](_o_h___n_n___memory.md) instance as the shared memory used by a single output.  |
96| [OH_NNExecutor_Destroy](#oh_nnexecutor_destroy) ([OH_NNExecutor](#oh_nnexecutor) \*\*executor) | Destroys an executor instance to release the memory occupied by the executor.  |
97| [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid) (const size_t \*\*allDevicesID, uint32_t \*deviceCount) | Obtains the ID of the device connected to Neural Network Runtime.  |
98| [OH_NNDevice_GetName](#oh_nndevice_getname) (size_t deviceID, const char \*\*name) | Obtains the name of the specified device.  |
99| [OH_NNDevice_GetType](#oh_nndevice_gettype) (size_t deviceID, [OH_NN_DeviceType](#oh_nn_devicetype) \*deviceType) | Obtains the type information of the specified device.  |
100
101
102## Type Description
103
104
105### OH_NN_Memory
106
107
108```
109typedef struct OH_NN_MemoryOH_NN_Memory
110```
111**Description**<br>
112Defines the memory structure.
113
114
115### OH_NN_QuantParam
116
117
118```
119typedef struct OH_NN_QuantParamOH_NN_QuantParam
120```
121**Description**<br>
122Quantization information.
123
124In quantization scenarios, the 32-bit floating-point data type is quantized into the fixed-point data type according to the following formula:
125
126s and z are quantization parameters, which are stored by **scale** and **zeroPoint** in [OH_NN_QuantParam](_o_h___n_n___quant_param.md). r is a floating point number, q is the quantization result, q_min is the lower bound of the quantization result, and q_max is an upper bound of a quantization result. The calculation method is as follows:
127
128The clamp function is defined as follows:
129
130
131### OH_NN_Tensor
132
133
134```
135typedef struct OH_NN_TensorOH_NN_Tensor
136```
137**Description**<br>
138Defines the tensor structure.
139
140It is usually used to construct data nodes and operator parameters in a model graph. When constructing a tensor, you need to specify the data type, number of dimensions, dimension information, and quantization information.
141
142
143### OH_NN_UInt32Array
144
145
146```
147typedef struct OH_NN_UInt32ArrayOH_NN_UInt32Array
148```
149**Description**<br>
150This structure is used to store a 32-bit unsigned integer array.
151
152
153### OH_NNCompilation
154
155
156```
157typedef struct OH_NNCompilationOH_NNCompilation
158```
159**Description**<br>
160Defines the compiler handle for Neural Network Runtime.
161
162
163### OH_NNExecutor
164
165
166```
167typedef struct OH_NNExecutorOH_NNExecutor
168```
169**Description**<br>
170Defines the executor handle for Neural Network Runtime.
171
172
173### OH_NNModel
174
175
176```
177typedef struct OH_NNModelOH_NNModel
178```
179**Description**<br>
180Defines the handles of models for Neural Network Runtime.
181
182
183## Enum Description
184
185
186### OH_NN_DataType
187
188
189```
190enum OH_NN_DataType
191```
192**Description**<br>
193Defines tensor data types supported by Neural Network Runtime.
194
195| Name | Description |
196| -------- | -------- |
197| OH_NN_UNKNOWN  | Unknown type |
198| OH_NN_BOOL  | bool |
199| OH_NN_INT8  | int8 |
200| OH_NN_INT16  | int16 |
201| OH_NN_INT32  | int32 |
202| OH_NN_INT64  | int64 |
203| OH_NN_UINT8  | uint8 |
204| OH_NN_UINT16  | uint16 |
205| OH_NN_UINT32  | uint32 |
206| OH_NN_UINT64  | uint64 |
207| OH_NN_FLOAT16  | float16 |
208| OH_NN_FLOAT32  | float32 |
209| OH_NN_FLOAT64  | float64 |
210
211
212### OH_NN_DeviceType
213
214
215```
216enum OH_NN_DeviceType
217```
218**Description**<br>
219Defines device types supported by Neural Network Runtime.
220
221| Name | Description |
222| -------- | -------- |
223| OH_NN_OTHERS  | Devices that are not CPU, GPU, or dedicated accelerator |
224| OH_NN_CPU  | CPU device |
225| OH_NN_GPU  | GPU device |
226| OH_NN_ACCELERATOR  | Dedicated hardware accelerator |
227
228
229### OH_NN_Format
230
231
232```
233enum OH_NN_Format
234```
235**Description**<br>
236Defines the layout type of tensor data.
237
238| Name | Description |
239| -------- | -------- |
240| OH_NN_FORMAT_NONE  | The tensor does not have a specific layout type (such as scalar or vector). |
241| OH_NN_FORMAT_NCHW  | The tensor arranges data in NCHW format. |
242| OH_NN_FORMAT_NHWC  | The tensor arranges data in NHWC format. |
243
244
245### OH_NN_FuseType
246
247
248```
249enum OH_NN_FuseType : int8_t
250```
251**Description**<br>
252Defines activation function types in the fusion operator for Neural Network Runtime.
253
254| Name | Description |
255| -------- | -------- |
256| OH_NN_FUSED_NONE  | The fusion activation function is not specified. |
257| OH_NN_FUSED_RELU  | Fusion relu activation function |
258| OH_NN_FUSED_RELU6  | Fusion relu6 activation function |
259
260
261### OH_NN_OperationType
262
263
264```
265enum OH_NN_OperationType
266```
267**Description**<br>
268Defines operator types supported by Neural Network Runtime.
269
270| Name | Description |
271| -------- | -------- |
272| OH_NN_OPS_ADD  | Returns the tensor of the sum of the elements corresponding to two input tensors.<br/>Inputs:<br/>- **input1**: first input tensor, of the Boolean or number type.<br/>- **input2**: second input tensor, whose data type must be the same as that of the first tensor.<br/>Parameters:<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: sum of **input1** and **input2**. The data shape is the same as that of the input after broadcasting, and the data type is the same as that of the input with a higher precision.  |
273| OH_NN_OPS_AVG_POOL  | Apply 2D average pooling to the input tensor, which now must be in NHWC format. The int8 quantization input is supported.<br/>If the input contains the **padMode** parameter:<br/>Inputs:<br/>- **input**: tensor.<br/>Parameters:<br/>- **kernelSize** indicates the kernel size used to obtain the average value. It is an int array [kernel_height, kernel_width]. The first number indicates the kernel height, and the second number indicates the kernel width.<br/>- **strides** indicates the distance of kernel moving. The value is an int array [stride_height, stride_width]. The first number indicates the moving step in height, and the second number indicates the moving step in width.<br/>- **padMode**: padding mode, which is optional. The value is of the int type and can be **0** (same) or **1** (valid). The nearest neighbor value is used for padding. **0** (same): The height and width of the output are the same as those of the input. The total padding quantity is calculated horizontally and vertically and evenly distributed to the top, bottom, left, and right if possible. Otherwise, the last additional padding will be completed from the bottom and right. **1** (valid): The possible maximum height and width of the output will be returned in case of no padding. Excessive pixels will be discarded.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>If the input contains the **padList** parameter:<br/>Inputs:<br/>- **input**: tensor.<br/>Parameters:<br/>- **kernelSize** indicates the kernel size used to obtain the average value. It is an int array [kernel_height, kernel_width]. The first number indicates the kernel height, and the second number indicates the kernel width.<br/>- **strides** indicates the distance of kernel moving. The value is an int array [stride_height, stride_width]. The first number indicates the moving step in height, and the second number indicates the moving step in width.<br/>- **padList**: padding around **input**. It is an int array [top, bottom, left, right], and the nearest neighbor values are used for padding.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: average pooling result of the input.  |
274| OH_NN_OPS_BATCH_NORM  | Batch normalization is performed on a tensor to scale and shift tensor elements, relieving potential covariate shift in a batch of data.<br/>Inputs:<br/>- **input**: n-dimensional tensor of shape [N, ..., C]. The nth dimension is the number of channels.<br/>- **scale**: 1D tensor of the scaling factor used to scale the first normalized tensor.<br/>- **offset**: 1D tensor used to move to the first normalized tensor.<br/>- **mean**: 1D tensor of the overall mean value. It is used only for inference. In case of training, this parameter must be left empty.<br/>- **variance**: 1D tensor used for the overall variance. It is used only for inference. In case of training, this parameter must be left empty.<br/>Parameters:<br/>- **epsilon**: fixed small additional value.<br/>Outputs:<br/>- **output**: n-dimensional output tensor whose shape and data type are the same as those of the input.  |
275| OH_NN_OPS_BATCH_TO_SPACE_ND  | Divides the batch dimension of a 4D tensor into small blocks by **block_shape**, and interleaves these blocks back into the spatial dimension.<br/>Parameters:<br/>- **input**: input tensor. The dimension will be divided into small blocks, and these blocks will be interleaved into the spatial dimension.<br/>Outputs:<br/>- **blockSize**: size of each block to be interleaved into the spatial dimension. The value is an array [height_block, width_block].<br/>- **crops**: elements truncated from the spatial dimension of the output. The value is a 2D array [[crop0_start, crop0_end], [crop1_start, crop1_end]] with the shape of (2, 2).<br/>Outputs:<br/>- **output**. Assume that the shape of **input** is (n,h,w,c) and the shape of **output** is (n',h',w',c'): n' = n / (block_shape[0] \* block_shape[1]) h' = h \* block_shape[0] - crops[0][0] - crops[0][1] w' = w \* block_shape[1] - crops[1][0] - crops[1][1] c'= c  |
276| OH_NN_OPS_BIAS_ADD  | Offsets the data in each dimension of the input tensor.<br/>Inputs:<br/>- **input**: input tensor, which can have two to five dimensions.<br/>- **bias**: offset of the number of input dimensions.<br/>Outputs:<br/>- **output**: sum of the input tensor and the bias in each dimension.  |
277| OH_NN_OPS_CAST  | Converts the data type in the input tensor.<br/>Inputs:<br/>- **input**: input tensor.<br/>- **type**: converted data type.<br/>Outputs:<br/>- **output**: converted tensor.  |
278| OH_NN_OPS_CONCAT  | Connects tensors in a specified dimension.<br/>Inputs:<br/>- **input**: N input tensors.<br/>Parameters:<br/>- **axis**: dimension for connecting tensors.<br/>Outputs:<br/>- **output**: result of connecting N tensors along the axis.  |
279| OH_NN_OPS_CONV2D  | 2D convolutional layer.<br/>If the input contains the **padMode** parameter:<br/>Inputs:<br/>- **input**: input tensor.<br/>- **weight**: convolution weight in [outChannel, kernelHeight, kernelWidth, inChannel/group] format. The value of **inChannel** must be exactly divided by the value of **group**.<br/>- **bias**: bias of the convolution. It is an array with a length of **[outChannel]**. In quantization scenarios, the **bias** parameter does not require quantization parameters. The quantization version requires data input of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br/>Parameters:<br/>- **stride**: movement stride of the convolution kernel in height and width. It is an int array [strideHeight, strideWidth].<br/>- **dilation**: dilation size of the convolution kernel in height and width. It is an int array [dilationHeight, dilationWidth]. The value must be greater than or equal to **1** and cannot exceed the height and width of **input**.<br/>- **padMode**: padding mode of **input**. The value is of the int type and can be **0** (same) or **1** (valid). **0** (same): The height and width of the output are the same as those of the input. The total padding quantity is calculated horizontally and vertically and evenly distributed to the top, bottom, left, and right if possible. Otherwise, the last additional padding will be completed from the bottom and right.<br/>  **1** (valid): The possible maximum height and width of the output will be returned in case of no padding. The excessive pixels will be discarded.<br/>- **group**: number of groups in which the input is divided by **in_channel**. The value is of the int type. If **group** is **1**, it is a conventional convolution. If **group** is greater than **1** and less than or equal to **in_channel**, it is a group convolution.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>If the input contains the **padList** parameter:<br/>Inputs:<br/>- **input**: input tensor.<br/>- **weight**: convolution weight in [outChannel, kernelHeight, kernelWidth, inChannel/group] format. The value of **inChannel** must be exactly divided by the value of **group**.<br/>- **bias**: bias of the convolution. It is an array with a length of **[outChannel]**. In quantization scenarios, the **bias** parameter does not require quantization parameters. The quantization version requires data input of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br/>Parameters:<br/>- **stride**: movement stride of the convolution kernel in height and width. It is an int array [strideHeight, strideWidth].<br/>- **dilation**: dilation size of the convolution kernel in height and width. It is an int array [dilationHeight, dilationWidth]. The value must be greater than or equal to **1** and cannot exceed the height and width of **input**.<br/>- **padList**: padding around **input**. It is an int array [top, bottom, left, right].<br/>- **group**: number of groups in which the input is divided by **in_channel**. The value is of the int type. If **group** is **1**, it is a conventional convolution. If **group** is **in_channel**, it is depthwiseConv2d. In this case, group==in_channel==out_channel. If **group** is greater than **1** and less than **in_channel**, it is a group convolution. In this case, out_channel==group.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: convolution computing result.  |
280| OH_NN_OPS_CONV2D_TRANSPOSE  | 2D convolution transposition.<br/>If the input contains the **padMode** parameter:<br/>Inputs:<br/>- **input**: input tensor.<br/>- **weight**: convolution weight in [outChannel, kernelHeight, kernelWidth, inChannel/group] format. The value of **inChannel** must be exactly divided by the value of **group**.<br/>- **bias**: bias of the convolution. It is an array with a length of **[outChannel]**. In quantization scenarios, the **bias** parameter does not require quantization parameters. The quantization version requires data input of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br/>- **stride**: movement stride of the convolution kernel in height and width. It is an int array [strideHeight, strideWidth].<br/>Parameters:<br/>- **dilation**: dilation size of the convolution kernel in height and width. It is an int array [dilationHeight, dilationWidth]. The value must be greater than or equal to **1** and cannot exceed the height and width of **input**.<br/>- **padMode**: padding mode of **input**. The value is of the int type and can be **0** (same) or **1** (valid). **0** (same): The height and width of the output are the same as those of the input. The total padding quantity is calculated horizontally and vertically and evenly distributed to the top, bottom, left, and right if possible. Otherwise, the last additional padding will be completed from the bottom and right. **1** (valid): The possible maximum height and width of the output will be returned in case of no padding. The excessive pixels will be discarded.<br/>- **group**: number of groups in which the input is divided by **in_channel**. The value is of the int type. If **group** is **1**, it is a conventional convolution. If **group** is greater than **1** and less than or equal to **in_channel**, it is a group convolution.<br/>- **outputPads**: padding along the height and width of the output tensor. The value is an int or a tuple. It can be a single integer to specify the same value for all spatial dimensions. The amount of output padding along a dimension must be less than the stride along this dimension.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>If the input contains the **padList** parameter:<br/>Inputs:<br/>- **input**: input tensor.<br/>- **weight**: convolution weight in [outChannel, kernelHeight, kernelWidth, inChannel/group] format. The value of **inChannel** must be exactly divided by the value of **group**.<br/>- **bias**: bias of the convolution. It is an array with a length of **[outChannel]**. In quantization scenarios, the **bias** parameter does not require quantization parameters. The quantization version requires data input of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br/>Parameters:<br/>- **stride**: movement stride of the convolution kernel in height and width. It is an int array [strideHeight, strideWidth].<br/>- **dilation**: dilation size of the convolution kernel in height and width. It is an int array [dilationHeight, dilationWidth]. The value must be greater than or equal to **1** and cannot exceed the height and width of **input**.<br/>- **padList**: padding around **input**. It is an int array [top, bottom, left, right].<br/>- **group**: number of groups in which the input is divided by **in_channel**. The value is of the int type. If **group** is **1**, it is a conventional convolution. If **group** is greater than **1** and less than or equal to **in_channel**, it is a group convolution.<br/>- **outputPads**: padding along the height and width of the output tensor. The value is an int or a tuple. It can be a single integer to specify the same value for all spatial dimensions. The amount of output padding along a dimension must be less than the stride along this dimension.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>**output**: computing result after convolution and transposition. |
281| OH_NN_OPS_DEPTHWISE_CONV2D_NATIVE  | 2D depthwise separable convolution.<br/>If the input contains the **padMode** parameter:<br/>Inputs:<br/>- **input**: input tensor.<br/>- **weight**: convolution weight in [outChannel, kernelHeight, kernelWidth, 1] format. **outChannel** is equal to **channelMultiplier** multiplied by **inChannel**.<br/>- **bias**: bias of the convolution. It is an array with a length of **[outChannel]**. In quantization scenarios, the **bias** parameter does not require quantization parameters. The quantization version requires data input of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br/>Parameters:<br/>- **stride**: movement stride of the convolution kernel in height and width. It is an int array [strideHeight, strideWidth].<br/>- **dilation**: dilation size of the convolution kernel in height and width. It is an int array [dilationHeight, dilationWidth]. The value must be greater than or equal to **1** and cannot exceed the height and width of **input**.<br/>- **padMode**: padding mode of **input**. The value is of the int type and can be **0** (same) or **1** (valid). **0** (same): The height and width of the output are the same as those of the input. The total padding quantity is calculated horizontally and vertically and evenly distributed to the top, bottom, left, and right if possible. Otherwise, the last additional padding will be completed from the bottom and right.<br/>  **1** (valid): The possible maximum height and width of the output will be returned in case of no padding. The excessive pixels will be discarded.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>If the input contains the **padList** parameter:<br/>Inputs:<br/>- **input**: input tensor.<br/>- **weight**: convolution weight in [outChannel, kernelHeight, kernelWidth, 1] format. **outChannel** is equal to **channelMultiplier** multiplied by **inChannel**.<br/>- **bias**: bias of the convolution. It is an array with a length of **[outChannel]**. In quantization scenarios, the **bias** parameter does not require quantization parameters. The quantization version requires data input of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br/>Parameters:<br/>- **stride**: movement stride of the convolution kernel in height and width. It is an int array [strideHeight, strideWidth].<br/>- **dilation**: dilation size of the convolution kernel in height and width. It is an int array [dilationHeight, dilationWidth]. The value must be greater than or equal to **1** and cannot exceed the height and width of **input**.<br/>- **padList**: padding around **input**. It is an int array [top, bottom, left, right].<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: convolution computing result.  |
282| OH_NN_OPS_DIV  | Divides two input scalars or tensors.<br/>Inputs:<br/>- **input1**: first input, which is a number, a bool, or a tensor whose data type is number or Boolean.<br/>- **input2**: second input, which must meet the following requirements: If the first input is a tensor, the second input can be a real number, a Boolean value, or a tensor whose data type is real number or Boolean value. If the first input is a real number or Boolean value, the second input must be a tensor whose data type is real number or Boolean value.<br/>Parameters:<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: result of dividing **input1** by **input2**.  |
283| OH_NN_OPS_ELTWISE  | Sets parameters to perform product (dot product), sum (addition and subtraction), or max (larger value) on the input.<br/>Inputs:<br/>- **input1**: first input tensor.<br/>- **input2**: second input tensor.<br/>Parameters:<br/>- **mode**: operation mode. The value is an enumerated value.<br/>Outputs:<br/>- **output**: computing result, which has the same data type and shape of **output** and **input1**.  |
284| OH_NN_OPS_EXPAND_DIMS  | Adds an additional dimension to a tensor in the given dimension.<br/>Inputs:<br/>- **input**: input tensor.<br/>- **axis**: index of the dimension to be added. The value is of the int32_t type and must be a constant in the range [-dim-1, dim].<br/>Outputs:<br/>- **output**: tensor after dimension expansion.  |
285| OH_NN_OPS_FILL  | Creates a tensor of the specified dimensions and fills it with a scalar.<br/>Inputs:<br/>- **value**: scalar used to fill the tensor.<br/>- **shape**: dimensions of the tensor to be created.<br/>Outputs:<br/>- **output**: generated tensor, which has the same data type as **value**. The tensor shape is specified by the **shape** parameter.  |
286| OH_NN_OPS_FULL_CONNECTION  | Full connection. The entire input is used as the feature map for feature extraction.<br/>Inputs:<br/>- **input**: full-connection input tensor.<br/>- **weight**: weight tensor for a full connection.<br/>- **bias**: full-connection bias. In quantization scenarios, no quantized parameter is required for this parameter. If quantization is required, the data must be of the OH_NN_INT32 type. The actual quantization parameters are determined by **input** and **weight**.<br/>Parameters:<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: computed tensor.<br/>If the input contains the **axis** parameter:<br/>Inputs:<br/>- **input**: full-connection input tensor.<br/>- **weight**: weight tensor for a full connection.<br/>- **bias**: full-connection bias. In quantization scenarios, no quantized parameter is required for this parameter. If quantization is required, the data must be of the OH_NN_INT32 type. The actual quantization parameters are determined by **input** and **weight**.<br/>Parameters:<br/>- **axis**: axis in which the full connection is applied. The specified axis and its following axes are converted into a 1D tensor for applying the full connection.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: computed tensor.  |
287| OH_NN_OPS_GATHER  | Returns the slice of the input tensor based on the specified index and axis.<br/>Inputs:<br/>- **input**: tensor to be sliced.<br/>- **inputIndices**: indices of the specified input on the axis. The value is an array of the int type and must be in the range [0,input.shape[axis]).<br/>- **axis**: axis on which **input** is sliced. The value is an array with one element of the int32_t type.<br/>Outputs:<br/>- **output**: sliced tensor.  |
288| OH_NN_OPS_HSWISH  | Calculate the **Hswish** activation value of the input.<br/>Inputs:<br/>- An n-dimensional input tensor.<br/>Outputs:<br/>- n-dimensional **Hswish** activation value. The data type is the same as that of **shape** and **input**.  |
289| OH_NN_OPS_LESS_EQUAL  | For **input1** and **input2**, calculate the result of input1[i]&lt;=input2[i] for each pair of elements, where i is the index of each element in the input tensor.<br/>Inputs:<br/>- **input1**, which can be a real number, Boolean value, or tensor whose data type is real number or NN_BOOL.<br/>- **input2**, which can be a real number or a Boolean value if **input1** is a tensor and must be a tensor with the data type of real number or NN_BOOL if **input1** is not a tensor.<br/>Outputs:<br/>- A tensor of the data type NN_BOOL. When a quantization model is used, the quantization parameters of the output cannot be omitted. However, values of the quantization parameters do not affect the result.  |
290| OH_NN_OPS_MATMUL  | Calculate the inner product of **input1** and **input2**.<br/>Inputs:<br/>- **input1**: n-dimensional input tensor.<br/>- **input2**: n-dimensional input tensor.<br/>Parameters:<br/>- **TransposeX**: Boolean value indicating whether to transpose **input1**.<br/>- **TransposeY**: Boolean value indicating whether to transpose **input2**.<br/>Outputs:<br/>- **output**: inner product obtained after calculation. In case of type!=NN_UNKNOWN, the output data type is determined by **type**. In case of type==NN_UNKNOWN, the output data type depends on the data type converted during computing of **inputX** and **inputY**.  |
291| OH_NN_OPS_MAXIMUM  | Calculates the maximum of **input1** and **input2** element-wise. The inputs of **input1** and **input2** comply with the implicit type conversion rules to make the data types consistent. \* The inputs must be two tensors or one tensor and one scalar. When the inputs are two tensors, their data types cannot be both NN_BOOL. Their shapes can be broadcast to the same size. When the inputs are one tensor and one scalar, the scalar must be a constant.<br/>Inputs:<br/>- **input1**: n-dimensional input tensor of the real number or NN_BOOL type.<br/>- **input2**: n-dimensional input tensor of the real number or NN_BOOL type.<br/>Outputs:<br/>- **output**: n-dimensional output tensor. The **shape** and data type of **output** are the same as those of the two inputs with a higher precision.  |
292| OH_NN_OPS_MAX_POOL  | Applies 2D maximum pooling to the input tensor.<br/>If the input contains the **padMode** parameter:<br/>Inputs:<br/>- **input**: tensor.<br/>Parameters:<br/>- **kernelSize**: kernel size used to obtain the maximum. It is an int array [kernel_height, kernel_width]. The first number indicates the kernel height, and the second number indicates the kernel width.<br/>- **strides** indicates the distance of kernel moving. The value is an int array [stride_height, stride_width]. The first number indicates the moving step in height, and the second number indicates the moving step in width.<br/>- **padMode**: padding mode, which is optional. The value is of the int type and can be **0** (same) or **1** (valid). The nearest neighbor value is used for padding. **0** (same): The height and width of the output are the same as those of the input. The total padding quantity is calculated horizontally and vertically and evenly distributed to the top, bottom, left, and right if possible. Otherwise, the last additional padding will be completed from the bottom and right.<br/>  **1** (valid): The possible maximum height and width of the output will be returned in case of no padding. The excessive pixels will be discarded.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>If the input contains the **padList** parameter:<br/>Inputs:<br/>- **input**: tensor.<br/>Parameters:<br/>- **kernelSize**: kernel size used to obtain the maximum. It is an int array [kernel_height, kernel_width]. The first number indicates the kernel height, and the second number indicates the kernel width.<br/>- **strides** indicates the distance of kernel moving. The value is an int array [stride_height, stride_width]. The first number indicates the moving step in height, and the second number indicates the moving step in width.<br/>- **padList**: padding around **input**. It is an int array [top, bottom, left, right], and the nearest neighbor values are used for padding.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: tensor obtained after maximum pooling is applied to the input.  |
293| OH_NN_OPS_MUL  | Multiplies elements in the same positions of **inputX** and **inputY** to obtain the output. If **inputX** and **inputY** have different shapes, expand them to the same shape through broadcast and then perform multiplication.<br/>Inputs:<br/>- **input1**: n-dimensional tensor.<br/>- **input2**: n-dimensional tensor.<br/>Parameters:<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- Product of each element of **input1** and **input2**.  |
294| OH_NN_OPS_ONE_HOT  | Generates a one-hot tensor based on the positions specified by **indices**. The positions specified by **indices** are determined by **on_value**, and other positions are determined by **off_value**.<br/>Inputs:<br/>- **indices**: n-dimensional tensor. Each element in **indices** determines the position of **on_value** in each one-hot vector.<br/>- **depth**: integer scalar that determines the depth of the one-hot vector. The value of **depth** must be greater than **0**.<br/>- **on_value**: scalar that specifies a valid value in the one-hot vector.<br/>- **off_value**: scalar that specifies the values of other posistions in the one-hot vector except the valid value.<br/>Parameters:<br/>- **axis**: integer scalar that specifies the dimension for inserting the one-hot. Assume that the shape of **indices** is [N, C], and the value of **depth** is D. When **axis** is **0**, the shape of the output is [D, N, C]. When **axis** is **-1**, the shape of the output is [N, C, D]. When **axis** is **1**, the shape of the output is [N, D, C].<br/>Outputs:<br/>- **output**: (n+1)-dimensional tensor if **indices** is an n-dimensional tensor. The output shape is determined by **indices** and **axis**.  |
295| OH_NN_OPS_PAD  | Pads **inputX** in the specified dimensions.<br/>Inputs:<br/>- **inputX**: n-dimensional tensor in [BatchSize, ...] format.<br/>- **paddings**: 2D tensor that specifies the length to pad in each dimension. The shape is [n, 2]. For example, **paddings[i][0]** indicates the number of paddings to be added preceding **inputX** in the ith dimension. **paddings[i][1]** indicates the number of paddings to be added following **inputX** in the ith dimension.<br/>Parameters:<br/>- **padValues**: value to be added to the pad operation. The value is a constant with the same data type as **inputX**.<br/>Outputs:<br/>- **output**: n-dimensional tensor after padding, with the same dimensions and data type as **inputX**. The shape is determined by **inputX** and **paddings**. output.shape[i] = input.shape[i] + paddings[i][0]+paddings[i][1]  |
296| OH_NN_OPS_POW  | Calculates the **y** power of each element in **input**. The inputs must be two tensors or one tensor and one scalar. When the inputs are two tensors, their data types cannot be both NN_BOOL, and their shapes must be the same. When the inputs are one tensor and one scalar, the scalar must be a constant.<br/>Inputs:<br/>- **input**: real number, Boolean value, or tensor whose data type is real number or NN_BOOL.<br/>- **y**: real number, Boolean value, or tensor whose data type is real number or NN_BOOL.<br/>Outputs:<br/>- **output**: tensor, whose shape is determined by the shape of **input** and **y** after broadcasting.  |
297| OH_NN_OPS_SCALE  | Scales a tensor.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>- **scale**: scaling tensor.<br/>- **bias**: bias tensor.<br/>Parameters:<br/>- **axis**: dimensions to be scaled.<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: scaled n-dimensional tensor, whose data type is the same as that of **input** and shape is determined by **axis**.  |
298| OH_NN_OPS_SHAPE  | Calculates the shape of the input tensor.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Outputs:<br/>- **output**: integer array representing the dimensions of the input tensor.  |
299| OH_NN_OPS_SIGMOID  | Applies the **sigmoid** operation to the input tensor.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Outputs:<br/>- **output**: result of the **sigmoid** operation. It is an n-dimensional tensor with the same data type and shape as **input**.  |
300| OH_NN_OPS_SLICE  | Slices a tensor of the specified size from the input in each dimension.<br/>Inputs:<br/>- **input**: n-dimensional input tensor.<br/>- **begin**: start of the slice, which is an array of integers greater than or equal to 0.<br/>- **size**: slice length, which is an array of integers greater than or equal to 0. Assume that a dimension is **i** and 1&lt;=size[i]&lt;=input.shape[i]-begin[i].<br/>Outputs:<br/>- **output**: n-dimensional tensor obtained by slicing. The **TensorType**, shape, and size of the output are the same as those of the input.  |
301| OH_NN_OPS_SOFTMAX  | Applies the **softmax** operation to the input tensor.<br/>Inputs:<br/>- **input**: n-dimensional input tensor.<br/>Parameters:<br/>- **axis**: dimension in which the **softmax** operation is performed. The value is of the int64 type. It is an integer in the range [-n, n).<br/>Outputs:<br/>- **output**: result of the **softmax** operation. It is an n-dimensional tensor with the same data type and shape as **input**.  |
302| OH_NN_OPS_SPACE_TO_BATCH_ND  | Divides a 4D tensor into small blocks and combines these blocks in the original batch. The number of blocks is **blockShape[0]** multiplied by **blockShape[1]**.<br/>Inputs:<br/>- **input**: 4D tensor.<br/>Parameters:<br/>- **blockShape**: a pair of integers. Each of them is greater than or equal to **1**.<br/>- **paddings**: a pair of arrays. Each of them consists of two integers. The four integers that form **paddings** must be greater than or equal to **0**. **paddings[0][0]** and **paddings[0][1]** specify the number of paddings in the third dimension, and **paddings[1][0]** and **paddings[1][1]** specify the number of paddings in the fourth dimension.<br/>Outputs:<br/>- **output**: 4D tensor with the same data type as **input**. The shape is determined by **input**, **blockShape**, and **paddings**. Assume that the input shape is [n,c,h,w], then: output.shape[0] = n \* blockShape[0] \* blockShape[1] output.shape[1] = c output.shape[2] = (h + paddings[0][0] + paddings[0][1]) / blockShape[0] output.shape[3] = (w + paddings[1][0] + paddings[1][1]) / blockShape[1] (h + paddings[0][0] + paddings[0][1]) and (w + paddings[1][0] + paddings[1][1]) is exactly divisible by (h + paddings[0][0] + paddings[0][1]) and (w + paddings[1][0] + paddings[1][1]).  |
303| OH_NN_OPS_SPLIT  | Splits the input into multiple tensors along the axis dimension. The number of tensors is specified by **outputNum**.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Parameters:<br/>- **outputNum**: number of output tensors. The data type is long.<br/>- **size_splits**: size of each tensor split from the input. The value is a 1D tensor of the int type. If **size_splits** is empty, the input will be evenly split into tensors of the same size. In this case, **input.shape[axis]** can be exactly divisible by **outputNum**. If **size_splits** is not empty, the sum of all its elements must be equal to **input.shape[axis]**.<br/>- **axis**: splitting dimension of the int type.<br/>Outputs:<br/>- **outputs**: array of n-dimensional tensors, with the same data type and dimensions. The data type of each tensor is the same as that of **input**.  |
304| OH_NN_OPS_SQRT  | Calculates the square root of a tensor.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Outputs:<br/>- **output**: square root of the input. It is an n-dimensional tensor with the same data type and shape as **input**.  |
305| OH_NN_OPS_SQUARED_DIFFERENCE  | Calculates the square of the difference between two tensors. The **SquaredDifference** operator supports tensor and tensor subtraction. If two tensors have different **TensorTypes**, the Sub operator converts the low-precision tensor to a high-precision one. If two tensors have different shapes, the two tensors can be extended to tensors with the same shape through broadcast.<br/>Inputs:<br/>- **input1**: minuend, which is a tensor of the NN_FLOAT16, NN_FLOAT32, NN_INT32, or NN_BOOL type.<br/>- **input2**: subtrahend, which is a tensor of the NN_FLOAT16, NN_FLOAT32, NN_INT32, or NN_BOOL type.<br/>Outputs:<br/>- **output**: square of the difference between two inputs. The output shape is determined by**input1** and **input2**. If they have the same shape, the output tensor has the same shape as them. If they have different shapes, perform the broadcast operation on **input1** and **input2** and perform subtraction. **TensorType** of the output is the same as that of the input tensor with higher precision.  |
306| OH_NN_OPS_SQUEEZE  | Removes the dimension with a length of 1 from the specified axis. The int8 quantization input is supported. Assume that the input shape is [2, 1, 1, 2, 2] and axis is [0,1], the output shape is [2, 1, 2, 2], which means the dimension whose length is 0 between dimensions 0 and dimension 1 is removed.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Parameters:<br/>- **axis**: dimension to be removed. The value is of int64_t type and can be an integer in the range [-n, n) or an array.<br/>Outputs:<br/>- **output**: output tensor.  |
307| OH_NN_OPS_STACK  | Stacks multiple tensors along the specified axis. If each tensor has n dimensions before stacking, the output tensor will have n+1 dimensions.<br/>Inputs:<br/>- **input**: input for stacking, which can contain multiple n-dimensional tensors. Each of them must have the same shape and type.<br/>Parameters:<br/>- **axis**: dimension for tensor stacking, which is an integer. The value range is [-(n+1),(n+1)), which means a negative number is allowed.<br/>Outputs:<br/>- **output**: stacking result of the input along the axis dimension. The value is an n+1-dimensional tensor and has the same **TensorType** as the input.  |
308| OH_NN_OPS_STRIDED_SLICE  | Slices a tensor with the specified stride.<br/>Inputs:<br/>- **input**: n-dimensional input tensor.<br/>- **begin**: start of slicing, which is a 1D tensor. The length of **begin** is n. **begin[i]** specifies the start of slicing in the ith dimension.<br/>- **end**: end of slicing, which is a 1D tensor. The length of **end** is n. **end[i]** specifies the end of slicing in the ith dimension.<br/>- **strides**: slicing stride, which is a 1D tensor. The length of **strides** is n. strides[i] specifies the stride at which the tensor is sliced in the ith dimension.<br/>Parameters:<br/>- **beginMask**: an integer used to mask **begin**. **beginMask** is represented in binary code. In case of binary(beginMask)[i]==1, for the ith dimension, elements are sliced from the first element at **strides[i]** until the end[i]-1 element.<br/>- **endMask**: an integer used to mask **end**. **endMask** is represented in binary code. In case of binary(endMask)[i]==1, elements are sliced from the element at the **begin[i]** position in the ith dimension until the tensor boundary at **strides[i]**.<br/>- **ellipsisMask**: integer used to mask **begin** and **end**. **ellipsisMask** is represented in binary code. In case of binary(ellipsisMask)[i]==1, elements are sliced from the first element at **strides[i]** in the ith dimension until the tensor boundary. Only one bit of **binary(ellipsisMask)** can be a non-zero value.<br/>- **newAxisMask**: new dimension, which is an integer. **newAxisMask** is represented in binary code. In case of binary(newAxisMask)[i]==1, a new dimension whose length is 1 is inserted into the ith dimension.<br/>- **shrinkAxisMask**: shrinking dimension, which is an integer. \* **shrinkAxisMask** is represented in binary code. In the case of binary(shrinkAxisMask)[i]==1, all elements in the ith dimension will be discarded, and the length of the ith dimension is shrunk to **1**.<br/>Outputs:<br/>- A tensor, with the same data type as **input**. The number of dimensions of the output tensor is rank(input[0])+1.  |
309| OH_NN_OPS_SUB  | Calculates the difference between two tensors.<br/>Inputs:<br/>- **input1**: minuend, which is a tensor.<br/>- **input2**: subtrahend, which is a tensor.<br/>Parameters:<br/>- **activationType** is an integer constant which is contained in **FuseType**. The specified activation function is called before output.<br/>Outputs:<br/>- **output**: difference between the two tensors. The output shape is determined by**input1** and **input2**. If they have the same shape, the output tensor has the same shape as them. If they have different shapes, perform the broadcast operation on **input1** and **input2** and perform subtraction. **TensorType** of the output is the same as that of the input tensor with higher precision.  |
310| OH_NN_OPS_TANH  | Computes hyperbolic tangent of the input tensor.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Outputs:<br/>- **output**: hyperbolic tangent of the input. The **TensorType** and tensor shape are the same as those of the input.  |
311| OH_NN_OPS_TILE  | Copies a tensor the specified times.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>- **multiples**: number of times that the input tensor is copied in each dimension. The value is a 1D tensor. The length m is not less than the number of dimensions, that is, n.<br/>Outputs:<br/>- An m-dimensional tensor whose **TensorType** is the same as that of the input. If **input** and **multiples** have the same length, **input** and **output** have the same number of dimensions. If the length of **multiples** is greater than n, 1 is used to fill the input dimension, and then the input is copied in each dimension the specified times to obtain the m-dimensional tensor.  |
312| OH_NN_OPS_TRANSPOSE  | Transposes data of **input 0** based on **permutation**.<br/>Inputs:<br/>- **input**: n-dimensional tensor to be transposed.<br/>- **permutation**: The value is a 1D tensor whose length is the same as the number of dimensions of **input 0**.<br/>Outputs:<br/>- **output**: n-dimensional tensor. **TensorType** of **output 0** is the same as that of **input 0**, and the output shape is determined by the shape and **permutation** of **input 0**.  |
313| OH_NN_OPS_REDUCE_MEAN  | Calculates the average value in the specified dimension. If **keepDims** is set to **false**, the number of dimensions is reduced for the input; if **keepDims** is set to **true**, the number of dimensions is retained.<br/>Inputs:<br/>- **input**: n-dimensional input tensor, where n is less than 8.<br/>- **axis**: dimension used to calculate the average value. The value is a 1D tensor. The value range of each element in **axis** is [–n, n).<br/>Parameters:<br/>- **keepDims**: indicates whether to retain the dimension. The value is a Boolean value.<br/>Outputs:<br/>- **output**: m-dimensional output tensor whose data type is the same as that of the input. If **keepDims** is **false**, m==n. If **keepDims** is **true**, m&lt;n.  |
314| OH_NN_OPS_RESIZE_BILINEAR  | The Bilinear method is used to deform the input based on the given parameters.<br/>Inputs:<br/>- **input**: 4D input tensor. Each element in the input cannot be less than 0. The input layout must be [batchSize, height, width, channels].<br/>Parameters:<br/>- **newHeight**: resized height of the 4D tensor.<br/>- **newWidth**: resized width of the 4D tensor.<br/>- **preserveAspectRatio**: indicates whether to maintain the height/width ratio of **input** after resizing.<br/>- **coordinateTransformMode**: coordinate transformation method used by the resize operation. The value is an int32 integer. Currently, the following methods are supported:<br/>- **excludeOutside**: an int64 floating point number. When its value is **1**, the sampling weight of the part that exceeds the boundary of **input** is set to **0**, and other weights are normalized.<br/>Outputs:<br/>- **output**: n-dimensional tensor, with the same shape and data type as **input**.  |
315| OH_NN_OPS_RSQRT  | Calculates the reciprocal of the square root of a tensor.<br/>Inputs:<br/>- **input**: n-dimensional tensor, where n is less than 8. Each element of the tensor cannot be less than 0.<br/>Outputs:<br/>- **output**: n-dimensional tensor, with the same shape and data type as **input**.  |
316| OH_NN_OPS_RESHAPE  | Reshapes a tensor.<br/>Inputs:<br/>- **input**: n-dimensional input tensor.<br/>- **InputShape**: shape of the output tensor. The value is a 1D constant tensor.<br/>Outputs:<br/>- **output**: tensor whose data type is the same as that of **input** and shape is determined by **InputShape**.  |
317| OH_NN_OPS_PRELU  | Calculates the PReLU activation value of **input** and **weight**.<br/>Inputs:<br/>- **input**: n-dimensional tensor. If n is greater than or equal to 2, **inputX** must be [BatchSize, ..., Channels]. The second dimension is the number of channels.<br/>- **weight**: 1D tensor. The length of **weight** must be 1 or equal to the number of channels. If the length of **weight** is 1, all channels share the same weight. If the length of **weight** is equal to the number of channels, each channel exclusively has a weight. If n is less than 2 for **inputX**, the **weight** length must be 1.<br/>Outputs:<br/>**output**: PReLU activation value of **x**, with the same shape and data type as **inputX**. |
318| OH_NN_OPS_RELU  | Calculates the Relu activation value of **input**.<br/>Inputs:<br/>- **input**: n-dimensional input tensor.<br/>Outputs:<br/>- **output**: n-dimensional tensor, with the same data type and shape as the input tensor.  |
319| OH_NN_OPS_RELU6  | Calculates the Relu6 activation value of the input, that is, calculate min(max(x, 0), 6) for each element x in the input.<br/>Inputs:<br/>- **input**: n-dimensional input tensor.<br/>Outputs:<br/>- **output**: n-dimensional Relu6 tensor, with the same data type and shape as the input tensor.  |
320| OH_NN_OPS_LAYER_NORM  | Applies layer normalization for a tensor from the specified axis.<br/>Inputs:<br/>- **input**: n-dimensional input tensor.<br/>- **gamma**: m-dimensional tensor. The dimensions of **gamma** must be the same as the shape of the part of the input tensor to normalize.<br/>- **beta**: m-dimensional tensor with the same shape as **gamma**.<br/>Parameters:<br/>- **beginAxis** is an NN_INT32 scalar that specifies the axis from which normalization starts. The value range is [1, rank(input)).<br/>- **epsilon** is a scalar of NN_FLOAT32. It is a tiny amount in the normalization formula. The common value is 1e-7.<br/>Outputs:<br/>- **output**: n-dimensional tensor, with the same data type and shape as the input tensor.  |
321| OH_NN_OPS_REDUCE_PROD  | Calculates the accumulated value for a tensor along the specified dimension.<br/>Inputs:<br/>- **input**: n-dimensional input tensor, where n is less than 8.<br/>- **axis**: dimension used to calculate the product. The value is a 1D tensor. The value range of each element in **axis** is [–n, n).<br/>Parameters:<br/>- **keepDims**: indicates whether to retain the dimension. The value is a Boolean value. When its value is **true**, the number of output dimensions is the same as that of the input. When its value is **false**, the number of output dimensions is reduced.<br/>Outputs:<br/>- **output**: m-dimensional output tensor whose data type is the same as that of the input. If **keepDims** is **false**, m==n. If **keepDims** is **true**, m&lt;n.  |
322| OH_NN_OPS_REDUCE_ALL  | Operates the logical OR in the specified dimension. If **keepDims** is set to **false**, the number of dimensions is reduced for the input; if **keepDims** is set to **true**, the number of dimensions is retained.<br/>Inputs:<br/>- A n-dimensional input tensor, where n is less than 8.<br/>- A 1D tensor specifying the dimension used to operate the logical OR. The value range of each element in **axis** is [–n, n).<br/>Parameters:<br/>- **keepDims**: indicates whether to retain the dimension. The value is a Boolean value.<br/>Outputs:<br/>- **output**: m-dimensional output tensor whose data type is the same as that of the input. If **keepDims** is **false**, m==n. If **keepDims** is **true**, m&lt;n.  |
323| OH_NN_OPS_QUANT_DTYPE_CAST  | Converts the data type.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Parameters:<br/>- **src_t**: data type of the input.<br/>- **dst_t**: data type of the output.<br/>Outputs:<br/>- **output**: n-dimensional tensor. The data type is determined by **input2**. The output shape is the same as the input shape.  |
324| OH_NN_OPS_TOP_K  | Obtains the values and indices of the largest k entries in the last dimension.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>- **input** k: first k records of data and their indices.<br/>Parameters:<br/>- **sorted**: order of sorting. The value **true** means descending and **false** means ascending.<br/>Outputs:<br/>- **output0**: largest k elements in each slice of the last dimension.<br/>- **output1**: index of the value in the last dimension of the input.  |
325| OH_NN_OPS_ARG_MAX  | Returns the index of the maximum tensor value across axes.<br/>Inputs:<br/>- **input**: n-dimensional tensor (N, ∗), where ∗ means any number of additional dimensions.<br/>Parameters:<br/>- **axis**: dimension for calculating the index of the maximum.<br/>- **keep_dims**: indicates whether to maintain the input tensor dimension. The value is a Boolean value.<br/>Outputs:<br/>- **output**: index of the maximum input tensor on the axis. The value is a tensor.  |
326| OH_NN_OPS_UNSQUEEZE  | Adds a dimension based on the value of **axis**.<br/>Inputs:<br/>- **input**: n-dimensional tensor.<br/>Parameters:<br/>- **axis**: dimension to be added. The value of **axis** can be an integer or an array of integers. The value range of the integer is [-n, n).<br/>Outputs:<br/>- **output**: output tensor.  |
327| OH_NN_OPS_GELU  | Gaussian error linear unit activation function. The int quantization input is not supported. output=0.5∗input∗(1+tanh(input/2))<br/>Inputs:<br/>- An n-dimensional input tensor.<br/>Outputs:<br/>- **output**: n-dimensional tensor, with the same data type and shape as the input tensor.  |
328
329
330### OH_NN_PerformanceMode
331
332
333```
334enum OH_NN_PerformanceMode
335```
336**Description**<br>
337Defines the hardware performance mode.
338
339| Name | Description |
340| -------- | -------- |
341| OH_NN_PERFORMANCE_NONE  | No performance mode preference |
342| OH_NN_PERFORMANCE_LOW  | Low power consumption mode |
343| OH_NN_PERFORMANCE_MEDIUM  | Medium performance mode |
344| OH_NN_PERFORMANCE_HIGH  | High performance mode |
345| OH_NN_PERFORMANCE_EXTREME  | Ultimate performance mode |
346
347
348### OH_NN_Priority
349
350
351```
352enum OH_NN_Priority
353```
354**Description**<br>
355Defines the model inference task priority.
356
357| Name | Description |
358| -------- | -------- |
359| OH_NN_PRIORITY_NONE  | No priority preference |
360| OH_NN_PRIORITY_LOW  | Low priority |
361| OH_NN_PRIORITY_MEDIUM  | Medium priority |
362| OH_NN_PRIORITY_HIGH  | High priority |
363
364
365### OH_NN_ReturnCode
366
367
368```
369enum OH_NN_ReturnCode
370```
371**Description**<br>
372Defines error codes for Neural Network Runtime.
373
374| Name | Description |
375| -------- | -------- |
376| OH_NN_SUCCESS  | The operation is successful. |
377| OH_NN_FAILED  | The operation failed. |
378| OH_NN_INVALID_PARAMETER  | Invalid parameter. |
379| OH_NN_MEMORY_ERROR  | Memory-related error, for example, insufficient memory, memory data copy failure, or memory application failure. |
380| OH_NN_OPERATION_FORBIDDEN  | Invalid operation. |
381| OH_NN_NULL_PTR  | Null pointer exception |
382| OH_NN_INVALID_FILE  | Invalid file. |
383| OH_NN_UNAVALIDABLE_DEVICE  | A hardware error occurs, for example, HDL service crash. |
384| OH_NN_INVALID_PATH  | Invalid path. |
385
386
387### OH_NN_TensorType
388
389
390```
391enum OH_NN_TensorType
392```
393**Description**<br>
394Enumerates the tensor data types.
395
396Tensors are usually used to set the input, output, and operator parameters of a model. When a tensor is used as the input or output of a model (or operator), set the tensor type to OH_NN_TENSOR. When the tensor is used as an operator parameter, select an enumerated value other than OH_NN_TENSOR as the tensor type. Assume that the **pad** parameter of the OH_NN_OPS_CONV2D operator is being set. You need to set the **type** attribute of the [OH_NN_Tensor](_o_h___n_n___tensor.md) instance to OH_NN_CONV2D_PAD. The settings of other operator parameters are similar. The enumerated values are named in the format OH_NN_{Operator name}_{Attribute name}.
397
398| Name | Description |
399| -------- | -------- |
400| OH_NN_TENSOR  | This enumerated value is used when the tensor is used as the input or output of a model (or operator). |
401| OH_NN_ADD_ACTIVATIONTYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the Add operator. |
402| OH_NN_AVG_POOL_KERNEL_SIZE  | This enumerated value is used when the tensor is used as the **kernel_size** parameter of the AvgPool operator. |
403| OH_NN_AVG_POOL_STRIDE  | This enumerated value is used when the tensor is used as the **stride** parameter of the AvgPool operator. |
404| OH_NN_AVG_POOL_PAD_MODE  | This enumerated value is used when the tensor is used as the **pad_mode** parameter of the AvgPool operator. |
405| OH_NN_AVG_POOL_PAD  | This enumerated value is used when the tensor is used as the **pad** parameter of the AvgPool operator. |
406| OH_NN_AVG_POOL_ACTIVATION_TYPE  | This enumerated value is used when the tensor is used as the **activation_type** parameter of the AvgPool operator. |
407| OH_NN_BATCH_NORM_EPSILON  | This enumerated value is used when the tensor is used as the **eosilon** parameter of the BatchNorm operator. |
408| OH_NN_BATCH_TO_SPACE_ND_BLOCKSIZE  | This enumerated value is used when the tensor is used as the **blockSize** parameter of the BatchToSpaceND operator. |
409| OH_NN_BATCH_TO_SPACE_ND_CROPS  | This enumerated value is used when the tensor is used as the **crops** parameter of the BatchToSpaceND operator. |
410| OH_NN_CONCAT_AXIS  | This enumerated value is used when the tensor is used as the **axis** parameter of the Concat operator. |
411| OH_NN_CONV2D_STRIDES  | This enumerated value is used when the tensor is used as the **strides** parameter of the Conv2D operator. |
412| OH_NN_CONV2D_PAD  | This enumerated value is used when the tensor is used as the **pad** parameter of the Conv2D operator. |
413| OH_NN_CONV2D_DILATION  | This enumerated value is used when the tensor is used as the **dilation** parameter of the Conv2D operator. |
414| OH_NN_CONV2D_PAD_MODE  | This enumerated value is used when the tensor is used as the **padMode** parameter of the Conv2D operator. |
415| OH_NN_CONV2D_ACTIVATION_TYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the Conv2D operator. |
416| OH_NN_CONV2D_GROUP  | This enumerated value is used when the tensor is used as the **group** parameter of the Conv2D operator. |
417| OH_NN_CONV2D_TRANSPOSE_STRIDES  | This enumerated value is used when the tensor is used as the **strides** parameter of the Conv2DTranspose operator. |
418| OH_NN_CONV2D_TRANSPOSE_PAD  | This enumerated value is used when the tensor is used as the **pad** parameter of the Conv2DTranspose operator. |
419| OH_NN_CONV2D_TRANSPOSE_DILATION  | This enumerated value is used when the tensor is used as the **dilation** parameter of the Conv2DTranspose operator. |
420| OH_NN_CONV2D_TRANSPOSE_OUTPUT_PADDINGS  | This enumerated value is used when the tensor is used as the **outputPaddings** parameter of the Conv2DTranspose operator. |
421| OH_NN_CONV2D_TRANSPOSE_PAD_MODE  | This enumerated value is used when the tensor is used as the **padMode** parameter of the Conv2DTranspose operator. |
422| OH_NN_CONV2D_TRANSPOSE_ACTIVATION_TYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the Conv2DTranspose operator. |
423| OH_NN_CONV2D_TRANSPOSE_GROUP  | This enumerated value is used when the tensor is used as the **group** parameter of the Conv2DTranspose operator. |
424| OH_NN_DEPTHWISE_CONV2D_NATIVE_STRIDES  | This enumerated value is used when the tensor is used as the **strides** parameter of the DepthwiseConv2dNative operator. |
425| OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD  | This enumerated value is used when the tensor is used as the **pad** parameter of the DepthwiseConv2dNative operator. |
426| OH_NN_DEPTHWISE_CONV2D_NATIVE_DILATION  | This enumerated value is used when the tensor is used as the **dilation** parameter of the DepthwiseConv2dNative operator. |
427| OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD_MODE  | This enumerated value is used when the tensor is used as the **padMode** parameter of the DepthwiseConv2dNative operator. |
428| OH_NN_DEPTHWISE_CONV2D_NATIVE_ACTIVATION_TYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the DepthwiseConv2dNative operator. |
429| OH_NN_DIV_ACTIVATIONTYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the Div operator. |
430| OH_NN_ELTWISE_MODE  | This enumerated value is used when the tensor is used as the **mode** parameter of the Eltwise operator. |
431| OH_NN_FULL_CONNECTION_AXIS  | This enumerated value is used when the tensor is used as the **axis** parameter of the FullConnection operator. |
432| OH_NN_FULL_CONNECTION_ACTIVATIONTYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the FullConnection operator. |
433| OH_NN_MATMUL_TRANSPOSE_A  | This enumerated value is used when the tensor is used as the **transposeA** parameter of the Matmul operator. |
434| OH_NN_MATMUL_TRANSPOSE_B  | This enumerated value is used when the tensor is used as the **transposeB** parameter of the Matmul operator. |
435| OH_NN_MATMUL_ACTIVATION_TYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the Matmul operator. |
436| OH_NN_MAX_POOL_KERNEL_SIZE  | This enumerated value is used when the tensor is used as the **kernel_size** parameter of the MaxPool operator. |
437| OH_NN_MAX_POOL_STRIDE  | This enumerated value is used when the tensor is used as the **stride** parameter of the MaxPool operator. |
438| OH_NN_MAX_POOL_PAD_MODE  | This enumerated value is used when the tensor is used as the **pad_mode** parameter of the MaxPool operator. |
439| OH_NN_MAX_POOL_PAD  | This enumerated value is used when the tensor is used as the **pad** parameter of the MaxPool operator. |
440| OH_NN_MAX_POOL_ACTIVATION_TYPE  | This enumerated value is used when the tensor is used as the **activation_type** parameter of the MaxPool operator. |
441| OH_NN_MUL_ACTIVATION_TYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the Mul operator. |
442| OH_NN_ONE_HOT_AXIS  | This enumerated value is used when the tensor is used as the **axis** parameter of the OneHot operator. |
443| OH_NN_PAD_CONSTANT_VALUE  | This enumerated value is used when the tensor is used as the **constant_value** parameter of the Pad operator. |
444| OH_NN_SCALE_ACTIVATIONTYPE  | This enumerated value is used when the tensor is used as the **activationType** parameter of the Scale operator. |
445| OH_NN_SCALE_AXIS  | This enumerated value is used when the tensor is used as the **axis** parameter of the Scale operator. |
446| OH_NN_SOFTMAX_AXIS  | This enumerated value is used when the tensor is used as the **axis** parameter of the Softmax operator. |
447| OH_NN_SPACE_TO_BATCH_ND_BLOCK_SHAPE  | This enumerated value is used when the tensor is used as the **BlockShape** parameter of the SpaceToBatchND operator. |
448| OH_NN_SPACE_TO_BATCH_ND_PADDINGS  | This enumerated value is used when the tensor is used as the **Paddings** parameter of the SpaceToBatchND operator. |
449| OH_NN_SPLIT_AXIS  | This enumerated value is used when the tensor is used as the **Axis** parameter of the Split operator. |
450| OH_NN_SPLIT_OUTPUT_NUM  | This enumerated value is used when the tensor is used as the **OutputNum** parameter of the Split operator. |
451| OH_NN_SPLIT_SIZE_SPLITS  | This enumerated value is used when the tensor is used as the **SizeSplits** parameter of the Split operator. |
452| OH_NN_SQUEEZE_AXIS  | This enumerated value is used when the tensor is used as the **Axis** parameter of the Squeeze operator. |
453| OH_NN_STACK_AXIS  | This enumerated value is used when the tensor is used as the **Axis** parameter of the Stack operator. |
454| OH_NN_STRIDED_SLICE_BEGIN_MASK  | This enumerated value is used when the tensor is used as the **BeginMask** parameter of the StridedSlice operator. |
455| OH_NN_STRIDED_SLICE_END_MASK  | This enumerated value is used when the tensor is used as the **EndMask** parameter of the StridedSlice operator. |
456| OH_NN_STRIDED_SLICE_ELLIPSIS_MASK  | This enumerated value is used when the tensor is used as the **EllipsisMask** parameter of the StridedSlice operator. |
457| OH_NN_STRIDED_SLICE_NEW_AXIS_MASK  | This enumerated value is used when the tensor is used as the **NewAxisMask** parameter of the StridedSlice operator. |
458| OH_NN_STRIDED_SLICE_SHRINK_AXIS_MASK  | This enumerated value is used when the tensor is used as the **ShrinkAxisMask** parameter of the StridedSlice operator. |
459| OH_NN_SUB_ACTIVATIONTYPE  | This enumerated value is used when the tensor is used as the **ActivationType** parameter of the Sub operator. |
460| OH_NN_REDUCE_MEAN_KEEP_DIMS  | This enumerated value is used when the tensor is used as the **keep_dims** parameter of the ReduceMean operator. |
461| OH_NN_RESIZE_BILINEAR_NEW_HEIGHT  | This enumerated value is used when the tensor is used as the **new_height** parameter of the ResizeBilinear operator. |
462| OH_NN_RESIZE_BILINEAR_NEW_WIDTH  | This enumerated value is used when the tensor is used as the **new_width** parameter of the ResizeBilinear operator. |
463| OH_NN_RESIZE_BILINEAR_PRESERVE_ASPECT_RATIO  | This enumerated value is used when the tensor is used as the **preserve_aspect_ratio** parameter of the ResizeBilinear operator. |
464| OH_NN_RESIZE_BILINEAR_COORDINATE_TRANSFORM_MODE  | This enumerated value is used when the tensor is used as the **coordinate_transform_mode** parameter of the ResizeBilinear operator. |
465| OH_NN_RESIZE_BILINEAR_EXCLUDE_OUTSIDE  | This enumerated value is used when the tensor is used as the **exclude_outside** parameter of the ResizeBilinear operator. |
466| OH_NN_LAYER_NORM_BEGIN_NORM_AXIS  | This enumerated value is used when the tensor is used as the **beginNormAxis** parameter of the LayerNorm operator. |
467| OH_NN_LAYER_NORM_EPSILON  | This enumerated value is used when the tensor is used as the **epsilon** parameter of the LayerNorm operator. |
468| OH_NN_LAYER_NORM_BEGIN_PARAM_AXIS  | This enumerated value is used when the tensor is used as the **beginParamsAxis** parameter of the LayerNorm operator. |
469| OH_NN_LAYER_NORM_ELEMENTWISE_AFFINE  | This enumerated value is used when the tensor is used as the **elementwiseAffine** parameter of the LayerNorm operator. |
470| OH_NN_REDUCE_PROD_KEEP_DIMS  | This enumerated value is used when the tensor is used as the **keep_dims** parameter of the ReduceProd operator. |
471| OH_NN_REDUCE_ALL_KEEP_DIMS  | This enumerated value is used when the tensor is used as the **keep_dims** parameter of the ReduceAll operator. |
472| OH_NN_QUANT_DTYPE_CAST_SRC_T  | This enumerated value is used when the tensor is used as the **src_t** parameter of the QuantDTypeCast operator. |
473| OH_NN_QUANT_DTYPE_CAST_DST_T  | This enumerated value is used when the tensor is used as the **dst_t** parameter of the QuantDTypeCast operator. |
474| OH_NN_TOP_K_SORTED  | This enumerated value is used when the tensor is used as the **Sorted** parameter of the Topk operator. |
475| OH_NN_ARG_MAX_AXIS  | This enumerated value is used when the tensor is used as the **axis** parameter of the ArgMax operator. |
476| OH_NN_ARG_MAX_KEEPDIMS  | This enumerated value is used when the tensor is used as the **keepDims** parameter of the ArgMax operator. |
477| OH_NN_UNSQUEEZE_AXIS  | This enumerated value is used when the tensor is used as the **Axis** parameter of the Unsqueeze operator. |
478
479
480## Function Description
481
482
483### OH_NNCompilation_Build()
484
485
486```
487OH_NN_ReturnCode OH_NNCompilation_Build (OH_NNCompilation * compilation)
488```
489**Description**<br>
490Compiles a model.
491
492After the compilation configuration is complete, call this method to return the compilation result. The compilation instance pushes the model and compilation options to the device for compilation. After this method is called, additional compilation operations cannot be performed. If the [OH_NNCompilation_SetDevice](#oh_nncompilation_setdevice), [OH_NNCompilation_SetCache](#oh_nncompilation_setcache), [OH_NNCompilation_SetPerformanceMode](#oh_nncompilation_setperformancemode), [OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority), and [OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16) methods are called, OH_NN_OPERATION_FORBIDDEN is returned.
493
494 **Parameters**
495
496| Name | Description |
497| -------- | -------- |
498| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.  |
499
500**Returns**
501
502Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
503
504
505
506### OH_NNCompilation_Construct()
507
508
509```
510OH_NNCompilation* OH_NNCompilation_Construct (const OH_NNModel * model)
511```
512**Description**<br>
513Creates a compilation instance of the [OH_NNCompilation](#oh_nncompilation) type.
514
515After the OH_NNModel module completes model construction, APIs provided by the OH_NNCompilation module pass the model to underlying device for compilation. This method creates a [OH_NNCompilation](#oh_nncompilation) instance based on the passed [OH_NNModel](#oh_nnmodel) instance. The [OH_NNCompilation_SetDevice](#oh_nncompilation_setdevice) method is called
516
517to set the device to compile on, and [OH_NNCompilation_Build](#oh_nncompilation_build) is then called to complete compilation.
518
519In addition to computing device selection, the OH_NNCompilation module supports features such as model caching, performance preference, priority setting, and float16 computing, which can be implemented by the following methods:
520
521- [OH_NNCompilation_SetCache](#oh_nncompilation_setcache)
522
523- [OH_NNCompilation_SetPerformanceMode](#oh_nncompilation_setperformancemode)
524
525- [OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority)
526
527- [OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16)
528
529After [OH_NNCompilation](#oh_nncompilation) is created by calling this method, the [OH_NNModel](#oh_nnmodel) instance can be released.
530
531 **Parameters**
532
533| Name | Description |
534| -------- | -------- |
535| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.  |
536
537**Returns**
538
539Returns the pointer to a [OH_NNCompilation](#oh_nncompilation) instance.
540
541
542### OH_NNCompilation_Destroy()
543
544
545```
546void OH_NNCompilation_Destroy (OH_NNCompilation ** compilation)
547```
548**Description**<br>
549Releases the **Compilation** object.
550
551This method needs to be called to release the compilation instance created by calling [OH_NNCompilation_Construct](#oh_nncompilation_construct). Otherwise, memory leak will occur.
552
553If **compilation** or **\*compilation** is a null pointer, this method only prints warning logs and does not execute the release logic.
554
555 **Parameters**
556
557| Name | Description |
558| -------- | -------- |
559| compilation | Level-2 pointer to the [OH_NNCompilation](#oh_nncompilation) instance. After a compilation instance is destroyed, this method sets **\*compilation** to a null pointer.  |
560
561
562### OH_NNCompilation_EnableFloat16()
563
564
565```
566OH_NN_ReturnCode OH_NNCompilation_EnableFloat16 (OH_NNCompilation * compilation, bool enableFloat16 )
567```
568**Description**<br>
569Enables float16 for computing.
570
571Currently, Neural Network Runtime supports only float32 and int8. If this method is called on a device that supports float16, float16 will be used for computing the float32 model to reduce memory usage and execution time.
572
573If this method is called on the device that does not support float16, the OH_NN_UNAVALIDABLE_DEVICE error code is returned.
574
575 **Parameters**
576
577| Name | Description |
578| -------- | -------- |
579| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.  |
580| enableFloat16 | Indicates whether to enable float16. If this parameter is set to **true**, float16 inference is performed. If this parameter is set to **false**, float32 inference is performed.  |
581
582**Returns**
583
584Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
585
586
587### OH_NNCompilation_SetCache()
588
589
590```
591OH_NN_ReturnCode OH_NNCompilation_SetCache (OH_NNCompilation * compilation, const char * cachePath, uint32_t version )
592```
593**Description**<br>
594Set the cache directory and version of the compiled model.
595
596On the device that supports caching, a model can be saved as a cache file after being compiled at the device driver layer. The model can be directly read from the cache file in the next compilation, saving recompilation time. This method performs different operations based on the passed cache directory and version:
597
598- No file exists in the cache directory: Caches the compiled model to the directory and sets the cache version to **version**.
599
600- A complete cache file exists in the cache directory, and its version is **version**: Reads the cache file in the path and passes the data to the underlying device for conversion into executable model instances.
601
602- A complete cache file exists in the cache directory, and its version is earlier than **version**: When model compilation is complete on the underlying device, overwrites the cache file and changes the version number to **version**.
603
604- A complete cache file exists in the cache directory, and its version is later than **version**: Returns the OH_NN_INVALID_PARAMETER error code without reading the cache file.
605
606- The cache file in the cache directory is incomplete or you do not have the permission to access the cache file. Returns the OH_NN_INVALID_FILE error code.
607
608- The cache directory does not exist or you do not have the access permission. Returns the OH_NN_INVALID_PATH error code.
609
610 **Parameters**
611
612| Name | Description |
613| -------- | -------- |
614| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.  |
615| cachePath | Directory for storing model cache files. This method creates directories for different devices in the **cachePath** directory. You are advised to use a separate cache directory for each model.  |
616| version | Cache version.  |
617
618**Returns**
619
620Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
621
622
623### OH_NNCompilation_SetDevice()
624
625
626```
627OH_NN_ReturnCode OH_NNCompilation_SetDevice (OH_NNCompilation * compilation, size_t deviceID )
628```
629**Description**<br>
630Specifies the device for model compilation and computing.
631
632In the compilation phase, you need to specify the device for model compilation and computing. Call [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid) to obtain available device IDs. Call [OH_NNDevice_GetType](#oh_nndevice_gettype) and [OH_NNDevice_GetName](#oh_nndevice_getname) to obtain device information and pass target device IDs to this method for setting.
633
634 **Parameters**
635
636| Name | Description |
637| -------- | -------- |
638| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.  |
639| deviceID | Device ID.  |
640
641**Returns**
642
643Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
644
645
646### OH_NNCompilation_SetPerformanceMode()
647
648
649```
650OH_NN_ReturnCode OH_NNCompilation_SetPerformanceMode (OH_NNCompilation * compilation, OH_NN_PerformanceMode performanceMode )
651```
652**Description**<br>
653Sets the performance mode for model computing.
654
655Neural Network Runtime allows you to set the performance mode for model computing to meet the requirements of low power consumption and ultimate performance. If this method is not called to set the performance mode in the compilation phase, the compilation instance assigns the OH_NN_PERFORMANCE_NONE mode for the model by default. In this case, the device performs computing in the default performance mode.
656
657If this method is called on the device that does not support the setting of the performance mode, the OH_NN_UNAVALIDABLE_DEVICE error code is returned.
658
659 **Parameters**
660
661| Name | Description |
662| -------- | -------- |
663| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.  |
664| performanceMode | Performance mode. For details about the available performance modes, see [OH_NN_PerformanceMode](#oh_nn_performancemode).  |
665
666**Returns**
667
668Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
669
670
671### OH_NNCompilation_SetPriority()
672
673
674```
675OH_NN_ReturnCode OH_NNCompilation_SetPriority (OH_NNCompilation * compilation, OH_NN_Priority priority )
676```
677**Description**<br>
678Sets the model computing priority.
679
680Neural Network Runtime allows you to set computing priorities for models.
681
682The priorities apply only to models created by the process with the same UID. The settings will not affect models created by processes with different UIDs on different devices.
683
684If this method is called on the device that does not support the priority setting, the OH_NN_UNAVALIDABLE_DEVICE error code is returned.
685
686 **Parameters**
687
688| Name | Description |
689| -------- | -------- |
690| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.  |
691| priority | Priority. For details about the optional priorities, see [OH_NN_Priority](#oh_nn_priority).  |
692
693**Returns**
694
695Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
696
697
698### OH_NNDevice_GetAllDevicesID()
699
700
701```
702OH_NN_ReturnCode OH_NNDevice_GetAllDevicesID (const size_t ** allDevicesID, uint32_t * deviceCount )
703```
704**Description**<br>
705Obtains the ID of the device connected to Neural Network Runtime.
706
707Each device has a unique and fixed ID in Neural Network Runtime. This method returns device IDs on the current device through the uint32_t array.
708
709Device IDs are returned through the size_t array. Each element of the array is the ID of a single device. The array memory is managed by Neural Network Runtime. The data pointer is valid before this method is called next time.
710
711 **Parameters**
712
713| Name | Description |
714| -------- | -------- |
715| allDevicesID | Pointer to the size_t array. The input **\*allDevicesID** must be a null pointer. Otherwise, OH_NN_INVALID_PARAMETER is returned. |
716| deviceCount | Pointer of the uint32_t type, which is used to return the length of **(\*allDevicesID)**.  |
717
718**Returns**
719
720Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
721
722
723### OH_NNDevice_GetName()
724
725
726```
727OH_NN_ReturnCode OH_NNDevice_GetName (size_t deviceID, const char ** name )
728```
729**Description**<br>
730Obtains the name of the specified device.
731
732**deviceID** specifies the device whose name will be obtained. The device ID needs to be obtained by calling [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid).
733
734 **Parameters**
735
736| Name | Description |
737| -------- | -------- |
738| deviceID | Device ID.  |
739| name | Pointer to the char array. The passed **(\*char)** must be a null pointer. Otherwise, OH_NN_INVALID_PARAMETER is returned. The value of **(\*name)** is a C-style string ended with **'\0'**.  |
740
741**Returns**
742
743Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
744
745
746### OH_NNDevice_GetType()
747
748
749```
750OH_NN_ReturnCode OH_NNDevice_GetType (size_t deviceID, OH_NN_DeviceType * deviceType )
751```
752**Description**<br>
753Obtains the type information of the specified device.
754
755**deviceID** specifies the device whose type will be obtained. Currently, Neural Network Runtime supports the following device types:
756
757- **OH_NN_CPU**: CPU device.
758
759- **OH_NN_GPU**: GPU device.
760
761- **OH_NN_ACCELERATOR**: machine learning dedicated accelerator.
762
763- **OH_NN_OTHERS**: other hardware types.
764
765**Parameters**
766
767| Name | Description |
768| -------- | -------- |
769| deviceID | Device ID. |
770| deviceType | Pointer to the [OH_NN_DeviceType](#oh_nn_devicetype) instance. The device type information is returned. |
771
772**Returns**
773
774Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
775
776
777### OH_NNExecutor_AllocateInputMemory()
778
779
780```
781OH_NN_Memory* OH_NNExecutor_AllocateInputMemory (OH_NNExecutor * executor, uint32_t inputIndex, size_t length )
782```
783**Description**<br>
784Allocates shared memory to a single input on a device.
785
786Neural Network Runtime provides a method for proactively allocating shared memory on a device. By specifying the executor and input index value, this method allocates shared memory whose size is specified by **length** on the device associated with a single input and returns the operation result through the [OH_NN_Memory](_o_h___n_n___memory.md) instance.
787
788 **Parameters**
789
790| Name | Description |
791| -------- | -------- |
792| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
793| inputIndex | Input index value, which is in the same sequence of the data input when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **inputIndices** is **{1, 5, 9}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. In the memory input application, the index value for the three inputs is **{0, 1, 2}**. |
794| length | Memory size to be applied for, in bytes.  |
795
796**Returns**
797
798Pointer to a [OH_NN_Memory](_o_h___n_n___memory.md) instance.
799
800
801### OH_NNExecutor_AllocateOutputMemory()
802
803
804```
805OH_NN_Memory* OH_NNExecutor_AllocateOutputMemory (OH_NNExecutor * executor, uint32_t outputIndex, size_t length )
806```
807**Description**<br>
808Allocates shared memory to a single output on a device.
809
810Neural Network Runtime provides a method for proactively allocating shared memory on a device. By specifying the executor and output index value, this method allocates shared memory whose size is specified by **length** on the device associated with a single output and returns the operation result through the [OH_NN_Memory](_o_h___n_n___memory.md) instance.
811
812 **Parameters**
813
814| Name | Description |
815| -------- | -------- |
816| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
817| outputIndex | Output Index value, which is in the same sequence of the data output when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **outputIndices** is **{4, 6, 8}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. In output memory application, the index value for the three outputs is **{0, 1, 2}**. |
818| length | Memory size to be applied for, in bytes.  |
819
820**Returns**
821
822Pointer to a [OH_NN_Memory](_o_h___n_n___memory.md) instance.
823
824
825### OH_NNExecutor_Construct()
826
827
828```
829OH_NNExecutor* OH_NNExecutor_Construct (OH_NNCompilation * compilation)
830```
831**Description**<br>
832Creates an executor instance of the [OH_NNExecutor](#oh_nnexecutor) type.
833
834This method constructs a model inference executor associated with the device based on the passed compiler. Use [OH_NNExecutor_SetInput](#oh_nnexecutor_setinput) to set the model input data. After the input data is set, call [OH_NNExecutor_Run](#oh_nnexecutor_run) to perform inference and then call [OH_NNExecutor_SetOutput](#oh_nnexecutor_setoutput) to obtain the computing result.
835
836After calling this method to create the [OH_NNExecutor](#oh_nnexecutor) instance, you can release the [OH_NNCompilation](#oh_nncompilation) instance if you do not need to create any other executors.
837
838 **Parameters**
839
840| Name | Description |
841| -------- | -------- |
842| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.  |
843
844**Returns**
845
846Pointer to a [OH_NNExecutor](#oh_nnexecutor) instance.
847
848
849### OH_NNExecutor_Destroy()
850
851
852```
853void OH_NNExecutor_Destroy (OH_NNExecutor ** executor)
854```
855**Description**<br>
856Destroys an executor instance to release the memory occupied by the executor.
857
858This method needs to be called to release the executor instance created by calling [OH_NNExecutor_Construct](#oh_nnexecutor_construct). Otherwise, memory leak will occur.
859
860If **executor** or **\*executor** is a null pointer, this method only prints warning logs and does not execute the release logic.
861
862 **Parameters**
863
864| Name | Description |
865| -------- | -------- |
866| executor | Level-2 pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
867
868
869### OH_NNExecutor_DestroyInputMemory()
870
871
872```
873void OH_NNExecutor_DestroyInputMemory (OH_NNExecutor * executor, uint32_t inputIndex, OH_NN_Memory ** memory )
874```
875**Description**<br>
876Releases the input memory to which the [OH_NN_Memory](_o_h___n_n___memory.md) instance points.
877
878This method needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateInputMemory](#oh_nnexecutor_allocateinputmemory). Otherwise, memory leak will occur. The mapping between **inputIndex** and **memory** must be the same as that in memory instance creation.
879
880If **memory** or **\*memory** is a null pointer, this method only prints warning logs and does not execute the release logic.
881
882 **Parameters**
883
884| Name | Description |
885| -------- | -------- |
886| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
887| inputIndex | Input index value, which is in the same sequence of the data input when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **inputIndices** is **{1, 5, 9}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. In memory input release, the index value for the three inputs is **{0, 1, 2}**. |
888| memory | Level-2 pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. After shared memory is destroyed, this method sets **\*memory** to a null pointer.  |
889
890
891### OH_NNExecutor_DestroyOutputMemory()
892
893
894```
895void OH_NNExecutor_DestroyOutputMemory (OH_NNExecutor * executor, uint32_t outputIndex, OH_NN_Memory ** memory )
896```
897**Description**<br>
898Releases the output memory to which the [OH_NN_Memory](_o_h___n_n___memory.md) instance points.
899
900This method needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateOutputMemory](#oh_nnexecutor_allocateoutputmemory). Otherwise, memory leak will occur. The mapping between **outputIndex** and **memory** must be the same as that in memory instance creation.
901
902If **memory** or **\*memory** is a null pointer, this method only prints warning logs and does not execute the release logic.
903
904 **Parameters**
905
906| Name | Description |
907| -------- | -------- |
908| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
909| outputIndex | Output Index value, which is in the same sequence of the data output when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **outputIndices** is **{4, 6, 8}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. In output memory release, the index value for the three outputs is **{0, 1, 2}**. |
910| memory | Level-2 pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. After shared memory is destroyed, this method sets **\*memory** to a null pointer.  |
911
912
913### OH_NNExecutor_GetOutputShape()
914
915
916```
917OH_NN_ReturnCode OH_NNExecutor_GetOutputShape (OH_NNExecutor * executor, uint32_t outputIndex, int32_t ** shape, uint32_t * shapeLength )
918```
919**Description**<br>
920Obtains the dimension information about the output tensor.
921
922After [OH_NNExecutor_Run](#oh_nnexecutor_run) is called to complete a single inference, call this method to obtain the specified output dimension information and number of dimensions. It is commonly used in dynamic shape input and output scenarios.
923
924 **Parameters**
925
926| Name | Description |
927| -------- | -------- |
928| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
929| outputIndex | Output Index value, which is in the same sequence of the data output when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that **outputIndices** is **{4, 6, 8}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When [OH_NNExecutor_GetOutputShape](#oh_nnexecutor_getoutputshape) is called to obtain dimension information about the output tensor, **outputIndices** is **{0, 1, 2}**. |
930| shape | Pointer to the int32_t array. The value of each element in the array is the length of the output tensor in each dimension.  |
931| shapeLength | Pointer to the uint32_t type. The number of output dimensions is returned.  |
932
933**Returns**
934
935Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
936
937
938### OH_NNExecutor_Run()
939
940
941```
942OH_NN_ReturnCode OH_NNExecutor_Run (OH_NNExecutor * executor)
943```
944**Description**<br>
945Performs inference.
946
947Performs end-to-end inference and computing of the model on the device associated with the executor.
948
949 **Parameters**
950
951| Name | Description |
952| -------- | -------- |
953| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
954
955**Returns**
956
957Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
958
959
960### OH_NNExecutor_SetInput()
961
962
963```
964OH_NN_ReturnCode OH_NNExecutor_SetInput (OH_NNExecutor * executor, uint32_t inputIndex, const OH_NN_Tensor * tensor, const void * dataBuffer, size_t length )
965```
966**Description**<br>
967Sets the single input data for a model.
968
969This method copies the data whose length is specified by **length** (in bytes) in **dataBuffer** to the shared memory of the underlying device. **inputIndex** specifies the input to be set and **tensor** sets information such as the input shape, type, and quantization parameters.
970
971Neural Network Runtime supports models with dynamical shape input. For fixed shape input and dynamic shape input scenarios, this method uses different processing policies.
972
973- Fixed shape input: The attributes of **tensor** must be the same as those of the tensor added by calling [OH_NNModel_AddTensor](#oh_nnmodel_addtensor) in the composition phase.
974
975- Dynamic shape input: In the composition phase, because the shape is not fixed, each value in **tensor.dimensions** must be greater than **0** in the method calls to determine the shape input in the calculation phase. When setting the shape, you can modify only the dimension whose value is **-1**. Assume that **[-1, 224, 224, 3]** is input as the the dimension of A in the composition phase. When this method is called, only the size of the first dimension can be modified, for example, to **[3, 224, 224, 3]**. If other dimensions are adjusted, OH_NN_INVALID_PARAMETER is returned.
976
977 **Parameters**
978
979| Name | Description |
980| -------- | -------- |
981| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
982| inputIndex | Input index value, which is in the same sequence of the data input when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **inputIndices** is **{1, 5, 9}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. In input settings, the index value for the three inputs is **{0, 1, 2}**. |
983| tensor | Sets the tensor corresponding to the input data.  |
984| dataBuffer | Pointer to the input data.  |
985| length | Length of the data buffer, in bytes.  |
986
987**Returns**
988
989Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
990
991
992### OH_NNExecutor_SetInputWithMemory()
993
994
995```
996OH_NN_ReturnCode OH_NNExecutor_SetInputWithMemory (OH_NNExecutor * executor, uint32_t inputIndex, const OH_NN_Tensor * tensor, const OH_NN_Memory * memory )
997```
998**Description**<br>
999Specifies the hardware shared memory pointed to by the [OH_NN_Memory](_o_h___n_n___memory.md) instance as the shared memory used by a single input.
1000
1001In scenarios where memory needs to be managed by yourself, this method binds the execution input to the [OH_NN_Memory](_o_h___n_n___memory.md) memory instance. During computing, the underlying device reads the input data from the shared memory pointed to by the memory instance. By using this method, concurrent execution of input setting, computing, and read can be implemented to improve inference efficiency of a data flow.
1002
1003 **Parameters**
1004
1005| Name | Description |
1006| -------- | -------- |
1007| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
1008| inputIndex | Input index value, which is in the same sequence of the data input when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **inputIndices** is **{1, 5, 9}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When the input shared memory is specified, the index value for the three inputs is **{0, 1, 2}**. |
1009| tensor | Pointer to [OH_NN_Tensor](_o_h___n_n___tensor.md), used to set the tensor corresponding to a single input.  |
1010| memory | Pointer to [OH_NN_Memory](_o_h___n_n___memory.md).  |
1011
1012**Returns**
1013
1014Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1015
1016
1017### OH_NNExecutor_SetOutput()
1018
1019
1020```
1021OH_NN_ReturnCode OH_NNExecutor_SetOutput (OH_NNExecutor * executor, uint32_t outputIndex, void * dataBuffer, size_t length )
1022```
1023**Description**<br>
1024Sets the buffer for a single output of a model.
1025
1026This method binds the buffer to which **dataBuffer** points to the output specified by **outputIndex**. The length of the buffer is specified by **length**.
1027
1028After [OH_NNExecutor_Run](#oh_nnexecutor_run) is called to complete a single model inference, Neural Network Runtime compares the length of the buffer to which **dataBuffer** points with the length of the output data and returns different results based on the actual situation.
1029
1030- If the buffer length is greater than or equal to the data length, the inference result is copied to the buffer and OH_NN_SUCCESS is returned. You can read the inference result from **dataBuffer**.
1031
1032- If the buffer length is smaller than the data length, [OH_NNExecutor_Run](#oh_nnexecutor_run) returns OH_NN_INVALID_PARAMETER and generates a log indicating that the buffer is too small.
1033
1034 **Parameters**
1035
1036| Name | Description |
1037| -------- | -------- |
1038| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.  |
1039| outputIndex | Output Index value, which is in the same sequence of the data output when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **outputIndices** is **{4, 6, 8}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. In output buffer settings, the index value for the three outputs is **{0, 1, 2}**. |
1040| dataBuffer | Pointer to the output data.  |
1041| length | Length of the data buffer, in bytes.  |
1042
1043**Returns**
1044
1045Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1046
1047
1048### OH_NNExecutor_SetOutputWithMemory()
1049
1050
1051```
1052OH_NN_ReturnCode OH_NNExecutor_SetOutputWithMemory (OH_NNExecutor * executor, uint32_t outputIndex, const OH_NN_Memory * memory )
1053```
1054**Description**<br>
1055Specifies the hardware shared memory pointed to by the [OH_NN_Memory](_o_h___n_n___memory.md) instance as the shared memory used by a single output.
1056
1057In scenarios where memory needs to be managed by yourself, this method binds the execution output to the [OH_NN_Memory](_o_h___n_n___memory.md) memory instance. When computing is performed, the underlying hardware directly writes the computing result to the shared memory to which the memory instance points. By using this method, concurrent execution of input setting, computing, and read can be implemented to improve inference efficiency of a data flow.
1058
1059 **Parameters**
1060
1061| Name | Description |
1062| -------- | -------- |
1063| executor | Executor.  |
1064| outputIndex | Output Index value, which is in the same sequence of the data output when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. Assume that the value of **outputIndices** is **{4, 6, 8}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When output shared memory is specified, the index value for the three outputs is **{0, 1, 2}**. |
1065| memory | Pointer to [OH_NN_Memory](_o_h___n_n___memory.md).  |
1066
1067**Returns**
1068
1069Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1070
1071
1072### OH_NNModel_AddOperation()
1073
1074
1075```
1076OH_NN_ReturnCode OH_NNModel_AddOperation (OH_NNModel * model, OH_NN_OperationType op, const OH_NN_UInt32Array * paramIndices, const OH_NN_UInt32Array * inputIndices, const OH_NN_UInt32Array * outputIndices )
1077```
1078**Description**<br>
1079Adds an operator to a model instance.
1080
1081This method is used to add an operator to a model instance. The operator type is specified by **op**, and the operator parameters, inputs, and outputs are specified by **paramIndices**, **inputIndices**, and **outputIndices** respectively. This method verifies the attributes of operator parameters and the number of input and output parameters. These attributes must be correctly set when [OH_NNModel_AddTensor](#oh_nnmodel_addtensor) is called to add tensors. For details about the expected parameters, input attributes, and output attributes of each operator, see [OH_NN_OperationType](#oh_nn_operationtype).
1082
1083**paramIndices**, **inputIndices**, and **outputIndices** store index values of tensors. Index values are determined by the sequence in which tensors are added to the model. For details about how to add a tensor, see [OH_NNModel_AddTensor](#oh_nnmodel_addtensor).
1084
1085If unnecessary parameters are added for adding an operator, this method returns OH_NN_INVALID_PARAMETER. If no operator parameter is set, the operator uses the default parameter value. For details about the default values, see [OH_NN_OperationType](#oh_nn_operationtype).
1086
1087 **Parameters**
1088
1089| Name | Description |
1090| -------- | -------- |
1091| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.  |
1092| op | Specifies the type of an operator to be added. For details, see the enumerated values of [OH_NN_OperationType](#oh_nn_operationtype).  |
1093| paramIndices | Pointer to the **[OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md)** instance, which is used to set operator parameters.  |
1094| inputIndices | Pointer to the **[OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md)** instance, which is used to set the operator input.  |
1095| outputIndices | Pointer to the **[OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md)** instance, which is used to set the operator output.  |
1096
1097**Returns**
1098
1099Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1100
1101
1102### OH_NNModel_AddTensor()
1103
1104
1105```
1106OH_NN_ReturnCode OH_NNModel_AddTensor (OH_NNModel * model, const OH_NN_Tensor * tensor )
1107```
1108**Description**<br>
1109Adds a tensor to a model instance.
1110
1111The data node and operator parameters in the Neural Network Runtime model are composed of tensors of the model. This method is used to add tensors to a model instance based on the **tensor** parameter. The sequence of adding tensors is specified by the index value recorded in the model. The [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata), [OH_NNModel_AddOperation](#oh_nnmodel_addoperation), and [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) methods specifies tensors based on the index value.
1112
1113Neural Network Runtime supports inputs and outputs of the dynamic shape. When adding a data node with a dynamic shape, you need to set the dimensions that support dynamic changes in **tensor.dimensions** to **-1**. For example, if **tensor.dimensions** of a four-dimensional tensor is set to **[1, -1, 2, 2]**, the second dimension supports dynamic changes.
1114
1115 **Parameters**
1116
1117| Name | Description |
1118| -------- | -------- |
1119| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.  |
1120| tensor | Pointer to the [OH_NN_Tensor](_o_h___n_n___tensor.md) tensor. The tensor specifies the attributes of the tensor added to the model instance.  |
1121
1122**Returns**
1123
1124Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1125
1126
1127### OH_NNModel_Construct()
1128
1129
1130```
1131OH_NNModel* OH_NNModel_Construct (void )
1132```
1133**Description**<br>
1134Creates a model instance of the [OH_NNModel](#oh_nnmodel) type and uses other APIs provided by OH_NNModel to construct the model instance.
1135
1136Before composition, call [OH_NNModel_Construct](#oh_nnmodel_construct) to create a model instance. Based on the model topology, call the [OH_NNModel_AddTensor](#oh_nnmodel_addtensor), [OH_NNModel_AddOperation](#oh_nnmodel_addoperation), and [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata) methods to fill in the data and operator nodes of the model, and then call [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) to specify the inputs and outputs of the model. After the model topology is constructed, call [OH_NNModel_Finish](#oh_nnmodel_finish) to build the model.
1137
1138After a model instance is used, you need to destroy it by calling [OH_NNModel_Destroy](#oh_nnmodel_destroy) to avoid memory leak.
1139
1140**Returns**
1141
1142Returns the pointer to a [OH_NNModel](#oh_nnmodel) instance.
1143
1144
1145### OH_NNModel_Destroy()
1146
1147
1148```
1149void OH_NNModel_Destroy (OH_NNModel ** model)
1150```
1151**Description**<br>
1152Releases a model instance.
1153
1154This method needs to be called to release the model instance created by calling [OH_NNModel_Construct](#oh_nnmodel_construct). Otherwise, memory leak will occur.
1155
1156If **model** or **\*model** is a null pointer, this method only prints warning logs and does not execute the release logic.
1157
1158 **Parameters**
1159
1160| Name | Description |
1161| -------- | -------- |
1162| model | Level-2 pointer to the [OH_NNModel](#oh_nnmodel) instance. After a model instance is destroyed, this method sets **\*model** to a null pointer.  |
1163
1164
1165### OH_NNModel_Finish()
1166
1167
1168```
1169OH_NN_ReturnCode OH_NNModel_Finish (OH_NNModel * model)
1170```
1171**Description**<br>
1172Completes model composition.
1173
1174After the model topology is set up, call this method to indicate that the composition is complete. After this method is called, additional composition operations cannot be performed. If [OH_NNModel_AddTensor](#oh_nnmodel_addtensor), [OH_NNModel_AddOperation](#oh_nnmodel_addoperation), [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata), and [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) are called, OH_NN_OPERATION_FORBIDDEN is returned.
1175
1176Before calling [OH_NNModel_GetAvailableOperations](#oh_nnmodel_getavailableoperations) and [OH_NNCompilation_Construct](#oh_nncompilation_construct), you must call this method to complete composition.
1177
1178 **Parameters**
1179
1180| Name | Description |
1181| -------- | -------- |
1182| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.  |
1183
1184**Returns**
1185
1186Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1187
1188
1189### OH_NNModel_GetAvailableOperations()
1190
1191
1192```
1193OH_NN_ReturnCode OH_NNModel_GetAvailableOperations (OH_NNModel * model, size_t deviceID, const bool ** isSupported, uint32_t * opCount )
1194```
1195**Description**<br>
1196Queries whether the device supports operators in the model. The support status is indicated by the Boolean value.
1197
1198Queries whether underlying device supports operators in a model instance. The device is specified by **deviceID**, and the result is represented by the array pointed by **isSupported**. If the ith operator is supported, the value of **(\*isSupported)**[i] is **true**. Otherwise, the value is **false**.
1199
1200After this method is successfully executed, **(\*isSupported)** points to the bool array that records the operator support status. The operator quantity for the array length is the same as that for the model instance. The memory corresponding to this array is managed by Neural Network Runtime and is automatically destroyed after the model instance is destroyed or this method is called again.
1201
1202 **Parameters**
1203
1204| Name | Description |
1205| -------- | -------- |
1206| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.  |
1207| deviceID | Device ID to be queried, which can be obtained by using [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid).  |
1208| isSupported | Pointer to the bool array. When this method is called, **(\*isSupported)** must be a null pointer. Otherwise, OH_NN_INVALID_PARAMETER is returned. |
1209| opCount | Number of operators in a model instance, corresponding to the length of the **(\*isSupported)** array.  |
1210
1211**Returns**
1212
1213Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1214
1215
1216### OH_NNModel_SetTensorData()
1217
1218
1219```
1220OH_NN_ReturnCode OH_NNModel_SetTensorData (OH_NNModel * model, uint32_t index, const void * dataBuffer, size_t length )
1221```
1222**Description**<br>
1223Sets the tensor value.
1224
1225For tensors with constant values (such as model weights), you need to use this method in the composition phase. The index value of a tensor is determined by the sequence in which the tensor is added to the model. For details about how to add a tensor, see [OH_NNModel_AddTensor](#oh_nnmodel_addtensor).
1226
1227 **Parameters**
1228
1229| Name | Description |
1230| -------- | -------- |
1231| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.  |
1232| index | Index value of a tensor.  |
1233| dataBuffer | Pointer to real data.  |
1234| length | Length of the data buffer.  |
1235
1236**Returns**
1237
1238Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).
1239
1240
1241### OH_NNModel_SpecifyInputsAndOutputs()
1242
1243
1244```
1245OH_NN_ReturnCode OH_NNModel_SpecifyInputsAndOutputs (OH_NNModel * model, const OH_NN_UInt32Array * inputIndices, const OH_NN_UInt32Array * outputIndices )
1246```
1247**Description**<br>
1248Specifies the inputs and outputs of a model.
1249
1250A tensor must be specified as the end-to-end inputs and outputs of a model instance. This type of tensor cannot be set using [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata). The **OH_NNExecutor** method needs to be called in the execution phase to set the input and output data.
1251
1252The index value of a tensor is determined by the sequence in which the tensor is added to the model. For details about how to add a tensor, see [OH_NNModel_AddTensor](#oh_nnmodel_addtensor).
1253
1254Currently, the model inputs and outputs cannot be set asynchronously.
1255
1256 **Parameters**
1257
1258| Name | Description |
1259| -------- | -------- |
1260| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.  |
1261| inputIndices | Pointer to the **[OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md)** instance, which is used to set the operator input.  |
1262| outputIndices | Pointer to the **[OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md)** instance, which is used to set the operator output.  |
1263
1264**Returns**
1265
1266Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error code is returned. For details about the error codes, see [OH_NN_ReturnCode](#oh_nn_returncode).