-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44387 from fwyzard/implement_AlpakaBackendFilter_…
…14_1_x Implement AlpakaBackendProducer and AlpakaBackendFilter
- Loading branch information
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
HeterogeneousCore/AlpakaCore/plugins/AlpakaBackendFilter.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,48 @@ | ||
#include <array> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/global/EDFilter.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/Backend.h" | ||
|
||
class AlpakaBackendFilter : public edm::global::EDFilter<> { | ||
public: | ||
explicit AlpakaBackendFilter(edm::ParameterSet const& config) | ||
: producer_(consumes<unsigned short>(config.getParameter<edm::InputTag>("producer"))), backends_{} { | ||
for (auto const& backend : config.getParameter<std::vector<std::string>>("backends")) { | ||
backends_[static_cast<unsigned short>(cms::alpakatools::toBackend(backend))] = true; | ||
} | ||
} | ||
|
||
bool filter(edm::StreamID sid, edm::Event& event, edm::EventSetup const& setup) const final { | ||
return backends_[event.get(producer_)]; | ||
} | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); | ||
|
||
private: | ||
const edm::EDGetTokenT<unsigned short> producer_; | ||
std::array<bool, static_cast<short>(cms::alpakatools::Backend::size)> backends_; | ||
}; | ||
|
||
void AlpakaBackendFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("producer", edm::InputTag("alpakaBackendProducer", "backend")) | ||
->setComment( | ||
"Use the 'backend' instance label to read the backend indicator that is implicitly produced by every alpaka " | ||
"EDProducer."); | ||
desc.add<std::vector<std::string>>("backends", {"SerialSync"}) | ||
->setComment("Valid backends are 'SerialSync', 'CudaAsync', 'ROCmAsync', and 'TbbAsync'."); | ||
descriptions.addWithDefaultLabel(desc); | ||
descriptions.setComment( | ||
"This EDFilter accepts events if the alpaka EDProducer 'producer' was run on a backend among those listed by the " | ||
"'backends' parameter."); | ||
} | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(AlpakaBackendFilter); |
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
31 changes: 31 additions & 0 deletions
31
HeterogeneousCore/AlpakaCore/plugins/alpaka/AlpakaBackendProducer.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,31 @@ | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/Utilities/interface/StreamID.h" | ||
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h" | ||
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h" | ||
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h" | ||
#include "HeterogeneousCore/AlpakaInterface/interface/config.h" | ||
|
||
namespace ALPAKA_ACCELERATOR_NAMESPACE { | ||
|
||
class AlpakaBackendProducer : public global::EDProducer<> { | ||
public: | ||
AlpakaBackendProducer(edm::ParameterSet const& config){}; | ||
|
||
void produce(edm::StreamID sid, device::Event& event, device::EventSetup const&) const override {} | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
descriptions.addWithDefaultLabel(desc); | ||
descriptions.setComment( | ||
"The alpaka EDProducer does not have any explicit products. " | ||
"Its only purpose is to produce a 'backend' value."); | ||
} | ||
}; | ||
|
||
} // namespace ALPAKA_ACCELERATOR_NAMESPACE | ||
|
||
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h" | ||
DEFINE_FWK_ALPAKA_MODULE(AlpakaBackendProducer); |
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 @@ | ||
<test name="testAlpakaBackendFilter" command="cmsRun ${LOCALTOP}/src/HeterogeneousCore/AlpakaCore/test/testAlpakaBackendFilter.py"> | ||
<flags ALPAKA_BACKENDS="1"/> | ||
</test> |
46 changes: 46 additions & 0 deletions
46
HeterogeneousCore/AlpakaCore/test/testAlpakaBackendFilter.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,46 @@ | ||
import os | ||
import sys | ||
|
||
# choose a different alpaka backend depending on the SCRAM test being run | ||
try: | ||
backend = os.environ['SCRAM_ALPAKA_BACKEND'] | ||
except: | ||
backend = 'SerialSync' | ||
|
||
# map the alpaka backends to the process accelerators | ||
accelerators = { | ||
'SerialSync': 'cpu', | ||
'CudaAsync': 'gpu-nvidia', | ||
'ROCmAsync': 'gpu-amd' | ||
} | ||
|
||
print(f"Testing the alpaka backend {backend} using the process accelerator {accelerators[backend]}") | ||
|
||
import FWCore.ParameterSet.Config as cms | ||
from HeterogeneousCore.AlpakaCore.functions import * | ||
|
||
process = cms.Process('Test') | ||
|
||
process.options.accelerators = [ accelerators[backend] ] | ||
|
||
process.maxEvents.input = 10 | ||
|
||
process.source = cms.Source('EmptySource') | ||
|
||
process.load('Configuration.StandardSequences.Accelerators_cff') | ||
process.load('HeterogeneousCore.AlpakaCore.ProcessAcceleratorAlpaka_cfi') | ||
|
||
process.alpakaBackendProducer = cms.EDProducer('AlpakaBackendProducer@alpaka') | ||
|
||
process.alpakaBackendFilter = cms.EDFilter('AlpakaBackendFilter', | ||
producer = cms.InputTag('alpakaBackendProducer', 'backend'), | ||
backends = cms.vstring(backend) | ||
) | ||
|
||
process.mustRun = cms.EDProducer("edmtest::MustRunIntProducer", ivalue=cms.int32(1)) | ||
process.mustNotRun = cms.EDProducer("FailingProducer") | ||
|
||
process.SelectedBackend = cms.Path(process.alpakaBackendProducer + process.alpakaBackendFilter + process.mustRun) | ||
process.AnyOtherBackend = cms.Path(process.alpakaBackendProducer + ~process.alpakaBackendFilter + process.mustNotRun) | ||
|
||
process.options.wantSummary = True |