16 #include <fmt/format.h>
17 #include <sys/resource.h>
18 #include <sys/times.h>
19 #include <tbb/tick_count.h>
26 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
27 #define DEBUG_MSG ON_DEBUG debug()
29 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
30 #define VERBOSE_MSG ON_VERBOSE verbose()
36 : AsynchronousAlgorithm(
name, pSvc ) {
40 CHM::accessor name_ninstances;
42 name_ninstances->second += 1;
55 pinned = Gaudi::CUDA::get_pinned_memory_resource();
88 std::pmr::vector<double> input( pinned );
89 if ( m_local_rndm_gen ) {
102 auto getGausRandom = [](
double mean,
double sigma ) ->
double {
105 auto getUnifRandom = [](
unsigned int&
seed ) ->
double {
107 constexpr
unsigned int m = 232;
108 constexpr
unsigned int a = 1664525;
109 constexpr
unsigned int c = 1013904223;
111 const double unif = double(
seed ) /
m;
117 unif1 = getUnifRandom(
seed );
118 unif2 = getUnifRandom(
seed );
121 const double normal =
sqrt( -2. *
log( unif1 ) ) * cos( 2 * M_PI * unif2 );
123 return normal * sigma + mean;
126 crunchtime = fabs( getGausRandom( m_avg_runtime, m_var_runtime ) );
128 input.reserve( 40000 * crunchtime );
129 for (
int i = 0; i < 40000 * crunchtime; ++i ) { input.push_back( getGausRandom( 10.0, 1.0 ) ); }
136 for (
int i = 0; i < 2000 * crunchtime; ++i ) { input.push_back( rndmgaus() ); }
138 unsigned int crunchtime_ms = 1000 * crunchtime;
140 DEBUG_MSG <<
"Crunching time will be: " << crunchtime_ms <<
" ms" <<
endmsg;
145 tbb::tick_count starttbb = tbb::tick_count::now();
148 for (
auto& inputHandle : m_inputHandles ) {
149 if ( !inputHandle->isValid() )
continue;
153 obj = inputHandle->get();
154 if ( obj ==
nullptr ) error() <<
"A read object was a null pointer." <<
endmsg;
158 info() <<
"Crunching..." <<
endmsg;
161 gpuExecute( input,
out ).orThrow(
"GPU_EXECUTE" );
163 info() <<
"Crunched." <<
endmsg;
164 fmt::print(
"{} GPU Crunch time: {}. Input length {}, output length {}.\n",
name(),
166 std::chrono::duration_cast<std::chrono::milliseconds>( endcrunch - startcrunch ).count() / 1
e3,
"s" ),
167 input.size(),
out.size() );
170 for (
auto& outputHandle : m_outputHandles ) {
171 if ( !outputHandle->isValid() )
continue;
174 outputHandle->put( std::make_unique<DataObject>() );
177 tbb::tick_count endtbb = tbb::tick_count::now();
178 const double actualRuntime = ( endtbb - starttbb ).seconds();
180 DEBUG_MSG <<
"Finish event " <<
ctx.evt() <<
" in " << int( 1000 * actualRuntime ) <<
" ms" <<
endmsg;
182 DEBUG_MSG <<
"Timing: ExpectedCrunchtime= " << crunchtime_ms
183 <<
" ms. ActualTotalRuntime= " << int( 1000 * actualRuntime )
184 <<
" ms. Ratio= " << crunchtime / actualRuntime <<
endmsg;
195 unsigned int ninstances;
198 CHM::const_accessor const_name_ninstances;
200 ninstances = const_name_ninstances->second;
203 constexpr
double s2ms = 1000.;
205 if ( ninstances != 0 ) {
206 info() <<
"Summary: name= " <<
name() <<
"\t avg_runtime= " <<
m_avg_runtime * s2ms <<
"\t n_clones= " << ninstances
209 CHM::accessor name_ninstances;
211 name_ninstances->second = 0;