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 (edm::StreamID streamID)
 Constructor to create a new CUDA stream (non-ExternalWork module) More...
 
 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...
 
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 Product< T > &data)
 
template<typename T >
const Tget (const edm::Event &iEvent, edm::EDGetTokenT< Product< T >> token)
 
- 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 (edm::StreamID streamID)
 
 ScopedContextBase (const ProductBase &data)
 
 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.

char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79

◆ 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.

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

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  }

◆ 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.

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

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  }
const SharedStreamPtr & streamPtr() const
Definition: ScopedContext.h:35
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
def move(src, dest)
Definition: eostools.py:511

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().