For example, if an AI Core error is reported during network inference, you can call this API to obtain the description of the error operator and then perform further troubleshooting.
The key steps for implementing the callback function are as follows:
For example, call aclGetTensorDescAddress to obtain the tensor data address, call aclGetTensorDescType to obtain the data type in the tensor description, call aclGetTensorDescFormat to obtain the tensor format, call aclGetTensorDescNumDims to obtain the tensor dimension count, and call aclGetTensorDescDimV2 to obtain the size of a specified dimension.
If an AI Core error is reported, the callback function fn is triggered to obtain the operator information for further troubleshooting.
Following the API calls, add exception handling branches and specify log printing of error and information levels. The following is a code snippet of key steps only, which is not ready to be built or run.
//1. Initialize AscendCL.
//2. Allocate runtime resources, including setting the compute device and creating a context and a stream.
//3. Load your model. After the model is successfully loaded, modelId that identifies the model is returned.
//4. Create data of type aclmdlDataset to describe the inputs and outputs of your model.
//5. Implement an exception callback function.
void callback(aclrtExceptionInfo *exceptionInfo)
{
deviceId = aclrtGetDeviceIdFromExceptionInfo(exceptionInfo);
streamId = aclrtGetStreamIdFromExceptionInfo(exceptionInfo);
taskId = aclrtGetTaskIdFromExceptionInfo(exceptionInfo);
char opName[256];
aclTensorDesc *inputDesc = nullptr;
aclTensorDesc *outputDesc = nullptr;
size_t inputCnt = 0;
size_t outputCnt = 0;
//You can write the obtained operator information to a file, or start another thread. When an error occurs, the thread handling function is triggered, and the operator information is printed to the screen.
aclmdlCreateAndGetOpDesc(deviceId, streamId, taskId, opName, 256, &inputDesc, &inputCnt, &outputDesc, &outputCnt);
//You can call related tensor APIs provided by AscendCL to obtain the operator information as required.
for (size_t i = 0; i < inputCnt; ++i) {
const aclTensorDesc *desc = aclGetTensorDescByIndex(inputDesc, i);
aclGetTensorDescAddress(desc);
aclGetTensorDescFormat(desc);
}
for (size_t i = 0; i < outputCnt; ++i) {
const aclTensorDesc *desc = aclGetTensorDescByIndex(outputDesc, i);
aclGetTensorDescAddress(desc);
aclGetTensorDescFormat(desc);
}
aclDestroyTensorDesc(inputDesc);
aclDestroyTensorDesc(outputDesc);
}
//6. Set the exception callback.
aclrtSetExceptionInfoCallback(callback);
//7. Execute your model.
ret = aclmdlExecute(modelId, input, output);
//8. Process the model inference result.
//9. Destroy the model input and output descriptions, free up memory, and unload the model.
//10. Destroy runtime allocations.
//11. Deinitialize AscendCL.
// ......