Skip to content

Commit 45cc65a

Browse files
zejun-chenfacebook-github-bot
authored andcommitted
add error handling for xpu profiler (#989)
Summary: Pull Request resolved: #989 Reviewed By: sraikund16 Differential Revision: D63052607 Pulled By: briancoutinho fbshipit-source-id: f8e27e1c8a44f1bf5dd850835f82b5136008a48b
1 parent 3d355d1 commit 45cc65a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

libkineto/src/init.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,15 @@ void libkineto_init(bool cpuOnly, bool logOnError) {
203203
libkineto::api().registerProfilerFactory([]() -> std::unique_ptr<IActivityProfiler> {
204204
auto returnCode = ptiViewGPULocalAvailable();
205205
if (returnCode != PTI_SUCCESS) {
206-
std::string errCode = std::to_string(returnCode);
207-
std::string errMsg(
206+
std::string errPrefixMsg(
208207
"Fail to enable Kineto Profiler on XPU due to error code: ");
209-
throw std::runtime_error(errMsg + errCode);
208+
errPrefixMsg = errPrefixMsg + std::to_string(returnCode);
209+
#if PTI_VERSION_MAJOR > 0 || PTI_VERSION_MINOR > 9
210+
std::string errMsg(ptiResultTypeToString(returnCode));
211+
throw std::runtime_error(errPrefixMsg + std::string(". The detailed error message is: ") + errMsg);
212+
#else
213+
throw std::runtime_error(errPrefixMsg);
214+
#endif
210215
}
211216
return std::make_unique<XPUActivityProfiler>();
212217
});

libkineto/src/plugin/xpupti/XpuptiProfilerMacros.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ namespace KINETO_NAMESPACE {
1111

1212
using namespace libkineto;
1313

14+
#if PTI_VERSION_MAJOR > 0 || PTI_VERSION_MINOR > 9
15+
#define XPUPTI_CALL(returnCode) \
16+
{ \
17+
if (returnCode != PTI_SUCCESS) { \
18+
std::string funcMsg(__func__); \
19+
std::string codeMsg = std::to_string(returnCode); \
20+
std::string HeadMsg("Kineto Profiler on XPU got error from function "); \
21+
std::string Msg(". The error code is "); \
22+
std::string detailMsg(". The detailed error message is "); \
23+
detailMsg = detailMsg + std::string(ptiResultTypeToString(returnCode)); \
24+
throw std::runtime_error(HeadMsg + funcMsg + Msg + codeMsg + detailMsg); \
25+
} \
26+
}
27+
#else
1428
#define XPUPTI_CALL(returnCode) \
1529
{ \
1630
if (returnCode != PTI_SUCCESS) { \
@@ -21,6 +35,7 @@ using namespace libkineto;
2135
throw std::runtime_error(HeadMsg + funcMsg + Msg + codeMsg); \
2236
} \
2337
}
38+
#endif
2439

2540
class XpuptiActivityApi;
2641
using DeviceIndex_t = int8_t;

0 commit comments

Comments
 (0)