Skip to content

Commit

Permalink
Migrate TestAlpakaProducer to the new framework interface
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Nov 16, 2022
1 parent 5ba5441 commit 2278370
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 101 deletions.
22 changes: 9 additions & 13 deletions HeterogeneousCore/AlpakaTest/plugins/alpaka/TestAlpakaProducer.cc
@@ -1,37 +1,33 @@
#include "DataFormats/Portable/interface/Product.h"
#include "DataFormats/PortableTestObjects/interface/alpaka/TestDeviceCollection.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "HeterogeneousCore/AlpakaCore/interface/ScopedContext.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
#include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/EDProducer.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

#include "TestAlgo.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

class TestAlpakaProducer : public edm::stream::EDProducer<> {
class TestAlpakaProducer : public stream::EDProducer<> {
public:
TestAlpakaProducer(edm::ParameterSet const& config)
: deviceToken_{produces()}, size_{config.getParameter<int32_t>("size")} {}

void produce(edm::Event& event, edm::EventSetup const&) override {
// create a context based on the EDM stream number
cms::alpakatools::ScopedContextProduce<Queue> ctx(event.streamID());

void produce(device::Event& event, device::EventSetup const&) override {
// run the algorithm, potentially asynchronously
portabletest::TestDeviceCollection deviceProduct{size_, ctx.queue()};
algo_.fill(ctx.queue(), deviceProduct);
portabletest::TestDeviceCollection deviceProduct{size_, event.queue()};
algo_.fill(event.queue(), deviceProduct);

// put the asynchronous product into the event without waiting
ctx.emplace(event, deviceToken_, std::move(deviceProduct));
event.emplace(deviceToken_, std::move(deviceProduct));
}

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand All @@ -41,7 +37,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
}

private:
const edm::EDPutTokenT<cms::alpakatools::Product<Queue, portabletest::TestDeviceCollection>> deviceToken_;
const device::EDPutToken<portabletest::TestDeviceCollection> deviceToken_;
const int32_t size_;

// implementation of the algorithm
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion HeterogeneousCore/AlpakaTest/test/reader.py
Expand Up @@ -17,7 +17,7 @@

# analyse the second product
process.testAnalyzerSerial = cms.EDAnalyzer('TestAlpakaAnalyzer',
source = cms.InputTag('testTranscriberSerial')
source = cms.InputTag('testProducerSerial')
)

process.cuda_path = cms.Path(process.testAnalyzer)
Expand Down
32 changes: 11 additions & 21 deletions HeterogeneousCore/AlpakaTest/test/writer.py
Expand Up @@ -20,28 +20,24 @@
size = cms.int32(42)
)

# copy the product from the gpu (if available) to the host
process.testTranscriberFromCuda = cms.EDProducer('alpaka_cuda_async::TestAlpakaTranscriber',
source = cms.InputTag('testProducerCuda')
)

# run the producer on the cpu
process.testProducerCpu = cms.EDProducer('alpaka_serial_sync::TestAlpakaProducer',
size = cms.int32(42)
)

# extract the cpu product from the heterogeneous wrapper
process.testTranscriberFromCpu = cms.EDProducer('alpaka_serial_sync::TestAlpakaTranscriber',
source = cms.InputTag('testProducerCpu')
)

# either run the producer on a CUDA gpu (if available) and copy the product to the cpu, or run the producer directly on the cpu
#
# TODO: the cuda case needs currently explicitly to restrict the
# host-only data products. In the near future the constraints of
# SwichProducer will be relaxed to not consider transient data
# products (as defined in classes_def.xml) after which the explicit
# set of data products can be removed.
process.testProducer = SwitchProducerCUDA(
cpu = cms.EDAlias(
testTranscriberFromCpu = cms.VPSet(cms.PSet(type = cms.string('*')))
testProducerCpu = cms.VPSet(cms.PSet(type = cms.string('*')))
),
cuda = cms.EDAlias(
testTranscriberFromCuda = cms.VPSet(cms.PSet(type = cms.string('*')))
testProducerCuda = cms.VPSet(cms.PSet(type = cms.string('128falseportabletestTestSoALayoutPortableHostCollection')))
)
)

Expand All @@ -55,14 +51,9 @@
size = cms.int32(99)
)

# extract the cpu product from the heterogeneous wrapper
process.testTranscriberSerial = cms.EDProducer('alpaka_serial_sync::TestAlpakaTranscriber',
source = cms.InputTag('testProducerSerial')
)

# analyse the second product
process.testAnalyzerSerial = cms.EDAnalyzer('TestAlpakaAnalyzer',
source = cms.InputTag('testTranscriberSerial')
source = cms.InputTag('testProducerSerial')
)

# write the two products to a 'test.root' file
Expand All @@ -71,11 +62,11 @@
outputCommands = cms.untracked.vstring(
'drop *',
'keep *_testProducer_*_*',
'keep *_testTranscriberSerial_*_*',
'keep *_testProducerSerial_*_*',
)
)

process.producer_task = cms.Task(process.testProducerCuda, process.testTranscriberFromCuda, process.testProducerCpu, process.testTranscriberFromCpu)
process.producer_task = cms.Task(process.testProducerCuda, process.testProducerCpu)

process.process_path = cms.Path(
process.testProducer +
Expand All @@ -84,7 +75,6 @@

process.serial_path = cms.Path(
process.testProducerSerial +
process.testTranscriberSerial +
process.testAnalyzerSerial)

process.output_path = cms.EndPath(process.output)
Expand Down

0 comments on commit 2278370

Please sign in to comment.