Synchronous and Asynchronous APIs
CANN supports the following explicit synchronization types. After calling these types of APIs, the host thread is blocked until the related tasks are completed.
- Device synchronization: aclrtSynchronizeDevice
Blocks the current host thread until all explicitly or implicitly created streams on the device complete all previously delivered tasks. Avoid using this function as much as possible, because it delays host running.
- Stream synchronization: aclrtSynchronizeStream
Blocks the current host thread until the specified stream completes all delivered tasks.
- Event synchronization: aclrtSynchronizeEvent
Blocks the current host thread until the specified event is completed. It is a finer-grained synchronization.
For asynchronous APIs, the API call only indicates that tasks are delivered. Before the tasks are complete, the asynchronous API has returned a success message to the host thread. You need to call the preceding explicit synchronous APIs to block the host thread and wait until the task is complete. Otherwise, service exceptions (such as training or inference exception) or unknown situations (such as device link or card disconnection) may occur.