1# NeuralNeworkRuntime 2 3 4## Overview 5 6Provides APIs for accelerating the Neural Network Runtime (NNRt) model inference. 7 8**Since**: 9 9 10 11## Summary 12 13 14### File 15 16| Name| Description| 17| -------- | -------- | 18| [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.| 19| [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.| 20| [neural_network_runtime_type.h](neural__network__runtime__type_8h.md) | Defines the structure and enums for NNRt.| 21 22 23### Structs 24 25| Name| Description| 26| -------- | -------- | 27| struct [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) | Used to store a 32-bit unsigned integer array.| 28| struct [OH_NN_QuantParam](_o_h___n_n___quant_param.md) | Used to define the quantization information.| 29| struct [OH_NN_Tensor](_o_h___n_n___tensor.md) | Used to define the tensor structure.| 30| struct [OH_NN_Memory](_o_h___n_n___memory.md) | Used to define the memory structure.| 31 32 33### Types 34 35| Name| Description| 36| -------- | -------- | 37| typedef struct [OH_NNModel](#oh_nnmodel) [OH_NNModel](#oh_nnmodel) | Model handle.| 38| typedef struct [OH_NNCompilation](#oh_nncompilation) [OH_NNCompilation](#oh_nncompilation) | Compiler handle.| 39| typedef struct [OH_NNExecutor](#oh_nnexecutor) [OH_NNExecutor](#oh_nnexecutor) | Executor handle.| 40| typedef struct [NN_QuantParam](#nn_quantparam) [NN_QuantParam](#nn_quantparam) | Quantization parameter handle.| 41| typedef struct [NN_TensorDesc](#nn_tensordesc) [NN_TensorDesc](#nn_tensordesc) | Tensor description handle.| 42| typedef struct [NN_Tensor](#nn_tensor) [NN_Tensor](#nn_tensor) | Tensor handle.| 43| typedef enum [OH_NN_PerformanceMode](#oh_nn_performancemode) [OH_NN_PerformanceMode](#oh_nn_performancemode) | Performance modes of the device.| 44| typedef enum [OH_NN_Priority](#oh_nn_priority) [OH_NN_Priority](#oh_nn_priority) | Priorities of a model inference task.| 45| typedef enum [OH_NN_ReturnCode](#oh_nn_returncode) [OH_NN_ReturnCode](#oh_nn_returncode) | Error codes for NNRt.| 46| typedef void(\* [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.| 47| typedef void(\* [NN_OnServiceDied](#nn_onservicedied)) (void \*userData) | Handle of the callback processing function invoked when the device driver service terminates unexpectedly during asynchronous inference.| 48| typedef enum [OH_NN_FuseType](#oh_nn_fusetype) [OH_NN_FuseType](#oh_nn_fusetype) | Activation function types in the fusion operator for NNRt.| 49| typedef enum [OH_NN_Format](#oh_nn_format) [OH_NN_Format](#oh_nn_format) | Formats of tensor data.| 50| typedef enum [OH_NN_DeviceType](#oh_nn_devicetype) [OH_NN_DeviceType](#oh_nn_devicetype) | Device types supported by NNRt.| 51| typedef enum [OH_NN_DataType](#oh_nn_datatype) [OH_NN_DataType](#oh_nn_datatype) | Data types supported by NNRt.| 52| typedef enum [OH_NN_OperationType](#oh_nn_operationtype) [OH_NN_OperationType](#oh_nn_operationtype) | Operator types supported by NNRt.| 53| typedef enum [OH_NN_TensorType](#oh_nn_tensortype) [OH_NN_TensorType](#oh_nn_tensortype) | Tensor types.| 54| typedef struct [OH_NN_UInt32Array](_o_h___n_n___u_int32_array.md) [OH_NN_UInt32Array](#oh_nn_uint32array) | Used to store a 32-bit unsigned integer array.| 55| typedef struct [OH_NN_QuantParam](_o_h___n_n___quant_param.md) [OH_NN_QuantParam](#oh_nn_quantparam) | Used to define the quantization information.| 56| typedef struct [OH_NN_Tensor](_o_h___n_n___tensor.md) [OH_NN_Tensor](#oh_nn_tensor) | Used to define the tensor structure.| 57| typedef struct [OH_NN_Memory](_o_h___n_n___memory.md) [OH_NN_Memory](#oh_nn_memory) | Used to define the memory structure.| 58 59 60### Enums 61 62| Name| Description| 63| -------- | -------- | 64| [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.| 65| [OH_NN_Priority](#oh_nn_priority) { OH_NN_PRIORITY_NONE = 0, OH_NN_PRIORITY_LOW = 1, OH_NN_PRIORITY_MEDIUM = 2, OH_NN_PRIORITY_HIGH = 3 } | Priorities of a model inference task.| 66| [OH_NN_ReturnCode](#oh_nn_returncode) {<br>OH_NN_SUCCESS = 0, OH_NN_FAILED = 1, OH_NN_INVALID_PARAMETER = 2, OH_NN_MEMORY_ERROR = 3,<br>OH_NN_OPERATION_FORBIDDEN = 4, OH_NN_NULL_PTR = 5, OH_NN_INVALID_FILE = 6, OH_NN_UNAVALIDABLE_DEVICE = 7,<br>OH_NN_INVALID_PATH = 8, OH_NN_TIMEOUT = 9, OH_NN_UNSUPPORTED = 10, OH_NN_CONNECTION_EXCEPTION = 11,<br>OH_NN_SAVE_CACHE_EXCEPTION = 12, OH_NN_DYNAMIC_SHAPE = 13, OH_NN_UNAVAILABLE_DEVICE = 14<br>} | Error codes for NNRt.| 67| [OH_NN_FuseType](#oh_nn_fusetype) : int8_t { OH_NN_FUSED_NONE = 0, OH_NN_FUSED_RELU = 1, OH_NN_FUSED_RELU6 = 2 } | Activation function types in the fusion operator for NNRt.| 68| [OH_NN_Format](#oh_nn_format) { OH_NN_FORMAT_NONE = 0, OH_NN_FORMAT_NCHW = 1, OH_NN_FORMAT_NHWC = 2, OH_NN_FORMAT_ND = 3 } | Formats of tensor data.| 69| [OH_NN_DeviceType](#oh_nn_devicetype) { OH_NN_OTHERS = 0, OH_NN_CPU = 1, OH_NN_GPU = 2, OH_NN_ACCELERATOR = 3 } | Device types supported by NNRt.| 70| [OH_NN_DataType](#oh_nn_datatype) {<br>OH_NN_UNKNOWN = 0, OH_NN_BOOL = 1, OH_NN_INT8 = 2, OH_NN_INT16 = 3,<br>OH_NN_INT32 = 4, OH_NN_INT64 = 5, OH_NN_UINT8 = 6, OH_NN_UINT16 = 7,<br>OH_NN_UINT32 = 8, OH_NN_UINT64 = 9, OH_NN_FLOAT16 = 10, OH_NN_FLOAT32 = 11,<br>OH_NN_FLOAT64 = 12<br>} | Data types supported by NNRt.| 71| [OH_NN_OperationType](#oh_nn_operationtype) {<br>OH_NN_OPS_ADD = 1, OH_NN_OPS_AVG_POOL = 2, OH_NN_OPS_BATCH_NORM = 3, OH_NN_OPS_BATCH_TO_SPACE_ND = 4,<br>OH_NN_OPS_BIAS_ADD = 5, OH_NN_OPS_CAST = 6, OH_NN_OPS_CONCAT = 7, OH_NN_OPS_CONV2D = 8,<br>OH_NN_OPS_CONV2D_TRANSPOSE = 9, OH_NN_OPS_DEPTHWISE_CONV2D_NATIVE = 10, OH_NN_OPS_DIV = 11, OH_NN_OPS_ELTWISE = 12,<br>OH_NN_OPS_EXPAND_DIMS = 13, OH_NN_OPS_FILL = 14, OH_NN_OPS_FULL_CONNECTION = 15, OH_NN_OPS_GATHER = 16,<br>OH_NN_OPS_HSWISH = 17, OH_NN_OPS_LESS_EQUAL = 18, OH_NN_OPS_MATMUL = 19, OH_NN_OPS_MAXIMUM = 20,<br>OH_NN_OPS_MAX_POOL = 21, OH_NN_OPS_MUL = 22, OH_NN_OPS_ONE_HOT = 23, OH_NN_OPS_PAD = 24,<br>OH_NN_OPS_POW = 25, OH_NN_OPS_SCALE = 26, OH_NN_OPS_SHAPE = 27, OH_NN_OPS_SIGMOID = 28,<br>OH_NN_OPS_SLICE = 29, OH_NN_OPS_SOFTMAX = 30, OH_NN_OPS_SPACE_TO_BATCH_ND = 31, OH_NN_OPS_SPLIT = 32,<br>OH_NN_OPS_SQRT = 33, OH_NN_OPS_SQUARED_DIFFERENCE = 34, OH_NN_OPS_SQUEEZE = 35, OH_NN_OPS_STACK = 36,<br>OH_NN_OPS_STRIDED_SLICE = 37, OH_NN_OPS_SUB = 38, OH_NN_OPS_TANH = 39, OH_NN_OPS_TILE = 40,<br>OH_NN_OPS_TRANSPOSE = 41, OH_NN_OPS_REDUCE_MEAN = 42, OH_NN_OPS_RESIZE_BILINEAR = 43, OH_NN_OPS_RSQRT = 44,<br>OH_NN_OPS_RESHAPE = 45, OH_NN_OPS_PRELU = 46, OH_NN_OPS_RELU = 47, OH_NN_OPS_RELU6 = 48,<br>OH_NN_OPS_LAYER_NORM = 49, OH_NN_OPS_REDUCE_PROD = 50, OH_NN_OPS_REDUCE_ALL = 51, OH_NN_OPS_QUANT_DTYPE_CAST = 52,<br>OH_NN_OPS_TOP_K = 53, OH_NN_OPS_ARG_MAX = 54, OH_NN_OPS_UNSQUEEZE = 55, OH_NN_OPS_GELU = 56,<br>OH_NN_OPS_UNSTACK = 57, OH_NN_OPS_ABS = 58, OH_NN_OPS_ERF = 59, OH_NN_OPS_EXP = 60,<br>OH_NN_OPS_LESS = 61, OH_NN_OPS_SELECT = 62, OH_NN_OPS_SQUARE = 63, OH_NN_OPS_FLATTEN = 64,<br>OH_NN_OPS_DEPTH_TO_SPACE = 65, OH_NN_OPS_RANGE = 66, OH_NN_OPS_INSTANCE_NORM = 67, OH_NN_OPS_CONSTANT_OF_SHAPE = 68,<br>OH_NN_OPS_BROADCAST_TO = 69, OH_NN_OPS_EQUAL = 70, OH_NN_OPS_GREATER = 71, OH_NN_OPS_NOT_EQUAL = 72,<br>OH_NN_OPS_GREATER_EQUAL = 73, OH_NN_OPS_LEAKY_RELU = 74, OH_NN_OPS_LSTM = 75, OH_NN_OPS_CLIP = 76,<br>OH_NN_OPS_ALL = 77, OH_NN_OPS_ASSERT = 78, OH_NN_OPS_COS = 79, OH_NN_OPS_LOG = 80,<br>OH_NN_OPS_LOGICAL_AND = 81, OH_NN_OPS_LOGICAL_NOT = 82, OH_NN_OPS_MOD = 83, OH_NN_OPS_NEG = 84,<br>OH_NN_OPS_RECIPROCAL = 85, OH_NN_OPS_SIN = 86, OH_NN_OPS_WHERE = 87, OH_NN_OPS_SPARSE_TO_DENSE = 88,<br>OH_NN_OPS_LOGICAL_OR = 89, OH_NN_OPS_CEIL = 90, OH_NN_OPS_CROP = 91, OH_NN_OPS_DETECTION_POST_PROCESS = 92,<br>OH_NN_OPS_FLOOR = 93, OH_NN_OPS_L2_NORMALIZE = 94, OH_NN_OPS_LOG_SOFTMAX = 95, OH_NN_OPS_LRN = 96,<br>OH_NN_OPS_MINIMUM = 97, OH_NN_OPS_RANK = 98, OH_NN_OPS_REDUCE_MAX = 99, OH_NN_OPS_REDUCE_MIN = 100,<br>OH_NN_OPS_REDUCE_SUM = 101, OH_NN_OPS_ROUND = 102, OH_NN_OPS_SCATTER_ND = 103, OH_NN_OPS_SPACE_TO_DEPTH = 104,<br>OH_NN_OPS_SWISH = 105, OH_NN_OPS_REDUCE_L2 = 106, OH_NN_OPS_HARD_SIGMOID = 107, OH_NN_OPS_GATHER_ND = 108<br>} | Operator types supported by NNRt.| 72| [OH_NN_TensorType](#oh_nn_tensortype) {<br>OH_NN_TENSOR = 0, OH_NN_ADD_ACTIVATIONTYPE = 1, OH_NN_AVG_POOL_KERNEL_SIZE = 2, OH_NN_AVG_POOL_STRIDE = 3,<br>OH_NN_AVG_POOL_PAD_MODE = 4, OH_NN_AVG_POOL_PAD = 5, OH_NN_AVG_POOL_ACTIVATION_TYPE = 6, OH_NN_BATCH_NORM_EPSILON = 7,<br>OH_NN_BATCH_TO_SPACE_ND_BLOCKSIZE = 8, OH_NN_BATCH_TO_SPACE_ND_CROPS = 9, OH_NN_CONCAT_AXIS = 10, OH_NN_CONV2D_STRIDES = 11,<br>OH_NN_CONV2D_PAD = 12, OH_NN_CONV2D_DILATION = 13, OH_NN_CONV2D_PAD_MODE = 14, OH_NN_CONV2D_ACTIVATION_TYPE = 15,<br>OH_NN_CONV2D_GROUP = 16, OH_NN_CONV2D_TRANSPOSE_STRIDES = 17, OH_NN_CONV2D_TRANSPOSE_PAD = 18, OH_NN_CONV2D_TRANSPOSE_DILATION = 19,<br>OH_NN_CONV2D_TRANSPOSE_OUTPUT_PADDINGS = 20, OH_NN_CONV2D_TRANSPOSE_PAD_MODE = 21, OH_NN_CONV2D_TRANSPOSE_ACTIVATION_TYPE = 22, OH_NN_CONV2D_TRANSPOSE_GROUP = 23,<br>OH_NN_DEPTHWISE_CONV2D_NATIVE_STRIDES = 24, OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD = 25, OH_NN_DEPTHWISE_CONV2D_NATIVE_DILATION = 26, OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD_MODE = 27,<br>OH_NN_DEPTHWISE_CONV2D_NATIVE_ACTIVATION_TYPE = 28, OH_NN_DIV_ACTIVATIONTYPE = 29, OH_NN_ELTWISE_MODE = 30, OH_NN_FULL_CONNECTION_AXIS = 31,<br>OH_NN_FULL_CONNECTION_ACTIVATIONTYPE = 32, OH_NN_MATMUL_TRANSPOSE_A = 33, OH_NN_MATMUL_TRANSPOSE_B = 34, OH_NN_MATMUL_ACTIVATION_TYPE = 35,<br>OH_NN_MAX_POOL_KERNEL_SIZE = 36, OH_NN_MAX_POOL_STRIDE = 37, OH_NN_MAX_POOL_PAD_MODE = 38, OH_NN_MAX_POOL_PAD = 39,<br>OH_NN_MAX_POOL_ACTIVATION_TYPE = 40, OH_NN_MUL_ACTIVATION_TYPE = 41, OH_NN_ONE_HOT_AXIS = 42, OH_NN_PAD_CONSTANT_VALUE = 43,<br>OH_NN_SCALE_ACTIVATIONTYPE = 44, OH_NN_SCALE_AXIS = 45, OH_NN_SOFTMAX_AXIS = 46, OH_NN_SPACE_TO_BATCH_ND_BLOCK_SHAPE = 47,<br>OH_NN_SPACE_TO_BATCH_ND_PADDINGS = 48, OH_NN_SPLIT_AXIS = 49, OH_NN_SPLIT_OUTPUT_NUM = 50, OH_NN_SPLIT_SIZE_SPLITS = 51,<br>OH_NN_SQUEEZE_AXIS = 52, OH_NN_STACK_AXIS = 53, OH_NN_STRIDED_SLICE_BEGIN_MASK = 54, OH_NN_STRIDED_SLICE_END_MASK = 55,<br>OH_NN_STRIDED_SLICE_ELLIPSIS_MASK = 56, OH_NN_STRIDED_SLICE_NEW_AXIS_MASK = 57, OH_NN_STRIDED_SLICE_SHRINK_AXIS_MASK = 58, OH_NN_SUB_ACTIVATIONTYPE = 59,<br>OH_NN_REDUCE_MEAN_KEEP_DIMS = 60, OH_NN_RESIZE_BILINEAR_NEW_HEIGHT = 61, OH_NN_RESIZE_BILINEAR_NEW_WIDTH = 62, OH_NN_RESIZE_BILINEAR_PRESERVE_ASPECT_RATIO = 63,<br>OH_NN_RESIZE_BILINEAR_COORDINATE_TRANSFORM_MODE = 64, OH_NN_RESIZE_BILINEAR_EXCLUDE_OUTSIDE = 65, OH_NN_LAYER_NORM_BEGIN_NORM_AXIS = 66, OH_NN_LAYER_NORM_EPSILON = 67,<br>OH_NN_LAYER_NORM_BEGIN_PARAM_AXIS = 68, OH_NN_LAYER_NORM_ELEMENTWISE_AFFINE = 69, OH_NN_REDUCE_PROD_KEEP_DIMS = 70, OH_NN_REDUCE_ALL_KEEP_DIMS = 71,<br>OH_NN_QUANT_DTYPE_CAST_SRC_T = 72, OH_NN_QUANT_DTYPE_CAST_DST_T = 73, OH_NN_TOP_K_SORTED = 74, OH_NN_ARG_MAX_AXIS = 75,<br>OH_NN_ARG_MAX_KEEPDIMS = 76, OH_NN_UNSQUEEZE_AXIS = 77, OH_NN_UNSTACK_AXIS = 78, OH_NN_FLATTEN_AXIS = 79,<br>OH_NN_DEPTH_TO_SPACE_BLOCK_SIZE = 80, OH_NN_DEPTH_TO_SPACE_MODE = 81, OH_NN_RANGE_START = 82, OH_NN_RANGE_LIMIT = 83,<br>OH_NN_RANGE_DELTA = 84, OH_NN_CONSTANT_OF_SHAPE_DATA_TYPE = 85, OH_NN_CONSTANT_OF_SHAPE_VALUE = 86, OH_NN_BROADCAST_TO_SHAPE = 87,<br>OH_NN_INSTANCE_NORM_EPSILON = 88, OH_NN_EXP_BASE = 89, OH_NN_EXP_SCALE = 90, OH_NN_EXP_SHIFT = 91,<br>OH_NN_LEAKY_RELU_NEGATIVE_SLOPE = 92, OH_NN_LSTM_BIDIRECTIONAL = 93, OH_NN_LSTM_HAS_BIAS = 94, OH_NN_LSTM_INPUT_SIZE = 95,<br>OH_NN_LSTM_HIDDEN_SIZE = 96, OH_NN_LSTM_NUM_LAYERS = 97, OH_NN_LSTM_NUM_DIRECTIONS = 98, OH_NN_LSTM_DROPOUT = 99,<br>OH_NN_LSTM_ZONEOUT_CELL = 100, OH_NN_LSTM_ZONEOUT_HIDDEN = 101, OH_NN_LSTM_PROJ_SIZE = 102, OH_NN_CLIP_MAX = 103,<br>OH_NN_CLIP_MIN = 104, OH_NN_ALL_KEEP_DIMS = 105, OH_NN_ASSERT_SUMMARIZE = 106, OH_NN_POW_SCALE = 107,<br>OH_NN_POW_SHIFT = 108, OH_NN_AVG_POOL_ROUND_MODE = 109, OH_NN_AVG_POOL_GLOBAL = 110, OH_NN_FULL_CONNECTION_HAS_BIAS = 111,<br>OH_NN_FULL_CONNECTION_USE_AXIS = 112, OH_NN_GELU_APPROXIMATE = 113, OH_NN_MAX_POOL_ROUND_MODE = 114, OH_NN_MAX_POOL_GLOBAL = 115,<br>OH_NN_PAD_PADDING_MODE = 116, OH_NN_REDUCE_MEAN_REDUCE_TO_END = 117, OH_NN_REDUCE_MEAN_COEFF = 118, OH_NN_REDUCE_PROD_REDUCE_TO_END = 119,<br>OH_NN_REDUCE_PROD_COEFF = 120, OH_NN_REDUCE_ALL_REDUCE_TO_END = 121, OH_NN_REDUCE_ALL_COEFF = 122, OH_NN_TOP_K_AXIS = 123,<br>OH_NN_ARG_MAX_TOP_K = 124, OH_NN_ARG_MAX_OUT_MAX_VALUE = 125, OH_NN_QUANT_DTYPE_CAST_AXIS = 126, OH_NN_SLICE_AXES = 127,<br>OH_NN_TILE_DIMS = 128, OH_NN_CROP_AXIS = 129, OH_NN_CROP_OFFSET = 130, OH_NN_DETECTION_POST_PROCESS_INPUT_SIZE = 131,<br>OH_NN_DETECTION_POST_PROCESS_SCALE = 132, OH_NN_DETECTION_POST_PROCESS_NMS_IOU_THRESHOLD = 133, OH_NN_DETECTION_POST_PROCESS_NMS_SCORE_THRESHOLD = 134, OH_NN_DETECTION_POST_PROCESS_MAX_DETECTIONS = 135,<br>OH_NN_DETECTION_POST_PROCESS_DETECTIONS_PER_CLASS = 136, OH_NN_DETECTION_POST_PROCESS_MAX_CLASSES_PER_DETECTION = 137, OH_NN_DETECTION_POST_PROCESS_NUM_CLASSES = 138, OH_NN_DETECTION_POST_PROCESS_USE_REGULAR_NMS = 139,<br>OH_NN_DETECTION_POST_PROCESS_OUT_QUANTIZED = 140, OH_NN_L2_NORMALIZE_AXIS = 141, OH_NN_L2_NORMALIZE_EPSILON = 142, OH_NN_L2_NORMALIZE_ACTIVATION_TYPE = 143,<br>OH_NN_LOG_SOFTMAX_AXIS = 144, OH_NN_LRN_DEPTH_RADIUS = 145, OH_NN_LRN_BIAS = 146, OH_NN_LRN_ALPHA = 147,<br>OH_NN_LRN_BETA = 148, OH_NN_LRN_NORM_REGION = 149, OH_NN_SPACE_TO_DEPTH_BLOCK_SIZE = 150, OH_NN_REDUCE_MAX_KEEP_DIMS = 151,<br>OH_NN_REDUCE_MAX_REDUCE_TO_END = 152, OH_NN_REDUCE_MAX_COEFF = 153, OH_NN_REDUCE_MIN_KEEP_DIMS = 154, OH_NN_REDUCE_MIN_REDUCE_TO_END = 155,<br>OH_NN_REDUCE_MIN_COEFF = 156, OH_NN_REDUCE_SUM_KEEP_DIMS = 157, OH_NN_REDUCE_SUM_REDUCE_TO_END = 158, OH_NN_REDUCE_SUM_COEFF = 159,<br>OH_NN_REDUCE_L2_KEEP_DIMS = 160, OH_NN_REDUCE_L2_REDUCE_TO_END = 161, OH_NN_REDUCE_L2_COEFF = 162<br>} | Tensor types.| 73 74 75### Functions 76 77| Name| Description| 78| -------- | -------- | 79| [OH_NNCompilation](#oh_nncompilation) \* [OH_NNCompilation_Construct](#oh_nncompilation_construct) (const [OH_NNModel](#oh_nnmodel) \*model) | Creates a model building instance of the [OH_NNCompilation](#oh_nncompilation) type.| 80| [OH_NNCompilation](#oh_nncompilation) \* [OH_NNCompilation_ConstructWithOfflineModelFile](#oh_nncompilation_constructwithofflinemodelfile) (const char \*modelPath) | Creates a model building instance based on an offline model file.| 81| [OH_NNCompilation](#oh_nncompilation) \* [OH_NNCompilation_ConstructWithOfflineModelBuffer](#oh_nncompilation_constructwithofflinemodelbuffer) (const void \*modelBuffer, size_t modelSize) | Creates a model building instance based on the offline model buffer.| 82| [OH_NNCompilation](#oh_nncompilation) \* [OH_NNCompilation_ConstructForCache](#oh_nncompilation_constructforcache) () | Creates an empty model building instance for later recovery from the model cache.| 83| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 84| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 85| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 86| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNCompilation_SetDevice](#oh_nncompilation_setdevice) ([OH_NNCompilation](#oh_nncompilation) \*compilation, size_t deviceID) | Sets the device for model building and computing.| 87| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 88| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 89| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority) ([OH_NNCompilation](#oh_nncompilation) \*compilation, [OH_NN_Priority](#oh_nn_priority) priority) | Sets the priority for model computing.| 90| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16) ([OH_NNCompilation](#oh_nncompilation) \*compilation, bool enableFloat16) | Enables float16 for computing.| 91| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNCompilation_Build](#oh_nncompilation_build) ([OH_NNCompilation](#oh_nncompilation) \*compilation) | Performs model building.| 92| void [OH_NNCompilation_Destroy](#oh_nncompilation_destroy) ([OH_NNCompilation](#oh_nncompilation) \*\*compilation) | Destroys a model building instance of the [OH_NNCompilation](#oh_nncompilation) type.| 93| [NN_TensorDesc](#nn_tensordesc) \* [OH_NNTensorDesc_Create](#oh_nntensordesc_create) () | Creates an [NN_TensorDesc](#nn_tensordesc) instance.| 94| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNTensorDesc_Destroy](#oh_nntensordesc_destroy) ([NN_TensorDesc](#nn_tensordesc) \*\*tensorDesc) | Releases an [NN_TensorDesc](#nn_tensordesc) instance.| 95| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNTensorDesc_SetName](#oh_nntensordesc_setname) ([NN_TensorDesc](#nn_tensordesc) \*tensorDesc, const char \*name) | Sets the name of an [NN_TensorDesc](#nn_tensordesc) instance.| 96| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 97| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 98| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 99| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 100| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 101| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 102| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 103| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 104| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 105| [NN_Tensor](#nn_tensor) \* [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).| 106| [NN_Tensor](#nn_tensor) \* [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.| 107| [NN_Tensor](#nn_tensor) \* [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.| 108| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNTensor_Destroy](#oh_nntensor_destroy) ([NN_Tensor](#nn_tensor) \*\*tensor) | Destroys an [NN_Tensor](#nn_tensor) instance.| 109| [NN_TensorDesc](#nn_tensordesc) \* [OH_NNTensor_GetTensorDesc](#oh_nntensor_gettensordesc) (const [NN_Tensor](#nn_tensor) \*tensor) | Obtains an [NN_TensorDesc](#nn_tensordesc) instance of [NN_Tensor](#nn_tensor).| 110| void \* [OH_NNTensor_GetDataBuffer](#oh_nntensor_getdatabuffer) (const [NN_Tensor](#nn_tensor) \*tensor) | Obtains the memory address of [NN_Tensor](#nn_tensor) data.| 111| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 112| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 113| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 114| [OH_NNExecutor](#oh_nnexecutor) \* [OH_NNExecutor_Construct](#oh_nnexecutor_construct) ([OH_NNCompilation](#oh_nncompilation) \*compilation) | Creates an [OH_NNExecutor](#oh_nnexecutor) instance.| 115| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 116| void [OH_NNExecutor_Destroy](#oh_nnexecutor_destroy) ([OH_NNExecutor](#oh_nnexecutor) \*\*executor) | Destroys an executor instance to release the memory occupied by it.| 117| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNExecutor_GetInputCount](#oh_nnexecutor_getinputcount) (const [OH_NNExecutor](#oh_nnexecutor) \*executor, size_t \*inputCount) | Obtains the number of input tensors.| 118| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNExecutor_GetOutputCount](#oh_nnexecutor_getoutputcount) (const [OH_NNExecutor](#oh_nnexecutor) \*executor, size_t \*outputCount) | Obtains the number of output tensors.| 119| [NN_TensorDesc](#nn_tensordesc) \* [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.| 120| [NN_TensorDesc](#nn_tensordesc) \* [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.| 121| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 122| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 123| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 124| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 125| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 126| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid) (const size_t \*\*allDevicesID, uint32_t \*deviceCount) | Obtains the ID of the device connected to NNRt.| 127| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNDevice_GetName](#oh_nndevice_getname) (size_t deviceID, const char \*\*name) | Obtains the name of the specified device.| 128| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNDevice_GetType](#oh_nndevice_gettype) (size_t deviceID, [OH_NN_DeviceType](#oh_nn_devicetype) \*deviceType) | Obtains the type of the specified device.| 129| [NN_QuantParam](#nn_quantparam) \* [OH_NNQuantParam_Create](#oh_nnquantparam_create) () | Creates an [NN_QuantParam](#nn_quantparam) instance.| 130| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 131| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 132| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 133| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNQuantParam_Destroy](#oh_nnquantparam_destroy) ([NN_QuantParam](#nn_quantparam) \*\*quantParams) | Destroys an [NN_QuantParam](#nn_quantparam) instance.| 134| [OH_NNModel](#oh_nnmodel) \* [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**.| 135| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNModel_AddTensorToModel](#oh_nnmodel_addtensortomodel) ([OH_NNModel](#oh_nnmodel) \*model, const [NN_TensorDesc](#nn_tensordesc) \*tensorDesc) | Adds a tensor to a model instance.| 136| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNModel_SetTensorData](#oh_nnmodel_settensordata) ([OH_NNModel](#oh_nnmodel) \*model, uint32_t index, const void \*dataBuffer, size_t length) | Sets the tensor value.| 137| [OH_NN_ReturnCode](#oh_nn_returncode)[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).| 138| [OH_NN_ReturnCode](#oh_nn_returncode)[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).| 139| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 140| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 141| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNModel_Finish](#oh_nnmodel_finish) ([OH_NNModel](#oh_nnmodel) \*model) | Completes model composition.| 142| void [OH_NNModel_Destroy](#oh_nnmodel_destroy) ([OH_NNModel](#oh_nnmodel) \*\*model) | Destroys a model instance.| 143| [OH_NN_ReturnCode](#oh_nn_returncode)[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.| 144| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNModel_AddTensor](#oh_nnmodel_addtensor) ([OH_NNModel](#oh_nnmodel) \*model, const [OH_NN_Tensor](_o_h___n_n___tensor.md) \*tensor) | Adds a tensor to a model instance.| 145| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNExecutor_SetInput](#oh_nnexecutor_setinput) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, const [OH_NN_Tensor](_o_h___n_n___tensor.md) \*tensor, const void \*dataBuffer, size_t length) | Sets the data for a single model input.| 146| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNExecutor_SetOutput](#oh_nnexecutor_setoutput) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, void \*dataBuffer, size_t length) | Sets the memory for a single model output.| 147| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNExecutor_Run](#oh_nnexecutor_run) ([OH_NNExecutor](#oh_nnexecutor) \*executor) | Executes model inference.| 148| [OH_NN_Memory](_o_h___n_n___memory.md) \* [OH_NNExecutor_AllocateInputMemory](#oh_nnexecutor_allocateinputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, size_t length) | Applies for shared memory for a single model input on the device.| 149| [OH_NN_Memory](_o_h___n_n___memory.md) \* [OH_NNExecutor_AllocateOutputMemory](#oh_nnexecutor_allocateoutputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, size_t length) | Applies for shared memory for a single model output on the device.| 150| void [OH_NNExecutor_DestroyInputMemory](#oh_nnexecutor_destroyinputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, [OH_NN_Memory](_o_h___n_n___memory.md) \*\*memory) | Releases the input memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance.| 151| void [OH_NNExecutor_DestroyOutputMemory](#oh_nnexecutor_destroyoutputmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, [OH_NN_Memory](_o_h___n_n___memory.md) \*\*memory) | Releases the output memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance.| 152| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNExecutor_SetInputWithMemory](#oh_nnexecutor_setinputwithmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t inputIndex, const [OH_NN_Tensor](_o_h___n_n___tensor.md) \*tensor, const [OH_NN_Memory](_o_h___n_n___memory.md) \*memory) | Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model input.| 153| [OH_NN_ReturnCode](#oh_nn_returncode)[OH_NNExecutor_SetOutputWithMemory](#oh_nnexecutor_setoutputwithmemory) ([OH_NNExecutor](#oh_nnexecutor) \*executor, uint32_t outputIndex, const [OH_NN_Memory](_o_h___n_n___memory.md) \*memory) | Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model output.| 154 155 156## Type Description 157 158 159### NN_OnRunDone 160 161``` 162typedef void(* NN_OnRunDone) (void *userData, OH_NN_ReturnCode errCode, void *outputTensor[], int32_t outputCount) 163``` 164 165**Description** 166 167Handle of the callback processing function invoked when the asynchronous inference ends. 168 169Use 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. 170 171**Since**: 11 172 173**Parameters** 174 175| Name| Description| 176| -------- | -------- | 177| userData | Identifier of asynchronous inference. The value is the same as the **userData** parameter passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync).| 178| errCode | Return result (defined by [OH_NN_ReturnCode](#oh_nn_returncode) of the asynchronous inference.| 179| outputTensor | Output tensor for asynchronous inference. The value is the same as the **outputTensor** parameter passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync).| 180| 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).| 181 182 183### NN_OnServiceDied 184 185``` 186typedef void(* NN_OnServiceDied) (void *userData) 187``` 188 189**Description** 190 191Handle of the callback processing function invoked when the device driver service terminates unexpectedly during asynchronous inference. 192 193You need to rebuild the model if the callback is invoked. 194 195Use 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). 196 197**Since**: 11 198 199**Parameters** 200 201| Name| Description| 202| -------- | -------- | 203| userData | Identifier of asynchronous inference. The value is the same as the **userData** parameter passed to [OH_NNExecutor_RunAsync](#oh_nnexecutor_runasync).| 204 205 206### NN_QuantParam 207 208``` 209typedef struct NN_QuantParamNN_QuantParam 210``` 211 212**Description** 213 214Quantization parameter handle. 215 216**Since**: 11 217 218 219### NN_Tensor 220 221``` 222typedef struct NN_Tensor NN_Tensor 223``` 224 225**Description** 226 227Tensor handle. 228 229**Since**: 11 230 231 232### NN_TensorDesc 233 234``` 235typedef struct NN_TensorDesc NN_TensorDesc 236``` 237 238**Description** 239 240Tensor description handle. 241 242**Since**: 11 243 244 245### OH_NN_DataType 246 247``` 248typedef enum OH_NN_DataType OH_NN_DataType 249``` 250 251**Description** 252 253Data types supported by NNRt. 254 255**Since**: 9 256 257 258### OH_NN_DeviceType 259 260``` 261typedef enum OH_NN_DeviceType OH_NN_DeviceType 262``` 263 264**Description** 265 266Device types supported by NNRt. 267 268**Since**: 9 269 270 271### OH_NN_Format 272 273``` 274typedef enum OH_NN_Format OH_NN_Format 275``` 276 277**Description** 278 279Formats of tensor data. 280 281**Since**: 9 282 283 284### OH_NN_FuseType 285 286``` 287typedef enum OH_NN_FuseType OH_NN_FuseType 288``` 289 290**Description** 291 292Activation function types in the fusion operator for NNRt. 293 294**Since**: 9 295 296 297### OH_NN_Memory 298 299``` 300typedef struct OH_NN_Memory OH_NN_Memory 301``` 302 303**Description** 304 305Used to define the memory structure. 306 307**Since**: 9 308 309 310### OH_NN_OperationType 311 312``` 313typedef enum OH_NN_OperationType OH_NN_OperationType 314``` 315 316**Description** 317 318Operator types supported by NNRt. 319 320**Since**: 9 321 322 323### OH_NN_PerformanceMode 324 325``` 326typedef enum OH_NN_PerformanceMode OH_NN_PerformanceMode 327``` 328 329**Description** 330 331Performance modes of the device. 332 333**Since**: 9 334 335 336### OH_NN_Priority 337 338``` 339typedef enum OH_NN_Priority OH_NN_Priority 340``` 341 342**Description** 343 344Priorities of a model inference task. 345 346**Since**: 9 347 348 349### OH_NN_QuantParam 350 351``` 352typedef struct OH_NN_QuantParam OH_NN_QuantParam 353``` 354 355**Description** 356 357Used to define the quantization information. 358 359In quantization scenarios, the 32-bit floating-point data type is quantized into the fixed-point data type according to the following formula: 360 361 362 363where, **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: 364 365 366 367 368 369The **clamp** function is defined as follows: 370 371 372 373**Since**: 9 374 375 376### OH_NN_ReturnCode 377 378``` 379typedef enum OH_NN_ReturnCode OH_NN_ReturnCode 380``` 381 382**Description** 383 384Error codes for NNRt. 385 386**Since**: 9 387 388 389### OH_NN_Tensor 390 391``` 392typedef struct OH_NN_Tensor OH_NN_Tensor 393``` 394 395**Description** 396 397Used to define the tensor structure. 398 399It 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. 400 401**Since**: 9 402 403 404### OH_NN_TensorType 405 406``` 407typedef enum OH_NN_TensorType OH_NN_TensorType 408``` 409 410**Description** 411 412Defines tensor types. 413 414Tensors 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](_o_h___n_n___tensor.md) instance to **OH_NN_CONV2D_PAD**. The settings of other operator parameters are similar. The enumerated values are named in the format OH_NN_{*Operator name*}_{*Attribute name*}. 415 416**Since**: 9 417 418 419### OH_NN_UInt32Array 420 421``` 422typedef struct OH_NN_UInt32Array OH_NN_UInt32Array 423``` 424 425**Description** 426 427Defines the structure for storing 32-bit unsigned integer arrays. 428 429**Since**: 9 430 431 432### OH_NNCompilation 433 434``` 435typedef struct OH_NNCompilation OH_NNCompilation 436``` 437 438**Description** 439 440Compiler handle. 441 442**Since**: 9 443 444 445### OH_NNExecutor 446 447``` 448typedef struct OH_NNExecutor OH_NNExecutor 449``` 450 451**Description** 452 453Executor handle. 454 455**Since**: 9 456 457 458### OH_NNModel 459 460``` 461typedef struct OH_NNModel OH_NNModel 462``` 463 464**Description** 465 466Model handle. 467 468**Since**: 9 469 470 471## Enum Description 472 473 474### OH_NN_DataType 475 476``` 477enum OH_NN_DataType 478``` 479 480**Description** 481 482Data types supported by NNRt. 483 484**Since**: 9 485 486| Value| Description| 487| -------- | -------- | 488| OH_NN_UNKNOWN | Unknown type.| 489| OH_NN_BOOL | bool type.| 490| OH_NN_INT8 | int8 type.| 491| OH_NN_INT16 | int16 type.| 492| OH_NN_INT32 | int32 type.| 493| OH_NN_INT64 | int64 type.| 494| OH_NN_UINT8 | uint8 type.| 495| OH_NN_UINT16 | uint16 type.| 496| OH_NN_UINT32 | uint32 type.| 497| OH_NN_UINT64 | uint64 type.| 498| OH_NN_FLOAT16 | float16 type.| 499| OH_NN_FLOAT32 | float32 type.| 500| OH_NN_FLOAT64 | float64 type.| 501 502 503### OH_NN_DeviceType 504 505``` 506enum OH_NN_DeviceType 507``` 508 509**Description** 510 511Device types supported by NNRt. 512 513**Since**: 9 514 515| Value| Description| 516| -------- | -------- | 517| OH_NN_OTHERS | Devices that are not CPU, GPU, or dedicated accelerator.| 518| OH_NN_CPU | CPU.| 519| OH_NN_GPU | GPU.| 520| OH_NN_ACCELERATOR | Dedicated device accelerator.| 521 522 523### OH_NN_Format 524 525``` 526enum OH_NN_Format 527``` 528 529**Description** 530 531Formats of tensor data. 532 533**Since**: 9 534 535| Value| Description| 536| -------- | -------- | 537| OH_NN_FORMAT_NONE | The tensor does not have a specific arrangement type (such as scalar or vector).| 538| OH_NN_FORMAT_NCHW | The tensor arranges data in NCHW format.| 539| OH_NN_FORMAT_NHWC | The tensor arranges data in NHWC format.| 540| OH_NN_FORMAT_ND<sup>11+</sup> | The tensor arranges data in ND format.| 541 542 543### OH_NN_FuseType 544 545``` 546enum OH_NN_FuseType : int8_t 547``` 548 549**Description** 550 551Activation function types in the fusion operator for NNRt. 552 553**Since**: 9 554 555| Value| Description| 556| -------- | -------- | 557| OH_NN_FUSED_NONE | The fusion activation function is not specified.| 558| OH_NN_FUSED_RELU | Fusion relu activation function.| 559| OH_NN_FUSED_RELU6 | Fusion relu6 activation function.| 560 561 562### OH_NN_OperationType 563 564``` 565enum OH_NN_OperationType 566``` 567 568**Description** 569 570Operator types supported by NNRt. 571 572**Since**: 9 573 574| Value| Description| 575| -------- | -------- | 576| 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 **OH_NN_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.| 577| 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 with a length of 2 in the format of [kernelHeight, kernelWeight], 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 with a length of 2 in the format of [strideHeight, strideWeight], 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>- **roundMode**: boundary processing mode, which is an optional value of the int type. When the pooling core cannot completely cover the input feature map, the output feature map is rounded down. The value **0** indicates rounding down, and the value **1** indicates rounding up.<br>- **global**: bool value indicating whether to perform the average pooling operation on the entire input tensor.<br>- **activationType**: integer constant contained in **OH_NN_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 with a length of 2 in the format of [kernelHeight, kernelWeight], where the first number indicates the kernel height, and the second number indicates the kernel width. <br>- **strides**: kernel moving stride. It is int array with a length of 2 in the format of [strideHeight, strideWeight], 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 with a length of 4 in the format of [top, bottom, left, right], and the nearest neighbor values are used for padding.<br>- **roundMode**: boundary processing mode, which is an optional value of the int type. When the pooling core cannot completely cover the input feature map, the output feature map is rounded down. The value **0** indicates rounding down, and the value **1** indicates rounding up.<br>- **global**: bool value indicating whether to perform the average pooling operation on the entire input tensor.<br>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>**output**: average pooling result of the input.| 578| OH_NN_OPS_BATCH_NORM | The input tensor is normalized in batches, and a transformation is applied to keep the average output close to 0 and the output standard deviation close to 1.<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.| 579| OH_NN_OPS_BATCH_TO_SPACE_ND | Divides batch dimension of a 4D tensor into small blocks by **blockSize** and interleaves them into the spatial dimension.<br>Input:<br>- **input**: input tensor. The dimension will be divided into small blocks, and these blocks will be interleaved into the spatial dimension.<br>Parameters:<br>- **blockSize**: size of blocks to be interleaved into the spatial dimension. The value is an array with a length of 2 in the format of [heightBlock, weightBlock].<br>- **crops**: elements truncated from the spatial dimension of the output. The value is a 2D array with the shape of (2, 2) in the format of [[crop0Start, crop0End], [crop1Start, crop1End]].<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 / (blockSize[0] \* blockSize[1]), h' = h \* blockSize[0] - crops[0][0] - crops[0][1], w' = w \* blockSize[1] - crops[1][0] - crops[1][1], and c'= c.| 580| 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.| 581| 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.| 582| 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.| 583| 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 with a length of 2 in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array with a length of 2 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 **inChannel**. 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 **inChannel**, it is a group convolution.<br>- **activationType**: integer constant contained in **OH_NN_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 with a length of 2 in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array with a length of 2 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 with a length of 4 in the format of [top, bottom, left, right].<br>- **group**: number of groups in which the input is divided by **inChannel**. The value is of the int type. If **group** is **1**, it is a conventional convolution. If **group** is equal to **inChannel**, it is a 2D depthwise convolution. In this case, group==inChannel==outChannel. If **group** is greater than **1** and less than **inChannel**, it is a group convolution. In this case, outChannel==group.<br>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: convolution computing result.| 584| 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 with a length of 2 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 with a length of 2 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 **inChannel**. 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 **inChannel**, 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 **OH_NN_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 with a length of 2 in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array with a length of 2 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 with a length of 4 in the format of [top, bottom, left, right].<br>- **group**: number of groups in which the input is divided by **inChannel**. 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 **inChannel**, 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 **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>**output**: computing result after convolution and transposition.| 585| 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 with a length of 2 in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array with a length of 2 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>- **activationType**: integer constant contained in **OH_NN_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 with a length of 2 in the format of [strideHeight, strideWidth].<br>- **dilation**: dilation size of the convolution kernel in height and weight. It is an int array with a length of 2 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 with a length of 4 in the format of [top, bottom, left, right].<br>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: convolution computing result.| 586| 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 **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: result of dividing **input1** by **input2**.| 587| 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**.| 588| 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.| 589| 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.| 590| 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>- **hasBias**: boolean value indicating whether to use the bias offset.<br>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: computed tensor.<br>If the input contains the **axis** or **useAxis** 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. The default value is **0**.<br>- **useAxis**: boolean value indicating whether to use the **axis** parameter. If **axis** is set, **useAxis** is automatically set to **true**. If **useAxis** is set to **true** and **axis** is not specified, the default axis is used to expand full connections. You cannot set **useAxis** to **false** and specify **axis** at the same time. The default value is **false**.<br>- **hasBias**: boolean value indicating whether to use the bias offset.<br>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: computed tensor.| 591| 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 int32_t array with a length of 1.<br>Output:<br>- **output**: sliced tensor.| 592| OH_NN_OPS_HSWISH | Calculates the activation value of the input **Hardswish**.<br>Input:<br>- An *n*-dimensional input tensor.<br>Output:<br>- *n*-dimensional **Hardswish** activation value. The data type is the same as that of **shape** and **input**.| 593| 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**: a real number, Boolean value, or tensor whose data type is real number or **OH_NN_BOOL**.<br>- **input2**: a real number or a Boolean value if **input1** is a tensor, or a tensor whose data type is real number or **OH_NN_BOOL** if **input1** is not a tensor.<br>Output:<br>- **output**: a tensor of the **OH_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.| 594| 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>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: inner product obtained after calculation. In case of **type!=OH_NN_UNKNOWN**, the output data type is determined by **type**. In case of **type==OH_NN_UNKNOWN**, the output data type depends on the data type converted during computing of **inputX** and **inputY**.| 595| 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 must not be both **OH_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 whose data type is real number or **OH_NN_BOOL**.<br>- **input2**: *n*-dimensional input tensor whose data type is real number or **OH_NN_BOOL**.<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.| 596| 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**: maximum kernel size. It is an int array with a length of 2 in the format of [kernelHeight, kernelWeight], 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 with a length of 2 in the format of [strideHeight, strideWeight], 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>- **roundMode**: boundary processing mode, which is an optional value of the int type. When the pooling core cannot completely cover the input feature map, the output feature map is rounded down. The value **0** indicates rounding down, and the value **1** indicates rounding up.<br>- **global**: bool value indicating whether to perform the average pooling operation on the entire input tensor.<br>- **activationType**: integer constant contained in **OH_NN_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**: maximum kernel size. It is an int array with a length of 2 in the format of [kernelHeight, kernelWeight], 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 with a length of 2 in the format of [strideHeight, strideWeight], 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 with a length of 4 in the format of [top, bottom, left, right], and the nearest neighbor values are used for padding.<br>- **roundMode**: boundary processing mode, which is an optional value of the int type. When the pooling core cannot completely cover the input feature map, the output feature map is rounded down. The value **0** indicates rounding down, and the value **1** indicates rounding up.<br>- **global**: bool value indicating whether to perform the average pooling operation on the entire input tensor.<br>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: tensor obtained after maximum pooling is applied to the input.| 597| OH_NN_OPS_MUL | Multiplies elements in the same locations of **input1** and **input2** to obtain the output. If the shapes of **input1** and **input2** are different, **input1** and **input2** can be extended to the same shape through broadcast for multiplication.<br>Input:<br>- **input1**: *n*-dimensional tensor.<br>- **input2**: *n*-dimensional tensor.<br>Parameters:<br>- **activationType**: integer constant contained in **OH_NN_FuseType**. The specified activation function is called before output.<br>Output:<br>- **output**: product of each element of **input1** and **input2**.| 598| OH_NN_OPS_ONE_HOT | Generates a one-hot tensor based on the locations specified by **indices**. The locations specified by **indices** are determined by **onValue**, and other locations are determined by **offValue**.<br>Input:<br>- **indices**: *n*-dimensional tensor. Each element in **indices** determines the location of **onValue** 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>- **onValue**: a scalar that specifies a valid value in the one-hot vector.<br>- **offValue**: 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**.| 599| 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>- **constantValues**: value to be added to the pad operation. The value is a constant with the same data type as **inputX**.<br>- **paddingMode**: padding mode. The value is of the **OH_NN_INT32** type. The value **0** indicates that constant 0 is used for padding. The value **1** indicates mirror padding without the symmetry axis. The value **2** indicates mirror padding with the symmetry axis. The value **3** indicates the reserved padding mode.<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].| 600| 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 must not be both **OH_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**: a real number, Boolean value, or tensor whose data type is real number or **OH_NN_BOOL**.<br>- **y**: a real number, Boolean value, or tensor whose data type is real number or **OH_NN_BOOL**.<br>Parameters:<br>- **scale**: an **OH_NN_FLOAT32** scalar indicating the scaling and fusion factor.<br>- **shift**, an **OH_NN_FLOAT32** scalar indicating the offset of scaling blending.<br>Output:<br>- **output**: tensor, whose shape is determined by the shape of **input** and **y** after broadcasting.| 601| 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 **OH_NN_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**.| 602| 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.| 603| 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**.| 604| 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>Parameters:<br>- **axes**: axis of a slice.<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.| 605| 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**.| 606| 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 blockShape[0] and blockShape[1].| 607| 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 int.<br>- **sizeSplits**: size of each tensor split from the input. The value is a 1D tensor of the **int** type. If **sizeSplits** 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 **sizeSplits** 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**.| 608| 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**.| 609| 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 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: subtractor, which is a tensor of the OH_NN_FLOAT16, OH_NN_FLOAT32, OH_NN_INT32, or OH_NN_BOOL type.<br>- input2: subtractor, which is a tensor of the OH_NN_FLOAT16, OH_NN_FLOAT32, OH_NN_INT32, or OH_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.| 610| 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 with a length of 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.| 611| 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.| 612| 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]** location 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 with a length of 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.| 613| 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 **OH_NN_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.| 614| 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.| 615| 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>Parameters:<br>- **dims**: 1D tensor, which specifies the index of the dimension to be copied.<br>Output:<br>- **output**, *m*-dimensional tensor. **TensorType** is the same as **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.| 616| OH_NN_OPS_TRANSPOSE | Transposes data of **input** based on **permutation**.<br>Input:<br>- **input**: *n*-dimensional tensor to be transposed.<br>- **permutation**: 1D tensor whose length is the same as the number of dimensions of **input**.<br>Output:<br>- **output**: *n*-dimensional tensor. **TensorType** of **output** is the same as that of **input**, and the output shape is determined by the shape and **permutation** of **input**.| 617| 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>- **reduceToEnd**: a boolean value indicating whether to perform the reduce operation until the last axis.<br>- **coeff**: an OH_NN_FLOAT32 scalar indicating the output scaling factor.<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.| 618| 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**: an int32 integer indicating the coordinate transformation method used by the Resize operation. The value 0 indicates **ASYMMETRIC**. The value **1** indicates **ALIGN_CORNERS**. The value **2** indicates **HALF_PIXEL**.<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**. | 619| OH_NN_OPS_RSQRT | Calculates the reciprocal of the square root of an input 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**. | 620| OH_NN_OPS_RESHAPE | Reshapes an input 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**.| 621| 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 of **input** 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 **input**, the **weight** length must be **1**.<br>Output:<br>- **output**: PReLU activation value of **input**, with the same shape and data type as **input**.| 622| 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 Relu tensor, with the same data type and shape as the input tensor.| 623| 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.| 624| 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**: an **OH_NN_INT32** scalar that specifies the axis from which normalization starts. The value range is [1, rank(input)).<br>- **epsilon**: an **OH_NN_FLOAT32** scalar that represents a tiny amount in the normalization formula. The common value is **1e-5**.<br>- **beginParamsAxis**: the start axis of the input (gamma, beta) to be normalized.<br>Output:<br>- **output**: *n*-dimensional tensor, with the same data type and shape as the input tensor.| 625| 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. If its value is **true**, the number of output dimensions is the same as that of the input. If its value is **false**, the number of output dimensions is reduced.<br>- **reduceToEnd**: a boolean value indicating whether to perform the reduce operation until the last axis.<br>- **coeff**: an **OH_NN_FLOAT32** scalar indicating the output scaling factor.<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.| 626| OH_NN_OPS_REDUCE_ALL | Calculates the logical AND of the specified dimension. If **keepDims** is **false**, the number of input dimensions is reduced. If **keepDims** is **true**, the number of input 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>- **reduceToEnd**: a boolean value indicating whether to perform the reduce operation until the last axis.<br>- **coeff**: an **OH_NN_FLOAT32** scalar indicating the output scaling factor.<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.| 627| OH_NN_OPS_QUANT_DTYPE_CAST | Converts the data type.<br>Input:<br>- **input**: *n*-dimensional tensor. For conversion between the quantization type and floating-point type, the input tensor must contain quantization parameters.<br>Parameters:<br>- **srcT**: data type of the input.<br>- **dstT**: data type of the output.<br>- **axis**: the dimension for extracting quantization parameters. If the size of the input tensor quantization parameter is **1**, the operator function is used for layer quantization conversion and this parameter does not take effect. If the size of the input tensor quantization parameter is greater than **1**, the operator function is used for channel quantization conversion and this parameter takes effect.<br>Output:<br>- **output**: *n*-dimensional tensor. The data type is determined by **dstT**. The output shape is the same as the input shape.| 628| 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>- **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>- **axis**: an **OH_NN_INT32** scalar that specifies the dimension to be sorted. The default value is **-1**, pointing to the last dimension.<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.| 629| 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>- **keepDims**: a boolean value indicatin gwhether to maintain the input tensor dimension.<br>- **topK**: number of maximum values to be returned. The default value is **1**. If **topK** is equal to **1**, the index of the max value in the input tensor is returned. If **topK** is greater than **1**, the indices of the first top K max values in the input tensor is returned. If multiple values in the input tensor are the max value, any of them is returned.<br>- **outMaxValue**: whether to output the maximum value. The default value is **false**.<br>Output:<br>- **output**: index of the maximum input tensor on the axis. The value is a tensor.| 630| 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.| 631| 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>Parameters:<br>- **approximate**: a boolean value that represents the option of the approximation function. If the value is **true**, the approximation function is a Tanh function. If the value is **false**, the approximation function is an Erf function.<br>Output:<br>- **output**: *n*-dimensional Relu tensor, with the same data type and shape as the input tensor.| 632| OH_NN_OPS_UNSTACK<sup>12+</sup> | Factorizes the input tensor based on the axis.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **axis**: an **OH_NN_INT32** scalar that specifies the axis for matrix factorization. The value range is [-n, n).<br>Output:<br>- **output**: a collection of multiple tensors factorized from the input. Each tensor has the same shape.| 633| OH_NN_OPS_ABS<sup>12+</sup> | Calculates the absolute value of the input data.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 634| OH_NN_OPS_ERF<sup>12+</sup> | Gaussian error function, which calculates the error of the input data by element.<br>Input:<br>- input: *n*-dimensional tensor. The number of dimensions must be less than **8**. The data type can only be **OH_NN_FLOAT32** or **OH_NN_FLOAT16**.<br>Output:<br>- **output**: *n*-dimensional tensor. The data type and shape are the same as those of the input.| 635| OH_NN_OPS_EXP<sup>12+</sup> | Calculates the input exponent by element. The calculation formula is output = base ^ (shift + scale \* input), in which the base number is **base>0**. The default value is **-1**, indicating that the base number is a natural constant **e**.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **base**: base of the exponential function. The default value is **-1**, indicating that the base is a natural constant **e**.<br>- **scale**: scaling factor of the exponent. The default value is **1**.<br>- **shift**: offset of the exponent. The default value is **0**.<br>Output:<br>- **output**: *n*-dimensional tensor, which is output result of the exponential function.| 636| OH_NN_OPS_LESS<sup>12+</sup> | Calculates the result of input1[i]<input2[i] by element for **input1** and **input2**, 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 OH_NN_BOOL.<br>- **input2**: a real number or a Boolean value if **input1** is a tensor, or a tensor whose data type is real number or **OH_NN_BOOL** if **input1** is not a tensor.<br>Output:<br>- **output**: a tensor of the **OH_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.| 637| OH_NN_OPS_SELECT<sup>12+</sup> | Determines whether the output is selected from input 1 or input 2 by element based on the input conditions. If the condition is **true**, the output is selected from input 1. If the condition is **false**, the output is selected from input 2. When the condition is a tensor, the shapes of the three inputs must be the same.<br>Input:<br>- **condition**: decision condition, which can be a real number or an n-dimensional tensor.<br>- **input1**: input 1 to be selected.<br>- **input2**: input 2 to be selected.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 638| OH_NN_OPS_SQUARE<sup>12+</sup> | Calculates the square of the input by element.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 639| OH_NN_OPS_FLATTEN<sup>12+</sup> | Specifies the axis to flatten the input tensor.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **axis**: axis along which the input is flattened. For a tensor whose input dimension is (d_0, d_1, ..., d_n), the output dimension should be (d_0\*\d_1\*...\*d_(axis-1), d_axis\*d_(axis+1)\*...\*d_n).<br>Output:<br>- **output**: 2D tensor after being flattened.| 640| OH_NN_OPS_DEPTH_TO_SPACE<sup>12+</sup> | Rearranges the depth data blocks of the input tensor into spatial dimensions.<br>Input:<br>- **input**: 4-dimensional tensor in NHWC or NCHW format. Currently, only NHWC is supported. The shape is [batchSize, height, width, channels].<br>Parameters:<br>- **blockSize**: size of the block to be converted. The value must be an integer.<br>- **mode**: conversion mode. The value **0** indicates DCR, and the value **1** indicates CRD. DCR indicates depth-column-row sequential rearrangement, and CRD indicates column-row-depth sequential rearrangement.<br>Output:<br>- **output**: 4-dimensional tensor. The format is the same as that of the input tensor, and the shape is [batchSize, height \* blockSize, weight \* blockSize, channel / blockSize^2].| 641| OH_NN_OPS_RANGE<sup>12+</sup> | Generates a sequence tensor. The generation range is [start, limit), and the step is delta.<br>Input:<br>- **input**: n-dimensional tensor. The output data type is the same as that of the input.<br>Parameters:<br>- **start**: start number of a generated sequence.<br>- **limit**: end number of the generated sequence, excluding this value.<br>- **delta**: step. Partial data is skipped from the generated sequence range by step.<br>Output:<br>- **output**: 1-dimensional sequence tensor.| 642| OH_NN_OPS_INSTANCE_NORM<sup>12+</sup> | Performs standardization processing on each input channel, so that the average value of each input channel is 0 and the variance is 1.<br>Input:<br>- **input**: 4-dimensional tensor.<br>- **scale**: 1D tensor. The scaling coefficient and size are the same as the number of input channels.<br>- **bias**: 1D tensor that represents the bias constant. The size is the same as the number of input channels.<br>Parameters:<br>- **epsilon**: a small value added to the denominator to ensure calculation stability.<br>Output:<br>- **output**: 4-dimensional tensor with the same shape as the input.| 643| OH_NN_OPS_CONSTANT_OF_SHAPE<sup>12+</sup> | Generates a tensor with the specified shape.<br>Input:<br>- **input**: 1D tensor that represents the shape of the target tensor.<br>Parameters:<br>- **dataType**: data type of the target tensor.<br>- **value**: value of the target tensor, which is a single-element array whose data type is **OH_NN_FLOAT32**.<br>Output:<br>- **output**: target tensor.| 644| OH_NN_OPS_BROADCAST_TO<sup>12+</sup> | Broadcasts a tensor to an adapted shape.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **shape**: 1D tensor that represents the expected output shape.<br>Output:<br>- **output**: broadcast tensor.| 645| OH_NN_OPS_EQUAL<sup>12+</sup> | Calculates the result of input1[i] = input2[i] by element for **input1** and **input2**, 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 OH_NN_BOOL.<br>- **input2**: a real number or a Boolean value if **input1** is a tensor, or a tensor whose data type is real number or **OH_NN_BOOL** if **input1** is not a tensor.<br>Output:<br>- **output**: a tensor of the **OH_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.| 646| OH_NN_OPS_GREATER<sup>12+</sup> | Calculates the result of input1[i]>input2[i] by element for **input1** and **input2**, 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 OH_NN_BOOL.<br>- **input2**: a real number or a Boolean value if **input1** is a tensor, or a tensor whose data type is real number or **OH_NN_BOOL** if **input1** is not a tensor.<br>Output:<br>- **output**: a tensor of the **OH_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.| 647| OH_NN_OPS_NOT_EQUAL<sup>12+</sup> | Calculates the result of input1[i] != input2[i] by element for **input1** and **input2**, 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 OH_NN_BOOL.<br>- **input2**: a real number or a Boolean value if **input1** is a tensor, or a tensor whose data type is real number or **OH_NN_BOOL** if **input1** is not a tensor.<br>Output:<br>- **output**: a tensor of the **OH_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.| 648| OH_NN_OPS_GREATER_EQUAL<sup>12+</sup> | Calculates the result of input1[i]>=input2[i] by element for **input1** and **input2**, 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 OH_NN_BOOL.<br>- **input2**: a real number or a Boolean value if **input1** is a tensor, or a tensor whose data type is real number or **OH_NN_BOOL** if **input1** is not a tensor.<br>Output:<br>- **output**: a tensor of the **OH_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.| 649| OH_NN_OPS_LEAKY_RELU<sup>12+</sup> | Calculates the activation value of the input **leakyRelu**.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Parameters:<br>- **negativeSlope**: slope when the input is less than **0**, which controls the output size. The data type is **OH_NN_FLOAT32**.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 650| OH_NN_OPS_LSTM<sup>12+</sup> | Performs long-term and short-term memory (LSTM) network calculations on the input.<br>Input:<br>- **input**: 3D tensor in the shape of [seqLen, batchSize, inputSize].<br>- **wIh**: weight from the input to the hidden layer. The shape is [numDirections\*numLayers, 4\*hiddenSize, inputSize].<br>- **wHh**: weight from the hidden layer to the hidden layer. The shape is [numDirections\*numLayers, 4\*hiddenSize, inputSize].<br>- **bias**: bias from the input and hidden layers to the hidden layer. The shape is [numDirections\*numLayers, 8\*hiddenSize].<br>- **hx**: initial hidden status of the unit gate. The shape is [numDirections\*numLayers, batchSize, hiddenSize].<br>- **cx**: initial cell status of the unit gate. The shape is [numDirections\*numLayers, batchSize, hiddenSize].<br>Parameters:<br>- **bidirectional**: boolean value indicating whether the LSTM is bidirectional.<br>- **hasBias**: boolean value indicating whether the unit gate has a bias.<br>- **inputSize**: input size.<br>- **hiddenSize**: status size of the hidden layer.<br>- **numLayers**: number of LSTM network layers.<br>- **numDirections**: number of directions of the LSTM network.<br>- **dropout**: drop probability. The probability that the input of each layer except the first layer is discarded is [0.0, 1.0].<br>- **zoneoutCell**: probability that the control unit retains the previous state. The default value is **0**.<br>- **zoneoutHidden**: probability that the hidden layer retains the previous state. The default value is **0**.<br>- **projSize**: projection size. If the value is greater than **0**, the LSTM projection is used. The default value is **0**.<br>Output:<br>- **output**: 3D tensor in the shape of [seqLen, batchSize, numDirections\*realHiddenSize]. The channels of all output tensors are stitched for output.<br>- **hy**: output tensor of the last hidden layer. The shape is [numDirections\*numLayers, batchSize, realHiddenSize].<br>- **cy**: output tensor of the unit gate at the last layer. The shape is [numDirections\*numLayers, batchSize, HiddenSize].| 651| OH_NN_OPS_CLIP<sup>12+</sup> | Crops the value of the input tensor to a value between the specified minimum and maximum values.<br>Input:<br>- **input**: *n*-dimensional tensor or tensor list or tuple. Tensors of any dimensions are supported.<br>Parameters:<br>- **min**: minimum cropping value.<br>- **max**: maximum cropping value.<br>Output:<br>- **output**: tensor after value cropping. The shape and data type are the same as those of the input.| 652| OH_NN_OPS_ALL<sup>12+</sup> | Checks whether all elements of the specified dimension in the input are non-zero values. If all elements are non-zero values, **true** is returned for the corresponding dimension. Otherwise, **false** is returned for the corresponding dimension.<br>Input:<br>- **input**: *n*-dimensional tensor in the shape of (N, \*), where \* indicates any number of additional dimensions.<br>- **axis**: 1D tensor that represents the dimension to be calculated.<br>Parameters:<br>- **keepDims**: whether to retain the dimension of the output tensor.<br>Output:<br>- **output**: 1-dimensional or *n*-dimensional tensor whose data type is **OH_NN_BOOL**. It is the tensor output after non-zero judgment.| 653| OH_NN_OPS_ASSERT<sup>12+</sup> | Asserts whether the given condition is true. If the result of the given condition is false, the tensor list in **data** is printed, where **summarize** is used to determine the number of tensor entries to be printed.<br>Input:<br>- **condition**: condition to evaluate.<br>- **data**: tensor to be printed when the condition is false.<br>Parameters:<br>- **summarize**: number of entries in each tensor to be printed. <br>Output:<br>- **output**: output result. If the condition is not true, **Error** is returned.| 654| OH_NN_OPS_COS<sup>12+</sup> | Calculates the cosine value of the input data by element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is **OH_NN_FLOAT64**, **OH_NN_FLOAT32**, or **OH_NN_FLOAT16**.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 655| OH_NN_OPS_LOG<sup>12+</sup> | Calculates the natural logarithm of the input by element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is **OH_NN_FLOAT64**, **OH_NN_FLOAT32**, or **OH_NN_FLOAT16**. The value must be greater than **0**.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 656| OH_NN_OPS_LOGICAL_AND<sup>12+</sup> | Calculates the logical AND operation of two input tensors by element.<br>Input:<br>- **input1**: *n*-dimensional tensor whose data type is **OH_NN_BOOL**.<br>- **input2**: *n*-dimensional tensor whose data type is **OH_NN_BOOL** and the shape is the same as that of **input1**.<br>Output:<br>- **output**: *n*-dimensional tensor whose data type is **OH_NN_BOOL**. It is the result of the logical AND operation.| 657| OH_NN_OPS_LOGICAL_NOT<sup>12+</sup> | Calculates the logical NOT operation of two input tensors by element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is **OH_NN_BOOL**.<br>Output:<br>- **output**: *n*-dimensional tensor whose data type is **OH_NN_BOOL**. It is the result of the logical NOT operation.| 658| OH_NN_OPS_MOD<sup>12+</sup> | Performs the mod operation on the input tensor. **input1** and **input2** must be converted into the same data type based on the data type conversion rules. The input must contain two tensors or contain one tensor and one scalar. If the input contains two tensors, their data types must not be both **OH_NN_BOOL** and they can be broadcast to the same shape. If the input contains one tensor and one scalar, the scalar input can only be a constant.<br>Input:<br>- **input1**: scalar or tensor for the mod operation. The data type is numeric, **OH_NN_BOOL**, or *n*-dimensional numeric tensor.<br>- **input2**: cofactor for the mod operation. When the first input is an *n*-dimensional tensor, the second input can be a numeric or **OH_NN_BOOL** value, or an *n*-dimensional numeric tensor. If the first input is a numeric or **OH_NN_BOOL** value, the second input must be an *n*-dimensional numeric tensor.<br>Output:<br>- **output**: *n*-dimensional tensor. The shape is the same as that of the broadcast input. The data type is the data type with higher precision in the two inputs.| 659| OH_NN_OPS_NEG<sup>12+</sup> | Calculates the opposite number of the input by element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is numeric.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 660| OH_NN_OPS_RECIPROCAL<sup>12+</sup> | Calculates the reciprocal of the input exponent by element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is **OH_NN_FLOAT64**, **OH_NN_FLOAT32**, or **OH_NN_FLOAT16**.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 661| OH_NN_OPS_SIN<sup>12+</sup> | Calculates the sine value of the input by element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is **OH_NN_FLOAT64**, **OH_NN_FLOAT32**, or **OH_NN_FLOAT16**.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 662| OH_NN_OPS_WHERE<sup>12+</sup> | Selects proper elements from **input1** and **input2** based on the specified condition.<br>Input:<br>- **condition**: *n*-dimensional tensor whose data type is **OH_NN_BOOL**. If the element is **true**, the element corresponding to **input1** is selected. If the element is **false**, the element corresponding to **input2** is selected.<br>- **input1**: *n*-dimensional tensor to be selected.<br>- **input2**: *n*-dimensional tensor to be selected.<br>Output:<br>- **output**: output result.| 663| OH_NN_OPS_SPARSE_TO_DENSE<sup>12+</sup> | Converts a sparse tensor to a dense tensor.<br>Input:<br>- **indices**: 2D tensor indicating the location of an element in the sparse tensor.<br>- **values**: 1D tensor indicating the value mapping to the location in **indices**.<br>- **sparseShape**: shape of a tensor, which consists of two positive integers. The shape is (N, C).<br>Output:<br>- **output**: tensor after conversion whose data type is the same as that of **value** and the shape is specified by **sparseShape**.| 664| OH_NN_OPS_LOGICAL_OR<sup>12+</sup> | Calculates the logical OR operation of two input tensors by element.<br>Input:<br>- **input1**: *n*-dimensional tensor whose data type is **OH_NN_BOOL**.<br>- **input2**: *n*-dimensional tensor whose data type is **OH_NN_BOOL** and the shape is the same as that of **input1**.<br>Output:<br>- **output**: *n*-dimensional tensor whose data type is **OH_NN_BOOL**. It is the result of the logical OR operation.| 665| OH_NN_OPS_CEIL<sup>12+</sup> | Rounds up each input element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is **OH_NN_FLOAT64**, **OH_NN_FLOAT32**, or **OH_NN_FLOAT16**.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 666| OH_NN_OPS_CROP<sup>12+</sup> | Crops the input tensor with the specified shape based on the specified axis and offset.<br>Input:<br>- **input**: *n*-dimensional tensor to be cropped.<br>- **shape**: 1D tensor indicating the size of the tensor to be cropped.<br>Parameters:<br>- **axis**: start axis of the cropped area. The value range is [0,1, ...,r-1], where **r** is the rank of the input tensor, and a negative number indicates the reverse value.<br>- **offset**: start offset of the cropped area.<br>Output:<br>- **output**: cropped tensor.| 667| OH_NN_OPS_DETECTION_POST_PROCESS<sup>12+</sup> | Performs post-processing on the output of the object detection model. Specific operations include decoding the bounding box, category probability, and score output by the model, performing Non-Max suppression (NMS) to remove the overlapping bounding box, and outputting the detection result.<br>Input:<br>- **bbox**: bounding box.<br>- **scores**: category score probability.<br>- **anchors**: anchors used to generate coordinates and size of the candidate box of a detection box. In an object detection task, candidate boxes are a series of rectangular boxes preset in an image according to specific rules. These rectangular boxes usually have different sizes and aspect ratios, and are used to preliminarily predict and screen a target in the image.<br>Parameters:<br>- **inputSize**: size of the input tensor.<br>- **scale**: scaling factor used to convert the output image from the normalized form to the coordinates of the original image.<br>- **nmsIoUThreshold**: Non-Max suppression threshold, which is used to remove duplicate detection boxes.<br>- **nmsScoreThreshold**: confidence threshold, which is used to filter low-confidence detection boxes.<br>- **maxDetections**: maximum number of detection boxes that can be output for each image.<br>- **detectionsPerClass**: maximum number of detections for each category.<br>- **maxClassesPerDetection**: maximum number of detection categories in each detection box.<br>- **numClasses**: total number of detection categories.<br>- **useRegularNms**: boolean value indicating whether to use the IoU threshold-based Non-Max suppression algorithm. When the value is **true**, the IoU threshold-based Non-Max suppression algorithm is used to filter overlapped target boxes and retain the target box with the highest score. If this parameter is set to **false**, the IoU threshold-based Non-Max suppression algorithm is not applicable. The target boxes are sorted based on the score and the target box with the highest score is retained.<br>- **outQuantized**: boolean value indicating whether the output needs to be quantized.<br>Output:<br>- **bboxes**: 3D tensor whose internal array indicates the coordinates of the object detection box.<br>- **classes**: 2D tensor whose internal value indicates the class index corresponding to each detection box.<br>- **confidences**: 2D tensor. The internal value indicates the confidence of the detected object.<br>- **numDetections**: number of detection results.| 668| OH_NN_OPS_FLOOR<sup>12+</sup> | Rounds down each input element.<br>Input:<br>- **input**: *n*-dimensional tensor whose data type is **OH_NN_FLOAT64**, **OH_NN_FLOAT32**, or **OH_NN_FLOAT16**.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 669| OH_NN_OPS_L2_NORMALIZE<sup>12+</sup> | Performs L2 regularization on the input tensor based on the specified axis.<br>Input:<br>- **input**: *n*-dimensional tensor for L2 regularization.<br>Parameters:<br>- **axis**: specified dimension for regularization. The value **-1** indicates the last dimension.<br>- **epsilon**: a small value added to the denominator to ensure calculation stability. The default value is **1e-6**.<br>- **activationType**: activation function type.<br>Output:<br>- **output**: output tensor whose data type and shape are the same as those of the input.| 670| OH_NN_OPS_LOG_SOFTMAX<sup>12+</sup> | Performs exponential operations on each element of the input tensor and normalizes the operation result to obtain a probability distribution vector.<br>Input:<br>- **input**: 2D tensor whose shape is [batchSize, numClasses] and data type is **OH_NN_FLOAT64**, **OH_NN_FLOAT32**, or **OH_NN_FLOAT16**.<br>Parameters:<br>- **axis**: dimension for calculation.<br>Output:<br>- **output**: 2D tensor that represents the probability vector after calculation.| 671| OH_NN_OPS_LRN<sup>12+</sup> | Normalizes the local response of the input.<br>Input:<br>- **input**: 4D tensor to be normalized.<br>Parameters:<br>- **depthRadius**: scalar type indicating the half width of the normalized window.<br>- **bias**: bias used to avoid division by zero. The default value is **1**.<br>- **alpha**: ratio coefficient. The default value is **1**.<br>- **beta**: exponential variable. The default value is **0.5**.<br>- **normRegion**: normalized region. The default value is **0**, indicating that the normalized region is **ACROSS_CHANNELS**. Currently, only this mode is supported.<br>Output:<br>- **output**: normalized output tensor whose shape and data type are the same as those of the input.| 672| OH_NN_OPS_MINIMUM<sup>12+</sup> | Calculates the minimum value of two tensors by element. The input must conain two tensors or contain one tensor and one scalar. If the input contains two tensors, their data types must not be both boolean and they can be broadcast to the same shape. If the input contains one tensor and one scalar, the scalar input can only be a constant.<br>Input:<br>- **input1**: *n*-dimensional tensor whose data type can be numeric or boolean.<br>- **input2**: *n*-dimensional tensor whose data type can be numeric or boolean.<br>Output:<br>- **output**: comparison result tensor whose shape and data type are the same as those of the input.| 673| OH_NN_OPS_RANK<sup>12+</sup> | Calculates the rank of a tensor.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: 0D tensor indicating the input rank. The data type is int32.| 674| OH_NN_OPS_REDUCE_MAX<sup>12+</sup> | Calculates the maximum value of the input tensors in the specified dimension. If **keepDims** is **false**, the dimension of the output tensor is reduced. If **keepDims** is **true**, the dimension of the output tensor and the input tensor remain unchanged.<br>Input:<br>- **input**: *n*-dimensional tensor, where n<8.<br>- **axis**: dimension used to calculate the maximum value.<br>Parameters:<br>- **keepDims**: whether to retain the dimension. The value is a Boolean value.<br>- **reduceToEnd**: a boolean value indicating whether to perform the reduce operation until the last axis.<br>- **coeff**: an OH_NN_FLOAT32 scalar indicating the output scaling factor.<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.| 675| OH_NN_OPS_REDUCE_MIN<sup>12+</sup> | Calculates the minimum value of the input tensors in the specified dimension. If **keepDims** is **false**, the dimension of the output tensor is reduced. If **keepDims** is **true**, the dimension of the output tensor and the input tensor remain unchanged.<br>Input:<br>- **input**: *n*-dimensional tensor, where n<8.<br>- **axis**: dimension used to calculate the minimum value.<br>Parameters:<br>- **keepDims**: whether to retain the dimension. The value is a Boolean value.<br>- **reduceToEnd**: a boolean value indicating whether to perform the reduce operation until the last axis.<br>- **coeff**: an OH_NN_FLOAT32 scalar indicating the output scaling factor.<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.| 676| OH_NN_OPS_REDUCE_SUM<sup>12+</sup> | Calculates the sum of the input tensors in the specified dimension. If **keepDims** is **false**, the dimension of the output tensor is reduced. If **keepDims** is **true**, the dimension of the output tensor and the input tensor remain unchanged.<br>Input:<br>- **input**: *n*-dimensional tensor, where n<8.<br>- **axis**: dimension used to calculate the sum.<br>Parameters:<br>- **keepDims**: whether to retain the dimension. The value is a Boolean value.<br>- **reduceToEnd**: a boolean value indicating whether to perform the reduce operation until the last axis.<br>- **coeff**: an OH_NN_FLOAT32 scalar indicating the output scaling factor.<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.| 677| OH_NN_OPS_ROUND<sup>12+</sup> | Rounds off the input tensor to approximate the value.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- **output**: *n*-dimensional tensor whose shape and data type are the same as those of the input.| 678| OH_NN_OPS_SCATTER_ND<sup>12+</sup> | Distributes the updated value to a new tensor based on the specified index.<br>Input:<br>- **indices**: indices scattered in the new tensor. The data type is **OH_NN_INT64** or **OH_NN_INT32**. The index rank is at least 2, and the value of the last dimension of **indices** is less than the size of the input shape.<br>- **updates**: tensor to be updated.<br>- **shape**: shape of the output tensor. The data type is the same as that of **indices**.<br>Output:<br>- **output**: updated tensor. The data type is the same as that of **updates**, and the shape is the same as that of **shape**.| 679| OH_NN_OPS_SPACE_TO_DEPTH<sup>12+</sup> | Rearranges spatial dimension data blocks of the input tensor into depth dimensions.<br>Input:<br>- **input**: 4-dimensional tensor in NHWC or NCHW format. Currently, only NHWC is supported. The shape is [batchSize, height, width, channels].<br>Parameters:<br>- **blockSize**: size of the block to be converted. The value must be an integer.<br>Output:<br>- **output**: 4-dimensional tensor. The format is the same as that of the input tensor, and the shape is [batchSize, height / blockSize, weight / blockSize, channel \* blockSize^2].| 680| OH_NN_OPS_SWISH<sup>12+</sup> | Calculates Swish activation for the input tensor by element.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- *n*-dimensional tensor. The data type and shape are the same as those of the input.| 681| OH_NN_OPS_REDUCE_L2<sup>12+</sup> | Calculates the L2 norm of the input tensors in the specified dimension. If **keepDims** is **false**, the dimension of the output tensor is reduced. If **keepDims** is **true**, the dimension of the output tensor and the input tensor remain unchanged.<br>Input:<br>- **input**: *n*-dimensional tensor, where n<8.<br>- **axis**: axis used to calculate the dimension of the L2 norm.<br>Parameters:<br>- **keepDims**: whether to retain the dimension. The value is a Boolean value.<br>- **reduceToEnd**: a boolean value indicating whether to perform the reduce operation until the last axis.<br>- **coeff**: an OH_NN_FLOAT32 scalar indicating the output scaling factor.<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.| 682| OH_NN_OPS_HARD_SIGMOID<sup>12+</sup> | Calculates HardSigmoid activation for the input tensor by element.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>Output:<br>- *n*-dimensional tensor. The data type and shape are the same as those of the input.| 683| OH_NN_OPS_GATHER_ND<sup>12+</sup> | Obtains the element at the specified location of the input tensor based on the specified index.<br>Input:<br>- **input**: *n*-dimensional tensor.<br>- **indices**: *m*-dimensional tensor whose data type is **OH_NN_INT64** or **OH_NN_INT32**.<br>Output:<br>- *n*-dimensional tensor. The data type is the same as that of the input. The shape is the concatenation of the first dimension (m-1) of **indices** and the last dimension (size of the last dimension of n-indices) of input.| 684 685 686### OH_NN_PerformanceMode 687 688``` 689enum OH_NN_PerformanceMode 690``` 691 692**Description** 693 694Performance modes of the device. 695 696**Since**: 9 697 698| Value| Description| 699| -------- | -------- | 700| OH_NN_PERFORMANCE_NONE | No performance mode preference.| 701| OH_NN_PERFORMANCE_LOW | Low power consumption mode.| 702| OH_NN_PERFORMANCE_MEDIUM | Medium performance mode.| 703| OH_NN_PERFORMANCE_HIGH | High performance mode.| 704| OH_NN_PERFORMANCE_EXTREME | Ultimate performance mode.| 705 706 707### OH_NN_Priority 708 709``` 710enum OH_NN_Priority 711``` 712 713**Description** 714 715Priorities of a model inference task. 716 717**Since**: 9 718 719| Value| Description| 720| -------- | -------- | 721| OH_NN_PRIORITY_NONE | No priority preference.| 722| OH_NN_PRIORITY_LOW | Low priority.| 723| OH_NN_PRIORITY_MEDIUM | Medium priority.| 724| OH_NN_PRIORITY_HIGH | High priority.| 725 726 727### OH_NN_ReturnCode 728 729``` 730enum OH_NN_ReturnCode 731``` 732 733**Description** 734 735Error codes for NNRt. 736 737**Since**: 9 738 739| Value| Description| 740| -------- | -------- | 741| OH_NN_SUCCESS | The operation is successful.| 742| OH_NN_FAILED | Operation failed.| 743| OH_NN_INVALID_PARAMETER | Invalid parameter.| 744| OH_NN_MEMORY_ERROR | Memory-related error, for example, insufficient memory, memory data copy failure, or memory application failure.| 745| OH_NN_OPERATION_FORBIDDEN | Invalid operation.| 746| OH_NN_NULL_PTR | Null pointer.| 747| OH_NN_INVALID_FILE | Invalid file.| 748| OH_NN_UNAVALIDABLE_DEVICE | 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.| 749| OH_NN_INVALID_PATH | Invalid path.| 750| OH_NN_TIMEOUT<sup>11+</sup> | Execution timed out.| 751| OH_NN_UNSUPPORTED<sup>11+</sup> | Not supported.| 752| OH_NN_CONNECTION_EXCEPTION<sup>11+</sup> | Connection error.| 753| OH_NN_SAVE_CACHE_EXCEPTION<sup>11+</sup> | Failed to save the cache.| 754| OH_NN_DYNAMIC_SHAPE<sup>11+</sup> | Dynamic shape.| 755| OH_NN_UNAVAILABLE_DEVICE<sup>11+</sup> | Hardware error, for example, HDL service crash.| 756 757 758### OH_NN_TensorType 759 760``` 761enum OH_NN_TensorType 762``` 763 764**Description** 765 766Defines tensor types. 767 768Tensors 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](_o_h___n_n___tensor.md) instance to **OH_NN_CONV2D_PAD**. The settings of other operator parameters are similar. The enumerated values are named in the format OH_NN_{*Operator name*}_{*Attribute name*}. 769 770**Since**: 9 771 772| Value| Description| 773| -------- | -------- | 774| OH_NN_TENSOR | Used when the tensor is used as the input or output of a model (or operator).| 775| OH_NN_ADD_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the Add operator.| 776| OH_NN_AVG_POOL_KERNEL_SIZE | Used when the tensor is used as the **kernelSize** parameter of the AvgPool operator.| 777| OH_NN_AVG_POOL_STRIDE | Used when the tensor is used as the **stride** parameter of the AvgPool operator.| 778| OH_NN_AVG_POOL_PAD_MODE | Used when the tensor is used as the **AvgPool** parameter of the AvgPool operator. | 779| OH_NN_AVG_POOL_PAD | Used when the tensor is used as the **pad** parameter of the AvgPool operator.| 780| OH_NN_AVG_POOL_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the AvgPool operator. | 781| OH_NN_BATCH_NORM_EPSILON | Used when the tensor is used as the **eosilon** parameter of the BatchNorm operator.| 782| OH_NN_BATCH_TO_SPACE_ND_BLOCKSIZE | Used when the tensor is used as the **blockSize** parameter of the BatchToSpaceND operator.| 783| OH_NN_BATCH_TO_SPACE_ND_CROPS | Used when the tensor is used as the **crops** parameter of the BatchToSpaceND operator.| 784| OH_NN_CONCAT_AXIS | Used when the tensor is used as the **axis** parameter of the Concat operator.| 785| OH_NN_CONV2D_STRIDES | Used when the tensor is used as the **strides** parameter of the Conv2D operator.| 786| OH_NN_CONV2D_PAD | Used when the tensor is used as the **pad** parameter of the Conv2D operator.| 787| OH_NN_CONV2D_DILATION | Used when the tensor is used as the **dilation** parameter of the Conv2D operator.| 788| OH_NN_CONV2D_PAD_MODE | Used when the tensor is used as the **padMode** parameter of the Conv2D operator.| 789| OH_NN_CONV2D_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Conv2D operator.| 790| OH_NN_CONV2D_GROUP | Used when the tensor is used as the **group** parameter of the Conv2D operator. | 791| OH_NN_CONV2D_TRANSPOSE_STRIDES | Used when the tensor is used as the **strides** parameter of the Conv2DTranspose operator.| 792| OH_NN_CONV2D_TRANSPOSE_PAD | Used when the tensor is used as the **pad** parameter of the Conv2DTranspose operator.| 793| OH_NN_CONV2D_TRANSPOSE_DILATION | Used when the tensor is used as the **dilation** parameter of the Conv2DTranspose operator. | 794| OH_NN_CONV2D_TRANSPOSE_OUTPUT_PADDINGS | Used when the tensor is used as the **outputPaddings** parameter of the Conv2DTranspose operator. | 795| OH_NN_CONV2D_TRANSPOSE_PAD_MODE | Used when the tensor is used as the **padMode** parameter of the Conv2DTranspose operator. | 796| OH_NN_CONV2D_TRANSPOSE_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Conv2DTranspose operator. | 797| OH_NN_CONV2D_TRANSPOSE_GROUP | Used when the tensor is used as the **group** parameter of the Conv2DTranspose operator. | 798| OH_NN_DEPTHWISE_CONV2D_NATIVE_STRIDES | Used when the tensor is used as the **strides** parameter of the DepthwiseConv2dNative operator. | 799| OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD | Used when the tensor is used as the **pad** parameter of the DepthwiseConv2dNative operator. | 800| OH_NN_DEPTHWISE_CONV2D_NATIVE_DILATION | Used when the tensor is used as the **dilation** parameter of the DepthwiseConv2dNative operator. | 801| OH_NN_DEPTHWISE_CONV2D_NATIVE_PAD_MODE | Used when the tensor is used as the **padMode** parameter of the DepthwiseConv2dNative operator. | 802| OH_NN_DEPTHWISE_CONV2D_NATIVE_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the DepthwiseConv2dNative operator. | 803| OH_NN_DIV_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the Div operator. | 804| OH_NN_ELTWISE_MODE | Used when the tensor is used as the **mode** parameter of the Eltwise operator. | 805| OH_NN_FULL_CONNECTION_AXIS | Used when the tensor is used as the **axis** parameter of the FullConnection operator. | 806| OH_NN_FULL_CONNECTION_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the FullConnection operator. | 807| OH_NN_MATMUL_TRANSPOSE_A | Used when the tensor is used as the **transposeA** parameter of the Matmul operator. | 808| OH_NN_MATMUL_TRANSPOSE_B | Used when the tensor is used as the **transposeB** parameter of the Matmul operator. | 809| OH_NN_MATMUL_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Matmul operator. | 810| OH_NN_MAX_POOL_KERNEL_SIZE | Used when the tensor is used as the **kernelSize** parameter of the MaxPool operator. | 811| OH_NN_MAX_POOL_STRIDE | Used when the tensor is used as the **stride** parameter of the MaxPool operator. | 812| OH_NN_MAX_POOL_PAD_MODE | Used when the tensor is used as the **padMode** parameter of the MaxPool operator. | 813| OH_NN_MAX_POOL_PAD | Used when the tensor is used as the **pad** parameter of the MaxPool operator. | 814| OH_NN_MAX_POOL_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the MaxPool operator. | 815| OH_NN_MUL_ACTIVATION_TYPE | Used when the tensor is used as the **activationType** parameter of the Mul operator. | 816| OH_NN_ONE_HOT_AXIS | Used when the tensor is used as the **axis** parameter of the OneHot operator. | 817| OH_NN_PAD_CONSTANT_VALUE | Used when the tensor is used as the **constantValue** parameter of the Pad operator. | 818| OH_NN_SCALE_ACTIVATIONTYPE | Used when the tensor is used as the **activationType** parameter of the Scale operator. | 819| OH_NN_SCALE_AXIS | Used when the tensor is used as the **axis** parameter of the Scale operator. | 820| OH_NN_SOFTMAX_AXIS | Used when the tensor is used as the **axis** parameter of the Softmax operator. | 821| OH_NN_SPACE_TO_BATCH_ND_BLOCK_SHAPE | Used when the tensor is used as the **BlockShape** parameter of the SpaceToBatchND operator. | 822| OH_NN_SPACE_TO_BATCH_ND_PADDINGS | Used when the tensor is used as the **Paddings** parameter of the SpaceToBatchND operator. | 823| OH_NN_SPLIT_AXIS | Used when the tensor is used as the **Axis** parameter of the Split operator. | 824| OH_NN_SPLIT_OUTPUT_NUM | Used when the tensor is used as the **OutputNum** parameter of the Split operator. | 825| OH_NN_SPLIT_SIZE_SPLITS | Used when the tensor is used as the **SizeSplits** parameter of the Split operator. | 826| OH_NN_SQUEEZE_AXIS | Used when the tensor is used as the **Axis** parameter of the Squeeze operator. | 827| OH_NN_STACK_AXIS | Used when the tensor is used as the **Axis** parameter of the Stack operator. | 828| OH_NN_STRIDED_SLICE_BEGIN_MASK | Used when the tensor is used as the **BeginMask** parameter of the StridedSlice operator. | 829| OH_NN_STRIDED_SLICE_END_MASK | Used when the tensor is used as the **EndMask** parameter of the StridedSlice operator. | 830| OH_NN_STRIDED_SLICE_ELLIPSIS_MASK | Used when the tensor is used as the **EllipsisMask** parameter of the StridedSlice operator. | 831| OH_NN_STRIDED_SLICE_NEW_AXIS_MASK | Used when the tensor is used as the **NewAxisMask** parameter of the StridedSlice operator. | 832| OH_NN_STRIDED_SLICE_SHRINK_AXIS_MASK | Used when the tensor is used as the **ShrinkAxisMask** parameter of the StridedSlice operator. | 833| OH_NN_SUB_ACTIVATIONTYPE | Used when the tensor is used as the **ActivationType** parameter of the Sub operator. | 834| OH_NN_REDUCE_MEAN_KEEP_DIMS | Used when the tensor is used as the **keepDims** parameter of the ReduceMean operator. | 835| OH_NN_RESIZE_BILINEAR_NEW_HEIGHT | Used when the tensor is used as the **newHeight** parameter of the ResizeBilinear operator. | 836| OH_NN_RESIZE_BILINEAR_NEW_WIDTH | Used when the tensor is used as the **newWidth** parameter of the ResizeBilinear operator. | 837| OH_NN_RESIZE_BILINEAR_PRESERVE_ASPECT_RATIO | Used when the tensor is used as the **preserveAspectRatio** parameter of the ResizeBilinear operator. | 838| OH_NN_RESIZE_BILINEAR_COORDINATE_TRANSFORM_MODE | Used when the tensor is used as the **coordinateTransformMode** parameter of the ResizeBilinear operator. | 839| OH_NN_RESIZE_BILINEAR_EXCLUDE_OUTSIDE | Used when the tensor is used as the **excludeOutside** parameter of the ResizeBilinear operator. | 840| OH_NN_LAYER_NORM_BEGIN_NORM_AXIS | Used when the tensor is used as the **beginNormAxis** parameter of the LayerNorm operator. | 841| OH_NN_LAYER_NORM_EPSILON | Used when the tensor is used as the **epsilon** parameter of the LayerNorm operator. | 842| OH_NN_LAYER_NORM_BEGIN_PARAM_AXIS | Used when the tensor is used as the **beginParamsAxis** parameter of the LayerNorm operator. | 843| OH_NN_LAYER_NORM_ELEMENTWISE_AFFINE | Used when the tensor is used as the **elementwiseAffine** parameter of the LayerNorm operator. | 844| OH_NN_REDUCE_PROD_KEEP_DIMS | Used when the tensor is used as the **keepDims** parameter of the ReduceProd operator. | 845| OH_NN_REDUCE_ALL_KEEP_DIMS | Used when the tensor is used as the **keepDims** parameter of the ArgMax operator. | 846| OH_NN_QUANT_DTYPE_CAST_SRC_T | Used when the tensor is used as the **srcT** parameter of the QuantDTypeCast operator. | 847| OH_NN_QUANT_DTYPE_CAST_DST_T | Used when the tensor is used as the **dstT** parameter of the QuantDTypeCast operator. | 848| OH_NN_TOP_K_SORTED | Used when the tensor is used as the **Sorted** parameter of the Topk operator. | 849| OH_NN_ARG_MAX_AXIS | Used when the tensor is used as the **axis** parameter of the ArgMax operator. | 850| OH_NN_ARG_MAX_KEEPDIMS | Used when the tensor is used as the **keepDims** parameter of the ArgMax operator. | 851| OH_NN_UNSQUEEZE_AXIS | Used when the tensor is used as the **Axis** parameter of the Unsqueeze operator. | 852| OH_NN_UNSTACK_AXIS<sup>12+</sup> | Used when the tensor is used as the **axis** parameter of the Unstack operator. | 853| OH_NN_FLATTEN_AXIS<sup>12+</sup> | Used when the tensor is used as the **axis** parameter of the Flatten operator. | 854| OH_NN_DEPTH_TO_SPACE_BLOCK_SIZE<sup>12+</sup> | Used when the tensor is used as the **blockSize** parameter of the DepthToSpace operator.| 855| OH_NN_DEPTH_TO_SPACE_MODE<sup>12+</sup> | Used when the tensor is used as the **mode** parameter of the DepthToSpace operator. | 856| OH_NN_RANGE_START<sup>12+</sup> | Used when the tensor is used as the **start** parameter of the Range operator. | 857| OH_NN_RANGE_LIMIT<sup>12+</sup> | Used when the tensor is used as the **limit** parameter of the Range operator. | 858| OH_NN_RANGE_DELTA<sup>12+</sup> | Used when the tensor is used as the **delta** parameter of the Range operator. | 859| OH_NN_CONSTANT_OF_SHAPE_DATA_TYPE<sup>12+</sup> | Used when the tensor is used as the **dataType** parameter of the ConstantOfShape operator. | 860| OH_NN_CONSTANT_OF_SHAPE_VALUE<sup>12+</sup> | Used when the tensor is used as the **value** parameter of the ConstantOfShape operator. | 861| OH_NN_BROADCAST_TO_SHAPE<sup>12+</sup> | Used when the tensor is used as the **shape** parameter of the BroadcastTo operator. | 862| OH_NN_INSTANCE_NORM_EPSILON<sup>12+</sup> | Used when the tensor is used as the **epsilon** parameter of the InstanceNorm operator. | 863| OH_NN_EXP_BASE<sup>12+</sup> | Used when the tensor is used as the **base** parameter of the Exp operator. | 864| OH_NN_EXP_SCALE<sup>12+</sup> | Used when the tensor is used as the **scale** parameter of the Exp operator. | 865| OH_NN_EXP_SHIFT<sup>12+</sup> | Used when the tensor is used as the **shift** parameter of the Exp operator. | 866| OH_NN_LEAKY_RELU_NEGATIVE_SLOPE<sup>12+</sup> | Used when the tensor is used as the **negativeSlope** parameter of the LeakyRelu operator. | 867| OH_NN_LSTM_BIDIRECTIONAL<sup>12+</sup> | Used when the tensor is used as the **bidirectional** parameter of the LSTM operator. | 868| OH_NN_LSTM_HAS_BIAS<sup>12+</sup> | Used when the tensor is used as the **hasBias** parameter of the LSTM operator. | 869| OH_NN_LSTM_INPUT_SIZE<sup>12+</sup> | Used when the tensor is used as the **inputSize** parameter of the LSTM operator. | 870| OH_NN_LSTM_HIDDEN_SIZE<sup>12+</sup> | Used when the tensor is used as the **hiddenSize** parameter of the LSTM operator. | 871| OH_NN_LSTM_NUM_LAYERS<sup>12+</sup> | Used when the tensor is used as the **numLayers** parameter of the LSTM operator. | 872| OH_NN_LSTM_NUM_DIRECTIONS<sup>12+</sup> | Used when the tensor is used as the **numDirections** parameter of the LSTM operator. | 873| OH_NN_LSTM_DROPOUT<sup>12+</sup> | Used when the tensor is used as the **numDirections** parameter of the LSTM operator. | 874| OH_NN_LSTM_ZONEOUT_CELL<sup>12+</sup> | Used when the tensor is used as the **zoneoutCell** parameter of the LSTM operator. | 875| OH_NN_LSTM_ZONEOUT_HIDDEN<sup>12+</sup> | Used when the tensor is used as the **zoneoutHidden** parameter of the LSTM operator. | 876| OH_NN_LSTM_PROJ_SIZE<sup>12+</sup> | Used when the tensor is used as the **projSize** parameter of the LSTM operator. | 877| OH_NN_CLIP_MAX<sup>12+</sup> | Used when the tensor is used as the **max** parameter of the LSTM operator. | 878| OH_NN_CLIP_MIN<sup>12+</sup> | Used when the tensor is used as the **min** parameter of the LSTM operator. | 879| OH_NN_ALL_KEEP_DIMS<sup>12+</sup> | Used when the tensor is used as the **keepDims** parameter of the All operator. | 880| OH_NN_ASSERT_SUMMARIZE<sup>12+</sup> | Used when the tensor is used as the **summarize** parameter of the All operator. | 881| OH_NN_POW_SCALE<sup>12+</sup> | Used when the tensor is used as the **scale** parameter of the Pow operator. | 882| OH_NN_POW_SHIFT<sup>12+</sup> | Used when the tensor is used as the **shift** parameter of the Pow operator. | 883| OH_NN_AVG_POOL_ROUND_MODE<sup>12+</sup> | Used when the tensor is used as the **RoundMode** parameter of the AvgPool operator. | 884| OH_NN_AVG_POOL_GLOBAL<sup>12+</sup> | Used when the tensor is used as the **global** parameter of the AvgPool operator. | 885| OH_NN_FULL_CONNECTION_HAS_BIAS<sup>12+</sup> | Used when the tensor is used as the **hasBias** parameter of the FullConnection operator. | 886| OH_NN_FULL_CONNECTION_USE_AXIS<sup>12+</sup> | Used when the tensor is used as the **useAxis** parameter of the FullConnection operator. | 887| OH_NN_GELU_APPROXIMATE<sup>12+</sup> | Used when the tensor is used as the **approximate** parameter of the GeLU operator. | 888| OH_NN_MAX_POOL_ROUND_MODE<sup>12+</sup> | Used when the tensor is used as the **RoundMode** parameter of the MaxPool operator. | 889| OH_NN_MAX_POOL_GLOBAL<sup>12+</sup> | Used when the tensor is used as the **global** parameter of the MaxPool operator. | 890| OH_NN_PAD_PADDING_MODE<sup>12+</sup> | Used when the tensor is used as the **paddingMode** parameter of the Pad operator. | 891| OH_NN_REDUCE_MEAN_REDUCE_TO_END<sup>12+</sup> | Used when the tensor is used as the **reduceToEnd** parameter of the ReduceMean operator. | 892| OH_NN_REDUCE_MEAN_COEFF<sup>12+</sup> | Used when the tensor is used as the **coeff** parameter of the ReduceMean operator. | 893| OH_NN_REDUCE_PROD_REDUCE_TO_END<sup>12+</sup> | Used when the tensor is used as the **reduceToEnd** parameter of the ReduceProd operator. | 894| OH_NN_REDUCE_PROD_COEFF<sup>12+</sup> | Used when the tensor is used as the **coeff** parameter of the ReduceProd operator. | 895| OH_NN_REDUCE_ALL_REDUCE_TO_END<sup>12+</sup> | Used when the tensor is used as the **reduceToEnd** parameter of the ReduceAll operator. | 896| OH_NN_REDUCE_ALL_COEFF<sup>12+</sup> | Used when the tensor is used as the **coeff** parameter of the ReduceAll operator. | 897| OH_NN_TOP_K_AXIS<sup>12+</sup> | Used when the tensor is used as the **axis** parameter of the TopK operator. | 898| OH_NN_ARG_MAX_TOP_K<sup>12+</sup> | Used when the tensor is used as the **topK** parameter of the ArgMax operator. | 899| OH_NN_ARG_MAX_OUT_MAX_VALUE<sup>12+</sup> | Used when the tensor is used as the **outMaxValue** parameter of the ArgMax operator. | 900| OH_NN_QUANT_DTYPE_CAST_AXIS<sup>12+</sup> | Used when the tensor is used as the **axis** parameter of the QuantDTypeCast operator. | 901| OH_NN_SLICE_AXES<sup>12+</sup> | Used when the tensor is used as the **axes** parameter of the Slice operator. | 902| OH_NN_TILE_DIMS<sup>12+</sup> | Used when the tensor is used as the **dims** parameter of the Tile operator. | 903| OH_NN_CROP_AXIS<sup>12+</sup> | Used when the tensor is used as the **axis** parameter of the Crop operator. | 904| OH_NN_CROP_OFFSET<sup>12+</sup> | Used when the tensor is used as the **offset** parameter of the Crop operator. | 905| OH_NN_DETECTION_POST_PROCESS_INPUT_SIZE<sup>12+</sup> | Used when the tensor is used as the **inputSize** parameter of the DetectionPostProcess operator. | 906| OH_NN_DETECTION_POST_PROCESS_SCALE<sup>12+</sup> | Used when the tensor is used as the **scale** parameter of the DetectionPostProcess operator. | 907| OH_NN_DETECTION_POST_PROCESS_NMS_IOU_THRESHOLD<sup>12+</sup> | Used when the tensor is used as the **nmsIouThreshold** parameter of the DetectionPostProcess operator. | 908| OH_NN_DETECTION_POST_PROCESS_NMS_SCORE_THRESHOLD<sup>12+</sup> | Used when the tensor is used as the **nmsScoreThreshold** parameter of the DetectionPostProcess operator. | 909| OH_NN_DETECTION_POST_PROCESS_MAX_DETECTIONS<sup>12+</sup> | Used when the tensor is used as the **maxDetections** parameter of the DetectionPostProcess operator. | 910| OH_NN_DETECTION_POST_PROCESS_DETECTIONS_PER_CLASS<sup>12+</sup> | Used when the tensor is used as the **preClass** parameter of the DetectionPostProcess operator. | 911| OH_NN_DETECTION_POST_PROCESS_MAX_CLASSES_PER_DETECTION<sup>12+</sup> | Used when the tensor is used as the **maxClassPreDetection** parameter of the DetectionPostProcess operator. | 912| OH_NN_DETECTION_POST_PROCESS_NUM_CLASSES<sup>12+</sup> | Used when the tensor is used as the **numClasses** parameter of the DetectionPostProcess operator. | 913| OH_NN_DETECTION_POST_PROCESS_USE_REGULAR_NMS<sup>12+</sup> | Used when the tensor is used as the **useRegularNms** parameter of the DetectionPostProcess operator. | 914| OH_NN_DETECTION_POST_PROCESS_OUT_QUANTIZED<sup>12+</sup> | Used when the tensor is used as the **outQuantized** parameter of the DetectionPostProcess operator. | 915| OH_NN_L2_NORMALIZE_AXIS<sup>12+</sup> | Used when the tensor is used as the **axis** parameter of the L2Normalize operator. | 916| OH_NN_L2_NORMALIZE_EPSILON<sup>12+</sup> | Used when the tensor is used as the **epslion** parameter of the L2Normalize operator. | 917| OH_NN_L2_NORMALIZE_ACTIVATION_TYPE<sup>12+</sup> | Used when the tensor is used as the **activationType** parameter of the L2Normalize operator. | 918| OH_NN_LOG_SOFTMAX_AXIS<sup>12+</sup> | Used when the tensor is used as the **axis** parameter of the LogSoftmax operator. | 919| OH_NN_LRN_DEPTH_RADIUS<sup>12+</sup> | Used when the tensor is used as the **depthRadius** parameter of the LRN operator. | 920| OH_NN_LRN_BIAS<sup>12+</sup> | Used when the tensor is used as the **bias** parameter of the LRN operator. | 921| OH_NN_LRN_ALPHA<sup>12+</sup> | Used when the tensor is used as the **alpha** parameter of the LRN operator. | 922| OH_NN_LRN_BETA<sup>12+</sup> | Used when the tensor is used as the **beta** parameter of the LRN operator. | 923| OH_NN_LRN_NORM_REGION<sup>12+</sup> | Used when the tensor is used as the **normRegion** parameter of the LRN operator. | 924| OH_NN_SPACE_TO_DEPTH_BLOCK_SIZE<sup>12+</sup> | Used when the tensor is used as the **blockSize** parameter of the SpaceToDepth operator.| 925| OH_NN_REDUCE_MAX_KEEP_DIMS<sup>12+</sup> | Used when the tensor is used as the **keepDims** parameter of the ReduceMax operator. | 926| OH_NN_REDUCE_MAX_REDUCE_TO_END<sup>12+</sup> | Used when the tensor is used as the **reduceToEnd** parameter of the ReduceMax operator. | 927| OH_NN_REDUCE_MAX_COEFF<sup>12+</sup> | Used when the tensor is used as the **coeff** parameter of the ReduceMax operator. | 928| OH_NN_REDUCE_MIN_KEEP_DIMS<sup>12+</sup> | Used when the tensor is used as the **keepDims** parameter of the ReduceMin operator. | 929| OH_NN_REDUCE_MIN_REDUCE_TO_END<sup>12+</sup> | Used when the tensor is used as the **reduceToEnd** parameter of the ReduceMin operator. | 930| OH_NN_REDUCE_MIN_COEFF<sup>12+</sup> | Used when the tensor is used as the **coeff** parameter of the ReduceMin operator. | 931| OH_NN_REDUCE_SUM_KEEP_DIMS<sup>12+</sup> | Used when the tensor is used as the **keepDims** parameter of the ReduceSum operator. | 932| OH_NN_REDUCE_SUM_REDUCE_TO_END<sup>12+</sup> | Used when the tensor is used as the **reduceToEnd** parameter of the ReduceSum operator. | 933| OH_NN_REDUCE_SUM_COEFF<sup>12+</sup> | Used when the tensor is used as the **coeff** parameter of the ReduceSum operator. | 934| OH_NN_REDUCE_L2_KEEP_DIMS<sup>12+</sup> | Used when the tensor is used as the **keepDims** parameter of the ReduceL2 operator. | 935| OH_NN_REDUCE_L2_REDUCE_TO_END<sup>12+</sup> | Used when the tensor is used as the **reduceToEnd** parameter of the ReduceL2 operator. | 936| OH_NN_REDUCE_L2_COEFF<sup>12+</sup> | Used when the tensor is used as the **coeff** parameter of the ReduceL2 operator. | 937 938 939## Function Description 940 941 942### OH_NNCompilation_AddExtensionConfig() 943 944``` 945OH_NN_ReturnCode OH_NNCompilation_AddExtensionConfig (OH_NNCompilation *compilation, const char *configName, const void *configValue, const size_t configValueSize ) 946``` 947 948**Description** 949 950Adds extended configurations for custom device attributes. 951 952Some 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. 953 954After [OH_NNCompilation_Build](#oh_nncompilation_build) is called, **configName** and **configValue** can be released. 955 956**Since**: 11 957 958**Parameters** 959 960| Name| Description| 961| -------- | -------- | 962| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 963| configName | Configuration name.| 964| configValue | Configured value.| 965| configValueSize | Size of the configured value, in bytes.| 966 967**Returns** 968 969Execution 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). 970 971 972### OH_NNCompilation_Build() 973 974``` 975OH_NN_ReturnCode OH_NNCompilation_Build (OH_NNCompilation *compilation) 976``` 977 978**Description** 979 980Performs model building. 981 982After 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. 983 984**Since**: 9 985 986**Parameters** 987 988| Name| Description| 989| -------- | -------- | 990| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 991 992**Returns** 993 994Execution 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). 995 996 997### OH_NNCompilation_Construct() 998 999``` 1000OH_NNCompilation *OH_NNCompilation_Construct (const OH_NNModel *model) 1001``` 1002 1003**Description** 1004 1005Creates a model building instance of the [OH_NNCompilation](#oh_nncompilation) type. 1006 1007After 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. 1008 1009In 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: 1010 1011[OH_NNCompilation_SetCache](#oh_nncompilation_setcache) 1012 1013[OH_NNCompilation_SetPerformanceMode](#oh_nncompilation_setperformancemode) 1014 1015[OH_NNCompilation_SetPriority](#oh_nncompilation_setpriority) 1016 1017[OH_NNCompilation_EnableFloat16](#oh_nncompilation_enablefloat16) 1018 1019After this API is called to create [OH_NNCompilation](#oh_nncompilation), the [OH_NNModel](#oh_nnmodel) instance can be released. 1020 1021**Since**: 9 1022 1023**Parameters** 1024 1025| Name| Description| 1026| -------- | -------- | 1027| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 1028 1029**Returns** 1030 1031Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 1032 1033 1034### OH_NNCompilation_ConstructForCache() 1035 1036``` 1037OH_NNCompilation *OH_NNCompilation_ConstructForCache () 1038``` 1039 1040**Description** 1041 1042Creates an empty model building instance for later recovery from the model cache. 1043 1044For details about the model cache, see [OH_NNCompilation_SetCache](#oh_nncompilation_setcache). 1045 1046The time required for model recovery from the model cache is less than the time required for building using [OH_NNModel](#oh_nnmodel). 1047 1048Call [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. 1049 1050**Since**: 11 1051 1052**Returns** 1053 1054Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 1055 1056 1057### OH_NNCompilation_ConstructWithOfflineModelBuffer() 1058 1059``` 1060OH_NNCompilation *OH_NNCompilation_ConstructWithOfflineModelBuffer (const void *modelBuffer, size_t modelSize ) 1061``` 1062 1063**Description** 1064 1065Creates a model building instance based on the offline model buffer. 1066 1067This 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. 1068 1069**NOTE**<br>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. 1070 1071**Since**: 11 1072 1073**Parameters** 1074 1075| Name| Description| 1076| -------- | -------- | 1077| modelBuffer | Memory for storing offline model files.| 1078| modelSize | Memory size of the offline model.| 1079 1080**Returns** 1081 1082Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 1083 1084 1085### OH_NNCompilation_ConstructWithOfflineModelFile() 1086 1087``` 1088OH_NNCompilation *OH_NNCompilation_ConstructWithOfflineModelFile (const char *modelPath) 1089``` 1090 1091**Description** 1092 1093Creates a model building instance based on an offline model file. 1094 1095This 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. 1096 1097An 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). 1098 1099During development, offline build needs to be performed and offline models need to be deployed in application packages. 1100 1101**Since**: 11 1102 1103**Parameters** 1104 1105| Name| Description| 1106| -------- | -------- | 1107| modelPath | Path of the offline model file.| 1108 1109**Returns** 1110 1111Pointer to the [OH_NNCompilation](#oh_nncompilation) instance. If the operation fails, **NULL** is returned. 1112 1113 1114### OH_NNCompilation_Destroy() 1115 1116``` 1117void OH_NNCompilation_Destroy (OH_NNCompilation **compilation) 1118``` 1119 1120**Description** 1121 1122Destroys a model building instance of the [OH_NNCompilation](#oh_nncompilation) type. 1123 1124This 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). 1125 1126If **compilation** or **\*compilation** is a null pointer, this API only prints warning logs but does not perform the destruction operation. 1127 1128**Since**: 9 1129 1130**Parameters** 1131 1132| Name| Description| 1133| -------- | -------- | 1134| 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.| 1135 1136 1137### OH_NNCompilation_EnableFloat16() 1138 1139``` 1140OH_NN_ReturnCode OH_NNCompilation_EnableFloat16 (OH_NNCompilation *compilation, bool enableFloat16 ) 1141``` 1142 1143**Description** 1144 1145Enables float16 for computing. 1146 1147By 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. 1148 1149This option is invalid for fixed-point models, for example, fixed-point models of the int8 type. 1150 1151If this API is called on the device that does not support float16, the error code **OH_NN_UNAVAILABLE_DEVICE** is returned. 1152 1153**Since**: 9 1154 1155**Parameters** 1156 1157| Name| Description| 1158| -------- | -------- | 1159| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1160| 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.| 1161 1162**Returns** 1163 1164Execution 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). 1165 1166 1167### OH_NNCompilation_ExportCacheToBuffer() 1168 1169``` 1170OH_NN_ReturnCode OH_NNCompilation_ExportCacheToBuffer (OH_NNCompilation *compilation, const void *buffer, size_t length, size_t *modelSize ) 1171``` 1172 1173**Description** 1174 1175Writes the model cache to the specified buffer. 1176 1177For details about the model cache, see [OH_NNCompilation_SetCache](#oh_nncompilation_setcache). 1178 1179Note: 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). 1180 1181**Since**: 11 1182 1183**Parameters** 1184 1185| Name| Description| 1186| -------- | -------- | 1187| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1188| buffer | Pointer to the given memory.| 1189| length | Memory length. | 1190| modelSize | Size of the model cache, in bytes.| 1191 1192**Returns** 1193 1194Execution 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). 1195 1196 1197### OH_NNCompilation_ImportCacheFromBuffer() 1198 1199``` 1200OH_NN_ReturnCode OH_NNCompilation_ImportCacheFromBuffer (OH_NNCompilation *compilation, const void *buffer, size_t modelSize ) 1201``` 1202 1203**Description** 1204 1205Reads the model cache from the specified buffer. 1206 1207For details about the model cache, see [OH_NNCompilation_SetCache](#oh_nncompilation_setcache). 1208 1209After calling [OH_NNCompilation_ImportCacheFromBuffer](#oh_nncompilation_importcachefrombuffer), call [OH_NNCompilation_Build](#oh_nncompilation_build) to complete model recovery. 1210 1211Note: 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. 1212 1213**Since**: 11 1214 1215**Parameters** 1216 1217| Name| Description| 1218| -------- | -------- | 1219| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1220| buffer | Pointer to the given memory.| 1221| modelSize | Size of the model cache, in bytes.| 1222 1223**Returns** 1224 1225Execution 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). 1226 1227 1228### OH_NNCompilation_SetCache() 1229 1230``` 1231OH_NN_ReturnCode OH_NNCompilation_SetCache (OH_NNCompilation *compilation, const char *cachePath, uint32_t version ) 1232``` 1233 1234**Description** 1235 1236Sets the cache directory and version for model building. 1237 1238On 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: 1239 1240- 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**. 1241 1242- 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. 1243 1244- 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 on the underlying device, the cached file in the cache directory is overwritten and the version is updated to **version**. 1245 1246- 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. 1247 1248- 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. 1249 1250- 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. 1251 1252**Since**: 9 1253 1254**Parameters** 1255 1256| Name| Description| 1257| -------- | -------- | 1258| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1259| 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.| 1260| version | Cached model version.| 1261 1262**Returns** 1263 1264Execution 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). 1265 1266 1267### OH_NNCompilation_SetDevice() 1268 1269``` 1270OH_NN_ReturnCode OH_NNCompilation_SetDevice (OH_NNCompilation *compilation, size_t deviceID ) 1271``` 1272 1273**Description** 1274 1275Sets the device for model building and computing. 1276 1277In 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. 1278 1279**Since**: 9 1280 1281**Parameters** 1282 1283| Name| Description| 1284| -------- | -------- | 1285| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1286| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 1287 1288**Returns** 1289 1290Execution 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). 1291 1292 1293### OH_NNCompilation_SetPerformanceMode() 1294 1295``` 1296OH_NN_ReturnCode OH_NNCompilation_SetPerformanceMode (OH_NNCompilation *compilation, OH_NN_PerformanceMode performanceMode ) 1297``` 1298 1299**Description** 1300 1301Sets the performance mode for model computing. 1302 1303NNRt 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. 1304 1305If 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. 1306 1307**Since**: 9 1308 1309**Parameters** 1310 1311| Name| Description| 1312| -------- | -------- | 1313| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1314| performanceMode | Performance mode for model computing. For details, see [OH_NN_PerformanceMode](#oh_nn_performancemode).| 1315 1316**Returns** 1317 1318Execution 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). 1319 1320 1321### OH_NNCompilation_SetPriority() 1322 1323``` 1324OH_NN_ReturnCode OH_NNCompilation_SetPriority (OH_NNCompilation *compilation, OH_NN_Priority priority ) 1325``` 1326 1327**Description** 1328 1329Sets the priority for model computing. 1330 1331NNRt 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. 1332 1333If this API is called on a device that does not support priority setting, the error code **OH_NN_UNAVAILABLE_DEVICE** is returned. 1334 1335**Since**: 9 1336 1337**Parameters** 1338 1339| Name| Description| 1340| -------- | -------- | 1341| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1342| priority | Priority for model computing. For details, see [OH_NN_Priority](#oh_nn_priority).| 1343 1344**Returns** 1345 1346Execution 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). 1347 1348 1349### OH_NNDevice_GetAllDevicesID() 1350 1351``` 1352OH_NN_ReturnCode OH_NNDevice_GetAllDevicesID (const size_t **allDevicesID, uint32_t *deviceCount ) 1353``` 1354 1355**Description** 1356 1357Obtains the ID of the device connected to NNRt. 1358 1359Each device has a unique and fixed ID, which is returned through a uin32_t array. 1360 1361When 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. 1362 1363**Since**: 9 1364 1365**Parameters** 1366 1367| Name| Description| 1368| -------- | -------- | 1369| 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.| 1370| deviceCount | Pointer of the uint32_t type, which is used to return the length of **\*allDevicesID**.| 1371 1372**Returns** 1373 1374Execution 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). 1375 1376 1377### OH_NNDevice_GetName() 1378 1379``` 1380OH_NN_ReturnCode OH_NNDevice_GetName (size_t deviceID, const char **name ) 1381``` 1382 1383**Description** 1384 1385Obtains the name of the specified device. 1386 1387**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. 1388 1389**\*name** is a C-style string ended with **'\0'**. 1390 1391**\*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. 1392 1393**Since**: 9 1394 1395**Parameters** 1396 1397| Name| Description| 1398| -------- | -------- | 1399| deviceID | Device ID. If the value of **deviceID** is **0**, the first device in the device list is used by default.| 1400| name | Pointer to the char array, which saves the returned device name.| 1401 1402**Returns** 1403 1404Execution 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). 1405 1406 1407### OH_NNDevice_GetType() 1408 1409``` 1410OH_NN_ReturnCode OH_NNDevice_GetType (size_t deviceID, OH_NN_DeviceType *deviceType ) 1411``` 1412 1413**Description** 1414 1415Obtains the type of the specified device. 1416 1417**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: 1418 1419- * - **OH_NN_CPU**: CPU device. 1420 1421- * - **OH_NN_GPU**: GPU device. 1422 1423- * - **OH_NN_ACCELERATOR**: machine learning dedicated accelerator. 1424 1425- * - **OH_NN_OTHERS**: other device types. 1426 1427**Since**: 9 1428 1429**Parameters** 1430 1431| Name| Description| 1432| -------- | -------- | 1433| deviceID | Device ID. If the value of **deviceID** is **0**, the first device in the device list is used by default.| 1434| deviceType | Pointer to the [OH_NN_DeviceType](#oh_nn_devicetype) instance. The device type information is returned.| 1435 1436**Returns** 1437 1438Execution 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). 1439 1440 1441### OH_NNExecutor_AllocateInputMemory() 1442 1443``` 1444OH_NN_Memory *OH_NNExecutor_AllocateInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, size_t length ) 1445``` 1446 1447**Description** 1448 1449Applies for shared memory for a single model input on the device. 1450 1451NNRt 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. 1452 1453**Since**: 9 1454 1455**Parameters** 1456 1457| Name| Description| 1458| -------- | -------- | 1459| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1460| 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}**.| 1461| length | Memory size to be applied for, in bytes.| 1462 1463**Returns** 1464 1465Pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. If the operation fails, **NULL** is returned. 1466 1467 1468### OH_NNExecutor_AllocateOutputMemory() 1469 1470``` 1471OH_NN_Memory *OH_NNExecutor_AllocateOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, size_t length ) 1472``` 1473 1474**Description** 1475 1476Applies for shared memory for a single model output on the device. 1477 1478NNRt 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. 1479 1480**Since**: 9 1481 1482**Parameters** 1483 1484| Name| Description| 1485| -------- | -------- | 1486| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1487| 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}**.| 1488| length | Memory size to be applied for, in bytes.| 1489 1490**Returns** 1491 1492Pointer to the [OH_NN_Memory](_o_h___n_n___memory.md) instance. If the operation fails, **NULL** is returned. 1493 1494 1495### OH_NNExecutor_Construct() 1496 1497``` 1498OH_NNExecutor *OH_NNExecutor_Construct (OH_NNCompilation *compilation) 1499``` 1500 1501**Description** 1502 1503Creates an [OH_NNExecutor](#oh_nnexecutor) instance. 1504 1505This API constructs a model inference executor for a device based on the specified [OH_NNCompilation](#oh_nncompilation) instance. Use [OH_NNExecutor_SetInput](#oh_nnexecutor_setinput) to set the model input data. After the input data is set, call [OH_NNExecutor_Run](#oh_nnexecutor_run) to perform inference and then call [OH_NNExecutor_SetOutput](#oh_nnexecutor_setoutput) to obtain the computing result. 1506 1507After 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. 1508 1509**Since**: 9 1510 1511**Parameters** 1512 1513| Name| Description| 1514| -------- | -------- | 1515| compilation | Pointer to the [OH_NNCompilation](#oh_nncompilation) instance.| 1516 1517**Returns** 1518 1519Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance. If the operation fails, **NULL** is returned. 1520 1521 1522### OH_NNExecutor_CreateInputTensorDesc() 1523 1524``` 1525NN_TensorDesc *OH_NNExecutor_CreateInputTensorDesc (const OH_NNExecutor *executor, size_t index ) 1526``` 1527 1528**Description** 1529 1530Creates the description of an input tensor based on the specified index value. 1531 1532The 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). 1533 1534**Since**: 11 1535 1536**Parameters** 1537 1538| Name| Description| 1539| -------- | -------- | 1540| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1541| index | Index value of the input tensor.| 1542 1543**Returns** 1544 1545Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 1546 1547 1548### OH_NNExecutor_CreateOutputTensorDesc() 1549 1550``` 1551NN_TensorDesc *OH_NNExecutor_CreateOutputTensorDesc (const OH_NNExecutor *executor, size_t index ) 1552``` 1553 1554**Description** 1555 1556Creates the description of an output tensor based on the specified index value. 1557 1558The 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). 1559 1560**Since**: 11 1561 1562**Parameters** 1563 1564| Name| Description| 1565| -------- | -------- | 1566| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1567| index | Index value of the output tensor.| 1568 1569**Returns** 1570 1571Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 1572 1573 1574### OH_NNExecutor_Destroy() 1575 1576``` 1577void OH_NNExecutor_Destroy (OH_NNExecutor **executor) 1578``` 1579 1580**Description** 1581 1582Destroys an executor instance to release the memory occupied by it. 1583 1584This API needs to be called to release the executor instance created by calling [OH_NNExecutor_Construct](#oh_nnexecutor_construct). Otherwise, memory leak will occur. 1585 1586If **executor** or **\*executor** is a null pointer, this API only prints the warning log and does not execute the release logic. 1587 1588**Since**: 9 1589 1590**Parameters** 1591 1592| Name| Description| 1593| -------- | -------- | 1594| executor | Level-2 pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1595 1596 1597### OH_NNExecutor_DestroyInputMemory() 1598 1599``` 1600void OH_NNExecutor_DestroyInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory ) 1601``` 1602 1603**Description** 1604 1605Releases the input memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance. 1606 1607This API needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateInputMemory](#oh_nnexecutor_allocateinputmemory). Otherwise, memory leak will occur. The mapping between **inputIndex** and **memory** must be the same as that in memory instance creation. 1608 1609If **memory** or **\*memory** is a null pointer, this API only prints the warning log and does not execute the release logic. 1610 1611**Since**: 9 1612 1613**Parameters** 1614 1615| Name| Description| 1616| -------- | -------- | 1617| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1618| 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}**.| 1619| 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.| 1620 1621 1622### OH_NNExecutor_DestroyOutputMemory() 1623 1624``` 1625void OH_NNExecutor_DestroyOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, OH_NN_Memory **memory ) 1626``` 1627 1628**Description** 1629 1630Releases the output memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance. 1631 1632This API needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateOutputMemory](#oh_nnexecutor_allocateoutputmemory). Otherwise, memory leak will occur. The mapping between **outputIndex** and **memory** must be the same as that in memory instance creation. 1633 1634If **memory** or **\*memory** is a null pointer, this API only prints the warning log and does not execute the release logic. 1635 1636**Since**: 9 1637 1638**Parameters** 1639 1640| Name| Description| 1641| -------- | -------- | 1642| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1643| 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}**.| 1644| 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.| 1645 1646 1647### OH_NNExecutor_GetInputCount() 1648 1649``` 1650OH_NN_ReturnCode OH_NNExecutor_GetInputCount (const OH_NNExecutor *executor, size_t *inputCount ) 1651``` 1652 1653**Description** 1654 1655Obtains the number of input tensors. 1656 1657You 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. 1658 1659**Since**: 11 1660 1661**Parameters** 1662 1663| Name| Description| 1664| -------- | -------- | 1665| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1666| inputCount | Number of returned input tensors.| 1667 1668**Returns** 1669 1670Execution 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). 1671 1672 1673### OH_NNExecutor_GetInputDimRange() 1674 1675``` 1676OH_NN_ReturnCode OH_NNExecutor_GetInputDimRange (const OH_NNExecutor *executor, size_t index, size_t **minInputDims, size_t **maxInputDims, size_t *shapeLength ) 1677``` 1678 1679**Description** 1680 1681Obtains the dimension range of all input tensors. 1682 1683If 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]. 1684 1685Note: 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). 1686 1687As 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. 1688 1689You do not need to release the memory of **\*minInputDims** and **\*maxInputDims**. It is released with **executor**. 1690 1691**Since**: 11 1692 1693**Parameters** 1694 1695| Name| Description| 1696| -------- | -------- | 1697| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1698| index | Index value of the input tensor.| 1699| minInputDims | Pointer to the returned array, which saves the minimum dimension of the specified input tensor (the number of dimensions matches the shape).| 1700| maxInputDims | Pointer to the returned array, which saves the maximum dimension of the specified input tensor (the number of dimensions matches the shape).| 1701| shapeLength | Number of dimensions of the returned input tensor, which is the same as the shape.| 1702 1703**Returns** 1704 1705Execution 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). 1706 1707 1708### OH_NNExecutor_GetOutputCount() 1709 1710``` 1711OH_NN_ReturnCode OH_NNExecutor_GetOutputCount (const OH_NNExecutor *executor, size_t *outputCount ) 1712``` 1713 1714**Description** 1715 1716Obtains the number of output tensors. 1717 1718You 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. 1719 1720**Since**: 11 1721 1722**Parameters** 1723 1724| Name| Description| 1725| -------- | -------- | 1726| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1727| outputCount | Number of returned output tensors.| 1728 1729**Returns** 1730 1731Execution 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). 1732 1733 1734### OH_NNExecutor_GetOutputShape() 1735 1736``` 1737OH_NN_ReturnCode OH_NNExecutor_GetOutputShape (OH_NNExecutor *executor, uint32_t outputIndex, int32_t **shape, uint32_t *shapeLength ) 1738``` 1739 1740**Description** 1741 1742Obtains the dimension information about the output tensor. 1743 1744You 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_run). It is commonly used in dynamic shape input and output scenarios. 1745 1746Note: 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). 1747 1748As 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. 1749 1750You do not need to release the memory of **shape**. It is released with **executor**. 1751 1752**Since**: 9 1753 1754**Parameters** 1755 1756| Name| Description| 1757| -------- | -------- | 1758| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1759| 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}.| 1760| 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.| 1761| shapeLength | Pointer to the uint32_t type. The number of output dimensions is returned.| 1762 1763**Returns** 1764 1765Execution 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). 1766 1767 1768### OH_NNExecutor_Run() 1769 1770``` 1771OH_NN_ReturnCode OH_NNExecutor_Run (OH_NNExecutor *executor) 1772``` 1773 1774**Description** 1775 1776Executes model inference. 1777 1778This API performs end-to-end model inference and computing on the device associated with the executor. 1779 1780**Since**: 9 1781 1782**Parameters** 1783 1784| Name| Description| 1785| -------- | -------- | 1786| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1787 1788**Returns** 1789 1790Execution 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). 1791 1792 1793### OH_NNExecutor_RunAsync() 1794 1795``` 1796OH_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 ) 1797``` 1798 1799**Description** 1800 1801Performs asynchronous inference. 1802 1803You 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. 1804 1805If 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). 1806 1807This 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. 1808 1809You 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). 1810 1811If the inference times out, it is terminated immediately and the error code **OH_NN_TIMEOUT** is returned through the [NN_OnRunDone](#nn_onrundone) callback. 1812 1813**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. 1814 1815**Since**: 11 1816 1817**Parameters** 1818 1819| Name| Description| 1820| -------- | -------- | 1821| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1822| inputTensor | Array of input tensors.| 1823| inputCount | Number of input tensors.| 1824| outputTensor | Array of output tensors.| 1825| outputCount | Number of output tensors.| 1826| timeout | Timeout interval of asynchronous inference, in ms.| 1827| userData | Identifier of asynchronous inference.| 1828 1829**Returns** 1830 1831Execution 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). 1832 1833 1834### OH_NNExecutor_RunSync() 1835 1836``` 1837OH_NN_ReturnCode OH_NNExecutor_RunSync (OH_NNExecutor *executor, NN_Tensor *inputTensor[], size_t inputCount, NN_Tensor *outputTensor[], size_t outputCount ) 1838``` 1839 1840**Description** 1841 1842Performs synchronous inference. 1843 1844You 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. 1845 1846If 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). 1847 1848**Since**: 11 1849 1850**Parameters** 1851 1852| Name| Description| 1853| -------- | -------- | 1854| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1855| inputTensor | Array of input tensors.| 1856| inputCount | Number of input tensors.| 1857| outputTensor | Array of output tensors.| 1858| outputCount | Number of output tensors.| 1859 1860**Returns** 1861 1862Execution 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). 1863 1864 1865### OH_NNExecutor_SetInput() 1866 1867``` 1868OH_NN_ReturnCode OH_NNExecutor_SetInput (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const void *dataBuffer, size_t length ) 1869``` 1870 1871**Description** 1872 1873Sets the data for a single model input. 1874 1875This 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. 1876 1877NNRt supports models with dynamical shape input. For fixed shape input and dynamic shape input scenarios, this API uses different processing policies. 1878 1879- - Fixed shape input: The attributes of **tensor** must be the same as those of the tensor added by calling [OH_NNModel_AddTensor](#oh_nnmodel_addtensor) in the build phase. 1880 1881- - 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. 1882 1883**Since**: 9 1884 1885**Parameters** 1886 1887| Name| Description| 1888| -------- | -------- | 1889| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1890| 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}**.| 1891| tensor | Tensor corresponding to the input data.| 1892| dataBuffer | Pointer to the input data.| 1893| length | Length of the data memory, in bytes.| 1894 1895**Returns** 1896 1897Execution 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). 1898 1899 1900### OH_NNExecutor_SetInputWithMemory() 1901 1902``` 1903OH_NN_ReturnCode OH_NNExecutor_SetInputWithMemory (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const OH_NN_Memory *memory ) 1904``` 1905 1906**Description** 1907 1908Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model input. 1909 1910In 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. 1911 1912**Since**: 9 1913 1914**Parameters** 1915 1916| Name| Description| 1917| -------- | -------- | 1918| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1919| 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}.| 1920| tensor | Pointer to [OH_NN_Tensor](_o_h___n_n___tensor.md), which is used to set the tensor corresponding to a single input.| 1921| memory | Pointer that points to [OH_NN_Memory](_o_h___n_n___memory.md).| 1922 1923**Returns** 1924 1925Execution 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). 1926 1927 1928### OH_NNExecutor_SetOnRunDone() 1929 1930``` 1931OH_NN_ReturnCode OH_NNExecutor_SetOnRunDone (OH_NNExecutor *executor, NN_OnRunDone onRunDone ) 1932``` 1933 1934**Description** 1935 1936Sets the callback processing function invoked when the asynchronous inference ends. 1937 1938For the definition of the callback function, see [NN_OnRunDone](#nn_onrundone). 1939 1940**Since**: 11 1941 1942**Parameters** 1943 1944| Name| Description| 1945| -------- | -------- | 1946| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1947| onRunDone | Handle of the callback function [NN_OnRunDone](#nn_onrundone)| 1948 1949**Returns** 1950 1951Execution 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). 1952 1953 1954### OH_NNExecutor_SetOnServiceDied() 1955 1956``` 1957OH_NN_ReturnCode OH_NNExecutor_SetOnServiceDied (OH_NNExecutor *executor, NN_OnServiceDied onServiceDied ) 1958``` 1959 1960**Description** 1961 1962Sets the callback processing function invoked when the device driver service terminates unexpectedly during asynchronous inference. 1963 1964For the definition of the callback function, see [NN_OnServiceDied](#nn_onservicedied). 1965 1966**Since**: 11 1967 1968**Parameters** 1969 1970| Name| Description| 1971| -------- | -------- | 1972| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 1973| onServiceDied | Callback function handle [NN_OnServiceDied](#nn_onservicedied).| 1974 1975**Returns** 1976 1977Execution 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). 1978 1979 1980### OH_NNExecutor_SetOutput() 1981 1982``` 1983OH_NN_ReturnCode OH_NNExecutor_SetOutput (OH_NNExecutor *executor, uint32_t outputIndex, void *dataBuffer, size_t length ) 1984``` 1985 1986**Description** 1987 1988Sets the memory for a single model output. 1989 1990This method binds the buffer pointed by **dataBuffer** to the output specified by **outputIndex**. The length of the buffer is specified by **length**. 1991 1992After [OH_NNExecutor_Run](#oh_nnexecutor_run) 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. 1993 1994- 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**. 1995 1996- 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. 1997 1998**Since**: 9 1999 2000**Parameters** 2001 2002| Name| Description| 2003| -------- | -------- | 2004| executor | Pointer to the [OH_NNExecutor](#oh_nnexecutor) instance.| 2005| 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}**.| 2006| dataBuffer | Pointer to the output data.| 2007| length | Length of the data memory, in bytes.| 2008 2009**Returns** 2010 2011Execution 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). 2012 2013 2014### OH_NNExecutor_SetOutputWithMemory() 2015 2016``` 2017OH_NN_ReturnCode OH_NNExecutor_SetOutputWithMemory (OH_NNExecutor *executor, uint32_t outputIndex, const OH_NN_Memory *memory ) 2018``` 2019 2020**Description** 2021 2022Shared memory pointed by the [OH_NN_Memory](_o_h___n_n___memory.md) instance for a single model output. 2023 2024In 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. 2025 2026**Since**: 9 2027 2028**Parameters** 2029 2030| Name| Description| 2031| -------- | -------- | 2032| executor | Pointer to the executor.| 2033| 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}.| 2034| memory | Pointer that points to [OH_NN_Memory](_o_h___n_n___memory.md).| 2035 2036**Returns** 2037 2038Execution 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). 2039 2040 2041### OH_NNModel_AddOperation() 2042 2043``` 2044OH_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 ) 2045``` 2046 2047**Description** 2048 2049Adds an operator to a model instance. 2050 2051You 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). 2052 2053**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). 2054 2055If 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). 2056 2057**Since**: 9 2058 2059**Parameters** 2060 2061| Name| Description| 2062| -------- | -------- | 2063| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2064| op | Type of the operator to be added. For details, see [OH_NN_OperationType](#oh_nn_operationtype).| 2065| paramIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the parameter tensor index of the operator.| 2066| inputIndices | Pointer to the **OH_NN_UInt32Array** instance, specifying the input tensor index of the operator.| 2067| outputIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the output tensor index of the operator.| 2068 2069**Returns** 2070 2071Execution 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). 2072 2073 2074### OH_NNModel_AddTensor() 2075 2076``` 2077OH_NN_ReturnCode OH_NNModel_AddTensor (OH_NNModel *model, const OH_NN_Tensor *tensor ) 2078``` 2079 2080**Description** 2081 2082Adds a tensor to a model instance. 2083 2084The 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. 2085 2086NNRt 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. 2087 2088**Since**: 9 2089 2090**Parameters** 2091 2092| Name| Description| 2093| -------- | -------- | 2094| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2095| 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.| 2096 2097**Returns** 2098 2099Execution 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). 2100 2101 2102### OH_NNModel_AddTensorToModel() 2103 2104``` 2105OH_NN_ReturnCode OH_NNModel_AddTensorToModel (OH_NNModel *model, const NN_TensorDesc *tensorDesc ) 2106``` 2107 2108**Description** 2109 2110Adds a tensor to a model instance. 2111 2112The 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. 2113 2114NNRt 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. 2115 2116**Since**: 9 2117 2118**Parameters** 2119 2120| Name| Description| 2121| -------- | -------- | 2122| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2123| tensorDesc | Pointer to [NN_TensorDesc](#nn_tensordesc) tensor, which specifies the attributes of the tensor added to the model instance.| 2124 2125**Returns** 2126 2127Execution 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). 2128 2129 2130### OH_NNModel_Construct() 2131 2132``` 2133OH_NNModel *OH_NNModel_Construct (void ) 2134``` 2135 2136**Description** 2137 2138Creates a model instance of the [OH_NNModel](#oh_nnmodel) type and constructs a model instance by using the APIs provided by **OH_NNModel**. 2139 2140Before 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. 2141 2142After a model instance is used, destroy it by calling [OH_NNModel_Destroy](#oh_nnmodel_destroy) to avoid memory leak. 2143 2144**Since**: 9 2145 2146**Returns** 2147 2148Pointer to the [OH_NNModel](#oh_nnmodel) instance. If the operation fails, **NULL** is returned. 2149 2150 2151### OH_NNModel_Destroy() 2152 2153``` 2154void OH_NNModel_Destroy (OH_NNModel **model) 2155``` 2156 2157**Description** 2158 2159Destroys a model instance. 2160 2161This API needs to be called to destroy the model instance created by calling [OH_NNModel_Construct](#oh_nnmodel_construct). Otherwise, memory leak will occur. 2162 2163If **model** or **\*model** is a null pointer, this API only prints warning logs but does not perform the destruction operation. 2164 2165**Since**: 9 2166 2167**Parameters** 2168 2169| Name| Description| 2170| -------- | -------- | 2171| 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.| 2172 2173 2174### OH_NNModel_Finish() 2175 2176``` 2177OH_NN_ReturnCode OH_NNModel_Finish (OH_NNModel *model) 2178``` 2179 2180**Description** 2181 2182Completes model composition. 2183 2184After 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. 2185 2186Before calling **OH_NNModel_GetAvailableOperations** and **OH_NNCompilation_Construct**, you must call this API to complete composition. 2187 2188**Since**: 9 2189 2190**Parameters** 2191 2192| Name| Description| 2193| -------- | -------- | 2194| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 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_NNModel_GetAvailableOperations() 2202 2203``` 2204OH_NN_ReturnCode OH_NNModel_GetAvailableOperations (OH_NNModel *model, size_t deviceID, const bool **isSupported, uint32_t *opCount ) 2205``` 2206 2207**Description** 2208 2209Checks whether all operators in a model are supported by the device. The result is indicated by a Boolean value. 2210 2211Checks 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**. 2212 2213After 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. 2214 2215**Since**: 9 2216 2217**Parameters** 2218 2219| Name| Description| 2220| -------- | -------- | 2221| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2222| deviceID | Device ID to be queried, which can be obtained by using [OH_NNDevice_GetAllDevicesID](#oh_nndevice_getalldevicesid).| 2223| isSupported | Pointer to the **OHHDRMetaData** array. The input **(\*isSupported)** must be a null pointer. Otherwise, **OH_NN_INVALID_PARAMETER** is returned.| 2224| opCount | Number of operators in a model instance, corresponding to the length of the **(\*isSupported)** array.| 2225 2226**Returns** 2227 2228Execution 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). 2229 2230 2231### OH_NNModel_SetTensorData() 2232 2233``` 2234OH_NN_ReturnCode OH_NNModel_SetTensorData (OH_NNModel *model, uint32_t index, const void *dataBuffer, size_t length ) 2235``` 2236 2237**Description** 2238 2239Sets the tensor value. 2240 2241For 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). 2242 2243**Since**: 9 2244 2245**Parameters** 2246 2247| Name| Description| 2248| -------- | -------- | 2249| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2250| index | Index value of a tensor.| 2251| dataBuffer | Pointer to the real data memory.| 2252| length | Length of the data memory.| 2253 2254**Returns** 2255 2256Execution 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). 2257 2258 2259### OH_NNModel_SetTensorQuantParams() 2260 2261``` 2262OH_NN_ReturnCode OH_NNModel_SetTensorQuantParams (OH_NNModel *model, uint32_t index, NN_QuantParam *quantParam ) 2263``` 2264 2265**Description** 2266 2267Sets the quantization parameters of a tensor. For details, see [NN_QuantParam](#nn_quantparam). 2268 2269**Since**: 11 2270 2271**Parameters** 2272 2273| Name| Description| 2274| -------- | -------- | 2275| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2276| index | Index value of a tensor.| 2277| quantParam | Pointer to [NN_QuantParam](#nn_quantparam).| 2278 2279**Returns** 2280 2281Execution 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). 2282 2283 2284### OH_NNModel_SetTensorType() 2285 2286``` 2287OH_NN_ReturnCode OH_NNModel_SetTensorType (OH_NNModel *model, uint32_t index, OH_NN_TensorType tensorType ) 2288``` 2289 2290**Description** 2291 2292Sets the tensor type. For details, see [OH_NN_TensorType](#oh_nn_tensortype). 2293 2294**Since**: 11 2295 2296**Parameters** 2297 2298| Name| Description| 2299| -------- | -------- | 2300| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2301| index | Index value of a tensor.| 2302| tensorType | Tensor type.| 2303 2304**Returns** 2305 2306Execution 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). 2307 2308 2309### OH_NNModel_SpecifyInputsAndOutputs() 2310 2311``` 2312OH_NN_ReturnCode OH_NNModel_SpecifyInputsAndOutputs (OH_NNModel *model, const OH_NN_UInt32Array *inputIndices, const OH_NN_UInt32Array *outputIndices ) 2313``` 2314 2315**Description** 2316 2317Sets an index value for the input and output tensors of a model. 2318 2319A 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. 2320 2321The 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). 2322 2323Currently, the model input and output cannot be set asynchronously. 2324 2325**Since**: 9 2326 2327**Parameters** 2328 2329| Name| Description| 2330| -------- | -------- | 2331| model | Pointer to the [OH_NNModel](#oh_nnmodel) instance.| 2332| inputIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the input tensor of the operator.| 2333| outputIndices | Pointer to the OH_NN_UInt32Array instance, which is used to set the output tensor of the operator.| 2334 2335**Returns** 2336 2337Execution 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). 2338 2339 2340### OH_NNQuantParam_Create() 2341 2342``` 2343NN_QuantParam *OH_NNQuantParam_Create () 2344``` 2345 2346**Description** 2347 2348Creates an [NN_QuantParam](#nn_quantparam) instance. 2349 2350After 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. 2351 2352**Since**: 11 2353 2354**Returns** 2355 2356Pointer to the [NN_QuantParam](#nn_quantparam) instance. If the operation fails, **NULL** is returned. 2357 2358 2359### OH_NNQuantParam_Destroy() 2360 2361``` 2362OH_NN_ReturnCode OH_NNQuantParam_Destroy (NN_QuantParam **quantParams) 2363``` 2364 2365**Description** 2366 2367Destroys an [NN_QuantParam](#nn_quantparam) instance. 2368 2369After 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. 2370 2371If **quantParams** or **\*quantParams** is a null pointer, this API only prints warning logs but does not perform the destruction operation. 2372 2373**Since**: 11 2374 2375**Parameters** 2376 2377| Name| Description| 2378| -------- | -------- | 2379| quantParams | Level-2 pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2380 2381**Returns** 2382 2383Execution 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). 2384 2385 2386### OH_NNQuantParam_SetNumBits() 2387 2388``` 2389OH_NN_ReturnCode OH_NNQuantParam_SetNumBits (NN_QuantParam *quantParams, const uint32_t *numBits, size_t quantCount ) 2390``` 2391 2392**Description** 2393 2394Sets the number of quantization bits for an [NN_QuantParam](#nn_quantparam) instance. 2395 2396**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels. 2397 2398**Since**: 11 2399 2400**Parameters** 2401 2402| Name| Description| 2403| -------- | -------- | 2404| quantParams | Pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2405| numBits | Array consisting of quantization bits of all quantization parameters in a tensor.| 2406| quantCount | Number of quantization parameters in a tensor.| 2407 2408**Returns** 2409 2410Execution 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). 2411 2412 2413### OH_NNQuantParam_SetScales() 2414 2415``` 2416OH_NN_ReturnCode OH_NNQuantParam_SetScales (NN_QuantParam *quantParams, const double *scales, size_t quantCount ) 2417``` 2418 2419**Description** 2420 2421Sets the scaling coefficient for an [NN_QuantParam](#nn_quantparam) instance. 2422 2423**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels. 2424 2425**Since**: 11 2426 2427**Parameters** 2428 2429| Name| Description| 2430| -------- | -------- | 2431| quantParams | Pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2432| scales | Array consisting of scaling coefficients of all quantization parameters in the tensor.| 2433| quantCount | Number of quantization parameters in a tensor.| 2434 2435**Returns** 2436 2437Execution 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). 2438 2439 2440### OH_NNQuantParam_SetZeroPoints() 2441 2442``` 2443OH_NN_ReturnCode OH_NNQuantParam_SetZeroPoints (NN_QuantParam *quantParams, const int32_t *zeroPoints, size_t quantCount ) 2444``` 2445 2446**Description** 2447 2448Sets the zero point for an [NN_QuantParam](#nn_quantparam) instance. 2449 2450**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels. 2451 2452**Since**: 11 2453 2454**Parameters** 2455 2456| Name| Description| 2457| -------- | -------- | 2458| quantParams | Pointer to the [NN_QuantParam](#nn_quantparam) instance.| 2459| zeroPoints | Array consisting of zero points of all quantization parameters in a tensor.| 2460| quantCount | Number of quantization parameters in a tensor.| 2461 2462**Returns** 2463 2464Execution 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). 2465 2466 2467### OH_NNTensor_Create() 2468 2469``` 2470NN_Tensor *OH_NNTensor_Create (size_t deviceID, NN_TensorDesc *tensorDesc ) 2471``` 2472 2473**Description** 2474 2475Creates an [NN_Tensor](#nn_tensor) instance from [NN_TensorDesc](#nn_tensordesc). 2476 2477This 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. 2478 2479Note: 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). 2480 2481If the tensor shape is dynamic, an error code is returned. 2482 2483**deviceID** indicates the selected device. If the value is **0**, the first device in the current device list is used by default. 2484 2485**tensorDesc is mandatory**. If it is a null pointer, an error code is returned. 2486 2487If the [NN_Tensor](#nn_tensor) instance is no longer needed, destroy it by calling [OH_NNTensor_Destroy](#oh_nntensor_destroy). 2488 2489**Since**: 11 2490 2491**Parameters** 2492 2493| Name| Description| 2494| -------- | -------- | 2495| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 2496| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2497 2498**Returns** 2499 2500Pointer to the [NN_Tensor](#nn_tensor) instance. If the operation fails, **NULL** is returned. 2501 2502 2503### OH_NNTensor_CreateWithFd() 2504 2505``` 2506NN_Tensor *OH_NNTensor_CreateWithFd (size_t deviceID, NN_TensorDesc *tensorDesc, int fd, size_t size, size_t offset ) 2507``` 2508 2509**Description** 2510 2511Creates an {\@Link NN_Tensor} instance based on the specified file descriptor of the shared memory and [NN_TensorDesc](#nn_tensordesc) instance. 2512 2513This 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. 2514 2515Note: 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). 2516 2517**deviceID** indicates the selected device. If the value is **0**, the first device in the current device list is used by default. 2518 2519**tensorDesc** is mandatory. If the pointer is null, an error code is returned. 2520 2521If the [NN_Tensor](#nn_tensor) instance is no longer needed, destroy it by calling [OH_NNTensor_Destroy](#oh_nntensor_destroy). 2522 2523**Since**: 11 2524 2525**Parameters** 2526 2527| Name| Description| 2528| -------- | -------- | 2529| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 2530| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2531| fd | **fd** of the shared memory to be used.| 2532| size | Size of the shared memory to be used.| 2533| offset | Offset of the shared memory to be used.| 2534 2535**Returns** 2536 2537Pointer to the [NN_Tensor](#nn_tensor) instance. If the operation fails, **NULL** is returned. 2538 2539 2540### OH_NNTensor_CreateWithSize() 2541 2542``` 2543NN_Tensor *OH_NNTensor_CreateWithSize (size_t deviceID, NN_TensorDesc *tensorDesc, size_t size ) 2544``` 2545 2546**Description** 2547 2548Creates an [NN_Tensor](#nn_tensor) instance based on the specified memory size and [NN_TensorDesc](#nn_tensordesc) instance. 2549 2550This 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. 2551 2552Note 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). 2553 2554**deviceID** indicates the ID of the selected device. If the value is **0**, the first device is used. 2555 2556**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. 2557 2558If the [NN_Tensor](#nn_tensor) instance is no longer needed, destroy it by calling [OH_NNTensor_Destroy](#oh_nntensor_destroy). 2559 2560**Since**: 11 2561 2562**Parameters** 2563 2564| Name| Description| 2565| -------- | -------- | 2566| deviceID | Device ID. If the value is **0**, the first device in the current device list is used by default.| 2567| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2568| size | Size of the tensor data to be allocated.| 2569 2570**Returns** 2571 2572Pointer to the [NN_Tensor](#nn_tensor) instance. If the operation fails, **NULL** is returned. 2573 2574 2575### OH_NNTensor_Destroy() 2576 2577``` 2578OH_NN_ReturnCode OH_NNTensor_Destroy (NN_Tensor **tensor) 2579``` 2580 2581**Description** 2582 2583Destroys an [NN_Tensor](#nn_tensor) instance. 2584 2585If the [NN_Tensor](#nn_tensor) instance is no longer needed, call this API to destroy it. Otherwise, memory leak will occur. 2586 2587If the **tensor** or **\*tensor** pointer is null, this API returns an error code but does not perform the destruction operation. 2588 2589**Since**: 11 2590 2591**Parameters** 2592 2593| Name| Description| 2594| -------- | -------- | 2595| tensor | Level-2 pointer to the [NN_Tensor](#nn_tensor) instance.| 2596 2597**Returns** 2598 2599Execution 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). 2600 2601 2602### OH_NNTensor_GetDataBuffer() 2603 2604``` 2605void *OH_NNTensor_GetDataBuffer (const NN_Tensor *tensor) 2606``` 2607 2608**Description** 2609 2610Obtains the memory address of [NN_Tensor](#nn_tensor) data. 2611 2612You 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. 2613 2614Note: 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). 2615 2616If the **tensor** pointer is null, a null pointer is returned. 2617 2618**Since**: 11 2619 2620**Parameters** 2621 2622| Name| Description| 2623| -------- | -------- | 2624| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2625 2626**Returns** 2627 2628Pointer to the tensor data memory. If the operation fails, a null pointer is returned. 2629 2630 2631### OH_NNTensor_GetFd() 2632 2633``` 2634OH_NN_ReturnCode OH_NNTensor_GetFd (const NN_Tensor *tensor, int *fd ) 2635``` 2636 2637**Description** 2638 2639Obtains the file descriptor of the shared memory where [NN_Tensor](#nn_tensor) data is stored. 2640 2641**fd** corresponds to a device shared memory and can be used by another [NN_Tensor](#nn_tensor) through [OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd). 2642 2643If **tensor** or **fd** pointer is null, an error code is returned. 2644 2645**Since**: 11 2646 2647**Parameters** 2648 2649| Name| Description| 2650| -------- | -------- | 2651| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2652| fd | **fd** of the shared memory.| 2653 2654**Returns** 2655 2656Execution 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). 2657 2658 2659### OH_NNTensor_GetOffset() 2660 2661``` 2662OH_NN_ReturnCode OH_NNTensor_GetOffset (const NN_Tensor *tensor, size_t *offset ) 2663``` 2664 2665**Description** 2666 2667Obtains the offset of [NN_Tensor](#nn_tensor) data in the shared memory. 2668 2669**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). 2670 2671Note: 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). 2672 2673If **tensor** or **offset** pointer is null, an error code is returned. 2674 2675**Since**: 11 2676 2677**Parameters** 2678 2679| Name| Description| 2680| -------- | -------- | 2681| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2682| offset | Offset for the fd of the tensor.| 2683 2684**Returns** 2685 2686Execution 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). 2687 2688 2689### OH_NNTensor_GetSize() 2690 2691``` 2692OH_NN_ReturnCode OH_NNTensor_GetSize (const NN_Tensor *tensor, size_t *size ) 2693``` 2694 2695**Description** 2696 2697Obtains the size of the shared memory where the [NN_Tensor](#nn_tensor) data is stored. 2698 2699The 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). 2700 2701Note: 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). 2702 2703If the **tensor** or **size** pointer is null, an error code is returned. 2704 2705**Since**: 11 2706 2707**Parameters** 2708 2709| Name| Description| 2710| -------- | -------- | 2711| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2712| size | Size of the shared memory where the returned data is located.| 2713 2714**Returns** 2715 2716Execution 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). 2717 2718 2719### OH_NNTensor_GetTensorDesc() 2720 2721``` 2722NN_TensorDesc *OH_NNTensor_GetTensorDesc (const NN_Tensor *tensor) 2723``` 2724 2725**Description** 2726 2727Obtains an [NN_TensorDesc](#nn_tensordesc) instance of [NN_Tensor](#nn_tensor). 2728 2729You 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. 2730 2731You 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. 2732 2733If the **tensor** pointer is null, a null pointer is returned. 2734 2735**Since**: 11 2736 2737**Parameters** 2738 2739| Name| Description| 2740| -------- | -------- | 2741| tensor | Pointer to the [NN_Tensor](#nn_tensor) instance.| 2742 2743**Returns** 2744 2745Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 2746 2747 2748### OH_NNTensorDesc_Create() 2749 2750``` 2751NN_TensorDesc *OH_NNTensorDesc_Create () 2752``` 2753 2754**Description** 2755 2756Creates an [NN_TensorDesc](#nn_tensordesc) instance. 2757 2758[NN_TensorDesc](#nn_tensordesc) describes various tensor attributes, such as the name, data type, shape, and format. 2759 2760You can create an [NN_Tensor](#nn_tensor) instance based on the input [NNN_TensorDesc](#nn_tensordesc) instance by calling the following APIs: 2761 2762[OH_NNTensor_Create](#oh_nntensor_create) 2763 2764[OH_NNTensor_CreateWithSize](#oh_nntensor_createwithsize) 2765 2766[OH_NNTensor_CreateWithFd](#oh_nntensor_createwithfd) 2767 2768Note: 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). 2769 2770**Since**: 11 2771 2772**Returns** 2773 2774Pointer to the [NN_TensorDesc](#nn_tensordesc) instance. If the operation fails, **NULL** is returned. 2775 2776 2777### OH_NNTensorDesc_Destroy() 2778 2779``` 2780OH_NN_ReturnCode OH_NNTensorDesc_Destroy (NN_TensorDesc **tensorDesc) 2781``` 2782 2783**Description** 2784 2785Releases an [NN_TensorDesc](#nn_tensordesc) instance. 2786 2787If the [NN_TensorDesc](#nn_tensordesc) instance is no longer needed, call this API to destroy it. Otherwise, memory leakage occurs. 2788 2789If **tensorDesc** or **\*tensorDesc** is a null pointer, an error code is returned but the object will not be destroyed. 2790 2791**Since**: 11 2792 2793**Parameters** 2794 2795| Name| Description| 2796| -------- | -------- | 2797| tensorDesc | Level-2 pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2798 2799**Returns** 2800 2801Execution 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). 2802 2803 2804### OH_NNTensorDesc_GetByteSize() 2805 2806``` 2807OH_NN_ReturnCode OH_NNTensorDesc_GetByteSize (const NN_TensorDesc *tensorDesc, size_t *byteSize ) 2808``` 2809 2810**Description** 2811 2812Obtains 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. 2813 2814The 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. 2815 2816If the tensor shape is dynamically variable, this API returns an error code and **byteSize** is **0**. 2817 2818To obtain the number of elements in the tensor data, call [OH_NNTensorDesc_GetElementCount](#oh_nntensordesc_getelementcount). 2819 2820If **tensorDesc** or **byteSize** is a null pointer, an error code is returned. 2821 2822**Since**: 11 2823 2824**Parameters** 2825 2826| Name| Description| 2827| -------- | -------- | 2828| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2829| byteSize | Size of the returned data, in bytes.| 2830 2831**Returns** 2832 2833Execution 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). 2834 2835 2836### OH_NNTensorDesc_GetDataType() 2837 2838``` 2839OH_NN_ReturnCode OH_NNTensorDesc_GetDataType (const NN_TensorDesc *tensorDesc, OH_NN_DataType *dataType ) 2840``` 2841 2842**Description** 2843 2844Obtains the data type of an [NN_TensorDesc](#nn_tensordesc) instance. 2845 2846You can use this API to obtain the data type of a specified [NN_TensorDesc](#nn_tensordesc) instance. 2847 2848If **tensorDesc** or **dataType** is a null pointer, an error code is returned. 2849 2850**Since**: 11 2851 2852**Parameters** 2853 2854| Name| Description| 2855| -------- | -------- | 2856| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2857| dataType | Tensor data type.| 2858 2859**Returns** 2860 2861Execution 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). 2862 2863 2864### OH_NNTensorDesc_GetElementCount() 2865 2866``` 2867OH_NN_ReturnCode OH_NNTensorDesc_GetElementCount (const NN_TensorDesc *tensorDesc, size_t *elementCount ) 2868``` 2869 2870**Description** 2871 2872Obtains the number of elements in an [NN_TensorDesc](#nn_tensordesc) instance. 2873 2874You 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). 2875 2876If the tensor shape is dynamically variable, this API returns an error code and **elementCount** is **0**. 2877 2878If **tensorDesc** or **elementCount** is a null pointer, an error code is returned. 2879 2880**Since**: 11 2881 2882**Parameters** 2883 2884| Name| Description| 2885| -------- | -------- | 2886| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2887| elementCount | Number of elements.| 2888 2889**Returns** 2890 2891Execution 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). 2892 2893 2894### OH_NNTensorDesc_GetFormat() 2895 2896``` 2897OH_NN_ReturnCode OH_NNTensorDesc_GetFormat (const NN_TensorDesc *tensorDesc, OH_NN_Format *format ) 2898``` 2899 2900**Description** 2901 2902Obtains the data format of an [NN_TensorDesc](#nn_tensordesc) instance. 2903 2904You can use this API to obtain the data format, that is, [OH_NN_Format](#oh_nn_format, of the specified [NN_TensorDesc](#nn_tensordesc) instance. 2905 2906If **tensorDesc** or **format** is a null pointer, an error code is returned. 2907 2908**Since**: 11 2909 2910**Parameters** 2911 2912| Name| Description| 2913| -------- | -------- | 2914| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2915| format | Tensor data format.| 2916 2917**Returns** 2918 2919Execution 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). 2920 2921 2922### OH_NNTensorDesc_GetName() 2923 2924``` 2925OH_NN_ReturnCode OH_NNTensorDesc_GetName (const NN_TensorDesc *tensorDesc, const char **name ) 2926``` 2927 2928**Description** 2929 2930Obtains the name of an [NN_TensorDesc](#nn_tensordesc) instance. 2931 2932You 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**. 2933 2934If **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**. 2935 2936You do not need to release the memory of **name**. When **tensorDesc** is destroyed, it is automatically released. 2937 2938**Since**: 11 2939 2940**Parameters** 2941 2942| Name| Description| 2943| -------- | -------- | 2944| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2945| name | Tensor name.| 2946 2947**Returns** 2948 2949Execution 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). 2950 2951 2952### OH_NNTensorDesc_GetShape() 2953 2954``` 2955OH_NN_ReturnCode OH_NNTensorDesc_GetShape (const NN_TensorDesc *tensorDesc, int32_t **shape, size_t *shapeLength ) 2956``` 2957 2958**Description** 2959 2960Obtains the shape of an [NN_TensorDesc](#nn_tensordesc) instance. 2961 2962You can use this API to obtain the shape of the specified [NN_TensorDesc](#nn_tensordesc) instance. 2963 2964If **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**. 2965 2966You do not need to release the memory of **shape**. When **tensorDesc** is destroyed, it is automatically released. 2967 2968**Since**: 11 2969 2970**Parameters** 2971 2972| Name| Description| 2973| -------- | -------- | 2974| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 2975| shape | List of tensor shapes.| 2976| shapeLength | Length of the list of tensor shapes.| 2977 2978**Returns** 2979 2980Execution 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). 2981 2982 2983### OH_NNTensorDesc_SetDataType() 2984 2985``` 2986OH_NN_ReturnCode OH_NNTensorDesc_SetDataType (NN_TensorDesc *tensorDesc, OH_NN_DataType dataType ) 2987``` 2988 2989**Description** 2990 2991Sets the data type of an [NN_TensorDesc](#nn_tensordesc) instance. 2992 2993After an [NN_TensorDesc](#nn_tensordesc) instance is created, call this API to set the tensor data type. 2994 2995If **tensorDesc** is a null pointer, an error code is returned. 2996 2997**Since**: 11 2998 2999**Parameters** 3000 3001| Name| Description| 3002| -------- | -------- | 3003| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 3004| dataType | Tensor data type to be set.| 3005 3006**Returns** 3007 3008Execution 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). 3009 3010 3011### OH_NNTensorDesc_SetFormat() 3012 3013``` 3014OH_NN_ReturnCode OH_NNTensorDesc_SetFormat (NN_TensorDesc *tensorDesc, OH_NN_Format format ) 3015``` 3016 3017**Description** 3018 3019Sets the data format of an [NN_TensorDesc](#nn_tensordesc) instance. 3020 3021After an [NN_TensorDesc](#nn_tensordesc) instance is created, call this API to set the data format of the tensor. 3022 3023If **tensorDesc** is a null pointer, an error code is returned. 3024 3025**Since**: 11 3026 3027**Parameters** 3028 3029| Name| Description| 3030| -------- | -------- | 3031| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 3032| format | Tensor data format to be set.| 3033 3034**Returns** 3035 3036Execution 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). 3037 3038 3039### OH_NNTensorDesc_SetName() 3040 3041``` 3042OH_NN_ReturnCode OH_NNTensorDesc_SetName (NN_TensorDesc *tensorDesc, const char *name ) 3043``` 3044 3045**Description** 3046 3047Sets the name of an [NN_TensorDesc](#nn_tensordesc) instance. 3048 3049After 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**. 3050 3051If **tensorDesc** or **name** is a null pointer, an error code is returned. 3052 3053**Since**: 11 3054 3055**Parameters** 3056 3057| Name| Description| 3058| -------- | -------- | 3059| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 3060| name | Name of the tensor to be set.| 3061 3062**Returns** 3063 3064Execution 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). 3065 3066 3067### OH_NNTensorDesc_SetShape() 3068 3069``` 3070OH_NN_ReturnCode OH_NNTensorDesc_SetShape (NN_TensorDesc *tensorDesc, const int32_t *shape, size_t shapeLength ) 3071``` 3072 3073**Description** 3074 3075Sets the data shape of an [NN_TensorDesc](#nn_tensordesc) instance. 3076 3077After an [NN_TensorDesc](#nn_tensordesc) instance is created, call this API to set the tensor shape. 3078 3079If **tensorDesc** or **shape** is a null pointer or **shapeLength** is **0**, an error code is returned. 3080 3081**Since**: 11 3082 3083**Parameters** 3084 3085| Name| Description| 3086| -------- | -------- | 3087| tensorDesc | Pointer to the [NN_TensorDesc](#nn_tensordesc) instance.| 3088| shape | List of tensor shapes to be set.| 3089| shapeLength | Length of the list of tensor shapes.| 3090 3091**Returns** 3092 3093Execution 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). 3094