harmony 鸿蒙MindSpore

2025-06-12 浏览 (1)

MindSpore

Overview

Provides APIs related to MindSpore Lite model inference. The APIs in this module are non-thread-safe.

Since: 9

Summary

Files

NameDescription
context.hProvides Context APIs for configuring runtime information.
File to include: <mindspore/context.h>
Library: libmindspore_lite_ndk.so
data_type.hDeclares tensor data types.
File to include: <mindspore/data_type.h>
Library: libmindspore_lite_ndk.so
format.hDeclares tensor data formats.
File to include: <mindspore/format.h>
Library: libmindspore_lite_ndk.so
model.hProvides model-related APIs for model creation and inference.
File to include: <mindspore/model.h>
Library: libmindspore_lite_ndk.so
status.hProvides the status codes of MindSpore Lite.
File to include: <mindspore/status.h>
Library: libmindspore_lite_ndk.so
tensor.hProvides APIs for creating and modifying tensor information.
File to include: <mindspore/tensor.h>
Library: libmindspore_lite_ndk.so
types.hProvides the model file types and device types supported by MindSpore Lite.
File to include: <mindspore/types.h>
Library: libmindspore_lite_ndk.so

Structs

NameDescription
OH_AI_TensorHandleArrayDefines the tensor array structure, which is used to store the tensor array pointer and tensor array length.
OH_AI_ShapeInfoDefines dimension information. The maximum dimension is set by OH_AI_MAX_SHAPE_NUM.
OH_AI_CallBackParamDefines the operator information passed in a callback.

Macro Definition

NameDescription
OH_AI_MAX_SHAPE_NUM 32Defines dimension information. The maximum dimension is set by MS_MAX_SHAPE_NUM.

Types

NameDescription
OH_AI_ContextHandleDefines the pointer to the MindSpore context.
OH_AI_DeviceInfoHandleDefines the pointer to the MindSpore device information.
OH_AI_DataTypeDeclares data types supported by MSTensor.
OH_AI_FormatDeclares data formats supported by MSTensor.
OH_AI_ModelHandleDefines the pointer to a model object.
OH_AI_TrainCfgHandleDefines the pointer to a training configuration object.
OH_AI_TensorHandleArrayDefines the tensor array structure, which is used to store the tensor array pointer and tensor array length.
OH_AI_ShapeInfoDefines dimension information. The maximum dimension is set by OH_AI_MAX_SHAPE_NUM.
OH_AI_CallBackParamDefines the operator information passed in a callback.
OH_AI_KernelCallBack) (const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs, const OH_AI_CallBackParam kernel_Info)Defines the pointer to a callback.
OH_AI_StatusDefines MindSpore status codes.
OH_AI_TensorHandleDefines the handle of a tensor object.
OH_AI_ModelTypeDefines model file types.
OH_AI_DeviceTypeDefines the supported device types.
OH_AI_NNRTDeviceTypeDefines NNRt device types.
OH_AI_PerformanceModeDefines performance modes of the NNRt device.
OH_AI_PriorityDefines NNRt inference task priorities.
OH_AI_OptimizationLevelDefines training optimization levels.
OH_AI_QuantizationTypeDefines quantization types.
NNRTDeviceDescDefines NNRt device information, including the device ID and device name.
OH_AI_AllocatorHandleDefines the handle of the memory allocator.

Enums

NameDescription
OH_AI_DataType {
OH_AI_DATATYPE_UNKNOWN = 0, OH_AI_DATATYPE_OBJECTTYPE_STRING = 12, OH_AI_DATATYPE_OBJECTTYPE_LIST = 13, OH_AI_DATATYPE_OBJECTTYPE_TUPLE = 14,
OH_AI_DATATYPE_OBJECTTYPE_TENSOR = 17, OH_AI_DATATYPE_NUMBERTYPE_BEGIN = 29, OH_AI_DATATYPE_NUMBERTYPE_BOOL = 30, OH_AI_DATATYPE_NUMBERTYPE_INT8 = 32,
OH_AI_DATATYPE_NUMBERTYPE_INT16 = 33, OH_AI_DATATYPE_NUMBERTYPE_INT32 = 34, OH_AI_DATATYPE_NUMBERTYPE_INT64 = 35, OH_AI_DATATYPE_NUMBERTYPE_UINT8 = 37,
OH_AI_DATATYPE_NUMBERTYPE_UINT16 = 38, OH_AI_DATATYPE_NUMBERTYPE_UINT32 = 39, OH_AI_DATATYPE_NUMBERTYPE_UINT64 = 40, OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 = 42,
OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 = 43, OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 = 44, OH_AI_DATATYPE_NUMBERTYPE_END = 46, OH_AI_DataTypeInvalid = INT32_MAX
}
Declares data types supported by MSTensor.
OH_AI_Format {
OH_AI_FORMAT_NCHW = 0, OH_AI_FORMAT_NHWC = 1, OH_AI_FORMAT_NHWC4 = 2, OH_AI_FORMAT_HWKC = 3,
OH_AI_FORMAT_HWCK = 4, OH_AI_FORMAT_KCHW = 5, OH_AI_FORMAT_CKHW = 6, OH_AI_FORMAT_KHWC = 7,
OH_AI_FORMAT_CHWK = 8, OH_AI_FORMAT_HW = 9, OH_AI_FORMAT_HW4 = 10, OH_AI_FORMAT_NC = 11,
OH_AI_FORMAT_NC4 = 12, OH_AI_FORMAT_NC4HW4 = 13, OH_AI_FORMAT_NCDHW = 15, OH_AI_FORMAT_NWC = 16,
OH_AI_FORMAT_NCW = 17
}
Declares data formats supported by MSTensor.
OH_AI_CompCode {
OH_AI_COMPCODE_CORE = 0x00000000u,
OH_AI_COMPCODE_MD = 0x10000000u,
OH_AI_COMPCODE_ME = 0x20000000u,
OH_AI_COMPCODE_MC = 0x30000000u,
OH_AI_COMPCODE_LITE = 0xF0000000u
}
Defines MindSpore component codes.
OH_AI_Status {
OH_AI_STATUS_SUCCESS = 0, OH_AI_STATUS_CORE_FAILED = OH_AI_COMPCODE_CORE |0x1, OH_AI_STATUS_LITE_ERROR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -1), OH_AI_STATUS_LITE_NULLPTR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -2),
OH_AI_STATUS_LITE_PARAM_INVALID = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -3), OH_AI_STATUS_LITE_NO_CHANGE = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -4), OH_AI_STATUS_LITE_SUCCESS_EXIT = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -5), OH_AI_STATUS_LITE_MEMORY_FAILED = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -6),
OH_AI_STATUS_LITE_NOT_SUPPORT = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -7), OH_AI_STATUS_LITE_THREADPOOL_ERROR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -8), OH_AI_STATUS_LITE_UNINITIALIZED_OBJ = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -9), OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -100),
OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR, OH_AI_STATUS_LITE_REENTRANT_ERROR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -102), OH_AI_STATUS_LITE_GRAPH_FILE_ERROR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -200), OH_AI_STATUS_LITE_NOT_FIND_OP = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -300),
OH_AI_STATUS_LITE_INVALID_OP_NAME = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -301), OH_AI_STATUS_LITE_INVALID_OP_ATTR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -302), OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE, OH_AI_STATUS_LITE_FORMAT_ERROR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -400),
OH_AI_STATUS_LITE_INFER_ERROR = OH_AI_COMPCODE_LITE |(0x0FFFFFFF & -500), OH_AI_STATUS_LITE_INFER_INVALID, OH_AI_STATUS_LITE_INPUT_PARAM_INVALID
}
Defines MindSpore status codes.
OH_AI_ModelType { OH_AI_MODELTYPE_MINDIR = 0, OH_AI_MODELTYPE_INVALID = 0xFFFFFFFF }Defines model file types.
OH_AI_DeviceType {
OH_AI_DEVICETYPE_CPU = 0, OH_AI_DEVICETYPE_GPU, OH_AI_DEVICETYPE_KIRIN_NPU, OH_AI_DEVICETYPE_NNRT = 60,
OH_AI_DEVICETYPE_INVALID = 100
}
Defines the supported device types.
OH_AI_NNRTDeviceType { OH_AI_NNRTDEVICE_OTHERS = 0, OH_AI_NNRTDEVICE_CPU = 1, OH_AI_NNRTDEVICE_GPU = 2, OH_AI_NNRTDEVICE_ACCELERATOR = 3 }Defines NNRt device types.
OH_AI_PerformanceMode {
OH_AI_PERFORMANCE_NONE = 0, OH_AI_PERFORMANCE_LOW = 1, OH_AI_PERFORMANCE_MEDIUM = 2, OH_AI_PERFORMANCE_HIGH = 3,
OH_AI_PERFORMANCE_EXTREME = 4
}
Defines performance modes of the NNRt device.
OH_AI_Priority { OH_AI_PRIORITY_NONE = 0, OH_AI_PRIORITY_LOW = 1, OH_AI_PRIORITY_MEDIUM = 2, OH_AI_PRIORITY_HIGH = 3 }Defines NNRt inference task priorities.
OH_AI_OptimizationLevel {
OH_AI_KO0 = 0, OH_AI_KO2 = 2, OH_AI_KO3 = 3, OH_AI_KAUTO = 4,
OH_AI_KOPTIMIZATIONTYPE = 0xFFFFFFFF
}
Defines training optimization levels.
OH_AI_QuantizationType { OH_AI_NO_QUANT = 0, OH_AI_WEIGHT_QUANT = 1, OH_AI_FULL_QUANT = 2, OH_AI_UNKNOWN_QUANT_TYPE = 0xFFFFFFFF }Defines quantization types.

Functions

NameDescription
OH_AI_ContextCreate ()Creates a context object. This API must be used together with OH_AI_ContextDestroy.
OH_AI_ContextDestroy (OH_AI_ContextHandle *context)Destroys a context object.
OH_AI_ContextSetThreadNum (OH_AI_ContextHandle context, int32_t thread_num)Sets the number of runtime threads.
OH_AI_ContextGetThreadNum (const OH_AI_ContextHandle context)Obtains the number of threads.
OH_AI_ContextSetThreadAffinityMode (OH_AI_ContextHandle context, int mode)Sets the affinity mode for binding runtime threads to CPU cores, which are classified into large, medium, and small cores based on the CPU frequency. You only need to bind the large or medium cores, but not small cores.
OH_AI_ContextGetThreadAffinityMode (const OH_AI_ContextHandle context)Obtains the affinity mode for binding runtime threads to CPU cores.
OH_AI_ContextSetThreadAffinityCoreList (OH_AI_ContextHandle context, const int32_t *core_list, size_t core_num)Sets the list of CPU cores bound to a runtime thread.
OH_AI_ContextGetThreadAffinityCoreList (const OH_AI_ContextHandle context, size_t *core_num)Obtains the list of bound CPU cores.
OH_AI_ContextSetEnableParallel (OH_AI_ContextHandle context, bool is_parallel)Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available.
OH_AI_ContextGetEnableParallel (const OH_AI_ContextHandle context)Checks whether parallelism between operators is supported.
OH_AI_ContextAddDeviceInfo (OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info)Attaches the custom device information to the inference context.
OH_AI_DeviceInfoCreate (OH_AI_DeviceType device_type)Creates a device information object.
OH_AI_DeviceInfoDestroy (OH_AI_DeviceInfoHandle *device_info)Destroys a device information object. Note: After the device information instance is added to the context, the caller does not need to destroy it manually.
OH_AI_DeviceInfoSetProvider (OH_AI_DeviceInfoHandle device_info, const char *provider)Sets the name of the provider.
OH_AI_DeviceInfoGetProvider (const OH_AI_DeviceInfoHandle device_info)Obtains the provider name.
OH_AI_DeviceInfoSetProviderDevice (OH_AI_DeviceInfoHandle device_info, const char *device)Sets the name of a provider device.
OH_AI_DeviceInfoGetProviderDevice (const OH_AI_DeviceInfoHandle device_info)Obtains the name of a provider device.
OH_AI_DeviceInfoGetDeviceType (const OH_AI_DeviceInfoHandle device_info)Obtains the device type.
OH_AI_DeviceInfoSetEnableFP16 (OH_AI_DeviceInfoHandle device_info, bool is_fp16)Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.
OH_AI_DeviceInfoGetEnableFP16 (const OH_AI_DeviceInfoHandle device_info)Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.
OH_AI_DeviceInfoSetFrequency (OH_AI_DeviceInfoHandle device_info, int frequency)Sets the NPU frequency type. This function is available only for NPU devices.
OH_AI_DeviceInfoGetFrequency (const OH_AI_DeviceInfoHandle device_info)Obtains the NPU frequency type. This function is available only for NPU devices.
OH_AI_GetAllNNRTDeviceDescs (size_t *num)Obtains the descriptions of all NNRt devices in the system.
OH_AI_GetElementOfNNRTDeviceDescs (NNRTDeviceDesc *descs, size_t index)Obtains the pointer to an element in the NNRt device description array.
OH_AI_DestroyAllNNRTDeviceDescs (NNRTDeviceDesc **desc)Destroys the NNRt device description array obtained by OH_AI_GetAllNNRTDeviceDescs.
OH_AI_GetDeviceIdFromNNRTDeviceDesc (const NNRtDeviceDesc *desc)Obtains the NNRt device ID from the specified NNRt device description. Note that this ID is valid only for NNRt devices.
OH_AI_GetNameFromNNRTDeviceDesc (const NNRTDeviceDesc *desc)Obtains the NNRt device name from the specified NNRt device description.
OH_AI_GetTypeFromNNRtDeviceDesc (const NNRTDeviceDesc *desc)Obtains the NNRt device type from the specified NNRt device description.
OH_AI_CreateNNRTDeviceInfoByName (const char *name)Searches for the NNRt device with the specified name and creates the NNRt device information based on the information about the first found NNRt device.
OH_AI_CreateNNRTDeviceInfoByType (OH_AI_NNRTDeviceType type)Searches for the NNRt device with the specified type and creates the NNRt device information based on the information about the first found NNRt device.
OH_AI_DeviceInfoSetDeviceId (OH_AI_DeviceInfoHandle device_info, size_t device_id)Sets the NNRt device ID. This function is available only for NNRt devices.
OH_AI_DeviceInfoGetDeviceId (const OH_AI_DeviceInfoHandle device_info)Obtains the NNRt device ID. This function is available only for NNRt devices.
OH_AI_DeviceInfoSetPerformanceMode (OH_AI_DeviceInfoHandle device_info, OH_AI_PerformanceMode mode)Sets the NNRt performance mode. This function is available only for NNRt devices.
OH_AI_DeviceInfoGetPerformanceMode (const OH_AI_DeviceInfoHandle device_info)Obtains the NNRt performance mode. This function is available only for NNRt devices.
OH_AI_DeviceInfoSetPriority (OH_AI_DeviceInfoHandle device_info, OH_AI_Priority priority)Sets the priority of an NNRt task. This function is available only for NNRt devices.
OH_AI_DeviceInfoGetPriority (const OH_AI_DeviceInfoHandle device_info)Obtains the priority of an NNRt task. This function is available only for NNRt devices.
OH_AI_DeviceInfoAddExtension (OH_AI_DeviceInfoHandle device_info, const char *name, const char *value, size_t value_size)Adds extended configuration in the form of key/value pairs to the device information. This function is available only for NNRt devices.
OH_AI_ModelCreate (void)Creates a model object.
OH_AI_ModelDestroy (OH_AI_ModelHandle *model)Destroys a model object.
OH_AI_ModelBuild (OH_AI_ModelHandle model, const void *model_data, size_t data_size, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context)Loads and builds a MindSpore model from the memory buffer.
OH_AI_ModelBuildFromFile (OH_AI_ModelHandle model, const char *model_path, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context)Loads and builds a MindSpore model from a model file.
OH_AI_ModelResize (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_ShapeInfo *shape_infos, size_t shape_info_num)Adjusts the input tensor shapes of a built model.
OH_AI_ModelPredict (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_TensorHandleArray *outputs, const OH_AI_KernelCallBack before, const OH_AI_KernelCallBack after)Performs model inference.
OH_AI_ModelGetInputs (const OH_AI_ModelHandle model)Obtains the input tensor array structure of a model.
OH_AI_ModelGetOutputs (const OH_AI_ModelHandle model)Obtains the output tensor array structure of a model.
OH_AI_ModelGetInputByTensorName (const OH_AI_ModelHandle model, const char *tensor_name)Obtains the input tensor of a model by tensor name.
OH_AI_ModelGetOutputByTensorName (const OH_AI_ModelHandle model, const char *tensor_name)Obtains the output tensor of a model by tensor name.
OH_AI_TrainCfgCreate ()Creates the pointer to the training configuration object. This API is used only for on-device training.
OH_AI_TrainCfgDestroy (OH_AI_TrainCfgHandle *train_cfg)Destroys the pointer to the training configuration object. This API is used only for on-device training.
OH_AI_TrainCfgGetLossName (OH_AI_TrainCfgHandle train_cfg, size_t *num)Obtains the list of loss functions, which are used only for on-device training.
OH_AI_TrainCfgSetLossName (OH_AI_TrainCfgHandle train_cfg, const char **loss_name, size_t num)Sets the list of loss functions, which are used only for on-device training.
OH_AI_TrainCfgGetOptimizationLevel (OH_AI_TrainCfgHandle train_cfg)Obtains the optimization level of the training configuration object. This API is used only for on-device training.
OH_AI_TrainCfgSetOptimizationLevel (OH_AI_TrainCfgHandle train_cfg, OH_AI_OptimizationLevel level)Sets the optimization level of the training configuration object. This API is used only for on-device training.
OH_AI_TrainModelBuild (OH_AI_ModelHandle model, const void *model_data, size_t data_size, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context, const OH_AI_TrainCfgHandle train_cfg)Loads a training model from the memory buffer and compiles the model to a state ready for running on the device. This API is used only for on-device training.
OH_AI_TrainModelBuildFromFile (OH_AI_ModelHandle model, const char *model_path, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context, const OH_AI_TrainCfgHandle train_cfg)Loads the training model from the specified path and compiles the model to a state ready for running on the device. This API is used only for on-device training.
OH_AI_RunStep (OH_AI_ModelHandle model, const OH_AI_KernelCallBack before, const OH_AI_KernelCallBack after)Defines a single-step training model. This API is used only for on-device training.
OH_AI_ModelSetLearningRate (OH_AI_ModelHandle model, float learning_rate)Sets the learning rate for model training. This API is used only for on-device training.
OH_AI_ModelGetLearningRate (OH_AI_ModelHandle model)Obtains the learning rate for model training. This API is used only for on-device training.
OH_AI_ModelGetWeights (OH_AI_ModelHandle model)Obtains all weight tensors of a model. This API is used only for on-device training.
OH_AI_ModelUpdateWeights (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray new_weights)Updates the weight tensors of a model. This API is used only for on-device training.
OH_AI_ModelGetTrainMode (OH_AI_ModelHandle model)Obtains the training mode.
OH_AI_ModelSetTrainMode (OH_AI_ModelHandle model, bool train)Sets the training mode. This API is used only for on-device training.
OH_AI_ModelSetupVirtualBatch (OH_AI_ModelHandle model, int virtual_batch_multiplier, float lr, float momentum)OH_AI_API OH_AI_Status
Sets the virtual batch for training. This API is used only for on-device training.
OH_AI_ExportModel (OH_AI_ModelHandle model, OH_AI_ModelType model_type, const char *model_file, OH_AI_QuantizationType quantization_type, bool export_inference_only, char **output_tensor_name, size_t num)Exports a training model. This API is used only for on-device training.
OH_AI_ExportModelBuffer (OH_AI_ModelHandle model, OH_AI_ModelType model_type, void *model_data, size_t *data_size, OH_AI_QuantizationType quantization_type, bool export_inference_only, char **output_tensor_name, size_t num)Exports the memory cache of the training model. This API is used only for on-device training.
OH_AI_ExportWeightsCollaborateWithMicro (OH_AI_ModelHandle model, OH_AI_ModelType model_type, const char *weight_file, bool is_inference, bool enable_fp16, char **changeable_weights_name, size_t num)Exports the weight file of the training model for micro inference. This API is used only for on-device training.
OH_AI_TensorCreate (const char *name, OH_AI_DataType type, const int64_t *shape, size_t shape_num, const void *data, size_t data_len)Creates a tensor object.
OH_AI_TensorDestroy (OH_AI_TensorHandle *tensor)Destroys a tensor object.
OH_AI_TensorClone (OH_AI_TensorHandle tensor)Clones a tensor.
OH_AI_TensorSetName (OH_AI_TensorHandle tensor, const char *name)Sets the tensor name.
OH_AI_TensorGetName (const OH_AI_TensorHandle tensor)Obtains the tensor name.
OH_AI_TensorSetDataType (OH_AI_TensorHandle tensor, OH_AI_DataType type)Sets the data type of a tensor.
OH_AI_TensorGetDataType (const OH_AI_TensorHandle tensor)Obtains the tensor type.
OH_AI_TensorSetShape (OH_AI_TensorHandle tensor, const int64_t *shape, size_t shape_num)Sets the tensor shape.
OH_AI_TensorGetShape (const OH_AI_TensorHandle tensor, size_t *shape_num)Obtains the tensor shape.
OH_AI_TensorSetFormat (OH_AI_TensorHandle tensor, OH_AI_Format format)Sets the tensor data format.
OH_AI_TensorGetFormat (const OH_AI_TensorHandle tensor)Obtains the tensor data format.
OH_AI_TensorSetData (OH_AI_TensorHandle tensor, void *data)Sets the tensor data.
OH_AI_TensorGetData (const OH_AI_TensorHandle tensor)Obtains the pointer to tensor data.
OH_AI_TensorGetMutableData (const OH_AI_TensorHandle tensor)Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.
OH_AI_TensorGetElementNum (const OH_AI_TensorHandle tensor)Obtains the number of tensor elements.
OH_AI_TensorGetDataSize (const OH_AI_TensorHandle tensor)Obtains the number of bytes of the tensor data.
OH_AI_TensorSetUserData (OH_AI_TensorHandle tensor, void *data, size_t data_size)Sets the tensor as the user data. This function allows you to reuse user data as the model input, which helps to reduce data copy by one time.
> NOTE
The user data is type of external data for the tensor and is not automatically released when the tensor is destroyed. The caller needs to release the data separately. In addition, the caller must ensure that the user data is valid during use of the tensor.
OH_AI_TensorGetAllocator(OH_AI_TensorHandle tensor)Obtains a memory allocator. The allocator is responsible for allocating memory for tensors.
OH_AI_TensorSetAllocator(OH_AI_TensorHandle tensor, OH_AI_AllocatorHandle allocator)Sets the memory allocator. The allocator is responsible for allocating memory for tensors.

Macro Description

OH_AI_MAX_SHAPE_NUM

#define OH_AI_MAX_SHAPE_NUM   32

Description

Maximum number of shapes. The maximum value reserved is 32, and the maximum number currently supported is 8.

Since: 9

Type Description

NNRTDeviceDesc

typedef struct NNRTDeviceDesc NNRTDeviceDesc

Description

Defines NNRt device information, including the device ID and device name.

Since: 10

OH_AI_AllocatorHandle

typedef void *OH_AI_AllocatorHandle

Description

Handle of the memory allocator.

Since: 12

OH_AI_CallBackParam

typedef struct OH_AI_CallBackParam OH_AI_CallBackParam

Description

Defines the operator information passed in a callback.

Since: 9

OH_AI_ContextHandle

typedef void* OH_AI_ContextHandle

Description

Defines the pointer to the MindSpore context.

Since: 9

OH_AI_DataType

typedef enum OH_AI_DataType OH_AI_DataType

Description

Declares data types supported by MSTensor.

Since: 9

OH_AI_DeviceInfoHandle

typedef void* OH_AI_DeviceInfoHandle

Description

Defines the pointer to the MindSpore device information.

Since: 9

OH_AI_DeviceType

typedef enum OH_AI_DeviceType OH_AI_DeviceType

Description

Defines the supported device types.

Since: 9

OH_AI_Format

typedef enum OH_AI_Format OH_AI_Format

Description

Declares data formats supported by MSTensor.

Since: 9

OH_AI_KernelCallBack

typedef bool(* OH_AI_KernelCallBack) (const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs, const OH_AI_CallBackParam kernel_Info)

Description

Defines the pointer to a callback.

This pointer is used to set the two callback functions in OH_AI_ModelPredict. Each callback function must contain three parameters, where inputs and outputs indicate the input and output tensors of the operator, and kernel_Info indicates information about the current operator. You can use the callback functions to monitor the operator execution status, for example, operator execution time and the operator correctness.

Since: 9

OH_AI_ModelHandle

typedef void* OH_AI_ModelHandle

Description

Defines the pointer to a model object.

Since: 9

OH_AI_ModelType

typedef enum OH_AI_ModelType OH_AI_ModelType

Description

Defines model file types.

Since: 9

OH_AI_NNRTDeviceType

typedef enum OH_AI_NNRTDeviceType OH_AI_NNRTDeviceType

Description

Defines NNRt device types.

Since: 10

OH_AI_PerformanceMode

typedef enum OH_AI_PerformanceMode OH_AI_PerformanceMode

Description

Defines performance modes of the NNRt device.

Since: 10

OH_AI_Priority

typedef enum OH_AI_Priority OH_AI_Priority

Description

Defines NNRt inference task priorities.

Since: 10

OH_AI_Status

typedef enum OH_AI_Status OH_AI_Status

Description

Defines MindSpore status codes.

Since: 9

OH_AI_TensorHandle

typedef void* OH_AI_TensorHandle

Description

Handle of a tensor object.

Since: 9

OH_AI_TensorHandleArray

typedef struct OH_AI_TensorHandleArray OH_AI_TensorHandleArray

Description

Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.

Since: 9

OH_AI_TrainCfgHandle

typedef void* OH_AI_TrainCfgHandle

Description

Defines the pointer to a training configuration object.

Since: 11

Enum Description

OH_AI_CompCode

enum OH_AI_CompCode

Description

Defines MindSpore component codes.

Since: 9

ValueDescription
OH_AI_COMPCODE_COREMindSpore Core code.
OH_AI_COMPCODE_MDMindSpore MindData code.
OH_AI_COMPCODE_MEMindSpore MindExpression code.
OH_AI_COMPCODE_MCMindSpore code.
OH_AI_COMPCODE_LITEMindSpore Lite code.

OH_AI_DataType

enum OH_AI_DataType

Description

Declares data types supported by MSTensor.

Since: 9

ValueDescription
OH_AI_DATATYPE_UNKNOWNUnknown data type.
OH_AI_DATATYPE_OBJECTTYPE_STRINGString data.
OH_AI_DATATYPE_OBJECTTYPE_LISTList data.
OH_AI_DATATYPE_OBJECTTYPE_TUPLETuple data.
OH_AI_DATATYPE_OBJECTTYPE_TENSORTensorList data.
OH_AI_DATATYPE_NUMBERTYPE_BEGINBeginning of the number type.
OH_AI_DATATYPE_NUMBERTYPE_BOOLBool data.
OH_AI_DATATYPE_NUMBERTYPE_INT8Int8 data.
OH_AI_DATATYPE_NUMBERTYPE_INT16Int16 data.
OH_AI_DATATYPE_NUMBERTYPE_INT32Int32 data.
OH_AI_DATATYPE_NUMBERTYPE_INT64Int64 data.
OH_AI_DATATYPE_NUMBERTYPE_UINT8UInt8 data.
OH_AI_DATATYPE_NUMBERTYPE_UINT16UInt16 data.
OH_AI_DATATYPE_NUMBERTYPE_UINT32UInt32 data.
OH_AI_DATATYPE_NUMBERTYPE_UINT64UInt64 data.
OH_AI_DATATYPE_NUMBERTYPE_FLOAT16Float16 data.
OH_AI_DATATYPE_NUMBERTYPE_FLOAT32Float32 data.
OH_AI_DATATYPE_NUMBERTYPE_FLOAT64Float64 data.
OH_AI_DATATYPE_NUMBERTYPE_ENDEnd of the number type.
OH_AI_DataTypeInvalidInvalid data type.

OH_AI_DeviceType

enum OH_AI_DeviceType

Description

Defines the supported device types.

Since: 9

ValueDescription
OH_AI_DEVICETYPE_CPUDevice type: CPU
OH_AI_DEVICETYPE_GPUDevice type: GPU
This configuration is open for upstream open source projects and is not supported by OpenHarmony.
OH_AI_DEVICETYPE_KIRIN_NPUDevice type: Kirin NPU
This configuration is open for upstream open source projects and is not supported by OpenHarmony.
To use KIRIN_NPU, set OH_AI_DEVICETYPE_NNRT.
OH_AI_DEVICETYPE_NNRTNNRt, a cross-chip inference and computing runtime oriented to the AI field.
OHOS device range: [60, 80)
OH_AI_DEVICETYPE_INVALIDInvalid device type.

OH_AI_Format

enum OH_AI_Format

Description

Declares data formats supported by MSTensor.

Since: 9

ValueDescription
OH_AI_FORMAT_NCHWTensor data is stored in the sequence of batch number N, channel C, height H, and width W.
OH_AI_FORMAT_NHWCTensor data is stored in the sequence of batch number N, height H, width W, and channel C.
OH_AI_FORMAT_NHWC4Tensor data is stored in the sequence of batch number N, height H, width W, and channel C. The C axis is 4-byte aligned.
OH_AI_FORMAT_HWKCTensor data is stored in the sequence of height H, width W, core count K, and channel C.
OH_AI_FORMAT_HWCKTensor data is stored in the sequence of height H, width W, channel C, and core count K.
OH_AI_FORMAT_KCHWTensor data is stored in the sequence of core count K, channel C, height H, and width W.
OH_AI_FORMAT_CKHWTensor data is stored in the sequence of channel C, core count K, height H, and width W.
OH_AI_FORMAT_KHWCTensor data is stored in the sequence of core count K, height H, width W, and channel C.
OH_AI_FORMAT_CHWKTensor data is stored in the sequence of channel C, height H, width W, and core count K.
OH_AI_FORMAT_HWTensor data is stored in the sequence of height H and width W.
OH_AI_FORMAT_HW4Tensor data is stored in the sequence of height H and width W. The W axis is 4-byte aligned.
OH_AI_FORMAT_NCTensor data is stored in the sequence of batch number N and channel C.
OH_AI_FORMAT_NC4Tensor data is stored in the sequence of batch number N and channel C. The C axis is 4-byte aligned.
OH_AI_FORMAT_NC4HW4Tensor data is stored in the sequence of batch number N, channel C, height H, and width W. The C axis and W axis are 4-byte aligned.
OH_AI_FORMAT_NCDHWTensor data is stored in the sequence of batch number N, channel C, depth D, height H, and width W.
OH_AI_FORMAT_NWCTensor data is stored in the sequence of batch number N, width W, and channel C.
OH_AI_FORMAT_NCWTensor data is stored in the sequence of batch number N, channel C, and width W.

OH_AI_ModelType

enum OH_AI_ModelType

Description

Defines model file types.

Since: 9

ValueDescription
OH_AI_MODELTYPE_MINDIRModel type of MindIR. The extension of the model file name is .ms.
OH_AI_MODELTYPE_INVALIDInvalid model type.

OH_AI_NNRTDeviceType

enum OH_AI_NNRTDeviceType

Description

Defines NNRt device types.

Since: 10

ValueDescription
OH_AI_NNRTDEVICE_OTHERSOthers (any device type except the following three types).
OH_AI_NNRTDEVICE_CPUCPU.
OH_AI_NNRTDEVICE_GPUGPU.
OH_AI_NNRTDEVICE_ACCELERATORSpecific acceleration device.

OH_AI_OptimizationLevel

enum OH_AI_OptimizationLevel

Description

Defines training optimization levels.

Since

11

ValueDescription
OH_AI_KO0No optimization level.
OH_AI_KO2Converts the precision type of the network to float16 and keeps the precision type of the batch normalization layer and loss function as float32.
OH_AI_KO3Converts the precision type of the network (including the batch normalization layer) to float16.
OH_AI_KAUTOSelects an optimization level based on the device.
OH_AI_KOPTIMIZATIONTYPEInvalid optimization level.

OH_AI_PerformanceMode

enum OH_AI_PerformanceMode

Description

Defines performance modes of the NNRt device.

Since: 10

ValueDescription
OH_AI_PERFORMANCE_NONENo special settings.
OH_AI_PERFORMANCE_LOWLow power consumption.
OH_AI_PERFORMANCE_MEDIUMPower consumption and performance balancing.
OH_AI_PERFORMANCE_HIGHHigh performance.
OH_AI_PERFORMANCE_EXTREMEUltimate performance.

OH_AI_Priority

enum OH_AI_Priority

Description

Defines NNRt inference task priorities.

Since: 10

ValueDescription
OH_AI_PRIORITY_NONENo priority preference.
OH_AI_PRIORITY_LOWLow priority.
OH_AI_PRIORITY_MEDIUMMedium priority.
OH_AI_PRIORITY_HIGHHigh priority.

OH_AI_QuantizationType

enum OH_AI_QuantizationType

Description

Defines quantization types.

Since

11

ValueDescription
OH_AI_NO_QUANTNo quantification.
OH_AI_WEIGHT_QUANTWeight quantization.
OH_AI_FULL_QUANTFull quantization.
OH_AI_UNKNOWN_QUANT_TYPEInvalid quantization type.

OH_AI_Status

enum OH_AI_Status

Description

Defines MindSpore status codes.

Since: 9

ValueDescription
OH_AI_STATUS_SUCCESSSuccess.
OH_AI_STATUS_CORE_FAILEDMindSpore Core failure.
OH_AI_STATUS_LITE_ERRORMindSpore Lite error.
OH_AI_STATUS_LITE_NULLPTRMindSpore Lite null pointer.
OH_AI_STATUS_LITE_PARAM_INVALIDMindSpore Lite invalid parameters.
OH_AI_STATUS_LITE_NO_CHANGEMindSpore Lite no change.
OH_AI_STATUS_LITE_SUCCESS_EXITMindSpore Lite exit without errors.
OH_AI_STATUS_LITE_MEMORY_FAILEDMindSpore Lite memory allocation failure.
OH_AI_STATUS_LITE_NOT_SUPPORTMindSpore Lite function not supported.
OH_AI_STATUS_LITE_THREADPOOL_ERRORMindSpore Lite thread pool error.
OH_AI_STATUS_LITE_UNINITIALIZED_OBJMindSpore Lite uninitialized.
OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGEMindSpore Lite tensor overflow.
OH_AI_STATUS_LITE_INPUT_TENSOR_ERRORMindSpore Lite input tensor error.
OH_AI_STATUS_LITE_REENTRANT_ERRORMindSpore Lite reentry error.
OH_AI_STATUS_LITE_GRAPH_FILE_ERRORMindSpore Lite file error.
OH_AI_STATUS_LITE_NOT_FIND_OPMindSpore Lite operator not found.
OH_AI_STATUS_LITE_INVALID_OP_NAMEMindSpore Lite invalid operators.
OH_AI_STATUS_LITE_INVALID_OP_ATTRMindSpore Lite invalid operator hyperparameters.
OH_AI_STATUS_LITE_OP_EXECUTE_FAILUREMindSpore Lite operator execution failure.
OH_AI_STATUS_LITE_FORMAT_ERRORMindSpore Lite tensor format error.
OH_AI_STATUS_LITE_INFER_ERRORMindSpore Lite shape inference error.
OH_AI_STATUS_LITE_INFER_INVALIDMindSpore Lite invalid shape inference.
OH_AI_STATUS_LITE_INPUT_PARAM_INVALIDMindSpore Lite invalid input parameters.

Function Description

OH_AI_ContextAddDeviceInfo()

OH_AI_API void OH_AI_ContextAddDeviceInfo (OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info )

Description

Attaches the custom device information to the inference context.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

OH_AI_ContextCreate()

OH_AI_API OH_AI_ContextHandle OH_AI_ContextCreate ()

Description

Creates a context object. This API must be used together with OH_AI_ContextDestroy.

Since: 9

Returns

OH_AI_ContextHandle that points to the context instance.

OH_AI_ContextDestroy()

OH_AI_API void OH_AI_ContextDestroy (OH_AI_ContextHandle * context)

Description

Destroys a context object.

Since: 9

Parameters

NameDescription
contextLevel-2 pointer to OH_AI_ContextHandle. After the context is destroyed, the pointer is set to null.

OH_AI_ContextGetEnableParallel()

OH_AI_API bool OH_AI_ContextGetEnableParallel (const OH_AI_ContextHandle context)

Description

Checks whether parallelism between operators is supported.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.

Returns

Whether parallelism between operators is supported. The value true means that parallelism between operators is supported, and the value false means the opposite.

OH_AI_ContextGetThreadAffinityCoreList()

OH_AI_API const int32_t* OH_AI_ContextGetThreadAffinityCoreList (const OH_AI_ContextHandle context, size_t * core_num )

Description

Obtains the list of bound CPU cores.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.
core_numNumber of CPU cores.

Returns

CPU core binding list. This list is managed by OH_AI_ContextHandle. The caller does not need to destroy it manually.

OH_AI_ContextGetThreadAffinityMode()

OH_AI_API int OH_AI_ContextGetThreadAffinityMode (const OH_AI_ContextHandle context)

Description

Obtains the affinity mode for binding runtime threads to CPU cores.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.

Returns

Affinity mode. 0: no affinities; 1: big cores first; 2: medium cores first

OH_AI_ContextGetThreadNum()

OH_AI_API int32_t OH_AI_ContextGetThreadNum (const OH_AI_ContextHandle context)

Description

Obtains the number of threads.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.

Returns

Number of threads.

OH_AI_ContextSetEnableParallel()

OH_AI_API void OH_AI_ContextSetEnableParallel (OH_AI_ContextHandle context, bool is_parallel )

Description

Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.
is_parallelWhether parallelism between operators is supported. The value true means that parallelism between operators is supported, and the value false means the opposite.

OH_AI_ContextSetThreadAffinityCoreList()

OH_AI_API void OH_AI_ContextSetThreadAffinityCoreList (OH_AI_ContextHandle context, const int32_t * core_list, size_t core_num )

Description

Sets the list of CPU cores bound to a runtime thread.

For example, if core_list is set to [2,6,8], threads run on the 2nd, 6th, and 8th CPU cores. If OH_AI_ContextSetThreadAffinityMode and OH_AI_ContextSetThreadAffinityCoreList are called for the same context object, the core_list parameter of OH_AI_ContextSetThreadAffinityCoreList takes effect, but the mode parameter of OH_AI_ContextSetThreadAffinityMode does not.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.
core_listList of bound CPU cores.
core_numNumber of cores, which indicates the length of core_list.

OH_AI_ContextSetThreadAffinityMode()

OH_AI_API void OH_AI_ContextSetThreadAffinityMode (OH_AI_ContextHandle context, int mode )

Description

Sets the affinity mode for binding runtime threads to CPU cores, which are classified into large, medium, and small cores based on the CPU frequency. You only need to bind the large or medium cores, but not small cores.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.
modeAffinity mode. 0: no affinities; 1: big cores first; 2: medium cores first

OH_AI_ContextSetThreadNum()

OH_AI_API void OH_AI_ContextSetThreadNum (OH_AI_ContextHandle context, int32_t thread_num )

Description

Sets the number of runtime threads.

Since: 9

Parameters

NameDescription
contextOH_AI_ContextHandle that points to the context instance.
thread_numNumber of runtime threads.

OH_AI_CreateNNRTDeviceInfoByName()

OH_AI_API OH_AI_DeviceInfoHandle OH_AI_CreateNNRTDeviceInfoByName (const char * name)

Description

Searches for the NNRt device with the specified name and creates the NNRt device information based on the information about the first found NNRt device.

Since: 10

Parameters

NameDescription
nameName of the target NNRt device.

Returns

OH_AI_DeviceInfoHandle that points to a device information instance.

OH_AI_CreateNNRTDeviceInfoByType()

OH_AI_API OH_AI_DeviceInfoHandle OH_AI_CreateNNRTDeviceInfoByType (OH_AI_NNRTDeviceType type)

Description

Searches for the NNRt device with the specified type and creates the NNRt device information based on the information about the first found NNRt device.

Since: 10

Parameters

NameDescription
typeNNRt device type, which is specified by OH_AI_NNRTDeviceType.

Returns

OH_AI_DeviceInfoHandle that points to a device information instance.

OH_AI_DestroyAllNNRTDeviceDescs()

OH_AI_API void OH_AI_DestroyAllNNRTDeviceDescs (NNRTDeviceDesc ** desc)

Description

Destroys the NNRt device description array obtained by OH_AI_GetAllNNRTDeviceDescs.

Since: 10

Parameters

NameDescription
descDouble pointer to the array of the NNRt device descriptions. After the operation is complete, the content pointed to by desc is set to NULL.

OH_AI_DeviceInfoAddExtension()

OH_AI_API OH_AI_Status OH_AI_DeviceInfoAddExtension (OH_AI_DeviceInfoHandle device_info, const char * name, const char * value, size_t value_size )

Description

Adds extended configuration in the form of key/value pairs to the device information. This function is available only for NNRt devices.

Note: Currently, only 11 key-value pairs are supported, including: {"CachePath": "YourCachePath"}, {"CacheVersion": "YouCacheVersion"}, {"QuantBuffer": "YourQuantBuffer"}, {"ModelName": "YourModelName"}, {"isProfiling": "YourisProfiling"}, {"opLayout": "YouropLayout"}, {"InputDims": "YourInputDims"}, {"DynamicDims": "YourDynamicDims"}, {"QuantConfigData": "YourQuantConfigData"}, {"BandMode": "YourBandMode"}, {"NPU_FM_SHARED": "YourNPU_FM_SHARED"}. Replace them as required.

Since: 10

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
nameKey in an extended key/value pair. The value is a C string.
valueStart address of the value in an extended key/value pair.
value_sizeLength of the value in an extended key/value pair.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_DeviceInfoCreate()

OH_AI_API OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate (OH_AI_DeviceType device_type)

Description

Creates a device information object.

Since: 9

Parameters

NameDescription
device_typeDevice type, which is specified by OH_AI_DeviceType.

Returns

OH_AI_DeviceInfoHandle that points to a device information instance.

OH_AI_DeviceInfoDestroy()

OH_AI_API void OH_AI_DeviceInfoDestroy (OH_AI_DeviceInfoHandle * device_info)

Description

Destroys a device information object. Note: After the device information instance is added to the context, the caller does not need to destroy it manually.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

OH_AI_DeviceInfoGetDeviceId()

OH_AI_API size_t OH_AI_DeviceInfoGetDeviceId (const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the NNRt device ID. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

NNRt device ID.

OH_AI_DeviceInfoGetDeviceType()

OH_AI_API OH_AI_DeviceType OH_AI_DeviceInfoGetDeviceType (const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the device type.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

Type of the provider device.

OH_AI_DeviceInfoGetEnableFP16()

OH_AI_API bool OH_AI_DeviceInfoGetEnableFP16 (const OH_AI_DeviceInfoHandle device_info)

Description

Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

Whether float16 inference is enabled.

OH_AI_DeviceInfoGetFrequency()

OH_AI_API int OH_AI_DeviceInfoGetFrequency (const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the NPU frequency type. This function is available only for NPU devices.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

NPU frequency type. The value ranges from 0 to 4. 1: low power consumption; 2: balanced; 3: high performance; 4: ultra-high performance

OH_AI_DeviceInfoGetPerformanceMode()

OH_AI_API OH_AI_PerformanceMode OH_AI_DeviceInfoGetPerformanceMode (const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the NNRt performance mode. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

NNRt performance mode, which is specified by OH_AI_PerformanceMode.

OH_AI_DeviceInfoGetPriority()

OH_AI_API OH_AI_Priority OH_AI_DeviceInfoGetPriority (const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the priority of an NNRt task. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

NNRt task priority, which is specified by OH_AI_Priority.

OH_AI_DeviceInfoGetProvider()

OH_AI_API const char* OH_AI_DeviceInfoGetProvider (const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the provider name.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

Provider name.

OH_AI_DeviceInfoGetProviderDevice()

OH_AI_API const char* OH_AI_DeviceInfoGetProviderDevice (const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the name of a provider device.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.

Returns

Name of the provider device.

OH_AI_DeviceInfoSetDeviceId()

OH_AI_API void OH_AI_DeviceInfoSetDeviceId (OH_AI_DeviceInfoHandle device_info, size_t device_id )

Description

Sets the NNRt device ID. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
device_idNNRt device ID.

OH_AI_DeviceInfoSetEnableFP16()

OH_AI_API void OH_AI_DeviceInfoSetEnableFP16 (OH_AI_DeviceInfoHandle device_info, bool is_fp16 )

Description

Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
is_fp16Whether to enable the float16 inference mode.

OH_AI_DeviceInfoSetFrequency()

OH_AI_API void OH_AI_DeviceInfoSetFrequency (OH_AI_DeviceInfoHandle device_info, int frequency )

Description

Sets the NPU frequency type. This function is available only for NPU devices.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
frequencyNPU frequency type. The value ranges from 0 to 4. The default value is 3. 1: low power consumption; 2: balanced; 3: high performance; 4: ultra-high performance

OH_AI_DeviceInfoSetPerformanceMode()

OH_AI_API void OH_AI_DeviceInfoSetPerformanceMode (OH_AI_DeviceInfoHandle device_info, OH_AI_PerformanceMode mode )

Description

Sets the NNRt performance mode. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
modeNNRt performance mode, which is specified by OH_AI_PerformanceMode.

OH_AI_DeviceInfoSetPriority()

OH_AI_API void OH_AI_DeviceInfoSetPriority (OH_AI_DeviceInfoHandle device_info, OH_AI_Priority priority )

Description

Sets the priority of an NNRt task. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
priorityNNRt task priority, which is specified by OH_AI_Priority.

OH_AI_DeviceInfoSetProvider()

OH_AI_API void OH_AI_DeviceInfoSetProvider (OH_AI_DeviceInfoHandle device_info, const char * provider )

Description

Sets the name of the provider.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
providerProvider name.

OH_AI_DeviceInfoSetProviderDevice()

OH_AI_API void OH_AI_DeviceInfoSetProviderDevice (OH_AI_DeviceInfoHandle device_info, const char * device )

Description

Sets the name of a provider device.

Since: 9

Parameters

NameDescription
device_infoOH_AI_DeviceInfoHandle that points to a device information instance.
deviceName of the provider device, for example, CPU.

OH_AI_ExportModel()

OH_AI_API OH_AI_Status OH_AI_ExportModel (OH_AI_ModelHandle model, OH_AI_ModelType model_type, const char * model_file, OH_AI_QuantizationType quantization_type, bool export_inference_only, char ** output_tensor_name, size_t num )

Description

Exports a training model. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
model_typeModel file type, which is specified by OH_AI_ModelType.
model_filePath of the exported model file.
quantization_typeQuantization type.
export_inference_onlyWhether to export an inference model.
output_tensor_nameOutput tensor of the exported model. This parameter is left blank by default, which indicates full export.
numNumber of output tensors.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ExportModelBuffer()

OH_AI_API OH_AI_Status OH_AI_ExportModelBuffer (OH_AI_ModelHandle model, OH_AI_ModelType model_type, void * model_data, size_t * data_size, OH_AI_QuantizationType quantization_type, bool export_inference_only, char ** output_tensor_name, size_t num )

Description Exports the memory cache of the training model. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
model_typeModel file type, which is specified by OH_AI_ModelType.
model_dataPointer to the buffer that stores the exported model file.
data_sizeBuffer size.
quantization_typeQuantization type.
export_inference_onlyWhether to export an inference model.
output_tensor_nameOutput tensor of the exported model. This parameter is left blank by default, which indicates full export.
numNumber of output tensors.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ExportWeightsCollaborateWithMicro()

OH_AI_API OH_AI_Status OH_AI_ExportWeightsCollaborateWithMicro (OH_AI_ModelHandle model, OH_AI_ModelType model_type, const char * weight_file, bool is_inference, bool enable_fp16, char ** changeable_weights_name, size_t num )

Description

Exports the weight file of the training model for micro inference. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
model_typeModel file type, which is specified by OH_AI_ModelType.
weight_filePath of the exported weight file.
is_inferenceWhether to export inference models. Currently, this parameter can only be set to true.
enable_fp16Whether to save floating-point weights in float16 format.
changeable_weights_nameName of the weight tensor with a variable shape.
numNumber of weight tensors with a variable shape.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_GetAllNNRTDeviceDescs()

OH_AI_API NNRTDeviceDesc* OH_AI_GetAllNNRTDeviceDescs (size_t * num)

Description

Obtains the descriptions of all NNRt devices in the system.

Since: 10

Parameters

NameDescription
numNumber of NNRt devices.

Returns

Pointer to the array of the NNRt device descriptions. If the operation fails, NULL is returned.

OH_AI_GetDeviceIdFromNNRTDeviceDesc()

OH_AI_API size_t OH_AI_GetDeviceIdFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)

Description

Obtains the NNRt device ID from the specified NNRt device description. Note that this ID is valid only for NNRt devices.

Since: 10

Parameters

NameDescription
descPointer to the NNRt device description.

Returns

NNRt device ID.

OH_AI_GetElementOfNNRTDeviceDescs()

OH_AI_API NNRTDeviceDesc* OH_AI_GetElementOfNNRTDeviceDescs (NNRTDeviceDesc * descs, size_t index )

Description

Obtains the pointer to an element in the NNRt device description array.

Since: 10

Parameters

NameDescription
descsNNRt device description array.
indexIndex of an array element.

Returns

Pointer to an element in the NNRt device description array.

OH_AI_GetNameFromNNRTDeviceDesc()

OH_AI_API const char* OH_AI_GetNameFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)

Description

Obtains the NNRt device name from the specified NNRt device description.

Since: 10

Parameters

NameDescription
descPointer to the NNRt device description.

Returns

NNRt device name. The value is a pointer that points to a constant string, which is held by desc. The caller does not need to destroy it separately.

OH_AI_GetTypeFromNNRTDeviceDesc()

OH_AI_API OH_AI_NNRTDeviceType OH_AI_GetTypeFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)

Description

Obtains the NNRt device type from the specified NNRt device description.

Since: 10

Parameters

NameDescription
descPointer to the NNRt device description.

Returns

NNRt device type, which is specified by OH_AI_NNRTDeviceType.

OH_AI_ModelBuild()

OH_AI_API OH_AI_Status OH_AI_ModelBuild (OH_AI_ModelHandle model, const void * model_data, size_t data_size, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context )

Description

Loads and builds a MindSpore model from the memory buffer.

Note that the same {@Link OH_AI_ContextHandle} object can only be passed to {@Link OH_AI_ModelBuild} or {@Link OH_AI_ModelBuildFromFile} once. If you call this function multiple times, make sure that you create multiple {@Link OH_AI_ContextHandle} objects accordingly.

Since: 9

Parameters

NameDescription
modelPointer to the model object.
model_dataAddress of the loaded model data in the memory.
data_sizeLength of the model data.
model_typeModel file type, which is specified by OH_AI_ModelType.
model_contextModel runtime context, which is specified by OH_AI_ContextHandle.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ModelBuildFromFile()

OH_AI_API OH_AI_Status OH_AI_ModelBuildFromFile (OH_AI_ModelHandle model, const char * model_path, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context )

Description

Loads and builds a MindSpore model from a model file.

Note that the same {@Link OH_AI_ContextHandle} object can only be passed to {@Link OH_AI_ModelBuild} or {@Link OH_AI_ModelBuildFromFile} once. If you call this function multiple times, make sure that you create multiple {@Link OH_AI_ContextHandle} objects accordingly.

Since: 9

Parameters

NameDescription
modelPointer to the model object.
model_pathPath of the model file.
model_typeModel file type, which is specified by OH_AI_ModelType.
model_contextModel runtime context, which is specified by OH_AI_ContextHandle.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ModelCreate()

OH_AI_API OH_AI_ModelHandle OH_AI_ModelCreate (void)

Description

Creates a model object.

Since: 9

Returns

Pointer to the model object.

OH_AI_ModelDestroy()

OH_AI_API void OH_AI_ModelDestroy (OH_AI_ModelHandle * model)

Description

Destroys a model object.

Since: 9

Parameters

NameDescription
modelPointer to the model object.

OH_AI_ModelGetInputByTensorName()

OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetInputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )

Description

Obtains the input tensor of a model by tensor name.

Since: 9

Parameters

NameDescription
modelPointer to the model object.
tensor_nameTensor name.

Returns

Pointer to the input tensor indicated by tensor_name. If the tensor does not exist in the input, null will be returned.

OH_AI_ModelGetInputs()

OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetInputs (const OH_AI_ModelHandle model)

Description

Obtains the input tensor array structure of a model.

Since: 9

Parameters

NameDescription
modelPointer to the model object.

Returns

Tensor array structure corresponding to the model input.

OH_AI_ModelGetLearningRate()

OH_AI_API float OH_AI_ModelGetLearningRate (OH_AI_ModelHandle model)

Description

Obtains the learning rate for model training. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.

Returns

Learning rate. If no optimizer is set, the value is 0.0.

OH_AI_ModelGetOutputByTensorName()

OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetOutputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )

Description

Obtains the output tensor of a model by tensor name.

Since: 9

Parameters

NameDescription
modelPointer to the model object.
tensor_nameTensor name.

Returns

Pointer to the input tensor indicated by tensor_name. If the tensor does not exist, null will be returned.

OH_AI_ModelGetOutputs()

OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetOutputs (const OH_AI_ModelHandle model)

Description

Obtains the output tensor array structure of a model.

Since: 9

Parameters

NameDescription
modelPointer to the model object.

Returns

Tensor array structure corresponding to the model output.

OH_AI_ModelGetTrainMode()

OH_AI_API bool OH_AI_ModelGetTrainMode (OH_AI_ModelHandle model)

Description

Obtains the training mode.

Since: 11

Parameters

NameDescription
modelPointer to the model object.

Returns

Whether the training mode is used.

OH_AI_ModelGetWeights()

OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetWeights (OH_AI_ModelHandle model)

Description

Obtains all weight tensors of a model. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.

Returns

All weight tensors of the model.

OH_AI_ModelPredict()

OH_AI_API OH_AI_Status OH_AI_ModelPredict (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_TensorHandleArray * outputs, const OH_AI_KernelCallBack before, const OH_AI_KernelCallBack after )

Description

Performs model inference.

Since: 9

Parameters

NameDescription
modelPointer to the model object.
inputsTensor array structure corresponding to the model input.
outputsPointer to the tensor array structure corresponding to the model output.
beforeCallback function executed before model inference.
afterCallback function executed after model inference.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ModelResize()

OH_AI_API OH_AI_Status OH_AI_ModelResize (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_ShapeInfo * shape_infos, size_t shape_info_num )

Description

Adjusts the input tensor shapes of a built model.

Since: 9

Parameters

NameDescription
modelPointer to the model object.
inputsTensor array structure corresponding to the model input.
shape_infosInput shape information array, which consists of tensor shapes arranged in the model input sequence. The model adjusts the tensor shapes in sequence.
shape_info_numLength of the shape information array.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ModelSetLearningRate()

OH_AI_API OH_AI_Status OH_AI_ModelSetLearningRate (OH_AI_ModelHandle model, float learning_rate )

Description

Sets the learning rate for model training. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
learning_rateLearning rate.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ModelSetTrainMode()

OH_AI_API OH_AI_Status OH_AI_ModelSetTrainMode (OH_AI_ModelHandle model, bool train )

Description

Sets the training mode. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
trainWhether the training mode is used.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ModelSetupVirtualBatch()

OH_AI_API OH_AI_Status OH_AI_ModelSetupVirtualBatch (OH_AI_ModelHandle model, int virtual_batch_multiplier, float lr, float momentum )

Description

Sets the virtual batch for training. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
virtual_batch_multiplierVirtual batch multiplier. If the value is less than 1, the virtual batch is disabled.
lrLearning rate. The default value is -1.0f.
momentumMomentum. The default value is -1.0f.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_ModelUpdateWeights()

OH_AI_API OH_AI_Status OH_AI_ModelUpdateWeights (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray new_weights )

Description

Updates the weight tensors of a model. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
new_weightsWeight tensors to be updated.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_RunStep()

OH_AI_API OH_AI_Status OH_AI_RunStep (OH_AI_ModelHandle model, const OH_AI_KernelCallBack before, const OH_AI_KernelCallBack after )

Description

Defines a single-step training model. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
beforeCallback function executed before model inference.
afterCallback function executed after model inference.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_TensorClone()

OH_AI_API OH_AI_TensorHandle OH_AI_TensorClone (OH_AI_TensorHandle tensor)

Description

Clones a tensor.

Since: 9

Parameters

NameDescription
tensorPointer to the tensor to clone.

Returns

Handle of a tensor object.

OH_AI_TensorCreate()

OH_AI_API OH_AI_TensorHandle OH_AI_TensorCreate (const char * name, OH_AI_DataType type, const int64_t * shape, size_t shape_num, const void * data, size_t data_len )

Description

Creates a tensor object.

Since: 9

Parameters

NameDescription
nameTensor name.
typeTensor data type.
shapeTensor dimension array.
shape_numLength of the tensor dimension array.
dataData pointer.
data_lenData length.

Returns

Handle of a tensor object.

OH_AI_TensorGetAllocator()

OH_AI_API OH_AI_AllocatorHandle OH_AI_TensorGetAllocator(OH_AI_TensorHandle tensor)

Description

Obtains a memory allocator. The allocator is responsible for allocating memory for tensors.

Since: 12

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Handle of the memory allocator.

OH_AI_TensorDestroy()

OH_AI_API void OH_AI_TensorDestroy (OH_AI_TensorHandle * tensor)

Description

Destroys a tensor object.

Since: 9

Parameters

NameDescription
tensorLevel-2 pointer to the tensor handle.

OH_AI_TensorGetData()

OH_AI_API const void* OH_AI_TensorGetData (const OH_AI_TensorHandle tensor)

Description

Obtains the pointer to tensor data.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Pointer to tensor data.

OH_AI_TensorGetDataSize()

OH_AI_API size_t OH_AI_TensorGetDataSize (const OH_AI_TensorHandle tensor)

Description

Obtains the number of bytes of the tensor data.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Number of bytes of the tensor data.

OH_AI_TensorGetDataType()

OH_AI_API OH_AI_DataType OH_AI_TensorGetDataType (const OH_AI_TensorHandle tensor)

Description

Obtains the tensor type.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Tensor data type.

OH_AI_TensorGetElementNum()

OH_AI_API int64_t OH_AI_TensorGetElementNum (const OH_AI_TensorHandle tensor)

Description

Obtains the number of tensor elements.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Number of tensor elements.

OH_AI_TensorGetFormat()

OH_AI_API OH_AI_Format OH_AI_TensorGetFormat (const OH_AI_TensorHandle tensor)

Description

Obtains the tensor data format.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Tensor data format.

OH_AI_TensorGetMutableData()

OH_AI_API void* OH_AI_TensorGetMutableData (const OH_AI_TensorHandle tensor)

Description

Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Pointer to tensor data.

OH_AI_TensorGetName()

OH_AI_API const char* OH_AI_TensorGetName (const OH_AI_TensorHandle tensor)

Description

Obtains the tensor name.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.

Returns

Tensor name.

OH_AI_TensorGetShape()

OH_AI_API const int64_t* OH_AI_TensorGetShape (const OH_AI_TensorHandle tensor, size_t * shape_num )

Description

Obtains the tensor shape.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.
shape_numLength of the tensor shape array.

Returns

Shape array.

OH_AI_TensorSetAllocator()

OH_AI_API OH_AI_Status OH_AI_TensorSetAllocator(OH_AI_TensorHandle tensor, OH_AI_AllocatorHandle allocator)

Description

Sets the memory allocator. The allocator is responsible for allocating memory for tensors.

Since: 12

Parameters

NameDescription
tensorHandle of the tensor object.
allocatorHandle of the memory allocator.

Returns

Execution status code. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_TensorSetData()

OH_AI_API void OH_AI_TensorSetData (OH_AI_TensorHandle tensor, void * data )

Description

Sets the tensor data.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.
dataData pointer.

OH_AI_TensorSetDataType()

OH_AI_API void OH_AI_TensorSetDataType (OH_AI_TensorHandle tensor, OH_AI_DataType type )

Description

Sets the data type of a tensor.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.
typeData type, which is specified by OH_AI_DataType.

OH_AI_TensorSetFormat()

OH_AI_API void OH_AI_TensorSetFormat (OH_AI_TensorHandle tensor, OH_AI_Format format )

Description

Sets the tensor data format.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.
formatTensor data format.

OH_AI_TensorSetName()

OH_AI_API void OH_AI_TensorSetName (OH_AI_TensorHandle tensor, const char * name )

Description

Sets the tensor name.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.
nameTensor name.

OH_AI_TensorSetShape()

OH_AI_API void OH_AI_TensorSetShape (OH_AI_TensorHandle tensor, const int64_t * shape, size_t shape_num )

Description

Sets the tensor shape.

Since: 9

Parameters

NameDescription
tensorHandle of the tensor object.
shapeShape array.
shape_numLength of the tensor shape array.

OH_AI_TensorSetUserData()

OH_AI_API OH_AI_Status OH_AI_TensorSetUserData (OH_AI_TensorHandle tensor, void * data, size_t data_size )

Description

Sets the tensor as the user data. This function allows you to reuse user data as the model input, which helps to reduce data copy by one time. > NOTE
The user data is type of external data for the tensor and is not automatically released when the tensor is destroyed. The caller needs to release the data separately. In addition, the caller must ensure that the user data is valid during use of the tensor.

Since: 10

Parameters

NameDescription
tensorHandle of the tensor object.
dataStart address of user data.
data_sizeLength of the user data length.

Returns

Execution status code. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_TrainCfgCreate()

OH_AI_API OH_AI_TrainCfgHandle OH_AI_TrainCfgCreate ()

Description

Creates the pointer to the training configuration object. This API is used only for on-device training.

Since: 11

Returns

Pointer to the training configuration object.

OH_AI_TrainCfgDestroy()

OH_AI_API void OH_AI_TrainCfgDestroy (OH_AI_TrainCfgHandle * train_cfg)

Description

Destroys the pointer to the training configuration object. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
train_cfgPointer to the training configuration object.

OH_AI_TrainCfgGetLossName()

OH_AI_API char** OH_AI_TrainCfgGetLossName (OH_AI_TrainCfgHandle train_cfg, size_t * num )

Description

Obtains the list of loss functions, which are used only for on-device training.

Since: 11

Parameters

NameDescription
train_cfgPointer to the training configuration object.
numNumber of loss functions.

Returns

List of loss functions.

OH_AI_TrainCfgGetOptimizationLevel()

OH_AI_API OH_AI_OptimizationLevel OH_AI_TrainCfgGetOptimizationLevel (OH_AI_TrainCfgHandle train_cfg)

Description

Obtains the optimization level of the training configuration object. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
train_cfgPointer to the training configuration object.

Returns

Optimization level.

OH_AI_TrainCfgSetLossName()

OH_AI_API void OH_AI_TrainCfgSetLossName (OH_AI_TrainCfgHandle train_cfg, const char ** loss_name, size_t num )

Description

Sets the list of loss functions, which are used only for on-device training.

Since: 11

Parameters

NameDescription
train_cfgPointer to the training configuration object.
loss_nameList of loss functions.
numNumber of loss functions.

OH_AI_TrainCfgSetOptimizationLevel()

OH_AI_API void OH_AI_TrainCfgSetOptimizationLevel (OH_AI_TrainCfgHandle train_cfg, OH_AI_OptimizationLevel level )

Description

Sets the optimization level of the training configuration object. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
train_cfgPointer to the training configuration object.
levelOptimization level.

OH_AI_TrainModelBuild()

OH_AI_API OH_AI_Status OH_AI_TrainModelBuild (OH_AI_ModelHandle model, const void * model_data, size_t data_size, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context, const OH_AI_TrainCfgHandle train_cfg )

Description

Loads a training model from the memory buffer and compiles the model to a state ready for running on the device. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
model_dataPointer to the buffer for storing the model file to be read.
data_sizeBuffer size.
model_typeModel file type, which is specified by OH_AI_ModelType.
model_contextModel runtime context, which is specified by OH_AI_ContextHandle.
train_cfgPointer to the training configuration object.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

OH_AI_TrainModelBuildFromFile()

OH_AI_API OH_AI_Status OH_AI_TrainModelBuildFromFile (OH_AI_ModelHandle model, const char * model_path, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context, const OH_AI_TrainCfgHandle train_cfg )

Description

Loads the training model from the specified path and compiles the model to a state ready for running on the device. This API is used only for on-device training.

Since: 11

Parameters

NameDescription
modelPointer to the model object.
model_pathPath of the model file.
model_typeModel file type, which is specified by OH_AI_ModelType.
model_contextModel runtime context, which is specified by OH_AI_ContextHandle.
train_cfgPointer to the training configuration object.

Returns

Status code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙MindSpore Lite Kit

harmony 鸿蒙OH_AI_CallBackParam

harmony 鸿蒙OH_AI_ShapeInfo

harmony 鸿蒙OH_AI_TensorHandleArray

harmony 鸿蒙context.h

harmony 鸿蒙data_type.h

harmony 鸿蒙format.h

harmony 鸿蒙@ohos.ai.mindSporeLite (On-device AI Framework)

harmony 鸿蒙model.h

harmony 鸿蒙status.h

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/r0zEoV