Skip to content

Commit 2e0d63c

Browse files
authored
Merge pull request #47280 from makortel/moveResourceInformation
Move `ResourceInformation` abstract base class to FWCore/AbstractServices, and few additional improvements
2 parents 6517ee7 + 9b9a39b commit 2e0d63c

File tree

25 files changed

+69
-47
lines changed

25 files changed

+69
-47
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<export>
2+
<lib name="1"/>
3+
</export>

FWCore/Utilities/interface/ResourceInformation.h renamed to FWCore/AbstractServices/interface/ResourceInformation.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef FWCore_Utilities_ResourceInformation_h
2-
#define FWCore_Utilities_ResourceInformation_h
1+
#ifndef FWCore_AbstractServices_ResourceInformation_h
2+
#define FWCore_AbstractServices_ResourceInformation_h
33

44
/** \class edm::ResourceInformation
55
@@ -22,12 +22,12 @@ namespace edm {
2222
ResourceInformation const& operator=(ResourceInformation const&) = delete;
2323
virtual ~ResourceInformation();
2424

25-
enum class AcceleratorType { GPU };
26-
27-
virtual std::vector<AcceleratorType> const& acceleratorTypes() const = 0;
25+
virtual std::vector<std::string> const& selectedAccelerators() const = 0;
2826
virtual std::vector<std::string> const& cpuModels() const = 0;
2927
virtual std::vector<std::string> const& gpuModels() const = 0;
3028

29+
virtual bool hasGpuNvidia() const = 0;
30+
3131
virtual std::string const& nvidiaDriverVersion() const = 0;
3232
virtual int cudaDriverVersion() const = 0;
3333
virtual int cudaRuntimeVersion() const = 0;
@@ -36,7 +36,7 @@ namespace edm {
3636
virtual std::string const& cpuModelsFormatted() const = 0;
3737
virtual double cpuAverageSpeed() const = 0;
3838

39-
virtual void initializeAcceleratorTypes(std::vector<std::string> const& selectedAccelerators) = 0;
39+
virtual void setSelectedAccelerators(std::vector<std::string> const& selectedAccelerators) = 0;
4040
virtual void setCPUModels(std::vector<std::string> const&) = 0;
4141
virtual void setGPUModels(std::vector<std::string> const&) = 0;
4242

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "FWCore/AbstractServices/interface/ResourceInformation.h"
2+
3+
namespace edm {
4+
ResourceInformation::ResourceInformation() = default;
5+
ResourceInformation::~ResourceInformation() = default;
6+
} // namespace edm

FWCore/Framework/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<use name="tbb"/>
55
<use name="DataFormats/Common"/>
66
<use name="DataFormats/Provenance"/>
7+
<use name="FWCore/AbstractServices"/>
78
<use name="FWCore/Common"/>
89
<use name="FWCore/Concurrency"/>
910
<use name="FWCore/MessageLogger"/>

FWCore/Framework/src/ScheduleItems.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
77
#include "DataFormats/Provenance/interface/SubProcessParentageHelper.h"
88
#include "DataFormats/Provenance/interface/SelectedProducts.h"
9+
#include "FWCore/AbstractServices/interface/ResourceInformation.h"
910
#include "FWCore/Common/interface/SubProcessBlockHelper.h"
1011
#include "FWCore/Framework/interface/ExceptionActions.h"
1112
#include "FWCore/Framework/src/CommonParams.h"
@@ -19,7 +20,6 @@
1920
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
2021
#include "FWCore/Utilities/interface/BranchType.h"
2122
#include "FWCore/Utilities/interface/GetPassID.h"
22-
#include "FWCore/Utilities/interface/ResourceInformation.h"
2323
#include "FWCore/Version/interface/GetReleaseVersion.h"
2424

2525
#include <memory>
@@ -123,7 +123,7 @@ namespace edm {
123123
if (resourceInformationService.isAvailable()) {
124124
auto const& selectedAccelerators =
125125
parameterSet.getUntrackedParameter<std::vector<std::string>>("@selected_accelerators");
126-
resourceInformationService->initializeAcceleratorTypes(selectedAccelerators);
126+
resourceInformationService->setSelectedAccelerators(selectedAccelerators);
127127
}
128128

129129
act_table_ = std::make_unique<ExceptionToActionTable>(parameterSet);

FWCore/Services/BuildFile.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<use name="SimDataFormats/RandomEngine"/>
2+
<use name="FWCore/AbstractServices"/>
3+
<use name="FWCore/Catalog"/>
24
<use name="FWCore/MessageLogger"/>
35
<use name="FWCore/ParameterSet"/>
46
<use name="FWCore/ServiceRegistry"/>
57
<use name="FWCore/Utilities"/>
6-
<use name="FWCore/Catalog"/>
78
<use name="boost"/>
89
<use name="tinyxml2"/>
910
<use name="rootcore"/>

FWCore/Services/plugins/CPU.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Original Author: Natalia Garcia
99
// CPU.cc: v 1.0 2009/01/08 11:31:07
1010

11+
#include "FWCore/AbstractServices/interface/ResourceInformation.h"
1112
#include "FWCore/MessageLogger/interface/JobReport.h"
1213
#include "FWCore/MessageLogger/interface/MessageLogger.h"
1314
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
@@ -16,7 +17,6 @@
1617
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
1718
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
1819
#include "FWCore/Utilities/interface/CPUServiceBase.h"
19-
#include "FWCore/Utilities/interface/ResourceInformation.h"
2020

2121
#include "cpu_features/cpu_features_macros.h"
2222

FWCore/Services/plugins/CondorStatusUpdater.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
#include "DataFormats/Provenance/interface/ModuleDescription.h"
33
#include "DataFormats/Provenance/interface/ParameterSetID.h"
4+
#include "FWCore/AbstractServices/interface/ResourceInformation.h"
45
#include "FWCore/MessageLogger/interface/MessageLogger.h"
5-
#include "FWCore/Utilities/interface/ResourceInformation.h"
66
#include "FWCore/Utilities/interface/TimingServiceBase.h"
77
#include "FWCore/ServiceRegistry/interface/Service.h"
88
#include "FWCore/ServiceRegistry/interface/ProcessContext.h"

FWCore/Services/plugins/ResourceInformationService.cc

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
1212
*/
1313

14+
#include "FWCore/AbstractServices/interface/ResourceInformation.h"
1415
#include "FWCore/MessageLogger/interface/MessageLogger.h"
1516
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
1617
#include "FWCore/ParameterSet/interface/ParameterSet.h"
1718
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
1819
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
1920
#include "FWCore/Utilities/interface/EDMException.h"
20-
#include "FWCore/Utilities/interface/ResourceInformation.h"
2121

2222
#include <string>
2323
#include <vector>
@@ -31,10 +31,12 @@ namespace edm {
3131

3232
static void fillDescriptions(ConfigurationDescriptions&);
3333

34-
std::vector<AcceleratorType> const& acceleratorTypes() const final;
34+
std::vector<std::string> const& selectedAccelerators() const final;
3535
std::vector<std::string> const& cpuModels() const final;
3636
std::vector<std::string> const& gpuModels() const final;
3737

38+
bool hasGpuNvidia() const final;
39+
3840
std::string const& nvidiaDriverVersion() const final;
3941
int cudaDriverVersion() const final;
4042
int cudaRuntimeVersion() const final;
@@ -43,7 +45,7 @@ namespace edm {
4345
std::string const& cpuModelsFormatted() const final;
4446
double cpuAverageSpeed() const final;
4547

46-
void initializeAcceleratorTypes(std::vector<std::string> const& selectedAccelerators) final;
48+
void setSelectedAccelerators(std::vector<std::string> const& selectedAccelerators) final;
4749
void setCPUModels(std::vector<std::string> const&) final;
4850
void setGPUModels(std::vector<std::string> const&) final;
4951

@@ -59,7 +61,7 @@ namespace edm {
5961
private:
6062
void throwIfLocked() const;
6163

62-
std::vector<AcceleratorType> acceleratorTypes_;
64+
std::vector<std::string> selectedAccelerators_;
6365
std::vector<std::string> cpuModels_;
6466
std::vector<std::string> gpuModels_;
6567

@@ -70,6 +72,7 @@ namespace edm {
7072
std::string cpuModelsFormatted_;
7173
double cpuAverageSpeed_ = 0;
7274

75+
bool hasGpuNvidia_ = false;
7376
bool locked_ = false;
7477
bool verbose_;
7578
};
@@ -87,14 +90,16 @@ namespace edm {
8790
descriptions.add("ResourceInformationService", desc);
8891
}
8992

90-
std::vector<ResourceInformation::AcceleratorType> const& ResourceInformationService::acceleratorTypes() const {
91-
return acceleratorTypes_;
93+
std::vector<std::string> const& ResourceInformationService::selectedAccelerators() const {
94+
return selectedAccelerators_;
9295
}
9396

9497
std::vector<std::string> const& ResourceInformationService::cpuModels() const { return cpuModels_; }
9598

9699
std::vector<std::string> const& ResourceInformationService::gpuModels() const { return gpuModels_; }
97100

101+
bool ResourceInformationService::hasGpuNvidia() const { return hasGpuNvidia_; }
102+
98103
std::string const& ResourceInformationService::nvidiaDriverVersion() const { return nvidiaDriverVersion_; }
99104

100105
int ResourceInformationService::cudaDriverVersion() const { return cudaDriverVersion_; }
@@ -105,15 +110,9 @@ namespace edm {
105110

106111
double ResourceInformationService::cpuAverageSpeed() const { return cpuAverageSpeed_; }
107112

108-
void ResourceInformationService::initializeAcceleratorTypes(std::vector<std::string> const& selectedAccelerators) {
113+
void ResourceInformationService::setSelectedAccelerators(std::vector<std::string> const& selectedAccelerators) {
109114
if (!locked_) {
110-
for (auto const& selected : selectedAccelerators) {
111-
// Test if the string begins with "gpu-"
112-
if (selected.rfind("gpu-", 0) == 0) {
113-
acceleratorTypes_.push_back(AcceleratorType::GPU);
114-
break;
115-
}
116-
}
115+
selectedAccelerators_ = selectedAccelerators;
117116
locked_ = true;
118117
}
119118
}
@@ -131,16 +130,19 @@ namespace edm {
131130
void ResourceInformationService::setNvidiaDriverVersion(std::string const& val) {
132131
throwIfLocked();
133132
nvidiaDriverVersion_ = val;
133+
hasGpuNvidia_ = true;
134134
}
135135

136136
void ResourceInformationService::setCudaDriverVersion(int val) {
137137
throwIfLocked();
138138
cudaDriverVersion_ = val;
139+
hasGpuNvidia_ = true;
139140
}
140141

141142
void ResourceInformationService::setCudaRuntimeVersion(int val) {
142143
throwIfLocked();
143144
cudaRuntimeVersion_ = val;
145+
hasGpuNvidia_ = true;
144146
}
145147

146148
void ResourceInformationService::setCpuModelsFormatted(std::string const& val) {
@@ -182,16 +184,12 @@ namespace edm {
182184
}
183185
}
184186

185-
LogAbsolute("ResourceInformation") << " acceleratorTypes:";
186-
if (acceleratorTypes().empty()) {
187+
LogAbsolute("ResourceInformation") << " selectedAccelerators:";
188+
if (selectedAccelerators().empty()) {
187189
LogAbsolute("ResourceInformation") << " None";
188190
} 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;
191+
for (auto const& iter : selectedAccelerators()) {
192+
LogAbsolute("ResourceInformation") << " " << iter;
195193
}
196194
}
197195
LogAbsolute("ResourceInformation") << " nvidiaDriverVersion: " << nvidiaDriverVersion();

FWCore/Services/test/test_resourceInformationService.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ function die { echo Failure $1: status $2 ; exit $2 ; }
44

55
cmsRun ${SCRAM_TEST_PATH}/test_resourceInformationService_cfg.py &> test_resourceInformationService.log || die "cmsRun test_resourceInformationService_cfg.py" $?
66

7-
grep -A 1 "acceleratorTypes:" test_resourceInformationService.log | grep "GPU" || die "Check for existence of GPU acceleratorType" $?
7+
grep -A 4 "selectedAccelerators:" test_resourceInformationService.log | grep "cpu" || die "Check for existence of cpu in selectedAccelerators" $?
8+
grep -A 4 "selectedAccelerators:" test_resourceInformationService.log | grep "gpu-foo" || die "Check for existence of gpu-foo in selectedAccelerators" $?
9+
grep -A 4 "selectedAccelerators:" test_resourceInformationService.log | grep "test1" || die "Check for existence of test1 in selectedAccelerators" $?
10+
grep -A 4 "selectedAccelerators:" test_resourceInformationService.log | grep "test2" || die "Check for existence of test2 in selectedAccelerators" $?
811
grep -A 1 "cpu models:" test_resourceInformationService.log | grep "None" && die "Check there is at least one model (not None)" 1
912

1013
exit 0

0 commit comments

Comments
 (0)