The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
GPUCruncher Class Reference

A test asynchronous algorithm on the GPU. More...

#include </builds/gaudi/Gaudi/GaudiCUDA/src/GPUCruncher.h>

Inheritance diagram for GPUCruncher:
Collaboration diagram for GPUCruncher:

Public Types

using CHM = tbb::concurrent_hash_map<std::string, unsigned int>
 
- Public Types inherited from Gaudi::Algorithm
typedef Gaudi::PluginService::Factory< IAlgorithm *(const std::string &, ISvcLocator *)> Factory
 
- Public Types inherited from extends< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >, IDataHandleHolder >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 

Public Member Functions

bool isClonable () const override
 
StatusCode execute (const EventContext &ctx) const override
 the execution of the algorithm
 
StatusCode initialize () override
 Its initialization.
 
StatusCode finalize () override
 the finalization of the algorithm
 
double get_runtime () const
 
 GPUCruncher (const std::string &name, ISvcLocator *pSvc)
 
virtual ~GPUCruncher ()
 virtual & protected desctrustor
 
- Public Member Functions inherited from Gaudi::AsynchronousAlgorithm
StatusCode sysInitialize () override
 
StatusCode sysExecute (const EventContext &ctx) override
 
virtual StatusCode restoreAfterSuspend () const
 Restore after suspend.
 
StatusCode yield () const
 Forwards to boost::this_fiber::yield.
 
template<typename Clock, typename Duration>
StatusCode sleep_until (std::chrono::time_point< Clock, Duration > const &sleep_time) const
 Forwards to boost::this_fiber::sleep_until.
 
template<typename Rep, typename Period>
StatusCode sleep_for (std::chrono::duration< Rep, Period > const &dur) const
 Forwards to boost::this_fiber::sleep_for.
 
 Algorithm (std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
 Constructor.
 
- Public Member Functions inherited from Gaudi::Algorithm
 Algorithm (std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
 Constructor.
 
StatusCode sysStart () override
 Reinitialization method invoked by the framework.
 
StatusCode sysInitialize () override
 Initialization method invoked by the framework.
 
StatusCode sysReinitialize () override
 Reinitialization method invoked by the framework.
 
StatusCode sysRestart () override
 Restart method invoked by the framework.
 
StatusCode sysExecute (const EventContext &ctx) override
 The actions to be performed by the algorithm on an event.
 
StatusCode sysStop () override
 System stop.
 
StatusCode sysFinalize () override
 System finalization.
 
const std::string & name () const override
 The identifying name of the algorithm object.
 
const Gaudi::StringKeynameKey () const override
 
const std::string & type () const override
 The type of the algorithm object.
 
void setType (std::string type) override
 
const std::string & version () const override
 
unsigned int index () const override
 
StatusCode configure () override
 Dummy implementation of IStateful::configure() method.
 
StatusCode terminate () override
 Dummy implementation of IStateful::terminate() method.
 
StatusCode initialize () override
 the default (empty) implementation of IStateful::initialize() method
 
StatusCode start () override
 the default (empty) implementation of IStateful::start() method
 
StatusCode stop () override
 the default (empty) implementation of IStateful::stop() method
 
StatusCode finalize () override
 the default (empty) implementation of IStateful::finalize() method
 
StatusCode reinitialize () override
 the default (empty) implementation of IStateful::reinitialize() method
 
StatusCode restart () override
 the default (empty) implementation of IStateful::restart() method
 
Gaudi::StateMachine::State FSMState () const override
 returns the current state of the algorithm
 
Gaudi::StateMachine::State targetFSMState () const override
 returns the state the algorithm will be in after the ongoing transition
 
bool isEnabled () const override
 Is this algorithm enabled or disabled?
 
bool isSequence () const override
 Are we a Sequence?
 
unsigned int errorCount () const
 Get the number of failures of the algorithm.
 
SmartIF< IServiceservice (std::string_view name, const bool createIf=true, const bool quiet=false) const
 Return a pointer to the service identified by name (or "type/name")
 
template<class T>
SmartIF< T > service (std::string_view name, bool createIf=true, bool quiet=false) const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
SmartIF< IChronoStatSvc > & chronoSvc () const
 The standard Chrono & Stat service, Return a pointer to the service if present.
 
SmartIF< IDataProviderSvc > & detSvc () const
 The standard detector data service.
 
SmartIF< IConversionSvc > & detCnvSvc () const
 The standard detector data persistency conversion service.
 
SmartIF< IDataProviderSvc > & eventSvc () const
 The standard event data service.
 
SmartIF< IDataProviderSvc > & evtSvc () const
 shortcut for method eventSvc
 
SmartIF< IConversionSvc > & eventCnvSvc () const
 The standard event data persistency conversion service.
 
SmartIF< IHistogramSvc > & histoSvc () const
 The standard histogram service.
 
SmartIF< INTupleSvc > & ntupleSvc () const
 The standard N tuple service.
 
SmartIF< IRndmGenSvc > & randSvc () const
 The standard RandomGen service, Return a pointer to the service if present.
 
SmartIF< IToolSvc > & toolSvc () const
 The standard ToolSvc service, Return a pointer to the service if present.
 
SmartIF< IExceptionSvc > & exceptionSvc () const
 Get the exception Service.
 
SmartIF< IAlgContextSvc > & contextSvc () const
 get Algorithm Context Service
 
SmartIF< ITimelineSvc > & timelineSvc () const
 
SmartIF< ISvcLocator > & serviceLocator () const override
 The standard service locator.
 
SmartIF< ISvcLocator > & svcLoc () const
 shortcut for method serviceLocator
 
SmartIF< IHiveWhiteBoard > & whiteboard () const
 
SmartIF< IAlgExecStateSvc > & algExecStateSvc () const
 
bool registerContext () const
 register for Algorithm Context Service?
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
SmartIF< IMonitorSvc > & monitorSvc () const
 Access the monitor service.
 
template<class T>
void declareInfo (const std::string &name, const T &var, const std::string &desc) const
 Declare monitoring information.
 
void declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const
 Declare monitoring information (special case)
 
void acceptDHVisitor (IDataHandleVisitor *) const override
 
void registerTool (IAlgTool *tool) const
 
void deregisterTool (IAlgTool *tool) const
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
bool isAsynchronous () const
 
void setAsynchronous (bool value)
 
unsigned int cardinality () const override
 Return the cardinality.
 
const std::vector< std::string > & neededResources () const override
 
AlgExecStateRef execState (const EventContext &ctx) const override
 get the AlgExecStateRef of current algorithm Actually a small wrapper around it, thus the plain object return type
 
std::ostream & toControlFlowExpression (std::ostream &os) const override
 Produce string represention of the control flow expression.
 
- Public Member Functions inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
std::vector< Gaudi::DataHandle * > inputHandles () const override
 
std::vector< Gaudi::DataHandle * > outputHandles () const override
 
virtual const DataObjIDCollextraInputDeps () const override
 
virtual const DataObjIDCollextraOutputDeps () const override
 
void declare (Gaudi::DataHandle &handle) override
 
void renounce (Gaudi::DataHandle &handle) override
 
bool renounceInput (const DataObjID &id) override
 
const DataObjIDCollinputDataObjs () const override
 
const DataObjIDColloutputDataObjs () const override
 
void addDependency (const DataObjID &id, const Gaudi::DataHandle::Mode &mode) override
 
- Public Member Functions inherited from extends< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >, IDataHandleHolder >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Private Member Functions

 GPUCruncher ()
 the default constructor is disabled
 
 GPUCruncher (const GPUCruncher &)
 the copy constructor is disabled
 
GPUCruncheroperator= (const GPUCruncher &)
 the assignement operator is disabled
 
StatusCode gpuExecute (const std::vector< double > &in, std::vector< double > &out) const
 The GPU intensive function.
 

Private Attributes

Gaudi::Property< std::vector< std::string > > m_inpKeys { this, "inpKeys", {}, "" }
 
Gaudi::Property< std::vector< std::string > > m_outKeys { this, "outKeys", {}, "" }
 
Gaudi::Property< double > m_avg_runtime { this, "avgRuntime", 1., "Average runtime of the module." }
 
Gaudi::Property< double > m_var_runtime { this, "varRuntime", 0.01, "Variance of the runtime of the module." }
 
const uint MAX_INPUTS = 40
 
const uint MAX_OUTPUTS = 10
 
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
 
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
 

Static Private Attributes

static CHM m_name_ncopies_map
 

Additional Inherited Members

- Public Attributes inherited from Gaudi::Algorithm
friend AlgorithmManager
 
- Protected Member Functions inherited from Gaudi::Algorithm
std::vector< IAlgTool * > & tools ()
 
bool isInitialized () const override
 Has the Algorithm already been initialized?
 
bool isFinalized () const override
 Has the Algorithm already been finalized?
 
void setIndex (const unsigned int &idx) override
 set instantiation index of Alg
 
bool isReEntrant () const override
 
- Protected Member Functions inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
void initDataHandleHolder ()
 initializes all handles - called by the sysInitialize method of any descendant of this
 
- Protected Member Functions inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 
- Protected Attributes inherited from Gaudi::Algorithm
std::unique_ptr< IDataHandleVisitorm_updateDataHandles
 Hook for for derived classes to provide a custom visitor for data handles.
 
- Protected Attributes inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
DataObjIDColl m_inputDataObjs
 
DataObjIDColl m_outputDataObjs
 

Detailed Description

A test asynchronous algorithm on the GPU.

Definition at line 26 of file GPUCruncher.h.

Member Typedef Documentation

◆ CHM

using GPUCruncher::CHM = tbb::concurrent_hash_map<std::string, unsigned int>

Definition at line 29 of file GPUCruncher.h.

Constructor & Destructor Documentation

◆ GPUCruncher() [1/3]

GPUCruncher::GPUCruncher ( const std::string & name,
ISvcLocator * pSvc )

Definition at line 32 of file GPUCruncher.cpp.

34 : AsynchronousAlgorithm( name, pSvc ) {
35
36 // Register the algo in the static concurrent hash map in order to
37 // monitor the # of copies
38 CHM::accessor name_ninstances;
39 m_name_ncopies_map.insert( name_ninstances, name );
40 name_ninstances->second += 1;
41}
static CHM m_name_ncopies_map
Definition GPUCruncher.h:71
const std::string & name() const override
The identifying name of the algorithm object.

◆ ~GPUCruncher()

GPUCruncher::~GPUCruncher ( )
virtual

virtual & protected desctrustor

Definition at line 43 of file GPUCruncher.cpp.

43 {
44 for ( uint i = 0; i < m_inputHandles.size(); ++i ) delete m_inputHandles[i];
45
46 for ( uint i = 0; i < m_outputHandles.size(); ++i ) delete m_outputHandles[i];
47}
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
Definition GPUCruncher.h:68
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Definition GPUCruncher.h:69

◆ GPUCruncher() [2/3]

GPUCruncher::GPUCruncher ( )
private

the default constructor is disabled

◆ GPUCruncher() [3/3]

GPUCruncher::GPUCruncher ( const GPUCruncher & )
private

the copy constructor is disabled

Member Function Documentation

◆ execute()

StatusCode GPUCruncher::execute ( const EventContext & ctx) const
override

the execution of the algorithm

Definition at line 80 of file GPUCruncher.cpp.

81{
82
83 double crunchtime;
84 std::vector<double> input{};
85 /* This will disappear with a thread safe random number generator service.
86 * Use basic Box-Muller to generate Gaussian random numbers.
87 * The quality is not good for in depth study given that the generator is a
88 * linear congruent.
89 * Throw away basically a free number: we are in a ~~cpu~~ /gpu/ cruncher after all.
90 * The seed is taken from the clock, but we could assign a seed per module to
91 * ensure reproducibility.
92 *
93 * This is not an overkill but rather an exercise towards a thread safe
94 * random number generation.
95 */
96
97 auto getGausRandom = []( double mean, double sigma ) -> double {
98 unsigned int seed = std::clock();
99
100 auto getUnifRandom = []( unsigned int& seed ) -> double {
101 // from "Numerical Recipes"
102 constexpr unsigned int m = 232;
103 constexpr unsigned int a = 1664525;
104 constexpr unsigned int c = 1013904223;
105 seed = ( a * seed + c ) % m;
106 const double unif = double( seed ) / m;
107 return unif;
108 };
109
110 double unif1, unif2;
111 do {
112 unif1 = getUnifRandom( seed );
113 unif2 = getUnifRandom( seed );
114 } while ( unif1 < std::numeric_limits<double>::epsilon() );
115
116 const double normal = sqrt( -2. * log( unif1 ) ) * cos( 2 * M_PI * unif2 );
117
118 return normal * sigma + mean;
119 };
120
121 crunchtime = fabs( getGausRandom( m_avg_runtime, m_var_runtime ) );
122 // Generate input vector
123 input.reserve( 50000 * crunchtime );
124 for ( int i = 0; i < 50000 * crunchtime; ++i ) { input.push_back( getGausRandom( 20.0, 1.0 ) ); }
125 unsigned int crunchtime_ms = 1000 * crunchtime;
126
127 // First figure out what output should be
128 double lower_bound = std::ranges::min( input );
129 double upper_bound = std::ranges::max( input ) * 256;
130 DEBUG_MSG << "Crunching time will be: " << crunchtime_ms << " ms" << endmsg;
131 DEBUG_MSG << "Start event " << ctx.evt() << " in slot " << ctx.slot() << " on pthreadID " << std::hex
132 << pthread_self() << std::dec << endmsg;
133
134 // start timer
135 tbb::tick_count starttbb = tbb::tick_count::now();
136
137 VERBOSE_MSG << "inputs number: " << m_inputHandles.size() << endmsg;
138 for ( auto& inputHandle : m_inputHandles ) {
139 if ( !inputHandle->isValid() ) continue;
140
141 VERBOSE_MSG << "get from TS: " << inputHandle->objKey() << endmsg;
142 DataObject* obj = nullptr;
143 try {
144 obj = inputHandle->get();
145 } catch ( const GaudiException& e ) {
146 error() << "Caught exception with message " << e.what() << " in evt " << ctx.evt() << endmsg;
147 throw;
148 }
149 if ( obj == nullptr ) error() << "A read object was a null pointer." << endmsg;
150 }
151
152 info() << "Crunching..." << endmsg;
153 auto startcrunch = std::chrono::steady_clock::now();
154 std::vector<double> out{};
155 gpuExecute( input, out ).orThrow( "GPU_EXECUTE" );
156 auto endcrunch = std::chrono::steady_clock::now();
157 int total_entries = std::accumulate( out.begin() + 2, out.end(), 0, std::plus{} );
158 bool match =
159 ( out.at( 0 ) == lower_bound ) && ( out.at( 1 ) == upper_bound ) && ( total_entries == 256 * input.size() );
160 info() << "Crunched." << endmsg;
161 ( match ? info() : warning() )
162 << std::format(
163 "GPU Crunch time: {} s. Input length {}, total entries {}. Pass: Lower {}, Upper {}, Entries {} ({} "
164 "missing)",
165 std::chrono::duration_cast<std::chrono::milliseconds>( endcrunch - startcrunch ).count() / 1e3,
166 input.size(), total_entries, out.at( 0 ) == lower_bound, out.at( 1 ) == upper_bound,
167 total_entries == 256 * input.size(), 256 * input.size() - total_entries )
168 << endmsg;
169
170 VERBOSE_MSG << "outputs number: " << m_outputHandles.size() << endmsg;
171 for ( auto& outputHandle : m_outputHandles ) {
172 if ( !outputHandle->isValid() ) continue;
173
174 VERBOSE_MSG << "put to TS: " << outputHandle->objKey() << endmsg;
175 try {
176 outputHandle->put( std::make_unique<DataObject>() );
177 } catch ( const GaudiException& e ) {
178 error() << "Caught exception with message " << e.what() << " in evt " << ctx.evt() << endmsg;
179 throw;
180 }
181 }
182
183 tbb::tick_count endtbb = tbb::tick_count::now();
184 const double actualRuntime = ( endtbb - starttbb ).seconds();
185
186 DEBUG_MSG << "Finish event " << ctx.evt() << " in " << int( 1000 * actualRuntime ) << " ms" << endmsg;
187
188 DEBUG_MSG << "Timing: ExpectedCrunchtime= " << crunchtime_ms
189 << " ms. ActualTotalRuntime= " << int( 1000 * actualRuntime )
190 << " ms. Ratio= " << crunchtime / actualRuntime << endmsg;
191
192 return StatusCode::SUCCESS;
193}
#define DEBUG_MSG
#define VERBOSE_MSG
HepRndm::Engine< DRand48Engine > e3
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode gpuExecute(const std::vector< double > &in, std::vector< double > &out) const
The GPU intensive function.
Gaudi::Property< double > m_var_runtime
Definition GPUCruncher.h:62
Gaudi::Property< double > m_avg_runtime
Definition GPUCruncher.h:61
const char * what() const override
method from std::exception
const StatusCode & orThrow(std::string_view message, std::string_view tag) const
Throw a GaudiException in case of failures.
Definition StatusCode.h:206
constexpr static const auto SUCCESS
Definition StatusCode.h:99
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Definition Counters.h:34
constexpr double m
constexpr auto size(const T &, Args &&...) noexcept

◆ finalize()

StatusCode GPUCruncher::finalize ( )
override

the finalization of the algorithm

Definition at line 197 of file GPUCruncher.cpp.

198{
199 MsgStream log( msgSvc(), name() );
200
201 unsigned int ninstances;
202
203 {
204 CHM::const_accessor const_name_ninstances;
205 m_name_ncopies_map.find( const_name_ninstances, name() );
206 ninstances = const_name_ninstances->second;
207 }
208
209 constexpr double s2ms = 1000.;
210 // do not show repetitions
211 if ( ninstances != 0 ) {
212 info() << "Summary: name= " << name() << "\t avg_runtime= " << m_avg_runtime * s2ms << "\t n_clones= " << ninstances
213 << endmsg;
214
215 CHM::accessor name_ninstances;
216 m_name_ncopies_map.find( name_ninstances, name() );
217 name_ninstances->second = 0;
218 }
219
220 return Algorithm::finalize();
221}
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition Algorithm.h:181

◆ get_runtime()

double GPUCruncher::get_runtime ( ) const
inline

Definition at line 40 of file GPUCruncher.h.

40{ return m_avg_runtime; }

◆ gpuExecute()

StatusCode GPUCruncher::gpuExecute ( const std::vector< double > & in,
std::vector< double > & out ) const
private

The GPU intensive function.

◆ initialize()

StatusCode GPUCruncher::initialize ( )
override

Its initialization.

Definition at line 49 of file GPUCruncher.cpp.

49 {
50 auto sc = Algorithm::initialize();
51 if ( !sc ) return sc;
52
53 // This is a bit ugly. There is no way to declare a vector of DataObjectHandles, so
54 // we need to wait until initialize when we've read in the input and output key
55 // properties, and know their size, and then turn them
56 // into Handles and register them with the framework by calling declareProperty. We
57 // could call declareInput/declareOutput on them too.
58
59 int i = 0;
60 for ( auto k : m_inpKeys ) {
61 DEBUG_MSG << "adding input key " << k << endmsg;
62 m_inputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Reader, this ) );
63 declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
64 i++;
65 }
66
67 i = 0;
68 for ( auto k : m_outKeys ) {
69 DEBUG_MSG << "adding output key " << k << endmsg;
70 m_outputHandles.push_back( new DataObjectHandle<DataObject>( k, Gaudi::DataHandle::Writer, this ) );
71 declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
72 i++;
73 }
74
75 return sc;
76}
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition GPUCruncher.h:58
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition GPUCruncher.h:59
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition Algorithm.h:286
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175

◆ isClonable()

bool GPUCruncher::isClonable ( ) const
inlineoverride

Definition at line 31 of file GPUCruncher.h.

31{ return true; }

◆ operator=()

GPUCruncher & GPUCruncher::operator= ( const GPUCruncher & )
private

the assignement operator is disabled

Member Data Documentation

◆ m_avg_runtime

Gaudi::Property<double> GPUCruncher::m_avg_runtime { this, "avgRuntime", 1., "Average runtime of the module." }
private

Definition at line 61 of file GPUCruncher.h.

61{ this, "avgRuntime", 1., "Average runtime of the module." };

◆ m_inpKeys

Gaudi::Property<std::vector<std::string> > GPUCruncher::m_inpKeys { this, "inpKeys", {}, "" }
private

Definition at line 58 of file GPUCruncher.h.

58{ this, "inpKeys", {}, "" };

◆ m_inputHandles

std::vector<DataObjectHandle<DataObject>*> GPUCruncher::m_inputHandles
private

Definition at line 68 of file GPUCruncher.h.

◆ m_name_ncopies_map

GPUCruncher::CHM GPUCruncher::m_name_ncopies_map
staticprivate

Definition at line 71 of file GPUCruncher.h.

◆ m_outKeys

Gaudi::Property<std::vector<std::string> > GPUCruncher::m_outKeys { this, "outKeys", {}, "" }
private

Definition at line 59 of file GPUCruncher.h.

59{ this, "outKeys", {}, "" };

◆ m_outputHandles

std::vector<DataObjectHandle<DataObject>*> GPUCruncher::m_outputHandles
private

Definition at line 69 of file GPUCruncher.h.

◆ m_var_runtime

Gaudi::Property<double> GPUCruncher::m_var_runtime { this, "varRuntime", 0.01, "Variance of the runtime of the module." }
private

Definition at line 62 of file GPUCruncher.h.

62{ this, "varRuntime", 0.01, "Variance of the runtime of the module." };

◆ MAX_INPUTS

const uint GPUCruncher::MAX_INPUTS = 40
private

Definition at line 65 of file GPUCruncher.h.

◆ MAX_OUTPUTS

const uint GPUCruncher::MAX_OUTPUTS = 10
private

Definition at line 66 of file GPUCruncher.h.


The documentation for this class was generated from the following files: