1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include "DataFormats/Provenance/interface/HardwareResourcesDescription.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/compactStringSerializer.h"
#include <iterator>
#include <ostream>
namespace edm {
HardwareResourcesDescription::HardwareResourcesDescription(std::string_view serialized) {
// allowing empty input is mostly for backwards compatibility
if (not serialized.empty()) {
auto ret = edm::compactString::deserialize(serialized,
microarchitecture,
std::back_inserter(cpuModels),
std::back_inserter(selectedAccelerators),
std::back_inserter(gpuModels));
// not comparing against serialized.size() to allow serialized
// to have more content (for kind of forward compatibility)
if (ret == 0) {
throw Exception(errors::EventCorruption) << "Failed to deserialize HardwareResourcesDescription string format";
}
}
}
std::string HardwareResourcesDescription::serialize() const {
if (microarchitecture.empty() and cpuModels.empty() and selectedAccelerators.empty() and gpuModels.empty())
return "";
return edm::compactString::serialize(microarchitecture, cpuModels, selectedAccelerators, gpuModels);
}
bool HardwareResourcesDescription::operator==(HardwareResourcesDescription const& other) const {
return microarchitecture == other.microarchitecture and std::ranges::equal(cpuModels, other.cpuModels) and
std::ranges::equal(selectedAccelerators, other.selectedAccelerators) and
std::ranges::equal(gpuModels, other.gpuModels);
}
std::ostream& operator<<(std::ostream& os, HardwareResourcesDescription const& rd) {
auto printContainer = [&os](std::string_view header, std::vector<std::string> const& cont) {
os << header << ": " << cont.front();
for (auto it = cont.begin() + 1; it != cont.end(); ++it) {
os << ", " << *it;
}
};
os << "uarch: " << rd.microarchitecture << "\n";
if (not rd.cpuModels.empty()) {
printContainer("CPU models", rd.cpuModels);
os << "\n";
}
if (not rd.selectedAccelerators.empty()) {
printContainer("Selected accelerators", rd.selectedAccelerators);
os << "\n";
}
if (not rd.gpuModels.empty()) {
printContainer("GPU models", rd.gpuModels);
}
return os;
}
} // namespace edm
|