Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XPUPTI] add error handling for xpu profiler #989

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading