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 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:72

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

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

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

References cms::alpakatools::module_backend_config().

61  {
62  Base::prevalidate(descriptions);
64  }
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 82 of file ProducerBase.h.

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

82  {
83  return Base::template produces<TProduct, Tr>(std::move(instanceName));
84  }
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 67 of file ProducerBase.h.

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

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