Synchronous Wait of Tasks Between Streams (Implemented Using Events)
The synchronization of tasks between multiple streams can be implemented by using events. The acl.rt.stream_wait_event API is called to block the running 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 process, see Single-Operator Execution.
Figure 1 Synchronization between streams
Following the API calls, add exception handling branches and specify log printing of error and information levels. The following is a code snippet of key steps only, which is not ready to use.
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