aclrtSubscribeReport

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

Description

Subscribes to a thread for handling the callback function in a stream.

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.

Prototype

1
aclError aclrtSubscribeReport(uint64_t threadId, aclrtStream stream)

Parameters

Parameter

Input/Output

Description

threadId

Input

Thread ID.

stream

Input

Stream. For details about the type definition, see aclrtStream.

Returns

0 on success; otherwise, failure. For details, see aclError.

Restrictions

Calling aclrtSubscribeReport multiple times to register the same callback thread for multiple streams is supported (restricted to multiple streams within the same device); To ensure that tasks within a stream are executed in the order of invocation, registering multiple callback threads for a single stream via aclrtSubscribeReport is not supported; Within the same process, the same thread ID cannot be specified when registering callback threads across different devices.

If the number of threads subscribed by this call in a single process exceeds a specified limit, a failure code is returned. Considering the thread switching performance overhead of the OS, try to keep the number of threads subscribed by the aclrtSubscribeReport call within 32. The maximum number of threads supported by each product model varies, as shown in the following table.

Model

Maximum Threads

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

1024

See Also

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