| Files | Last commit | Last update |
|---|---|---|
1_stream_with_failure_mode
Description
This sample demonstrates Stream stop-on-error mode and simulates scenarios where errors occur during Stream execution through kernel function tasks.
This sample contains three parts: stop-on-error demonstration on normal Stream, aclrtStreamStop auxiliary demonstration, and aclrtStreamAbort auxiliary demonstration.
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
If the current environment does not meet the additional prerequisites for stop/abort auxiliary demonstrations, the sample will print WARN and skip corresponding auxiliary demonstrations. The aclrtSetStreamFailureMode demonstration in the main flow will still execute.
- 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/stream/1_stream_with_failure_mode
- 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
aclrtResetDeviceForceinterface to forcefully reset the current computation Device and reclaim Device resources.
- Call
- Context Management
- Call
aclrtCreateContextinterface to create Context. - Call
aclrtDestroyContextinterface to destroy Context.
- Call
- Stream Management
- Call
aclrtCreateStreaminterface to create Stream. - Call
aclrtCreateStreamWithConfiginterface to createACL_STREAM_DEVICE_USE_ONLYtype Stream. On Atlas A2/Atlas A3,aclrtStreamStoprequires the target Stream to be created throughaclrtCreateStreamWithConfig(..., ACL_STREAM_DEVICE_USE_ONLY). - Call
aclrtSynchronizeStreaminterface to block and wait for Stream tasks to complete. - Call
aclrtSetStreamFailureModeinterface to set the operation when Stream execution encounters errors. Default is continue on error, can be set to stop on error. - Call
aclrtRegStreamStateCallbackinterface to register Stream status callback. - Call
aclrtStreamStopinterface to stop auxiliary Stream. The sample will separately create a device-use-only Stream and callaclrtStreamStopafter submitting a long-running kernel task on it. - Call
aclrtStreamAbortinterface to abort auxiliary Stream.aclrtStreamAbortdoes not supportACL_STREAM_DEVICE_USE_ONLYStream, so the sample will demonstrate separately on normal Stream. When callingaclrtSynchronizeStreamagain after demonstration, it may return stream abort type status code, which is an expected result. The sample will log this but will not judge the entire flow as failed. - Call
aclrtDestroyStreamForceinterface to forcefully destroy Stream and discard all tasks.
- 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
Sample Output
[INFO] Assigning task without failure mode.
[ERROR] Operation failed: aclrtSynchronizeStream(stream) returned error code 507035
[INFO] Without failure mode, the result is 2.
[INFO] Assigning task with failure mode.
[ERROR] Operation failed: aclrtSynchronizeStream(stream) returned error code 507035
[INFO] After set failure mode, the current result is: 1.
[INFO] aclrtStreamStop returned 0.
[WARN] aclrtSynchronizeStream(after stop) returned 507000.
[INFO] aclrtStreamAbort returned 0.
[INFO] aclrtSynchronizeStream(after abort) returned 507035 after stream abort, which is expected.
[INFO] Resource cleanup completed.
[INFO] Run the stream_with_failure_mode sample successfully.