Function: set_exception_info_callback

C Prototype

aclError aclrtSetExceptionInfoCallback(aclrtExceptionInfoCallback callback)

Python Function

ret = acl.rt.set_exception_info_callback(fn)

Function Usage

Sets the exception callback function.

Input Description

fn: 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

ret: int, error code.

Restrictions

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

Reference

For details about the API call example, see AI Core Troubleshooting.