Synchronization
- Function: create_event
- Function: destroy_event
- Function: record_event
- Function: reset_event
- Function: query_event
- Function: synchronize_event
- Function: event_elapsed_time
- Function: stream_wait_event
- Function: synchronize_device
- Function: synchronize_stream
- Function: subscribe_report
- Function: launch_callback
- Function: process_report
- Function: unsubscribe_report
- Function: set_exception_info_callback
- Function: get_task_id_from_exception_info
- Function: get_stream_id_from_exception_info
- Function: get_thread_id_from_exception_info
Function: create_event
C Prototype |
aclError aclrtCreateEvent(aclrtEvent *event) |
---|---|
Python Function |
event, ret = acl.rt.create_event() |
Function Usage |
Creates an event. It is a synchronous interface. |
Input Description |
None |
Return Value |
event: int, event object pointer. ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: destroy_event
C Prototype |
aclError aclrtDestroyEvent(aclrtEvent event) |
---|---|
Python Function |
ret = acl.rt.destroy_event(event) |
Function Usage |
Destroys an event. Only the events created by calling acl.rt.create_event can be destroyed. It is a synchronous interface. Before destroying an event, ensure that the tasks involved in acl.rt.synchronize_event or acl.rt.stream_wait_event are complete. |
Input Description |
event: int, event pointer to be destroyed. |
Return Value |
ret: int, error code.
|
Restrictions |
Destruction API: The released or destroyed resources are no longer available after this API is called. You are advised to set the released or destroyed resources to invalid values (for example, 0 or None) after calling this API. When calling the acl.rt.destroy_event API to destroy an event, ensure that the event is not being used by other APIs. |
Precautions |
None |
Function: record_event
C Prototype |
aclError aclrtRecordEvent(aclrtEvent event, aclrtStream stream) |
---|---|
Python Function |
ret = acl.rt.record_event(event, stream) |
Function Usage |
Records an event in a stream. It is a synchronous interface. |
Input Description |
event: int, event pointer to be recorded. stream: int. Record the event in the specified stream. If the default stream is used, set this parameter to 0. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: reset_event
C Prototype |
aclError aclrtResetEvent(aclrtEvent event, aclrtStream stream) |
---|---|
Python Function |
ret = acl.rt.reset_event(event, stream) |
Function Usage |
Resets an event. Resets the event only after all tasks in the stream are completely executed. It is a synchronous interface. |
Input Description |
event: int, event object pointer to be reset. stream: int, stream object pointer where the event is located. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: query_event
C Prototype |
aclError aclrtQueryEvent(aclrtEvent event, aclrtEventStatus *status) |
---|---|
Python Function |
status, ret = acl.rt.query_event(event) |
Function Usage |
Queries the status of an event. It is a synchronous interface. |
Input Description |
event: int, event object pointer to be queried. |
Return Value |
status: int, event status.
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: synchronize_event
C Prototype |
aclError aclrtSynchronizeEvent(aclrtEvent event) |
---|---|
Python Function |
ret = acl.rt.synchronize_event(event) |
Function Usage |
Blocks application execution and waits for the event to be complete. It is a synchronous interface. |
Input Description |
event: int, event object pointer to be waited for. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: event_elapsed_time
C Prototype |
aclError aclrtEventElapsedTime(float *ms, aclrtEvent start, aclrtEvent end) |
---|---|
Python Function |
ms, ret = acl.rt.event_elapsed_time(start, end) |
Function Usage |
Collects statistics on the elapsed time between two events. It is a synchronous interface. |
Input Description |
start: int, start event object pointer. end: int, end event object pointer. |
Return Value |
ms: float, duration between two events, in milliseconds. ret: int, error code.
|
Restrictions |
The API calling sequence is as follows: call acl.rt.create_event to create an event -> call acl.rt.record_event to record the start event and end event in the same stream-> call acl.rt.synchronize_stream to block application execution until all tasks in the specified stream are complete -> call acl.rt.event_elapsed_time to collect statistics on the elapsed time between two events. |
Precautions |
None |
Function: stream_wait_event
C Prototype |
aclError aclrtStreamWaitEvent(aclrtStream stream, aclrtEvent event) |
---|---|
Python Function |
ret = acl.rt.stream_wait_event(stream, event) |
Function Usage |
Blocks the execution of a stream until the specified event is complete. It is a synchronous interface. It is allowed for multiple streams to wait for a single event. acl.rt.record_event and acl.rt.stream_wait_event are used in conjunction for synchronization between streams. When acl.rt.record_event is called, an event resource is allocated. After acl.rt.stream_wait_event is called, acl.rt.reset_event should be called to release the event resource in a timely manner. Interfaces calling sequence: acl.rt.create_event --> acl.rt.record_event --> acl.rt.stream_wait_event --> acl.rt.reset_event. |
Input Description |
stream: int, stream that needs to wait for the event to complete. Pass 0 if the default stream is used. event: int, event to be waited for. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: synchronize_device
C Prototype |
aclError ret = aclrtSynchronizeDevice(); |
---|---|
Python Function |
ret = acl.rt.synchronize_device() |
Function Usage |
Blocks application execution until the ongoing computation on the device is complete. It is a synchronous interface. In the multi-device scenario, device of the current context is waited. |
Input Description |
None |
Return Value |
ret: int, error code.
|
Restrictions |
Concurrent calls to synchronize_device in multithreaded processes is not allowed. |
Precautions |
None |
Function: synchronize_stream
C Prototype |
aclError aclrtSynchronizeStream(aclrtStream stream) |
---|---|
Python Function |
ret = acl.rt.synchronize_stream(stream) |
Function Usage |
Block application execution until all tasks in a specified stream are complete. It is a synchronous interface. |
Input Description |
event: int, stream object pointer that needs to complete all tasks. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: subscribe_report
C Prototype |
aclError ret = aclrtSubscribeReport(thread_id, stream); |
---|---|
Python Function |
ret = acl.rt.subscribe_report(thread_id, stream) |
Function Usage |
Specifies the thread that processes the callback function in the stream. It is a synchronous interface. |
Input Description |
thread_id: int, thread ID. stream: int, stream object pointer to be processed. |
Return Value |
ret: int, error code.
|
Restrictions |
|
Precautions |
None |
Function: launch_callback
C Prototype |
aclError ret = aclrtLaunchCallback(aclrtCallback fn, void *userData, aclrtCallbackBlockType blockType, aclrtStream stream) |
---|---|
Python Function |
ret = acl.rt.launch_callback(fn, user_data_list, block_type, stream) |
Function Usage |
Adds a callback function executed on the host or device to the stream task queue. It is an asynchronous interface. |
Input Description |
fn: function, callback function on the Python side. user_data_list: parameters to be transferred to the callback function. Currently, data of the list type is transferred. block_type: int, whether a thread is blocked.
stream: int, stream. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: process_report
C Prototype |
aclError ret = aclrtProcessReport(timeout); |
---|---|
Python Function |
ret = acl.rt.process_report(timeout) |
Function Usage |
Triggers callback handling after a specified period. (Thread specified by acl.rt.subscribe_report handles the callback.) It is a synchronous interface. A thread needs to be created to call acl.rt.process_report in the thread function. |
Input Description |
timeout: int, timeout interval, in milliseconds. The value can be as follows:
|
Return Value |
ret: int, error code.
|
Restrictions |
This function needs to be called in the callback function. |
Precautions |
None |
Function: unsubscribe_report
C Prototype |
aclError ret = aclrtUnSubscribeReport(thread_id, stream); |
---|---|
Python Function |
ret = acl.rt.unsubscribe_report(thread_id, stream) |
Function Usage |
Unsubscribes a thread and specifies a callback function in a stream to not be handled by a specified thread. It is a synchronous interface. |
Input Description |
thread_id: int, thread ID. stream: int, stream object pointer to be processed. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: set_exception_info_callback
C Prototype |
aclError ret = aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback) |
---|---|
Python Function |
ret = acl.rt.set_exception_info_callback(fn) |
Function Usage |
Sets the exception callback function. When an exception occurs during task execution on the device, the system transfers an aclExceptionInfo structure pointer that contains the task ID, stream ID, and thread ID to the exception callback function and executes the callback function. |
Input Description |
fn: function, callback function on the Python side. |
Return Value |
ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: get_task_id_from_exception_info
C Prototype |
uint32_t streamId = aclrtGetTaskIdFromExceptionInfo(const aclrtExceptionInfo *info) |
---|---|
Python Function |
task_id = acl.rt.get_task_id_from_exception_info(info) |
Function Usage |
Obtains the current task ID from the pointer of the aclExceptionInfo structure. |
Input Description |
info: int, pointer object of the aclrtExceptionInfo structure. |
Return Value |
task_id: int, ID of the current task. |
Restrictions |
None |
Precautions |
None |
Function: get_stream_id_from_exception_info
C Prototype |
uint32_t streamId = aclrtGetStreamIdFromExceptionInfo(const aclrtExceptionInfo *info) |
---|---|
Python Function |
stream_id = acl.rt.get_stream_id_from_exception_info(info) |
Function Usage |
Obtains the current stream ID from the pointer of the aclExceptionInfo structure. |
Input Description |
info: int, pointer object of the aclrtExceptionInfo structure. |
Return Value |
stream_id: int, ID of the current stream. |
Restrictions |
None |
Precautions |
None |
Function: get_thread_id_from_exception_info
C Prototype |
uint32_t streamId = aclrtGetThreadIdFromExceptionInfo(const aclrtExceptionInfo *info) |
---|---|
Python Function |
thread_id = acl.rt.get_thread_id_from_exception_info(info) |
Function Usage |
Obtains the current thread ID from the pointer of the aclExceptionInfo structure. |
Input Description |
info: int, pointer object of the aclrtExceptionInfo structure. |
Return Value |
thread_id: int, ID of the current thread. |
Restrictions |
None |
Precautions |
None |
- Function: create_event
- Function: destroy_event
- Function: record_event
- Function: reset_event
- Function: query_event
- Function: synchronize_event
- Function: event_elapsed_time
- Function: stream_wait_event
- Function: synchronize_device
- Function: synchronize_stream
- Function: subscribe_report
- Function: launch_callback
- Function: process_report
- Function: unsubscribe_report
- Function: set_exception_info_callback
- Function: get_task_id_from_exception_info
- Function: get_stream_id_from_exception_info
- Function: get_thread_id_from_exception_info