1# NeuralNeworkRuntime 2 3 4## Overview 5 6Provides APIs for accelerating the Neural Network Runtime (NNRt) model inference. 7 8**Since**: 9 9 10**System capability**: \@Syscap SystemCapability.Ai.NeuralNetworkRuntime 11 12 13## Summary 14 15 16### File 17 18| Name| Description| 19| -------- | -------- | 20| [neural_network_core.h](neural__network__core_8h.md) | Defines APIs for the Neural Network Core module. The AI inference framework uses the native interfaces provided by Neural Network Core to build models and perform inference and computing on acceleration device.| 21| [neural_network_runtime.h](neural__network__runtime_8h.md) | Defines APIs for NNRt. The AI inference framework uses the native APIs provided by the NNRt to construct and build models.| 22| [neural_network_runtime_type.h](neural__network__runtime__type_8h.md) | Defines the structure and enums for NNRt.| 23 24 25### Structs 26 27| Name| Description| 28| -------- | -------- | 29| [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) | Used to store a 32-bit unsigned integer array.| 30| [OH_NN_QuantParam](_o_h___n_n___quant_param.md) | Used to define the quantization information.| 31| [OH_NN_Tensor](_o_h___n_n___tensor.md) | Used to define the tensor structure.| 32| [OH_NN_Memory](_o_h___n_n___memory.md) | Used to define the memory structure.| 33 34 35### Types 36 37| Name| Description| 38| -------- | -------- | 39| [OH_NNModel](#oh_nnmodel) | Model handle.| 40| [OH_NNCompilation](#oh_nncompilation) | Compiler handle.| 41| [OH_NNExecutor](#oh_nnexecutor) | Executor handle.| 42| [NN_QuantParam](#nn_quantparam) | Quantization parameter handle.| 43| [NN_TensorDesc](#nn_tensordesc) | Tensor description handle.| 44| [NN_Tensor](#nn_tensor) | Tensor handle.| 45| (\*[NN_OnRunDone](#nn_onrundone)) (void \*userData, [OH_NN_ReturnCode](#oh_nn_returncode) errCode, void \*outputTensor[], int32_t outputCount) | Handle of the callback processing function invoked when the asynchronous inference ends.| 46| (\*[NN_OnServiceDied](#nn_onservicedied)) (void \*userData) | Handle of the callback processing function invoked when the device driver service terminates unexpectedly during asynchronous inference.| 47| [OH_NN_UInt32Array](#oh_nn_uint32array) | Used to store a 32-bit unsigned integer array.| 48| [OH_NN_QuantParam](#oh_nn_quantparamdeprecated) | Used to define the quantization information.| 49| [OH_NN_Tensor](#oh_nn_tensordeprecated) | Used to define the tensor structure.| 50| [OH_NN_Memory](#oh_nn_memorydeprecated) | Used to define the memory structure.| 51 52 53### Enums 54 55| Name| Description| 56| -------- | -------- | 57| [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>} | Performance modes of the device.| 58| [OH_NN_Priority](#oh_nn_priority) {<br>OH_NN_PRIORITY_NONE = 0, OH_NN_PRIORITY_LOW = 1, OH_NN_PRIORITY_MEDIUM = 2, OH_NN_PRIORITY_HIGH = 3<br>} | Priorities of a model inference task.| 59| [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,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, OH_NN_TIMEOUT = 9, OH_NN_UNSUPPORTED = 10, OH_NN_CONNECTION_EXCEPTION = 11,OH_NN_SAVE_CACHE_EXCEPTION = 12, OH_NN_DYNAMIC_SHAPE = 13, OH_NN_UNAVAILABLE_DEVICE = 14<br>} | Error codes for NNRt.| 60| [OH_NN_FuseType](#oh_nn_fusetype) : int8_t {<br>OH_NN_FUSED_NONE = 0, OH_NN_FUSED_RELU = 1, OH_NN_FUSED_RELU6 = 2<br>} | Activation function types in the fusion operator for NNRt.| 61| [OH_NN_Format](#oh_nn_format) {<br>OH_NN_FORMAT_NONE = 0, OH_NN_FORMAT_NCHW = 1, OH_NN_FORMAT_NHWC = 2, OH_NN_FORMAT_ND = 3<br>} | Formats of tensor data.| 62| [OH_NN_DeviceType](#oh_nn_devicetype) {<br>OH_NN_OTHERS = 0, OH_NN_CPU = 1,<br>OH_NN_GPU = 2, OH_NN_ACCELERATOR = 3<br>} | Device types supported by NNRt.| 63| [OH_NN_DataType](#oh_nn_datatype) {<br>OH_NN_UNKNOWN = 0, OH_NN_BOOL = 1, OH_NN_INT8 = 2, OH_NN_INT16 = 3,OH_NN_INT32 = 4, OH_NN_INT64 = 5, OH_NN_UINT8 = 6, OH_NN_UINT16 = 7,OH_NN_UINT32 = 8, OH_NN_UINT64 = 9, OH_NN_FLOAT16 = 10, OH_NN_FLOAT32 = 11,OH_NN_FLOAT64 = 12<br>} | Data types supported by NNRt.| 64| [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,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,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,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>} | Operator types supported by NNRt.| 65| [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,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>} | Tensor types.| 66 67 68### Functions 69 70| Name| Description| 71| -------- | -------- | 72| \*[OH_NNCompilation_Construct](#oh_nncompilation_construct) (const [OH_NNModel](#oh_nnmodel) \*model) | Creates a model building instance of the [OH_NNCompilation](#oh_nncompilation) type.| 73| \*[OH_NNCompilation_ConstructWithOfflineModelFile](#oh_nncompilation_constructwithofflinemodelfile) (const char \*modelPath) | Creates a model building instance based on an offline model file.| 74| \*[OH_NNCompilation_ConstructWithOfflineModelBuffer](#oh_nncompilation_constructwithofflinemodelbuffer) (const void \*modelBuffer, size_t modelSize) | Creates a model building instance based on the offline model buffer.| 75| \*[OH_NNCompilation_ConstructForCache](#oh_nncompilation_constructforcache) () | Creates an empty model building instance for later recovery from the model cache.| 76| [OH_NNCompilation_ExportCacheToBuffer](#oh_nncompilation_exportcachetobuffer) ([OH_NNCompilation](#oh_nncompilation) \*compilation, const void \*buffer, size_t length, size_t \*modelSize) | Writes the model cache to the specified buffer.| 77| [OH_NNCompilation_ImportCacheFromBuffer](#oh_nncompilation_importcachefrombuffer) ([OH_NNCompilation](#oh_nncompilation) \*compilation, const void \*buffer, size_t modelSize) | Reads the model cache from the specified buffer.| 78| [OH_NNCompilation_AddExtensionConfig](#oh_nncompilation_addextensionconfig) ([OH_NNCompilation](#oh_nncompilation) \*compilation, const char \*configName, const void \*configValue, const size_t configValueSize) | Adds extended configurations for custom device attributes.| 79| [OH_NNCompilation_SetDevice](#oh_nncompilation_setdevice) ([OH_NNCompilation](#oh_nncompilation) \*compilation, size_t deviceID) | Sets the device for model building and computing.| 80| [OH_NNCompilation_SetCache](#oh_nncompilation_setcache) ([OH_NNCompilation](#oh_nncompilation) \*compilation, const char \*cachePath, uint32_t version) | Sets the cache directory and version for model building.| 81| [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.| 82| [OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority) ([OH_NNCompilation](#oh_nncompilation) \*compilation, [OH_NN_Priority](#oh_nn_priority) priority) | Sets the priority for model computing.| 83| [OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16) ([OH_NNCompilation](#oh_nncompilation) \*compilation, bool enableFloat16) | Enables float16 for computing.| 84| [OH_NNCompilation_Build](#oh_nncompilation_build) ([OH_NNCompilation](#oh_nncompilation) \*compilation) | Performs model building.| 85| [OH_NNCompilation_Destroy](#oh_nncompilation_destroy) ([OH_NNCompilation](#oh_nncompilation) \*\*compilation) | Destroys a model building instance of the [OH_NNCompilation](#oh_nncompilation) type.| 86| \*[OH_NNTensorDesc_Create](#oh_nntensordesc_create) () | Creates an [NN_TensorDesc](#nn_tensordesc) instance.| 87| [OH_NNTensorDesc_Destroy](#oh_nntensordesc_destroy) ([NN_TensorDesc](#nn_tensordesc) \*\*tensorDesc) | Releases an [NN_TensorDesc](#nn_tensordesc) instance.| 88| [OH_NNTensorDesc_SetName](#oh_nntensordesc_setname) ([NN_TensorDesc](#nn_tensordesc) \*tensorDesc, const char \*name) | Sets the name of an [NN_TensorDesc](#nn_tensordesc) instance.| 89| [OH_NNTensorDesc_GetName](#oh_nntensordesc_getname) (const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, const char \*\*name) | Obtains the name of an [NN_TensorDesc](#nn_tensordesc) instance.| 90| [OH_NNTensorDesc_SetDataType](#oh_nntensordesc_setdatatype) ([NN_TensorDesc](#nn_tensordesc) \*tensorDesc, [OH_NN_DataType](#oh_nn_datatype) dataType) | Sets the data type of an [NN_TensorDesc](#nn_tensordesc) instance.| 91| [OH_NNTensorDesc_GetDataType](#oh_nntensordesc_getdatatype) (const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, [OH_NN_DataType](#oh_nn_datatype) \*dataType) | Obtains the data type of an [NN_TensorDesc](#nn_tensordesc) instance.| 92| [OH_NNTensorDesc_SetShape](#oh_nntensordesc_setshape) ([NN_TensorDesc](#nn_tensordesc) \*tensorDesc, const int32_t \*shape, size_t shapeLength) | Sets the data shape of an [NN_TensorDesc](#nn_tensordesc) instance.| 93| [OH_NNTensorDesc_GetShape](#oh_nntensordesc_getshape) (const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, int32_t \*\*shape, size_t \*shapeLength) | Obtains the shape of an [NN_TensorDesc](#nn_tensordesc) instance.| 94| [OH_NNTensorDesc_SetFormat](#oh_nntensordesc_setformat) ([NN_TensorDesc](#nn_tensordesc) \*tensorDesc, [OH_NN_Format](#oh_nn_format) format) | Sets the data format of an [NN_TensorDesc](#nn_tensordesc) instance.| 95| [OH_NNTensorDesc_GetFormat](#oh_nntensordesc_getformat) (const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, [OH_NN_Format](#oh_nn_format) \*format) | Obtains the data format of an [NN_TensorDesc](#nn_tensordesc) instance.| 96| [OH_NNTensorDesc_GetElementCount](#oh_nntensordesc_getelementcount) (const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, size_t \*elementCount) | Obtains the number of elements in an [NN_TensorDesc](#nn_tensordesc) instance.| 97| [OH_NNTensorDesc_GetByteSize](#oh_nntensordesc_getbytesize) (const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, size_t \*byteSize) | Obtains the number of bytes occupied by the tensor data obtained through calculation based on the shape and data type of an [NN_TensorDesc](#nn_tensordesc) instance.| 98| \*[OH_NNTensor_Create](#oh_nntensor_create) (size_t deviceID, [NN_TensorDesc](#nn_tensordesc) \*tensorDesc) | Creates an [NN_Tensor](#nn_tensor) instance from [NN_TensorDesc](#nn_tensordesc).| 99| \*[OH_NNTensor_CreateWithSize](#oh_nntensor_createwithsize) (size_t deviceID, [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, size_t size) | Creates an [NN_Tensor](#nn_tensor) instance based on the specified memory size and [NN_TensorDesc](#nn_tensordesc) instance.| 100| \*[OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd) (size_t deviceID, [NN_TensorDesc](#nn_tensordesc) \*tensorDesc, int fd, size_t size, size_t offset) | Creates an {\@Link NN_Tensor} instance based on the specified file descriptor of the shared memory and [NN_TensorDesc](#nn_tensordesc) instance.| 101| [OH_NNTensor_Destroy](#oh_nntensor_destroy) ([NN_Tensor](#nn_tensor) \*\*tensor) | Destroys an [NN_Tensor](#nn_tensor) instance.| 102| \*[OH_NNTensor_GetTensorDesc](#oh_nntensor_gettensordesc) (const [NN_Tensor](#nn_tensor) \*tensor) | Obtains an [NN_TensorDesc](#nn_tensordesc) instance of [NN_Tensor](#nn_tensor).| 103| \*[OH_NNTensor_GetDataBuffer](#oh_nntensor_getdatabuffer) (const [NN_Tensor](#nn_tensor) \*tensor) | Obtains the memory address of [NN_Tensor](#nn_tensor) data.| 104| [OH_NNTensor_GetFd](#oh_nntensor_getfd) (const [NN_Tensor](#nn_tensor) \*tensor, int \*fd) | Obtains the file descriptor of the shared memory where [NN_Tensor](#nn_tensor) data is stored.| 105| [OH_NNTensor_GetSize](#oh_nntensor_getsize) (const [NN_Tensor](#nn_tensor) \*tensor, size_t \*size) | Obtains the size of the shared memory where the [NN_Tensor](#nn_tensor) data is stored.| 106| [OH_NNTensor_GetOffset](#oh_nntensor_getoffset) (const [NN_Tensor](#nn_tensor) \*tensor, size_t \*offset) | Obtains the offset of [NN_Tensor](#nn_tensor) data in the shared memory.| 107| \*[OH_NNExecutor_Construct](#oh_nnexecutor_construct) ([OH_NNCompilation](#oh_nncompilation) \*compilation) | Creates an [OH_NNExecutor](#oh_nnexecutor) instance.| 108| [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.| 109| [OH_NNExecutor_Destroy](#oh_nnexecutor_destroy) ([OH_NNExecutor](#oh_nnexecutor) \*\*executor) | Destroys an executor instance to release the memory occupied by it.| 110| [OH_NNExecutor_GetInputCount](#oh_nnexecutor_getinputcount) (const [OH_NNExecutor](#oh_nnexecutor) \*executor, size_t \*inputCount) | Obtains the number of input tensors.| 111| [OH_NNExecutor_GetOutputCount](#oh_nnexecutor_getoutputcount) (const [OH_NNExecutor](#oh_nnexecutor) \*executor, size_t \*outputCount) | Obtains the number of output tensors.| 112| \*[OH_NNExecutor_CreateInputTensorDesc](#oh_nnexecutor_createinputtensordesc) (const [OH_NNExecutor](#oh_nnexecutor) \*executor, size_t index) | Creates the description of an input tensor based on the specified index value.| 113| \*[OH_NNExecutor_CreateOutputTensorDesc](#oh_nnexecutor_createoutputtensordesc) (const [OH_NNExecutor](#oh_nnexecutor) \*executor, size_t index) | Creates the description of an output tensor based on the specified index value.| 114| [OH_NNExecutor_GetInputDimRange](#oh_nnexecutor_getinputdimrange) (const [OH_NNExecutor](#oh_nnexecutor) \*executor, size_t index, size_t \*\*minInputDims, size_t \*\*maxInputDims, size_t \*shapeLength) | Obtains the dimension range of all input tensors.| 115| [OH_NNExecutor_SetOnRunDone](#oh_nnexecutor_setonrundone) ([OH_NNExecutor](#oh_nnexecutor) \*executor, [NN_OnRunDone](#nn_onrundone) onRunDone) | Sets the callback processing function invoked when the asynchronous inference ends.| 116| [OH_NNExecutor_SetOnServiceDied](#oh_nnexecutor_setonservicedied) ([OH_NNExecutor](#oh_nnexecutor) \*executor, [NN_OnServiceDied](#nn_onservicedied) onServiceDied) | Sets the callback processing function invoked when the device driver service terminates unexpectedly during asynchronous inference.| 117| [OH_NNExecutor_RunSync](#oh_nnexecutor_runsync) ([OH_NNExecutor](#oh_nnexecutor) \*executor, [NN_Tensor](#nn_tensor) \*inputTensor[], size_t inputCount, [NN_Tensor](#nn_tensor) \*outputTensor[], size_t outputCount) | Performs synchronous inference.| 118| [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync) ([OH_NNExecutor](#oh_nnexecutor) \*executor, [NN_Tensor](#nn_tensor) \*inputTensor[], size_t inputCount, [NN_Tensor](#nn_tensor) \*outputTensor[], size_t outputCount, int32_t timeout, void \*userData) | Performs asynchronous inference.| 119| [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid) (const size_t \*\*allDevicesID, uint32_t \*deviceCount) | Obtains the ID of the device connected to NNRt.| 120| [OH_NNDevice_GetName](#oh_nndevice_getname) (size_t deviceID, const char \*\*name) | Obtains the name of the specified device.| 121| [OH_NNDevice_GetType](#oh_nndevice_gettype) (size_t deviceID, [OH_NN_DeviceType](#oh_nn_devicetype) \*deviceType) | Obtains the type of the specified device.| 122| \*[OH_NNQuantParam_Create](#oh_nnquantparam_create) () | Creates an [NN_QuantParam](#nn_quantparam) instance.| 123| [OH_NNQuantParam_SetScales](#oh_nnquantparam_setscales) ([NN_QuantParam](#nn_quantparam) \*quantParams, const double \*scales, size_t quantCount) | Sets the scaling coefficient for an [NN_QuantParam](#nn_quantparam) instance.| 124| [OH_NNQuantParam_SetZeroPoints](#oh_nnquantparam_setzeropoints) ([NN_QuantParam](#nn_quantparam) \*quantParams, const int32_t \*zeroPoints, size_t quantCount) | Sets the zero point for an [NN_QuantParam](#nn_quantparam) instance.| 125| [OH_NNQuantParam_SetNumBits](#oh_nnquantparam_setnumbits) ([NN_QuantParam](#nn_quantparam) \*quantParams, const uint32_t \*numBits, size_t quantCount) | Sets the number of quantization bits for an [NN_QuantParam](#nn_quantparam) instance.| 126| [OH_NNQuantParam_Destroy](#oh_nnquantparam_destroy) ([NN_QuantParam](#nn_quantparam) \*\*quantParams) | Destroys an [NN_QuantParam](#nn_quantparam) instance.| 127| \*[OH_NNModel_Construct](#oh_nnmodel_construct) (void) | Creates a model instance of the [OH_NNModel](#oh_nnmodel) type and constructs a model instance by using the APIs provided by **OH_NNModel**.| 128| [OH_NNModel_AddTensorToModel](#oh_nnmodel_addtensortomodel) ([OH_NNModel](#oh_nnmodel) \*model, const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc) | Adds a tensor to a model instance.| 129| [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata) ([OH_NNModel](#oh_nnmodel) \*model, uint32_t index, const void \*dataBuffer, size_t length) | Sets the tensor value.| 130| [OH_NNModel_SetTensorQuantParams](#oh_nnmodel_settensorquantparams) ([OH_NNModel](#oh_nnmodel) \*model, uint32_t index, [NN_QuantParam](#nn_quantparam) \*quantParam) | Sets the quantization parameters of a tensor. For details, see [NN_QuantParam](#nn_quantparam).| 131| [OH_NNModel_SetTensorType](#oh_nnmodel_settensortype) ([OH_NNModel](#oh_nnmodel) \*model, uint32_t index, [OH_NN_TensorType](#oh_nn_tensortype) tensorType) | Sets the tensor type. For details, see [OH_NN_TensorType](#oh_nn_tensortype).| 132| [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.| 133| [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) | Sets an index value for the input and output tensors of a model.| 134| [OH_NNModel_Finish](#oh_nnmodel_finish) ([OH_NNModel](#oh_nnmodel) \*model) | Completes model composition.| 135| [OH_NNModel_Destroy](#oh_nnmodel_destroy) ([OH_NNModel](#oh_nnmodel) \*\*model) | Destroys a model instance.| 136| [OH_NNModel_GetAvailableOperations](#oh_nnmodel_getavailableoperations) ([OH_NNModel](#oh_nnmodel) \*model, size_t deviceID, const bool \*\*isSupported, uint32_t \*opCount) | Checks whether all operators in a model are supported by the device. The result is indicated by a Boolean value.| 137| [OH_NNModel_AddTensor](#oh_nnmodel_addtensordeprecated) ([OH_NNModel](#oh_nnmodel) \*model, const [OH_NN_Tensor](_o_h___n_n___tensor.md) \*tensor) | Adds a tensor to a model instance.| 138| [OH_NNExecutor_SetInput](#oh_nnexecutor_setinputdeprecated) ([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 data for a single model input.| 139| [OH_NNExecutor_SetOutput](#oh_nnexecutor_setoutputdeprecated) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, void \*dataBuffer, size_t length) | Sets the memory for a single model output.| 140| [OH_NNExecutor_Run](#oh_nnexecutor_rundeprecated) ([OH_NNExecutor](#oh_nnexecutor) \*executor) | Executes model inference.| 141| \*[OH_NNExecutor_AllocateInputMemory](#oh_nnexecutor_allocateinputmemorydeprecated) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, size_t length) | Applies for shared memory for a single model input on the device.| 142| \*[OH_NNExecutor_AllocateOutputMemory](#oh_nnexecutor_allocateoutputmemorydeprecated) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, size_t length) | Applies for shared memory for a single model output on the device.| 143| [OH_NNExecutor_DestroyInputMemory](#oh_nnexecutor_destroyinputmemorydeprecated) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, [OH_NN_Memory](_o_h___n_n___memory.md) \*\*memory) | Releases the input memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance.| 144| [OH_NNExecutor_DestroyOutputMemory](#oh_nnexecutor_destroyoutputmemorydeprecated) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, [OH_NN_Memory](_o_h___n_n___memory.md) \*\*memory) | Releases the output memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance.| 145| [OH_NNExecutor_SetInputWithMemory](#oh_nnexecutor_setinputwithmemorydeprecated) ([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) | Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model input.| 146| [OH_NNExecutor_SetOutputWithMemory](#oh_nnexecutor_setoutputwithmemorydeprecated) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, const [OH_NN_Memory](_o_h___n_n___memory.md) \*memory) | Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model output.| 147 148## Type Description 149 150 151### NN_OnRunDone 152 153``` 154typedef void(*NN_OnRunDone) (void *userData, OH_NN_ReturnCode errCode, void *outputTensor[], int32_t outputCount) 155``` 156 157**Description** 158 159Handle of the callback processing function invoked when the asynchronous inference ends. 160 161Use the **userData** parameter to specify the asynchronous inference to query. The value of **userData** is the same as that passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync). Use the **errCode** parameter to obtain the return result (defined by [OH_NN_ReturnCode](#oh_nn_returncode) of the asynchronous inference. 162 163**Since**: 11 164 165**Parameters** 166 167| Name| Description| 168| -------- | -------- | 169| userData | Identifier of asynchronous inference. The value is the same as the **userData** parameter passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync).| 170| errCode | Return result (defined by [OH_NN_ReturnCode](#oh_nn_returncode) of the asynchronous inference.| 171| outputTensor | Output tensor for asynchronous inference. The value is the same as the **outputTensor** parameter passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync).| 172| outputCount | Number of output tensors for asynchronous inference. The value is the same as the **outputCount** parameter passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync).| 173 174 175### NN_OnServiceDied 176 177``` 178typedef void(*NN_OnServiceDied) (void *userData) 179``` 180 181**Description** 182 183Handle of the callback processing function invoked when the device driver service terminates unexpectedly during asynchronous inference. 184 185You need to rebuild the model if the callback is invoked. 186 187You can use the **userData** parameter to specify the asynchronous inference to query. The value of **userData** is the same as that passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync). 188 189**Since**: 11 190 191**Parameters** 192 193| Name| Description| 194| -------- | -------- | 195| userData | Identifier of asynchronous inference. The value is the same as the **userData** parameter passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync).| 196 197 198### NN_QuantParam 199 200``` 201typedef struct NN_QuantParam NN_QuantParam 202``` 203 204**Description** 205 206Quantization parameter handle. 207 208**Since**: 11 209 210 211### NN_Tensor 212 213``` 214typedef struct NN_Tensor NN_Tensor 215``` 216 217**Description** 218 219Tensor handle. 220 221**Since**: 11 222 223 224### NN_TensorDesc 225 226``` 227typedef struct NN_TensorDesc NN_TensorDesc 228``` 229 230**Description** 231 232Tensor description handle. 233 234**Since**: 11 235 236 237### OH_NN_Memory<sup>(deprecated)</sup> 238 239``` 240typedef struct OH_NN_Memory OH_NN_Memory 241``` 242 243**Description** 244 245Used to define the memory structure. 246 247**Since**: 9 248 249**Deprecated**: This API is deprecated since API version 11. 250 251**Substitute**: You are advised to use [NN_Tensor](#nn_tensor). 252 253 254### OH_NN_QuantParam<sup>(deprecated)</sup> 255 256``` 257typedef struct OH_NN_QuantParam OH_NN_QuantParam 258``` 259 260**Description** 261 262Used to define the quantization information. 263 264In quantization scenarios, the 32-bit floating-point data type is quantized into the fixed-point data type according to the following formula: 265 266 267 268where, **s** and **z** are quantization parameters, which are stored by **scale** and **zeroPoint** in OH_NN_QuanParam. **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 the upper bound of the quantization result. The calculation method is as follows: 269 270 271 272 273 274The **clamp** function is defined as follows: 275 276 277 278**Since**: 9 279 280**Deprecated**: This API is deprecated since API version 11. 281 282**Substitute**: You are advised to use [NN_QuantParam](#nn_quantparam). 283 284 285### OH_NN_Tensor<sup>(deprecated)</sup> 286 287``` 288typedef struct OH_NN_Tensor OH_NN_Tensor 289``` 290 291**Description** 292 293Used to define the tensor structure. 294 295It is usually used to construct data nodes and operator parameters in a model diagram. When constructing a tensor, you need to specify the data type, number of dimensions, dimension information, and quantization information. 296 297**Since**: 9 298 299**Deprecated**: This API is deprecated since API version 11. 300 301**Substitute**: You are advised to use [NN_TensorDesc](#nn_tensordesc). 302 303 304### OH_NN_UInt32Array 305 306``` 307typedef struct OH_NN_UInt32Array OH_NN_UInt32Array 308``` 309 310**Description** 311 312Defines the structure for storing 32-bit unsigned integer arrays. 313 314**Since**: 9 315 316 317### OH_NNCompilation 318 319``` 320typedef struct OH_NNCompilation OH_NNCompilation 321``` 322 323**Description** 324 325Compiler handle. 326 327**Since**: 9 328 329 330### OH_NNExecutor 331 332``` 333typedef struct OH_NNExecutor OH_NNExecutor 334``` 335 336**Description** 337 338Executor handle. 339 340**Since**: 9 341 342 343### OH_NNModel 344 345``` 346typedef struct OH_NNModel OH_NNModel 347``` 348 349**Description** 350 351Model handle. 352 353**Since**: 9 354 355## Enum Description 356 357 358### OH_NN_DataType 359 360``` 361enum OH_NN_DataType 362``` 363 364**Description** 365 366Data types supported by NNRt. 367 368**Since**: 9 369 370| Value| Description| 371| -------- | -------- | 372| OH_NN_UNKNOWN | Unknown type.| 373| OH_NN_BOOL | bool type.| 374| OH_NN_INT8 | int8 type.| 375| OH_NN_INT16 | int16 type.| 376| OH_NN_INT32 | int32 type.| 377| OH_NN_INT64 | int64 type.| 378| OH_NN_UINT8 | uint8 type.| 379| OH_NN_UINT16 | uint16 type.| 380| OH_NN_UINT32 | uint32 type.| 381| OH_NN_UINT64 | uint64 type.| 382| OH_NN_FLOAT16 | float16 type.| 383| OH_NN_FLOAT32 | float32 type.| 384| OH_NN_FLOAT64 | float64 type.| 385 386 387### OH_NN_DeviceType 388 389``` 390enum OH_NN_DeviceType 391``` 392 393**Description** 394 395Device types supported by NNRt. 396 397**Since**: 9 398 399| Value| Description| 400| -------- | -------- | 401| OH_NN_OTHERS | Devices that are not CPU, GPU, or dedicated accelerator.| 402| OH_NN_CPU | CPU.| 403| OH_NN_GPU | GPU.| 404| OH_NN_ACCELERATOR | Dedicated device accelerator.| 405 406 407### OH_NN_Format 408 409``` 410enum OH_NN_Format 411``` 412 413**Description** 414 415Formats of tensor data. 416 417**Since**: 9 418 419| Value| Description| 420| -------- | -------- | 421| OH_NN_FORMAT_NONE | The tensor does not have a specific arrangement type (such as scalar or vector).| 422| OH_NN_FORMAT_NCHW | The tensor arranges data in NCHW format.| 423| OH_NN_FORMAT_NHWC | The tensor arranges data in NHWC format.| 424| OH_NN_FORMAT_ND<sup>11+</sup> | The tensor arranges data in ND format.<br>This API is supported since API version 11.| 425 426 427### OH_NN_FuseType 428 429``` 430enum OH_NN_FuseType : int8_t 431``` 432 433**Description** 434 435Activation function types in the fusion operator for NNRt. 436 437**Since**: 9 438 439| Value| Description| 440| -------- | -------- | 441| OH_NN_FUSED_NONE | The fusion activation function is not specified.| 442| OH_NN_FUSED_RELU | Fusion relu activation function.| 443| OH_NN_FUSED_RELU6 | Fusion relu6 activation function.| 444 445 446### OH_NN_OperationType 447 448``` 449enum OH_NN_OperationType 450``` 451 452**Description** 453 454Operator types supported by NNRt. 455 456**Since**: 9 457 458| Value| Description| 459| -------- | -------- | 460| OH_NN_OPS_ADD | Returns the tensor of the sum of the elements corresponding to two input tensors.<br>Input:<br>- **input1**: first input tensor, which is 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**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<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.| 461| OH_NN_OPS_AVG_POOL | Applies 2D average pooling to the input tensor, which must be in the NHWC format. The int8 quantization input is supported.<br>If the input contains the **padMode** parameter:<br>Input:<br>- **input**: a tensor.<br>Parameters:<br>- **kernelSize**: average kernel size. It is an **int** array whose length is **2**. It is in the format of [kernel_height, kernel_weight], where the first number indicates the kernel height, and the second number indicates the kernel width. <br>- **strides**: kernel moving stride. It is an **int** array whose length is **2**. It is in the format of [stride_height, stride_weight], where the first number indicates the moving stride in height, and the second number indicates the moving stride in width.<br>- **padMode**: padding mode, which is optional. It is an **int** value, which 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. The excessive pixels will be discarded.<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>If the input contains the **padList** parameter:<br>Input:<br>- **input**: a tensor.<br>Parameters:<br>- **kernelSize**: average kernel size. It is an **int** array whose length is **2**. It is in the format of [kernel_height, kernel_weight], where the first number indicates the kernel height, and the second number indicates the kernel width. <br>- **strides**: kernel moving stride. It is an **int** array whose length is **2**. It is in the format of [stride_height, stride_weight], where the first number indicates the moving stride in height, and the second number indicates the moving stride in width.<br>**padList**: padding around **input**. It is an int array in the format of [top, bottom, left, right], and the nearest neighbor values are used for padding.<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>**output**: average pooling result of the input.| 462| OH_NN_OPS_BATCH_NORM | Performs batch normalization on a tensor to scale and shift tensor elements, relieving potential covariate shift in a batch of data.<br>Input:<br>- **input**: *n*-dimensional tensor in the shape of [N, ..., C]. The *n*th 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>Output:<br>**output**: *n*-dimensional output tensor whose shape and data type are the same as those of the input.| 463| OH_NN_OPS_BATCH_TO_SPACE_ND | Divides batch dimension of a 4D tensor into small blocks by **block_shape** and interleaves them 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>Output:<br>**blockSize**: size of blocks to be interleaved into the spatial dimension. The value is an array in the format of [height_block, weight_block].<br>**crops**: elements truncated from the spatial dimension of the output. The value is a 2D array in the format of [[crop0_start, crop0_end], [crop1_start, crop1_end]] with the shape of (2, 2).<br>Output:<br>- **output**. If the shape of **input** is (n,h,w,c), the shape of **output** is (n',h',w',c'), where 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], and c'= c.| 464| OH_NN_OPS_BIAS_ADD | Offsets the data in each dimension of the input tensor.<br>Input:<br>**input**: input tensor, which can have two to five dimensions.<br>**bias**: offset of the number of input dimensions.<br>Output:<br>**output**: sum of the input tensor and the bias in each dimension.| 465| OH_NN_OPS_CAST | Converts the data type in the input tensor.<br>Input:<br>- **input**: input tensor.<br>- **type**: converted data type.<br>Output:<br>**output**: converted tensor.| 466| OH_NN_OPS_CONCAT | Connects tensors in a specified dimension.<br>Input:<br>- **input**: *n* input tensors.<br>Parameters:<br>- **axis**: dimension for connecting tensors.<br>Output:<br>**output**: result of connecting *n* tensors along the axis.| 467| OH_NN_OPS_CONV2D | Sets a 2D convolutional layer.<br>If the input contains the **padMode** parameter:<br>Input:<br>- **input**: input tensor.<br>- **weight**: convolution weight in the format of [outChannel, kernelHeight, kernelWidth, inChannel/group]. 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, quantization parameters are not required for **bias**. You only need to input data of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br>Parameters:<br>- **stride**: moving stride of the convolution kernel in height and weight. It is an int array in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array in the format of [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>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>If the input contains the **padList** parameter:<br>Input:<br>- **input**: input tensor.<br>- **weight**: convolution weight in the format of [outChannel, kernelHeight, kernelWidth, inChannel/group]. 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, quantization parameters are not required for **bias**. You only need to input data of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br>Parameters:<br>- **stride**: moving stride of the convolution kernel in height and weight. It is an int array in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array in the format of [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 in the format of [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**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: convolution computing result.| 468| OH_NN_OPS_CONV2D_TRANSPOSE | Sets 2D convolution transposition.<br>If the input contains the **padMode** parameter:<br>Input:<br>- **input**: input tensor.<br>- **weight**: convolution weight in the format of [outChannel, kernelHeight, kernelWidth, inChannel/group]. 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, quantization parameters are not required for **bias**. You only need to input data of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br>- **stride**: moving stride of the convolution kernel in height and weight. It is an int array in the format of [strideHeight, strideWidth].<br>Parameters:<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array in the format of [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 number, a tuple, or a list of two integers. 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**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>If the input contains the **padList** parameter:<br>Input:<br>- **input**: input tensor.<br>- **weight**: convolution weight in the format of [outChannel, kernelHeight, kernelWidth, inChannel/group]. 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, quantization parameters are not required for **bias**. You only need to input data of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br>Parameters:<br>- **stride**: moving stride of the convolution kernel in height and weight. It is an int array in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array in the format of [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 in the format of [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 number, a tuple, or a list of two integers. 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**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>**output**: computing result after convolution and transposition.| 469| OH_NN_OPS_DEPTHWISE_CONV2D_NATIVE | Sets 2D depthwise separable convolution.<br>If the input contains the **padMode** parameter:<br>Input:<br>- **input**: input tensor.<br>- **weight**: convolution weight in the format of [outChannel, kernelHeight, kernelWidth, 1]. **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, quantization parameters are not required for **bias**. You only need to input data of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br>Parameters:<br>- **stride**: moving stride of the convolution kernel in height and weight. It is an int array in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array in the format of [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). The value **0** (same) indicates that 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. The value **1** (valid) indicates that 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**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>If the input contains the **padList** parameter:<br>Input:<br>- **input**: input tensor.<br>- **weight**: convolution weight in the format of [outChannel, kernelHeight, kernelWidth, 1]. **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, quantization parameters are not required for **bias**. You only need to input data of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br>Parameters:<br>- **stride**: moving stride of the convolution kernel in height and weight. It is an int array in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array in the format of [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 in the format of [top, bottom, left, right].<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: convolution computing result.| 470| OH_NN_OPS_DIV | Divides two input scalars or tensors.<br>Input:<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 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**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: result of dividing **input1** by **input2**.| 471| OH_NN_OPS_ELTWISE | Sets parameters to perform product (dot product), sum (addition and subtraction), or max (larger value) on the input.<br>Input:<br>- **input1**: first input tensor.<br>- **input2**: second input tensor.<br>Parameters:<br>- **mode**: operation mode. The value is an enumerated value.<br>Output:<br>- **output**: computing result, which has the same data type and shape of **output** and **input1**.| 472| OH_NN_OPS_EXPAND_DIMS | Adds an additional dimension to a tensor in the given dimension.<br>Input:<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>Output:<br>- **output**: tensor after dimension expansion.| 473| OH_NN_OPS_FILL | Creates a tensor of the specified dimensions and fills it with a scalar.<br>Input:<br>- **value**: scalar used to fill the tensor.<br>- **shape**: dimensions of the tensor to be created.<br>Output:<br>- **output**: generated tensor, which has the same data type as **value**. The tensor shape is specified by the **shape** parameter.| 474| OH_NN_OPS_FULL_CONNECTION | Sets a full connection. The entire input is used as the feature map for feature extraction.<br>Input:<br>- **input**: full-connection input tensor.<br>- **weight**: weight tensor for a full connection.<br>- **bias**: full-connection bias. In quantization scenarios, quantization parameters are not required for **bias**. You only need to input data of the **OH_NN_INT32** type. The actual quantization parameters are determined by **input** and **weight**.<br>Parameters:<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: computed tensor.<br>If the input contains the **axis** parameter:<br>Input:<br>- **input**: full-connection input tensor.<br>- **weight**: weight tensor for a full connection.<br>- **bias**: full-connection bias. In quantization scenarios, quantization parameters are not required for **bias**. You only need to input data 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**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: computed tensor.| 475| OH_NN_OPS_GATHER | Returns the slice of the input tensor based on the specified index and axis.<br>Input:<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>Output:<br>- **output**: sliced tensor.| 476| OH_NN_OPS_HSWISH | Calculates the activation value of the input **Hswish**.<br>Input:<br>- An *n*-dimensional input tensor.<br>Output:<br>*n*-dimensional **Hswish** activation value. The data type is the same as that of **shape** and **input**.| 477| OH_NN_OPS_LESS_EQUAL | For **input1** and **input2**, calculate the result of input1[i]<=input2[i] for each pair of elements, where **i** is the index of each element in the input tensor.<br>Input:<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 **input_1** is a tensor and must be a tensor with the data type of real number or NN_BOOL if **input_1** is not a tensor.<br>Output:<br>A tensor of the NN_BOOL type. 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.| 478| OH_NN_OPS_MATMUL | Calculates the inner product of **input1** and **input2**.<br>Input:<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>Output:<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**.| 479| 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 input must be two tensors or one tensor and one scalar. If the input contains two tensors, their data types cannot be both NN_BOOL. Their shapes can be broadcast to the same size. If the input contains one tensor and one scalar, the scalar must be a constant.<br>Input:<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>Output:<br>- **output**: *n*-dimensional output tensor. The **shape** and data type of **output** are the same as those of the two inputs with higher precision or bits.| 480| OH_NN_OPS_MAX_POOL | Applies 2D maximum pooling to the input tensor.<br>If the input contains the **padMode** parameter:<br>Input:<br>- **input**: a tensor.<br>Parameters:<br>- **kernelSize**: average kernel size. It is an **int** array whose length is **2**. It is in the format of [kernel_height, kernel_weight], where the first number indicates the kernel height, and the second number indicates the kernel width. <br>- **strides**: kernel moving stride. It is an **int** array whose length is **2**. It is in the format of [stride_height, stride_weight], where the first number indicates the moving stride in height, and the second number indicates the moving stride in width.<br>- **padMode**: padding mode, which is optional. It is an **int** value, which 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. The excessive pixels will be discarded.<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>If the input contains the **padList** parameter:<br>Input:<br>- **input**: a tensor.<br>Parameters:<br>- **kernelSize**: average kernel size. It is an **int** array whose length is **2**. It is in the format of [kernel_height, kernel_weight], where the first number indicates the kernel height, and the second number indicates the kernel width. <br>- **strides**: kernel moving stride. It is an **int** array whose length is **2**. It is in the format of [stride_height, stride_weight], where the first number indicates the moving stride in height, and the second number indicates the moving stride in width.<br>**padList**: padding around **input**. It is an int array in the format of [top, bottom, left, right], and the nearest neighbor values are used for padding.<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: tensor obtained after maximum pooling is applied to the input.| 481| 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>Input:<br>- **input1**: *n*-dimensional tensor.<br>- **input2**: *n*-dimensional tensor.<br>Parameters:<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>Product of each element of **input1** and **input2**.| 482| 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>Input:<br>- **indices**: *n*-dimensional tensor. Each element in **indices** determines the position of **on_value** in each one-hot vector.<br>- **depth**, an integer scalar that determines the depth of the one-hot vector. The value of **depth** must be greater than **0**.<br>- **on_value**, a scalar that specifies a valid value in the one-hot vector.<br>- **off_value**, a scalar that specifies the values of other locations 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>Output:<br>- **output**: (*n*+1)-dimensional tensor if **indices** is an *n*-dimensional tensor. The output shape is determined by **indices** and **axis**.| 483| OH_NN_OPS_PAD | Pads **inputX** in the specified dimensions.<br>Input:<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 *n*th dimension, and **paddings[i][1]** indicates the number of paddings to be added following **inputX** in the *n*th 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>Output:<br>- **output**: *n*-dimensional tensor after padding, with the same dimensions and data type as **inputX**. The shape is determined by **inputX** and **paddings**; that is, output.shape[i] = input.shape[i] + paddings[i][0]+paddings[i][1].| 484| OH_NN_OPS_POW | Calculates the **y** power of each element in **input**. The input must contain two tensors or one tensor and one scalar. If the input contains two tensors, their data types cannot be both NN_BOOL, and their shapes must be the same. If the input contains one tensor and one scalar, the scalar must be a constant.<br>Input:<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>Output:<br>- **output**: tensor, whose shape is determined by the shape of **input** and **y** after broadcasting.| 485| OH_NN_OPS_SCALE | Scales a tensor.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>- **scale**: scaling tensor.<br>- **bias**: bias tensor.<br>Parameters:<br>- **axis**: dimensions to be scaled.<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: scaled *n*-dimensional tensor, whose data type is the same as that of **input** and shape is determined by **axis**.| 486| OH_NN_OPS_SHAPE | Calculates the shape of the input tensor.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: integer array representing the dimensions of the input tensor.| 487| OH_NN_OPS_SIGMOID | Applies the **sigmoid** operation to the input tensor.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: result of the **sigmoid** operation. It is an *n*-dimensional tensor with the same data type and shape as **input**.| 488| OH_NN_OPS_SLICE | Slices a tensor of the specified size from the input tensor in each dimension.<br>Input:<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 **1**. Assume that a dimension is 1<=size[i]<=input.shape[i]-begin[i].<br>Output:<br>- **output**: *n*-dimensional tensor obtained by slicing. The **TensorType**, shape, and size of the output are the same as those of the input.| 489| OH_NN_OPS_SOFTMAX | Applies the **softmax** operation to the input tensor.<br>Input:<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>Output:<br>- **output**: result of the **softmax** operation. It is an *n*-dimensional tensor with the same data type and shape as **input**.| 490| 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>Input:<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>Output:<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]. Note that (h + paddings[0][0] + paddings[0][1]) and (w + paddings[1][0] + paddings[1][1]) must be exactly divisible by (h + paddings[0][0] + paddings[0][1]) and (w + paddings[1][0] + paddings[1][1]).| 491| OH_NN_OPS_SPLIT | Splits the input into multiple tensors along the axis dimension. The number of tensors is specified by **outputNum**.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **outputNum**: number of output tensors. The data type is long int.<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>Output:<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**.| 492| OH_NN_OPS_SQRT | Calculates the square root of a tensor.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: square root of the input. It is an *n*-dimensional tensor with the same data type and shape as **input**.| 493| 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>Input:<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>Output:<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.| 494| 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 dimension 0 and dimension 1 is removed.<br>Input:<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>Output:<br>- **output**: output tensor.| 495| 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>Input:<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>Output:<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.| 496| OH_NN_OPS_STRIDED_SLICE | Slices a tensor with the specified stride.<br>Input:<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 *i*th 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 *i*th 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 *i*th 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 *i*th 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 *i*th 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 *i*th 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 *i*th 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 *i*th dimension will be discarded, and the length of the *i*th dimension is shrunk to **1**.<br>Output:<br>- A tensor, with the same data type as **input**. The number of dimensions of the output tensor is rank(input[0])+1.| 497| OH_NN_OPS_SUB | Calculates the difference between two tensors.<br>Input:<br>- **input1**: minuend, which is a tensor.<br>- **input2**: subtrahend, which is a tensor.<br>Parameters:<br>- **activationType**: integer constant contained in **FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: difference between the two tensors. The shape of the output is determined by input1 and input2. When the shapes of input1 and input2 are the same, the shape of the output is the same as that of input1 and input2. If the shapes of input1 and input2 are different, the output is obtained after the broadcast operation is performed on input1 or input2. **TensorType** of the output is the same as that of the input tensor with higher precision.| 498| OH_NN_OPS_TANH | Computes hyperbolic tangent of the input tensor.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: hyperbolic tangent of the input. The **TensorType** and tensor shape are the same as those of the input.| 499| OH_NN_OPS_TILE | Copies a tensor for the specified number of times.<br>Input:<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>Output:<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.| 500| OH_NN_OPS_TRANSPOSE | Transposes data of **input 0** based on **permutation**.<br>Input:<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>Output:<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**.| 501| 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>Input:<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**: whether to retain the dimension. The value is a Boolean value.<br>Output:<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<n.| 502| OH_NN_OPS_RESIZE_BILINEAR | The Bilinear method is used to deform the input based on the given parameters.<br>Input:<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**: 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 APIs 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>Output:<br>- **output**: *n*-dimensional tensor, with the same shape and data type as **input**. | 503| OH_NN_OPS_RSQRT | Calculates the reciprocal of the square root of a tensor.<br>Input:<br>- **input**: *n*-dimensional tensor, where *n* is less than 8. Each element of the tensor cannot be less than **0**.<br>Output:<br>- **output**: *n*-dimensional tensor, with the same shape and data type as **input**. | 504| OH_NN_OPS_RESHAPE | Reshapes a tensor.<br>Input:<br>- **input**: *n*-dimensional input tensor.<br>- **InputShape**: shape of the output tensor. The value is a 1D constant tensor.<br>Output:<br>- **output**: tensor whose data type is the same as that of **input** and shape is determined by **InputShape**.| 505| OH_NN_OPS_PRELU | Calculates the PReLU activation value of **input** and **weight**.<br>Input:<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>Output:<br>- **output**: PReLU activation value of **input**, with the same shape and data type as **inputX**.| 506| OH_NN_OPS_RELU | Calculates the Relu activation value of **input**.<br>Input:<br>- **input**: *n*-dimensional input tensor.<br>Output:<br>- **output**: *n*-dimensional tensor, with the same data type and shape as the input tensor.| 507| 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>Input:<br>- **input**: *n*-dimensional input tensor.<br>Output:<br>- **output**: *n*-dimensional Relu6 tensor, with the same data type and shape as the input tensor.| 508| OH_NN_OPS_LAYER_NORM | Applies layer normalization for a tensor from the specified axis.<br>Input:<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>Output:<br>- **output**: *n*-dimensional tensor, with the same data type and shape as the input tensor.| 509| OH_NN_OPS_REDUCE_PROD | Calculates the accumulated value for a tensor along the specified dimension.<br>Input:<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**: 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>Output:<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<n.| 510| 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>Input:<br>- An *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**: whether to retain the dimension. The value is a Boolean value.<br>Output:<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<n.| 511| OH_NN_OPS_QUANT_DTYPE_CAST | Converts the data type.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **src_t**: data type of the input.<br>- **dst_t**: data type of the output.<br>Output:<br>- **output**: *n*-dimensional tensor. The data type is determined by **input2**. The output shape is the same as the input shape.| 512| OH_NN_OPS_TOP_K | Obtains the values and indices of the largest *k* entries in the last dimension.<br>Input:<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>Output:<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.| 513| OH_NN_OPS_ARG_MAX | Returns the index of the maximum tensor value across axes.<br>Input:<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**: whether to maintain the input tensor dimension. The value is a Boolean value.<br>Output:<br>- **output**: index of the maximum input tensor on the axis. The value is a tensor.| 514| OH_NN_OPS_UNSQUEEZE | Adds a dimension based on the value of **axis**. <br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **axis**: dimension to add. The value of **axis** can be an integer or an array of integers. The value range of the integer is [-n, n).<br>Output:<br>- **output**: output tensor.| 515| OH_NN_OPS_GELU | Activates the Gaussian error linear unit. The int quantization input is not supported. output=0.5*input*(1+tanh(input/2)) <br>Input:<br>- An *n*-dimensional input tensor.<br>Output:<br>- **output**: *n*-dimensional tensor, with the same data type and shape as the input tensor.| 516 517### OH_NN_PerformanceMode 518 519``` 520enum OH_NN_PerformanceMode 521``` 522 523**Description** 524 525Performance modes of the device. 526 527**Since**: 9 528 529| Value| Description| 530| -------- | -------- | 531| OH_NN_PERFORMANCE_NONE | No performance mode preference.| 532| OH_NN_PERFORMANCE_LOW | Low power consumption mode.| 533| OH_NN_PERFORMANCE_MEDIUM | Medium performance mode.| 534| OH_NN_PERFORMANCE_HIGH | High performance mode.| 535| OH_NN_PERFORMANCE_EXTREME | Ultimate performance mode.| 536 537 538### OH_NN_Priority 539 540``` 541enum OH_NN_Priority 542``` 543 544**Description** 545 546Priorities of a model inference task. 547 548**Since**: 9 549 550| Value| Description| 551| -------- | -------- | 552| OH_NN_PRIORITY_NONE | No priority preference.| 553| OH_NN_PRIORITY_LOW | Low priority.| 554| OH_NN_PRIORITY_MEDIUM | Medium priority.| 555| OH_NN_PRIORITY_HIGH | High priority.| 556 557 558### OH_NN_ReturnCode 559 560``` 561enum OH_NN_ReturnCode 562``` 563 564**Description** 565 566Error codes for NNRt. 567 568**Since**: 9 569 570| Value| Description| 571| -------- | -------- | 572| OH_NN_SUCCESS | The operation is successful.| 573| OH_NN_FAILED | Operation failed.| 574| OH_NN_INVALID_PARAMETER | Invalid parameter.| 575| OH_NN_MEMORY_ERROR | Memory-related error, for example, insufficient memory, memory data copy failure, or memory application failure.| 576| OH_NN_OPERATION_FORBIDDEN | Invalid operation.| 577| OH_NN_NULL_PTR | Null pointer.| 578| OH_NN_INVALID_FILE | Invalid file.| 579| OH_NN_UNAVALIDABLE_DEVICE<sup> (deprecated) </sup>| Hardware error, for example, HDL service crash.<br>**Deprecated**: This API is deprecated since API version 11.<br>**Substitute**: OH_NN_UNAVAILABLE_DEVICE is recommended.| 580| OH_NN_INVALID_PATH | Invalid path.| 581| OH_NN_TIMEOUT<sup>11+</sup> | Execution timed out.<br>This API is supported since API version 11.| 582| OH_NN_UNSUPPORTED<sup>11+</sup> | Not supported.<br>This API is supported since API version 11.| 583| OH_NN_CONNECTION_EXCEPTION<sup>11+</sup> | Connection error.<br>This API is supported since API version 11.| 584| OH_NN_SAVE_CACHE_EXCEPTION<sup>11+</sup> | Failed to save the cache.<br>This API is supported since API version 11.| 585| OH_NN_DYNAMIC_SHAPE<sup>11+</sup> | Dynamic shape.<br>This API is supported since API version 11.| 586| OH_NN_UNAVAILABLE_DEVICE<sup>11+</sup> | Hardware error, for example, HDL service crash.<br>This API is supported since API version 11.| 587 588 589### OH_NN_TensorType 590 591``` 592enum OH_NN_TensorType 593``` 594 595**Description** 596 597Defines tensor types. 598 599Tensors 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 **pad** of the **OH_NN_OPS_CONV2D** operator is being set. You need to set the **type** attribute of the **OH_NN_Tensor** 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*}. 600 601**Since**: 9 602 603| Value| Description| 604| -------- | -------- | 605| OH_NN_TENSOR | Used when the tensor is used as the input or output of a model (or operator).| 606| OH_NN_ADD_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the Add operator.| 607| OH_NN_AVG_POOL_KERNEL_SIZE | Used when the tensor is used as the **kernel_size** parameter of the AvgPool operator. | 608| OH_NN_AVG_POOL_STRIDE | Used when the tensor is used as the **stride** parameter of the AvgPool operator.| 609| OH_NN_AVG_POOL_PAD_MODE | Used when the tensor is used as the **pad_mode** parameter of the AvgPool operator.| 610| OH_NN_AVG_POOL_PAD | Used when the tensor is used as the **pad** parameter of the AvgPool operator.| 611| OH_NN_AVG_POOL_ACTIVATION_TYPE | Used when the tensor is used as the **activation_type** parameter of the AvgPool operator. | 612| OH_NN_BATCH_NORM_EPSILON | Used when the tensor is used as the **eosilon** parameter of the BatchNorm operator.| 613| OH_NN_BATCH_TO_SPACE_ND_BLOCKSIZE | Used when the tensor is used as the **blockSize** parameter of the BatchToSpaceND operator.| 614| OH_NN_BATCH_TO_SPACE_ND_CROPS | Used when the tensor is used as the **crops** parameter of the BatchToSpaceND operator.| 615| OH_NN_CONCAT_AXIS | Used when the tensor is used as the **axis** parameter of the Concat operator.| 616| OH_NN_CONV2D_STRIDES | Used when the tensor is used as the **strides** parameter of the Conv2D operator.| 617| OH_NN_CONV2D_PAD | Used when the tensor is used as the **pad** parameter of the Conv2D operator.| 618| OH_NN_CONV2D_DILATION | Used when the tensor is used as the **dilation** parameter of the Conv2D operator.| 619| OH_NN_CONV2D_PAD_MODE | Used when the tensor is used as the **padMode** parameter of the Conv2D operator.| 620| OH_NN_CONV2D_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Conv2D operator.| 621| OH_NN_CONV2D_GROUP | Used when the tensor is used as the **group** parameter of the Conv2D operator. | 622| OH_NN_CONV2D_TRANSPOSE_STRIDES | Used when the tensor is used as the **strides** parameter of the Conv2DTranspose operator.| 623| OH_NN_CONV2D_TRANSPOSE_PAD | Used when the tensor is used as the **pad** parameter of the Conv2DTranspose operator.| 624| OH_NN_CONV2D_TRANSPOSE_DILATION | Used when the tensor is used as the **dilation** parameter of the Conv2DTranspose operator. | 625| OH_NN_CONV2D_TRANSPOSE_OUTPUT_PADDINGS | Used when the tensor is used as the **outputPaddings** parameter of the Conv2DTranspose operator. | 626| OH_NN_CONV2D_TRANSPOSE_PAD_MODE | Used when the tensor is used as the **padMode** parameter of the Conv2DTranspose operator. | 627| OH_NN_CONV2D_TRANSPOSE_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Conv2DTranspose operator. | 628| OH_NN_CONV2D_TRANSPOSE_GROUP | Used when the tensor is used as the **group** parameter of the Conv2DTranspose operator. | 629| OH_NN_DEPTHWISE_CONV2D_NATIVE_STRIDES | Used when the tensor is used as the **strides** parameter of the DepthwiseConv2dNative operator. | 630| OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD | Used when the tensor is used as the **pad** parameter of the DepthwiseConv2dNative operator. | 631| OH_NN_DEPTHWISE_CONV2D_NATIVE_DILATION | Used when the tensor is used as the **dilation** parameter of the DepthwiseConv2dNative operator. | 632| OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD_MODE | Used when the tensor is used as the **padMode** parameter of the DepthwiseConv2dNative operator. | 633| OH_NN_DEPTHWISE_CONV2D_NATIVE_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the DepthwiseConv2dNative operator. | 634| OH_NN_DIV_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the Div operator. | 635| OH_NN_ELTWISE_MODE | Used when the tensor is used as the **mode** parameter of the Eltwise operator. | 636| OH_NN_FULL_CONNECTION_AXIS | Used when the tensor is used as the **axis** parameter of the FullConnection operator. | 637| OH_NN_FULL_CONNECTION_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the FullConnection operator. | 638| OH_NN_MATMUL_TRANSPOSE_A | Used when the tensor is used as the **transposeA** parameter of the Matmul operator. | 639| OH_NN_MATMUL_TRANSPOSE_B | Used when the tensor is used as the **transposeB** parameter of the Matmul operator. | 640| OH_NN_MATMUL_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Matmul operator. | 641| OH_NN_MAX_POOL_KERNEL_SIZE | Used when the tensor is used as the **kernel_size** parameter of the MaxPool operator. | 642| OH_NN_MAX_POOL_STRIDE | Used when the tensor is used as the **stride** parameter of the MaxPool operator. | 643| OH_NN_MAX_POOL_PAD_MODE | Used when the tensor is used as the **pad_mode** parameter of the MaxPool operator. | 644| OH_NN_MAX_POOL_PAD | Used when the tensor is used as the **pad** parameter of the MaxPool operator. | 645| OH_NN_MAX_POOL_ACTIVATION_TYPE | Used when the tensor is used as the **activation_type** parameter of the MaxPool operator. | 646| OH_NN_MUL_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Mul operator. | 647| OH_NN_ONE_HOT_AXIS | Used when the tensor is used as the **axis** parameter of the OneHot operator. | 648| OH_NN_PAD_CONSTANT_VALUE | Used when the tensor is used as the **constant_value** parameter of the Pad operator. | 649| OH_NN_SCALE_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the Scale operator. | 650| OH_NN_SCALE_AXIS | Used when the tensor is used as the **axis** parameter of the Scale operator. | 651| OH_NN_SOFTMAX_AXIS | Used when the tensor is used as the **axis** parameter of the Softmax operator. | 652| OH_NN_SPACE_TO_BATCH_ND_BLOCK_SHAPE | Used when the tensor is used as the **BlockShape** parameter of the SpaceToBatchND operator. | 653| OH_NN_SPACE_TO_BATCH_ND_PADDINGS | Used when the tensor is used as the **Paddings** parameter of the SpaceToBatchND operator. | 654| OH_NN_SPLIT_AXIS | Used when the tensor is used as the **Axis** parameter of the Split operator. | 655| OH_NN_SPLIT_OUTPUT_NUM | Used when the tensor is used as the **OutputNum** parameter of the Split operator. | 656| OH_NN_SPLIT_SIZE_SPLITS | Used when the tensor is used as the **SizeSplits** parameter of the Split operator. | 657| OH_NN_SQUEEZE_AXIS | Used when the tensor is used as the **Axis** parameter of the Squeeze operator. | 658| OH_NN_STACK_AXIS | Used when the tensor is used as the **Axis** parameter of the Stack operator. | 659| OH_NN_STRIDED_SLICE_BEGIN_MASK | Used when the tensor is used as the **BeginMask** parameter of the StridedSlice operator. | 660| OH_NN_STRIDED_SLICE_END_MASK | Used when the tensor is used as the **EndMask** parameter of the StridedSlice operator. | 661| OH_NN_STRIDED_SLICE_ELLIPSIS_MASK | Used when the tensor is used as the **EllipsisMask** parameter of the StridedSlice operator. | 662| OH_NN_STRIDED_SLICE_NEW_AXIS_MASK | Used when the tensor is used as the **NewAxisMask** parameter of the StridedSlice operator. | 663| OH_NN_STRIDED_SLICE_SHRINK_AXIS_MASK | Used when the tensor is used as the **ShrinkAxisMask** parameter of the StridedSlice operator. | 664| OH_NN_SUB_ACTIVATIONTYPE | Used when the tensor is used as the **ActivationType** parameter of the Sub operator. | 665| OH_NN_REDUCE_MEAN_KEEP_DIMS | Used when the tensor is used as the **keep_dims** parameter of the ReduceMean operator. | 666| OH_NN_RESIZE_BILINEAR_NEW_HEIGHT | Used when the tensor is used as the **new_height** parameter of the ResizeBilinear operator. | 667| OH_NN_RESIZE_BILINEAR_NEW_WIDTH | Used when the tensor is used as the **new_width** parameter of the ResizeBilinear operator. | 668| OH_NN_RESIZE_BILINEAR_PRESERVE_ASPECT_RATIO | Used when the tensor is used as the **preserve_aspect_ratio** parameter of the ResizeBilinear operator. | 669| OH_NN_RESIZE_BILINEAR_COORDINATE_TRANSFORM_MODE | Used when the tensor is used as the **coordinate_transform_mode** parameter of the ResizeBilinear operator. | 670| OH_NN_RESIZE_BILINEAR_EXCLUDE_OUTSIDE | Used when the tensor is used as the **exclude_outside** parameter of the ResizeBilinear operator. | 671| OH_NN_LAYER_NORM_BEGIN_NORM_AXIS | Used when the tensor is used as the **beginNormAxis** parameter of the LayerNorm operator. | 672| OH_NN_LAYER_NORM_EPSILON | Used when the tensor is used as the **epsilon** parameter of the LayerNorm operator. | 673| OH_NN_LAYER_NORM_BEGIN_PARAM_AXIS | Used when the tensor is used as the **beginParamsAxis** parameter of the LayerNorm operator. | 674| OH_NN_LAYER_NORM_ELEMENTWISE_AFFINE | Used when the tensor is used as the **elementwiseAffine** parameter of the LayerNorm operator. | 675| OH_NN_REDUCE_PROD_KEEP_DIMS | Used when the tensor is used as the **keep_dims** parameter of the ReduceProd operator. | 676| OH_NN_REDUCE_ALL_KEEP_DIMS | Used when the tensor is used as the **keep_dims** parameter of the ReduceAll operator. | 677| OH_NN_QUANT_DTYPE_CAST_SRC_T | Used when the tensor is used as the **src_t** parameter of the QuantDTypeCast operator. | 678| OH_NN_QUANT_DTYPE_CAST_DST_T | Used when the tensor is used as the **dst_t** parameter of the QuantDTypeCast operator. | 679| OH_NN_TOP_K_SORTED | Used when the tensor is used as the **Sorted** parameter of the Topk operator. | 680| OH_NN_ARG_MAX_AXIS | Used when the tensor is used as the **axis** parameter of the ArgMax operator. | 681| OH_NN_ARG_MAX_KEEPDIMS | Used when the tensor is used as the **keepDims** parameter of the ArgMax operator. | 682| OH_NN_UNSQUEEZE_AXIS | Used when the tensor is used as the **Axis** parameter of the Unsqueeze operator. | 683 684 685## Function Description 686 687 688### OH_NNCompilation_AddExtensionConfig() 689 690``` 691OH_NN_ReturnCode OH_NNCompilation_AddExtensionConfig (OH_NNCompilation *compilation, const char *configName, const void *configValue, const size_t configValueSize ) 692``` 693 694**Description** 695 696Adds extended configurations for custom device attributes. 697 698Some devices have their own attributes, which have not been enabled in NNRt. This API helps you to set custom attributes for these devices. You need to obtain their names and values from the device vendor's documentation and add them to the model building instance. These attributes are passed directly to the device driver. If the device driver cannot parse the attributes, this API returns an error code. 699 700After [OH_NNCompilation_Build](#oh_nncompilation_build) is called, **configName** and **configValue** can be released. 701 702**Since**: 11 703 704**Parameters** 705 706| Name| Description| 707| -------- | -------- | 708| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 709| configName | Configuration name.| 710| configValue | Configured value.| 711| configValueSize | Size of the configured value, in bytes.| 712 713**Returns** 714 715Execution 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). 716 717 718### OH_NNCompilation_Build() 719 720``` 721OH_NN_ReturnCode OH_NNCompilation_Build (OH_NNCompilation *compilation) 722``` 723 724**Description** 725 726Performs model building. 727 728After the build configuration is complete, call this API to start model building. The model building instance pushes the model and build options to the device for building. After this API is called, additional build operations cannot be performed. If [OH_NNCompilation_SetDevice](#oh_nncompilation_setdevice), [OH_NNCompilation_SetCache](#oh_nncompilation_setcache), [OH_NNCompilation_SetPerformanceMode](#oh_nncompilation_setperformancemode), [OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority), or [OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16) is called, **OH_NN_OPERATION_FORBIDDEN** is returned. 729 730**Since**: 9 731 732**Parameters** 733 734| Name| Description| 735| -------- | -------- | 736| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 737 738**Returns** 739 740Execution 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). 741 742 743### OH_NNCompilation_Construct() 744 745``` 746OH_NNCompilation *OH_NNCompilation_Construct (const OH_NNModel *model) 747``` 748 749**Description** 750 751Creates a model building instance of the [OH_NNCompilation](#oh_nncompilation) type. 752 753After the OH_NNModel module completes model construction, APIs provided by the OH_NNCompilation module pass the model to underlying device for building. This API creates an [OH_NNCompilation](#oh_nncompilation) instance based on the passed [OH_NNModel](#oh_nnmodel) instance. The [OH_NNCompilation_SetDevice](#oh_nncompilation_setdevice) API is called to specify the device for model building, and the [OH_NNCompilation_Build](#oh_nncompilation_build) API is then called to complete model building. 754 755In addition to computing device selection, the OH_NNCompilation module supports features such as model cache, performance preference, priority setting, and float16 computing, which can be implemented by the following APIs: 756 757[OH_NNCompilation_SetCache](#oh_nncompilation_setcache) 758 759[OH_NNCompilation_SetPerformanceMode](#oh_nncompilation_setperformancemode) 760 761[OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority) 762 763[OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16) 764 765After this API is called to create [OH_NNCompilation](#oh_nncompilation), the [OH_NNModel](#oh_nnmodel) instance can be released. 766 767**Since**: 9 768 769**Parameters** 770 771| Name| Description| 772| -------- | -------- | 773| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 774 775**Returns** 776 777Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 778 779 780### OH_NNCompilation_ConstructForCache() 781 782``` 783OH_NNCompilation *OH_NNCompilation_ConstructForCache () 784``` 785 786**Description** 787 788Creates an empty model building instance for later recovery from the model cache. 789 790For details about the model cache, see [OH_NNCompilation_SetCache](#oh_nncompilation_setcache). 791 792The time required for model recovery from the model cache is less than the time required for building using [OH_NNModel](#oh_nnmodel). 793 794Call [OH_NNCompilation_SetCache](#oh_nncompilation_setcache) or [OH_NNCompilation_ImportCacheFromBuffer](#oh_nncompilation_importcachefrombuffer), and then call [OH_NNCompilation_Build](#oh_nncompilation_build) to complete model recovery. 795 796**Since**: 11 797 798**Returns** 799 800Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 801 802 803### OH_NNCompilation_ConstructWithOfflineModelBuffer() 804 805``` 806OH_NNCompilation *OH_NNCompilation_ConstructWithOfflineModelBuffer (const void *modelBuffer, size_t modelSize ) 807``` 808 809**Description** 810 811Creates a model building instance based on the offline model buffer. 812 813This API conflicts with the one for transferring the path of the online or offline model building file. You can select only one of the three build APIs. 814 815Note: The returned [OH_NNCompilation](#oh_nncompilation) instance only saves the modelBuffer pointer in it, but does not copy its data. The modelBuffer should not be released before the [OH_NNCompilation](#oh_nncompilation) instance is destroyed. 816 817**Since**: 11 818 819**Parameters** 820 821| Name| Description| 822| -------- | -------- | 823| modelBuffer | Memory for storing offline model files.| 824| modelSize | Memory size of the offline model.| 825 826**Returns** 827 828Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 829 830 831### OH_NNCompilation_ConstructWithOfflineModelFile() 832 833``` 834OH_NNCompilation *OH_NNCompilation_ConstructWithOfflineModelFile (const char *modelPath) 835``` 836 837**Description** 838 839Creates a model building instance based on an offline model file. 840 841This API conflicts with the one for transferring the memory of the online or offline model building file. You can select only one of the three build APIs. 842 843An offline model is a model type built offline by the model converter provided by the device vendor. Therefore, an offline model can be used only on a specified device. However, the build time of an offline model is usually far shorter than that of the image composition instance [OH_NNModel](#oh_nnmodel). 844 845During development, offline build needs to be performed and offline models need to be deployed in application packages. 846 847**Since**: 11 848 849**Parameters** 850 851| Name| Description| 852| -------- | -------- | 853| modelPath | Path of the offline model file.| 854 855**Returns** 856 857Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 858 859 860### OH_NNCompilation_Destroy() 861 862``` 863void OH_NNCompilation_Destroy (OH_NNCompilation **compilation) 864``` 865 866**Description** 867 868Destroys a model building instance of the [OH_NNCompilation](#oh_nncompilation) type. 869 870This API needs to be called to destroy the model building instances created by calling [OH_NNCompilation_Construct](#oh_nncompilation_construct), [OH_NNCompilation_ConstructWithOfflineModelFile](#oh_nncompilation_constructwithofflinemodelfile), [OH_NNCompilation_ConstructWithOfflineModelBuffer](#oh_nncompilation_constructwithofflinemodelbuffer) and [OH_NNCompilation_ConstructForCache](#oh_nncompilation_constructforcache). 871 872If **compilation** or **\*compilation** is a null pointer, this API only prints warning logs but does not perform the destruction operation. 873 874**Since**: 9 875 876**Parameters** 877 878| Name| Description| 879| -------- | -------- | 880| compilation | Level-2 pointer to the [OH_NNCompilation](#oh_nncompilation) instance. After the model building instance is destroyed, this API sets **\*compilation** to a null pointer.| 881 882### OH_NNCompilation_EnableFloat16() 883 884``` 885OH_NN_ReturnCode OH_NNCompilation_EnableFloat16 (OH_NNCompilation *compilation, bool enableFloat16 ) 886``` 887 888**Description** 889 890Enables float16 for computing. 891 892By default, the floating-point model uses float32 for computing. If this API is called on a device that supports float16, floating-point model that supports float32 will use float16 for computing, so to reduce memory usage and execution time. 893 894This option is invalid for fixed-point models, for example, fixed-point models of the int8 type. 895 896If this API is called on the device that does not support float16, the error code **OH_NN_UNAVAILABLE_DEVICE** is returned. 897 898**Since**: 9 899 900**Parameters** 901 902| Name| Description| 903| -------- | -------- | 904| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 905| enableFloat16 | 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.| 906 907**Returns** 908 909Execution 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). 910 911 912### OH_NNCompilation_ExportCacheToBuffer() 913 914``` 915OH_NN_ReturnCode OH_NNCompilation_ExportCacheToBuffer (OH_NNCompilation *compilation, const void *buffer, size_t length, size_t *modelSize ) 916``` 917 918**Description** 919 920Writes the model cache to the specified buffer. 921 922For details about the model cache, see [OH_NNCompilation_SetCache](#oh_nncompilation_setcache). 923 924Note: The model cache is the build result [OH_NNCompilation_Build](#oh_nncompilation_build). Therefore, this API must be called after [OH_NNCompilation_Build](#oh_nncompilation_build). 925 926**Since**: 11 927 928**Parameters** 929 930| Name| Description| 931| -------- | -------- | 932| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 933| buffer | Pointer to the given memory.| 934| length | Memory length. | 935| modelSize | Size of the model cache, in bytes.| 936 937**Returns** 938 939Execution 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). 940 941 942### OH_NNCompilation_ImportCacheFromBuffer() 943 944``` 945OH_NN_ReturnCode OH_NNCompilation_ImportCacheFromBuffer (OH_NNCompilation *compilation, const void *buffer, size_t modelSize ) 946``` 947 948**Description** 949 950Reads the model cache from the specified buffer. 951 952For details about the model cache, see [OH_NNCompilation_SetCache](#oh_nncompilation_setcache). 953 954After calling [OH_NNCompilation_ImportCacheFromBuffer](#oh_nncompilation_importcachefrombuffer), call [OH_NNCompilation_Build](#oh_nncompilation_build) to complete model recovery. 955 956Note: The **compilation** instance stores the buffer pointer in the buffer, but does not copy its data. You cannot release the memory buffer before the **compilation** instance is destroyed. 957 958**Since**: 11 959 960**Parameters** 961 962| Name| Description| 963| -------- | -------- | 964| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 965| buffer | Pointer to the given memory.| 966| modelSize | Size of the model cache, in bytes.| 967 968**Returns** 969 970Execution 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). 971 972 973### OH_NNCompilation_SetCache() 974 975``` 976OH_NN_ReturnCode OH_NNCompilation_SetCache (OH_NNCompilation *compilation, const char *cachePath, uint32_t version ) 977``` 978 979**Description** 980 981Sets the cache directory and version for model building. 982 983On the device that supports model caching, a model can be saved as a cache file after being built at the device driver layer. The model can be directly read from the cache file in the next build, saving the rebuild time. This API performs different operations based on the model cache directory and version: 984 985- If no file exists in the specified model cache directory, cache the built model to the directory and set the cache version to the value of **version**. 986 987- If a complete cached file exists in the specified model cache directory, and its version number is equal to **version**, read the cached file in the directory and pass it to the underlying device to convert it into an executable model instance. 988 989- If a complete cached file exists in the specified model cache directory, but its version is earlier than **version**, update the cached file. After the model is built in the underlying device, the cached file in the cache directory is overwritten and the version is updated to **version**. 990 991- If a complete cached file exists in the specified model cache directory, but its version is later than **version**, the cached file is not read and the error code **OH_NN_INVALID_PARAMETER** is returned. 992 993- If the cached file in the specified model cache directory is incomplete or you do not have the file access permission, the error code **OH_NN_INVALID_FILE** is returned. 994 995- If the model cache directory does not exist or you do not have the file access permission, the error code **OH_NN_INVALID_PATH** is returned. 996 997**Since**: 9 998 999**Parameters** 1000 1001| Name| Description| 1002| -------- | -------- | 1003| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1004| cachePath | Directory for storing model cache files. This API creates model cache directories for different devices in the cachePath directory. You are advised to use a separate cache directory for each model.| 1005| version | Cached model version.| 1006 1007**Returns** 1008 1009Execution 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). 1010 1011 1012### OH_NNCompilation_SetDevice() 1013 1014``` 1015OH_NN_ReturnCode OH_NNCompilation_SetDevice (OH_NNCompilation *compilation, size_t deviceID ) 1016``` 1017 1018**Description** 1019 1020Sets the device for model building and computing. 1021 1022In the build phase, you need to specify the device for model building and computing. Call [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid) to obtain available device IDs. Then, call [OH_NNDevice_GetType](#oh_nndevice_gettype) and [OH_NNDevice_GetType](#oh_nndevice_gettype) to obtain device information and pass target device IDs to this API for setting. 1023 1024**Since**: 9 1025 1026**Parameters** 1027 1028| Name| Description| 1029| -------- | -------- | 1030| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1031| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 1032 1033**Returns** 1034 1035Execution 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). 1036 1037 1038### OH_NNCompilation_SetPerformanceMode() 1039 1040``` 1041OH_NN_ReturnCode OH_NNCompilation_SetPerformanceMode (OH_NNCompilation *compilation, OH_NN_PerformanceMode performanceMode ) 1042``` 1043 1044**Description** 1045 1046Sets the performance mode for model computing. 1047 1048NNRt allows you to set the performance mode for model computing to meet the requirements of low power consumption and ultimate performance. If this API is not called to set the performance mode in the build phase, the model building 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. 1049 1050If this API is called on a device that does not support setting of the performance mode, the error code **OH_NN_UNAVAILABLE_DEVICE** is returned. 1051 1052**Since**: 9 1053 1054**Parameters** 1055 1056| Name| Description| 1057| -------- | -------- | 1058| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1059| performanceMode | Performance mode for model computing. For details, see [OH_NN_PerformanceMode](#oh_nn_performancemode).| 1060 1061**Returns** 1062 1063Execution 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). 1064 1065 1066 1067### OH_NNCompilation_SetPriority() 1068 1069``` 1070OH_NN_ReturnCode OH_NNCompilation_SetPriority (OH_NNCompilation *compilation, OH_NN_Priority priority ) 1071``` 1072 1073**Description** 1074 1075Sets the priority for model computing. 1076 1077NNRt allows you to set computing priorities for models. The 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. 1078 1079If this API is called on a device that does not support priority setting, the error code **OH_NN_UNAVAILABLE_DEVICE** is returned. 1080 1081**Since**: 9 1082 1083**Parameters** 1084 1085| Name| Description| 1086| -------- | -------- | 1087| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1088| priority | Priority for model computing. For details, see [OH_NN_Priority](#oh_nn_priority).| 1089 1090**Returns** 1091 1092Execution 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). 1093 1094 1095### OH_NNDevice_GetAllDevicesID() 1096 1097``` 1098OH_NN_ReturnCode OH_NNDevice_GetAllDevicesID (const size_t **allDevicesID, uint32_t *deviceCount ) 1099``` 1100 1101**Description** 1102 1103Obtains the ID of the device connected to NNRt. 1104 1105Each device has a unique and fixed ID, which is returned through a uin32_t array. 1106 1107When device IDs are returned through the size_t array, each element of the array is the ID of a single device. Internal managment is used for array memory. The data pointer remains valid before this API is called next time. 1108 1109**Since**: 9 1110 1111**Parameters** 1112 1113| Name| Description| 1114| -------- | -------- | 1115| allDevicesID | Pointer to the **size_t** array. The input **\*allDevicesID** must be a null pointer. Otherwise, the error code **OH_NN_INVALID_PARAMETER** is returned.| 1116| deviceCount | Pointer of the uint32_t type, which is used to return the length of **\*allDevicesID**.| 1117 1118**Returns** 1119 1120Execution 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). 1121 1122 1123### OH_NNDevice_GetName() 1124 1125``` 1126OH_NN_ReturnCode OH_NNDevice_GetName (size_t deviceID, const char **name ) 1127``` 1128 1129**Description** 1130 1131Obtains the name of the specified device. 1132 1133**deviceID** specifies the device ID used to obtain the device name. You can obtain the device ID by calling [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid). If the value of **deviceID** is **0**, the first device in the device list is used by default. 1134 1135**\*name** is a C-style string ended with **'\0'**. 1136 1137**\*name** must be a null pointer. Otherwise, the error code **OH_NN_INVALID_PARAMETER** is returned. For example, you should define **char\* deviceName = NULL**, and then pass **&deviceName** as an input parameter. 1138 1139**Since**: 9 1140 1141**Parameters** 1142 1143| Name| Description| 1144| -------- | -------- | 1145| deviceID | Device ID. If the value of **deviceID** is **0**, the first device in the device list is used by default.| 1146| name | Pointer to the char array, which saves the returned device name.| 1147 1148**Returns** 1149 1150Execution 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). 1151 1152 1153### OH_NNDevice_GetType() 1154 1155``` 1156OH_NN_ReturnCode OH_NNDevice_GetType (size_t deviceID, OH_NN_DeviceType *deviceType ) 1157``` 1158 1159**Description** 1160 1161Obtains the type of the specified device. 1162 1163**deviceID** specifies the device ID used to obtain the device type. If the value of **deviceID** is **0**, the first device in the device list is used by default. Currently, the following device types are supported: 1164 1165- * - **OH_NN_CPU**: CPU device. 1166 1167- * - **OH_NN_GPU**: GPU device. 1168 1169- * - **OH_NN_ACCELERATOR**: machine learning dedicated accelerator. 1170 1171- * - **OH_NN_OTHERS**: other device types. 1172 1173**Since**: 9 1174 1175**Parameters** 1176 1177| Name| Description| 1178| -------- | -------- | 1179| deviceID | Device ID. If the value of **deviceID** is **0**, the first device in the device list is used by default.| 1180| deviceType | Pointer to the [OH_NN_DeviceType](#oh_nn_devicetype) instance. The device type information is returned.| 1181 1182**Returns** 1183 1184Execution 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). 1185 1186 1187### OH_NNExecutor_AllocateInputMemory()<sup>(deprecated)</sup> 1188 1189``` 1190OH_NN_Memory *OH_NNExecutor_AllocateInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, size_t length ) 1191``` 1192 1193**Description** 1194 1195Applies for shared memory for a single model input on the device. 1196 1197NNRt provides an API for proactively applying for shared memory on a device. Based on the specified executor and input index value, this API applies for the shared memory whose size is **length** on the device associated with a single input. Then, it returns the shared memory through the [OH_NN_Memory](_o_h___n_n___memory.md) instance. 1198 1199**Since**: 9 1200 1201**Deprecated**: This API is deprecated since API version 11. 1202 1203**Substitute**: [OH_NNTensor_CreateWithSize()](#oh_nntensor_createwithsize) is recommended. 1204 1205**Parameters** 1206 1207| Name| Description| 1208| -------- | -------- | 1209| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1210| inputIndex | Input index value, which complies with the data input sequence for calling [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs). Assume that **inputIndices** is **{1, 5, 9}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When you apply for the input memory, set the value of this parameter to **{0, 1, 2}**.| 1211| length | Memory size to be applied for, in bytes.| 1212 1213**Returns** 1214 1215Pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. If the operation fails, **NULL** is returned. 1216 1217 1218### OH_NNExecutor_AllocateOutputMemory()<sup>(deprecated)</sup> 1219 1220``` 1221OH_NN_Memory *OH_NNExecutor_AllocateOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, size_t length ) 1222``` 1223 1224**Description** 1225 1226Applies for shared memory for a single model output on the device. 1227 1228NNRt provides an API for proactively applying for shared memory on a device. Based on the specified executor and input index value, this API applies for the shared memory whose size is **length** on the device associated with a single input. Then, it returns the shared memory through the [OH_NN_Memory](_o_h___n_n___memory.md) instance. 1229 1230**Since**: 9 1231 1232**Deprecated**: This API is deprecated since API version 11. 1233 1234**Substitute**: [OH_NNTensor_CreateWithSize()](#oh_nntensor_createwithsize) is recommended. 1235 1236**Parameters** 1237 1238| Name| Description| 1239| -------- | -------- | 1240| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1241| outputIndex | Output index value, index value, which complies with the data input sequence for calling [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs). Assume that **outputIndices** is **{4, 6, 8}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When you apply for the output memory, set the value of this parameter to **{0, 1, 2}**.| 1242| length | Memory size to be applied for, in bytes.| 1243 1244**Returns** 1245 1246Pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. If the operation fails, **NULL** is returned. 1247 1248 1249### OH_NNExecutor_Construct() 1250 1251``` 1252OH_NNExecutor *OH_NNExecutor_Construct (OH_NNCompilation *compilation) 1253``` 1254 1255**Description** 1256 1257Creates an [OH_NNExecutor](#oh_nnexecutor) instance. 1258 1259This API constructs a model inference executor for a device based on the specified [OH_NNCompilation](#oh_nncompilation) instance. Use [OH_NNExecutor_SetInput](#oh_nnexecutor_setinputdeprecated) to set the model input data. After the input data is set, call [OH_NNExecutor_Run](#oh_nnexecutor_rundeprecated) to perform inference and then call [OH_NNExecutor_SetOutput](#oh_nnexecutor_setoutputdeprecated) to obtain the computing result. 1260 1261After an [OH_NNExecutor](#oh_nnexecutor) instance is created through the [OH_NNCompilation](#oh_nncompilation) instance, destroy the [OH_NNCompilation](#oh_nncompilation) instance if it is is no longer needed. 1262 1263**Since**: 9 1264 1265**Parameters** 1266 1267| Name| Description| 1268| -------- | -------- | 1269| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1270 1271**Returns** 1272 1273Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance. If the operation fails, **NULL** is returned. 1274 1275 1276### OH_NNExecutor_CreateInputTensorDesc() 1277 1278``` 1279NN_TensorDesc *OH_NNExecutor_CreateInputTensorDesc (const OH_NNExecutor *executor, size_t index ) 1280``` 1281 1282**Description** 1283 1284Creates the description of an input tensor based on the specified index value. 1285 1286The description contains all types of attribute values of the tensor. If the value of **index** reaches or exceeds the number of input tensors, this API returns an error code. You can obtain the number of input tensors by calling [OH_NNExecutor_GetInputCount](#oh_nnexecutor_getinputcount). 1287 1288**Since**: 11 1289 1290**Parameters** 1291 1292| Name| Description| 1293| -------- | -------- | 1294| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1295| index | Index value of the input tensor.| 1296 1297**Returns** 1298 1299Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 1300 1301 1302### OH_NNExecutor_CreateOutputTensorDesc() 1303 1304``` 1305NN_TensorDesc *OH_NNExecutor_CreateOutputTensorDesc (const OH_NNExecutor *executor, size_t index ) 1306``` 1307 1308**Description** 1309 1310Creates the description of an output tensor based on the specified index value. 1311 1312The description contains all types of attribute values of the tensor. If the value of **index** reaches or exceeds the number of output tensors, this API returns an error code. You can obtain the number of output tensors by calling [OH_NNExecutor_GetOutputCount](#oh_nnexecutor_getoutputcount). 1313 1314**Since**: 11 1315 1316**Parameters** 1317 1318| Name| Description| 1319| -------- | -------- | 1320| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1321| index | Index value of the output tensor.| 1322 1323**Returns** 1324 1325Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 1326 1327 1328### OH_NNExecutor_Destroy() 1329 1330``` 1331void OH_NNExecutor_Destroy (OH_NNExecutor **executor) 1332``` 1333 1334**Description** 1335 1336Destroys an executor instance to release the memory occupied by it. 1337 1338This API needs to be called to release the executor instance created by calling [OH_NNExecutor_Construct](#oh_nnexecutor_construct). Otherwise, memory leak will occur. 1339 1340If **executor** or **\*executor** is a null pointer, this API only prints the warning log and does not execute the release logic. 1341 1342**Since**: 9 1343 1344**Parameters** 1345 1346| Name| Description| 1347| -------- | -------- | 1348| executor | Level-2 pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1349 1350 1351### OH_NNExecutor_DestroyInputMemory()<sup>(deprecated)</sup> 1352 1353``` 1354void OH_NNExecutor_DestroyInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory ) 1355``` 1356 1357**Description** 1358 1359Releases the input memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance. 1360 1361This API needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateInputMemory](#oh_nnexecutor_allocateinputmemorydeprecated). Otherwise, memory leak will occur. The mapping between **inputIndex** and **memory** must be the same as that in memory instance creation. 1362 1363If **memory** or **\*memory** is a null pointer, this API only prints the warning log and does not execute the release logic. 1364 1365**Since**: 9 1366 1367**Deprecated**: This API is deprecated since API version 11. 1368 1369**Substitute**: [OH_NNTensor_Destroy()](#oh_nntensor_destroy) is recommended. 1370 1371**Parameters** 1372 1373| Name| Description| 1374| -------- | -------- | 1375| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1376| inputIndex | Input index value, which complies with the data input sequence for calling [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs). Assume that **inputIndices** is **{1, 5, 9}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When you release the input memory, set the value of this parameter to **{0, 1, 2}**.| 1377| memory | Level-2 pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. After the shared memory is released, this API sets **\*memory** to a null pointer.| 1378 1379 1380### OH_NNExecutor_DestroyOutputMemory()<sup>(deprecated)</sup> 1381 1382``` 1383void OH_NNExecutor_DestroyOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, OH_NN_Memory **memory ) 1384``` 1385 1386**Description** 1387 1388Releases the output memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance. 1389 1390This API needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateOutputMemory](#oh_nnexecutor_allocateoutputmemorydeprecated). Otherwise, memory leak will occur. The mapping between **outputIndex** and **memory** must be the same as that in memory instance creation. 1391 1392If **memory** or **\*memory** is a null pointer, this API only prints the warning log and does not execute the release logic. 1393 1394**Since**: 9 1395 1396**Deprecated**: This API is deprecated since API version 11. 1397 1398**Substitute**: [OH_NNTensor_Destroy()](#oh_nntensor_destroy) is recommended. 1399 1400**Parameters** 1401 1402| Name| Description| 1403| -------- | -------- | 1404| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1405| outputIndex | Output index value, index value, which complies with the data input sequence for calling [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs). Assume that **outputIndices** is **{4, 6, 8}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When you release the output memory, set the value of this parameter to **{0, 1, 2}**.| 1406| memory | Level-2 pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. After the shared memory is released, this API sets **\*memory** to a null pointer.| 1407 1408 1409### OH_NNExecutor_GetInputCount() 1410 1411``` 1412OH_NN_ReturnCode OH_NNExecutor_GetInputCount (const OH_NNExecutor *executor, size_t *inputCount ) 1413``` 1414 1415**Description** 1416 1417Obtains the number of input tensors. 1418 1419You can obtain the number of input tensors from **executor**, and then use [OH_NNExecutor_CreateInputTensorDesc](#oh_nnexecutor_createinputtensordesc) to create a tensor description based on the specified tensor index. 1420 1421**Since**: 11 1422 1423**Parameters** 1424 1425| Name| Description| 1426| -------- | -------- | 1427| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1428| inputCount | Number of returned input tensors.| 1429 1430**Returns** 1431 1432Execution 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). 1433 1434 1435### OH_NNExecutor_GetInputDimRange() 1436 1437``` 1438OH_NN_ReturnCode OH_NNExecutor_GetInputDimRange (const OH_NNExecutor *executor, size_t index, size_t **minInputDims, size_t **maxInputDims, size_t *shapeLength ) 1439``` 1440 1441**Description** 1442 1443Obtains the dimension range of all input tensors. 1444 1445If the input tensor has a dynamic shape, the dimension range supported by the tensor may vary according to device. You can call this API to obtain the dimension range supported by the current device. **\*minInputDims** saves the minimum dimension of the specified input tensor (the number of dimensions matches the shape), while **\*maxInputDims** saves the maximum dimension. For example, if an input tensor has a dynamic shape of [-1, -1, -1, 3], **\*minInputDims** may be [1, 10, 10, 3], and **\*maxInputDims** may be [100, 1024, 1024, 3]. 1446 1447Note: If the value of **index** reaches or exceeds the number of output tensors, this API returns an error code. You can obtain the number of input tensors by calling [OH_NNExecutor_GetInputCount](#oh_nnexecutor_getinputcount). 1448 1449As output parameters, **\*minInputDims** and **\*maxInputDims** cannot be null pointers. Otherwise, an error is returned. For example, you should define **int32_t\* minInDims = NULL**, and then pass **&minInDims** as a parameter. 1450 1451You do not need to release the memory of **\*minInputDims** and **\*maxInputDims**. It is released with **executor**. 1452 1453**Since**: 11 1454 1455**Parameters** 1456 1457| Name| Description| 1458| -------- | -------- | 1459| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1460| index | Index value of the input tensor.| 1461| minInputDims | Pointer to the returned array, which saves the minimum dimension of the specified input tensor (the number of dimensions matches the shape).| 1462| maxInputDims | Pointer to the returned array, which saves the maximum dimension of the specified input tensor (the number of dimensions matches the shape).| 1463| shapeLength | Number of dimensions of the returned input tensor, which is the same as the shape.| 1464 1465**Returns** 1466 1467Execution 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). 1468 1469 1470### OH_NNExecutor_GetOutputCount() 1471 1472``` 1473OH_NN_ReturnCode OH_NNExecutor_GetOutputCount (const OH_NNExecutor *executor, size_t *outputCount ) 1474``` 1475 1476**Description** 1477 1478Obtains the number of output tensors. 1479 1480You can obtain the number of output tensors from **executor**, and then use [OH_NNExecutor_CreateOutputTensorDesc](#oh_nnexecutor_createoutputtensordesc) to create a tensor description based on the specified tensor index. 1481 1482**Since**: 11 1483 1484**Parameters** 1485 1486| Name| Description| 1487| -------- | -------- | 1488| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1489| outputCount | Number of returned output tensors.| 1490 1491**Returns** 1492 1493Execution 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). 1494 1495 1496### OH_NNExecutor_GetOutputShape() 1497 1498``` 1499OH_NN_ReturnCode OH_NNExecutor_GetOutputShape (OH_NNExecutor *executor, uint32_t outputIndex, int32_t **shape, uint32_t *shapeLength ) 1500``` 1501 1502**Description** 1503 1504Obtains the dimension information about the output tensor. 1505 1506You can use this API to obtain information about the specified output dimension and number of dimensions after a single inference is performed by calling [OH_NNExecutor_Run](#oh_nnexecutor_rundeprecated). It is commonly used in dynamic shape input and output scenarios. 1507 1508Note: If the value of **outputIndex** reaches or exceeds the number of output tensors, an error code is returned. You can obtain the number of output tensors by calling [OH_NNExecutor_GetOutputCount](#oh_nnexecutor_getoutputcount). 1509 1510As an output parameter, **\*shape** cannot be a null pointer. Otherwise, an error is returned. For example, you should define **int32_t\* tensorShape = NULL** and pass **&tensorShape** as a parameter. 1511 1512You do not need to release the memory of **shape**. It is released with **executor**. 1513 1514**Since**: 9 1515 1516**Parameters** 1517 1518| Name| Description| 1519| -------- | -------- | 1520| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1521| outputIndex | Output index value, which is the same as the sequence of the output data 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 you obtain information about the output dimension, set the value of this parameter to {0, 1, 2}.| 1522| 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.| 1523| shapeLength | Pointer to the uint32_t type. The number of output dimensions is returned.| 1524 1525**Returns** 1526 1527Execution 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). 1528 1529 1530### OH_NNExecutor_Run()<sup>(deprecated)</sup> 1531 1532``` 1533OH_NN_ReturnCode OH_NNExecutor_Run (OH_NNExecutor *executor) 1534``` 1535 1536**Description** 1537 1538Executes model inference. 1539 1540This API performs end-to-end model inference and computing on the device associated with the executor. 1541 1542**Since**: 9 1543 1544**Deprecated**: This API is deprecated since API version 11. 1545 1546**Substitute**: [OH_NNExecutor_RunSync()](#oh_nnexecutor_runsync) is recommended. 1547 1548**Parameters** 1549 1550| Name| Description| 1551| -------- | -------- | 1552| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1553 1554**Returns** 1555 1556Execution 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). 1557 1558 1559### OH_NNExecutor_RunAsync() 1560 1561``` 1562OH_NN_ReturnCode OH_NNExecutor_RunAsync (OH_NNExecutor *executor, NN_Tensor *inputTensor[], size_t inputCount, NN_Tensor *outputTensor[], size_t outputCount, int32_t timeout, void *userData ) 1563``` 1564 1565**Description** 1566 1567Performs asynchronous inference. 1568 1569You need to create the input and output tensors by calling [OH_NNTensor_Create](#oh_nntensor_create), [OH_NNTensor_CreateWithSize](#oh_nntensor_createwithsize), or [OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd). 1570 1571Then, call [OH_NNTensor_GetDataBuffer](#oh_nntensor_getdatabuffer) o obtain the pointer to the tensor data and copies the input data to it. The executor performs model inference, generates the inference result, and writes the result to the output tensor. 1572 1573If the output tensor has a dynamic shape, you can obtain the actual shape of the output tensor by calling [OH_NNExecutor_GetOutputShape](#oh_nnexecutor_getoutputshape). Alternatively, obtain the tensor description from the input tensor by calling [OH_NNTensor_GetTensorDesc](#oh_nntensor_gettensordesc), and then obtain the actual shape by calling [OH_NNTensorDesc_GetShape](#oh_nntensordesc_getshape). 1574 1575This API works in non-blocking mode and returns the result immediately after being called. You can obtain the inference result and execution return status through the [NN_OnRunDone](#nn_onrundone) callback. If the device driver service stops abnormally during execution, you can use the [NN_OnServiceDied](#nn_onservicedied) callback for exception processing. 1576 1577You can set the [NN_OnRunDone](#nn_onrundone) and [NN_OnServiceDied](#nn_onservicedied) callbacks by calling [OH_NNExecutor_SetOnRunDone](#oh_nnexecutor_setonrundone) and [OH_NNExecutor_SetOnServiceDied](#oh_nnexecutor_setonservicedied). 1578 1579If the inference times out, it is terminated immediately and the error code **OH_NN_TIMEOUT** is returned through the [NN_OnRunDone](#nn_onrundone) callback. 1580 1581**userData** is the identifier used to distinguish different asynchronous inferences and is returned as the first parameter in the callback. You can use any data that can distinguish different inferences as the identifier. 1582 1583**Since**: 11 1584 1585**Parameters** 1586 1587| Name| Description| 1588| -------- | -------- | 1589| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1590| inputTensor | Array of input tensors.| 1591| inputCount | Number of input tensors.| 1592| outputTensor | Array of output tensors.| 1593| outputCount | Number of output tensors.| 1594| timeout | Timeout interval of asynchronous inference, in ms.| 1595| userData | Identifier of asynchronous inference.| 1596 1597**Returns** 1598 1599Execution 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). 1600 1601 1602### OH_NNExecutor_RunSync() 1603 1604``` 1605OH_NN_ReturnCode OH_NNExecutor_RunSync (OH_NNExecutor *executor, NN_Tensor *inputTensor[], size_t inputCount, NN_Tensor *outputTensor[], size_t outputCount ) 1606``` 1607 1608**Description** 1609 1610Performs synchronous inference. 1611 1612You need to create the input and output tensors by calling [OH_NNTensor_Create](#oh_nntensor_create), [OH_NNTensor_CreateWithSize](#oh_nntensor_createwithsize), or [OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd). Then, call [OH_NNTensor_GetDataBuffer](#oh_nntensor_getdatabuffer) o obtain the pointer to the tensor data and copies the input data to it. The executor performs model inference, generates the inference result, and writes the result to the output tensor. 1613 1614If the output tensor has a dynamic shape, you can obtain the actual shape of the output tensor by calling [OH_NNExecutor_GetOutputShape](#oh_nnexecutor_getoutputshape). Alternatively, obtain the tensor description from the input tensor by calling [OH_NNTensor_GetTensorDesc](#oh_nntensor_gettensordesc), and then obtain the actual shape by calling [OH_NNTensorDesc_GetShape](#oh_nntensordesc_getshape). 1615 1616**Since**: 11 1617 1618**Parameters** 1619 1620| Name| Description| 1621| -------- | -------- | 1622| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1623| inputTensor | Array of input tensors.| 1624| inputCount | Number of input tensors.| 1625| outputTensor | Array of output tensors.| 1626| outputCount | Number of output tensors.| 1627 1628**Returns** 1629 1630Execution 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). 1631 1632 1633### OH_NNExecutor_SetInput()<sup>(deprecated)</sup> 1634 1635``` 1636OH_NN_ReturnCode OH_NNExecutor_SetInput (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const void *dataBuffer, size_t length ) 1637``` 1638 1639**Description** 1640 1641Sets the data for a single model input. 1642 1643This API 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 tensor information such as the shape, type, and quantization parameters. 1644 1645NNRt supports models with dynamical shape input. For fixed shape input and dynamic shape input scenarios, this API uses different processing policies. 1646 1647- - Fixed shape input: The attributes of **tensor** must be the same as those of the tensor added by calling [OH_NNModel_AddTensor](#oh_nnmodel_addtensordeprecated) in the build phase. 1648 1649- - 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 API calls to determine the shape input in the computing 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 API is called, you can only change the size of the first dimension, for example, to [3, 224, 224, 3]. If other dimensions are adjusted, **OH_NN_INVALID_PARAMETER** is returned. 1650 1651**Since**: 9 1652 1653**Deprecated**: This API is deprecated since API version 11. 1654 1655**Substitute**: [OH_NNExecutor_RunSync()](#oh_nnexecutor_runsync) is recommended. 1656 1657**Parameters** 1658 1659| Name| Description| 1660| -------- | -------- | 1661| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1662| inputIndex | Input index value, which complies with the data input sequence for calling [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs). Assume that **inputIndices** is **{1, 5, 9}** when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When you set the input data, set the value of this parameter to **{0, 1, 2}**.| 1663| tensor | Tensor corresponding to the input data.| 1664| dataBuffer | Pointer to the input data.| 1665| length | Length of the data memory, in bytes.| 1666 1667**Returns** 1668 1669Execution 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). 1670 1671 1672### OH_NNExecutor_SetInputWithMemory()<sup>(deprecated)</sup> 1673 1674``` 1675OH_NN_ReturnCode OH_NNExecutor_SetInputWithMemory (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const OH_NN_Memory *memory ) 1676``` 1677 1678**Description** 1679 1680Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model input. 1681 1682In the scenario where the memory needs to be managed by yourself, this API 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 by the memory instance. By using this API, you can implement concurrent execution of input setting, computing, and read to improve the data flow inference efficiency. 1683 1684**Since**: 9 1685 1686**Deprecated**: This API is deprecated since API version 11. 1687 1688**Substitute**: [OH_NNExecutor_RunSync()](#oh_nnexecutor_runsync) is recommended. 1689 1690**Parameters** 1691 1692| Name| Description| 1693| -------- | -------- | 1694| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1695| inputIndex | Input index value, which complies with the data input sequence for calling [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs). Assume that **inputIndices** is {1, 5, 9} when [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called. When you set the input shared memory, set the value of this parameter to {0, 1, 2}.| 1696| tensor | Pointer to [OH_NN_Tensor](_o_h___n_n___tensor.md), which is used to set the tensor corresponding to a single input.| 1697| memory | Pointer that points to [OH_NN_Memory](_o_h___n_n___memory.md).| 1698 1699**Returns** 1700 1701Execution 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). 1702 1703 1704### OH_NNExecutor_SetOnRunDone() 1705 1706``` 1707OH_NN_ReturnCode OH_NNExecutor_SetOnRunDone (OH_NNExecutor *executor, NN_OnRunDone onRunDone ) 1708``` 1709 1710**Description** 1711 1712Sets the callback processing function invoked when the asynchronous inference ends. 1713 1714For the definition of the callback function, see [NN_OnRunDone](#nn_onrundone). 1715 1716**Since**: 11 1717 1718**Parameters** 1719 1720| Name| Description| 1721| -------- | -------- | 1722| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1723| onRunDone | Handle of the callback function [NN_OnRunDone](#nn_onrundone)| 1724 1725**Returns** 1726 1727Execution 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). 1728 1729 1730### OH_NNExecutor_SetOnServiceDied() 1731 1732``` 1733OH_NN_ReturnCode OH_NNExecutor_SetOnServiceDied (OH_NNExecutor *executor, NN_OnServiceDied onServiceDied ) 1734``` 1735 1736**Description** 1737 1738Sets the callback processing function invoked when the device driver service terminates unexpectedly during asynchronous inference. 1739 1740For the definition of the callback function, see [NN_OnServiceDied](#nn_onservicedied). 1741 1742**Since**: 11 1743 1744**Parameters** 1745 1746| Name| Description| 1747| -------- | -------- | 1748| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1749| onServiceDied | Callback function handle [NN_OnServiceDied](#nn_onservicedied).| 1750 1751**Returns** 1752 1753Execution 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). 1754 1755 1756### OH_NNExecutor_SetOutput()<sup>(deprecated)</sup> 1757 1758``` 1759OH_NN_ReturnCode OH_NNExecutor_SetOutput (OH_NNExecutor *executor, uint32_t outputIndex, void *dataBuffer, size_t length ) 1760``` 1761 1762**Description** 1763 1764Sets the memory for a single model output. 1765 1766This method binds the buffer pointed by **dataBuffer** to the output specified by **outputIndex**. The length of the buffer is specified by **length**. 1767 1768After [OH_NNExecutor_Run](#oh_nnexecutor_rundeprecated) is called to complete a single model inference, NNRt compares the length of the buffer pointed by **dataBuffer** with the length of the output data and returns different results based on the actual situation. 1769 1770- If the memory size is greater than or equal to the data length, the API copies the inference result to the memory and returns **OH_NN_SUCCESS**. You can read the inference result from **dataBuffer**. 1771 1772- If the memory size is less than the data length, this API returns the error code **OH_NN_INVALID_PARAMETER** and generates a log indicating that the memory size is too small. 1773 1774**Since**: 9 1775 1776**Deprecated**: This API is deprecated since API version 11. 1777 1778**Substitute**: [OH_NNExecutor_RunSync()](#oh_nnexecutor_runsync) is recommended. 1779 1780**Parameters** 1781 1782| Name| Description| 1783| -------- | -------- | 1784| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1785| outputIndex | Output index value, which is the same as the sequence of the output data 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 you set the output memory, set the value of this parameter to **{0, 1, 2}**.| 1786| dataBuffer | Pointer to the output data.| 1787| length | Length of the data memory, in bytes.| 1788 1789**Returns** 1790 1791Execution 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). 1792 1793 1794### OH_NNExecutor_SetOutputWithMemory()<sup>(deprecated)</sup> 1795 1796``` 1797OH_NN_ReturnCode OH_NNExecutor_SetOutputWithMemory (OH_NNExecutor *executor, uint32_t outputIndex, const OH_NN_Memory *memory ) 1798``` 1799 1800**Description** 1801 1802Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model output. 1803 1804In the scenario where the memory needs to be managed by yourself, this API binds the execution output to the [OH_NN_Memory](_o_h___n_n___memory.md) memory instance. During computing, the underlying device writes the computing result to the shared memory pointed by the memory instance. By using this API, you can implement concurrent execution of input setting, computing, and read to improve the data flow inference efficiency. 1805 1806**Since**: 9 1807 1808**Deprecated**: This API is deprecated since API version 11. 1809 1810**Substitute**: [OH_NNExecutor_RunSync()](#oh_nnexecutor_runsync) is recommended. 1811 1812**Parameters** 1813 1814| Name| Description| 1815| -------- | -------- | 1816| executor | Pointer to the executor.| 1817| outputIndex | Output index value, which is the same as the sequence of the output data 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 you set the output shared memory, set the value of this parameter to {0, 1, 2}.| 1818| memory | Pointer to [OH_NN_Memory](_o_h___n_n___memory.md).| 1819 1820**Returns** 1821 1822Execution 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). 1823 1824 1825### OH_NNModel_AddOperation() 1826 1827``` 1828OH_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 ) 1829``` 1830 1831**Description** 1832 1833Adds an operator to a model instance. 1834 1835You can use this API 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 API verifies the attributes of operator parameters and the number of input and output parameters. These attributes must be correctly set when [OH_NNModel_AddTensorToModel](#oh_nnmodel_addtensortomodel) 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). 1836 1837**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_AddTensorToModel](#oh_nnmodel_addtensortomodel). 1838 1839If unnecessary parameters are added for adding an operator, this API returns the error code **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). 1840 1841**Since**: 9 1842 1843**Parameters** 1844 1845| Name| Description| 1846| -------- | -------- | 1847| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 1848| op | Type of the operator to be added. For details, see [OH_NN_OperationType](#oh_nn_operationtype).| 1849| paramIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the parameter tensor index of the operator.| 1850| inputIndices | Pointer to the **OH_NN_UInt32Array** instance, specifying the input tensor index of the operator.| 1851| outputIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the output tensor index of the operator.| 1852 1853**Returns** 1854 1855Execution 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). 1856 1857 1858### OH_NNModel_AddTensor()<sup>(deprecated)</sup> 1859 1860``` 1861OH_NN_ReturnCode OH_NNModel_AddTensor (OH_NNModel *model, const OH_NN_Tensor *tensor ) 1862``` 1863 1864**Description** 1865 1866Adds a tensor to a model instance. 1867 1868The data node and operator parameters in the NNRt model are composed of tensors of the model. You can use this API 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) APIs specify tensors based on the index value. 1869 1870NNRt supports input and output of dynamic shapes. 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. 1871 1872**Since**: 9 1873 1874**Deprecated**: This API is deprecated since API version 11. 1875 1876**Substitute**: [OH_NNModel_AddTensorToModel()](#oh_nnmodel_addtensortomodel) is recommended. 1877 1878**Parameters** 1879 1880| Name| Description| 1881| -------- | -------- | 1882| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 1883| 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.| 1884 1885**Returns** 1886 1887Execution 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). 1888 1889 1890### OH_NNModel_AddTensorToModel() 1891 1892``` 1893OH_NN_ReturnCode OH_NNModel_AddTensorToModel (OH_NNModel *model, const NN_TensorDesc *tensorDesc ) 1894``` 1895 1896**Description** 1897 1898Adds a tensor to a model instance. 1899 1900The data node and operator parameters in the NNRt model are composed of tensors of the model. This API adds tensors to a model instance based on [NN_TensorDesc](#nn_tensordesc). 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) APIs specify tensors based on the index value. 1901 1902NNRt supports input and output of dynamic shapes. 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. 1903 1904**Since**: 9 1905 1906**Parameters** 1907 1908| Name| Description| 1909| -------- | -------- | 1910| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 1911| tensorDesc | Pointer to [NN_TensorDesc](#nn_tensordesc) tensor, which specifies the attributes of the tensor added to the model instance.| 1912 1913**Returns** 1914 1915Execution 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). 1916 1917 1918### OH_NNModel_Construct() 1919 1920``` 1921OH_NNModel *OH_NNModel_Construct (void ) 1922``` 1923 1924**Description** 1925 1926Creates a model instance of the [OH_NNModel](#oh_nnmodel) type and constructs a model instance by using the APIs provided by **OH_NNModel**. 1927 1928Before composition, call [OH_NNModel_Construct](#oh_nnmodel_construct) to create a model instance. Based on the model topology, call the [OH_NNModel_AddTensorToModel](#oh_nnmodel_addtensortomodel), [OH_NNModel_AddOperation](#oh_nnmodel_addoperation), and [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata) APIs to fill in the data and operator nodes of the model, and then call [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) to specify the input and output of the model. After the model topology is constructed, call [OH_NNModel_Finish](#oh_nnmodel_finish) to build the model. 1929 1930After a model instance is used, destroy it by calling [OH_NNModel_Destroy](#oh_nnmodel_destroy) to avoid memory leak. 1931 1932**Since**: 9 1933 1934**Returns** 1935 1936Pointer to the [OH_NNModel](#oh_nnmodel) instance. If the operation fails, **NULL** is returned. 1937 1938 1939### OH_NNModel_Destroy() 1940 1941``` 1942void OH_NNModel_Destroy (OH_NNModel **model) 1943``` 1944 1945**Description** 1946 1947Destroys a model instance. 1948 1949This API needs to be called to destroy the model instance created by calling [OH_NNModel_Construct](#oh_nnmodel_construct). Otherwise, memory leak will occur. 1950 1951If **model** or **\*model** is a null pointer, this API only prints warning logs but does not perform the destruction operation. 1952 1953**Since**: 9 1954 1955**Parameters** 1956 1957| Name| Description| 1958| -------- | -------- | 1959| model | Level-2 pointer to the [OH_NNModel](#oh_nnmodel) instance. After a model instance is destroyed, this API sets **\*model** to a null pointer.| 1960 1961 1962### OH_NNModel_Finish() 1963 1964``` 1965OH_NN_ReturnCode OH_NNModel_Finish (OH_NNModel *model) 1966``` 1967 1968**Description** 1969 1970Completes model composition. 1971 1972After the model topology is set up, call this API to indicate that the composition is complete. After this API is called, additional image composition cannot be performed. If [OH_NNModel_AddTensorToModel](#oh_nnmodel_addtensortomodel), [OH_NNModel_AddOperation](#oh_nnmodel_addoperation), [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata), or [OH_NNModel_SpecifyInputsAndOutputs](#oh_nnmodel_specifyinputsandoutputs) is called, **OH_NN_OPERATION_FORBIDDEN** is returned. 1973 1974Before calling **OH_NNModel_GetAvailableOperations** and **OH_NNCompilation_Construct**, you must call this API to complete composition. 1975 1976**Since**: 9 1977 1978**Parameters** 1979 1980| Name| Description| 1981| -------- | -------- | 1982| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 1983 1984**Returns** 1985 1986Execution 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). 1987 1988 1989### OH_NNModel_GetAvailableOperations() 1990 1991``` 1992OH_NN_ReturnCode OH_NNModel_GetAvailableOperations (OH_NNModel *model, size_t deviceID, const bool **isSupported, uint32_t *opCount ) 1993``` 1994 1995**Description** 1996 1997Checks whether all operators in a model are supported by the device. The result is indicated by a Boolean value. 1998 1999Checks whether the 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 *i*th operator is supported, the value of **(\*isSupported)**[*i*] is **true**. Otherwise, the value is **false**. 2000 2001After this API 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 NNRt and is automatically destroyed after the model instance is destroyed or this API is called again. 2002 2003**Since**: 9 2004 2005**Parameters** 2006 2007| Name| Description| 2008| -------- | -------- | 2009| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2010| deviceID | Device ID to be queried, which can be obtained by using [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid).| 2011| isSupported | Pointer to the **OHHDRMetaData** array. The input **(\*isSupported)** must be a null pointer. Otherwise, **OH_NN_INVALID_PARAMETER** is returned.| 2012| opCount | Number of operators in a model instance, corresponding to the length of the **(\*isSupported)** array.| 2013 2014**Returns** 2015 2016Execution 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). 2017 2018 2019### OH_NNModel_SetTensorData() 2020 2021``` 2022OH_NN_ReturnCode OH_NNModel_SetTensorData (OH_NNModel *model, uint32_t index, const void *dataBuffer, size_t length ) 2023``` 2024 2025**Description** 2026 2027Sets the tensor value. 2028 2029For tensors with constant values (such as model weights), you need to use this API 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_AddTensorToModel](#oh_nnmodel_addtensortomodel). 2030 2031**Since**: 9 2032 2033**Parameters** 2034 2035| Name| Description| 2036| -------- | -------- | 2037| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2038| index | Index value of a tensor.| 2039| dataBuffer | Pointer to the real data memory.| 2040| length | Length of the data memory.| 2041 2042**Returns** 2043 2044Execution 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). 2045 2046 2047### OH_NNModel_SetTensorQuantParams() 2048 2049``` 2050OH_NN_ReturnCode OH_NNModel_SetTensorQuantParams (OH_NNModel *model, uint32_t index, NN_QuantParam *quantParam ) 2051``` 2052 2053**Description** 2054 2055Sets the quantization parameters of a tensor. For details, see [NN_QuantParam](#nn_quantparam). 2056 2057**Since**: 11 2058 2059**Parameters** 2060 2061| Name| Description| 2062| -------- | -------- | 2063| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2064| index | Index value of a tensor.| 2065| quantParam | Pointer to [NN_QuantParam](#nn_quantparam).| 2066 2067**Returns** 2068 2069Execution 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). 2070 2071 2072### OH_NNModel_SetTensorType() 2073 2074``` 2075OH_NN_ReturnCode OH_NNModel_SetTensorType (OH_NNModel *model, uint32_t index, OH_NN_TensorType tensorType ) 2076``` 2077 2078**Description** 2079 2080Sets the tensor type. For details, see [OH_NN_TensorType](#oh_nn_tensortype). 2081 2082**Since**: 11 2083 2084**Parameters** 2085 2086| Name| Description| 2087| -------- | -------- | 2088| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2089| index | Index value of a tensor.| 2090| tensorType | Tensor type.| 2091 2092**Returns** 2093 2094Execution 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). 2095 2096 2097### OH_NNModel_SpecifyInputsAndOutputs() 2098 2099``` 2100OH_NN_ReturnCode OH_NNModel_SpecifyInputsAndOutputs (OH_NNModel *model, const OH_NN_UInt32Array *inputIndices, const OH_NN_UInt32Array *outputIndices ) 2101``` 2102 2103**Description** 2104 2105Sets an index value for the input and output tensors of a model. 2106 2107A tensor must be specified as the end-to-end input and output of a model instance. After a tensor is set as the input or output tensor, you are not allowed to set the tensor data by calling [OH_NNModel_SetTensorData](#oh_nnmodel_settensordata). Instead, call **OH_NNExecutor** in the execution phase to set the input or output tensor data. 2108 2109The 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_AddTensorToModel](#oh_nnmodel_addtensortomodel). 2110 2111Currently, the model input and output cannot be set asynchronously. 2112 2113**Since**: 9 2114 2115**Parameters** 2116 2117| Name| Description| 2118| -------- | -------- | 2119| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2120| inputIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the input tensor of the operator.| 2121| outputIndices | Pointer to the OH_NN_UInt32Array instance, which is used to set the output tensor of the operator.| 2122 2123**Returns** 2124 2125Execution 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). 2126 2127 2128### OH_NNQuantParam_Create() 2129 2130``` 2131NN_QuantParam *OH_NNQuantParam_Create () 2132``` 2133 2134**Description** 2135 2136Creates an [NN_QuantParam](#nn_quantparam) instance. 2137 2138After creating an [NN_QuantParam](#nn_quantparam) quantization parameter instance, set its attribute values by calling [OH_NNQuantParam_SetScales](#oh_nnquantparam_setscales), [OH_NNQuantParam_SetZeroPoints](#oh_nnquantparam_setzeropoints), or [OH_NNQuantParam_SetNumBits](#oh_nnquantparam_setnumbits), and pass it to [NN_Tensor](#nn_tensor) by calling [OH_NNModel_SetTensorQuantParams](#oh_nnmodel_settensorquantparams). Finally, call [OH_NNQuantParam_Destroy](#oh_nnquantparam_destroy) to destroy it to avoid memory leakage. 2139 2140**Since**: 11 2141 2142**Returns** 2143 2144Pointer to the [NN_QuantParam](#nn_quantparam) instance. If the operation fails, **NULL** is returned. 2145 2146 2147### OH_NNQuantParam_Destroy() 2148 2149``` 2150OH_NN_ReturnCode OH_NNQuantParam_Destroy (NN_QuantParam **quantParams) 2151``` 2152 2153**Description** 2154 2155Destroys an [NN_QuantParam](#nn_quantparam) instance. 2156 2157After an [NN_QuantParam](#nn_quantparam) instance is no longer needed after being passed to [NN_Tensor](#nn_tensor), you need to destroy it to avoid memory leak. 2158 2159If **quantParams** or **\*quantParams** is a null pointer, this API only prints warning logs but does not perform the destruction operation. 2160 2161**Since**: 11 2162 2163**Parameters** 2164 2165| Name| Description| 2166| -------- | -------- | 2167| quantParams | Level-2 pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2168 2169**Returns** 2170 2171Execution 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). 2172 2173 2174### OH_NNQuantParam_SetNumBits() 2175 2176``` 2177OH_NN_ReturnCode OH_NNQuantParam_SetNumBits (NN_QuantParam *quantParams, const uint32_t *numBits, size_t quantCount ) 2178``` 2179 2180**Description** 2181 2182Sets the number of quantization bits for an [NN_QuantParam](#nn_quantparam) instance. 2183 2184**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels. 2185 2186**Since**: 11 2187 2188**Parameters** 2189 2190| Name| Description| 2191| -------- | -------- | 2192| quantParams | Pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2193| numBits | Array consisting of quantization bits of all quantization parameters in a tensor.| 2194| quantCount | Number of quantization parameters in a tensor.| 2195 2196**Returns** 2197 2198Execution 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). 2199 2200 2201### OH_NNQuantParam_SetScales() 2202 2203``` 2204OH_NN_ReturnCode OH_NNQuantParam_SetScales (NN_QuantParam *quantParams, const double *scales, size_t quantCount ) 2205``` 2206 2207**Description** 2208 2209Sets the scaling coefficient for an [NN_QuantParam](#nn_quantparam) instance. 2210 2211**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels. 2212 2213**Since**: 11 2214 2215**Parameters** 2216 2217| Name| Description| 2218| -------- | -------- | 2219| quantParams | Pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2220| scales | Array consisting of scaling coefficients of all quantization parameters in the tensor.| 2221| quantCount | Number of quantization parameters in a tensor.| 2222 2223**Returns** 2224 2225Execution 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). 2226 2227 2228### OH_NNQuantParam_SetZeroPoints() 2229 2230``` 2231OH_NN_ReturnCode OH_NNQuantParam_SetZeroPoints (NN_QuantParam *quantParams, const int32_t *zeroPoints, size_t quantCount ) 2232``` 2233 2234**Description** 2235 2236Sets the zero point for an [NN_QuantParam](#nn_quantparam) instance. 2237 2238**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels. 2239 2240**Since**: 11 2241 2242**Parameters** 2243 2244| Name| Description| 2245| -------- | -------- | 2246| quantParams | Pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2247| zeroPoints | Array consisting of zero points of all quantization parameters in a tensor.| 2248| quantCount | Number of quantization parameters in a tensor.| 2249 2250**Returns** 2251 2252Execution 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). 2253 2254 2255### OH_NNTensor_Create() 2256 2257``` 2258NN_Tensor *OH_NNTensor_Create (size_t deviceID, NN_TensorDesc *tensorDesc ) 2259``` 2260 2261**Description** 2262 2263Creates an [NN_Tensor](#nn_tensor) instance from [NN_TensorDesc](#nn_tensordesc). 2264 2265This API uses [OH_NNTensorDesc_GetByteSize](#oh_nntensordesc_getbytesize) to calculate the number of bytes of tensor data and allocate device memory for it. The device driver directly obtains tensor data in zero-copy mode. 2266 2267Note: This API copies **tensorDesc** to [NN_Tensor](#nn_tensor). Therefore, if **tensorDesc** is no longer needed, destroy it by calling [OH_NNTensorDesc_Destroy](#oh_nntensordesc_destroy). 2268 2269If the tensor shape is dynamic, an error code is returned. 2270 2271**deviceID** indicates the selected device. If the value is **0**, the first device in the current device list is used by default. 2272 2273**tensorDesc is mandatory**. If it is a null pointer, an error code is returned. 2274 2275If the [NN_Tensor](#nn_tensor) instance is no longer needed, destroy it by calling [OH_NNTensor_Destroy](#oh_nntensor_destroy). 2276 2277**Since**: 11 2278 2279**Parameters** 2280 2281| Name| Description| 2282| -------- | -------- | 2283| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 2284| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2285 2286**Returns** 2287 2288Pointer to the [NN_Tensor](#nn_tensor) instance. If the operation fails, **NULL** is returned. 2289 2290 2291### OH_NNTensor_CreateWithFd() 2292 2293``` 2294NN_Tensor *OH_NNTensor_CreateWithFd (size_t deviceID, NN_TensorDesc *tensorDesc, int fd, size_t size, size_t offset ) 2295``` 2296 2297**Description** 2298 2299Creates an {\@Link NN_Tensor} instance based on the specified file descriptor of the shared memory and [NN_TensorDesc](#nn_tensordesc) instance. 2300 2301This API reuses the shared memory corresponding to **fd**, which may source from another [NN_Tensor](#nn_tensor) instance. When the tensor created by calling [OH_NNTensor_Destroy](#oh_nntensor_destroy) is destroyed, the memory for storing the tensor data is not released. 2302 2303Note: This API copies **tensorDesc** to [NN_Tensor](#nn_tensor). Therefore, if **tensorDesc** is no longer needed, destroy it by calling [OH_NNTensorDesc_Destroy](#oh_nntensordesc_destroy). 2304 2305**deviceID** indicates the selected device. If the value is **0**, the first device in the current device list is used by default. 2306 2307**tensorDesc** is mandatory. If the pointer is null, an error code is returned. 2308 2309If the [NN_Tensor](#nn_tensor) instance is no longer needed, destroy it by calling [OH_NNTensor_Destroy](#oh_nntensor_destroy). 2310 2311**Since**: 11 2312 2313**Parameters** 2314 2315| Name| Description| 2316| -------- | -------- | 2317| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 2318| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2319| fd | **fd** of the shared memory to be used.| 2320| size | Size of the shared memory to be used.| 2321| offset | Offset of the shared memory to be used.| 2322 2323**Returns** 2324 2325Pointer to the [NN_Tensor](#nn_tensor) instance. If the operation fails, **NULL** is returned. 2326 2327 2328### OH_NNTensor_CreateWithSize() 2329 2330``` 2331NN_Tensor *OH_NNTensor_CreateWithSize (size_t deviceID, NN_TensorDesc *tensorDesc, size_t size ) 2332``` 2333 2334**Description** 2335 2336Creates an [NN_Tensor](#nn_tensor) instance based on the specified memory size and [NN_TensorDesc](#nn_tensordesc) instance. 2337 2338This API uses **size** as the number of bytes of tensor data and allocates device memory to it. The device driver directly obtains tensor data in zero-copy mode. 2339 2340Note that this API copies **tensorDesc** to [NN_Tensor](#nn_tensor). Therefore, if **tensorDesc** is no longer needed, destroy it by calling [OH_NNTensorDesc_Destroy](#oh_nntensordesc_destroy). 2341 2342**deviceID** indicates the ID of the selected device. If the value is **0**, the first device is used. 2343 2344**tensorDesc** is mandatory. If it is a null pointer, an error code is returned. The value of **size** must be greater than or equal to the number of bytes occupied by **tensorDesc**, which can be obtained by calling [OH_NNTensorDesc_GetByteSize](#oh_nntensordesc_getbytesize). Otherwise, an error code is returned. If the tensor shape is dynamic, **size** is not checked. 2345 2346If the [NN_Tensor](#nn_tensor) instance is no longer needed, destroy it by calling [OH_NNTensor_Destroy](#oh_nntensor_destroy). 2347 2348**Since**: 11 2349 2350**Parameters** 2351 2352| Name| Description| 2353| -------- | -------- | 2354| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 2355| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2356| size | Size of the tensor data to be allocated.| 2357 2358**Returns** 2359 2360Pointer to the [NN_Tensor](#nn_tensor) instance. If the operation fails, **NULL** is returned. 2361 2362 2363### OH_NNTensor_Destroy() 2364 2365``` 2366OH_NN_ReturnCode OH_NNTensor_Destroy (NN_Tensor **tensor) 2367``` 2368 2369**Description** 2370 2371Destroys an [NN_Tensor](#nn_tensor) instance. 2372 2373If the [NN_Tensor](#nn_tensor) instance is no longer needed, call this API to destroy it. Otherwise, memory leak will occur. 2374 2375If the **tensor** or **\*tensor** pointer is null, this API returns an error code but does not perform the destruction operation. 2376 2377**Since**: 11 2378 2379**Parameters** 2380 2381| Name| Description| 2382| -------- | -------- | 2383| tensor | Level-2 pointer to the [NN_Tensor](#nn_tensor) instance.| 2384 2385**Returns** 2386 2387Execution 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). 2388 2389 2390### OH_NNTensor_GetDataBuffer() 2391 2392``` 2393void *OH_NNTensor_GetDataBuffer (const NN_Tensor *tensor) 2394``` 2395 2396**Description** 2397 2398Obtains the memory address of [NN_Tensor](#nn_tensor) data. 2399 2400You can read/write data from/to tensor data memory. The data memory is mapped from the shared memory on the device. Therefore, the device driver can directly obtain tensor data in zero-copy mode. 2401 2402Note: Only tensor data in the [offset, size) segment in the corresponding shared memory can be used. **offset** indicates the offset in the shared memory and can be obtained by calling [OH_NNTensor_GetOffset](#oh_nntensor_getoffset). **size** indicates the total size of the shared memory, which can be obtained by calling [OH_NNTensor_GetSize](#oh_nntensor_getsize). 2403 2404If the **tensor** pointer is null, a null pointer is returned. 2405 2406**Since**: 11 2407 2408**Parameters** 2409 2410| Name| Description| 2411| -------- | -------- | 2412| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2413 2414**Returns** 2415 2416Pointer to the tensor data memory. If the operation fails, a null pointer is returned. 2417 2418 2419### OH_NNTensor_GetFd() 2420 2421``` 2422OH_NN_ReturnCode OH_NNTensor_GetFd (const NN_Tensor *tensor, int *fd ) 2423``` 2424 2425**Description** 2426 2427Obtains the file descriptor of the shared memory where [NN_Tensor](#nn_tensor) data is stored. 2428 2429**fd** corresponds to a device shared memory and can be used by another [NN_Tensor](#nn_tensor) through [OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd). 2430 2431If **tensor** or **fd** pointer is null, an error code is returned. 2432 2433**Since**: 11 2434 2435**Parameters** 2436 2437| Name| Description| 2438| -------- | -------- | 2439| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2440| fd | **fd** of the shared memory.| 2441 2442**Returns** 2443 2444Execution 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). 2445 2446 2447### OH_NNTensor_GetOffset() 2448 2449``` 2450OH_NN_ReturnCode OH_NNTensor_GetOffset (const NN_Tensor *tensor, size_t *offset ) 2451``` 2452 2453**Description** 2454 2455Obtains the offset of [NN_Tensor](#nn_tensor) data in the shared memory. 2456 2457**offset** indicates the offset of tensor data in the corresponding shared memory. It can be used by another [NN_Tensor](#nn_tensor) together with **fd** and **size** of the shared memory through [OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd). 2458 2459Note: Only tensor data in the [offset, size) segment in the shared memory corresponding to the **fd** can be used. **offset** indicates the offset in the shared memory and can be obtained by calling [OH_NNTensor_GetOffset](#oh_nntensor_getoffset). **size** indicates the total size of the shared memory, which can be obtained by calling [OH_NNTensor_GetSize](#oh_nntensor_getsize). 2460 2461If **tensor** or **offset** pointer is null, an error code is returned. 2462 2463**Since**: 11 2464 2465**Parameters** 2466 2467| Name| Description| 2468| -------- | -------- | 2469| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2470| offset | Offset for the fd of the tensor.| 2471 2472**Returns** 2473 2474Execution 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). 2475 2476 2477### OH_NNTensor_GetSize() 2478 2479``` 2480OH_NN_ReturnCode OH_NNTensor_GetSize (const NN_Tensor *tensor, size_t *size ) 2481``` 2482 2483**Description** 2484 2485Obtains the size of the shared memory where the [NN_Tensor](#nn_tensor) data is stored. 2486 2487The value of **size** is the same as that of [OH_NNTensor_CreateWithSize](#oh_nntensor_createwithsize) and [OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd). However, for a tensor created by using [OH_NNTensor_Create](#oh_nntensor_create), the value of **size** is equal to the number of bytes actually occupied by the tensor data, which can be obtained by calling [OH_NNTensorDesc_GetByteSize](#oh_nntensordesc_getbytesize). 2488 2489Note: Only tensor data in the [offset, size) segment in the shared memory corresponding to the **fd** can be used. **offset** indicates the offset in the shared memory and can be obtained by calling [OH_NNTensor_GetOffset](#oh_nntensor_getoffset). **size** indicates the total size of the shared memory, which can be obtained by calling [OH_NNTensor_GetSize](#oh_nntensor_getsize). 2490 2491If the **tensor** or **size** pointer is null, an error code is returned. 2492 2493**Since**: 11 2494 2495**Parameters** 2496 2497| Name| Description| 2498| -------- | -------- | 2499| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2500| size | Size of the shared memory where the returned data is located.| 2501 2502**Returns** 2503 2504Execution 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). 2505 2506 2507### OH_NNTensor_GetTensorDesc() 2508 2509``` 2510NN_TensorDesc *OH_NNTensor_GetTensorDesc (const NN_Tensor *tensor) 2511``` 2512 2513**Description** 2514 2515Obtains an [NN_TensorDesc](#nn_tensordesc) instance of [NN_Tensor](#nn_tensor). 2516 2517You can use this API to obtain the pointer of the [NN_TensorDesc](#nn_tensordesc) instance of the specified [NN_Tensor](#nn_tensor) instance. You can obtain tensor attributes of various types from the returned [NN_TensorDesc](#nn_tensordesc) instance, such as the name, data format, data type, and shape. 2518 2519You should not destroy the returned [NN_TensorDesc](#nn_tensordesc) instance because it points to an internal instance of [NN_Tensor](#nn_tensor). Otherwise, once [OH_NNTensor_Destroy](#oh_nntensor_destroy) is called, a crash may occur due to double memory release. 2520 2521If the **tensor** pointer is null, a null pointer is returned. 2522 2523**Since**: 11 2524 2525**Parameters** 2526 2527| Name| Description| 2528| -------- | -------- | 2529| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2530 2531**Returns** 2532 2533Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 2534 2535 2536### OH_NNTensorDesc_Create() 2537 2538``` 2539NN_TensorDesc *OH_NNTensorDesc_Create () 2540``` 2541 2542**Description** 2543 2544Creates an [NN_TensorDesc](#nn_tensordesc) instance. 2545 2546[NN_TensorDesc](#nn_tensordesc) describes various tensor attributes, such as the name, data type, shape, and format. 2547 2548You can create an [NN_Tensor](#nn_tensor) instance based on the input [NNN_TensorDesc](#nn_tensordesc) instance by calling the following APIs: 2549 2550[OH_NNTensor_Create](#oh_nntensor_create) 2551 2552[OH_NNTensor_CreateWithSize](#oh_nntensor_createwithsize) 2553 2554[OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd) 2555 2556Note: This API copies the [NN_TensorDesc](#nn_tensordesc) instance to [NN_Tensor](#nn_tensor). This way, you can create multiple [NN_Tensor](#nn_tensor) instances with the same [NN_TensorDesc](#nn_tensordesc) instance. If the [NN_TensorDesc](#nn_tensordesc) instance is no longer needed, destroy it by calling [OH_NNTensorDesc_Destroy](#oh_nntensordesc_destroy). 2557 2558**Since**: 11 2559 2560**Returns** 2561 2562Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 2563 2564 2565### OH_NNTensorDesc_Destroy() 2566 2567``` 2568OH_NN_ReturnCode OH_NNTensorDesc_Destroy (NN_TensorDesc **tensorDesc) 2569``` 2570 2571**Description** 2572 2573Releases an [NN_TensorDesc](#nn_tensordesc) instance. 2574 2575If the [NN_TensorDesc](#nn_tensordesc) instance is no longer needed, call this API to destroy it. Otherwise, memory leakage occurs. 2576 2577If **tensorDesc** or **\*tensorDesc** is a null pointer, an error code is returned but the object will not be destroyed. 2578 2579**Since**: 11 2580 2581**Parameters** 2582 2583| Name| Description| 2584| -------- | -------- | 2585| tensorDesc | Level-2 pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2586 2587**Returns** 2588 2589Execution 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). 2590 2591 2592### OH_NNTensorDesc_GetByteSize() 2593 2594``` 2595OH_NN_ReturnCode OH_NNTensorDesc_GetByteSize (const NN_TensorDesc *tensorDesc, size_t *byteSize ) 2596``` 2597 2598**Description** 2599 2600Obtains the number of bytes occupied by the tensor data obtained through calculation based on the shape and data type of an [NN_TensorDesc](#nn_tensordesc) instance. 2601 2602The number of bytes occupied by data can be calculated based on the shape and data type of [NN_TensorDesc](#nn_tensordesc) by calling this API. 2603 2604If the tensor shape is dynamically variable, this API returns an error code and **byteSize** is **0**. 2605 2606To obtain the number of elements in the tensor data, call [OH_NNTensorDesc_GetElementCount](#oh_nntensordesc_getelementcount). 2607 2608If **tensorDesc** or **byteSize** is a null pointer, an error code is returned. 2609 2610**Since**: 11 2611 2612**Parameters** 2613 2614| Name| Description| 2615| -------- | -------- | 2616| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2617| byteSize | Size of the returned data, in bytes.| 2618 2619**Returns** 2620 2621Execution 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). 2622 2623 2624### OH_NNTensorDesc_GetDataType() 2625 2626``` 2627OH_NN_ReturnCode OH_NNTensorDesc_GetDataType (const NN_TensorDesc *tensorDesc, OH_NN_DataType *dataType ) 2628``` 2629 2630**Description** 2631 2632Obtains the data type of an [NN_TensorDesc](#nn_tensordesc) instance. 2633 2634You can use this API to obtain the data type of a specified [NN_TensorDesc](#nn_tensordesc) instance. 2635 2636If **tensorDesc** or **dataType** is a null pointer, an error code is returned. 2637 2638**Since**: 11 2639 2640**Parameters** 2641 2642| Name| Description| 2643| -------- | -------- | 2644| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2645| dataType | Tensor data type.| 2646 2647**Returns** 2648 2649Execution 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). 2650 2651 2652### OH_NNTensorDesc_GetElementCount() 2653 2654``` 2655OH_NN_ReturnCode OH_NNTensorDesc_GetElementCount (const NN_TensorDesc *tensorDesc, size_t *elementCount ) 2656``` 2657 2658**Description** 2659 2660Obtains the number of elements in an [NN_TensorDesc](#nn_tensordesc) instance. 2661 2662You can use this API to obtain the number of elements in the specified [NN_TensorDesc](#nn_tensordesc) instance. To obtain the size of tensor data, call [OH_NNTensorDesc_GetByteSize](#oh_nntensordesc_getbytesize). 2663 2664If the tensor shape is dynamically variable, this API returns an error code and **elementCount** is **0**. 2665 2666If **tensorDesc** or **elementCount** is a null pointer, an error code is returned. 2667 2668**Since**: 11 2669 2670**Parameters** 2671 2672| Name| Description| 2673| -------- | -------- | 2674| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2675| elementCount | Number of elements.| 2676 2677**Returns** 2678 2679Execution 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). 2680 2681 2682### OH_NNTensorDesc_GetFormat() 2683 2684``` 2685OH_NN_ReturnCode OH_NNTensorDesc_GetFormat (const NN_TensorDesc *tensorDesc, OH_NN_Format *format ) 2686``` 2687 2688**Description** 2689 2690Obtains the data format of an [NN_TensorDesc](#nn_tensordesc) instance. 2691 2692You can use this API to obtain the data format (that is, [NN_TensorDesc](#nn_tensordesc)) of the specified [NN_TensorDesc](#nn_tensordesc) instance. 2693 2694If **tensorDesc** or **format** is a null pointer, an error code is returned. 2695 2696**Since**: 11 2697 2698**Parameters** 2699 2700| Name| Description| 2701| -------- | -------- | 2702| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2703| format | Tensor data format.| 2704 2705**Returns** 2706 2707Execution 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). 2708 2709 2710### OH_NNTensorDesc_GetName() 2711 2712``` 2713OH_NN_ReturnCode OH_NNTensorDesc_GetName (const NN_TensorDesc *tensorDesc, const char **name ) 2714``` 2715 2716**Description** 2717 2718Obtains the name of an [NN_TensorDesc](#nn_tensordesc) instance. 2719 2720You can use this API to obtain the name of the specified [NN_TensorDesc](#nn_tensordesc) instance. The value of **\*name** is a C-style string ending with **\0**. 2721 2722If **tensorDesc** or **name** is a null pointer, an error code is returned. As an output parameter, **\*name** must be a null pointer. Otherwise, an error code is returned. For example, you should define **char\* tensorName = NULL** and pass **&tensorName** as a parameter of **name**. 2723 2724You do not need to release the memory of **name**. When **tensorDesc** is destroyed, it is automatically released. 2725 2726**Since**: 11 2727 2728**Parameters** 2729 2730| Name| Description| 2731| -------- | -------- | 2732| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2733| name | Tensor name.| 2734 2735**Returns** 2736 2737Execution 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). 2738 2739 2740### OH_NNTensorDesc_GetShape() 2741 2742``` 2743OH_NN_ReturnCode OH_NNTensorDesc_GetShape (const NN_TensorDesc *tensorDesc, int32_t **shape, size_t *shapeLength ) 2744``` 2745 2746**Description** 2747 2748Obtains the shape of an [NN_TensorDesc](#nn_tensordesc) instance. 2749 2750You can use this API to obtain the shape of the specified [NN_TensorDesc](#nn_tensordesc) instance. 2751 2752If **tensorDesc**, **shape**, or **shapeLength** is a null pointer, an error code is returned. As an output parameter, **\*shape** must be a null pointer. Otherwise, an error code is returned. For example, you should define **int32_t\* tensorShape = NULL** and pass **&tensorShape** as a parameter of **shape**. 2753 2754You do not need to release the memory of **shape**. When **tensorDesc** is destroyed, it is automatically released. 2755 2756**Since**: 11 2757 2758**Parameters** 2759 2760| Name| Description| 2761| -------- | -------- | 2762| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2763| shape | List of tensor shapes.| 2764| shapeLength | Length of the list of tensor shapes.| 2765 2766**Returns** 2767 2768Execution 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). 2769 2770 2771### OH_NNTensorDesc_SetDataType() 2772 2773``` 2774OH_NN_ReturnCode OH_NNTensorDesc_SetDataType (NN_TensorDesc *tensorDesc, OH_NN_DataType dataType ) 2775``` 2776 2777**Description** 2778 2779Sets the data type of an [NN_TensorDesc](#nn_tensordesc) instance. 2780 2781After an [NN_TensorDesc](#nn_tensordesc) instance is created, call this API to set the tensor data type. 2782 2783If **tensorDesc** is a null pointer, an error code is returned. 2784 2785**Since**: 11 2786 2787**Parameters** 2788 2789| Name| Description| 2790| -------- | -------- | 2791| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2792| dataType | Tensor data type to be set.| 2793 2794**Returns** 2795 2796Execution 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). 2797 2798 2799### OH_NNTensorDesc_SetFormat() 2800 2801``` 2802OH_NN_ReturnCode OH_NNTensorDesc_SetFormat (NN_TensorDesc *tensorDesc, OH_NN_Format format ) 2803``` 2804 2805**Description** 2806 2807Sets the data format of an [NN_TensorDesc](#nn_tensordesc) instance. 2808 2809After an [NN_TensorDesc](#nn_tensordesc) instance is created, call this API to set the data format of the tensor. 2810 2811If **tensorDesc** is a null pointer, an error code is returned. 2812 2813**Since**: 11 2814 2815**Parameters** 2816 2817| Name| Description| 2818| -------- | -------- | 2819| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2820| format | Tensor data format to be set.| 2821 2822**Returns** 2823 2824Execution 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). 2825 2826 2827### OH_NNTensorDesc_SetName() 2828 2829``` 2830OH_NN_ReturnCode OH_NNTensorDesc_SetName (NN_TensorDesc *tensorDesc, const char *name ) 2831``` 2832 2833**Description** 2834 2835Sets the name of an [NN_TensorDesc](#nn_tensordesc) instance. 2836 2837After an [NN_TensorDesc](#nn_tensordesc) instance is created, call this API to set the tensor name. The value of **\*name** is a C-style string ending with **\0**. 2838 2839If **tensorDesc** or **name** is a null pointer, an error code is returned. 2840 2841**Since**: 11 2842 2843**Parameters** 2844 2845| Name| Description| 2846| -------- | -------- | 2847| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2848| name | Name of the tensor to be set.| 2849 2850**Returns** 2851 2852Execution 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). 2853 2854 2855### OH_NNTensorDesc_SetShape() 2856 2857``` 2858OH_NN_ReturnCode OH_NNTensorDesc_SetShape (NN_TensorDesc *tensorDesc, const int32_t *shape, size_t shapeLength ) 2859``` 2860 2861**Description** 2862 2863Sets the data shape of an [NN_TensorDesc](#nn_tensordesc) instance. 2864 2865After an [NN_TensorDesc](#nn_tensordesc) instance is created, call this API to set the tensor shape. 2866 2867If **tensorDesc** or **shape** is a null pointer or **shapeLength** is **0**, an error code is returned. 2868 2869**Since**: 11 2870 2871**Parameters** 2872 2873| Name| Description| 2874| -------- | -------- | 2875| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2876| shape | List of tensor shapes to be set.| 2877| shapeLength | Length of the list of tensor shapes.| 2878 2879**Returns** 2880 2881Execution 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). 2882