aclrtLaunchHostFunc

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

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 callback in the asynchronous scenario. Otherwise, an exception may occur.

Prototype

1
aclError aclrtLaunchHostFunc(aclrtStream stream, aclrtHostFunc fn, void *args)

Parameters

Parameter

Input/Output

Description

stream

Input

Stream for executing a callback task. For details about the type definition, see aclrtStream.

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; otherwise, 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.

API Call Example

For the API call example, see Host Callback Task.