Function: launch_callback

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)

Function Usage

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 (acl.rt.subscribe_report). This API is asynchronous.

This API must be work with the following APIs to implement the callback function in asynchronous scenarios:
  1. Create a thread. Once acl.rt.process_report in the thread function is called to set the timeout interval (cyclic calling is required), acl.rt.launch_callback will deliver a callback task after a period of time.
  2. 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.
  3. Execute an asynchronous task (for example, an asynchronous inference task) on the specified stream.
  4. 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.
  5. Call acl.rt.unsubscribe_report to unsubscribe from threads and unbind threads from streams after all asynchronous tasks are executed.

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.
  • 0: not blocked. For the Atlas 200/300/500 Inference Product, this option is not supported in the current version and is reserved.
  • 1: blocked.

stream: int, stream.

Return Value

ret: int, error code.

Restrictions

This API is asynchronous. The API call delivers a task rather than executes a task. After this API is called, call the synchronization API (for example, acl.rt.synchronize_stream) to ensure that the task is complete.

Reference