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
 
void producesTemporarily (std::string const &iTypeName, std::string instanceName=std::string())
 

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 42 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 46 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 49 of file ProducerBase.h.

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

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

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 97 of file ProducerBase.h.

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

97  {
98  if constexpr (detail::useProductDirectly<TProduct>) {
99  return Base::template produces<TToken, Tr>(std::move(instanceName));
100  } else {
101  edm::EDPutTokenT<TToken> token = Base::template produces<TToken, Tr>(instanceName);
102  this->registerTransformAsync(
103  token,
104  [](TToken const& deviceProduct, edm::WaitingTaskWithArenaHolder holder) {
105  auto const& device = alpaka::getDev(deviceProduct.template metadata<EDMetadata>().queue());
106  detail::EDMetadataAcquireSentry sentry(device, std::move(holder));
107  auto metadataPtr = sentry.metadata();
108  constexpr bool tryReuseQueue = true;
109  TProduct const& productOnDevice =
110  deviceProduct.template getSynchronized<EDMetadata>(*metadataPtr, tryReuseQueue);
111 
113  auto productOnHost = CopyT::copyAsync(metadataPtr->queue(), productOnDevice);
114 
115  // Need to keep the EDMetadata object from sentry.finish()
116  // alive until the synchronization
117  using TplType = std::tuple<decltype(productOnHost), std::shared_ptr<EDMetadata>>;
118  // Wrap possibly move-only type into a copyable type
119  return std::make_shared<TplType>(std::move(productOnHost), sentry.finish());
120  },
121  [](auto tplPtr) { return std::move(std::get<0>(*tplPtr)); },
122  std::move(instanceName));
123  return token;
124  }
125  }
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 67 of file ProducerBase.h.

References cms::alpakatools::module_backend_config().

67  {
68  Base::prevalidate(descriptions);
70  }
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 52 of file ProducerBase.h.

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

◆ 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 57 of file ProducerBase.h.

References eostools::move().

57  {
58  return ProducerBaseAdaptor<ProducerBase, Tr>(*this, std::move(instanceName));
59  }
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 88 of file ProducerBase.h.

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

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

◆ producesTemporarily()

template<template< typename... > class BaseT, typename... Args>
void ALPAKA_ACCELERATOR_NAMESPACE::ProducerBase< BaseT, Args >::producesTemporarily ( std::string const &  iTypeName,
std::string  instanceName = std::string() 
)
inline

Definition at line 62 of file ProducerBase.h.

References edm::TypeWithDict::byName(), eostools::move(), and svgfig::template().

62  {
63  auto td = edm::TypeWithDict::byName(iTypeName);
64  Base::template produces<edm::Transition::Event>(edm::TypeID(td.typeInfo()), std::move(instanceName));
65  }
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
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 73 of file ProducerBase.h.

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

73  {
74  iEvent.emplace(this->backendToken_, static_cast<unsigned short>(kBackend));
75  }
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 81 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