CMS 3D CMS Logo

hipCheck.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_ROCmUtilities_hipCheck_h
2 #define HeterogeneousCore_ROCmUtilities_hipCheck_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 <hip/hip_runtime.h>
13 
14 // CMSSW headers
16 
17 namespace cms {
18  namespace rocm {
19 
20  [[noreturn]] inline void abortOnError(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 << "hipCheck(" << 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 hipCheck_(const char* file,
37  int line,
38  const char* cmd,
39  hipError_t result,
40  std::string_view description = std::string_view()) {
41  if (LIKELY(result == hipSuccess))
42  return true;
43 
44  const char* error = hipGetErrorName(result);
45  const char* message = hipGetErrorString(result);
46  abortOnError(file, line, cmd, error, message, description);
47  return false;
48  }
49  } // namespace rocm
50 } // namespace cms
51 
52 #define hipCheck(ARG, ...) (cms::rocm::hipCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__))
53 
54 #endif // HeterogeneousCore_ROCmUtilities_hipCheck_h
void abortOnError(const char *file, int line, const char *cmd, const char *error, const char *message, std::string_view description=std::string_view())
Definition: hipCheck.h:20
#define LIKELY(x)
Definition: Likely.h:20
bool hipCheck_(const char *file, int line, const char *cmd, hipError_t result, std::string_view description=std::string_view())
Definition: hipCheck.h:36
Namespace of DDCMS conversion namespace.
list cmd
Definition: mps_setup.py:244