neural_network_runtime.h

Overview

Defines APIs for Neural Network Runtime. The AI inference framework uses the native APIs provided by the Neural Network Runtime to construct and build models.

NOTE
Currently, the APIs of Neural Network Runtime do not support multi-thread calling.

File to include: <neural_network_runtime/neural_network_runtime_type.h>

Library: libneural_network_runtime.so

System capability: @Syscap SystemCapability.Ai.NeuralNetworkRuntime

Since: 9

Related module: NeuralnetworkRuntime

Summary

Functions

Name Description
*OH_NNQuantParam_Create () Creates an NN_QuantParam instance.
OH_NNQuantParam_SetScales (NN_QuantParam *quantParams, const double *scales, size_t quantCount) Sets the scaling coefficient for an NN_QuantParam instance.
OH_NNQuantParam_SetZeroPoints (NN_QuantParam *quantParams, const int32_t *zeroPoints, size_t quantCount) Sets the zero point for an NN_QuantParam instance.
OH_NNQuantParam_SetNumBits (NN_QuantParam *quantParams, const uint32_t *numBits, size_t quantCount) Sets the number of quantization bits for an NN_QuantParam instance.
OH_NNQuantParam_Destroy (NN_QuantParam **quantParams) Destroys an NN_QuantParam instance.
*OH_NNModel_Construct (void) Creates a model instance of the OH_NNModel type and constructs a model instance by using the APIs provided by OH_NNModel.
OH_NNModel_AddTensorToModel (OH_NNModel *model, const NN_TensorDesc *tensorDesc) Adds a tensor to a model instance.
OH_NNModel_SetTensorData (OH_NNModel *model, uint32_t index, const void *dataBuffer, size_t length) Sets the tensor value.
OH_NNModel_SetTensorQuantParams (OH_NNModel *model, uint32_t index, NN_QuantParam *quantParam) Sets the quantization parameters of a tensor. For details, see NN_QuantParam.
OH_NNModel_SetTensorType (OH_NNModel *model, uint32_t index, OH_NN_TensorType tensorType) Sets the tensor type. For details, see OH_NN_TensorType.
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) Adds an operator to a model instance.
OH_NNModel_SpecifyInputsAndOutputs (OH_NNModel *model, const OH_NN_UInt32Array *inputIndices, const OH_NN_UInt32Array *outputIndices) Sets an index value for the input and output tensors of a model.
OH_NNModel_Finish (OH_NNModel *model) Completes model composition.
OH_NNModel_Destroy (OH_NNModel **model) Destroys a model instance.
OH_NNModel_GetAvailableOperations (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.
OH_NNModel_AddTensor (OH_NNModel *model, const OH_NN_Tensor *tensor) Adds a tensor to a model instance.
OH_NNExecutor_SetInput (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const void *dataBuffer, size_t length) Sets the data for a single model input.
OH_NNExecutor_SetOutput (OH_NNExecutor *executor, uint32_t outputIndex, void *dataBuffer, size_t length) Sets the memory for a single model output.
OH_NNExecutor_Run (OH_NNExecutor *executor) Executes model inference.
*OH_NNExecutor_AllocateInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, size_t length) Applies for shared memory for a single model input on the device.
*OH_NNExecutor_AllocateOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, size_t length) Applies for shared memory for a single model output on the device.
OH_NNExecutor_DestroyInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory) Releases the input memory pointed by the OH_NN_Memory instance.
OH_NNExecutor_DestroyOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, OH_NN_Memory **memory) Releases the output memory pointed by the OH_NN_Memory instance.
OH_NNExecutor_SetInputWithMemory (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const OH_NN_Memory *memory) Specifies the shared memory pointed by the OH_NN_Memory instance for a single model input.
OH_NNExecutor_SetOutputWithMemory (OH_NNExecutor *executor, uint32_t outputIndex, const OH_NN_Memory *memory) Specifies the shared memory pointed by the OH_NN_Memory instance for a single model output.