Synchronous Wait of Tasks Between Streams (Implemented Using Notify)
Synchronous wait of tasks between streams can be implemented using Notify. For example, if the tasks in stream2 depend on the tasks in stream1 and you want to ensure that the tasks in stream1 are complete first, you can create a Notify object, call acl.rt.record_notify to insert the Notify object into stream 1 (usually called a Record Notify task), and call acl.rt.wait_and_reset_notify to insert a task that waits for the completion of Notify into stream2 (usually called a Wait Notify task).
For details about the loading and execution process of models and operators, see Model Management and Single-Operator Calling, respectively.
After APIs are called, add an exception handling branch, and record error logs and warning logs. The following is a code snippet of key steps only, which is not ready to be built or run.
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 a Notify object. notify, ret = acl.rt.create_notify(0) # Create stream_1 and stream_2. stream_1, ret = acl.rt.create_stream() stream_2, ret = acl.rt.create_stream() # Append the Notify object to stream_1. ret = acl.rt.record_notify(notify, stream_1) # Block stream_2 until the specified Notify occurs, which means stream_1 is executed. # Wake up stream_2 for execution after stream_1 is complete. ret = acl.rt.wait_and_reset_notify(notify, stream_2, 0) ret = acl.rt.synchronize_stream(stream_1) ret = acl.rt.synchronize_stream(stream_2) # Explicitly destroy resources. ret = acl.rt.destroy_stream(stream_2) ret = acl.rt.destroy_stream(stream_1) ret = acl.rt.destroy_notify(notify) # ...... |