harmony 鸿蒙neural_network_runtime.h

  • 2025-06-12
  • 浏览 (4)

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.h>

Library: libneural_network_runtime.so

System capability: \@Syscap SystemCapability.Ai.NeuralNetworkRuntime

Since: 9

Related module: NeuralNeworkRuntime

Summary

Functions

Name Description
NN_QuantParam * OH_NNQuantParam_Create () Creates an NN_QuantParam instance.
OH_NN_ReturnCodeOH_NNQuantParam_SetScales (NN_QuantParam *quantParams, const double *scales, size_t quantCount) Sets the scaling coefficient for an NN_QuantParam instance.
OH_NN_ReturnCodeOH_NNQuantParam_SetZeroPoints (NN_QuantParam *quantParams, const int32_t *zeroPoints, size_t quantCount) Sets the zero point for an NN_QuantParam instance.
OH_NN_ReturnCodeOH_NNQuantParam_SetNumBits (NN_QuantParam *quantParams, const uint32_t *numBits, size_t quantCount) Sets the number of quantization bits for an NN_QuantParam instance.
OH_NN_ReturnCodeOH_NNQuantParam_Destroy (NN_QuantParam **quantParams) Destroys an NN_QuantParam instance.
OH_NNModel * OH_NNModel_Construct (void) Creates a model instance of the NN_QuantParam type and constructs a model instance by using the APIs provided by OH_NNModel.
OH_NN_ReturnCodeOH_NNModel_AddTensorToModel (OH_NNModel *model, const NN_TensorDesc *tensorDesc) Adds a tensor to a model instance.
OH_NN_ReturnCodeOH_NNModel_SetTensorData (OH_NNModel *model, uint32_t index, const void *dataBuffer, size_t length) Sets the tensor value.
OH_NN_ReturnCodeOH_NNModel_SetTensorQuantParams (OH_NNModel *model, uint32_t index, NN_QuantParam *quantParam) Sets the quantization parameters of a tensor. For details, see NN_QuantParam.
OH_NN_ReturnCodeOH_NNModel_SetTensorType (OH_NNModel *model, uint32_t index, OH_NN_TensorType tensorType) Sets the tensor type. For details, see OH_NN_TensorType.
OH_NN_ReturnCodeOH_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_NN_ReturnCodeOH_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_NN_ReturnCodeOH_NNModel_Finish (OH_NNModel *model) Completes model composition.
void OH_NNModel_Destroy (OH_NNModel **model) Destroys a model instance.
OH_NN_ReturnCodeOH_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_NN_ReturnCodeOH_NNModel_AddTensor (OH_NNModel *model, const OH_NN_Tensor *tensor) Adds a tensor to a model instance.
OH_NN_ReturnCodeOH_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_NN_ReturnCodeOH_NNExecutor_SetOutput (OH_NNExecutor *executor, uint32_t outputIndex, void *dataBuffer, size_t length) Sets the memory for a single model output.
OH_NN_ReturnCodeOH_NNExecutor_Run (OH_NNExecutor *executor) Executes model inference.
OH_NN_Memory * 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_NN_Memory * OH_NNExecutor_AllocateOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, size_t length) Applies for shared memory for a single model output on the device.
void OH_NNExecutor_DestroyInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory) Releases the input memory pointed by the OH_NN_Memory instance.
void 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_NN_ReturnCodeOH_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_NN_ReturnCodeOH_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.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Neural Network Runtime Kit

harmony 鸿蒙_neural_network_runtime

harmony 鸿蒙OH_NN_Memory

harmony 鸿蒙OH_NN_QuantParam

harmony 鸿蒙OH_NN_Tensor

harmony 鸿蒙OH_NN_UInt32Array

harmony 鸿蒙neural_network_core.h

harmony 鸿蒙neural_network_runtime_type.h

0  赞