| Files | Last commit | Last update |
|---|---|---|
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago |
10_simd_stack_budget
Description
This sample demonstrates the complete flow for reserving stack space before a single-Device compute task executes a SIMD Kernel with a large amount of local data. After initialization and before binding the Device, the program configures the per-AI-Core SIMD stack budget for the current process to 64 KiB, a value supported by A2, A3, and A5, and reads the setting back for confirmation. It then runs a validation Kernel that uses 48 KiB of local stack data and verifies the deterministic checksum copied back to the Host. The program returns a nonzero value if the configured budget differs, the Kernel result is incorrect, or any Runtime operation or cleanup fails.
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 is installed, and switch to the sample directory.
cd ${git_clone_path}/example/2_advanced_features/kernel/10_simd_stack_budget
- Set the environment variables.
# Replace ${install_root} with the CANN installation root directory
source ${install_root}/cann/set_env.sh
source ${git_clone_path}/example/set_sample_env.sh
- Run the following command to compile and 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 and Deinitialization
- Call
aclInitto initialize the Runtime environment. - Call
aclFinalizefor deinitialization.
- Call
- Device Management
- Call
aclrtDeviceSetLimitbefore binding a Device to set the SIMD stack budget for the current process to 64 KiB. - Call
aclrtDeviceGetLimitto read and confirm the SIMD stack budget for the current process. - Call
aclrtSetDeviceto select the Device and apply the resource limit configured in advance. - Call
aclrtResetDeviceForceto reset the Device and reclaim its resources.
- Call
- Stream Management
- Call
aclrtCreateStreamto create the Stream used for Kernel execution. - Call
aclrtSynchronizeStreamto wait for the Kernel to finish. - Call
aclrtDestroyStreamForceto destroy the Stream.
- Call
- Device Memory Management
- Call
aclrtMallocto allocate Device memory for the Kernel checksum. - Call
aclrtMemcpyto copy the Kernel checksum to the Host for verification. - Call
aclrtFreeto release the Device memory.
- Call
- Kernel Configuration and Execution
- Call
aclrtBinaryLoadFromFileto load the validation Kernel binary after the SIMD stack budget takes effect. - Call
aclrtBinaryGetFunctionto obtain a function handle from the validation Kernel name. - Call
aclrtLaunchKernelWithArgsArrayto launch the validation Kernel that uses local stack data. - Call
aclrtBinaryUnLoadto unload the validation Kernel binary.
- Call
Sample Output
[INFO] ASCEND_HOME_PATH=...
[INFO] SOC_VERSION=Ascend910_9362
[INFO] ASCENDC_CMAKE_DIR=...
...
[INFO] Start to run the 10_simd_stack_budget sample.
[INFO] Configured and verified the SIMD stack budget: 65536 bytes.
[INFO] Verified Kernel checksum 723969 using 49152 bytes of local stack data.
[INFO] Run the 10_simd_stack_budget sample successfully.