aclrtLaunchHostFunc

Applicable Products

Product

Supported

Ascend 950PR / Ascend 950DT

√

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

√

Function

Delivers a host callback task in the task queue of a stream. When the callback task is executed in the system, the callback function is also executed in the thread subscribed in 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 is an asynchronous API.

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 in 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 in 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.

Prototype:

typedef void (*aclrtHostFunc)(void *args)

args

Input

User 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.