Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef HeterogeneousCore_ROCmUtilities_rsmiCheck_h
0002 #define HeterogeneousCore_ROCmUtilities_rsmiCheck_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 <rocm_smi/rocm_smi.h>
0013 
0014 // CMSSW headers
0015 #include "FWCore/Utilities/interface/Likely.h"
0016 
0017 namespace cms {
0018   namespace rocm {
0019 
0020     [[noreturn]] inline void abortOnRsmiError(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 << "rsmiCheck(" << 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 rsmiCheck_(const char* file,
0037                            int line,
0038                            const char* cmd,
0039                            rsmi_status_t result,
0040                            std::string_view description = std::string_view()) {
0041       if (LIKELY(result == RSMI_STATUS_SUCCESS))
0042         return true;
0043 
0044       std::string error = "ROCm SMI Error " + std::to_string(result);
0045       const char* message;
0046       rsmi_status_string(result, &message);
0047       abortOnRsmiError(file, line, cmd, error.c_str(), message, description);
0048       return false;
0049     }
0050   }  // namespace rocm
0051 }  // namespace cms
0052 
0053 #define rsmiCheck(ARG, ...) (cms::rocm::rsmiCheck_(__FILE__, __LINE__, #ARG, (ARG), ##__VA_ARGS__))
0054 
0055 #endif  // HeterogeneousCore_ROCmUtilities_rsmiCheck_h