• 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:**
119
12
13## Summary
14
15
16### Files
17
18| Name | Description |
19| -------- | -------- |
20| [context.h](context_8h.md) | Provides **Context** APIs for configuring runtime information. <br>File to Include: <mindspore/context.h> |
21| [data_type.h](data__type_8h.md) | Declares tensor data types. <br>File to Include: <mindspore/data_type.h> |
22| [format.h](format_8h.md) | Declares tensor data formats. <br>File to Include: <mindspore/format.h> |
23| [model.h](model_8h.md) | Provides model-related APIs for model creation and inference. <br>File to Include: <mindspore/model.h> |
24| [status.h](status_8h.md) | Provides the status codes of MindSpore Lite. <br>File to Include: <mindspore/status.h> |
25| [tensor.h](tensor_8h.md) | Provides APIs for creating and modifying tensor information. <br>File to Include: <mindspore/tensor.h> |
26| [types.h](types_8h.md) | Provides the model file types and device types supported by MindSpore Lite. <br>File to Include: <mindspore/types.h> |
27
28
29### Structs
30
31| Name | Description |
32| -------- | -------- |
33| [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.  |
34| [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md) | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. |
35| [OH_AI_CallBackParam](_o_h___a_i___call_back_param.md) | Defines the operator information passed in a callback.  |
36
37
38### Macros
39
40| Name | Description |
41| -------- | -------- |
42| [OH_AI_MAX_SHAPE_NUM](#oh_ai_max_shape_num)   32 | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.  |
43
44
45
46### Types
47
48| Name | Description |
49| -------- | -------- |
50| [OH_AI_ContextHandle](#oh_ai_contexthandle) | Defines the pointer to the MindSpore context.  |
51| [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) | Defines the pointer to the MindSpore device information.  |
52| [OH_AI_DataType](#oh_ai_datatype) | Declares data types supported by MSTensor.  |
53| [OH_AI_Format](#oh_ai_format) | Declares data formats supported by MSTensor.  |
54| [OH_AI_ModelHandle](#oh_ai_modelhandle) | Defines the pointer to a model object.  |
55| [OH_AI_TensorHandleArray](#oh_ai_tensorhandlearray) | Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.  |
56| **OH_AI_ShapeInfo** | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. |
57| [OH_AI_CallBackParam](#oh_ai_callbackparam) | Defines the operator information passed in a callback.  |
58| [OH_AI_KernelCallBack](#oh_ai_kernelcallback)) (const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) outputs, const [OH_AI_CallBackParam](_o_h___a_i___call_back_param.md) kernel_Info) | Defines the pointer to a callback.  |
59| [OH_AI_Status](#oh_ai_status) | Defines MindSpore status codes.  |
60| [OH_AI_TensorHandle](#oh_ai_tensorhandle) | Defines the handle of a tensor object.  |
61| [OH_AI_ModelType](#oh_ai_modeltype) | Defines model file types.  |
62| [OH_AI_DeviceType](#oh_ai_devicetype) | Defines the supported device types.  |
63
64
65### Enums
66
67| Name | Description |
68| -------- | -------- |
69| [OH_AI_DataType](#oh_ai_datatype) {<br/>OH_AI_DATATYPE_UNKNOWN = 0, OH_AI_DATATYPE_OBJECTTYPE_STRING = 12, OH_AI_DATATYPE_OBJECTTYPE_LIST = 13, OH_AI_DATATYPE_OBJECTTYPE_TUPLE = 14,<br/>OH_AI_DATATYPE_OBJECTTYPE_TENSOR = 17, OH_AI_DATATYPE_NUMBERTYPE_BEGIN = 29, OH_AI_DATATYPE_NUMBERTYPE_BOOL = 30, OH_AI_DATATYPE_NUMBERTYPE_INT8 = 32,<br/>OH_AI_DATATYPE_NUMBERTYPE_INT16 = 33, OH_AI_DATATYPE_NUMBERTYPE_INT32 = 34, OH_AI_DATATYPE_NUMBERTYPE_INT64 = 35, OH_AI_DATATYPE_NUMBERTYPE_UINT8 = 37,<br/>OH_AI_DATATYPE_NUMBERTYPE_UINT16 = 38, OH_AI_DATATYPE_NUMBERTYPE_UINT32 = 39, OH_AI_DATATYPE_NUMBERTYPE_UINT64 = 40, OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 = 42,<br/>OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 = 43, OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 = 44, OH_AI_DATATYPE_NUMBERTYPE_END = 46, OH_AI_DataTypeInvalid = INT32_MAX<br/>} | Declares data types supported by MSTensor.  |
70| [OH_AI_Format](#oh_ai_format) {<br/>OH_AI_FORMAT_NCHW = 0, OH_AI_FORMAT_NHWC = 1, OH_AI_FORMAT_NHWC4 = 2, OH_AI_FORMAT_HWKC = 3,<br/>OH_AI_FORMAT_HWCK = 4, OH_AI_FORMAT_KCHW = 5, OH_AI_FORMAT_CKHW = 6, OH_AI_FORMAT_KHWC = 7,<br/>OH_AI_FORMAT_CHWK = 8, OH_AI_FORMAT_HW = 9, OH_AI_FORMAT_HW4 = 10, OH_AI_FORMAT_NC = 11,<br/>OH_AI_FORMAT_NC4 = 12, OH_AI_FORMAT_NC4HW4 = 13, OH_AI_FORMAT_NCDHW = 15, OH_AI_FORMAT_NWC = 16,<br/>OH_AI_FORMAT_NCW = 17<br/>} | Declares data formats supported by MSTensor.  |
71| [OH_AI_CompCode](#oh_ai_compcode) { OH_AI_COMPCODE_CORE = 0x00000000u, OH_AI_COMPCODE_LITE = 0xF0000000u } | Defines MinSpore component codes.  |
72| [OH_AI_Status](#oh_ai_status) {<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.  |
73| [OH_AI_ModelType](#oh_ai_modeltype) { OH_AI_MODELTYPE_MINDIR = 0, OH_AI_MODELTYPE_INVALID = 0xFFFFFFFF } | Defines model file types.  |
74| [OH_AI_DeviceType](#oh_ai_devicetype) {<br/>OH_AI_DEVICETYPE_CPU = 0, OH_AI_DEVICETYPE_GPU, OH_AI_DEVICETYPE_KIRIN_NPU, OH_AI_DEVICETYPE_NNRT = 60,<br/>OH_AI_DEVICETYPE_INVALID = 100<br/>} | Defines the supported device types.  |
75
76
77### Functions
78
79| Name | Description |
80| -------- | -------- |
81| [OH_AI_ContextCreate](#oh_ai_contextcreate) () | Creates a context object.  |
82| [OH_AI_ContextDestroy](#oh_ai_contextdestroy) ([OH_AI_ContextHandle](#oh_ai_contexthandle) \*context) | Destroys a context object.  |
83| [OH_AI_ContextSetThreadNum](#oh_ai_contextsetthreadnum) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, int32_t thread_num) | Sets the number of runtime threads.  |
84| [OH_AI_ContextGetThreadNum](#oh_ai_contextgetthreadnum) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Obtains the number of threads.  |
85| [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 categorized into little cores and big cores depending on the CPU frequency.  |
86| [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.  |
87| [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.  |
88| [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.  |
89| [OH_AI_ContextSetEnableParallel](#oh_ai_contextsetenableparallel) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, bool is_parallel) | Sets whether to enable parallelism between operators.  |
90| [OH_AI_ContextGetEnableParallel](#oh_ai_contextgetenableparallel) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Checks whether parallelism between operators is supported.  |
91| [OH_AI_ContextAddDeviceInfo](#oh_ai_contextadddeviceinfo) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Adds information about a running device.  |
92| [OH_AI_DeviceInfoCreate](#oh_ai_deviceinfocreate) ([OH_AI_DeviceType](#oh_ai_devicetype) device_type) | Creates a device information object.  |
93| [OH_AI_DeviceInfoDestroy](#oh_ai_deviceinfodestroy) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) \*device_info) | Destroys a device information instance.  |
94| [OH_AI_DeviceInfoSetProvider](#oh_ai_deviceinfosetprovider) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*provider) | Sets the name of a provider.  |
95| [OH_AI_DeviceInfoGetProvider](#oh_ai_deviceinfogetprovider) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the provider name.  |
96| [OH_AI_DeviceInfoSetProviderDevice](#oh_ai_deviceinfosetproviderdevice) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*device) | Sets the name of a provider device.  |
97| [OH_AI_DeviceInfoGetProviderDevice](#oh_ai_deviceinfogetproviderdevice) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) |  Obtains the name of a provider device.  |
98| [OH_AI_DeviceInfoGetDeviceType](#oh_ai_deviceinfogetdevicetype) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the type of a provider device.  |
99| [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/GPU devices.  |
100| [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/GPU devices.  |
101| [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.  |
102| [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.  |
103| [OH_AI_ModelCreate](#oh_ai_modelcreate) () | Creates a model object.  |
104| [OH_AI_ModelDestroy](#oh_ai_modeldestroy) ([OH_AI_ModelHandle](#oh_ai_modelhandle) \*model) | Destroys a model object.  |
105| [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.  |
106| [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.  |
107| [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.  |
108| [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.  |
109| [OH_AI_ModelGetInputs](#oh_ai_modelgetinputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the input tensor array structure of a model.  |
110| [OH_AI_ModelGetOutputs](#oh_ai_modelgetoutputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the output tensor array structure of a model.  |
111| [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.  |
112| [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.  |
113| [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.  |
114| [OH_AI_TensorDestroy](#oh_ai_tensordestroy) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) \*tensor) | Destroys a tensor object.  |
115| [OH_AI_TensorClone](#oh_ai_tensorclone) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Clones a tensor.  |
116| [OH_AI_TensorSetName](#oh_ai_tensorsetname) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const char \*name) | Sets the name of a tensor.  |
117| [OH_AI_TensorGetName](#oh_ai_tensorgetname) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the name of a tensor.  |
118| [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.  |
119| [OH_AI_TensorGetDataType](#oh_ai_tensorgetdatatype) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the data type of a tensor.  |
120| [OH_AI_TensorSetShape](#oh_ai_tensorsetshape) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const int64_t \*shape, size_t shape_num) | Sets the shape of a tensor.  |
121| [OH_AI_TensorGetShape](#oh_ai_tensorgetshape) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, size_t \*shape_num) | Obtains the shape of a tensor.  |
122| [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.  |
123| [OH_AI_TensorGetFormat](#oh_ai_tensorgetformat) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor data format.  |
124| [OH_AI_TensorSetData](#oh_ai_tensorsetdata) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, void \*data) | Sets the tensor data.  |
125| [OH_AI_TensorGetData](#oh_ai_tensorgetdata) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the pointer to tensor data.  |
126| [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.  |
127| [OH_AI_TensorGetElementNum](#oh_ai_tensorgetelementnum) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of tensor elements.  |
128| [OH_AI_TensorGetDataSize](#oh_ai_tensorgetdatasize) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of bytes of the tensor data.  |
129
130
131## Macro Description
132
133
134### OH_AI_MAX_SHAPE_NUM
135
136
137```
138#define OH_AI_MAX_SHAPE_NUM   32
139```
140**Description**<br>
141Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.
142
143
144## Type Description
145
146
147### OH_AI_CallBackParam
148
149
150```
151typedef struct OH_AI_CallBackParamOH_AI_CallBackParam
152```
153**Description**<br>
154Defines the operator information passed in a callback.
155
156
157### OH_AI_ContextHandle
158
159
160```
161typedef void* OH_AI_ContextHandle
162```
163**Description**<br>
164Defines the pointer to the MindSpore context.
165
166
167### OH_AI_DataType
168
169
170```
171typedef enum OH_AI_DataTypeOH_AI_DataType
172```
173**Description**<br>
174Declares data types supported by MSTensor.
175
176
177### OH_AI_DeviceInfoHandle
178
179
180```
181typedef void* OH_AI_DeviceInfoHandle
182```
183**Description**<br>
184Defines the pointer to the MindSpore device information.
185
186
187### OH_AI_DeviceType
188
189
190```
191typedef enum OH_AI_DeviceTypeOH_AI_DeviceType
192```
193**Description**<br>
194Defines the supported device types.
195
196
197### OH_AI_Format
198
199
200```
201typedef enum OH_AI_FormatOH_AI_Format
202```
203**Description**<br>
204Declares data formats supported by MSTensor.
205
206
207### OH_AI_KernelCallBack
208
209
210```
211typedef bool(* OH_AI_KernelCallBack) (const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs, const OH_AI_CallBackParam kernel_Info)
212```
213**Description**<br>
214Defines the pointer to a callback.
215
216This 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.
217
218
219### OH_AI_ModelHandle
220
221
222```
223typedef void* OH_AI_ModelHandle
224```
225**Description**<br>
226Defines the pointer to a model object.
227
228
229### OH_AI_ModelType
230
231
232```
233typedef enum OH_AI_ModelTypeOH_AI_ModelType
234```
235**Description**<br>
236Defines model file types.
237
238
239### OH_AI_Status
240
241
242```
243typedef enum OH_AI_StatusOH_AI_Status
244```
245**Description**<br>
246Defines MindSpore status codes.
247
248
249### OH_AI_TensorHandle
250
251
252```
253typedef void* OH_AI_TensorHandle
254```
255**Description**<br>
256Defines the handle of a tensor object.
257
258
259### OH_AI_TensorHandleArray
260
261
262```
263typedef struct OH_AI_TensorHandleArrayOH_AI_TensorHandleArray
264```
265**Description**<br>
266Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.
267
268
269## Enum Description
270
271
272### OH_AI_CompCode
273
274
275```
276enum OH_AI_CompCode
277```
278**Description**<br>
279Defines MinSpore component codes.
280
281| Name | Description |
282| -------- | -------- |
283| OH_AI_COMPCODE_CORE  | MindSpore Core code |
284| OH_AI_COMPCODE_LITE  | MindSpore Lite code |
285
286
287### OH_AI_DataType
288
289
290```
291enum OH_AI_DataType
292```
293**Description**<br>
294Declares data types supported by MSTensor.
295
296| Name | Description |
297| -------- | -------- |
298| OH_AI_DATATYPE_UNKNOWN  | Unknown data type |
299| OH_AI_DATATYPE_OBJECTTYPE_STRING  | String data type |
300| OH_AI_DATATYPE_OBJECTTYPE_LIST  | List data type |
301| OH_AI_DATATYPE_OBJECTTYPE_TUPLE  | Tuple data type |
302| OH_AI_DATATYPE_OBJECTTYPE_TENSOR  | TensorList data type |
303| OH_AI_DATATYPE_NUMBERTYPE_BEGIN  | Beginning of the number type |
304| OH_AI_DATATYPE_NUMBERTYPE_BOOL  | Bool data type |
305| OH_AI_DATATYPE_NUMBERTYPE_INT8  | Int8 data type |
306| OH_AI_DATATYPE_NUMBERTYPE_INT16  | Int16 data type |
307| OH_AI_DATATYPE_NUMBERTYPE_INT32  | Int32 data type |
308| OH_AI_DATATYPE_NUMBERTYPE_INT64  | Int64 data type |
309| OH_AI_DATATYPE_NUMBERTYPE_UINT8  | UInt8 data type |
310| OH_AI_DATATYPE_NUMBERTYPE_UINT16  | UInt16 data type |
311| OH_AI_DATATYPE_NUMBERTYPE_UINT32  | UInt32 data type |
312| OH_AI_DATATYPE_NUMBERTYPE_UINT64  | UInt64 data type |
313| OH_AI_DATATYPE_NUMBERTYPE_FLOAT16  | Float16 data type |
314| OH_AI_DATATYPE_NUMBERTYPE_FLOAT32  | Float32 data type |
315| OH_AI_DATATYPE_NUMBERTYPE_FLOAT64  | Float64 data type |
316| OH_AI_DATATYPE_NUMBERTYPE_END  | End of the number type |
317| OH_AI_DataTypeInvalid  | Invalid data type |
318
319
320### OH_AI_DeviceType
321
322
323```
324enum OH_AI_DeviceType
325```
326**Description**<br>
327Defines the supported device types.
328
329| Name | Description |
330| -------- | -------- |
331| OH_AI_DEVICETYPE_CPU  | Device type: CPU<br/>since 9  |
332| OH_AI_DEVICETYPE_GPU  | Device type: GPU<br/>Reserved, not support yet.<br/>since 9  |
333| OH_AI_DEVICETYPE_KIRIN_NPU  | Device type: Kirin NPU<br/>Reserved, not support yet.<br/>since 9  |
334| OH_AI_DEVICETYPE_NNRT  | Device type: NNRt<br/>OHOS-only device range[60,80).<br/>since 9  |
335| OH_AI_DEVICETYPE_INVALID  | Invalid device type<br/>since 9  |
336
337
338### OH_AI_Format
339
340
341```
342enum OH_AI_Format
343```
344**Description**<br>
345Declares data formats supported by MSTensor.
346
347| Name | Description |
348| -------- | -------- |
349| OH_AI_FORMAT_NCHW  | NCHW format |
350| OH_AI_FORMAT_NHWC  | NHWC format |
351| OH_AI_FORMAT_NHWC4  | NHWC4 format |
352| OH_AI_FORMAT_HWKC  | HWKC format |
353| OH_AI_FORMAT_HWCK  | HWCK format |
354| OH_AI_FORMAT_KCHW  | KCHW format |
355| OH_AI_FORMAT_CKHW  | CKHW format |
356| OH_AI_FORMAT_KHWC  | KHWC format |
357| OH_AI_FORMAT_CHWK  | CHWK format |
358| OH_AI_FORMAT_HW  | HW format |
359| OH_AI_FORMAT_HW4  | HW4 format |
360| OH_AI_FORMAT_NC  | NC format |
361| OH_AI_FORMAT_NC4  | NC4 format |
362| OH_AI_FORMAT_NC4HW4  | NC4HW4 format |
363| OH_AI_FORMAT_NCDHW  | NCDHW format |
364| OH_AI_FORMAT_NWC  | NWC format |
365| OH_AI_FORMAT_NCW  | NCW format |
366
367
368### OH_AI_ModelType
369
370
371```
372enum OH_AI_ModelType
373```
374**Description**<br>
375Defines model file types.
376
377| Name | Description |
378| -------- | -------- |
379| OH_AI_MODELTYPE_MINDIR  | Model type: MindIR<br/>since 9  |
380| OH_AI_MODELTYPE_INVALID  | Invalid model type<br/>since 9  |
381
382
383### OH_AI_Status
384
385
386```
387enum OH_AI_Status
388```
389**Description**<br>
390Defines MindSpore status codes.
391
392| Name | Description |
393| -------- | -------- |
394| OH_AI_STATUS_SUCCESS  | Success |
395| OH_AI_STATUS_CORE_FAILED  | MindSpore Core failure |
396| OH_AI_STATUS_LITE_ERROR  | MindSpore Lite error |
397| OH_AI_STATUS_LITE_NULLPTR  | MindSpore Lite null pointer |
398| OH_AI_STATUS_LITE_PARAM_INVALID  | MindSpore Lite invalid parameters |
399| OH_AI_STATUS_LITE_NO_CHANGE  | MindSpore Lite no change |
400| OH_AI_STATUS_LITE_SUCCESS_EXIT  | MindSpore Lite exit without errors |
401| OH_AI_STATUS_LITE_MEMORY_FAILED  | MindSpore Lite memory allocation failure |
402| OH_AI_STATUS_LITE_NOT_SUPPORT  | MindSpore Lite not supported |
403| OH_AI_STATUS_LITE_THREADPOOL_ERROR  | MindSpore Lite thread pool error |
404| OH_AI_STATUS_LITE_UNINITIALIZED_OBJ  | MindSpore Lite uninitialized |
405| OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE  | MindSpore Lite tensor overflow |
406| OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR  | MindSpore Lite input tensor error |
407| OH_AI_STATUS_LITE_REENTRANT_ERROR  | MindSpore Lite reentry error |
408| OH_AI_STATUS_LITE_GRAPH_FILE_ERROR  | MindSpore Lite file error |
409| OH_AI_STATUS_LITE_NOT_FIND_OP  | MindSpore Lite operator not found |
410| OH_AI_STATUS_LITE_INVALID_OP_NAME  | MindSpore Lite invalid operators |
411| OH_AI_STATUS_LITE_INVALID_OP_ATTR  | MindSpore Lite invalid operator hyperparameters |
412| OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE  | MindSpore Lite operator execution failure |
413| OH_AI_STATUS_LITE_FORMAT_ERROR  | MindSpore Lite tensor format error |
414| OH_AI_STATUS_LITE_INFER_ERROR  | MindSpore Lite shape inference error |
415| OH_AI_STATUS_LITE_INFER_INVALID  | MindSpore Lite invalid shape inference |
416| OH_AI_STATUS_LITE_INPUT_PARAM_INVALID  | MindSpore Lite invalid input parameters |
417
418
419## Function Description
420
421
422### OH_AI_ContextAddDeviceInfo()
423
424
425```
426OH_AI_API void OH_AI_ContextAddDeviceInfo (OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info )
427```
428**Description**<br>
429Adds information about a running device.
430
431 **Parameters**
432
433| Name | Description |
434| -------- | -------- |
435| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
436| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
437
438
439### OH_AI_ContextCreate()
440
441
442```
443OH_AI_API OH_AI_ContextHandle OH_AI_ContextCreate ()
444```
445**Description**<br>
446Creates a context object.
447
448**Returns**
449
450[OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context.
451
452
453### OH_AI_ContextDestroy()
454
455
456```
457OH_AI_API void OH_AI_ContextDestroy (OH_AI_ContextHandle * context)
458```
459**Description**<br>
460Destroys a context object.
461
462 **Parameters**
463
464| Name | Description |
465| -------- | -------- |
466| context | Level-2 pointer to [OH_AI_ContextHandle](#oh_ai_contexthandle). After the context is destroyed, the pointer is set to null.  |
467
468
469### OH_AI_ContextGetEnableParallel()
470
471
472```
473OH_AI_API bool OH_AI_ContextGetEnableParallel (const OH_AI_ContextHandle context)
474```
475**Description**<br>
476Checks whether parallelism between operators is supported.
477
478 **Parameters**
479
480| Name | Description |
481| -------- | -------- |
482| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
483
484**Returns**
485
486Whether parallelism between operators is supported. The value **true** means that parallelism between operators is supported, and the value **false** means the opposite.
487
488
489### OH_AI_ContextGetThreadAffinityCoreList()
490
491
492```
493OH_AI_API const int32_t* OH_AI_ContextGetThreadAffinityCoreList (const OH_AI_ContextHandle context, size_t * core_num )
494```
495**Description**<br>
496Obtains the list of bound CPU cores.
497
498 **Parameters**
499
500| Name | Description |
501| -------- | -------- |
502| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
503| core_num | Number of CPU cores.  |
504
505**Returns**
506
507List of bound CPU cores.
508
509
510### OH_AI_ContextGetThreadAffinityMode()
511
512
513```
514OH_AI_API int OH_AI_ContextGetThreadAffinityMode (const OH_AI_ContextHandle context)
515```
516**Description**<br>
517Obtains the affinity mode for binding runtime threads to CPU cores.
518
519 **Parameters**
520
521| Name | Description |
522| -------- | -------- |
523| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
524
525**Returns**
526
527Affinity mode. **0**: no affinities; **1**: big cores first; **2**: little cores first
528
529
530### OH_AI_ContextGetThreadNum()
531
532
533```
534OH_AI_API int32_t OH_AI_ContextGetThreadNum (const OH_AI_ContextHandle context)
535```
536**Description**<br>
537Obtains the number of threads.
538
539 **Parameters**
540
541| Name | Description |
542| -------- | -------- |
543| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
544
545**Returns**
546
547Number of threads.
548
549
550### OH_AI_ContextSetEnableParallel()
551
552
553```
554OH_AI_API void OH_AI_ContextSetEnableParallel (OH_AI_ContextHandle context, bool is_parallel )
555```
556**Description**<br>
557Sets whether to enable parallelism between operators.
558
559 **Parameters**
560
561| Name | Description |
562| -------- | -------- |
563| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
564| is_parallel | Whether to enable parallelism between operators. The value **true** means to enable parallelism between operators, and the value **false** means the opposite.  |
565
566
567### OH_AI_ContextSetThreadAffinityCoreList()
568
569
570```
571OH_AI_API void OH_AI_ContextSetThreadAffinityCoreList (OH_AI_ContextHandle context, const int32_t * core_list, size_t core_num )
572```
573**Description**<br>
574Sets the list of CPU cores bound to a runtime thread.
575
576For 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.
577
578 **Parameters**
579
580| Name | Description |
581| -------- | -------- |
582| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
583| core_list | List of bound CPU cores.  |
584| core_num | Number of cores, which indicates the length of **core_list**.  |
585
586
587### OH_AI_ContextSetThreadAffinityMode()
588
589
590```
591OH_AI_API void OH_AI_ContextSetThreadAffinityMode (OH_AI_ContextHandle context, int mode )
592```
593**Description**<br>
594Sets the affinity mode for binding runtime threads to CPU cores, which are categorized into little cores and big cores depending on the CPU frequency.
595
596 **Parameters**
597
598| Name | Description |
599| -------- | -------- |
600| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
601| mode | Affinity mode. **0**: no affinities; **1**: big cores first; **2**: little cores first  |
602
603
604### OH_AI_ContextSetThreadNum()
605
606
607```
608OH_AI_API void OH_AI_ContextSetThreadNum (OH_AI_ContextHandle context, int32_t thread_num )
609```
610**Description**<br>
611Sets the number of runtime threads.
612
613 **Parameters**
614
615| Name | Description |
616| -------- | -------- |
617| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.  |
618| thread_num | Number of runtime threads.  |
619
620
621### OH_AI_DeviceInfoCreate()
622
623
624```
625OH_AI_API OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate (OH_AI_DeviceType device_type)
626```
627**Description**<br>
628Creates a device information object.
629
630 **Parameters**
631
632| Name | Description |
633| -------- | -------- |
634| device_type | Device type. For details, see [OH_AI_DeviceType](#oh_ai_devicetype). |
635
636**Returns**
637
638[OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to the device information instance.
639
640
641### OH_AI_DeviceInfoDestroy()
642
643
644```
645OH_AI_API void OH_AI_DeviceInfoDestroy (OH_AI_DeviceInfoHandle * device_info)
646```
647**Description**<br>
648Destroys a device information instance.
649
650 **Parameters**
651
652| Name | Description |
653| -------- | -------- |
654| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
655
656
657### OH_AI_DeviceInfoGetDeviceType()
658
659
660```
661OH_AI_API OH_AI_DeviceType OH_AI_DeviceInfoGetDeviceType (const OH_AI_DeviceInfoHandle device_info)
662```
663**Description**<br>
664Obtains the type of a provider device.
665
666 **Parameters**
667
668| Name | Description |
669| -------- | -------- |
670| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
671
672**Returns**
673
674Type of the provider device.
675
676
677### OH_AI_DeviceInfoGetEnableFP16()
678
679
680```
681OH_AI_API bool OH_AI_DeviceInfoGetEnableFP16 (const OH_AI_DeviceInfoHandle device_info)
682```
683**Description**<br>
684Checks whether float16 inference is enabled. This function is available only for CPU/GPU devices.
685
686 **Parameters**
687
688| Name | Description |
689| -------- | -------- |
690| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
691
692**Returns**
693
694Whether float16 inference is enabled.
695
696
697### OH_AI_DeviceInfoGetFrequency()
698
699
700```
701OH_AI_API int OH_AI_DeviceInfoGetFrequency (const OH_AI_DeviceInfoHandle device_info)
702```
703**Description**<br>
704Obtains the NPU frequency type. This function is available only for NPU devices.
705
706 **Parameters**
707
708| Name | Description |
709| -------- | -------- |
710| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. |
711
712**Returns**
713
714Frequency type of the NPU. The value ranges from **0** to **4**. **1**: low power consumption; **2**: balanced; **3**: high performance; **4**: ultra-high performance
715
716
717### OH_AI_DeviceInfoGetProvider()
718
719
720```
721OH_AI_API const char* OH_AI_DeviceInfoGetProvider (const OH_AI_DeviceInfoHandle device_info)
722```
723**Description**<br>
724Obtains the provider name.
725
726 **Parameters**
727
728| Name | Description |
729| -------- | -------- |
730| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. |
731
732**Returns**
733
734Provider name.
735
736
737### OH_AI_DeviceInfoGetProviderDevice()
738
739
740```
741OH_AI_API const char* OH_AI_DeviceInfoGetProviderDevice (const OH_AI_DeviceInfoHandle device_info)
742```
743**Description**<br>
744Obtains the name of a provider device.
745
746 **Parameters**
747
748| Name | Description |
749| -------- | -------- |
750| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. |
751
752**Returns**
753
754Name of the provider device.
755
756
757### OH_AI_DeviceInfoSetEnableFP16()
758
759
760```
761OH_AI_API void OH_AI_DeviceInfoSetEnableFP16 (OH_AI_DeviceInfoHandle device_info, bool is_fp16 )
762```
763**Description**<br>
764Sets whether to enable float16 inference. This function is available only for CPU/GPU devices.
765
766 **Parameters**
767
768| Name | Description |
769| -------- | -------- |
770| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
771| is_fp16 | Whether to enable float16 inference.  |
772
773
774### OH_AI_DeviceInfoSetFrequency()
775
776
777```
778OH_AI_API void OH_AI_DeviceInfoSetFrequency (OH_AI_DeviceInfoHandle device_info, int frequency )
779```
780**Description**<br>
781Sets the NPU frequency type. This function is available only for NPU devices.
782
783 **Parameters**
784
785| Name | Description |
786| -------- | -------- |
787| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
788| 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  |
789
790
791### OH_AI_DeviceInfoSetProvider()
792
793
794```
795OH_AI_API void OH_AI_DeviceInfoSetProvider (OH_AI_DeviceInfoHandle device_info, const char * provider )
796```
797**Description**<br>
798Sets the name of a provider.
799
800 **Parameters**
801
802| Name | Description |
803| -------- | -------- |
804| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
805| provider | Provider name.  |
806
807
808### OH_AI_DeviceInfoSetProviderDevice()
809
810
811```
812OH_AI_API void OH_AI_DeviceInfoSetProviderDevice (OH_AI_DeviceInfoHandle device_info, const char * device )
813```
814**Description**<br>
815Sets the name of a provider device.
816
817 **Parameters**
818
819| Name | Description |
820| -------- | -------- |
821| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.  |
822| device | Name of the provider device, for example, CPU.  |
823
824
825### OH_AI_ModelBuild()
826
827
828```
829OH_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 )
830```
831**Description**<br>
832Loads and builds a MindSpore model from the memory buffer.
833
834Note 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.
835
836 **Parameters**
837
838| Name | Description |
839| -------- | -------- |
840| model | Pointer to the model object.  |
841| model_data | Address of the loaded model data in the memory.  |
842| data_size | Length of the model data.  |
843| model_type | Type of the model file. For details, see [OH_AI_ModelType](#oh_ai_modeltype).  |
844| model_context | Context for model running. For details, see [OH_AI_ContextHandle](#oh_ai_contexthandle).  |
845
846**Returns**
847
848Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
849
850
851### OH_AI_ModelBuildFromFile()
852
853
854```
855OH_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 )
856```
857**Description**<br>
858Loads and builds a MindSpore model from a model file.
859
860Note 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.
861
862 **Parameters**
863
864| Name | Description |
865| -------- | -------- |
866| model | Pointer to the model object.  |
867| model_path | Path of the model file.  |
868| model_type | Type of the model file. For details, see [OH_AI_ModelType](#oh_ai_modeltype).  |
869| model_context | Context for model running. For details, see [OH_AI_ContextHandle](#oh_ai_contexthandle).  |
870
871**Returns**
872
873Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
874
875
876### OH_AI_ModelCreate()
877
878
879```
880OH_AI_API OH_AI_ModelHandle OH_AI_ModelCreate ()
881```
882**Description**<br>
883Creates a model object.
884
885**Returns**
886
887Pointer to the model object.
888
889
890### OH_AI_ModelDestroy()
891
892
893```
894OH_AI_API void OH_AI_ModelDestroy (OH_AI_ModelHandle * model)
895```
896**Description**<br>
897Destroys a model object.
898
899 **Parameters**
900
901| Name | Description |
902| -------- | -------- |
903| model | Pointer to the model object.  |
904
905
906### OH_AI_ModelGetInputByTensorName()
907
908
909```
910OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetInputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )
911```
912**Description**<br>
913Obtains the input tensor of a model by tensor name.
914
915 **Parameters**
916
917| Name | Description |
918| -------- | -------- |
919| model | Pointer to the model object.  |
920| tensor_name | Tensor name.  |
921
922**Returns**
923
924Pointer to the input tensor indicated by **tensor_name**. If the tensor does not exist in the input, **null** will be returned.
925
926
927### OH_AI_ModelGetInputs()
928
929
930```
931OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetInputs (const OH_AI_ModelHandle model)
932```
933**Description**<br>
934Obtains the input tensor array structure of a model.
935
936 **Parameters**
937
938| Name | Description |
939| -------- | -------- |
940| model | Pointer to the model object.  |
941
942**Returns**
943
944Tensor array structure corresponding to the model input.
945
946
947### OH_AI_ModelGetOutputByTensorName()
948
949
950```
951OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetOutputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )
952```
953**Description**<br>
954Obtains the output tensor of a model by tensor name.
955
956 **Parameters**
957
958| Name | Description |
959| -------- | -------- |
960| model | Pointer to the model object.  |
961| tensor_name | Tensor name.  |
962
963**Returns**
964
965Pointer to the output tensor indicated by **tensor_name**. If the tensor does not exist in the input, **null** will be returned.
966
967
968### OH_AI_ModelGetOutputs()
969
970
971```
972OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetOutputs (const OH_AI_ModelHandle model)
973```
974**Description**<br>
975Obtains the output tensor array structure of a model.
976
977 **Parameters**
978
979| Name | Description |
980| -------- | -------- |
981| model | Pointer to the model object.  |
982
983**Returns**
984
985Tensor array structure corresponding to the model output.
986
987
988### OH_AI_ModelPredict()
989
990
991```
992OH_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 )
993```
994**Description**<br>
995Performs model inference.
996
997 **Parameters**
998
999| Name | Description |
1000| -------- | -------- |
1001| model | Pointer to the model object.  |
1002| inputs | Tensor array structure corresponding to the model input.  |
1003| outputs | Pointer to the tensor array structure corresponding to the model output.  |
1004| before | Callback function executed before model inference.  |
1005| after | Callback function executed after model inference.  |
1006
1007**Returns**
1008
1009Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
1010
1011
1012### OH_AI_ModelResize()
1013
1014
1015```
1016OH_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 )
1017```
1018**Description**<br>
1019Adjusts the input tensor shapes of a built model.
1020
1021 **Parameters**
1022
1023| Name | Description |
1024| -------- | -------- |
1025| model | Pointer to the model object.  |
1026| inputs | Tensor array structure corresponding to the model input.  |
1027| shape_infos | Input shape array, which consists of tensor shapes arranged in the model input sequence. The model adjusts the tensor shapes in sequence.  |
1028| shape_info_num | Length of the input shape array.  |
1029
1030**Returns**
1031
1032Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
1033
1034
1035### OH_AI_TensorClone()
1036
1037
1038```
1039OH_AI_API OH_AI_TensorHandle OH_AI_TensorClone (OH_AI_TensorHandle tensor)
1040```
1041**Description**<br>
1042Clones a tensor.
1043
1044 **Parameters**
1045
1046| Name | Description |
1047| -------- | -------- |
1048| tensor | Pointer to the tensor to clone. |
1049
1050**Returns**
1051
1052Handle of the new tensor object.
1053
1054
1055### OH_AI_TensorCreate()
1056
1057
1058```
1059OH_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 )
1060```
1061**Description**<br>
1062Creates a tensor object.
1063
1064 **Parameters**
1065
1066| Name | Description |
1067| -------- | -------- |
1068| name | Tensor name.  |
1069| type | Tensor data type.  |
1070| shape | Tensor dimension array.  |
1071| shape_num | Length of the tensor dimension array.  |
1072| data | Data pointer.  |
1073| data_len | Data length. |
1074
1075**Returns**
1076
1077Handle of the tensor object.
1078
1079
1080### OH_AI_TensorDestroy()
1081
1082
1083```
1084OH_AI_API void OH_AI_TensorDestroy (OH_AI_TensorHandle * tensor)
1085```
1086**Description**<br>
1087Destroys a tensor object.
1088
1089 **Parameters**
1090
1091| Name | Description |
1092| -------- | -------- |
1093| tensor | Level-2 pointer to the tensor handle. |
1094
1095
1096### OH_AI_TensorGetData()
1097
1098
1099```
1100OH_AI_API const void* OH_AI_TensorGetData (const OH_AI_TensorHandle tensor)
1101```
1102**Description**<br>
1103Obtains the pointer to tensor data.
1104
1105 **Parameters**
1106
1107| Name | Description |
1108| -------- | -------- |
1109| tensor | Handle of the tensor object. |
1110
1111**Returns**
1112
1113Pointer to tensor data.
1114
1115
1116### OH_AI_TensorGetDataSize()
1117
1118
1119```
1120OH_AI_API size_t OH_AI_TensorGetDataSize (const OH_AI_TensorHandle tensor)
1121```
1122**Description**<br>
1123Obtains the number of bytes of the tensor data.
1124
1125 **Parameters**
1126
1127| Name | Description |
1128| -------- | -------- |
1129| tensor | Handle of the tensor object. |
1130
1131**Returns**
1132
1133Number of bytes of the tensor data.
1134
1135
1136### OH_AI_TensorGetDataType()
1137
1138
1139```
1140OH_AI_API OH_AI_DataType OH_AI_TensorGetDataType (const OH_AI_TensorHandle tensor)
1141```
1142**Description**<br>
1143Obtains the data type of a tensor.
1144
1145 **Parameters**
1146
1147| Name | Description |
1148| -------- | -------- |
1149| tensor | Handle of the tensor object. |
1150
1151**Returns**
1152
1153Data type of the tensor.
1154
1155
1156### OH_AI_TensorGetElementNum()
1157
1158
1159```
1160OH_AI_API int64_t OH_AI_TensorGetElementNum (const OH_AI_TensorHandle tensor)
1161```
1162**Description**<br>
1163Obtains the number of tensor elements.
1164
1165 **Parameters**
1166
1167| Name | Description |
1168| -------- | -------- |
1169| tensor | Handle of the tensor object. |
1170
1171**Returns**
1172
1173Number of tensor elements.
1174
1175
1176### OH_AI_TensorGetFormat()
1177
1178
1179```
1180OH_AI_API OH_AI_Format OH_AI_TensorGetFormat (const OH_AI_TensorHandle tensor)
1181```
1182**Description**<br>
1183Obtains the tensor data format.
1184
1185 **Parameters**
1186
1187| Name | Description |
1188| -------- | -------- |
1189| tensor | Handle of the tensor object. |
1190
1191**Returns**
1192
1193Tensor data format.
1194
1195
1196### OH_AI_TensorGetMutableData()
1197
1198
1199```
1200OH_AI_API void* OH_AI_TensorGetMutableData (const OH_AI_TensorHandle tensor)
1201```
1202**Description**<br>
1203Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.
1204
1205 **Parameters**
1206
1207| Name | Description |
1208| -------- | -------- |
1209| tensor | Handle of the tensor object. |
1210
1211**Returns**
1212
1213Pointer to variable tensor data.
1214
1215
1216### OH_AI_TensorGetName()
1217
1218
1219```
1220OH_AI_API const char* OH_AI_TensorGetName (const OH_AI_TensorHandle tensor)
1221```
1222**Description**<br>
1223Obtains the name of a tensor.
1224
1225 **Parameters**
1226
1227| Name | Description |
1228| -------- | -------- |
1229| tensor | Handle of the tensor object. |
1230
1231**Returns**
1232
1233Tensor name.
1234
1235
1236### OH_AI_TensorGetShape()
1237
1238
1239```
1240OH_AI_API const int64_t* OH_AI_TensorGetShape (const OH_AI_TensorHandle tensor, size_t * shape_num )
1241```
1242**Description**<br>
1243Obtains the shape of a tensor.
1244
1245 **Parameters**
1246
1247| Name | Description |
1248| -------- | -------- |
1249| tensor | Handle of the tensor object.  |
1250| shape_num | Length of the tensor shape array. |
1251
1252**Returns**
1253
1254Tensor shape array.
1255
1256
1257### OH_AI_TensorSetData()
1258
1259
1260```
1261OH_AI_API void OH_AI_TensorSetData (OH_AI_TensorHandle tensor, void * data )
1262```
1263**Description**<br>
1264Sets the tensor data.
1265
1266 **Parameters**
1267
1268| Name | Description |
1269| -------- | -------- |
1270| tensor | Handle of the tensor object.  |
1271| data | Data pointer. |
1272
1273
1274### OH_AI_TensorSetDataType()
1275
1276
1277```
1278OH_AI_API void OH_AI_TensorSetDataType (OH_AI_TensorHandle tensor, OH_AI_DataType type )
1279```
1280**Description**<br>
1281Sets the data type of a tensor.
1282
1283 **Parameters**
1284
1285| Name | Description |
1286| -------- | -------- |
1287| tensor | Handle of the tensor object.  |
1288| type | Data type. For details, see [OH_AI_DataType](#oh_ai_datatype). |
1289
1290
1291### OH_AI_TensorSetFormat()
1292
1293
1294```
1295OH_AI_API void OH_AI_TensorSetFormat (OH_AI_TensorHandle tensor, OH_AI_Format format )
1296```
1297**Description**<br>
1298Sets the tensor data format.
1299
1300 **Parameters**
1301
1302| Name | Description |
1303| -------- | -------- |
1304| tensor | Handle of the tensor object.  |
1305| format | Tensor data format. |
1306
1307
1308### OH_AI_TensorSetName()
1309
1310
1311```
1312OH_AI_API void OH_AI_TensorSetName (OH_AI_TensorHandle tensor, const char * name )
1313```
1314**Description**<br>
1315Sets the name of a tensor.
1316
1317 **Parameters**
1318
1319| Name | Description |
1320| -------- | -------- |
1321| tensor | Handle of the tensor object.  |
1322| name | Tensor name. |
1323
1324
1325### OH_AI_TensorSetShape()
1326
1327
1328```
1329OH_AI_API void OH_AI_TensorSetShape (OH_AI_TensorHandle tensor, const int64_t * shape, size_t shape_num )
1330```
1331**Description**<br>
1332Sets the shape of a tensor.
1333
1334 **Parameters**
1335
1336| Name | Description |
1337| -------- | -------- |
1338| tensor | Handle of the tensor object.  |
1339| shape | Tensor shape array.  |
1340| shape_num | Length of the tensor shape array. |
1341