CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
cms::cuda::ScopedContextProduce Class Reference

#include <ScopedContext.h>

Inheritance diagram for cms::cuda::ScopedContextProduce:
cms::cuda::impl::ScopedContextGetterBase cms::cuda::impl::ScopedContextBase

Public Member Functions

template<typename T , typename... Args>
auto emplace (edm::Event &iEvent, edm::EDPutTokenT< T > token, Args &&... args)
 
 ScopedContextProduce (const ProductBase &data)
 Constructor to (possibly) re-use a CUDA stream (non-ExternalWork module) More...
 
 ScopedContextProduce (ContextState &state)
 Constructor to re-use the CUDA stream of acquire() (ExternalWork module) More...
 
 ScopedContextProduce (edm::StreamID streamID)
 Constructor to create a new CUDA stream (non-ExternalWork module) More...
 
template<typename T >
std::unique_ptr< Product< T > > wrap (T data)
 
 ~ScopedContextProduce ()
 Record the CUDA event, all asynchronous work must have been queued before the destructor. More...
 
- Public Member Functions inherited from cms::cuda::impl::ScopedContextGetterBase
template<typename T >
const Tget (const edm::Event &iEvent, edm::EDGetTokenT< Product< T >> token)
 
template<typename T >
const Tget (const Product< T > &data)
 
- Public Member Functions inherited from cms::cuda::impl::ScopedContextBase
int device () const
 
cudaStream_t stream () const
 
const SharedStreamPtrstreamPtr () const
 

Private Member Functions

 ScopedContextProduce (int device, SharedStreamPtr stream, SharedEventPtr event)
 

Private Attributes

SharedEventPtr event_ = getEventCache().get()
 

Friends

class cudatest::TestScopedContext
 

Additional Inherited Members

- Protected Member Functions inherited from cms::cuda::impl::ScopedContextGetterBase
template<typename... Args>
 ScopedContextGetterBase (Args &&... args)
 
void synchronizeStreams (int dataDevice, cudaStream_t dataStream, bool available, cudaEvent_t dataEvent)
 
- Protected Member Functions inherited from cms::cuda::impl::ScopedContextBase
 ScopedContextBase (const ProductBase &data)
 
 ScopedContextBase (edm::StreamID streamID)
 
 ScopedContextBase (int device, SharedStreamPtr stream)
 

Detailed Description

The aim of this class is to do necessary per-event "initialization" in ExternalWork produce() or normal produce():

Definition at line 149 of file ScopedContext.h.

Constructor & Destructor Documentation

◆ ScopedContextProduce() [1/4]

cms::cuda::ScopedContextProduce::ScopedContextProduce ( edm::StreamID  streamID)
inlineexplicit

Constructor to create a new CUDA stream (non-ExternalWork module)

Definition at line 152 of file ScopedContext.h.

152 : ScopedContextGetterBase(streamID) {}

◆ ScopedContextProduce() [2/4]

cms::cuda::ScopedContextProduce::ScopedContextProduce ( const ProductBase data)
inlineexplicit

Constructor to (possibly) re-use a CUDA stream (non-ExternalWork module)

Definition at line 155 of file ScopedContext.h.

◆ ScopedContextProduce() [3/4]

cms::cuda::ScopedContextProduce::ScopedContextProduce ( ContextState state)
inlineexplicit

Constructor to re-use the CUDA stream of acquire() (ExternalWork module)

Definition at line 158 of file ScopedContext.h.

159  : ScopedContextGetterBase(state.device(), state.releaseStreamPtr()) {}

◆ ~ScopedContextProduce()

cms::cuda::ScopedContextProduce::~ScopedContextProduce ( )

Record the CUDA event, all asynchronous work must have been queued before the destructor.

Definition at line 108 of file ScopedContext.cc.

108  {
109  // Intentionally not checking the return value to avoid throwing
110  // exceptions. If this call would fail, we should get failures
111  // elsewhere as well.
112  cudaEventRecord(event_.get(), stream());
113  }

References event_, and cms::cuda::impl::ScopedContextBase::stream().

◆ ScopedContextProduce() [4/4]

cms::cuda::ScopedContextProduce::ScopedContextProduce ( int  device,
SharedStreamPtr  stream,
SharedEventPtr  event 
)
inlineexplicitprivate

Definition at line 179 of file ScopedContext.h.

References eostools::move().

Member Function Documentation

◆ emplace()

template<typename T , typename... Args>
auto cms::cuda::ScopedContextProduce::emplace ( edm::Event iEvent,
edm::EDPutTokenT< T token,
Args &&...  args 
)
inline

◆ wrap()

template<typename T >
std::unique_ptr<Product<T> > cms::cuda::ScopedContextProduce::wrap ( T  data)
inline

Definition at line 165 of file ScopedContext.h.

165  {
166  // make_unique doesn't work because of private constructor
167  return std::unique_ptr<Product<T>>(new Product<T>(device(), streamPtr(), event_, std::move(data)));
168  }

References data, cms::cuda::impl::ScopedContextBase::device(), event_, eostools::move(), and cms::cuda::impl::ScopedContextBase::streamPtr().

Friends And Related Function Documentation

◆ cudatest::TestScopedContext

friend class cudatest::TestScopedContext
friend

Definition at line 176 of file ScopedContext.h.

Member Data Documentation

◆ event_

SharedEventPtr cms::cuda::ScopedContextProduce::event_ = getEventCache().get()
private

Definition at line 183 of file ScopedContext.h.

Referenced by emplace(), wrap(), and ~ScopedContextProduce().

writedatasetfile.args
args
Definition: writedatasetfile.py:18
cms::cuda::impl::ScopedContextBase::stream
cudaStream_t stream() const
Definition: ScopedContext.h:34
cms::cuda::ScopedContextProduce::event_
SharedEventPtr event_
Definition: ScopedContext.h:183
cms::cuda::impl::ScopedContextGetterBase::ScopedContextGetterBase
ScopedContextGetterBase(Args &&... args)
Definition: ScopedContext.h:70
cms::cuda::impl::ScopedContextBase::streamPtr
const SharedStreamPtr & streamPtr() const
Definition: ScopedContext.h:35
iEvent
int iEvent
Definition: GenABIO.cc:224
eostools.move
def move(src, dest)
Definition: eostools.py:511
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
event
Definition: event.py:1
cms::cuda::impl::ScopedContextBase::device
int device() const
Definition: ScopedContext.h:28
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316