aclrtRecordEvent
Description
Records an event in a stream.
aclrtRecordEvent and aclrtStreamWaitEvent are used together for synchronization between streams. When aclrtRecordEvent is called, the system applies for event resources. After aclrtStreamWaitEvent is called: Call aclrtResetEvent to release event resources in a timely manner. If multiple streams are waiting for the same event, call aclrtStreamWaitEvent for all the streams and then call aclrtResetEvent to release event resources. API invoking sequence: aclrtCreateEvent-->aclrtRecordEvent-->aclrtStreamWaitEvent-->aclrtResetEvent.
When the aclrtRecordEvent API is called, AscendCL captures the tasks delivered in the current stream and records them in the event. Therefore, when the aclrtQueryEventStatus or aclrtStreamWaitEvent API is called later, AscendCL checks or waits until all the tasks captured in the event are complete.
For events created using aclrtCreateEventExWithFlag:
- aclrtRecordEvent supports event reuse for multiple records of the same event. Each record captures the tasks that have been delivered on the current stream and overwrites the tasks in the event. When aclrtStreamWaitEvent is called, the task saved in the latest event is used and will not be affected by subsequent calling of aclrtRecordEvent.
- Before the aclrtRecordEvent API is called for the first time, ACL_EVENT_RECORDED_STATUS_COMPLETE is returned when aclrtQueryEventStatus is called because there is no task in the event.
Restrictions
This API is asynchronous. The API call delivers a task rather than executes a task. After this API is called, you need to call the synchronization waiting API (for example, aclrtSynchronizeStream) to ensure that the task is complete. Otherwise, service exceptions such as training or inference, device disconnection, and card disconnection may occur.
Prototype
aclError aclrtRecordEvent(aclrtEvent event, aclrtStream stream)
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
event |
Input |
Event to record. |
|
stream |
Input |
Stream. For example, in the Stream1 scenario such as Stream2, set this parameter to Stream1. To specify the default stream, pass NULL. |
Returns
The value 0 indicates success, and other values indicate failure. For details, see aclError.