CMS 3D CMS Logo

rsmiCheck.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_ROCmUtilities_rsmiCheck_h
2 #define HeterogeneousCore_ROCmUtilities_rsmiCheck_h
3 
4 // C++ standard headers
5 #include <iostream>
6 #include <sstream>
7 #include <stdexcept>
8 #include <string>
9 #include <string_view>
10 
11 // ROCm headers
12 #include <rocm_smi/rocm_smi.h>
13 
14 // CMSSW headers
16 
17 namespace cms {
18  namespace rocm {
19 
20  [[noreturn]] inline void abortOnRsmiError(const char* file,
21  int line,
22  const char* cmd,
23  const char* error,
24  const char* message,
25  std::string_view description = std::string_view()) {
26  std::ostringstream out;
27  out << "\n";
28  out << file << ", line " << line << ":\n";
29  out << "rsmiCheck(" << cmd << ");\n";
30  out << error << ": " << message << "\n";
31  if (!description.empty())
32  out << description << "\n";
33  throw std::runtime_error(out.str());
34  }
35 
36  inline bool rsmiCheck_(const char* file,
37  int line,
38  const char* cmd,
39  rsmi_status_t result,
40  std::string_view description = std::string_view()) {
41  if (LIKELY(result == RSMI_STATUS_SUCCESS))
42  return true;
43 
44  std::string error = "ROCm SMI Error " + std::to_string(result);
45  const char* message;
46  rsmi_status_string(result, &message);
47  abortOnRsmiError(file, line, cmd, error.c_str(), message, description);
48  return false;
49  }
50  } // namespace rocm
51 } // namespace cms
52 
53 #define rsmiCheck(ARG, ...) (cms::rocm::rsmiCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__))
54 
55 #endif // HeterogeneousCore_ROCmUtilities_rsmiCheck_h
#define LIKELY(x)
Definition: Likely.h:20
static std::string to_string(const XMLCh *ch)
Namespace of DDCMS conversion namespace.
void abortOnRsmiError(const char *file, int line, const char *cmd, const char *error, const char *message, std::string_view description=std::string_view())
Definition: rsmiCheck.h:20
list cmd
Definition: mps_setup.py:244
bool rsmiCheck_(const char *file, int line, const char *cmd, rsmi_status_t result, std::string_view description=std::string_view())
Definition: rsmiCheck.h:36