CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | 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

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

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)
 

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 transfer 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::TransferToHost<T> template, that should be provided in the same file where T is defined.

TODO: add "override" for labelsForToken()

Definition at line 37 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 41 of file ProducerBase.h.

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

72  {
73  edm::EDPutTokenT<TToken> token = Base::template produces<TToken, Tr>(std::move(instanceName));
74  // TODO: should host-synchronous backend(s) have DeviceProduct<TProduct> branch?
75 #ifndef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
76  // All device backends or devices with asynchronous queue
77 
78  // TODO: in principle we could also decide to not register the
79  // transfer to host if the TransferToHost<T> has not been
80  // specialized for TProduct.
81  this->registerTransformAsync(
82  token,
83  [](TToken const& deviceProduct, edm::WaitingTaskWithArenaHolder holder) {
84  auto const& device = alpaka::getDev(deviceProduct.template metadata<EDMetadata>().queue());
85  detail::EDMetadataAcquireSentry sentry(device, std::move(holder));
86  auto metadataPtr = sentry.metadata();
87  constexpr bool tryReuseQueue = true;
88  TProduct const& productOnDevice =
89  deviceProduct.template getSynchronized<EDMetadata>(*metadataPtr, tryReuseQueue);
90 
92  using HostType = typename TransferT::HostDataType;
93  HostType productOnHost = TransferT::transferAsync(metadataPtr->queue(), productOnDevice);
94 
95  // Need to keep the EDMetadata object from sentry.finish()
96  // alive until the synchronization
97  using TplType = std::tuple<HostType, std::shared_ptr<EDMetadata>>;
98  // Wrap possibly move-only type into a copyable type
99  return std::make_shared<TplType>(std::move(productOnHost), sentry.finish());
100  },
101  [](auto tplPtr) { return std::move(std::get<0>(*tplPtr)); });
102 #endif
103  return token;
104  }
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
def move(src, dest)
Definition: eostools.py:511

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

45  {
46  return ProducerBaseAdaptor<ProducerBase, Tr>(*this);
47  }

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

50  {
51  return ProducerBaseAdaptor<ProducerBase, Tr>(*this, std::move(instanceName));
52  }
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 63 of file ProducerBase.h.

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

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