Function: set_exception_info_callback
Applicability
|
Product |
Supported (√/x) |
|---|---|
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Function Usage
Sets the exception callback function.
Prototype
- C Prototype
1aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback)
- Python Function
1ret = acl.rt.set_exception_info_callback(fn)
Parameter Description
|
Parameter |
Description |
|---|---|
|
callback |
Function, callback function on the Python side. The format is as follows: def exception_callback(exception_info) """ :exception_info: pointer address of aclrtExceptionInfo. :return: """ |
Return Value Description
|
Return Value |
Description |
|---|---|
|
ret |
Int, error code: 0 on success; else, failure. |
Restrictions
- Callback functions involve shared resources (such as locks). Exercise caution when using callback functions. Do not call other APIs for resource allocation, resource deallocation, stream synchronization, device synchronization, task delivery, and task termination except the APIs of the callback function call in the AI Core Troubleshooting example. 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 address of aclrtExceptionInfo 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 acl.rt.get_task_id_from_exception_info, acl.rt.get_stream_id_from_exception_info, acl.rt.get_thread_id_from_exception_info, acl.rt.get_device_id_from_exception_info, and acl.rt.get_error_code_from_exception_info 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 acl.op.execute_v2 call, call acl.rt.set_exception_info_callback to set an exception callback function. When operator execution on the device fails, the system passes a pointer address of aclrtExceptionInfo 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 None or no parameter to the acl.rt.set_exception_info_callback call.