harmony 鸿蒙neural_network_runtime.h

  • 2025-06-16
  • 浏览 (2)

neural_network_runtime.h

概述

Neural Network Runtime模块接口定义,AI推理框架使用Neural Network Runtime提供的Native接口,完成模型构建。

注意:Neural Network Runtime的接口目前均不支持多线程并发调用。

引用文件:<neural_network_runtime/neural_network_runtime.h>

库: libneural_network_runtime.so

系统能力: SystemCapability.Ai.NeuralNetworkRuntime

起始版本: 9

相关模块:NeuralNetworkRuntime

汇总

函数

名称 描述
NN_QuantParam * OH_NNQuantParam_Create () 创建一个NN_QuantParam量化参数实例。
OH_NN_ReturnCodeOH_NNQuantParam_SetScales (NN_QuantParam *quantParams, const double *scales, size_t quantCount) 设置NN_QuantParam的缩放系数。
OH_NN_ReturnCodeOH_NNQuantParam_SetZeroPoints (NN_QuantParam *quantParams, const int32_t *zeroPoints, size_t quantCount) 设置NN_QuantParam的零点。
OH_NN_ReturnCodeOH_NNQuantParam_SetNumBits (NN_QuantParam *quantParams, const uint32_t *numBits, size_t quantCount) 设置NN_QuantParam的量化位数。
OH_NN_ReturnCodeOH_NNQuantParam_Destroy (NN_QuantParam **quantParams) 销毁NN_QuantParam实例。
OH_NNModel * OH_NNModel_Construct (void) 创建OH_NNModel类型的模型实例,搭配OH_NNModel模块提供的其他接口,完成模型实例的构造。
OH_NN_ReturnCodeOH_NNModel_AddTensorToModel (OH_NNModel *model, const NN_TensorDesc *tensorDesc) 向模型实例中添加张量。
OH_NN_ReturnCodeOH_NNModel_SetTensorData (OH_NNModel *model, uint32_t index, const void *dataBuffer, size_t length) 设置张量的数值。
OH_NN_ReturnCodeOH_NNModel_SetTensorQuantParams (OH_NNModel *model, uint32_t index, NN_QuantParam *quantParam) 设置张量的量化参数,参考NN_QuantParam
OH_NN_ReturnCodeOH_NNModel_SetTensorType (OH_NNModel *model, uint32_t index, OH_NN_TensorType tensorType) 设置张量的类型,参考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) 向模型实例中添加算子。
OH_NN_ReturnCodeOH_NNModel_SpecifyInputsAndOutputs (OH_NNModel *model, const OH_NN_UInt32Array *inputIndices, const OH_NN_UInt32Array *outputIndices) 指定模型的输入和输出张量的索引值。
OH_NN_ReturnCodeOH_NNModel_Finish (OH_NNModel *model) 完成模型构图。
void OH_NNModel_Destroy (OH_NNModel **model) 销毁模型实例。
OH_NN_ReturnCodeOH_NNModel_GetAvailableOperations (OH_NNModel *model, size_t deviceID, const bool **isSupported, uint32_t *opCount) 查询硬件对模型内所有算子的支持情况,通过布尔值序列指示支持情况。
OH_NN_ReturnCodeOH_NNModel_AddTensor (OH_NNModel *model, const OH_NN_Tensor *tensor) 向模型实例中添加张量。
OH_NN_ReturnCodeOH_NNExecutor_SetInput (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const void *dataBuffer, size_t length) 设置模型单个输入的数据。
OH_NN_ReturnCodeOH_NNExecutor_SetOutput (OH_NNExecutor *executor, uint32_t outputIndex, void *dataBuffer, size_t length) 设置模型单个输出的内存。
OH_NN_ReturnCodeOH_NNExecutor_Run (OH_NNExecutor *executor) 执行推理。
OH_NN_Memory * OH_NNExecutor_AllocateInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, size_t length) 在硬件上为单个输入申请共享内存。
OH_NN_Memory * OH_NNExecutor_AllocateOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, size_t length) 在硬件上为单个输出申请共享内存。
void OH_NNExecutor_DestroyInputMemory (OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory) 释放OH_NN_Memory实例指向的输入内存。
void OH_NNExecutor_DestroyOutputMemory (OH_NNExecutor *executor, uint32_t outputIndex, OH_NN_Memory **memory) 释放OH_NN_Memory实例指向的输出内存。
OH_NN_ReturnCodeOH_NNExecutor_SetInputWithMemory (OH_NNExecutor *executor, uint32_t inputIndex, const OH_NN_Tensor *tensor, const OH_NN_Memory *memory) OH_NN_Memory实例指向的硬件共享内存,并指定为单个输入使用的内存。
OH_NN_ReturnCodeOH_NNExecutor_SetOutputWithMemory (OH_NNExecutor *executor, uint32_t outputIndex, const OH_NN_Memory *memory) OH_NN_Memory实例指向的硬件共享内存,并指定为单个输出使用的内存。

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Neural Network Runtime Kit(Neural Network运行时服务)

harmony 鸿蒙_neural_network_runtime

harmony 鸿蒙_neural_nework_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  赞