diff --git a/libkineto/src/init.cpp b/libkineto/src/init.cpp index 55ef76b33..cc9d19040 100644 --- a/libkineto/src/init.cpp +++ b/libkineto/src/init.cpp @@ -203,10 +203,15 @@ void libkineto_init(bool cpuOnly, bool logOnError) { libkineto::api().registerProfilerFactory([]() -> std::unique_ptr { auto returnCode = ptiViewGPULocalAvailable(); if (returnCode != PTI_SUCCESS) { - std::string errCode = std::to_string(returnCode); - std::string errMsg( + std::string errPrefixMsg( "Fail to enable Kineto Profiler on XPU due to error code: "); - throw std::runtime_error(errMsg + errCode); + errPrefixMsg = errPrefixMsg + std::to_string(returnCode); +#if PTI_VERSION_MAJOR > 0 || PTI_VERSION_MINOR > 9 + std::string errMsg(ptiResultTypeToString(returnCode)); + throw std::runtime_error(errPrefixMsg + std::string(". The detailed error message is: ") + errMsg); +#else + throw std::runtime_error(errPrefixMsg); +#endif } return std::make_unique(); }); diff --git a/libkineto/src/plugin/xpupti/XpuptiProfilerMacros.h b/libkineto/src/plugin/xpupti/XpuptiProfilerMacros.h index a1eb54881..ab4cac151 100644 --- a/libkineto/src/plugin/xpupti/XpuptiProfilerMacros.h +++ b/libkineto/src/plugin/xpupti/XpuptiProfilerMacros.h @@ -11,6 +11,20 @@ namespace KINETO_NAMESPACE { using namespace libkineto; +#if PTI_VERSION_MAJOR > 0 || PTI_VERSION_MINOR > 9 +#define XPUPTI_CALL(returnCode) \ + { \ + if (returnCode != PTI_SUCCESS) { \ + std::string funcMsg(__func__); \ + std::string codeMsg = std::to_string(returnCode); \ + std::string HeadMsg("Kineto Profiler on XPU got error from function "); \ + std::string Msg(". The error code is "); \ + std::string detailMsg(". The detailed error message is "); \ + detailMsg = detailMsg + std::string(ptiResultTypeToString(returnCode)); \ + throw std::runtime_error(HeadMsg + funcMsg + Msg + codeMsg + detailMsg); \ + } \ + } +#else #define XPUPTI_CALL(returnCode) \ { \ if (returnCode != PTI_SUCCESS) { \ @@ -21,6 +35,7 @@ using namespace libkineto; throw std::runtime_error(HeadMsg + funcMsg + Msg + codeMsg); \ } \ } +#endif class XpuptiActivityApi; using DeviceIndex_t = int8_t;