Synchronous Wait of Tasks Between Streams (Implemented Using Events)
Synchronization of tasks between streams can be implemented by using events. Call acl.rt.stream_wait_event to block the execution of a specified stream until the specified event is complete. Call acl.rt.record_event before the acl.rt.stream_wait_event call.
For details about the model loading and execution workflow, see Model Management.
For details about the operator loading and execution workflow, see Single-Operator Calling.
Figure 1 Synchronization between streams
After APIs are called, add an exception handling branch, and record error logs and warning logs. The sample code of key steps is as follows, which is for reference only. Do not directly copy and run the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import acl # ...... # Create an event. event, ret = acl.rt.create_event() # Create two streams. s1, ret = acl.rt.create_stream() s2, ret = acl.rt.create_stream() # Append an event to s1. ret = acl.rt.record_event(event, s1) # Block s2 until the event is complete, that is, the completion of s1. # Wake up s2 for execution after s1 is complete. ret = acl.rt.stream_wait_event(s2, event) ret = acl.rt.synchronize_stream(s1) ret = acl.rt.synchronize_stream(s2) # Explicitly destroy resources. ret = acl.rt.destroy_stream(s2) ret = acl.rt.destroy_stream(s1) ret = acl.rt.destroy_event(event) # ...... |
Parent topic: Synchronous Wait