• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# neural_network_runtime.h
2<!--Kit: Neural Network Runtime Kit-->
3<!--Subsystem: AI-->
4<!--Owner: @GbuzhidaoR-->
5<!--Designer: @GbuzhidaoR-->
6<!--Tester: @GbuzhidaoR-->
7<!--Adviser: @ge-yafang-->
8
9## Overview
10
11Defines APIs for Neural Network Runtime. The AI inference framework uses the native APIs provided by the Neural Network Runtime to construct and build models.
12
13Currently, the APIs of Neural Network Runtime do not support multi-thread calling.
14
15**File to include**: <neural_network_runtime/neural_network_runtime.h>
16
17**Library**: libneural_network_runtime.so
18
19**System capability**: SystemCapability.Ai.NeuralNetworkRuntime
20
21**Since**: 9
22
23**Related module**: [NeuralNetworkRuntime](capi-neuralnetworkruntime.md)
24
25## Summary
26
27### Functions
28
29| Name| Description|
30| -- | -- |
31| [NN_QuantParam *OH_NNQuantParam_Create()](#oh_nnquantparam_create) | Creates an [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.|
32| [OH_NN_ReturnCode OH_NNQuantParam_SetScales(NN_QuantParam *quantParams, const double *scales, size_t quantCount)](#oh_nnquantparam_setscales) | Sets the scaling coefficient of the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.<br>**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels.|
33| [OH_NN_ReturnCode OH_NNQuantParam_SetZeroPoints(NN_QuantParam *quantParams, const int32_t *zeroPoints, size_t quantCount)](#oh_nnquantparam_setzeropoints) | Sets the zero point of the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.<br>**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels.|
34| [OH_NN_ReturnCode OH_NNQuantParam_SetNumBits(NN_QuantParam *quantParams, const uint32_t *numBits, size_t quantCount)](#oh_nnquantparam_setnumbits) | Sets the quantization bit width of the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.<br>**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels.|
35| [OH_NN_ReturnCode OH_NNQuantParam_Destroy(NN_QuantParam **quantParams)](#oh_nnquantparam_destroy) | Destroys an [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.<br>After an [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance is no longer needed after being passed to [NN_Tensor](capi-neuralnetworkruntime-nn-tensor.md), you need to destroy it to avoid memory leak.<br>If **quantParams** or ***quantParams** is a null pointer, this API only prints warning logs but does not perform the destruction operation.|
36| [OH_NNModel *OH_NNModel_Construct(void)](#oh_nnmodel_construct) | Creates an [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
37| [OH_NN_ReturnCode OH_NNModel_AddTensorToModel(OH_NNModel *model, const NN_TensorDesc *tensorDesc)](#oh_nnmodel_addtensortomodel) | Adds a tensor to a model instance.<br>The data node and operator parameters in the NNRt model are composed of tensors of the model.|
38| [OH_NN_ReturnCode OH_NNModel_SetTensorData(OH_NNModel *model, uint32_t index, const void *dataBuffer, size_t length)](#oh_nnmodel_settensordata) | Sets the tensor value. For tensors with constant values (such as model weights), you need to use this API in the composition phase. The index value of a tensor is determined by the sequence in which the tensor is added to the model. For details about how to add a tensor, see [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel).|
39| [OH_NN_ReturnCode OH_NNModel_SetTensorQuantParams(OH_NNModel *model, uint32_t index, NN_QuantParam *quantParam)](#oh_nnmodel_settensorquantparams) | Sets the quantization parameters of a tensor. For details, see [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md).|
40| [OH_NN_ReturnCode OH_NNModel_SetTensorType(OH_NNModel *model, uint32_t index, OH_NN_TensorType tensorType)](#oh_nnmodel_settensortype) | Sets the tensor type. For details, see [OH_NN_TensorType](capi-neural-network-runtime-type-h.md#oh_nn_tensortype).|
41| [OH_NN_ReturnCode OH_NNModel_AddOperation(OH_NNModel *model,OH_NN_OperationType op,const OH_NN_UInt32Array *paramIndices,const OH_NN_UInt32Array *inputIndices,const OH_NN_UInt32Array *outputIndices)](#oh_nnmodel_addoperation) | Adds an operator to a model instance.|
42| [OH_NN_ReturnCode OH_NNModel_SpecifyInputsAndOutputs(OH_NNModel *model,const OH_NN_UInt32Array *inputIndices,const OH_NN_UInt32Array *outputIndices)](#oh_nnmodel_specifyinputsandoutputs) | Sets an index value for the input and output tensors of a model. A tensor must be specified as the end-to-end input and output of a model instance. |
43| [OH_NN_ReturnCode OH_NNModel_Finish(OH_NNModel *model)](#oh_nnmodel_finish) | Completes model composition. After the model topology is set up, call this API to indicate that the composition is complete.|
44| [void OH_NNModel_Destroy(OH_NNModel **model)](#oh_nnmodel_destroy) | Destroys a model instance. This API needs to be called to destroy the model instance created by calling [OH_NNModel_Construct](capi-neural-network-runtime-h.md#oh_nnmodel_construct). Otherwise, memory leak will occur. If **model** or ***model** is a null pointer, this API only prints warning logs but does not perform the destruction operation.|
45| [OH_NN_ReturnCode OH_NNModel_GetAvailableOperations(OH_NNModel *model,size_t deviceID,const bool **isSupported,uint32_t *opCount)](#oh_nnmodel_getavailableoperations) | Checks whether all operators in a model are supported by the device. The result is indicated by a Boolean value.|
46| [OH_NN_ReturnCode OH_NNModel_AddTensor(OH_NNModel *model, const OH_NN_Tensor *tensor)](#oh_nnmodel_addtensor) | Adds a tensor to a model instance.<br>The data node and operator parameters in the NNRt model are composed of tensors of the model. You can use this API to add tensors to a model instance based on the **tensor** parameter.|
47| [OH_NN_ReturnCode OH_NNExecutor_SetInput(OH_NNExecutor *executor,uint32_t inputIndex,const OH_NN_Tensor *tensor,const void *dataBuffer,size_t length)](#oh_nnexecutor_setinput) | Sets the data for a single model input. This API copies the data whose length is specified by **length** (in bytes) in **dataBuffer** to the shared memory of the underlying device.|
48| [OH_NN_ReturnCode OH_NNExecutor_SetOutput(OH_NNExecutor *executor,uint32_t outputIndex,void *dataBuffer,size_t length)](#oh_nnexecutor_setoutput) | Sets the memory for a single model output.<br>This API binds the buffer pointed by **dataBuffer** to the output specified by **outputIndex**. The length of the buffer is specified by **length**.|
49| [OH_NN_ReturnCode OH_NNExecutor_Run(OH_NNExecutor *executor)](#oh_nnexecutor_run) | Perform model inference through This API performs end-to-end model inference and computing on the device associated with the executor.|
50| [OH_NN_Memory *OH_NNExecutor_AllocateInputMemory(OH_NNExecutor *executor, uint32_t inputIndex, size_t length)](#oh_nnexecutor_allocateinputmemory) | Applies for shared memory for a single model input on the device.|
51| [OH_NN_Memory *OH_NNExecutor_AllocateOutputMemory(OH_NNExecutor *executor, uint32_t outputIndex, size_t length)](#oh_nnexecutor_allocateoutputmemory) | Applies for shared memory for a single model output on the device.|
52| [void OH_NNExecutor_DestroyInputMemory(OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory)](#oh_nnexecutor_destroyinputmemory) | Releases the input memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance. This API is used to release the memory instance created by calling [OH_NNExecutor_AllocateInputMemory](capi-neural-network-runtime-h.md#oh_nnexecutor_allocateinputmemory). If this API is not called, memory leakage occurs.|
53| [void OH_NNExecutor_DestroyOutputMemory(OH_NNExecutor *executor, uint32_t outputIndex, OH_NN_Memory **memory)](#oh_nnexecutor_destroyoutputmemory) | Releases the output memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance. This API needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateOutputMemory](capi-neural-network-runtime-h.md#oh_nnexecutor_allocateoutputmemory). Otherwise, memory leak will occur. The mapping between **outputIndex** and **memory** must be the same as that in memory instance creation. If **memory** or ***memory** is a null pointer, this API only prints the warning log and does not execute the release logic.|
54| [OH_NN_ReturnCode OH_NNExecutor_SetInputWithMemory(OH_NNExecutor *executor,uint32_t inputIndex,const OH_NN_Tensor *tensor,const OH_NN_Memory *memory)](#oh_nnexecutor_setinputwithmemory) | Specifies the hardware shared memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance as the shared memory used by a single model input.|
55| [OH_NN_ReturnCode OH_NNExecutor_SetOutputWithMemory(OH_NNExecutor *executor,uint32_t outputIndex,const OH_NN_Memory *memory)](#oh_nnexecutor_setoutputwithmemory) | Specifies the hardware shared memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance as the shared memory used by a single model output.|
56
57## Function Description
58
59### OH_NNQuantParam_Create()
60
61```
62NN_QuantParam *OH_NNQuantParam_Create()
63```
64
65**Description**
66
67Creates an [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.
68
69After creating an [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance, set its attribute values by calling [OH_NNQuantParam_SetScales](capi-neural-network-runtime-h.md#oh_nnquantparam_setscales), [OH_NNQuantParam_SetZeroPoints](capi-neural-network-runtime-h.md#oh_nnquantparam_setzeropoints), or [OH_NNQuantParam_SetNumBits](capi-neural-network-runtime-h.md#oh_nnquantparam_setnumbits), and pass it to [NN_Tensor](capi-neuralnetworkruntime-nn-tensor.md) by calling [OH_NNModel_SetTensorQuantParams](capi-neural-network-runtime-h.md#oh_nnmodel_settensorquantparams). Finally, call [OH_NNQuantParam_Destroy](capi-neural-network-runtime-h.md#oh_nnquantparam_destroy) to destroy the instance to prevent a memory leak.
70
71**Since**: 11
72
73**Returns**
74
75| Type| Description|
76| -- | -- |
77| [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) * | Pointer to the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance. If the operation fails, **NULL** is returned.|
78
79### OH_NNQuantParam_SetScales()
80
81```
82OH_NN_ReturnCode OH_NNQuantParam_SetScales(NN_QuantParam *quantParams, const double *scales, size_t quantCount)
83```
84
85**Description**
86
87Sets the scaling coefficient of the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.
88
89**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels.
90
91**Since**: 11
92
93
94**Parameters**
95
96| Name| Description|
97| -- | -- |
98| [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) *quantParams | Pointer to the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.|
99| const double *scales | Array consisting of scaling coefficients of all quantization parameters in the tensor.|
100| size_t quantCount | Number of quantization parameters in a tensor.|
101
102**Returns**
103
104| Type| Description|
105| -- | -- |
106| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
107
108### OH_NNQuantParam_SetZeroPoints()
109
110```
111OH_NN_ReturnCode OH_NNQuantParam_SetZeroPoints(NN_QuantParam *quantParams, const int32_t *zeroPoints, size_t quantCount)
112```
113
114**Description**
115
116Sets the zero point of the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.
117
118**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels.
119
120**Since**: 11
121
122
123**Parameters**
124
125| Name| Description|
126| -- | -- |
127| [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) *quantParams | Pointer to the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.|
128| const int32_t *zeroPoints | Array consisting of zero points of all quantization parameters in a tensor.|
129| size_t quantCount | Number of quantization parameters in a tensor.|
130
131**Returns**
132
133| Type| Description|
134| -- | -- |
135| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
136
137### OH_NNQuantParam_SetNumBits()
138
139```
140OH_NN_ReturnCode OH_NNQuantParam_SetNumBits(NN_QuantParam *quantParams, const uint32_t *numBits, size_t quantCount)
141```
142
143**Description**
144
145Sets the quantization bit width of the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.
146
147**quantCount** is the number of quantization parameters in the tensor. For example, for per-channel quantization, **quantCount** is the number of channels.
148
149**Since**: 11
150
151
152**Parameters**
153
154| Name| Description|
155| -- | -- |
156| [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) *quantParams | Pointer to the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.|
157| const uint32_t *numBits | Array consisting of quantization bits of all quantization parameters in a tensor.|
158| size_t quantCount | Number of quantization parameters in a tensor.|
159
160**Returns**
161
162| Type| Description|
163| -- | -- |
164| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
165
166### OH_NNQuantParam_Destroy()
167
168```
169OH_NN_ReturnCode OH_NNQuantParam_Destroy(NN_QuantParam **quantParams)
170```
171
172**Description**
173
174Destroys an [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.
175
176After an [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance is no longer needed after being passed to [NN_Tensor](capi-neuralnetworkruntime-nn-tensor.md), you need to destroy it to avoid memory leak.<br>If **quantParams** or ***quantParams** is a null pointer, this API only prints warning logs but does not perform the destruction operation.
177
178**Since**: 11
179
180
181**Parameters**
182
183| Name| Description|
184| -- | -- |
185| [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) **quantParams | Level-2 pointer to the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.|
186
187**Returns**
188
189| Type| Description|
190| -- | -- |
191| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
192
193### OH_NNModel_Construct()
194
195```
196OH_NNModel *OH_NNModel_Construct(void)
197```
198
199**Description**
200
201Creates an [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.
202
203Before graph composition, call [OH_NNModel_Construct](capi-neural-network-runtime-h.md#oh_nnmodel_construct) to create a model instance. Based on the model topology, call [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel), [OH_NNModel_AddOperation](capi-neural-network-runtime-h.md#oh_nnmodel_addoperation), and [OH_NNModel_SetTensorData](capi-neural-network-runtime-h.md#oh_nnmodel_settensordata) to fill in the data and operator nodes of the model, and then call [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) to specify the input and output of the model. After the model topology is constructed, call [OH_NNModel_Finish](capi-neural-network-runtime-h.md#oh_nnmodel_finish) to build the model.
204
205If a model instance is no longer needed, destroy it by calling [OH_NNModel_Destroy](capi-neural-network-runtime-h.md#oh_nnmodel_destroy) to prevent a memory leak.
206
207**Since**: 9
208
209**Returns**
210
211| Type| Description|
212| -- | -- |
213| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) * | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance. If the operation fails, **NULL** is returned.|
214
215### OH_NNModel_AddTensorToModel()
216
217```
218OH_NN_ReturnCode OH_NNModel_AddTensorToModel(OH_NNModel *model, const NN_TensorDesc *tensorDesc)
219```
220
221**Description**
222
223Adds a tensor to a model instance.
224
225The data node and operator parameters in the NNRt model are composed of tensors of the model.
226
227This API adds tensors to a model instance based on [NN_TensorDesc](capi-neuralnetworkruntime-nn-tensordesc.md). The sequence of adding tensors is specified by the index value recorded in the model. The [OH_NNModel_SetTensorData](capi-neural-network-runtime-h.md#oh_nnmodel_settensordata), [OH_NNModel_AddOperation](capi-neural-network-runtime-h.md#oh_nnmodel_addoperation), and [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) APIs specify tensors based on the index value.
228
229NNRt supports input and output of dynamic shapes. When adding a data node with a dynamic shape, you need to set the dimensions that support dynamic changes in **tensor.dimensions** to **-1**. For example, if **tensor.dimensions** of a four-dimensional tensor is set to **[1, -1, 2, 2]**, the second dimension supports dynamic changes.
230
231**Since**: 11
232
233
234**Parameters**
235
236| Name| Description|
237| -- | -- |
238| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
239| [const NN_TensorDesc](capi-neuralnetworkruntime-nn-tensordesc.md) *tensorDesc | Pointer to the [NN_TensorDesc](capi-neuralnetworkruntime-nn-tensordesc.md) tensor, where [NN_TensorDesc](capi-neuralnetworkruntime-nn-tensordesc.md) specify the attributes of the tensor to be added to the model instance.|
240
241**Returns**
242
243| Type| Description|
244| -- | -- |
245| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
246
247### OH_NNModel_SetTensorData()
248
249```
250OH_NN_ReturnCode OH_NNModel_SetTensorData(OH_NNModel *model, uint32_t index, const void *dataBuffer, size_t length)
251```
252
253**Description**
254
255Sets the tensor value. For tensors with constant values (such as model weights), you need to use this API in the composition phase.
256
257The index value of a tensor is determined by the sequence in which the tensor is added to the model. For details about how to add a tensor, see [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel).
258
259**Since**: 9
260
261
262**Parameters**
263
264| Name| Description|
265| -- | -- |
266| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
267| uint32_t index | Index value of a tensor.|
268| const void *dataBuffer | Pointer to the real data memory.|
269| size_t length | Length of the data memory.|
270
271**Returns**
272
273| Type| Description|
274| -- | -- |
275| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
276
277### OH_NNModel_SetTensorQuantParams()
278
279```
280OH_NN_ReturnCode OH_NNModel_SetTensorQuantParams(OH_NNModel *model, uint32_t index, NN_QuantParam *quantParam)
281```
282
283**Description**
284
285Sets the quantization parameters of a tensor. For details, see [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md).
286
287**Since**: 11
288
289
290**Parameters**
291
292| Name| Description|
293| -- | -- |
294| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
295| uint32_t index | Index value of a tensor.|
296| [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) *quantParam | Pointer to the [NN_QuantParam](capi-neuralnetworkruntime-nn-quantparam.md) instance.|
297
298**Returns**
299
300| Type| Description|
301| -- | -- |
302| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
303
304### OH_NNModel_SetTensorType()
305
306```
307OH_NN_ReturnCode OH_NNModel_SetTensorType(OH_NNModel *model, uint32_t index, OH_NN_TensorType tensorType)
308```
309
310**Description**
311
312Sets the tensor type. For details, see [OH_NN_TensorType](capi-neural-network-runtime-type-h.md#oh_nn_tensortype).
313
314**Since**: 11
315
316
317**Parameters**
318
319| Name| Description|
320| -- | -- |
321| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
322| uint32_t index | Index value of a tensor.|
323| [OH_NN_TensorType](capi-neural-network-runtime-type-h.md#oh_nn_tensortype) tensorType | Tensor type.|
324
325**Returns**
326
327| Type| Description|
328| -- | -- |
329| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
330
331### OH_NNModel_AddOperation()
332
333```
334OH_NN_ReturnCode OH_NNModel_AddOperation(OH_NNModel *model,OH_NN_OperationType op,const OH_NN_UInt32Array *paramIndices,const OH_NN_UInt32Array *inputIndices,const OH_NN_UInt32Array *outputIndices)
335```
336
337**Description**
338
339Adds an operator to a model instance.
340
341You can use this API to add an operator to a model instance. The operator type is specified by **op**, and the operator parameters, inputs, and outputs are specified by **paramIndices**, **inputIndices**, and **outputIndices** respectively.
342
343This API verifies the attributes of operator parameters and the number of input and output parameters. These attributes must be correctly set when [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel) is called to add tensors.
344
345For details about the expected parameters, input attributes, and output attributes of each operator, see [OH_NN_OperationType](capi-neural-network-runtime-type-h.md#oh_nn_operationtype).
346
347**paramIndices**, **inputIndices**, and **outputIndices** store index values of tensors. Index values are determined by the sequence in which tensors are added to the model.
348
349For details about how to add a tensor, see [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel).
350
351If unnecessary parameters are added for adding an operator, this API returns the error code [OH_NN_INVALID_PARAMETER](capi-neural-network-runtime-type-h.md#oh_nn_returncode). If no operator parameter is set, the operator uses the default parameter value. For details about the default values, see OH_NN_OperationType](capi-neural-network-runtime-type-h.md#oh_nn_operationtype).
352
353**Since**: 9
354
355
356**Parameters**
357
358| Name| Description|
359| -- | -- |
360| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
361| [OH_NN_OperationType](capi-neural-network-runtime-type-h.md#oh_nn_operationtype) op | Type of the operator to be added. For details, see [OH_NN_OperationType](capi-neural-network-runtime-type-h.md#oh_nn_operationtype).|
362| [const OH_NN_UInt32Array](capi-neuralnetworkruntime-oh-nn-uint32array.md) *paramIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the parameter tensor index of the operator.|
363| [const OH_NN_UInt32Array](capi-neuralnetworkruntime-oh-nn-uint32array.md) *inputIndices | Pointer to the **OH_NN_UInt32Array** instance, specifying the input tensor index of the operator.|
364| [const OH_NN_UInt32Array](capi-neuralnetworkruntime-oh-nn-uint32array.md) *outputIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the output tensor index of the operator.|
365
366**Returns**
367
368| Type| Description|
369| -- | -- |
370| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
371
372### OH_NNModel_SpecifyInputsAndOutputs()
373
374```
375OH_NN_ReturnCode OH_NNModel_SpecifyInputsAndOutputs(OH_NNModel *model,const OH_NN_UInt32Array *inputIndices,const OH_NN_UInt32Array *outputIndices)
376```
377
378**Description**
379
380Sets an index value for the input and output tensors of a model.
381
382A tensor must be specified as the end-to-end input and output of a model instance. After a tensor is set as the input or output tensor, you are not allowed to set the tensor data by calling [OH_NNModel_SetTensorData](capi-neural-network-runtime-h.md#oh_nnmodel_settensordata). Instead, call OH_NNExecutor in the execution phase to set the input or output tensor data.
383
384The index value of a tensor is determined by the sequence in which the tensor is added to the model. For details about how to add a tensor, see [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel). Currently, the model input and output cannot be set asynchronously.
385
386**Since**: 9
387
388
389**Parameters**
390
391| Name| Description|
392| -- | -- |
393| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
394| [const OH_NN_UInt32Array](capi-neuralnetworkruntime-oh-nn-uint32array.md) *inputIndices | Pointer to the **OH_NN_UInt32Array** instance, which is used to set the input tensor of the operator.|
395| [const OH_NN_UInt32Array](capi-neuralnetworkruntime-oh-nn-uint32array.md) *outputIndices | Pointer to the OH_NN_UInt32Array instance, which is used to set the output tensor of the operator.|
396
397**Returns**
398
399| Type| Description|
400| -- | -- |
401| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
402
403### OH_NNModel_Finish()
404
405```
406OH_NN_ReturnCode OH_NNModel_Finish(OH_NNModel *model)
407```
408
409**Description**
410
411Completes model composition.
412
413After the model topology is set up, call this API to indicate that the composition is complete.
414
415After this API is called, additional graph composition cannot be performed. If [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel), [OH_NNModel_AddOperation](capi-neural-network-runtime-h.md#oh_nnmodel_addoperation), [OH_NNModel_SetTensorData](capi-neural-network-runtime-h.md#oh_nnmodel_settensordata), or [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called, [OH_NN_OPERATION_FORBIDDEN](capi-neural-network-runtime-type-h.md#oh_nn_returncode) is returned.
416
417Before calling Before calling [OH_NNModel_GetAvailableOperations](capi-neural-network-runtime-h.md#oh_nnmodel_getavailableoperations) and [OH_NNCompilation_Construct](capi-neural-network-core-h.md#oh_nncompilation_construct), you must call this API to complete composition., you must call this API to complete composition.
418
419**Since**: 9
420
421
422**Parameters**
423
424| Name| Description|
425| -- | -- |
426| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
427
428**Returns**
429
430| Type| Description|
431| -- | -- |
432| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
433
434### OH_NNModel_Destroy()
435
436```
437void OH_NNModel_Destroy(OH_NNModel **model)
438```
439
440**Description**
441
442Destroys a model instance.
443
444This API needs to be called to destroy the model instance created by calling [OH_NNModel_Construct](capi-neural-network-runtime-h.md#oh_nnmodel_construct). Otherwise, memory leak will occur.
445
446If **model** or ***model** is a null pointer, this API only prints warning logs but does not perform the destruction operation.
447
448**Since**: 9
449
450
451**Parameters**
452
453| Name| Description|
454| -- | -- |
455| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) **model | Level-2 pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance. After a model instance is destroyed, this API sets ***model** to a null pointer.|
456
457### OH_NNModel_GetAvailableOperations()
458
459```
460OH_NN_ReturnCode OH_NNModel_GetAvailableOperations(OH_NNModel *model,size_t deviceID,const bool **isSupported,uint32_t *opCount)
461```
462
463**Description**
464
465Checks whether all operators in a model are supported by the device. The result is indicated by a Boolean value.
466
467Checks whether the underlying device supports operators in a model instance. The device is specified by **deviceID**, and the result is represented by the array pointed by **isSupported**.
468
469If the *i*th operator is supported, the value of **(\*isSupported)**[*i*] is **true**. Otherwise, the value is **false**. After this API is successfully executed, **(*isSupported)** points to the bool array that records the operator support status. The operator quantity for the array length is the same as that for the model instance.
470
471The memory corresponding to this array is managed by NNRt and is automatically destroyed after the model instance is destroyed or this API is called again.
472
473**Since**: 9
474
475
476**Parameters**
477
478| Name| Description|
479| -- | -- |
480| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
481| size_t deviceID | Device ID to be queried, which can be obtained by using [OH_NNDevice_GetAllDevicesID](capi-neural-network-core-h.md#oh_nndevice_getalldevicesid).|
482| const bool **isSupported | Pointer to the **bool** array. The input ***isSupported** must be a null pointer. Otherwise, [OH_NN_INVALID_PARAMETER](capi-neural-network-runtime-type-h.md#oh_nn_returncode) is returned.|
483| uint32_t *opCount | Number of operators in a model instance, corresponding to the length of the ***isSupported** array.|
484
485**Returns**
486
487| Type| Description|
488| -- | -- |
489| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
490
491### OH_NNModel_AddTensor()
492
493```
494OH_NN_ReturnCode OH_NNModel_AddTensor(OH_NNModel *model, const OH_NN_Tensor *tensor)
495```
496
497**Description**
498
499Adds a tensor to a model instance.
500
501The data node and operator parameters in the NNRt model are composed of tensors of the model. You can use this API to add tensors to a model instance based on the **tensor** parameter.
502
503The sequence of adding tensors is specified by the index value recorded in the model. The [OH_NNModel_SetTensorData](capi-neural-network-runtime-h.md#oh_nnmodel_settensordata), [OH_NNModel_AddOperation](capi-neural-network-runtime-h.md#oh_nnmodel_addoperation), and [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) APIs specify tensors based on the index value.
504
505NNRt supports input and output of dynamic shapes.
506
507When adding a data node with a dynamic shape, you need to set the dimensions that support dynamic changes in **tensor.dimensions** to **-1**. For example, if **tensor.dimensions** of a four-dimensional tensor is set to **[1, -1, 2, 2]**, the second dimension supports dynamic changes.
508
509**Since**: 9
510
511**Deprecated from**: 11
512
513**Substitute**: [OH_NNModel_AddTensorToModel](capi-neural-network-runtime-h.md#oh_nnmodel_addtensortomodel)
514
515
516**Parameters**
517
518| Name| Description|
519| -- | -- |
520| [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) *model | Pointer to the [OH_NNModel](capi-neuralnetworkruntime-oh-nnmodel.md) instance.|
521| [const OH_NN_Tensor](capi-neuralnetworkruntime-oh-nn-tensor.md) *tensor | Pointer to the [OH_NN_Tensor](capi-neuralnetworkruntime-oh-nn-tensor.md) tensor, where **tensor** specifies the attributes of the tensor to be added to the model instance.|
522
523**Returns**
524
525| Type| Description|
526| -- | -- |
527| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
528
529### OH_NNExecutor_SetInput()
530
531```
532OH_NN_ReturnCode OH_NNExecutor_SetInput(OH_NNExecutor *executor,uint32_t inputIndex,const OH_NN_Tensor *tensor,const void *dataBuffer,size_t length)
533```
534
535**Description**
536
537Sets the data for a single model input.
538
539This API copies the data whose length is specified by **length** (in bytes) in **dataBuffer** to the shared memory of the underlying device.
540
541**inputIndex** specifies the input to be set and **tensor** sets tensor information such as the shape, type, and quantization parameters.
542
543NNRt supports models with dynamical shape input. For fixed shape input and dynamic shape input scenarios, this API uses different processing policies.
544
545- Fixed shape input: The attributes of tensor must be the same as those of the tensor added by calling [OH_NNModel_AddTensor](capi-neural-network-runtime-h.md#oh_nnmodel_addtensor) in the build phase.
546- Dynamic shape input: In the composition phase, because the shape is not fixed, each value in **tensor.dimensions** must be greater than **0** in the API calls to determine the shape input in the computing phase. When setting the shape, you can modify only the dimension whose value is **-1**.<br>Assume that **[-1, 224, 224, 3]** is input as the the dimension of A in the composition phase. When this API is called, you can only change the size of the first dimension, for example, to [3, 224, 224, 3]. If other dimensions are adjusted, [OH_NN_INVALID_PARAMETER](capi-neural-network-runtime-type-h.md#oh_nn_returncode) is returned.
547
548**Since**: 9
549
550**Deprecated from**: 11
551
552**Substitute**: [OH_NNExecutor_RunSync](capi-neural-network-core-h.md#oh_nnexecutor_runsync)
553
554
555**Parameters**
556
557| Name| Description|
558| -- | -- |
559| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
560| uint32_t inputIndex | Input index value, which is the same as the sequence of the input data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **inputIndices** is {1, 5, 9} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you set the input data, set the value of this parameter to {0, 1, 2}.|
561| [const OH_NN_Tensor](capi-neuralnetworkruntime-oh-nn-tensor.md) *tensor | Tensor corresponding to the input data.|
562| const void *dataBuffer | Pointer to the input data.|
563| size_t length | Length of the data memory, in bytes.|
564
565**Returns**
566
567| Type| Description|
568| -- | -- |
569| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
570
571### OH_NNExecutor_SetOutput()
572
573```
574OH_NN_ReturnCode OH_NNExecutor_SetOutput(OH_NNExecutor *executor,uint32_t outputIndex,void *dataBuffer,size_t length)
575```
576
577**Description**
578
579Sets the memory for a single model output.
580
581This method binds the buffer pointed by **dataBuffer** to the output specified by **outputIndex**. The length of the buffer is specified by **length**.
582
583After [OH_NNExecutor_Run](capi-neural-network-runtime-h.md#oh_nnexecutor_run) is called to complete a single model inference, NNRt compares the length of the buffer pointed by **dataBuffer** with the length of the output data and returns different results based on the actual situation.
584
585- If the memory size is greater than or equal to the data length, the API copies the inference result to the memory and returns [OH_NN_SUCCESS](capi-neural-network-runtime-type-h.md#oh_nn_returncode). You can read the inference result from **dataBuffer**.
586- If the memory size is less than the data length, the [OH_NNExecutor_Run](capi-neural-network-runtime-h.md#oh_nnexecutor_run) API returns the error code [OH_NN_INVALID_PARAMETER](capi-neural-network-runtime-type-h.md#oh_nn_returncode) and generates a log indicating that the memory size is too small.
587
588**Since**: 9
589
590**Deprecated from**: 11
591
592**Substitute**: [OH_NNExecutor_RunSync](capi-neural-network-core-h.md#oh_nnexecutor_runsync)
593
594
595**Parameters**
596
597| Name| Description|
598| -- | -- |
599| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
600| uint32_t outputIndex | Output index value, which is the same as the sequence of the output data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **outputIndices** is {4, 6, 8} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you set the output memory, set the value of this parameter to {0, 1, 2}.|
601| void *dataBuffer | Pointer to the output data.|
602| size_t length | Length of the data memory, in bytes.|
603
604**Returns**
605
606| Type| Description|
607| -- | -- |
608| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
609
610### OH_NNExecutor_Run()
611
612```
613OH_NN_ReturnCode OH_NNExecutor_Run(OH_NNExecutor *executor)
614```
615
616**Description**
617
618Perform model inference through This API performs end-to-end model inference and computing on the device associated with the executor.
619
620**Since**: 9
621
622**Deprecated from**: 11
623
624**Substitute**: [OH_NNExecutor_RunSync](capi-neural-network-core-h.md#oh_nnexecutor_runsync)
625
626**Parameters**
627
628| Name| Description|
629| -- | -- |
630| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
631
632**Returns**
633
634| Type| Description|
635| -- | -- |
636| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
637
638### OH_NNExecutor_AllocateInputMemory()
639
640```
641OH_NN_Memory *OH_NNExecutor_AllocateInputMemory(OH_NNExecutor *executor, uint32_t inputIndex, size_t length)
642```
643
644**Description**
645
646Applies for shared memory for a single model input on the device.
647
648NNRt provides an API for proactively applying for shared memory on a device.
649
650Based on the specified executor and input index value, this API applies for the shared memory whose size is **length** on the device associated with a single input. Then, it returns the shared memory through the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.
651
652**Since**: 9
653
654**Deprecated from**: 11
655
656**Substitute**: [OH_NNTensor_CreateWithSize](capi-neural-network-core-h.md#oh_nntensor_createwithsize)
657
658
659**Parameters**
660
661| Name| Description|
662| -- | -- |
663| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
664| uint32_t inputIndex | Input index value, which is the same as the sequence of the input data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **inputIndices** is {1, 5, 9} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you request the input memory, set the value of this parameter to {0, 1, 2}.|
665| size_t length | Memory size to be applied for, in bytes.|
666
667**Returns**
668
669| Type| Description|
670| -- | -- |
671| [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) * | Pointer to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance. If the operation fails, **NULL** is returned.|
672
673### OH_NNExecutor_AllocateOutputMemory()
674
675```
676OH_NN_Memory *OH_NNExecutor_AllocateOutputMemory(OH_NNExecutor *executor, uint32_t outputIndex, size_t length)
677```
678
679**Description**
680
681Applies for shared memory for a single model output on the device.
682
683NNRt provides an API for proactively applying for shared memory on a device.
684
685Based on the specified executor and output index value, this API applies for the shared memory whose size is **length** on the device associated with a single output. Then, it returns the shared memory through the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.
686
687**Since**: 9
688
689**Deprecated from**: 11
690
691**Substitute**: [OH_NNTensor_CreateWithSize](capi-neural-network-core-h.md#oh_nntensor_createwithsize)
692
693
694**Parameters**
695
696| Name| Description|
697| -- | -- |
698| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
699| uint32_t outputIndex | Output index value, which is the same as the sequence of the output data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **outputIndices** is {4, 6, 8} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you request the output memory, set the value of this parameter to {0, 1, 2}.|
700| size_t length | Memory size to be applied for, in bytes.|
701
702**Returns**
703
704| Type| Description|
705| -- | -- |
706| [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) * | Pointer to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance. If the operation fails, **NULL** is returned.|
707
708### OH_NNExecutor_DestroyInputMemory()
709
710```
711void OH_NNExecutor_DestroyInputMemory(OH_NNExecutor *executor, uint32_t inputIndex, OH_NN_Memory **memory)
712```
713
714**Description**
715
716Releases the input memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.
717
718This API is used to release the memory instance created by calling [OH_NNExecutor_AllocateInputMemory](capi-neural-network-runtime-h.md#oh_nnexecutor_allocateinputmemory). If this API is not called, memory leakage occurs.
719
720The mapping between **inputIndex** and **memory** must be the same as that in memory instance creation. If **memory** or ***memory** is a null pointer, this API only prints the warning log and does not execute the release logic.
721
722**Since**: 9
723
724**Deprecated from**: 11
725
726**Substitute**: [OH_NNTensor_Destroy](capi-neural-network-core-h.md#oh_nntensor_destroy)
727
728
729**Parameters**
730
731| Name| Description|
732| -- | -- |
733| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
734| uint32_t inputIndex | Input index value, which is the same as the sequence of the input data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **inputIndices** is {1, 5, 9} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you release the input memory, set the value of this parameter to {0, 1, 2}.|
735| [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) **memory | Level-2 pointer to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance. After the shared memory is released, this API sets ***memory** to a null pointer.|
736
737### OH_NNExecutor_DestroyOutputMemory()
738
739```
740void OH_NNExecutor_DestroyOutputMemory(OH_NNExecutor *executor, uint32_t outputIndex, OH_NN_Memory **memory)
741```
742
743**Description**
744
745Releases the output memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.
746
747This API needs to be called to release the memory instance created by calling [OH_NNExecutor_AllocateOutputMemory](capi-neural-network-runtime-h.md#oh_nnexecutor_allocateoutputmemory). Otherwise, memory leak will occur.
748
749The mapping between **outputIndex** and **memory** must be the same as that in memory instance creation.
750
751If **memory** or ***memory** is a null pointer, this API only prints the warning log and does not execute the release logic.
752
753**Since**: 9
754
755**Deprecated from**: 11
756
757**Substitute**: [OH_NNTensor_Destroy](capi-neural-network-core-h.md#oh_nntensor_destroy)
758
759
760**Parameters**
761
762| Name| Description|
763| -- | -- |
764| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
765| uint32_t outputIndex | Output index value, which is the same as the sequence of the output data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **outputIndices** is {4, 6, 8} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you release the output memory, set the value of this parameter to {0, 1, 2}.|
766| [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) **memory | Level-2 pointer to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance. After the shared memory is released, this API sets ***memory** to a null pointer.|
767
768### OH_NNExecutor_SetInputWithMemory()
769
770```
771OH_NN_ReturnCode OH_NNExecutor_SetInputWithMemory(OH_NNExecutor *executor,uint32_t inputIndex,const OH_NN_Tensor *tensor,const OH_NN_Memory *memory)
772```
773
774**Description**
775
776Specifies the hardware shared memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance as the shared memory used by a single model input.
777
778In the scenario where the memory needs to be managed by yourself, this API binds the input to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.
779
780During computing, the underlying device reads the input data from the shared memory pointed to by the memory instance.
781
782By using this API, you can implement concurrent execution of input setting, computing, and read to improve the data flow inference efficiency.
783
784**Since**: 9
785
786**Deprecated from**: 11
787
788**Substitute**: [OH_NNExecutor_RunSync](capi-neural-network-core-h.md#oh_nnexecutor_runsync)
789
790
791**Parameters**
792
793| Name| Description|
794| -- | -- |
795| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) instance.|
796| uint32_t inputIndex | Input index value, which is the same as the sequence of the input data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **inputIndices** is {1, 5, 9} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you specify the input shared memory, set the value of this parameter to {0, 1, 2}.|
797| [const OH_NN_Tensor](capi-neuralnetworkruntime-oh-nn-tensor.md) *tensor | Pointer to the [OH_NN_Tensor](capi-neuralnetworkruntime-oh-nn-tensor.md) instance, which is used to set the tensor corresponding to a single input.|
798| [const OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) *memory | Pointer to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.|
799
800**Returns**
801
802| Type| Description|
803| -- | -- |
804| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
805
806### OH_NNExecutor_SetOutputWithMemory()
807
808```
809OH_NN_ReturnCode OH_NNExecutor_SetOutputWithMemory(OH_NNExecutor *executor,uint32_t outputIndex,const OH_NN_Memory *memory)
810```
811
812**Description**
813
814Specifies the hardware shared memory pointed by the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance as the shared memory used by a single model output.
815
816In the scenario where the memory needs to be managed by yourself, this API binds the output to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.
817
818During computing, the underlying device writes the computing result to the shared memory pointed by the memory instance.
819
820By using this API, you can implement concurrent execution of input setting, computing, and read to improve the data flow inference efficiency.
821
822**Since**: 9
823
824**Deprecated from**: 11
825
826**Substitute**: [OH_NNExecutor_RunSync](capi-neural-network-core-h.md#oh_nnexecutor_runsync)
827
828
829**Parameters**
830
831| Name| Description|
832| -- | -- |
833| [OH_NNExecutor](capi-neuralnetworkruntime-oh-nnexecutor.md) *executor | Pointer to the executor.|
834| uint32_t outputIndex | Output index value, which is the same as the sequence of the output data when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called.<br>Assume that **outputIndices** is {4, 6, 8} when [OH_NNModel_SpecifyInputsAndOutputs](capi-neural-network-runtime-h.md#oh_nnmodel_specifyinputsandoutputs) is called. When you specify the output shared memory, set the value of this parameter to {0, 1, 2}.|
835| [const OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) *memory | Pointer to the [OH_NN_Memory](capi-neuralnetworkruntime-oh-nn-memory.md) instance.|
836
837**Returns**
838
839| Type| Description|
840| -- | -- |
841| [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode) | Execution result of the function. If the operation is successful, **OH_NN_SUCCESS** is returned. If the operation fails, an error is returned. For details about the error codes, see [OH_NN_ReturnCode](capi-neural-network-runtime-type-h.md#oh_nn_returncode).|
842