Skip to content

Commit

Permalink
add error handling for xpu profiler (#989)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #989

Reviewed By: sraikund16

Differential Revision: D63052607

Pulled By: briancoutinho

fbshipit-source-id: f8e27e1c8a44f1bf5dd850835f82b5136008a48b
  • Loading branch information
zejun-chen authored and facebook-github-bot committed Sep 20, 2024
1 parent 3d355d1 commit 45cc65a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libkineto/src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,15 @@ void libkineto_init(bool cpuOnly, bool logOnError) {
libkineto::api().registerProfilerFactory([]() -> std::unique_ptr<IActivityProfiler> {
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<XPUActivityProfiler>();
});
Expand Down
15 changes: 15 additions & 0 deletions libkineto/src/plugin/xpupti/XpuptiProfilerMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand All @@ -21,6 +35,7 @@ using namespace libkineto;
throw std::runtime_error(HeadMsg + funcMsg + Msg + codeMsg); \
} \
}
#endif

class XpuptiActivityApi;
using DeviceIndex_t = int8_t;
Expand Down

0 comments on commit 45cc65a

Please sign in to comment.