Skip to content

Commit adc5096

Browse files
committed
Add abstract interfaces for the CUDA and ROCm services
Split the CUDA and ROCm services into an interface and a concrete implementation.
1 parent 71cefd4 commit adc5096

File tree

8 files changed

+23
-46
lines changed

8 files changed

+23
-46
lines changed

PhysicsTools/TensorFlow/test/testBaseCUDA.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,9 @@
2323
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
2424
#include "FWCore/Utilities/interface/Exception.h"
2525
#include "FWCore/Utilities/interface/ResourceInformation.h"
26-
#include "HeterogeneousCore/CUDAServices/interface/CUDAService.h"
26+
#include "HeterogeneousCore/CUDAServices/interface/CUDAInterface.h"
2727
#include "HeterogeneousCore/CUDAUtilities/interface/requireDevices.h"
2828

29-
namespace {
30-
CUDAService makeCUDAService(edm::ParameterSet ps) {
31-
auto desc = edm::ConfigurationDescriptions("Service", "CUDAService");
32-
CUDAService::fillDescriptions(desc);
33-
desc.validate(ps, "CUDAService");
34-
return CUDAService(ps);
35-
}
36-
} // namespace
37-
3829
class testBaseCUDA : public CppUnit::TestFixture {
3930
public:
4031
std::string dataPath_;

PhysicsTools/TensorFlow/test/testConstSessionCUDA.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,14 @@ process.add_(cms.Service('CUDAService'))
4646
edm::makeParameterSets(config, params);
4747
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
4848
edm::ServiceRegistry::Operate operate2(tempToken);
49-
50-
auto cs = makeCUDAService(edm::ParameterSet{});
51-
std::cout << "CUDA service enabled: " << cs.enabled() << std::endl;
52-
53-
std::string pbFile = dataPath_ + "/constantgraph.pb";
49+
edm::Service<CUDAInterface> cuda;
50+
std::cout << "CUDA service enabled: " << cuda->enabled() << std::endl;
5451

5552
std::cout << "Testing CUDA backend" << std::endl;
5653
tensorflow::Backend backend = tensorflow::Backend::cuda;
5754

5855
// load the graph
56+
std::string pbFile = dataPath_ + "/constantgraph.pb";
5957
tensorflow::setLogging();
6058
tensorflow::GraphDef* graphDef = tensorflow::loadGraphDef(pbFile);
6159
CPPUNIT_ASSERT(graphDef != nullptr);

PhysicsTools/TensorFlow/test/testGraphLoadingCUDA.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,14 @@ process.add_(cms.Service('CUDAService'))
4646
edm::makeParameterSets(config, params);
4747
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
4848
edm::ServiceRegistry::Operate operate2(tempToken);
49-
50-
auto cs = makeCUDAService(edm::ParameterSet{});
51-
std::cout << "CUDA service enabled: " << cs.enabled() << std::endl;
52-
53-
std::string pbFile = dataPath_ + "/constantgraph.pb";
49+
edm::Service<CUDAInterface> cuda;
50+
std::cout << "CUDA service enabled: " << cuda->enabled() << std::endl;
5451

5552
std::cout << "Testing CUDA backend" << std::endl;
5653
tensorflow::Backend backend = tensorflow::Backend::cuda;
5754

5855
// load the graph
56+
std::string pbFile = dataPath_ + "/constantgraph.pb";
5957
tensorflow::setLogging();
6058
tensorflow::GraphDef* graphDef = tensorflow::loadGraphDef(pbFile);
6159
CPPUNIT_ASSERT(graphDef != nullptr);

PhysicsTools/TensorFlow/test/testHelloWorldCUDA.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ process.add_(cms.Service('CUDAService'))
4848
edm::makeParameterSets(config, params);
4949
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
5050
edm::ServiceRegistry::Operate operate2(tempToken);
51+
edm::Service<CUDAInterface> cuda;
52+
std::cout << "CUDA service enabled: " << cuda->enabled() << std::endl;
5153

52-
auto cs = makeCUDAService(edm::ParameterSet{});
53-
std::cout << "CUDA service enabled: " << cs.enabled() << std::endl;
54-
55-
std::string modelDir = dataPath_ + "/simplegraph";
56-
// Testing CPU
5754
std::cout << "Testing CUDA backend" << std::endl;
5855
tensorflow::Backend backend = tensorflow::Backend::cuda;
5956

@@ -65,6 +62,7 @@ process.add_(cms.Service('CUDAService'))
6562
tensorflow::SavedModelBundle bundle;
6663

6764
// load everything
65+
std::string modelDir = dataPath_ + "/simplegraph";
6866
status = tensorflow::LoadSavedModel(sessionOptions, runOptions, modelDir, {"serve"}, &bundle);
6967
if (!status.ok()) {
7068
std::cout << status.ToString() << std::endl;

PhysicsTools/TensorFlow/test/testMetaGraphLoadingCUDA.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ process.add_(cms.Service('CUDAService'))
4646
edm::makeParameterSets(config, params);
4747
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
4848
edm::ServiceRegistry::Operate operate2(tempToken);
49-
50-
auto cs = makeCUDAService(edm::ParameterSet{});
51-
std::cout << "CUDA service enabled: " << cs.enabled() << std::endl;
52-
std::string exportDir = dataPath_ + "/simplegraph";
49+
edm::Service<CUDAInterface> cuda;
50+
std::cout << "CUDA service enabled: " << cuda->enabled() << std::endl;
5351

5452
std::cout << "Testing CUDA backend" << std::endl;
5553
tensorflow::Backend backend = tensorflow::Backend::cuda;
5654

5755
// load the graph
56+
std::string exportDir = dataPath_ + "/simplegraph";
5857
tensorflow::setLogging();
5958
tensorflow::MetaGraphDef* metaGraphDef = tensorflow::loadMetaGraphDef(exportDir);
6059
CPPUNIT_ASSERT(metaGraphDef != nullptr);

PhysicsTools/TensorFlow/test/testSessionCacheCUDA.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,15 @@ process.add_(cms.Service('CUDAService'))
4545
edm::makeParameterSets(config, params);
4646
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
4747
edm::ServiceRegistry::Operate operate2(tempToken);
48-
49-
auto cs = makeCUDAService(edm::ParameterSet{});
50-
std::cout << "CUDA service enabled: " << cs.enabled() << std::endl;
51-
52-
std::string pbFile = dataPath_ + "/constantgraph.pb";
48+
edm::Service<CUDAInterface> cuda;
49+
std::cout << "CUDA service enabled: " << cuda->enabled() << std::endl;
5350

5451
std::cout << "Testing CUDA backend" << std::endl;
5552
tensorflow::Backend backend = tensorflow::Backend::cuda;
5653

57-
tensorflow::setLogging();
58-
5954
// load the graph and the session
55+
std::string pbFile = dataPath_ + "/constantgraph.pb";
56+
tensorflow::setLogging();
6057
tensorflow::SessionCache cache(pbFile, backend);
6158
CPPUNIT_ASSERT(cache.graph.load() != nullptr);
6259
CPPUNIT_ASSERT(cache.session.load() != nullptr);

PhysicsTools/TensorFlow/test/testThreadPoolsCUDA.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@ process.add_(cms.Service('CUDAService'))
4646
edm::makeParameterSets(config, params);
4747
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
4848
edm::ServiceRegistry::Operate operate2(tempToken);
49-
50-
auto cs = makeCUDAService(edm::ParameterSet{});
51-
std::cout << "CUDA service enabled: " << cs.enabled() << std::endl;
52-
53-
std::string pbFile = dataPath_ + "/constantgraph.pb";
49+
edm::Service<CUDAInterface> cuda;
50+
std::cout << "CUDA service enabled: " << cuda->enabled() << std::endl;
5451

5552
std::cout << "Testing CUDA backend" << std::endl;
5653
tensorflow::Backend backend = tensorflow::Backend::cuda;
@@ -60,6 +57,7 @@ process.add_(cms.Service('CUDAService'))
6057
tensorflow::TBBThreadPool::instance(nThreads);
6158

6259
// load the graph
60+
std::string pbFile = dataPath_ + "/constantgraph.pb";
6361
tensorflow::setLogging();
6462
tensorflow::GraphDef* graphDef = tensorflow::loadGraphDef(pbFile);
6563
CPPUNIT_ASSERT(graphDef != nullptr);

PhysicsTools/TensorFlow/test/testVisibleDevicesCUDA.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ process.add_(cms.Service('CUDAService'))
4949
edm::makeParameterSets(config, params);
5050
edm::ServiceToken tempToken(edm::ServiceRegistry::createServicesFromConfig(std::move(params)));
5151
edm::ServiceRegistry::Operate operate2(tempToken);
52-
53-
auto cs = makeCUDAService(edm::ParameterSet{});
54-
std::cout << "CUDA service enabled: " << cs.enabled() << std::endl;
55-
56-
std::string pbFile = dataPath_ + "/constantgraph.pb";
52+
edm::Service<CUDAInterface> cuda;
53+
std::cout << "CUDA service enabled: " << cuda->enabled() << std::endl;
5754

5855
std::cout << "Testing CUDA backend" << std::endl;
5956
tensorflow::Backend backend = tensorflow::Backend::cuda;
6057

6158
// load the graph
59+
std::string pbFile = dataPath_ + "/constantgraph.pb";
6260
tensorflow::setLogging();
6361
tensorflow::GraphDef* graphDef = tensorflow::loadGraphDef(pbFile);
6462
CPPUNIT_ASSERT(graphDef != nullptr);

0 commit comments

Comments
 (0)