0_ipcevent
Description
This sample demonstrates task synchronization between two processes using IPC Event.
- Process A (producer): Creates IPC event, records event and exports handle, then waits for consumer to complete.
- Process B (consumer): Imports IPC event handle, waits for event, completes work then records event to notify producer.
This sample uses binary file to pass event handle, demonstrating core IPC event usage: create, export, import, wait, record, query, and destroy.
Product Support
| 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 |
Build and Run
This sample launches proc_a and proc_b processes simultaneously by run.sh, and exchanges IPC Event handle through temporary file.
For environment installation details and general running steps, see README in the example directory.
CANN RUNTIME API
Key features and interfaces in this sample:
- Initialization
- Call
aclInitinterface to initialize configuration. - Call
aclFinalizeinterface to deinitialize.
- Call
- Device Management
- Call
aclrtSetDeviceinterface to specify Device for computation. - Call
aclrtResetDeviceinterface to reset Device.
- Call
- Stream Management
- Call
aclrtCreateStreaminterface to create Stream. - Call
aclrtSynchronizeStreaminterface to block waiting for Stream task completion. - Call
aclrtDestroyStreaminterface to destroy Stream.
- Call
- Event Management
- Call
aclrtCreateEventExWithFlaginterface to create IPC-enabled Event. - Call
aclrtRecordEventinterface to record Event. - Call
aclrtSynchronizeEventinterface to block waiting for Event completion. - Call
aclrtQueryEventStatusinterface to query Event status. - Call
aclrtIpcGetEventHandleinterface to get Event IPC handle. - Call
aclrtIpcOpenEventHandleinterface to open IPC Event. - Call
aclrtStreamWaitEventinterface to block Stream waiting for Event completion. - Call
aclrtDestroyEventinterface to destroy Event.
- Call
Sample Output
[INFO] Process A: IPC event created
[INFO] Process A: event recorded and synchronized
[INFO] Process A: event status = 1 (1=completed)
[INFO] Process A: IPC event handle written to ./event_handle.bin
[INFO] Process A: consumer finished
[INFO] Process A: cleanup completed
[INFO] Process B: IPC event opened
[INFO] Process B: event received, stream synchronized
[INFO] Process B: event status = 1 (1=completed)
[INFO] Process B: cleanup completed
[SUCCESS] IPC event synchronization works correctly.