ATLAS Offline Software
Loading...
Searching...
No Matches
StreamPoolSvc.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
6#include "StreamPoolSvc.h"
7
8// Project include(s).
9#include "AthCUDACore/Info.h"
10
11// System include(s).
12#include <cassert>
13
14namespace AthCUDA {
15
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 }
36
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 }
48
50
51 return ( m_nStreams.value() == 0 );
52 }
53
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 }
67
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 }
77
78} // namespace AthCUDA
#define ATH_MSG_INFO(x)
static const Info & instance()
Singleton accessor function.
Helper class for handling CUDA streams.
virtual StatusCode initialize() override
Initialise the service.
virtual StreamHolder getAvailableStream() override
Get a stream from the pool.
virtual void yieldStream(StreamHolder &stream) override
Put a given stream back into the pool.
virtual bool isEmpty() const override
Check whether any streams are available for the job.
Gaudi::Property< unsigned int > m_nStreams
The number of streams to use.
virtual StatusCode finalize() override
Finalise the service.
std::unique_ptr< StreamPoolSvcImpl > m_impl
The object implementing the interaction with CUDA.
Definition Info.h:14