aclrtSetExceptionInfoCallback
Applicability
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Description
Sets the exception callback function.
Prototype
aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback)
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
callback |
Input |
Callback function. Prototype: typedef void (*aclrtExceptionInfoCallback)(aclrtExceptionInfo *exceptionInfo); |
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 & release, stream synchronization, device synchronization, task delivery, and task termination in callback functions. Otherwise, errors or deadlocks may occur.
- Set an exception callback function before task execution on the device. When a task fails, the system passes a pointer to the aclrtExceptionInfo structure that contains the task ID, stream ID, thread ID, device ID, and error code to the exception callback function and executes the callback function. You can call aclrtGetTaskIdFromExceptionInfo, aclrtGetStreamIdFromExceptionInfo, aclrtGetThreadIdFromExceptionInfo, aclrtGetDeviceIdFromExceptionInfo, and aclrtGetErrorCodeFromExceptionInfo to obtain the error task ID, stream ID, thread ID, device ID, and error code, respectively, to facilitate fault locating.
Example use case: Before the call, call aclrtSetExceptionInfoCallback to set an exception callback function. When operator execution on the device fails, the system passes a pointer to the aclrtExceptionInfo structure that contains the task ID, stream ID, thread ID, device ID, and error code to the exception callback function and executes the callback function.
- If the exception callback function is set repeatedly, the most recent setting applies.
- To clear the callback function, pass a null pointer to the aclrtSetExceptionInfoCallback call.