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