Skip to content
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

Require the AlpakaService to be enabled before running on a Device #39498

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions HeterogeneousCore/AlpakaCore/interface/chooseDevice.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
#ifndef HeterogeneousCore_AlpakaCore_interface_chooseDevice_h
#define HeterogeneousCore_AlpakaCore_interface_chooseDevice_h

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaInterface/interface/devices.h"
#include "HeterogeneousCore/AlpakaInterface/interface/traits.h"
#include "HeterogeneousCore/AlpakaServices/interface/alpaka/AlpakaService.h"

namespace cms::alpakatools {

template <typename TPlatform, typename = std::enable_if_t<is_platform_v<TPlatform>>>
alpaka::Dev<TPlatform> const& chooseDevice(edm::StreamID id) {
edm::Service<ALPAKA_TYPE_ALIAS(AlpakaService)> service;
rappoccio marked this conversation as resolved.
Show resolved Hide resolved
if (not service->enabled()) {
cms::Exception ex("RuntimeError");
ex << "Unable to choose current device because " << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " is disabled.\n"
<< "If " << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " was not explicitly disabled in the configuration,\n"
<< "the probable cause is that there is no accelerator or there is some problem\n"
<< "with the accelerator runtime or drivers.";
ex.addContext("Calling cms::alpakatools::chooseDevice()");
throw ex;
}

// For startes we "statically" assign the device based on
// edm::Stream number. This is suboptimal if the number of
// edm::Streams is not a multiple of the number of devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ServiceRegistry/interface/Service.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/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaServices/interface/alpaka/AlpakaService.h"

#include "TestAlgo.h"

Expand All @@ -24,13 +22,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
TestAlpakaProducer(edm::ParameterSet const& config)
: deviceToken_{produces()}, size_{config.getParameter<int32_t>("size")} {}

void beginStream(edm::StreamID) override {
edm::Service<ALPAKA_TYPE_ALIAS(AlpakaService)> service;
if (not service->enabled()) {
throw cms::Exception("Configuration") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " is disabled.";
}
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ServiceRegistry/interface/Service.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/AlpakaInterface/interface/config.h"
#include "HeterogeneousCore/AlpakaServices/interface/alpaka/AlpakaService.h"

namespace ALPAKA_ACCELERATOR_NAMESPACE {

Expand All @@ -25,13 +23,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE {
TestAlpakaTranscriber(edm::ParameterSet const& config)
: deviceToken_{consumes(config.getParameter<edm::InputTag>("source"))}, hostToken_{produces()} {}

void beginStream(edm::StreamID) override {
edm::Service<ALPAKA_TYPE_ALIAS(AlpakaService)> service;
if (not service->enabled()) {
throw cms::Exception("Configuration") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " is disabled.";
}
}

void acquire(edm::Event const& event, edm::EventSetup const& setup, edm::WaitingTaskWithArenaHolder task) override {
// create a context reusing the same device and queue as the producer of the input collection
auto const& input = event.get(deviceToken_);
Expand Down