-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement AlpakaBackendProducer and AlpakaBackendFilter #44387
Merged
cmsbuild
merged 1 commit into
cms-sw:master
from
fwyzard:implement_AlpakaBackendFilter_14_1_x
Mar 16, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem lies here, duplicate plugin name wrt
cmssw/HeterogeneousCore/AlpakaTest/plugins/BuildFile.xml
Line 16 in ec85b46