neural_network_core.h
概述
Neural Network Core模块接口定义,AI推理框架使用Neural Network Core提供的Native接口,完成模型编译,并在加速硬件上执行推理和计算。
注意: Neural Network Core的接口目前均不支持多线程并发调用.
引用文件: <neural_network_runtime/neural_network_core.h>
库: libneural_network_core.so
系统能力: @Syscap SystemCapability.Ai.NeuralNetworkRuntime
起始版本: 11
相关模块: NeuralNeworkRuntime
汇总
函数
名称 | 描述 |
---|---|
*OH_NNCompilation_Construct (const OH_NNModel *model) | 创建OH_NNCompilation类型的编译实例。 |
*OH_NNCompilation_ConstructWithOfflineModelFile (const char *modelPath) | 基于离线模型文件创建编译实例。 |
*OH_NNCompilation_ConstructWithOfflineModelBuffer (const void *modelBuffer, size_t modelSize) | 基于离线模型文件内存创建编译实例。 |
*OH_NNCompilation_ConstructForCache () | 创建一个空的编译实例,以便稍后从模型缓存中恢复。 |
OH_NNCompilation_ExportCacheToBuffer (OH_NNCompilation *compilation, const void *buffer, size_t length, size_t *modelSize) | 将模型缓存写入到指定内存区域。 |
OH_NNCompilation_ImportCacheFromBuffer (OH_NNCompilation *compilation, const void *buffer, size_t modelSize) | 从指定内存区域读取模型缓存。 |
OH_NNCompilation_AddExtensionConfig (OH_NNCompilation *compilation, const char *configName, const void *configValue, const size_t configValueSize) | 为自定义硬件属性添加扩展配置。 |
OH_NNCompilation_SetDevice (OH_NNCompilation *compilation, size_t deviceID) | 指定模型编译和计算的硬件。 |
OH_NNCompilation_SetCache (OH_NNCompilation *compilation, const char *cachePath, uint32_t version) | 设置编译模型的缓存目录和版本。 |
OH_NNCompilation_SetPerformanceMode (OH_NNCompilation *compilation, OH_NN_PerformanceMode performanceMode) | 设置模型计算的性能模式。 |
OH_NNCompilation_SetPriority (OH_NNCompilation *compilation, OH_NN_Priority priority) | 设置模型计算的优先级。 |
OH_NNCompilation_EnableFloat16 (OH_NNCompilation *compilation, bool enableFloat16) | 是否以float16的浮点数精度计算。 |
OH_NNCompilation_Build (OH_NNCompilation *compilation) | 执行模型编译。 |
OH_NNCompilation_Destroy (OH_NNCompilation **compilation) | 销毁Compilation实例。 |
*OH_NNTensorDesc_Create () | 创建一个NN_TensorDesc实例。 |
OH_NNTensorDesc_Destroy (NN_TensorDesc **tensorDesc) | 释放一个NN_TensorDesc实例。 |
OH_NNTensorDesc_SetName (NN_TensorDesc *tensorDesc, const char *name) | 设置NN_TensorDesc的名称。 |
OH_NNTensorDesc_GetName (const NN_TensorDesc *tensorDesc, const char **name) | 获取NN_TensorDesc的名称。 |
OH_NNTensorDesc_SetDataType (NN_TensorDesc *tensorDesc, OH_NN_DataType dataType) | 设置NN_TensorDesc的数据类型。 |
OH_NNTensorDesc_GetDataType (const NN_TensorDesc *tensorDesc, OH_NN_DataType *dataType) | 获取NN_TensorDesc的数据类型。 |
OH_NNTensorDesc_SetShape (NN_TensorDesc *tensorDesc, const int32_t *shape, size_t shapeLength) | 设置NN_TensorDesc的数据形状。 |
OH_NNTensorDesc_GetShape (const NN_TensorDesc *tensorDesc, int32_t **shape, size_t *shapeLength) | 获取NN_TensorDesc的形状。 |
OH_NNTensorDesc_SetFormat (NN_TensorDesc *tensorDesc, OH_NN_Format format) | 设置NN_TensorDesc的数据布局。 |
OH_NNTensorDesc_GetFormat (const NN_TensorDesc *tensorDesc, OH_NN_Format *format) | 获取NN_TensorDesc的数据布局。 |
OH_NNTensorDesc_GetElementCount (const NN_TensorDesc *tensorDesc, size_t *elementCount) | 获取NN_TensorDesc的元素个数。 |
OH_NNTensorDesc_GetByteSize (const NN_TensorDesc *tensorDesc, size_t *byteSize) | 获取基于NN_TensorDesc的形状和数据类型计算的数据占用字节数。 |
*OH_NNTensor_Create (size_t deviceID, NN_TensorDesc *tensorDesc) | 从NN_TensorDesc创建一个NN_Tensor实例。 |
*OH_NNTensor_CreateWithSize (size_t deviceID, NN_TensorDesc *tensorDesc, size_t size) | 按照指定内存大小和NN_TensorDesc创建NN_Tensor实例。 |
*OH_NNTensor_CreateWithFd (size_t deviceID, NN_TensorDesc *tensorDesc, int fd, size_t size, size_t offset) | 按照指定共享内存的文件描述符和NN_TensorDesc创建{@Link NN_Tensor}实例。 |
OH_NNTensor_Destroy (NN_Tensor **tensor) | 销毁一个NN_Tensor实例。 |
*OH_NNTensor_GetTensorDesc (const NN_Tensor *tensor) | 获取NN_Tensor的NN_TensorDesc实例。 |
*OH_NNTensor_GetDataBuffer (const NN_Tensor *tensor) | 获取NN_Tensor数据的内存地址。 |
OH_NNTensor_GetFd (const NN_Tensor *tensor, int *fd) | 获取NN_Tensor数据所在共享内存的文件描述符。 |
OH_NNTensor_GetSize (const NN_Tensor *tensor, size_t *size) | 获取NN_Tensor数据所在共享内存的大小。 |
OH_NNTensor_GetOffset (const NN_Tensor *tensor, size_t *offset) | 获取NN_Tensor数据所在共享内存上的偏移量。 |
*OH_NNExecutor_Construct (OH_NNCompilation *compilation) | 创建OH_NNExecutor执行器实例。 |
OH_NNExecutor_GetOutputShape (OH_NNExecutor *executor, uint32_t outputIndex, int32_t **shape, uint32_t *shapeLength) | 获取输出张量的维度信息。 |
OH_NNExecutor_Destroy (OH_NNExecutor **executor) | 销毁执行器实例,释放执行器占用的内存。 |
OH_NNExecutor_GetInputCount (const OH_NNExecutor *executor, size_t *inputCount) | 获取输入张量的数量。 |
OH_NNExecutor_GetOutputCount (const OH_NNExecutor *executor, size_t *outputCount) | 获取输出张量的数量。 |
*OH_NNExecutor_CreateInputTensorDesc (const OH_NNExecutor *executor, size_t index) | 由指定索引值创建一个输入张量的描述。 |
*OH_NNExecutor_CreateOutputTensorDesc (const OH_NNExecutor *executor, size_t index) | 由指定索引值创建一个输出张量的描述。 |
OH_NNExecutor_GetInputDimRange (const OH_NNExecutor *executor, size_t index, size_t **minInputDims, size_t **maxInputDims, size_t *shapeLength) | 获取所有输入张量的维度范围。 |
OH_NNExecutor_SetOnRunDone (OH_NNExecutor *executor, NN_OnRunDone onRunDone) | 设置异步推理结束后的回调处理函数。 |
OH_NNExecutor_SetOnServiceDied (OH_NNExecutor *executor, NN_OnServiceDied onServiceDied) | 设置异步推理执行期间设备驱动服务突然死亡时的回调处理函数。 |
OH_NNExecutor_RunSync (OH_NNExecutor *executor, NN_Tensor *inputTensor[], size_t inputCount, NN_Tensor *outputTensor[], size_t outputCount) | 执行同步推理。 |
OH_NNExecutor_RunAsync (OH_NNExecutor *executor, NN_Tensor *inputTensor[], size_t inputCount, NN_Tensor *outputTensor[], size_t outputCount, int32_t timeout, void *userData) | 执行异步推理。 |
OH_NNDevice_GetAllDevicesID (const size_t **allDevicesID, uint32_t *deviceCount) | 获取对接到 Neural Network Runtime 的硬件ID。 |
OH_NNDevice_GetName (size_t deviceID, const char **name) | 获取指定硬件的名称。 |
OH_NNDevice_GetType (size_t deviceID, OH_NN_DeviceType *deviceType) | 获取指定硬件的类别信息。 |