Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-27 07:19:50

0001 #include "DataFormats/Provenance/interface/HardwareResourcesDescription.h"
0002 #include "FWCore/Utilities/interface/EDMException.h"
0003 #include "FWCore/Utilities/interface/compactStringSerializer.h"
0004 
0005 #include <iterator>
0006 #include <ostream>
0007 
0008 namespace edm {
0009   HardwareResourcesDescription::HardwareResourcesDescription(std::string_view serialized) {
0010     // allowing empty input is mostly for backwards compatibility
0011     if (not serialized.empty()) {
0012       auto ret = edm::compactString::deserialize(serialized,
0013                                                  microarchitecture,
0014                                                  std::back_inserter(cpuModels),
0015                                                  std::back_inserter(selectedAccelerators),
0016                                                  std::back_inserter(gpuModels));
0017       // not comparing against serialized.size() to allow serialized
0018       // to have more content (for kind of forward compatibility)
0019       if (ret == 0) {
0020         throw Exception(errors::EventCorruption) << "Failed to deserialize HardwareResourcesDescription string format";
0021       }
0022     }
0023   }
0024 
0025   std::string HardwareResourcesDescription::serialize() const {
0026     if (microarchitecture.empty() and cpuModels.empty() and selectedAccelerators.empty() and gpuModels.empty())
0027       return "";
0028     return edm::compactString::serialize(microarchitecture, cpuModels, selectedAccelerators, gpuModels);
0029   }
0030 
0031   bool HardwareResourcesDescription::operator==(HardwareResourcesDescription const& other) const {
0032     return microarchitecture == other.microarchitecture and std::ranges::equal(cpuModels, other.cpuModels) and
0033            std::ranges::equal(selectedAccelerators, other.selectedAccelerators) and
0034            std::ranges::equal(gpuModels, other.gpuModels);
0035   }
0036 
0037   std::ostream& operator<<(std::ostream& os, HardwareResourcesDescription const& rd) {
0038     auto printContainer = [&os](std::string_view header, std::vector<std::string> const& cont) {
0039       os << header << ": " << cont.front();
0040       for (auto it = cont.begin() + 1; it != cont.end(); ++it) {
0041         os << ", " << *it;
0042       }
0043     };
0044 
0045     os << "uarch: " << rd.microarchitecture << "\n";
0046     if (not rd.cpuModels.empty()) {
0047       printContainer("CPU models", rd.cpuModels);
0048       os << "\n";
0049     }
0050     if (not rd.selectedAccelerators.empty()) {
0051       printContainer("Selected accelerators", rd.selectedAccelerators);
0052       os << "\n";
0053     }
0054     if (not rd.gpuModels.empty()) {
0055       printContainer("GPU models", rd.gpuModels);
0056     }
0057     return os;
0058   }
0059 }  // namespace edm