Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:47

0001 #ifndef HeterogeneousCore_ROCmUtilities_hipCheck_h
0002 #define HeterogeneousCore_ROCmUtilities_hipCheck_h
0003 
0004 // C++ standard headers
0005 #include <iostream>
0006 #include <sstream>
0007 #include <stdexcept>
0008 #include <string>
0009 #include <string_view>
0010 
0011 // ROCm headers
0012 #include <hip/hip_runtime.h>
0013 
0014 // CMSSW headers
0015 #include "FWCore/Utilities/interface/Likely.h"
0016 
0017 namespace cms {
0018   namespace rocm {
0019 
0020     [[noreturn]] inline void abortOnError(const char* file,
0021                                           int line,
0022                                           const char* cmd,
0023                                           const char* error,
0024                                           const char* message,
0025                                           std::string_view description = std::string_view()) {
0026       std::ostringstream out;
0027       out << "\n";
0028       out << file << ", line " << line << ":\n";
0029       out << "hipCheck(" << cmd << ");\n";
0030       out << error << ": " << message << "\n";
0031       if (!description.empty())
0032         out << description << "\n";
0033       throw std::runtime_error(out.str());
0034     }
0035 
0036     inline bool hipCheck_(const char* file,
0037                           int line,
0038                           const char* cmd,
0039                           hipError_t result,
0040                           std::string_view description = std::string_view()) {
0041       if (LIKELY(result == hipSuccess))
0042         return true;
0043 
0044       const char* error = hipGetErrorName(result);
0045       const char* message = hipGetErrorString(result);
0046       abortOnError(file, line, cmd, error, message, description);
0047       return false;
0048     }
0049   }  // namespace rocm
0050 }  // namespace cms
0051 
0052 #define hipCheck(ARG, ...) (cms::rocm::hipCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__))
0053 
0054 #endif  // HeterogeneousCore_ROCmUtilities_hipCheck_h