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.
Figure 1 Synchronization flowchart in the callback scenario
The key APIs are described as follows:
- Create a callback function in advance to obtain and process the model inference or operator execution result.
- Create a thread and define a thread function in advance. Once aclrtProcessReport is called in the thread function, the created callback function will be triggered after a specified period of time.
- Call aclrtSubscribeReport to subscribe to a thread for handling the callback function in the stream. You need to create a thread in advance.
- Call aclrtLaunchCallback to add the created callback function to the stream. The callback function will be executed.
- Call aclrtUnSubscribeReport to unsubscribe from a thread, so that the callback function in the stream is no longer handled by the specified thread.
- In the asynchronous inference scenario with callback processing, to ensure all tasks in a stream are complete, and all inference results are handled by the callback function, aclrtSynchronizeStream needs to be called before the stream is destroyed.