Function: subscribe_report

C Prototype

aclError aclrtSubscribeReport(uint64_t threadId, aclrtStream stream)

Python Function

ret = acl.rt.subscribe_report(thread_id, stream)

Function Usage

Specifies the thread that processes the callback function in the stream in the asynchronous task scenario.

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

thread_id: int, thread ID.

stream: int, pointer address of the stream to be processed.

Return Value

ret: int, error code.

Restrictions

  • acl.rt.subscribe_report can be called for multiple times to subscribe to the same thread for processing the callback function in multiple streams of the same device.

  • To ensure that tasks in a stream can be executed in order, acl.rt.subscribe_report cannot be called to subscribe to multiple threads for processing more than one callback function in the same stream.

  • For the Atlas 200/300/500 Inference Product: If the number of threads subscribed by this call in a single process exceeds 128, a failure code is returned.
  • For the Atlas Training Series Product: If the number of threads subscribed by this call in a single process exceeds 1024, a failure code is returned.
  • Considering the thread switching performance overhead of the operating system, try to keep the number of threads subscribed by this call within 32.

  • It is not allowed to pass the same thread ID for subscribing to different callback functions on different devices in the same process.

Reference