aclrtSubscribeReport

Description

Registers 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. Define and implement a callback function. Function prototype: typedef void (*aclrtCallback)(void *userData)
  2. Create a thread. Call aclrtProcessReport in the thread function to set the timeout interval (cyclic calling is required), and wait for the callback task execution.
  3. Call aclrtSubscribeReport to bind the thread created in Step 2 to the stream. The callback function delivered by the stream is executed in the bound thread.
  4. Execute an asynchronous task (for example, an asynchronous inference job) on the specified stream.
  5. Call aclrtLaunchCallback to deliver a callback task in the task queue of the stream and trigger the thread created in step 2 to process the callback function. Each time aclrtLaunchCallback is called, the callback function is executed.
  6. After all asynchronous tasks are executed, call aclrtUnSubscribeReport to unsubscribe from the thread.

Restrictions

  • aclrtSubscribeReport 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, do not call aclrtSubscribeReport to subscribe to multiple threads for processing more than one callback function in the same stream.
  • Do not pass the same thread ID for subscribing to callback functions on different devices in the same process.
  • If the number of threads registered by calling this API in a single process exceeds a specified limit, a failure message is returned. Considering the thread switching performance overhead of the OS, try to keep the number of threads subscribed by this call within 32.

    The maximum number of threads supported by each product model varies, as shown in the following table.

    Model

    Maximum Threads

    Atlas 200/300/500 Inference Product

    128

    Atlas Training Series Product

    1024

Prototype

aclError aclrtSubscribeReport(uint64_t threadId, aclrtStream stream)

Parameters

Parameter

Input/Output

Description

threadId

Input

Thread ID.

stream

Input

Stream.

Returns

The value 0 indicates success, and other values indicate failure. For details, see aclError.

Reference

For details about the API call sequence and sample code, see Asynchronous Model Inference.