ATLAS Offline Software
List of all members
AthCUDA::StreamPoolSvc Class Reference

Service managing a fixed number of CUDA streams for an application. More...

#include <StreamPoolSvc.h>

Inheritance diagram for AthCUDA::StreamPoolSvc:
Collaboration diagram for AthCUDA::StreamPoolSvc:

Public Member Functions

Interface inherited from @c IService
virtual StatusCode initialize () override
 Initialise the service. More...
 
virtual StatusCode finalize () override
 Finalise the service. More...
 
Interface inherited from @c AthCUDA::IStreamPoolSvc
virtual bool isEmpty () const override
 Check whether any streams are available for the job. More...
 
virtual StreamHolder getAvailableStream () override
 Get a stream from the pool. More...
 
virtual void yieldStream (StreamHolder &stream) override
 Put a given stream back into the pool. More...
 

Private Attributes

Service properties
Gaudi::Property< unsigned int > m_nStreams
 The number of streams to use. More...
 
Implementation variable(s)
std::unique_ptr< StreamPoolSvcImplm_impl
 The object implementing the interaction with CUDA. More...
 

Detailed Description

Service managing a fixed number of CUDA streams for an application.

The service provides streams to the callers by endlessly looping over the available queue of streams that it allocates during the initialisation.

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 31 of file StreamPoolSvc.h.

Member Function Documentation

◆ finalize()

StatusCode AthCUDA::StreamPoolSvc::finalize ( )
overridevirtual

Finalise the service.

Definition at line 37 of file StreamPoolSvc.cxx.

37  {
38 
39  // Destroy the implementation object.
40  m_impl.reset();
41 
42  // Tell the user what happened.
43  ATH_MSG_INFO( "Destroyed all streams" );
44 
45  // Return gracefully.
46  return StatusCode::SUCCESS;
47  }

◆ getAvailableStream()

StreamHolder AthCUDA::StreamPoolSvc::getAvailableStream ( )
overridevirtual

Get a stream from the pool.

Note that the returned holder may point to a null memory address, in case no streams are available at the moment of the call.

Returns
A stream holder describing a possibly abailable stream

Definition at line 54 of file StreamPoolSvc.cxx.

54  {
55 
56  // If we don't have streams available, return right away.
57  if( m_nStreams.value() == 0 ) {
58  return StreamHolder();
59  }
60 
61  // A security check.
62  assert( m_impl );
63 
64  // Get the next available stream for the user.
65  return m_impl->getAvailableStream();
66  }

◆ initialize()

StatusCode AthCUDA::StreamPoolSvc::initialize ( )
overridevirtual

Initialise the service.

Definition at line 16 of file StreamPoolSvc.cxx.

16  {
17 
18  // If there are no CUDA capable devices available, then don't try to
19  // set up any streams.
20  if( Info::instance().nDevices() == 0 ) {
21  ATH_MSG_INFO( "CUDA device(s) not available. Not setting up "
22  "streams." );
23  return StatusCode::SUCCESS;
24  }
25 
26  // Create the implementation object.
27  m_impl =
28  std::make_unique< StreamPoolSvcImpl >( m_nStreams.value(), *this );
29 
30  // Tell the user what happened.
31  ATH_MSG_INFO( "Allocated " << m_nStreams.value() << " stream(s)" );
32 
33  // Return gracefully.
34  return StatusCode::SUCCESS;
35  }

◆ isEmpty()

bool AthCUDA::StreamPoolSvc::isEmpty ( ) const
overridevirtual

Check whether any streams are available for the job.

This is a thread-safe way to check whether any CUDA streams are available at runtime.

Returns
true if the service will under no circumstances return a valid stream, false if it might

Definition at line 49 of file StreamPoolSvc.cxx.

49  {
50 
51  return ( m_nStreams.value() == 0 );
52  }

◆ yieldStream()

void AthCUDA::StreamPoolSvc::yieldStream ( StreamHolder stream)
overridevirtual

Put a given stream back into the pool.

This is a function called by AthCUDA::StreamHolder behind the scenes when it goes out of scope. It should not be called by hand.

Parameters
streamThe stream holder whose stream is to be put back into the pool

Definition at line 68 of file StreamPoolSvc.cxx.

68  {
69 
70  // A security check.
71  assert( m_impl );
72 
73  // Put the stream back into our queue.
74  m_impl->yieldStream( stream );
75  return;
76  }

Member Data Documentation

◆ m_impl

std::unique_ptr< StreamPoolSvcImpl > AthCUDA::StreamPoolSvc::m_impl
private

The object implementing the interaction with CUDA.

Definition at line 95 of file StreamPoolSvc.h.

◆ m_nStreams

Gaudi::Property< unsigned int > AthCUDA::StreamPoolSvc::m_nStreams
private
Initial value:
{ this, "NStreams", 2,
"The number of CUDA streams to use" }

The number of streams to use.

Definition at line 86 of file StreamPoolSvc.h.


The documentation for this class was generated from the following files:
AthCUDA::Info::instance
static const Info & instance()
Singleton accessor function.
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCUDA::StreamPoolSvc::m_impl
std::unique_ptr< StreamPoolSvcImpl > m_impl
The object implementing the interaction with CUDA.
Definition: StreamPoolSvc.h:95
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
AthCUDA::StreamPoolSvc::m_nStreams
Gaudi::Property< unsigned int > m_nStreams
The number of streams to use.
Definition: StreamPoolSvc.h:86