-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ProcessAcceleratorCUDA, and replace the direct use of CUDAService…
… with it
Showing
10 changed files
with
157 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
HeterogeneousCore/CUDACore/python/ProcessAcceleratorCUDA.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
import os | ||
|
||
class ProcessAcceleratorCUDA(cms.ProcessAccelerator): | ||
def __init__(self): | ||
super(ProcessAcceleratorCUDA,self).__init__() | ||
self._label = "gpu-nvidia" | ||
def labels(self): | ||
return [self._label] | ||
def enabledLabels(self): | ||
enabled = (os.system("cudaIsEnabled") == 0) | ||
if enabled: | ||
return self.labels() | ||
else: | ||
return [] | ||
def apply(self, process): | ||
if not hasattr(process, "CUDAService"): | ||
process.load("HeterogeneousCore.CUDAServices.CUDAService_cfi") | ||
|
||
if self._label in process.options.accelerators: | ||
process.CUDAService.enabled = True | ||
process.MessageLogger.CUDAService = cms.untracked.PSet() | ||
else: | ||
process.CUDAService.enabled = False | ||
|
||
cms.specialImportRegistry.registerSpecialImportForType(ProcessAcceleratorCUDA, "from HeterogeneousCore.CUDACore.ProcessAcceleratorCUDA import ProcessAcceleratorCUDA") |
3 changes: 3 additions & 0 deletions
3
HeterogeneousCore/CUDACore/python/ProcessAcceleratorCUDA_cfi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from HeterogeneousCore.CUDACore.ProcessAcceleratorCUDA import ProcessAcceleratorCUDA as _ProcessAcceleratorCUDA | ||
|
||
ProcessAcceleratorCUDA = _ProcessAcceleratorCUDA() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
HeterogeneousCore/CUDACore/test/test_ProcessAcceleratorCUDA.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "catch.hpp" | ||
|
||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSetReader/interface/ParameterSetReader.h" | ||
#include "FWCore/TestProcessor/interface/TestProcessor.h" | ||
|
||
#include <fmt/format.h> | ||
|
||
#include <iostream> | ||
#include <string_view> | ||
|
||
static constexpr auto s_tag = "[ProcessAcceleratorCUDA]"; | ||
|
||
namespace { | ||
std::string makeConfig(std::string_view cpu, | ||
std::string_view cuda, | ||
std::string_view accelerator) { | ||
return fmt::format( | ||
R"_(from FWCore.TestProcessor.TestProcess import * | ||
import FWCore.ParameterSet.Config as cms | ||
process = TestProcess() | ||
process.options.accelerators = [{}] | ||
process.load("HeterogeneousCore.CUDACore.ProcessAcceleratorCUDA_cfi") | ||
from HeterogeneousCore.CUDACore.SwitchProducerCUDA import * | ||
process.s = SwitchProducerCUDA( | ||
cpu = {}, | ||
cuda = {} | ||
) | ||
process.moduleToTest(process.s) | ||
)_", accelerator, cpu, cuda); | ||
} | ||
} // namespace | ||
|
||
TEST_CASE("Configuration", s_tag) { | ||
const std::string test1{"cms.EDProducer('IntProducer', ivalue = cms.int32(1))"}; | ||
const std::string test2{"cms.EDProducer('ManyIntProducer', ivalue = cms.int32(2), values = cms.VPSet())"}; | ||
|
||
const std::string baseConfig_auto = makeConfig(test1, test2, "'auto'"); | ||
const std::string baseConfig_cpu = makeConfig(test1, test2, ""); | ||
const std::string baseConfig_cuda = makeConfig(test1, test2, "'gpu-nvidia'"); | ||
|
||
SECTION("Configuration hash is not changed") { | ||
auto pset_auto = edm::readConfig(baseConfig_auto); | ||
auto pset_cpu = edm::readConfig(baseConfig_cpu); | ||
auto pset_cuda = edm::readConfig(baseConfig_cuda); | ||
pset_auto->registerIt(); | ||
pset_cpu->registerIt(); | ||
pset_cuda->registerIt(); | ||
REQUIRE(pset_auto->id() == pset_cpu->id()); | ||
REQUIRE(pset_auto->id() == pset_cuda->id()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters