CMS 3D CMS Logo

ResourceInformationService.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Services
4 // Class : ResourceInformationService
5 //
6 // Implementation:
7 
21 
22 #include <string>
23 #include <vector>
24 
25 namespace edm {
26  namespace service {
27 
29  public:
31 
33 
34  std::vector<AcceleratorType> const& acceleratorTypes() const final;
35  std::vector<std::string> const& cpuModels() const final;
36  std::vector<std::string> const& gpuModels() const final;
37 
38  std::string const& nvidiaDriverVersion() const final;
39  int cudaDriverVersion() const final;
40  int cudaRuntimeVersion() const final;
41 
42  // Same as cpuModels except in a single string with models separated by ", "
43  std::string const& cpuModelsFormatted() const final;
44  double cpuAverageSpeed() const final;
45 
46  void initializeAcceleratorTypes(std::vector<std::string> const& selectedAccelerators) final;
47  void setCPUModels(std::vector<std::string> const&) final;
48  void setGPUModels(std::vector<std::string> const&) final;
49 
50  void setNvidiaDriverVersion(std::string const&) final;
51  void setCudaDriverVersion(int) final;
52  void setCudaRuntimeVersion(int) final;
53 
54  void setCpuModelsFormatted(std::string const&) final;
55  void setCpuAverageSpeed(double) final;
56 
57  void postBeginJob();
58 
59  private:
60  void throwIfLocked() const;
61 
62  std::vector<AcceleratorType> acceleratorTypes_;
63  std::vector<std::string> cpuModels_;
64  std::vector<std::string> gpuModels_;
65 
69 
71  double cpuAverageSpeed_ = 0;
72 
73  bool locked_ = false;
74  bool verbose_;
75  };
76 
77  inline bool isProcessWideService(ResourceInformationService const*) { return true; }
78 
80  : verbose_(pset.getUntrackedParameter<bool>("verbose")) {
82  }
83 
86  desc.addUntracked<bool>("verbose", false);
87  descriptions.add("ResourceInformationService", desc);
88  }
89 
90  std::vector<ResourceInformation::AcceleratorType> const& ResourceInformationService::acceleratorTypes() const {
91  return acceleratorTypes_;
92  }
93 
94  std::vector<std::string> const& ResourceInformationService::cpuModels() const { return cpuModels_; }
95 
96  std::vector<std::string> const& ResourceInformationService::gpuModels() const { return gpuModels_; }
97 
99 
101 
103 
105 
107 
108  void ResourceInformationService::initializeAcceleratorTypes(std::vector<std::string> const& selectedAccelerators) {
109  if (!locked_) {
110  for (auto const& selected : selectedAccelerators) {
111  // Test if the string begins with "gpu-"
112  if (selected.rfind("gpu-", 0) == 0) {
114  break;
115  }
116  }
117  locked_ = true;
118  }
119  }
120 
121  void ResourceInformationService::setCPUModels(std::vector<std::string> const& val) {
122  throwIfLocked();
123  cpuModels_ = val;
124  }
125 
126  void ResourceInformationService::setGPUModels(std::vector<std::string> const& val) {
127  throwIfLocked();
128  gpuModels_ = val;
129  }
130 
132  throwIfLocked();
134  }
135 
137  throwIfLocked();
139  }
140 
142  throwIfLocked();
144  }
145 
147  throwIfLocked();
149  }
150 
152  throwIfLocked();
154  }
155 
157  if (locked_) {
158  // Only Services should modify ResourceInformationService. Service construction is run serially.
159  // The lock provides thread safety and prevents modules from modifying ResourceInformationService.
161  << "Attempt to modify member data after ResourceInformationService was locked ";
162  }
163  }
164 
166  if (verbose_) {
167  LogAbsolute("ResourceInformation") << "ResourceInformationService";
168  LogAbsolute("ResourceInformation") << " cpu models:";
169  if (cpuModels().empty()) {
170  LogAbsolute("ResourceInformation") << " None";
171  } else {
172  for (auto const& iter : cpuModels()) {
173  LogAbsolute("ResourceInformation") << " " << iter;
174  }
175  }
176  LogAbsolute("ResourceInformation") << " gpu models:";
177  if (gpuModels().empty()) {
178  LogAbsolute("ResourceInformation") << " None";
179  } else {
180  for (auto const& iter : gpuModels()) {
181  LogAbsolute("ResourceInformation") << " " << iter;
182  }
183  }
184 
185  LogAbsolute("ResourceInformation") << " acceleratorTypes:";
186  if (acceleratorTypes().empty()) {
187  LogAbsolute("ResourceInformation") << " None";
188  } else {
189  for (auto const& iter : acceleratorTypes()) {
190  std::string acceleratorTypeString("unknown type");
191  if (iter == AcceleratorType::GPU) {
192  acceleratorTypeString = std::string("GPU");
193  }
194  LogAbsolute("ResourceInformation") << " " << acceleratorTypeString;
195  }
196  }
197  LogAbsolute("ResourceInformation") << " nvidiaDriverVersion: " << nvidiaDriverVersion();
198  LogAbsolute("ResourceInformation") << " cudaDriverVersion: " << cudaDriverVersion();
199  LogAbsolute("ResourceInformation") << " cudaRuntimeVersion: " << cudaRuntimeVersion();
200  LogAbsolute("ResourceInformation") << " cpuModelsFormatted: " << cpuModelsFormatted();
201  LogAbsolute("ResourceInformation") << " cpuAverageSpeed: " << cpuAverageSpeed();
202  }
203  }
204 
205  } // namespace service
206 } // namespace edm
207 
209 
#define DEFINE_FWK_SERVICE_MAKER(concrete, maker)
Definition: ServiceMaker.h:102
bool isProcessWideService(TFileService const *)
Definition: TFileService.h:98
std::string const & cpuModelsFormatted() const final
std::vector< AcceleratorType > const & acceleratorTypes() const final
void setCPUModels(std::vector< std::string > const &) final
std::vector< std::string > const & gpuModels() const final
ResourceInformationService(ParameterSet const &, ActivityRegistry &)
void setNvidiaDriverVersion(std::string const &) final
void initializeAcceleratorTypes(std::vector< std::string > const &selectedAccelerators) final
std::string const & nvidiaDriverVersion() const final
static void fillDescriptions(ConfigurationDescriptions &)
std::vector< std::string > const & cpuModels() const final
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
void setGPUModels(std::vector< std::string > const &) final
Log< level::System, true > LogAbsolute
void setCpuModelsFormatted(std::string const &) final
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal