aclrtLaunchHostFunc
Applicability
Product |
Supported |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Description
Delivers a host callback task in the task queue of a stream. When the callback task is executed, the callback function is also executed in the thread subscribed on the stream (the thread is created and subscribed within this API). By default, the callback task blocks the execution of subsequent tasks in the stream. This API is asynchronous.
This API implements callback in the asynchronous scenario. This API is different from other callback APIs (aclrtLaunchCallback, aclrtSubscribeReport, aclrtProcessReport, and aclrtUnSubscribeReport) in the asynchronous scenario. When the APIs such as aclrtLaunchCallback are called, the thread to subscribe on the stream must be user-created and subscribed through the aclrtSubscribeReport API. In addition, you can specify whether the callback task blocks the execution of subsequent tasks on the stream.
For the same stream, these two APIs cannot be used together to implement a callback function in the asynchronous scenario. Otherwise, an exception may occur.
Prototype
aclError aclrtLaunchHostFunc(aclrtStream stream, aclrtHostFunc fn, void *args)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
stream |
Input |
Stream for executing a callback task. |
fn |
Input |
Callback function to add. The prototype of the callback function is as follows: typedef void (*aclrtHostFunc)(void *args) |
args |
Input |
User specified data to be passed to the callback function. |
Returns
0 on success; else, failure. For details, see aclError.
Restrictions
Callback functions involve shared resources (such as locks). Exercise caution when using callback functions. Do not call APIs for resource application, resource release, stream synchronization, device synchronization, task delivery, and task termination. Otherwise, errors or deadlocks may occur.