aclrtSubscribeReport
Applicability
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Description
Subscribes to a thread for handling the callback function in a stream.
- Define and implement a callback function. Function prototype: typedef void (*aclrtCallback)(void *userData)
- Create a thread. Call aclrtProcessReport in the thread function to set the timeout interval (cyclic calling is required), and wait for the callback task to be executed.
- 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.
- Execute an asynchronous task (for example, an asynchronous inference job) on the specified stream.
- 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.
- After all asynchronous tasks are executed, call aclrtUnSubscribeReport to unsubscribe from the thread.
Prototype
aclError aclrtSubscribeReport(uint64_t threadId, aclrtStream stream)
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
threadId |
Input |
Thread ID. |
|
stream |
Input |
Stream. |
Returns
0 on success; else, failure. For details, see aclError.
Restrictions
- aclrtSubscribeReport can be called 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 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 A3 training products /Atlas A3 inference products Atlas A2 training products /Atlas A2 inference products Atlas 200I/500 A2 inference products Atlas inference products Atlas training products 1024