API Call Sequence
If synchronization in the asynchronous scenario is involved, your app must contain the related code logic. For details about the API call sequence, see the following figure.
The key APIs are described as follows:
- Create a callback function in advance to obtain and process the model inference or operator execution result.
- You need to create a thread in advance and customize a thread function. In the thread function, call the acl.rt.process_report API, set the timeout interval, and wait for the callback task delivered by the acl.rt.launch_callback API to be executed.
- Call the acl.rt.subscribe_report API to specify the thread for processing the callback function in the stream. The thread must be the same as that created in 2.
- Call the acl.mdl.execute_async API during asynchronous inference.
For asynchronous APIs, the acl.rt.synchronize_stream API needs to be called to block application running until all tasks in the specified stream are complete.
You can obtain the asynchronous inference results of all images at a time after the acl.rt.synchronize_stream API is called. However, if the image data volume is large, you need to wait for a long time. In this case, you can use the callback function to deliver a callback task at a specified interval to obtain the asynchronous inference results in the previous period.
- Call acl.rt.launch_callback to deliver a callback task in the task queue of the stream. When the callback task is executed in the system, it is also executed in the thread subscribed to the stream (acl.rt.subscribe_report). The callback function must be the same as that in 1.
Each time acl.rt.launch_callback is called, a callback task is delivered.
- Call the acl.rt.unsubscribe_report API to unsubscribe from a thread. (The callback function on the stream is no longer processed by the specified thread.)