CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args > Class Template Reference

#include <ProducerBase.h>

Inheritance diagram for ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >:

Public Member Functions

 ProducerBase ()
 
template<edm::Transition Tr = edm::Transition::Event>
auto produces () noexcept
 
template<edm::Transition Tr = edm::Transition::Event>
auto produces (std::string instanceName) noexcept
 

Static Public Member Functions

static void prevalidate (edm::ConfigurationDescriptions &descriptions)
 

Protected Member Functions

void putBackend (edm::Event &iEvent) const
 

Private Types

using Base = BaseT< Args..., edm::Transformer >
 

Private Member Functions

template<typename TProduct , typename TToken , edm::Transition Tr>
edm::EDPutTokenT< TToken > deviceProduces (std::string instanceName)
 
template<typename TProduct , edm::Transition Tr>
edm::EDPutTokenT< TProduct > produces (std::string instanceName)
 

Private Attributes

edm::EDPutTokenT< unsigned short > const backendToken_
 

Friends

template<typename TProducer , edm::Transition Tr>
class ProducerBaseAdaptor
 

Detailed Description

template<template< typename... > class BaseT, typename... Args>
class ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >

The ProducerBase acts as a common base class for all Alpaka EDProducers. The main benefit is to have a single place for the definition of produces() functions.

The produces() functions return a custom ProducerBaseAdaptor in order to call the deviceProduces(). For device or asynchronous backends the deviceProduces() registers the automatic copy to host and a transformation from edm::DeviceProduct<T> to U, where U is the host-equivalent of T. The transformation from T to U is done by a specialization of cms::alpakatools::CopyToHost<T> class template, that should be provided in the same file where T is defined

TODO: add "override" for labelsForToken()

Definition at line 41 of file ProducerBase.h.

Member Typedef Documentation

◆ Base

template<template< typename... > class BaseT, typename... Args>
using ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::Base = BaseT<Args..., edm::Transformer>
private

Definition at line 45 of file ProducerBase.h.

Constructor & Destructor Documentation

◆ ProducerBase()

template<template< typename... > class BaseT, typename... Args>
ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::ProducerBase ( )
inline

Definition at line 48 of file ProducerBase.h.

References ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::backendToken_.

48 : backendToken_(Base::produces("backend")) {}
edm::EDPutTokenT< unsigned short > const backendToken_
Definition: ProducerBase.h:71

Member Function Documentation

◆ deviceProduces()

template<template< typename... > class BaseT, typename... Args>
template<typename TProduct , typename TToken , edm::Transition Tr>
edm::EDPutTokenT<TToken> ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::deviceProduces ( std::string  instanceName)
inlineprivate

Definition at line 90 of file ProducerBase.h.

References ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), cms::cuda::copyAsync(), eostools::move(), svgfig::template(), and unpackBuffers-CaloStage2::token.

90  {
91  if constexpr (detail::useProductDirectly<TProduct>) {
92  return Base::template produces<TToken, Tr>(std::move(instanceName));
93  } else {
94  edm::EDPutTokenT<TToken> token = Base::template produces<TToken, Tr>(instanceName);
95  this->registerTransformAsync(
96  token,
97  [](TToken const& deviceProduct, edm::WaitingTaskWithArenaHolder holder) {
98  auto const& device = alpaka::getDev(deviceProduct.template metadata<EDMetadata>().queue());
99  detail::EDMetadataAcquireSentry sentry(device, std::move(holder));
100  auto metadataPtr = sentry.metadata();
101  constexpr bool tryReuseQueue = true;
102  TProduct const& productOnDevice =
103  deviceProduct.template getSynchronized<EDMetadata>(*metadataPtr, tryReuseQueue);
104 
106  auto productOnHost = CopyT::copyAsync(metadataPtr->queue(), productOnDevice);
107 
108  // Need to keep the EDMetadata object from sentry.finish()
109  // alive until the synchronization
110  using TplType = std::tuple<decltype(productOnHost), std::shared_ptr<EDMetadata>>;
111  // Wrap possibly move-only type into a copyable type
112  return std::make_shared<TplType>(std::move(productOnHost), sentry.finish());
113  },
114  [](auto tplPtr) { return std::move(std::get<0>(*tplPtr)); },
115  std::move(instanceName));
116  return token;
117  }
118  }
void copyAsync(device::unique_ptr< T > &dst, const host::unique_ptr< T > &src, cudaStream_t stream)
Definition: copyAsync.h:20
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
def move(src, dest)
Definition: eostools.py:511

◆ prevalidate()

template<template< typename... > class BaseT, typename... Args>
static void ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::prevalidate ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 60 of file ProducerBase.h.

References cms::alpakatools::module_backend_config().

60  {
61  Base::prevalidate(descriptions);
63  }
void module_backend_config(edm::ConfigurationDescriptions &iDesc)

◆ produces() [1/3]

template<template< typename... > class BaseT, typename... Args>
template<edm::Transition Tr = edm::Transition::Event>
auto ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::produces ( )
inlinenoexcept

Definition at line 51 of file ProducerBase.h.

51  {
52  return ProducerBaseAdaptor<ProducerBase, Tr>(*this);
53  }

◆ produces() [2/3]

template<template< typename... > class BaseT, typename... Args>
template<edm::Transition Tr = edm::Transition::Event>
auto ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::produces ( std::string  instanceName)
inlinenoexcept

Definition at line 56 of file ProducerBase.h.

References eostools::move().

56  {
57  return ProducerBaseAdaptor<ProducerBase, Tr>(*this, std::move(instanceName));
58  }
def move(src, dest)
Definition: eostools.py:511

◆ produces() [3/3]

template<template< typename... > class BaseT, typename... Args>
template<typename TProduct , edm::Transition Tr>
edm::EDPutTokenT<TProduct> ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::produces ( std::string  instanceName)
inlineprivate

Definition at line 81 of file ProducerBase.h.

References eostools::move(), and svgfig::template().

81  {
82  return Base::template produces<TProduct, Tr>(std::move(instanceName));
83  }
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
def move(src, dest)
Definition: eostools.py:511

◆ putBackend()

template<template< typename... > class BaseT, typename... Args>
void ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::putBackend ( edm::Event iEvent) const
inlineprotected

Definition at line 66 of file ProducerBase.h.

References ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::backendToken_, and iEvent.

66  {
67  iEvent.emplace(this->backendToken_, static_cast<unsigned short>(kBackend));
68  }
int iEvent
Definition: GenABIO.cc:224

Friends And Related Function Documentation

◆ ProducerBaseAdaptor

template<template< typename... > class BaseT, typename... Args>
template<typename TProducer , edm::Transition Tr>
friend class ProducerBaseAdaptor
friend

Definition at line 74 of file ProducerBase.h.

Member Data Documentation

◆ backendToken_

template<template< typename... > class BaseT, typename... Args>
edm::EDPutTokenT<unsigned short> const ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::backendToken_
private