• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# MindSpore
2
3
4## Overview
5
6Provides APIs related to MindSpore Lite model inference.
7
8\@Syscap SystemCapability.Ai.MindSpore
9
10**Since**
11
129
13
14
15## Summary
16
17
18### Files
19
20| Name                           | Description                                                        |
21| ------------------------------- | ------------------------------------------------------------ |
22| [context.h](context_8h.md)      | Provides **Context** APIs for configuring runtime information.<br>File to include: \<mindspore/context.h><br>Library: libmindspore_lite_ndk.so|
23| [data_type.h](data__type_8h.md) | Declares tensor data types.<br>File to include: \<mindspore/data_type.h><br>Library: libmindspore_lite_ndk.so|
24| [format.h](format_8h.md)        | Declares tensor data formats.<br>File to include: \<mindspore/format.h><br>Library: libmindspore_lite_ndk.so|
25| [model.h](model_8h.md)          | Provides model-related APIs for model creation and inference.<br>File to include: \<mindspore/model.h><br>Library: libmindspore_lite_ndk.so|
26| [status.h](status_8h.md)        | Provides the status codes of MindSpore Lite.<br>File to include: \<mindspore/status.h><br>Library: libmindspore_lite_ndk.so|
27| [tensor.h](tensor_8h.md)        | Provides APIs for creating and modifying tensor information.<br>File to include: \<mindspore/tensor.h><br>Library: libmindspore_lite_ndk.so|
28| [types.h](types_8h.md)          | Provides the model file types and device types supported by MindSpore Lite.<br>File to include: \<mindspore/types.h><br>Library: libmindspore_lite_ndk.so|
29
30
31### Structs
32
33| Name                                                        | Description                                                |
34| ------------------------------------------------------------ | ---------------------------------------------------- |
35| [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) | Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.|
36| [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md)                | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.        |
37| [OH_AI_CallBackParam](_o_h___a_i___call_back_param.md)       | Defines the operator information passed in a callback.                          |
38
39
40### Macro Definition
41
42| Name                                            | Description                                        |
43| ------------------------------------------------ | -------------------------------------------- |
44| [OH_AI_MAX_SHAPE_NUM](#oh_ai_max_shape_num)   32 | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.|
45
46
47### Types
48
49| Name                                                        | Description                                              |
50| ------------------------------------------------------------ | -------------------------------------------------- |
51| [OH_AI_ContextHandle](#oh_ai_contexthandle)                  | Defines the pointer to the MindSpore context. |
52| [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle)            | Defines the pointer to the MindSpore device information.                   |
53| [OH_AI_DataType](#oh_ai_datatype)                            | Declares data types supported by MSTensor.                    |
54| [OH_AI_Format](#oh_ai_format)                                | Declares data formats supported by MSTensor.                |
55| [OH_AI_ModelHandle](#oh_ai_modelhandle)                      | Defines the pointer to a model object.                              |
56| [OH_AI_TensorHandleArray](#oh_ai_tensorhandlearray)          | Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.|
57| [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md)                | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.          |
58| [OH_AI_CallBackParam](#oh_ai_callbackparam)                  | Defines the operator information passed in a callback.                        |
59| [OH_AI_KernelCallBack](#oh_ai_kernelcallback) | Defines the pointer to a callback.                                    |
60| [OH_AI_Status](#oh_ai_status)                                | Defines MindSpore status codes.                                |
61| [OH_AI_TensorHandle](#oh_ai_tensorhandle)                    | Defines the handle of a tensor object.                                |
62| [OH_AI_ModelType](#oh_ai_modeltype)                          | Defines model file types.                                  |
63| [OH_AI_DeviceType](#oh_ai_devicetype)                        | Defines the supported device types.          |
64| [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype)                | Defines NNRt device types.                            |
65| [OH_AI_PerformanceMode](#oh_ai_performancemode)              | Defines performance modes of the NNRt device.                            |
66| [OH_AI_Priority](#oh_ai_priority)                            | Defines NNRt inference task priorities.                                |
67| [NNRTDeviceDesc](#nnrtdevicedesc)                            | Defines the NNRt device information, including the device ID and device name.    |
68
69
70### Enums
71
72| Name                                                        | Description                                    |
73| ------------------------------------------------------------ | ---------------------------------------- |
74| [OH_AI_DataType](#oh_ai_datatype-1) {<br>OH_AI_DATATYPE_UNKNOWN = 0, <br>OH_AI_DATATYPE_OBJECTTYPE_STRING = 12, <br>OH_AI_DATATYPE_OBJECTTYPE_LIST = 13, <br>OH_AI_DATATYPE_OBJECTTYPE_TUPLE = 14,<br>OH_AI_DATATYPE_OBJECTTYPE_TENSOR = 17, <br>OH_AI_DATATYPE_NUMBERTYPE_BEGIN = 29,<br> OH_AI_DATATYPE_NUMBERTYPE_BOOL = 30,<br> OH_AI_DATATYPE_NUMBERTYPE_INT8 = 32,<br>OH_AI_DATATYPE_NUMBERTYPE_INT16 = 33, <br>OH_AI_DATATYPE_NUMBERTYPE_INT32 = 34, <br>OH_AI_DATATYPE_NUMBERTYPE_INT64 = 35, <br>OH_AI_DATATYPE_NUMBERTYPE_UINT8 = 37,<br>OH_AI_DATATYPE_NUMBERTYPE_UINT16 = 38, <br>OH_AI_DATATYPE_NUMBERTYPE_UINT32 = 39,<br> OH_AI_DATATYPE_NUMBERTYPE_UINT64 = 40, <br>OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 = 42,<br>OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 = 43, <br>OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 = 44, <br>OH_AI_DATATYPE_NUMBERTYPE_END = 46,<br> OH_AI_DataTypeInvalid = INT32_MAX<br>} | Declares data types supported by MSTensor.          |
75| [OH_AI_Format](#oh_ai_format-1) {<br>OH_AI_FORMAT_NCHW = 0,<br> OH_AI_FORMAT_NHWC = 1, <br>OH_AI_FORMAT_NHWC4 = 2, <br>OH_AI_FORMAT_HWKC = 3,<br>OH_AI_FORMAT_HWCK = 4, <br>OH_AI_FORMAT_KCHW = 5, <br>OH_AI_FORMAT_CKHW = 6,<br> OH_AI_FORMAT_KHWC = 7,<br>OH_AI_FORMAT_CHWK = 8,<br> OH_AI_FORMAT_HW = 9, <br>OH_AI_FORMAT_HW4 = 10,<br> OH_AI_FORMAT_NC = 11,<br>OH_AI_FORMAT_NC4 = 12, <br>OH_AI_FORMAT_NC4HW4 = 13, <br>OH_AI_FORMAT_NCDHW = 15,<br> OH_AI_FORMAT_NWC = 16,<br>OH_AI_FORMAT_NCW = 17<br>} | Declares data formats supported by MSTensor.      |
76| [OH_AI_CompCode](#oh_ai_compcode) { <br>OH_AI_COMPCODE_CORE = 0x00000000u, <br>OH_AI_COMPCODE_LITE = 0xF0000000u<br> } | Defines MindSpore component codes.                 |
77| [OH_AI_Status](#oh_ai_status-1) {<br>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 &amp; -1), OH_AI_STATUS_LITE_NULLPTR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -2),<br>OH_AI_STATUS_LITE_PARAM_INVALID = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -3), OH_AI_STATUS_LITE_NO_CHANGE = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -4), OH_AI_STATUS_LITE_SUCCESS_EXIT = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -5), OH_AI_STATUS_LITE_MEMORY_FAILED = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -6),<br>OH_AI_STATUS_LITE_NOT_SUPPORT = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -7), OH_AI_STATUS_LITE_THREADPOOL_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -8), OH_AI_STATUS_LITE_UNINITIALIZED_OBJ = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -9), OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -100),<br>OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR, OH_AI_STATUS_LITE_REENTRANT_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -102), OH_AI_STATUS_LITE_GRAPH_FILE_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -200), OH_AI_STATUS_LITE_NOT_FIND_OP = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -300),<br>OH_AI_STATUS_LITE_INVALID_OP_NAME = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -301), OH_AI_STATUS_LITE_INVALID_OP_ATTR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -302), OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE, OH_AI_STATUS_LITE_FORMAT_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -400),<br>OH_AI_STATUS_LITE_INFER_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -500), OH_AI_STATUS_LITE_INFER_INVALID, OH_AI_STATUS_LITE_INPUT_PARAM_INVALID<br>} | Defines MindSpore status codes.                      |
78| [OH_AI_ModelType](#oh_ai_modeltype-1) { <br>OH_AI_MODELTYPE_MINDIR = 0, <br>OH_AI_MODELTYPE_INVALID = 0xFFFFFFFF <br>} | Defines model file types.                        |
79| [OH_AI_DeviceType](#oh_ai_devicetype-1) {<br>OH_AI_DEVICETYPE_CPU = 0, <br>OH_AI_DEVICETYPE_GPU, <br>OH_AI_DEVICETYPE_KIRIN_NPU, <br>OH_AI_DEVICETYPE_NNRT = 60,<br>OH_AI_DEVICETYPE_INVALID = 100<br>} | Defines the supported device types.|
80| [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype-1) { <br>OH_AI_NNRTDEVICE_OTHERS = 0, <br>OH_AI_NNRTDEVICE_CPU = 1, <br>OH_AI_NNRTDEVICE_GPU = 2, <br>OH_AI_NNRTDEVICE_ACCELERATOR = 3<br> } | Defines NNRt device types.                |
81| [OH_AI_PerformanceMode](#oh_ai_performancemode-1) {<br>OH_AI_PERFORMANCE_NONE = 0, <br>OH_AI_PERFORMANCE_LOW = 1, <br>OH_AI_PERFORMANCE_MEDIUM = 2,<br> OH_AI_PERFORMANCE_HIGH = 3,<br>OH_AI_PERFORMANCE_EXTREME = 4<br>} | Defines performance modes of the NNRt device.                |
82| [OH_AI_Priority](#oh_ai_priority-1) { <br>OH_AI_PRIORITY_NONE = 0, <br>OH_AI_PRIORITY_LOW = 1, <br>OH_AI_PRIORITY_MEDIUM = 2, <br>OH_AI_PRIORITY_HIGH = 3 <br>} | Defines NNRt inference task priorities.                    |
83
84
85### Functions
86
87| Name                                                        | Description                                                        |
88| ------------------------------------------------------------ | ------------------------------------------------------------ |
89| [OH_AI_ContextCreate](#oh_ai_contextcreate) ()               | Creates a context object.                                      |
90| [OH_AI_ContextDestroy](#oh_ai_contextdestroy) ([OH_AI_ContextHandle](#oh_ai_contexthandle) \*context) | Destroys a context object.                                            |
91| [OH_AI_ContextSetThreadNum](#oh_ai_contextsetthreadnum) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, int32_t thread_num) | Sets the number of runtime threads.                                      |
92| [OH_AI_ContextGetThreadNum](#oh_ai_contextgetthreadnum) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Obtains the number of threads.                                              |
93| [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) ([OH_AI_ContextHandle](#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.|
94| [OH_AI_ContextGetThreadAffinityMode](#oh_ai_contextgetthreadaffinitymode) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Obtains the affinity mode for binding runtime threads to CPU cores.                           |
95| [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, const int32_t \*core_list, size_t core_num) | Sets the list of CPU cores bound to a runtime thread.                           |
96| [OH_AI_ContextGetThreadAffinityCoreList](#oh_ai_contextgetthreadaffinitycorelist) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context, size_t \*core_num) | Obtains the list of bound CPU cores.                                           |
97| [OH_AI_ContextSetEnableParallel](#oh_ai_contextsetenableparallel) ([OH_AI_ContextHandle](#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.                                    |
98| [OH_AI_ContextGetEnableParallel](#oh_ai_contextgetenableparallel) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Checks whether parallelism between operators is supported.                                    |
99| [OH_AI_ContextAddDeviceInfo](#oh_ai_contextadddeviceinfo) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Attaches the custom device information to the inference context.                                          |
100| [OH_AI_DeviceInfoCreate](#oh_ai_deviceinfocreate) ([OH_AI_DeviceType](#oh_ai_devicetype) device_type) | Creates a device information object.                                      |
101| [OH_AI_DeviceInfoDestroy](#oh_ai_deviceinfodestroy) ([OH_AI_DeviceInfoHandle](#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.                                          |
102| [OH_AI_DeviceInfoSetProvider](#oh_ai_deviceinfosetprovider) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*provider) | Sets the provider name.                                          |
103| [OH_AI_DeviceInfoGetProvider](#oh_ai_deviceinfogetprovider) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the provider name.                                          |
104| [OH_AI_DeviceInfoSetProviderDevice](#oh_ai_deviceinfosetproviderdevice) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*device) | Sets the name of a provider device.                                      |
105| [OH_AI_DeviceInfoGetProviderDevice](#oh_ai_deviceinfogetproviderdevice) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the name of a provider device.                                      |
106| [OH_AI_DeviceInfoGetDeviceType](#oh_ai_deviceinfogetdevicetype) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the device type.                                            |
107| [OH_AI_DeviceInfoSetEnableFP16](#oh_ai_deviceinfosetenablefp16) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, bool is_fp16) | Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.            |
108| [OH_AI_DeviceInfoGetEnableFP16](#oh_ai_deviceinfogetenablefp16) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.            |
109| [OH_AI_DeviceInfoSetFrequency](#oh_ai_deviceinfosetfrequency) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, int frequency) | Sets the NPU frequency type. This function is available only for NPU devices.                              |
110| [OH_AI_DeviceInfoGetFrequency](#oh_ai_deviceinfogetfrequency) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the NPU frequency type. This function is available only for NPU devices.                          |
111| [OH_AI_GetAllNNRTDeviceDescs](#oh_ai_getallnnrtdevicedescs) (size_t \*num) | Obtains the descriptions of all NNRt devices in the system.                      |
112| [OH_AI_GetElementOfNNRTDeviceDescs](#oh_ai_getelementofnnrtdevicedescs) (NNRTDeviceDesc \*descs, size_t index) | Obtains the pointer to an element in the NNRt device description array.|
113| [OH_AI_DestroyAllNNRTDeviceDescs](#oh_ai_destroyallnnrtdevicedescs) ([NNRTDeviceDesc](#nnrtdevicedesc) \*\*desc) | Destroys the NNRt device description array obtained by [OH_AI_GetAllNNRTDeviceDescs](#oh_ai_getallnnrtdevicedescs).|
114| [OH_AI_GetDeviceIdFromNNRTDeviceDesc](#oh_ai_getdeviceidfromnnrtdevicedesc) (const [NNRTDeviceDesc](#nnrtdevicedesc) \*desc) | Obtains the NNRt device ID from the specified NNRt device description. Note that this ID is valid only for NNRt devices.|
115| [OH_AI_GetNameFromNNRTDeviceDesc](#oh_ai_getnamefromnnrtdevicedesc) (const [NNRTDeviceDesc](#nnrtdevicedesc) \*desc) | Obtains the NNRt device name from the specified NNRt device description.              |
116| [OH_AI_GetTypeFromNNRTDeviceDesc](#oh_ai_gettypefromnnrtdevicedesc) (const [NNRTDeviceDesc](#nnrtdevicedesc) \*desc) | Obtains the NNRt device type from the specified NNRt device description.              |
117| [OH_AI_CreateNNRTDeviceInfoByName](#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.|
118| [OH_AI_CreateNNRTDeviceInfoByType](#oh_ai_creatennrtdeviceinfobytype) ([OH_AI_NNRTDeviceType](#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.|
119| [OH_AI_DeviceInfoSetDeviceId](#oh_ai_deviceinfosetdeviceid) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, size_t device_id) | Sets the ID of an NNRt device. This function is available only for NNRt devices.                            |
120| [OH_AI_DeviceInfoGetDeviceId](#oh_ai_deviceinfogetdeviceid) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the ID of an NNRt device. This function is available only for NNRt devices.                            |
121| [OH_AI_DeviceInfoSetPerformanceMode](#oh_ai_deviceinfosetperformancemode) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, [OH_AI_PerformanceMode](#oh_ai_performancemode) mode) | Sets the performance mode of an NNRt device. This function is available only for NNRt devices.                          |
122| [OH_AI_DeviceInfoGetPerformanceMode](#oh_ai_deviceinfogetperformancemode) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the performance mode of an NNRt device. This function is available only for NNRt devices.                          |
123| [OH_AI_DeviceInfoSetPriority](#oh_ai_deviceinfosetpriority) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, [OH_AI_Priority](#oh_ai_priority) priority) | Sets the priority of an NNRt task. This function is available only for NNRt devices.                        |
124| [OH_AI_DeviceInfoGetPriority](#oh_ai_deviceinfogetpriority) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the priority of an NNRt task. This function is available only for NNRt devices.                        |
125| [OH_AI_ModelCreate](#oh_ai_modelcreate) ()                   | Creates a model object.                                          |
126| [OH_AI_ModelDestroy](#oh_ai_modeldestroy) ([OH_AI_ModelHandle](#oh_ai_modelhandle) \*model) | Destroys a model object.                                          |
127| [OH_AI_ModelBuild](#oh_ai_modelbuild) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const void \*model_data, size_t data_size, [OH_AI_ModelType](#oh_ai_modeltype) model_type, const [OH_AI_ContextHandle](#oh_ai_contexthandle) model_context) | Loads and builds a MindSpore model from the memory buffer.                       |
128| [OH_AI_ModelBuildFromFile](#oh_ai_modelbuildfromfile) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*model_path, [OH_AI_ModelType](#oh_ai_modeltype) model_type, const [OH_AI_ContextHandle](#oh_ai_contexthandle) model_context) | Loads and builds a MindSpore model from a model file.                       |
129| [OH_AI_ModelResize](#oh_ai_modelresize) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md) \*shape_infos, size_t shape_info_num) | Adjusts the input tensor shapes of a built model.                                  |
130| [OH_AI_ModelPredict](#oh_ai_modelpredict) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) \*outputs, const [OH_AI_KernelCallBack](#oh_ai_kernelcallback) before, const [OH_AI_KernelCallBack](#oh_ai_kernelcallback) after) | Performs model inference.                                              |
131| [OH_AI_ModelGetInputs](#oh_ai_modelgetinputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the input tensor array structure of a model.                              |
132| [OH_AI_ModelGetOutputs](#oh_ai_modelgetoutputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the output tensor array structure of a model.                              |
133| [OH_AI_ModelGetInputByTensorName](#oh_ai_modelgetinputbytensorname) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*tensor_name) | Obtains the input tensor of a model by tensor name.                              |
134| [OH_AI_ModelGetOutputByTensorName](#oh_ai_modelgetoutputbytensorname) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*tensor_name) | Obtains the output tensor of a model by tensor name.                              |
135| [OH_AI_DeviceInfoAddExtension](#oh_ai_deviceinfoaddextension) ([OH_AI_DeviceInfoHandle](#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 device information.|
136| [OH_AI_TensorCreate](#oh_ai_tensorcreate) (const char \*name, [OH_AI_DataType](#oh_ai_datatype) type, const int64_t \*shape, size_t shape_num, const void \*data, size_t data_len) | Creates a tensor object.                                          |
137| [OH_AI_TensorDestroy](#oh_ai_tensordestroy) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) \*tensor) | Destroys a tensor object.                                              |
138| [OH_AI_TensorClone](#oh_ai_tensorclone) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Clones a tensor.                                            |
139| [OH_AI_TensorSetName](#oh_ai_tensorsetname) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const char \*name) | Sets the tensor name.                                            |
140| [OH_AI_TensorGetName](#oh_ai_tensorgetname) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor name.                                            |
141| [OH_AI_TensorSetDataType](#oh_ai_tensorsetdatatype) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, [OH_AI_DataType](#oh_ai_datatype) type) | Sets the data type of a tensor.                                        |
142| [OH_AI_TensorGetDataType](#oh_ai_tensorgetdatatype) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor type.                                              |
143| [OH_AI_TensorSetShape](#oh_ai_tensorsetshape) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const int64_t \*shape, size_t shape_num) | Sets the tensor shape.                                            |
144| [OH_AI_TensorGetShape](#oh_ai_tensorgetshape) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, size_t \*shape_num) | Obtains the tensor shape.                                            |
145| [OH_AI_TensorSetFormat](#oh_ai_tensorsetformat) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, [OH_AI_Format](#oh_ai_format) format) | Sets the tensor data format.                                    |
146| [OH_AI_TensorGetFormat](#oh_ai_tensorgetformat) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor data format.                                    |
147| [OH_AI_TensorSetData](#oh_ai_tensorsetdata) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, void \*data) | Sets the tensor data.                                            |
148| [OH_AI_TensorGetData](#oh_ai_tensorgetdata) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the pointer to tensor data.                                        |
149| [OH_AI_TensorGetMutableData](#oh_ai_tensorgetmutabledata) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.          |
150| [OH_AI_TensorGetElementNum](#oh_ai_tensorgetelementnum) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of tensor elements.                                          |
151| [OH_AI_TensorGetDataSize](#oh_ai_tensorgetdatasize) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of bytes of the tensor data.                              |
152| [OH_AI_TensorSetUserData](#oh_ai_tensorsetuserdata) ([OH_AI_TensorHandle](#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.|
153
154## Macro Description
155
156
157### OH_AI_MAX_SHAPE_NUM
158
159
160```
161#define OH_AI_MAX_SHAPE_NUM   32
162```
163
164**Description**
165
166Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.
167
168
169## Type Description
170
171
172### NNRTDeviceDesc
173
174
175```
176typedef struct NNRTDeviceDesc NNRTDeviceDesc
177```
178
179**Description**
180
181Defines the NNRt device information, including the device ID and device name.
182
183**Since**
184
18510
186
187
188### OH_AI_CallBackParam
189
190
191```
192typedef struct OH_AI_CallBackParam OH_AI_CallBackParam
193```
194
195**Description**
196
197Defines the operator information passed in a callback.
198
199
200### OH_AI_ContextHandle
201
202
203```
204typedef void* OH_AI_ContextHandle
205```
206
207**Description**
208
209Defines the pointer to the MindSpore context.
210
211
212### OH_AI_DataType
213
214
215```
216typedef enum OH_AI_DataType OH_AI_DataType
217```
218
219**Description**
220
221Declares data types supported by MSTensor.
222
223
224### OH_AI_DeviceInfoHandle
225
226
227```
228typedef void* OH_AI_DeviceInfoHandle
229```
230
231**Description**
232
233Defines the pointer to the MindSpore device information.
234
235
236### OH_AI_DeviceType
237
238
239```
240typedef enum OH_AI_DeviceType OH_AI_DeviceType
241```
242
243**Description**
244
245Defines the supported device types.
246
247
248### OH_AI_Format
249
250
251```
252typedef enum OH_AI_Format OH_AI_Format
253```
254
255**Description**
256
257Declares data formats supported by MSTensor.
258
259
260### OH_AI_KernelCallBack
261
262
263```
264typedef bool(* OH_AI_KernelCallBack) (const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs, const OH_AI_CallBackParam kernel_Info)
265```
266
267**Description**
268
269Defines the pointer to a callback.
270
271This pointer is used to set the two callback functions in [OH_AI_ModelPredict](#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.
272
273
274### OH_AI_ModelHandle
275
276
277```
278typedef void* OH_AI_ModelHandle
279```
280
281**Description**
282
283Defines the pointer to a model object.
284
285
286### OH_AI_ModelType
287
288
289```
290typedef enum OH_AI_ModelType OH_AI_ModelType
291```
292
293**Description**
294
295Defines model file types.
296
297
298### OH_AI_NNRTDeviceType
299
300
301```
302typedef enum OH_AI_NNRTDeviceType OH_AI_NNRTDeviceType
303```
304
305**Description**
306
307Defines NNRt device types.
308
309**Since**
310
31110
312
313
314### OH_AI_PerformanceMode
315
316
317```
318typedef enum OH_AI_PerformanceMode OH_AI_PerformanceMode
319```
320
321**Description**
322
323Defines performance modes of the NNRt device.
324
325**Since**
326
32710
328
329
330### OH_AI_Priority
331
332
333```
334typedef enum OH_AI_Priority OH_AI_Priority
335```
336
337**Description**
338
339Defines NNRt inference task priorities.
340
341**Since**
342
34310
344
345
346### OH_AI_Status
347
348
349```
350typedef enum OH_AI_Status OH_AI_Status
351```
352
353**Description**
354
355Defines MindSpore status codes.
356
357
358### OH_AI_TensorHandle
359
360
361```
362typedef void* OH_AI_TensorHandle
363```
364
365**Description**
366
367Defines the handle of a tensor object.
368
369
370### OH_AI_TensorHandleArray
371
372
373```
374typedef struct OH_AI_TensorHandleArray OH_AI_TensorHandleArray
375```
376
377**Description**
378
379Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.
380
381
382## Enum Description
383
384
385### OH_AI_CompCode
386
387
388```
389enum OH_AI_CompCode
390```
391
392**Description**
393
394Defines MindSpore component codes.
395
396| Value             | Description                 |
397| ------------------- | --------------------- |
398| OH_AI_COMPCODE_CORE | MindSpore Core code|
399| OH_AI_COMPCODE_LITE | MindSpore Lite code|
400
401
402### OH_AI_DataType
403
404
405```
406enum OH_AI_DataType
407```
408
409**Description**
410
411Declares data types supported by MSTensor.
412
413| Value                           | Description                  |
414| --------------------------------- | ---------------------- |
415| OH_AI_DATATYPE_UNKNOWN            | Unknown data type.      |
416| OH_AI_DATATYPE_OBJECTTYPE_STRING  | String data.      |
417| OH_AI_DATATYPE_OBJECTTYPE_LIST    | List data.        |
418| OH_AI_DATATYPE_OBJECTTYPE_TUPLE   | Tuple data.       |
419| OH_AI_DATATYPE_OBJECTTYPE_TENSOR  | TensorList data.  |
420| OH_AI_DATATYPE_NUMBERTYPE_BEGIN   | Beginning of the number type.    |
421| OH_AI_DATATYPE_NUMBERTYPE_BOOL    | Bool data.        |
422| OH_AI_DATATYPE_NUMBERTYPE_INT8    | Int8 data.        |
423| OH_AI_DATATYPE_NUMBERTYPE_INT16   | Int16 data.   |
424| OH_AI_DATATYPE_NUMBERTYPE_INT32   | Int32 data.   |
425| OH_AI_DATATYPE_NUMBERTYPE_INT64   | Int64 data.   |
426| OH_AI_DATATYPE_NUMBERTYPE_UINT8   | UInt8 data.   |
427| OH_AI_DATATYPE_NUMBERTYPE_UINT16  | UInt16 data.  |
428| OH_AI_DATATYPE_NUMBERTYPE_UINT32  | UInt32 data.  |
429| OH_AI_DATATYPE_NUMBERTYPE_UINT64  | UInt64 data.  |
430| OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 | Float16 data. |
431| OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 | Float32 data. |
432| OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 | Float64 data. |
433| OH_AI_DATATYPE_NUMBERTYPE_END     | End of the number type.|
434| OH_AI_DataTypeInvalid             | Invalid data type.  |
435
436
437### OH_AI_DeviceType
438
439
440```
441enum OH_AI_DeviceType
442```
443
444**Description**
445
446Defines the supported device types.
447
448| Value                    | Description                                   |
449| -------------------------- | --------------------------------------- |
450| OH_AI_DEVICETYPE_CPU       | Device type: CPU                        |
451| OH_AI_DEVICETYPE_GPU       | Device type: GPU Reserved   |
452| OH_AI_DEVICETYPE_KIRIN_NPU | Device type: Kirin NPU Reserved|
453| OH_AI_DEVICETYPE_NNRT      | Device type: NNRt OHOS device range: [60, 80)|
454| OH_AI_DEVICETYPE_INVALID   | Invalid device type                         |
455
456
457### OH_AI_Format
458
459
460```
461enum OH_AI_Format
462```
463
464**Description**
465
466Declares data formats supported by MSTensor.
467
468| Value             | Description            |
469| ------------------- | ---------------- |
470| OH_AI_FORMAT_NCHW   | Tensor data is stored in the sequence of batch number N, channel C, height H, and width W.  |
471| OH_AI_FORMAT_NHWC   | Tensor data is stored in the sequence of batch number N, height H, width W, and channel C.  |
472| OH_AI_FORMAT_NHWC4  | Tensor data is stored in the sequence of batch number N, height H, width W, and channel C. The C axis is 4-byte aligned.  |
473| OH_AI_FORMAT_HWKC   | Tensor data is stored in the sequence of height H, width W, core count K, and channel C.   |
474| OH_AI_FORMAT_HWCK   | Tensor data is stored in the sequence of height H, width W, channel C, and core count K.  |
475| OH_AI_FORMAT_KCHW   | Tensor data is stored in the sequence of core count K, channel C, height H, and width W.  |
476| OH_AI_FORMAT_CKHW   | Tensor data is stored in the sequence of channel C, core count K, height H, and width W.  |
477| OH_AI_FORMAT_KHWC   | Tensor data is stored in the sequence of core count K, height H, width W, and channel C.   |
478| OH_AI_FORMAT_CHWK   | Tensor data is stored in the sequence of channel C, height H, width W, and core count K.  |
479| OH_AI_FORMAT_HW     | Tensor data is stored in the sequence of height H and width W.    |
480| OH_AI_FORMAT_HW4    | Tensor data is stored in the sequence of height H and width W. The W axis is 4-byte aligned.   |
481| OH_AI_FORMAT_NC     | Tensor data is stored in the sequence of batch number N and channel C.    |
482| OH_AI_FORMAT_NC4    | Tensor data is stored in the sequence of batch number N and channel C. The C axis is 4-byte aligned.    |
483| OH_AI_FORMAT_NC4HW4 | Tensor 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.|
484| OH_AI_FORMAT_NCDHW  | Tensor data is stored in the sequence of batch number N, channel C, depth D, height H, and width W. |
485| OH_AI_FORMAT_NWC    | Tensor data is stored in the sequence of batch number N, width W, and channel C.   |
486| OH_AI_FORMAT_NCW    | Tensor data is stored in the sequence of batch number N, channel C, and width W.   |
487
488
489### OH_AI_ModelType
490
491
492```
493enum OH_AI_ModelType
494```
495
496**Description**
497
498Defines model file types.
499
500| Value                 | Description              |
501| ----------------------- | ------------------ |
502| OH_AI_MODELTYPE_MINDIR  | Model type of MindIR. The extension of the model file name is **.ms**.|
503| OH_AI_MODELTYPE_INVALID | Invalid model type.    |
504
505
506### OH_AI_NNRTDeviceType
507
508
509```
510enum OH_AI_NNRTDeviceType
511```
512
513**Description**
514
515Defines NNRt device types.
516
517**Since**
518
51910
520
521| Value                      | Description                               |
522| ---------------------------- | ----------------------------------- |
523| OH_AI_NNRTDEVICE_OTHERS      | Others (any device type except the following three types).|
524| OH_AI_NNRTDEVICE_CPU         | CPU.                          |
525| OH_AI_NNRTDEVICE_GPU         | GPU.                          |
526| OH_AI_NNRTDEVICE_ACCELERATOR | Specific acceleration device.                   |
527
528
529### OH_AI_PerformanceMode
530
531
532```
533enum OH_AI_PerformanceMode
534```
535
536**Description**
537
538Defines performance modes of the NNRt device.
539
540**Since**
541
54210
543
544| Value                   | Description               |
545| ------------------------- | ------------------- |
546| OH_AI_PERFORMANCE_NONE    | No special settings.       |
547| OH_AI_PERFORMANCE_LOW     | Low power consumption.       |
548| OH_AI_PERFORMANCE_MEDIUM  | Power consumption and performance balancing.|
549| OH_AI_PERFORMANCE_HIGH    | High performance.       |
550| OH_AI_PERFORMANCE_EXTREME | Ultimate performance.     |
551
552
553### OH_AI_Priority
554
555
556```
557enum OH_AI_Priority
558```
559
560**Description**
561
562Defines NNRt inference task priorities.
563
564**Since**
565
56610
567
568| Value               | Description          |
569| --------------------- | -------------- |
570| OH_AI_PRIORITY_NONE   | No priority preference.|
571| OH_AI_PRIORITY_LOW    | Low priority.|
572| OH_AI_PRIORITY_MEDIUM | Medium priority|
573| OH_AI_PRIORITY_HIGH   | High priority.    |
574
575
576### OH_AI_Status
577
578
579```
580enum OH_AI_Status
581```
582
583**Description**
584
585Defines MindSpore status codes.
586
587| Value                               | Description                                     |
588| ------------------------------------- | ----------------------------------------- |
589| OH_AI_STATUS_SUCCESS                  | Success.                       |
590| OH_AI_STATUS_CORE_FAILED              | MindSpore Core failure.              |
591| OH_AI_STATUS_LITE_ERROR               | MindSpore Lite error.              |
592| OH_AI_STATUS_LITE_NULLPTR             | MindSpore Lite null pointer.            |
593| OH_AI_STATUS_LITE_PARAM_INVALID       | MindSpore Lite invalid parameters.          |
594| OH_AI_STATUS_LITE_NO_CHANGE           | MindSpore Lite no change.            |
595| OH_AI_STATUS_LITE_SUCCESS_EXIT        | MindSpore Lite exit without errors.|
596| OH_AI_STATUS_LITE_MEMORY_FAILED       | MindSpore Lite memory allocation failure.    |
597| OH_AI_STATUS_LITE_NOT_SUPPORT         | MindSpore Lite not supported.      |
598| OH_AI_STATUS_LITE_THREADPOOL_ERROR    | MindSpore Lite thread pool error.        |
599| OH_AI_STATUS_LITE_UNINITIALIZED_OBJ   | MindSpore Lite uninitialized.          |
600| OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE | MindSpore Lite tensor overflow.    |
601| OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR  | MindSpore Lite input tensor error.    |
602| OH_AI_STATUS_LITE_REENTRANT_ERROR     | MindSpore Lite reentry error.        |
603| OH_AI_STATUS_LITE_GRAPH_FILE_ERROR    | MindSpore Lite file error.          |
604| OH_AI_STATUS_LITE_NOT_FIND_OP         | MindSpore Lite operator not found.      |
605| OH_AI_STATUS_LITE_INVALID_OP_NAME     | MindSpore Lite invalid operators.          |
606| OH_AI_STATUS_LITE_INVALID_OP_ATTR     | MindSpore Lite invalid operator hyperparameters.    |
607| OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE  | MindSpore Lite operator execution failure.    |
608| OH_AI_STATUS_LITE_FORMAT_ERROR        | MindSpore Lite tensor format error.      |
609| OH_AI_STATUS_LITE_INFER_ERROR         | MindSpore Lite shape inference error.      |
610| OH_AI_STATUS_LITE_INFER_INVALID       | MindSpore Lite invalid shape inference.  |
611| OH_AI_STATUS_LITE_INPUT_PARAM_INVALID | MindSpore Lite invalid input parameters.|
612
613## Function Description
614
615
616### OH_AI_ContextAddDeviceInfo()
617
618
619```
620OH_AI_API void OH_AI_ContextAddDeviceInfo (OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info )
621```
622
623**Description**
624
625Attaches the custom device information to the inference context.
626
627**Parameters**
628
629| Name       | Description                                                        |
630| ----------- | ------------------------------------------------------------ |
631| context     | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
632| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
633
634
635### OH_AI_ContextCreate()
636
637
638```
639OH_AI_API OH_AI_ContextHandle OH_AI_ContextCreate ()
640```
641
642**Description**
643
644Creates a context object.
645
646**Returns**
647
648[OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.
649
650
651### OH_AI_ContextDestroy()
652
653
654```
655OH_AI_API void OH_AI_ContextDestroy (OH_AI_ContextHandle * context)
656```
657
658**Description**
659
660Destroys a context object.
661
662**Parameters**
663
664| Name   | Description                                                        |
665| ------- | ------------------------------------------------------------ |
666| context | Level-2 pointer to [OH_AI_ContextHandle](#oh_ai_contexthandle). After the context is destroyed, the pointer is set to null. |
667
668
669### OH_AI_ContextGetEnableParallel()
670
671
672```
673OH_AI_API bool OH_AI_ContextGetEnableParallel (const OH_AI_ContextHandle context)
674```
675
676**Description**
677
678Checks whether parallelism between operators is supported.
679
680**Parameters**
681
682| Name   | Description                                                        |
683| ------- | ------------------------------------------------------------ |
684| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
685
686**Returns**
687
688Whether parallelism between operators is supported. The value **true** means that parallelism between operators is supported, and the value **false** means the opposite.
689
690
691### OH_AI_ContextGetThreadAffinityCoreList()
692
693
694```
695OH_AI_API const int32_t* OH_AI_ContextGetThreadAffinityCoreList (const OH_AI_ContextHandle context, size_t * core_num )
696```
697
698**Description**
699
700Obtains the list of bound CPU cores.
701
702**Parameters**
703
704| Name    | Description                                                        |
705| -------- | ------------------------------------------------------------ |
706| context  | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
707| core_num | Number of CPU cores.                            |
708
709**Returns**
710
711Specifies the CPU core binding list. This list is managed by [OH_AI_ContextHandle](#oh_ai_contexthandle). The caller does not need to destroy it manually.
712
713
714### OH_AI_ContextGetThreadAffinityMode()
715
716
717```
718OH_AI_API int OH_AI_ContextGetThreadAffinityMode (const OH_AI_ContextHandle context)
719```
720
721**Description**
722
723Obtains the affinity mode for binding runtime threads to CPU cores.
724
725**Parameters**
726
727| Name   | Description                                                        |
728| ------- | ------------------------------------------------------------ |
729| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
730
731**Returns**
732
733Affinity mode. **0**: no affinities; **1**: big cores first; **2**: medium cores first
734
735
736### OH_AI_ContextGetThreadNum()
737
738
739```
740OH_AI_API int32_t OH_AI_ContextGetThreadNum (const OH_AI_ContextHandle context)
741```
742
743**Description**
744
745Obtains the number of threads.
746
747**Parameters**
748
749| Name   | Description                                                        |
750| ------- | ------------------------------------------------------------ |
751| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
752
753**Returns**
754
755Number of threads.
756
757
758### OH_AI_ContextSetEnableParallel()
759
760
761```
762OH_AI_API void OH_AI_ContextSetEnableParallel (OH_AI_ContextHandle context, bool is_parallel )
763```
764
765**Description**
766
767Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available.
768
769**Parameters**
770
771| Name       | Description                                                        |
772| ----------- | ------------------------------------------------------------ |
773| context     | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
774| is_parallel | Whether parallelism between operators is supported. The value **true** means that parallelism between operators is supported, and the value **false** means the opposite.         |
775
776
777### OH_AI_ContextSetThreadAffinityCoreList()
778
779
780```
781OH_AI_API void OH_AI_ContextSetThreadAffinityCoreList (OH_AI_ContextHandle context, const int32_t * core_list, size_t core_num )
782```
783
784**Description**
785
786Sets the list of CPU cores bound to a runtime thread.
787
788For example, if **core_list** is set to **[2,6,8]**, threads run on the 2nd, 6th, and 8th CPU cores. If [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) and [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) are called for the same context object, the **core_list** parameter of [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) takes effect, but the **mode** parameter of [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) does not.
789
790**Parameters**
791
792| Name     | Description                                                        |
793| --------- | ------------------------------------------------------------ |
794| context   | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
795| core_list | List of bound CPU cores.                                             |
796| core_num  | Number of cores, which indicates the length of **core_list**.                     |
797
798
799### OH_AI_ContextSetThreadAffinityMode()
800
801
802```
803OH_AI_API void OH_AI_ContextSetThreadAffinityMode (OH_AI_ContextHandle context, int mode )
804```
805
806**Description**
807
808Sets 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.
809
810**Parameters**
811
812| Name   | Description                                                        |
813| ------- | ------------------------------------------------------------ |
814| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
815| mode    | Affinity mode. **0**: no affinities; **1**: big cores first; **2**: medium cores first|
816
817
818### OH_AI_ContextSetThreadNum()
819
820
821```
822OH_AI_API void OH_AI_ContextSetThreadNum (OH_AI_ContextHandle context, int32_t thread_num )
823```
824
825**Description**
826
827Sets the number of runtime threads.
828
829**Parameters**
830
831| Name      | Description                                                        |
832| ---------- | ------------------------------------------------------------ |
833| context    | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
834| thread_num | Number of runtime threads.                                          |
835
836
837### OH_AI_CreateNNRTDeviceInfoByName()
838
839
840```
841OH_AI_API OH_AI_DeviceInfoHandle OH_AI_CreateNNRTDeviceInfoByName (const char * name)
842```
843
844**Description**
845
846Searches for the NNRt device with the specified name and creates the NNRt device information based on the information about the first found NNRt device.
847
848**Parameters**
849
850| Name| Description            |
851| ---- | ---------------- |
852| name | Name of the NNRt device.|
853
854**Returns**
855
856[OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.
857
858**Since**
859
86010
861
862
863### OH_AI_CreateNNRTDeviceInfoByType()
864
865
866```
867OH_AI_API OH_AI_DeviceInfoHandle OH_AI_CreateNNRTDeviceInfoByType (OH_AI_NNRTDeviceType type)
868```
869
870**Description**
871
872Searches for the NNRt device with the specified type and creates the NNRt device information based on the information about the first found NNRt device.
873
874**Parameters**
875
876| Name| Description                                                        |
877| ---- | ------------------------------------------------------------ |
878| type | NNRt device type, which is specified by [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype).|
879
880**Returns**
881
882[OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.
883
884**Since**
885
88610
887
888
889### OH_AI_DestroyAllNNRTDeviceDescs()
890
891
892```
893OH_AI_API void OH_AI_DestroyAllNNRTDeviceDescs (NNRTDeviceDesc ** desc)
894```
895
896**Description**
897
898Destroys the NNRt device description array obtained by [OH_AI_GetAllNNRTDeviceDescs](#oh_ai_getallnnrtdevicedescs).
899
900**Parameters**
901
902| Name| Description                                                        |
903| ---- | ------------------------------------------------------------ |
904| desc | Double pointer to the array of the NNRt device descriptions. After the operation is complete, the content pointed to by **desc** is set to **NULL**.|
905
906**Since**
907
90810
909
910
911### OH_AI_DeviceInfoCreate()
912
913
914```
915OH_AI_API OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate (OH_AI_DeviceType device_type)
916```
917
918**Description**
919
920Creates a device information object.
921
922**Parameters**
923
924| Name       | Description                                                   |
925| ----------- | ------------------------------------------------------- |
926| device_type | Device type, which is specified by [OH_AI_DeviceType](#oh_ai_devicetype).|
927
928**Returns**
929
930[OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.
931
932
933### OH_AI_DeviceInfoDestroy()
934
935
936```
937OH_AI_API void OH_AI_DeviceInfoDestroy (OH_AI_DeviceInfoHandle * device_info)
938```
939
940**Description**
941
942Destroys a device information object. Note: After the device information instance is added to the context, the caller does not need to destroy it manually.
943
944**Parameters**
945
946| Name       | Description                                                        |
947| ----------- | ------------------------------------------------------------ |
948| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
949
950
951### OH_AI_DeviceInfoGetDeviceId()
952
953
954```
955OH_AI_API size_t OH_AI_DeviceInfoGetDeviceId (const OH_AI_DeviceInfoHandle device_info)
956```
957
958**Description**
959
960Obtains the ID of an NNRt device. This function is available only for NNRt devices.
961
962**Parameters**
963
964| Name       | Description                                                        |
965| ----------- | ------------------------------------------------------------ |
966| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
967
968**Returns**
969
970NNRt device ID.
971
972**Since**
973
97410
975
976
977### OH_AI_DeviceInfoGetDeviceType()
978
979
980```
981OH_AI_API OH_AI_DeviceType OH_AI_DeviceInfoGetDeviceType (const OH_AI_DeviceInfoHandle device_info)
982```
983
984**Description**
985
986Obtains the device type.
987
988**Parameters**
989
990| Name       | Description                                                        |
991| ----------- | ------------------------------------------------------------ |
992| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
993
994**Returns**
995
996Type of the provider device.
997
998
999### OH_AI_DeviceInfoGetEnableFP16()
1000
1001
1002```
1003OH_AI_API bool OH_AI_DeviceInfoGetEnableFP16 (const OH_AI_DeviceInfoHandle device_info)
1004```
1005
1006**Description**
1007
1008Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.
1009
1010**Parameters**
1011
1012| Name       | Description                                                        |
1013| ----------- | ------------------------------------------------------------ |
1014| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1015
1016**Returns**
1017
1018Whether float16 inference is enabled.
1019
1020
1021### OH_AI_DeviceInfoGetFrequency()
1022
1023
1024```
1025OH_AI_API int OH_AI_DeviceInfoGetFrequency (const OH_AI_DeviceInfoHandle device_info)
1026```
1027
1028**Description**
1029
1030Obtains the NPU frequency type. This function is available only for NPU devices.
1031
1032**Parameters**
1033
1034| Name       | Description                                                        |
1035| ----------- | ------------------------------------------------------------ |
1036| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1037
1038**Returns**
1039
1040NPU frequency type. The value ranges from **0** to **4**. **1**: low power consumption; **2**: balanced; **3**: high performance; **4**: ultra-high performance
1041
1042
1043### OH_AI_DeviceInfoGetPerformanceMode()
1044
1045
1046```
1047OH_AI_API OH_AI_PerformanceMode OH_AI_DeviceInfoGetPerformanceMode (const OH_AI_DeviceInfoHandle device_info)
1048```
1049
1050**Description**
1051
1052Obtains the performance mode of an NNRt device. This function is available only for NNRt devices.
1053
1054**Parameters**
1055
1056| Name       | Description                                                        |
1057| ----------- | ------------------------------------------------------------ |
1058| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1059
1060**Returns**
1061
1062NNRt performance mode, which is specified by [OH_AI_PerformanceMode](#oh_ai_performancemode).
1063
1064**Since**
1065
106610
1067
1068
1069### OH_AI_DeviceInfoGetPriority()
1070
1071
1072```
1073OH_AI_API OH_AI_Priority OH_AI_DeviceInfoGetPriority (const OH_AI_DeviceInfoHandle device_info)
1074```
1075
1076**Description**
1077
1078Obtains the priority of an NNRt task. This function is available only for NNRt devices.
1079
1080**Parameters**
1081
1082| Name       | Description                                                        |
1083| ----------- | ------------------------------------------------------------ |
1084| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1085
1086**Returns**
1087
1088NNRt task priority, which is specified by [OH_AI_Priority](#oh_ai_priority).
1089
1090**Since**
1091
109210
1093
1094
1095### OH_AI_DeviceInfoGetProvider()
1096
1097
1098```
1099OH_AI_API const char* OH_AI_DeviceInfoGetProvider (const OH_AI_DeviceInfoHandle device_info)
1100```
1101
1102**Description**
1103
1104Obtains the provider name.
1105
1106**Parameters**
1107
1108| Name       | Description                                                        |
1109| ----------- | ------------------------------------------------------------ |
1110| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1111
1112**Returns**
1113
1114Provider name.
1115
1116
1117### OH_AI_DeviceInfoGetProviderDevice()
1118
1119
1120```
1121OH_AI_API const char* OH_AI_DeviceInfoGetProviderDevice (const OH_AI_DeviceInfoHandle device_info)
1122```
1123
1124**Description**
1125
1126Obtains the name of a provider device.
1127
1128**Parameters**
1129
1130| Name       | Description                                                        |
1131| ----------- | ------------------------------------------------------------ |
1132| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1133
1134**Returns**
1135
1136Name of the provider device.
1137
1138
1139### OH_AI_DeviceInfoSetDeviceId()
1140
1141
1142```
1143OH_AI_API void OH_AI_DeviceInfoSetDeviceId (OH_AI_DeviceInfoHandle device_info, size_t device_id )
1144```
1145
1146**Description**
1147
1148Sets the ID of an NNRt device. This function is available only for NNRt devices.
1149
1150**Parameters**
1151
1152| Name       | Description                                                        |
1153| ----------- | ------------------------------------------------------------ |
1154| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1155| device_id   | NNRt device ID.                                                |
1156
1157**Since**
1158
115910
1160
1161
1162### OH_AI_DeviceInfoSetEnableFP16()
1163
1164
1165```
1166OH_AI_API void OH_AI_DeviceInfoSetEnableFP16 (OH_AI_DeviceInfoHandle device_info, bool is_fp16 )
1167```
1168
1169**Description**
1170
1171Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.
1172
1173**Parameters**
1174
1175| Name       | Description                                                        |
1176| ----------- | ------------------------------------------------------------ |
1177| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1178| is_fp16     | Whether to enable the float16 inference mode.                                   |
1179
1180
1181### OH_AI_DeviceInfoSetFrequency()
1182
1183
1184```
1185OH_AI_API void OH_AI_DeviceInfoSetFrequency (OH_AI_DeviceInfoHandle device_info, int frequency )
1186```
1187
1188**Description**
1189
1190Sets the NPU frequency type. This function is available only for NPU devices.
1191
1192**Parameters**
1193
1194| Name       | Description                                                        |
1195| ----------- | ------------------------------------------------------------ |
1196| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1197| frequency   | NPU 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|
1198
1199
1200### OH_AI_DeviceInfoSetPerformanceMode()
1201
1202
1203```
1204OH_AI_API void OH_AI_DeviceInfoSetPerformanceMode (OH_AI_DeviceInfoHandle device_info, OH_AI_PerformanceMode mode )
1205```
1206
1207**Description**
1208
1209Sets the performance mode of an NNRt device. This function is available only for NNRt devices.
1210
1211**Parameters**
1212
1213| Name       | Description                                                        |
1214| ----------- | ------------------------------------------------------------ |
1215| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1216| mode        | NNRt performance mode, which is specified by [OH_AI_PerformanceMode](#oh_ai_performancemode).|
1217
1218**Since**
1219
122010
1221
1222
1223### OH_AI_DeviceInfoSetPriority()
1224
1225
1226```
1227OH_AI_API void OH_AI_DeviceInfoSetPriority (OH_AI_DeviceInfoHandle device_info, OH_AI_Priority priority )
1228```
1229
1230**Description**
1231
1232Sets the priority of an NNRt task. This function is available only for NNRt devices.
1233
1234**Parameters**
1235
1236| Name       | Description                                                        |
1237| ----------- | ------------------------------------------------------------ |
1238| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1239| priority    | NNRt task priority, which is specified by [OH_AI_Priority](#oh_ai_priority).          |
1240
1241**Since**
1242
124310
1244
1245
1246### OH_AI_DeviceInfoSetProvider()
1247
1248
1249```
1250OH_AI_API void OH_AI_DeviceInfoSetProvider (OH_AI_DeviceInfoHandle device_info, const char * provider )
1251```
1252
1253**Description**
1254
1255Sets the provider name.
1256
1257**Parameters**
1258
1259| Name       | Description                                                        |
1260| ----------- | ------------------------------------------------------------ |
1261| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1262| provider    | Provider name.                                              |
1263
1264
1265### OH_AI_DeviceInfoSetProviderDevice()
1266
1267
1268```
1269OH_AI_API void OH_AI_DeviceInfoSetProviderDevice (OH_AI_DeviceInfoHandle device_info, const char * device )
1270```
1271
1272**Description**
1273
1274Sets the name of a provider device.
1275
1276**Parameters**
1277
1278| Name       | Description                                                        |
1279| ----------- | ------------------------------------------------------------ |
1280| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
1281| device      | Name of the provider device, for example, CPU.                                 |
1282
1283
1284### OH_AI_GetAllNNRTDeviceDescs()
1285
1286
1287```
1288OH_AI_API NNRTDeviceDesc* OH_AI_GetAllNNRTDeviceDescs (size_t * num)
1289```
1290
1291**Description**
1292
1293Obtains the descriptions of all NNRt devices in the system.
1294
1295**Parameters**
1296
1297| Name| Description                    |
1298| ---- | ------------------------ |
1299| num  | Number of NNRt devices.|
1300
1301**Returns**
1302
1303Pointer to the array of the NNRt device descriptions. If the operation fails, **NULL** is returned.
1304
1305**Since**
1306
130710
1308
1309
1310### OH_AI_GetDeviceIdFromNNRTDeviceDesc()
1311
1312
1313```
1314OH_AI_API size_t OH_AI_GetDeviceIdFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)
1315```
1316
1317**Description**
1318
1319Obtains the NNRt device ID from the specified NNRt device description. Note that this ID is valid only for NNRt devices.
1320
1321**Parameters**
1322
1323| Name| Description                            |
1324| ---- | -------------------------------- |
1325| desc | Pointer to the NNRt device description.|
1326
1327**Returns**
1328
1329NNRt device ID.
1330
1331**Since**
1332
133310
1334
1335
1336### OH_AI_GetNameFromNNRTDeviceDesc()
1337
1338
1339```
1340OH_AI_API const char* OH_AI_GetNameFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)
1341```
1342
1343**Description**
1344
1345Obtains the NNRt device name from the specified NNRt device description.
1346
1347**Parameters**
1348
1349| Name| Description                            |
1350| ---- | -------------------------------- |
1351| desc | Pointer to the NNRt device description.|
1352
1353**Returns**
1354
1355NNRt 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.
1356
1357**Since**
1358
135910
1360
1361
1362### OH_AI_GetTypeFromNNRTDeviceDesc()
1363
1364
1365```
1366OH_AI_API OH_AI_NNRTDeviceType OH_AI_GetTypeFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)
1367```
1368
1369**Description**
1370
1371Obtains the NNRt device type from the specified NNRt device description.
1372
1373**Parameters**
1374
1375| Name| Description                            |
1376| ---- | -------------------------------- |
1377| desc | Pointer to the NNRt device description.|
1378
1379**Returns**
1380
1381NNRt device type, which is specified by [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype).
1382
1383**Since**
1384
138510
1386
1387
1388### OH_AI_ModelBuild()
1389
1390
1391```
1392OH_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 )
1393```
1394
1395**Description**
1396
1397Loads and builds a MindSpore model from the memory buffer.
1398
1399Note 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.
1400
1401**Parameters**
1402
1403| Name         | Description                                                        |
1404| ------------- | ------------------------------------------------------------ |
1405| model         | Pointer to the model object.                                              |
1406| model_data    | Address of the loaded model data in the memory.                              |
1407| data_size     | Length of the model data.                                            |
1408| model_type    | Model file type, which is specified by [OH_AI_ModelType](#oh_ai_modeltype).   |
1409| model_context | Model runtime context, which is specified by [OH_AI_ContextHandle](#oh_ai_contexthandle).|
1410
1411**Returns**
1412
1413Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
1414
1415
1416### OH_AI_ModelBuildFromFile()
1417
1418
1419```
1420OH_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 )
1421```
1422
1423**Description**
1424
1425Loads and builds a MindSpore model from a model file.
1426
1427Note 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.
1428
1429**Parameters**
1430
1431| Name         | Description                                                        |
1432| ------------- | ------------------------------------------------------------ |
1433| model         | Pointer to the model object.                                              |
1434| model_path    | Path of the model file.                                              |
1435| model_type    | Model file type, which is specified by [OH_AI_ModelType](#oh_ai_modeltype).   |
1436| model_context | Model runtime context, which is specified by [OH_AI_ContextHandle](#oh_ai_contexthandle).|
1437
1438**Returns**
1439
1440Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
1441
1442
1443### OH_AI_ModelCreate()
1444
1445
1446```
1447OH_AI_API OH_AI_ModelHandle OH_AI_ModelCreate ()
1448```
1449
1450**Description**
1451
1452Creates a model object.
1453
1454**Returns**
1455
1456Pointer to the model object.
1457
1458
1459### OH_AI_ModelDestroy()
1460
1461
1462```
1463OH_AI_API void OH_AI_ModelDestroy (OH_AI_ModelHandle * model)
1464```
1465
1466**Description**
1467
1468Destroys a model object.
1469
1470**Parameters**
1471
1472| Name | Description          |
1473| ----- | -------------- |
1474| model | Pointer to the model object.|
1475
1476
1477### OH_AI_ModelGetInputByTensorName()
1478
1479
1480```
1481OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetInputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )
1482```
1483
1484**Description**
1485
1486Obtains the input tensor of a model by tensor name.
1487
1488**Parameters**
1489
1490| Name       | Description          |
1491| ----------- | -------------- |
1492| model       | Pointer to the model object.|
1493| tensor_name | Tensor name.    |
1494
1495**Returns**
1496
1497Pointer to the input tensor indicated by **tensor_name**. If the tensor does not exist in the input, **null** will be returned.
1498
1499
1500### OH_AI_ModelGetInputs()
1501
1502
1503```
1504OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetInputs (const OH_AI_ModelHandle model)
1505```
1506
1507**Description**
1508
1509Obtains the input tensor array structure of a model.
1510
1511**Parameters**
1512
1513| Name | Description          |
1514| ----- | -------------- |
1515| model | Pointer to the model object.|
1516
1517**Returns**
1518
1519Tensor array structure corresponding to the model input.
1520
1521
1522### OH_AI_ModelGetOutputByTensorName()
1523
1524
1525```
1526OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetOutputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )
1527```
1528
1529**Description**
1530
1531Obtains the output tensor of a model by tensor name.
1532
1533**Parameters**
1534
1535| Name       | Description          |
1536| ----------- | -------------- |
1537| model       | Pointer to the model object.|
1538| tensor_name | Tensor name.    |
1539
1540**Returns**
1541
1542Pointer to the input tensor indicated by **tensor_name**. If the tensor does not exist, **null** will be returned.
1543
1544
1545### OH_AI_ModelGetOutputs()
1546
1547
1548```
1549OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetOutputs (const OH_AI_ModelHandle model)
1550```
1551
1552**Description**
1553
1554Obtains the output tensor array structure of a model.
1555
1556**Parameters**
1557
1558| Name | Description          |
1559| ----- | -------------- |
1560| model | Pointer to the model object.|
1561
1562**Returns**
1563
1564Tensor array structure corresponding to the model output.
1565
1566
1567### OH_AI_ModelPredict()
1568
1569
1570```
1571OH_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 )
1572```
1573
1574**Description**
1575
1576Performs model inference.
1577
1578**Parameters**
1579
1580| Name   | Description                                |
1581| ------- | ------------------------------------ |
1582| model   | Pointer to the model object.                      |
1583| inputs  | Tensor array structure corresponding to the model input.      |
1584| outputs | Pointer to the tensor array structure corresponding to the model output.|
1585| before  | Callback function executed before model inference.          |
1586| after   | Callback function executed after model inference.          |
1587
1588**Returns**
1589
1590Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
1591
1592
1593### OH_AI_ModelResize()
1594
1595
1596```
1597OH_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 )
1598```
1599
1600**Description**
1601
1602Adjusts the input tensor shapes of a built model.
1603
1604**Parameters**
1605
1606| Name          | Description                                                        |
1607| -------------- | ------------------------------------------------------------ |
1608| model          | Pointer to the model object.                                              |
1609| inputs         | Tensor array structure corresponding to the model input.                              |
1610| shape_infos    | Input shape information array, which consists of tensor shapes arranged in the model input sequence. The model adjusts the tensor shapes in sequence.|
1611| shape_info_num | Length of the shape information array.                                        |
1612
1613**Returns**
1614
1615Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
1616
1617
1618### OH_AI_TensorClone()
1619
1620
1621```
1622OH_AI_API OH_AI_TensorHandle OH_AI_TensorClone (OH_AI_TensorHandle tensor)
1623```
1624
1625**Description**
1626
1627Clones a tensor.
1628
1629**Parameters**
1630
1631| Name  | Description              |
1632| ------ | ------------------ |
1633| tensor | Pointer to the tensor to clone.|
1634
1635**Returns**
1636
1637Defines the handle of a tensor object.
1638
1639
1640### OH_AI_TensorCreate()
1641
1642
1643```
1644OH_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 )
1645```
1646
1647**Description**
1648
1649Creates a tensor object.
1650
1651**Parameters**
1652
1653| Name     | Description              |
1654| --------- | ------------------ |
1655| name      | Tensor name.          |
1656| type      | Tensor data type.    |
1657| shape     | Tensor dimension array.  |
1658| shape_num | Length of the tensor dimension array.|
1659| data      | Data pointer.  |
1660| data_len  | Data length.      |
1661
1662**Returns**
1663
1664Defines the handle of a tensor object.
1665
1666
1667### OH_AI_TensorDestroy()
1668
1669
1670```
1671OH_AI_API void OH_AI_TensorDestroy (OH_AI_TensorHandle * tensor)
1672```
1673
1674**Description**
1675
1676Destroys a tensor object.
1677
1678**Parameters**
1679
1680| Name  | Description                    |
1681| ------ | ------------------------ |
1682| tensor | Level-2 pointer to the tensor handle.|
1683
1684
1685### OH_AI_TensorGetData()
1686
1687
1688```
1689OH_AI_API const void* OH_AI_TensorGetData (const OH_AI_TensorHandle tensor)
1690```
1691
1692**Description**
1693
1694Obtains the pointer to tensor data.
1695
1696**Parameters**
1697
1698| Name  | Description          |
1699| ------ | -------------- |
1700| tensor | Handle of the tensor object.|
1701
1702**Returns**
1703
1704Pointer to tensor data.
1705
1706
1707### OH_AI_TensorGetDataSize()
1708
1709
1710```
1711OH_AI_API size_t OH_AI_TensorGetDataSize (const OH_AI_TensorHandle tensor)
1712```
1713
1714**Description**
1715
1716Obtains the number of bytes of the tensor data.
1717
1718**Parameters**
1719
1720| Name  | Description          |
1721| ------ | -------------- |
1722| tensor | Handle of the tensor object.|
1723
1724**Returns**
1725
1726Number of bytes of the tensor data.
1727
1728
1729### OH_AI_TensorGetDataType()
1730
1731
1732```
1733OH_AI_API OH_AI_DataType OH_AI_TensorGetDataType (const OH_AI_TensorHandle tensor)
1734```
1735
1736**Description**
1737
1738Obtains the tensor type.
1739
1740**Parameters**
1741
1742| Name  | Description          |
1743| ------ | -------------- |
1744| tensor | Handle of the tensor object.|
1745
1746**Returns**
1747
1748Tensor data type.
1749
1750
1751### OH_AI_TensorGetElementNum()
1752
1753
1754```
1755OH_AI_API int64_t OH_AI_TensorGetElementNum (const OH_AI_TensorHandle tensor)
1756```
1757
1758**Description**
1759
1760Obtains the number of tensor elements.
1761
1762**Parameters**
1763
1764| Name  | Description          |
1765| ------ | -------------- |
1766| tensor | Handle of the tensor object.|
1767
1768**Returns**
1769
1770Number of tensor elements.
1771
1772
1773### OH_AI_TensorGetFormat()
1774
1775
1776```
1777OH_AI_API OH_AI_Format OH_AI_TensorGetFormat (const OH_AI_TensorHandle tensor)
1778```
1779
1780**Description**
1781
1782Obtains the tensor data format.
1783
1784**Parameters**
1785
1786| Name  | Description          |
1787| ------ | -------------- |
1788| tensor | Handle of the tensor object.|
1789
1790**Returns**
1791
1792Tensor data format.
1793
1794
1795### OH_AI_TensorGetMutableData()
1796
1797
1798```
1799OH_AI_API void* OH_AI_TensorGetMutableData (const OH_AI_TensorHandle tensor)
1800```
1801
1802**Description**
1803
1804Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.
1805
1806**Parameters**
1807
1808| Name  | Description          |
1809| ------ | -------------- |
1810| tensor | Handle of the tensor object.|
1811
1812**Returns**
1813
1814Pointer to tensor data.
1815
1816
1817### OH_AI_TensorGetName()
1818
1819
1820```
1821OH_AI_API const char* OH_AI_TensorGetName (const OH_AI_TensorHandle tensor)
1822```
1823
1824**Description**
1825
1826Obtains the name of a tensor.
1827
1828**Parameters**
1829
1830| Name  | Description          |
1831| ------ | -------------- |
1832| tensor | Handle of the tensor object.|
1833
1834**Returns**
1835
1836Tensor name.
1837
1838
1839### OH_AI_TensorGetShape()
1840
1841
1842```
1843OH_AI_API const int64_t* OH_AI_TensorGetShape (const OH_AI_TensorHandle tensor, size_t * shape_num )
1844```
1845
1846**Description**
1847
1848Obtains the tensor shape.
1849
1850**Parameters**
1851
1852| Name     | Description                                          |
1853| --------- | ---------------------------------------------- |
1854| tensor    | Handle of the tensor object.                                |
1855| shape_num | Length of the tensor shape array.|
1856
1857**Returns**
1858
1859Shape array.
1860
1861
1862### OH_AI_TensorSetData()
1863
1864
1865```
1866OH_AI_API void OH_AI_TensorSetData (OH_AI_TensorHandle tensor, void * data )
1867```
1868
1869**Description**
1870
1871Sets the tensor data.
1872
1873**Parameters**
1874
1875| Name  | Description            |
1876| ------ | ---------------- |
1877| tensor | Handle of the tensor object.  |
1878| data   | Data pointer.|
1879
1880
1881### OH_AI_TensorSetDataType()
1882
1883
1884```
1885OH_AI_API void OH_AI_TensorSetDataType (OH_AI_TensorHandle tensor, OH_AI_DataType type )
1886```
1887
1888**Description**
1889
1890Sets the tensor data type.
1891
1892**Parameters**
1893
1894| Name  | Description                                               |
1895| ------ | --------------------------------------------------- |
1896| tensor | Handle of the tensor object.                                     |
1897| type   | Data type, which is specified by [OH_AI_DataType](#oh_ai_datatype).|
1898
1899
1900### OH_AI_TensorSetFormat()
1901
1902
1903```
1904OH_AI_API void OH_AI_TensorSetFormat (OH_AI_TensorHandle tensor, OH_AI_Format format )
1905```
1906
1907**Description**
1908
1909Sets the tensor data format.
1910
1911**Parameters**
1912
1913| Name  | Description              |
1914| ------ | ------------------ |
1915| tensor | Handle of the tensor object.    |
1916| format | Tensor data format.|
1917
1918
1919### OH_AI_TensorSetName()
1920
1921
1922```
1923OH_AI_API void OH_AI_TensorSetName (OH_AI_TensorHandle tensor, const char *name )
1924```
1925
1926**Description**
1927
1928Sets the tensor name.
1929
1930**Parameters**
1931
1932| Name  | Description          |
1933| ------ | -------------- |
1934| tensor | Handle of the tensor object.|
1935| name   | Tensor name.    |
1936
1937
1938### OH_AI_TensorSetShape()
1939
1940
1941```
1942OH_AI_API void OH_AI_TensorSetShape (OH_AI_TensorHandle tensor, const int64_t * shape, size_t shape_num )
1943```
1944
1945**Description**
1946
1947Sets the tensor shape.
1948
1949**Parameters**
1950
1951| Name     | Description              |
1952| --------- | ------------------ |
1953| tensor    | Handle of the tensor object.    |
1954| shape     | Shape array.        |
1955| shape_num | Length of the tensor shape array.|
1956
1957
1958### OH_AI_TensorSetUserData()
1959
1960```
1961OH_AI_API OH_AI_Status OH_AI_TensorSetUserData (OH_AI_TensorHandle tensor, void * data, size_t data_size )
1962```
1963
1964**Description**
1965
1966Sets the tensor as the user data.
1967
1968This function allows you to reuse user data as the model input, which helps to reduce data copy by one time.
1969
1970> **NOTE**<br>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.
1971
1972**Parameters**
1973
1974| Name| Description|
1975| -------- | -------- |
1976| tensor | Handle of the tensor object.|
1977| data | Start address of user data.|
1978| data_size | Length of the user data length.|
1979
1980**Returns**
1981
1982Execution status code. The value **OH_AI_STATUS_SUCCESS** indicates that the operation is successful. If the operation fails, an error code is returned.
1983
1984**Since**
1985
198610
1987
1988
1989### OH_AI_DeviceInfoAddExtension()
1990
1991```
1992OH_AI_API OH_AI_Status OH_AI_DeviceInfoAddExtension (OH_AI_DeviceInfoHandle device_info, const char * name, const char * value, size_t value_size )
1993```
1994
1995**Description**
1996
1997Adds extended configuration in the form of key/value pairs to the device information. This function is available only for NNRt device information.
1998
1999>**NOTE**<br>Key value pairs currently supported include {"CachePath": "YourCachePath"}, {"CacheVersion": "YourCacheVersion"}, and {"QuantParam": "YourQuantConfig"}. Replace the actual value as required.
2000
2001**Parameters**
2002
2003| Name| Description|
2004| -------- | -------- |
2005| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
2006| name | Key in an extended key/value pair. The value is a C string.|
2007| value |  Start address of the value in an extended key/value pair.|
2008| value_size | Length of the value in an extended key/value pair.|
2009
2010**Returns**
2011
2012Status 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.
2013
2014**Since**
2015
201610
2017
2018
2019### OH_AI_GetElementOfNNRTDeviceDescs()
2020
2021```
2022OH_AI_API NNRTDeviceDesc* OH_AI_GetElementOfNNRTDeviceDescs (NNRTDeviceDesc * descs, size_t index )
2023```
2024
2025**Description**
2026
2027Obtains the pointer to an element in the NNRt device description array.
2028
2029**Parameters**
2030
2031| Name| Description|
2032| -------- | -------- |
2033| descs | NNRt device description array.|
2034| index | Index of an array element.|
2035
2036**Returns**
2037
2038Pointer to an element in the NNRt device description array.
2039
2040**Since**
2041
204210
2043