AscendCL API Call Sequence
This section describes the process of calling AscendCL APIs and the header and library files required for calling AscendCL APIs.
API Call Sequence
By calling AscendCL APIs, you can develop applications 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 AscendCL 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.
- Initialize AscendCL.
- Allocate runtime resources.
For details, see Runtime Resource Allocation and Deallocation.
- Process app services.
- Model inference
- Load the model.
For 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 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 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, use single-operator calling when using AscendCL 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 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.
- Deinitialize AscendCL.
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 and deallocation, and memory copy APIs, see Memory Management. For details about data type creation and destruction APIs, see acltdtStopChannel.
Dependent Header Files and Library Files
Include the dependency header files based on the AscendCL APIs to be called. Refer to following table for details.
The AscendCL header file is stored in the “${INSTALL_DIR}/include/ directory, and the AscendCL library file is stored in the “${INSTALL_DIR}/lib64/ directory. Replace ${INSTALL_DIR} with the actual CANN component directory. If the Ascend-CANN-Toolkit package is installed as the root user, the CANN component directory is /usr/local/Ascend/ascend-toolkit/latest.
When building code based on the AscendCL APIs, depend on the corresponding library files based on the included header files. If redundant .so files (such as libascendcl.a) are referenced, version functions may be abnormal or compatibility issues may occur during version update.
|
Header File |
Description |
Matching Library |
|---|---|---|
|
acl/acl_base.h |
Declares basic data types (such as aclDataBuffer and aclTensorDesc) and their operation APIs, enumerations (such as aclFormat), and log management APIs. |
libascendcl.so |
|
acl/acl.h |
Has already included acl/acl_mdl.h, acl/acl_rt.h, and acl/acl_op.h. Once the acl.h file is included, APIs related to initialization/deinitialization, device management, group management, context management, stream management, synchronization, memory management, model loading and execution, single-operator execution (some of the APIs) can be referenced. |
libascendcl.so |
|
acl/acl_prof.h |
Declares the Profiling configuration APIs. |
libmsprofiler.so
NOTE:
libascendcl.so is supported in earlier versions to avoid compatibility issues. However, it will be removed in later versions. Therefore, you are advised to use libmsprofiler.so to ensure compatibility with later versions. |
|
acl/ops/acl_cblas.h |
Declares the CBLAS APIs. |
libacl_cblas.so |
|
acl/ops/acl_dvpp.h |
Declares the media data processing V1 APIs. |
libacl_dvpp.so |
|
acl/ops/acl_fv.h |
Declares the feature vector search APIs. |
libacl_retr.so |
|
acl/acl_op_compiler.h |
Declares the APIs, data types, and enumerations related to online operator compilation such as aclopCompile, aclopCompileAndExecute, and aclSetCompileopt. |
libacl_op_compiler.so |
|
acl/acl_tdt.h |
Declares the tensor data transfer APIs. |
libacl_tdt_channel.so |
|
acl/acl_tdt_queue.h |
Declares the shared queue management and shared buffer management APIs. |
libacl_tdt_queue.so |
|
acl/dvpp/hi_dvpp.h |
Declares the media data processing V2 APIs. |
libacl_dvpp_mpi.so |
|
In the acl/media directory: hi_mpi_vi.h hi_common_vi.h hi_common_dis.h hi_common_gdc.h hi_media_common.h hi_media_type.h hi_mpi_sys.h |
Declares the video input (VI) data obtaining APIs. |
libacl_vi_mpi.so libacl_dvpp_mpi.so |
|
In the acl/media directory: hi_mpi_isp.h hi_common_isp.h hi_common_3a.h hi_mpi_ae.h hi_common_ae.h hi_mpi_awb.h hi_common_awb.h hi_common_sns.h hi_media_common.h hi_media_type.h hi_mpi_sys.h |
Declares the image signal processing (ISP) system control APIs. |
libacl_isp_ae_mpi.so libacl_isp_awb_mpi.so libacl_isp_mpi.so libacl_dvpp_mpi.so |
|
In the acl/media directory: hi_mpi_vpss.h hi_media_common.h hi_media_type.h hi_mpi_sys.h |
Declares the video process sub-system (VPSS) image processing APIs. |
libacl_vpss_mpi.so libacl_dvpp_mpi.so |
|
acl/media/hi_mipi_rx.h |
Declares the MIPI RX ioctl command word. |
- |
|
In the acl/media directory: hi_mpi_audio.h hi_common_aio.h |
Declares the audio input and output APIs. |
libacl_audio_mpi.so |
|
acl/media/hi_acodec.h |
Declares the volume adjusting command word. |
- |
|
In the acl/media directory: hi_common_vo.h hi_mpi_vo.h |
Declares the video output APIs. |
libacl_vo_mpi.so |
|
acl/media/hi_mpi_hdmi.h |
Declares the HDMI APIs for connecting to peripherals. |
libacl_hdmi_mpi.so |
|
acl/media/hi_mpi_tde.h |
Declares the TDE APIs for graphics drawing. |
libacl_tde_mpi.so |
|
acl/media/hifb.h |
Declares APIs for managing overlaid graphics layers. |
- |
|
aclnn/acl_meta.h |
Defines the AscendCL meta APIs on which single-operator API execution depends, which can be used to build different data structures, such as aclTensor, aclScalar, and aclIntArray. |
libnnopbase.so |
|
aclnn/aclnn_base.h |
Defines the common base APIs for single-operator API execution, that is, aclnnInit and aclnnFinalize. |
libnnopbase.so |
|
aclnnop/aclnn_*.h (* indicates the operator name.)
NOTE:
The path of the NN/fusion operator header file will be changed from aclnnop/level2/aclnn_*.h to aclnnop/aclnn_*.h. You are advised to use the new path in later versions to prevent compatibility issues. |
Defines APIs for single-operator API execution, such as NN and fusion operator APIs. |
NOTICE:
|
|
In the acldvppop directory: acldvpp_base.h acldvpp_op_api.h |
Defines the functional APIs of DVPP operators. |
libacl_dvpp_op.so |