ATLAS Offline Software
Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
CaloGPUTimed Class Reference

Base class to provide some basic common infrastructure for timing measurements... More...

#include <CaloGPUTimed.h>

Inheritance diagram for CaloGPUTimed:
Collaboration diagram for CaloGPUTimed:

Protected Member Functions

template<class T >
 CaloGPUTimed (T *ptr)
 
void record_times (const size_t event_num, const std::vector< size_t > &times) const
 
template<class ... Args>
void record_times (const size_t event_num, const size_t &value) const
 
template<class ... Args>
void record_times (const size_t event_num, const size_t &value, Args &&... args) const
 
void print_times (const std::string &header, const size_t time_size) const
 

Protected Attributes

std::mutex m_timeMutex
 Mutex that is locked when recording times. More...
 
std::vector< size_t > m_times ATLAS_THREAD_SAFE
 Vector to hold execution times to be recorded if necessary. More...
 
std::vector< size_t > m_eventNumbers ATLAS_THREAD_SAFE
 Vector to hold the event numbers to be recorded if necessary. More...
 
Gaudi::Property< bool > m_measureTimes
 If true, times are recorded to the file given by m_timeFileName. More...
 
Gaudi::Property< std::string > m_timeFileName
 File to which times should be saved. More...
 

Private Member Functions

void record_times_helper (size_t) const
 
void record_times_helper (size_t index, size_t t) const
 
template<class ... Args>
void record_times_helper (size_t index, size_t t, Args &&... args) const
 

Detailed Description

Base class to provide some basic common infrastructure for timing measurements...

Author
Nuno Fernandes nuno..nosp@m.dos..nosp@m.santo.nosp@m.s.fe.nosp@m.rnand.nosp@m.es@c.nosp@m.ern.c.nosp@m.h
Date
01 June 2022

Definition at line 24 of file CaloGPUTimed.h.

Constructor & Destructor Documentation

◆ CaloGPUTimed()

template<class T >
CaloGPUTimed::CaloGPUTimed ( T *  ptr)
inlineprotected

Definition at line 55 of file CaloGPUTimed.h.

55  :
56  m_measureTimes(ptr, "MeasureTimes", false, "Save time measurements"),
57  m_timeFileName(ptr, "TimeFileOutput", "times.txt", "File to which time measurements should be saved")
58  {
59  }

Member Function Documentation

◆ print_times()

void CaloGPUTimed::print_times ( const std::string &  header,
const size_t  time_size 
) const
inlineprotected

Definition at line 138 of file CaloGPUTimed.h.

139  {
140  if (m_timeFileName.size() == 0)
141  {
142  return;
143  }
144 
145  std::vector<size_t> indices(m_eventNumbers.size());
146  std::iota(indices.begin(), indices.end(), 0);
147  std::sort(indices.begin(), indices.end(), [&](size_t a, size_t b)
148  {
149  return m_eventNumbers[a] < m_eventNumbers[b];
150  }
151  );
152  std::ofstream out(m_timeFileName);
153 
154  out << "Event_Number Total " << header << "\n";
155 
156  for (const size_t idx : indices)
157  {
158  out << m_eventNumbers[idx] << " ";
159 
160  size_t total = 0;
161 
162  for (size_t i = 0; i < time_size; ++i)
163  {
164  total += m_times[idx * time_size + i];
165  }
166 
167  out << total << " ";
168 
169  for (size_t i = 0; i < time_size; ++i)
170  {
171  out << m_times[idx * time_size + i] << " ";
172  }
173  out << "\n";
174  }
175 
176  out << std::endl;
177 
178  out.close();
179  }

◆ record_times() [1/3]

template<class ... Args>
void CaloGPUTimed::record_times ( const size_t  event_num,
const size_t &  value 
) const
inlineprotected

Definition at line 102 of file CaloGPUTimed.h.

103  {
104  const size_t time_size = 1;
105 
106  size_t old_size;
107 
108  //Scope just for the lock_guard.
109  {
110  std::lock_guard<std::mutex> lock_guard(m_timeMutex);
111  old_size = m_times.size();
112  m_times.resize(old_size + time_size);
113  m_eventNumbers.push_back(event_num);
114  }
115 
116  record_times_helper(old_size, value);
117  }

◆ record_times() [2/3]

template<class ... Args>
void CaloGPUTimed::record_times ( const size_t  event_num,
const size_t &  value,
Args &&...  args 
) const
inlineprotected

Definition at line 120 of file CaloGPUTimed.h.

121  {
122  const size_t time_size = sizeof...(args) + 1;
123 
124  size_t old_size;
125 
126  //Scope just for the lock_guard.
127  {
128  std::lock_guard<std::mutex> lock_guard(m_timeMutex);
129  old_size = m_times.size();
130  m_times.resize(old_size + time_size);
131  m_eventNumbers.push_back(event_num);
132  }
133 
134  record_times_helper(old_size, value, std::forward<Args>(args)...);
135 
136  }

◆ record_times() [3/3]

void CaloGPUTimed::record_times ( const size_t  event_num,
const std::vector< size_t > &  times 
) const
inlineprotected

Definition at line 84 of file CaloGPUTimed.h.

85  {
86  size_t old_size;
87  //Scope just for the lock_guard.
88  {
89  std::lock_guard<std::mutex> lock_guard(m_timeMutex);
90  old_size = m_times.size();
91  m_times.resize(old_size + times.size());
92  m_eventNumbers.push_back(event_num);
93  }
94 
95  for (size_t i = 0; i < times.size(); ++i)
96  {
97  m_times[old_size + i] = times[i];
98  }
99  }

◆ record_times_helper() [1/3]

void CaloGPUTimed::record_times_helper ( size_t  index,
size_t  t 
) const
inlineprivate

Definition at line 70 of file CaloGPUTimed.h.

71  {
72  m_times[index] = t;
73  }

◆ record_times_helper() [2/3]

template<class ... Args>
void CaloGPUTimed::record_times_helper ( size_t  index,
size_t  t,
Args &&...  args 
) const
inlineprivate

Definition at line 76 of file CaloGPUTimed.h.

77  {
79  record_times_helper(index + 1, std::forward<Args>(args)...);
80  }

◆ record_times_helper() [3/3]

void CaloGPUTimed::record_times_helper ( size_t  ) const
inlineprivate

Definition at line 64 of file CaloGPUTimed.h.

65  {
66  //Do nothing
67  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/2]

std::vector<size_t> m_times CaloGPUTimed::ATLAS_THREAD_SAFE
mutableprotected

Vector to hold execution times to be recorded if necessary.

Definition at line 35 of file CaloGPUTimed.h.

◆ ATLAS_THREAD_SAFE [2/2]

std::vector<size_t> m_eventNumbers CaloGPUTimed::ATLAS_THREAD_SAFE
mutableprotected

Vector to hold the event numbers to be recorded if necessary.

Definition at line 40 of file CaloGPUTimed.h.

◆ m_measureTimes

Gaudi::Property<bool> CaloGPUTimed::m_measureTimes
protected

If true, times are recorded to the file given by m_timeFileName.

Defaults to false.

Definition at line 46 of file CaloGPUTimed.h.

◆ m_timeFileName

Gaudi::Property<std::string> CaloGPUTimed::m_timeFileName
protected

File to which times should be saved.

Definition at line 50 of file CaloGPUTimed.h.

◆ m_timeMutex

std::mutex CaloGPUTimed::m_timeMutex
mutableprotected

Mutex that is locked when recording times.

Definition at line 32 of file CaloGPUTimed.h.


The documentation for this class was generated from the following file:
header
Definition: hcg.cxx:526
index
Definition: index.py:1
Trk::indices
std::pair< long int, long int > indices
Definition: AlSymMatBase.h:24
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CaloGPUTimed::m_timeFileName
Gaudi::Property< std::string > m_timeFileName
File to which times should be saved.
Definition: CaloGPUTimed.h:50
athena.value
value
Definition: athena.py:122
CaloGPUTimed::record_times_helper
void record_times_helper(size_t) const
Definition: CaloGPUTimed.h:64
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
lumiFormat.i
int i
Definition: lumiFormat.py:92
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CaloGPUTimed::m_timeMutex
std::mutex m_timeMutex
Mutex that is locked when recording times.
Definition: CaloGPUTimed.h:32
DeMoScan.index
string index
Definition: DeMoScan.py:362
a
TList * a
Definition: liststreamerinfos.cxx:10
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
CaloGPUTimed::m_measureTimes
Gaudi::Property< bool > m_measureTimes
If true, times are recorded to the file given by m_timeFileName.
Definition: CaloGPUTimed.h:46
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
plot_times.times
def times(fn)
Definition: plot_times.py:11