| Files | Last commit | Last update |
|---|---|---|
0_device_normal
Description
This sample demonstrates the basic usage flow of CANN Runtime Device management, including initialization, specifying Device, creating Stream, executing aclnnAdd vector addition operator, synchronously waiting for task completion, and releasing resources.
Product Support
This sample supports the following products:
| Product | Supported |
|---|---|
| Ascend 950PR/Ascend 950DT | Yes |
| Atlas A3 training series products/Atlas A3 inference series products | Yes |
| Atlas A2 training series products/Atlas A2 inference series products | Yes |
Compile and Run
- Download the sample code to the environment where CANN software is installed. Switch to the sample directory.
cd ${git_clone_path}/example/1_basic_features/device/0_device_normal
- Set environment variables.
# Replace ${install_root} with the CANN installation root directory. The default installation is in the `/usr/local/Ascend` directory.
source ${install_root}/cann/set_env.sh
# Set SOC_VERSION and ASCENDC_CMAKE_DIR
# -SOC_VERSION: Ascend AI processor model, such as Ascend910_9362, Ascend910B2, and so on
# -ASCENDC_CMAKE_DIR: The sample involves calling AscendC operators. Configure the AscendC compiler ascendc.cmake path, such as /usr/local/Ascend/cann/x86_64-linux/tikcpp/ascendc_kernel_cmake
source ${git_clone_path}/example/set_sample_env.sh
- Run the following command to execute the sample.
bash run.sh
CANN RUNTIME API
The key functionality points and their key interfaces involved in this sample are as follows:
- Initialization
- Call
aclInitinterface for initialization configuration. - Call
aclFinalizeinterface for deinitialization.
- Call
- Device Management
- Call
aclrtSetDeviceinterface to specify the Device for computation. - Call
aclrtSynchronizeDeviceinterface to block and wait for the computing Device to complete computation. - Call
aclrtResetDeviceForceinterface to forcefully reset the current computation Device and reclaim Device resources.
- Call
- Stream Management
- Call
aclrtCreateStreaminterface to create a Stream. - Call
aclrtSynchronizeStreaminterface to block and wait for Stream tasks to complete. - Call
aclrtDestroyStreaminterface to destroy a Stream.
- Call
- Memory Management
- Call
aclrtMallocinterface to allocate memory on Device. - Call
aclrtFreeinterface to release memory on Device.
- Call
- Data Transfer
- Call
aclrtMemcpyinterface to implement data transfer through memory copy.
- Call
- Operator Execution
- Call
aclnnAddGetWorkspaceSizeinterface to get workspace information required foraclnnAddoperator execution. - Call
aclnnAddinterface to execute vector addition operator.
- Call
Sample Output
[INFO]: Current compile soc version is ...
...
[INFO] Start to run device_normal sample.
[INFO] result[0] is: 1.200000
[INFO] result[1] is: 2.200000
[INFO] result[2] is: 3.200000
[INFO] result[3] is: 5.400000
[INFO] result[4] is: 6.400000
[INFO] result[5] is: 7.400000
[INFO] result[6] is: 9.600000
[INFO] result[7] is: 10.600000
[INFO] Run the device_normal sample successfully.