API Call Sequence
This section describes the process of calling APIs for app development.
API Call Sequence
By calling acl APIs, you can develop apps that provide functions such as model inference, media data processing, and single-operator execution. These functions can exist independently or in combinations. The following figure shows the overall sequence of calling acl APIs to develop AI apps.
The figure briefs the API calls in typical scenarios. If the size of the input image does not meet the model requirements, media data processing is required. To implement model inference, the model needs to be loaded first. On the completion of model inference, the model needs to be unloaded. After model inference, the inference result needs to be postprocessed for displaying the class indexes corresponding to the top confidence values.
- Perform initialization.
- Allocate runtime resources.
For details, see Runtime Resource Allocation and Deallocation.
- Process app services.
- Model inference
- Load the model.
For details about the API call sequence, see Loading a Model.
Before loading a model, ensure that you have the required offline model adapted to the Ascend AI Processor. For details about how to build a model, see Building a Model.
- (Optional) Process media data, including JPEG image and video decoding, image cropping, resizing, format conversion, and JPEG image encoding.
For details about the API call sequence, see Media Data Processing (Including Images and Videos).
- Run model inference to implement functions such as image classification and target recognition.
For details about the API call sequence, see Running a Model.
- (Optional) Postprocess the model inference result as required. For example, you can export the inference result to a file and look up in the inference result for the class indexes with top confidence values using single-operators.
- Call aclmdlUnload to unload your model.
- Load the model.
- Single-Operator Execution
If your AI app involves not only model inference but also mathematical operations, such as Basic Linear Algebra Subprogram (BLAS), and data type conversion, and wants to use the compute in Ascend AI Processor, you can use single-operator calling when using acl APIs. In this way, you can avoid additional model building and training. You can also use single-operator calling to verify the functions of a custom operator.
For details about the API call sequence, see Single-Operator Call Sequence.
- Model inference
- Deallocate runtime resources.
When data processing is complete, destroy runtime allocations in sequence. For details about the API call sequence, see Runtime Resource Allocation and Deallocation.
- Perform deinitialization.
Memory allocation and deallocation, data transfer via memory copy, and data type creation and destruction are the most frequent calls across the app development workflow, and therefore are not thoroughly illustrated in the flowchart. For details about memory allocation, deallocation, and copy APIs, see Memory Management. For details about data type creation and destruction APIs, see Data Types and Operation APIs.