Function: launch_callback
Applicable Products
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
- Atlas 200I/500 A2 inference products: Supported
- Atlas inference products: Supported
- Atlas training products: Supported
Function
Delivers a callback task in the task queue of the stream in the asynchronous task scenario. When the callback task is executed in the system, it is also executed in the thread subscribed to on the stream (registered by calling acl.rt.subscribe_report). This API is asynchronous.
This API must work with the following APIs to implement the callback function in asynchronous scenarios:
- Create a thread. Call acl.rt.process_report in the thread function to set the timeout interval (cyclic calling is required), and wait for the function callback task delivered by acl.rt.launch_callback.
- Call acl.rt.subscribe_report to bind the thread created in step 1 to the stream. The callback task delivered by the stream is executed in the bound thread.
- Execute an asynchronous job (for example, an asynchronous inference job) on the specified stream.
- Define and implement the callback function, call acl.rt.launch_callback to deliver a callback task in the task queue of the stream, and trigger the thread to process the callback function subscribed by acl.rt.subscribe_report. Each time acl.rt.launch_callback is called, a callback task is delivered.
- Call acl.rt.unsubscribe_report to unsubscribe from threads and unbind threads from streams after all asynchronous tasks are executed.
Prototype
-
C Prototype
aclError aclrtLaunchCallback(aclrtCallback fn, void *userData, aclrtCallbackBlockType blockType, aclrtStream stream) -
Python Function
ret = acl.rt.launch_callback(fn, user_data_list, block_type, stream)
Parameters
| Parameter | Description |
|---|---|
| fn | Function, callback function on the Python side. |
| user_data_list | List, parameters to be transferred to the callback function. Currently, data of the list type is transferred. |
| block_type | Int, whether the callback task blocks subsequent tasks in the stream.0: not blocked.1: blocked. |
| stream | Int, stream. |
Return Values
| Return Value | Description |
|---|---|
| ret | Int, error code. If 0 is returned, the operation is successful. If other values are returned, the operation fails. |
Constraints
This API is asynchronous. A successful call indicates only that the task has been delivered, not that it has completed. After calling this API, call a synchronization API (for example, acl.rt.synchronize_stream) to ensure that the task is complete.