If network-wide model inference is involved, ensure that your app contains the code logic for model execution. For details about the API call sequence, see API Call Sequence.
This section describes the API call sequence for executing a model. For details about loading and executing a single-operator, see Single-Operator Execution.
The key APIs are described as follows:
To configure dynamic batch size, dynamic image size, dynamic AIPP, or dynamic dimensions (ND format only) for your model input, see Model Inference with Dynamic-Shape Inputs and Dynamic AIPP Model Inference.
In static batch size (greater than 1) scenarios, the input data is fed to your model for inference only when the input data reaches the given batch size. Design the processing logic for the remainder data that is less than the batch size as needed.
Currently, synchronous model inference and asynchronous model inference are supported.
Also call aclrtSynchronizeStream to wait for the stream tasks to complete.
For details about asynchronous inference, see Asynchronous Model Inference.
For synchronous inference, obtain the output data of model inference directly.
For asynchronous inference with callback, obtain the model inference result from the callback function for subsequent use.
Call aclrtFree to free the device memory.
After the model inference is complete, call aclDestroyDataBuffer and aclmdlDestroyDataset in sequence to destroy the input data of the model. If the model takes multiple inputs or outputs, a separate call to aclDestroyDataBuffer is needed for each input or output.
AscendCL provides the following data types to describe a model, model inputs, model outputs, and data buffers, as the input parameters of the model execution call.
After a model is successfully loaded, call aclmdlGetDesc to obtain the model description based on the model ID. Then, you can obtain the input/output count, and memory size, shape, format, and data type of each input/output from the model description by using the operation APIs under aclmdlDesc.
Call the operation APIs under aclmdlDataset to add aclDataBuffers and obtain the number of aclDataBuffers.
Call the operation APIs of under aclDataBuffer type to obtain the buffer address and buffer size of each input/output.
After learning related data types, you can use the operation APIs for these data types to prepare the input and output data structures of the model, as shown in the following figure.
The key points are described as follows:
If the model allows dynamic batch size, dynamic image size, or dynamic dimensions (ND format only), the input tensor supports a range of shape profiles and is not determined until the model is executed, you are advised to use the aclmdlGetInputSizeByIndex call to obtain the required buffer size, which is the buffer size required by the maximum profile to ensure buffer sufficiency.