timemory  3.2.1
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::component::papi_array< MaxNumEvents > Struct Template Reference

#include "timemory/components/papi/papi_array.hpp"

+ Collaboration diagram for tim::component::papi_array< MaxNumEvents >:

Public Types

using size_type = size_t
 
using event_list = std::vector< int >
 
using value_type = std::array< long long, MaxNumEvents >
 
using entry_type = typename value_type::value_type
 
using this_type = papi_array< MaxNumEvents >
 
using base_type = base< this_type, value_type >
 
using storage_type = typename base_type::storage_type
 
using tracker_type = policy::instance_tracker< this_type >
 
using get_initializer_t = std::function< event_list()>
 
using common_type = void
 
template<typename Tp >
using array_t = std::array< Tp, MaxNumEvents >
 

Public Member Functions

 papi_array ()
 
 ~papi_array ()=default
 
 papi_array (const papi_array &)=default
 
 papi_array (papi_array &&) noexcept=default
 
papi_arrayoperator= (const papi_array &)=default
 
papi_arrayoperator= (papi_array &&) noexcept=default
 
size_t size ()
 
template<typename Tp = double>
std::vector< Tp > get () const
 
void sample ()
 
void start ()
 
void stop ()
 
this_typeoperator+= (const this_type &rhs)
 
this_typeoperator-= (const this_type &rhs)
 
entry_type get_display (int evt_type) const
 
template<typename Archive >
void load (Archive &ar, const unsigned int)
 
template<typename Archive >
void save (Archive &ar, const unsigned int) const
 
std::vector< std::string > label_array () const
 
std::vector< std::string > description_array () const
 
std::vector< std::string > display_unit_array () const
 
std::vector< int64_t > unit_array () const
 
string_t get_display () const
 

Static Public Member Functions

static auto & get_initializer ()
 
static void configure ()
 
static void initialize ()
 
static void thread_finalize ()
 
static void finalize ()
 
static value_type record ()
 
static std::string label ()
 
static std::string description ()
 

Static Public Attributes

static const short precision = 3
 
static const short width = 8
 

Protected Attributes

event_list events
 

Friends

struct operation::record< this_type >
 
struct operation::start< this_type >
 
struct operation::stop< this_type >
 
struct operation::set_started< this_type >
 
struct operation::set_stopped< this_type >
 
class impl::storage< this_type, trait::uses_value_storage< this_type, value_type >::value >
 
std::ostream & operator<< (std::ostream &os, const this_type &obj)
 

Detailed Description

template<size_t MaxNumEvents>
struct tim::component::papi_array< MaxNumEvents >

Definition at line 47 of file papi_array.hpp.

Member Typedef Documentation

◆ array_t

template<size_t MaxNumEvents>
template<typename Tp >
using tim::component::papi_array< MaxNumEvents >::array_t = std::array<Tp, MaxNumEvents>

Definition at line 67 of file papi_array.hpp.

◆ base_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::base_type = base<this_type, value_type>

Definition at line 57 of file papi_array.hpp.

◆ common_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::common_type = void

Definition at line 61 of file papi_array.hpp.

◆ entry_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::entry_type = typename value_type::value_type

Definition at line 55 of file papi_array.hpp.

◆ event_list

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::event_list = std::vector<int>

Definition at line 53 of file papi_array.hpp.

◆ get_initializer_t

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::get_initializer_t = std::function<event_list()>

Definition at line 60 of file papi_array.hpp.

◆ size_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::size_type = size_t

Definition at line 52 of file papi_array.hpp.

◆ storage_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::storage_type = typename base_type::storage_type

Definition at line 58 of file papi_array.hpp.

◆ this_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::this_type = papi_array<MaxNumEvents>

Definition at line 56 of file papi_array.hpp.

◆ tracker_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::tracker_type = policy::instance_tracker<this_type>

Definition at line 59 of file papi_array.hpp.

◆ value_type

template<size_t MaxNumEvents>
using tim::component::papi_array< MaxNumEvents >::value_type = std::array<long long, MaxNumEvents>

Definition at line 54 of file papi_array.hpp.

Constructor & Destructor Documentation

◆ papi_array() [1/3]

template<size_t MaxNumEvents>
tim::component::papi_array< MaxNumEvents >::papi_array ( )
inline

Definition at line 93 of file papi_array.hpp.

93 { events = get_events<common_type>(); }

References tim::component::papi_array< MaxNumEvents >::events.

◆ ~papi_array()

template<size_t MaxNumEvents>
tim::component::papi_array< MaxNumEvents >::~papi_array ( )
default

◆ papi_array() [2/3]

template<size_t MaxNumEvents>
tim::component::papi_array< MaxNumEvents >::papi_array ( const papi_array< MaxNumEvents > &  )
default

◆ papi_array() [3/3]

template<size_t MaxNumEvents>
tim::component::papi_array< MaxNumEvents >::papi_array ( papi_array< MaxNumEvents > &&  )
defaultnoexcept

Member Function Documentation

◆ configure()

template<size_t MaxNumEvents>
static void tim::component::papi_array< MaxNumEvents >::configure ( )
inlinestatic

Definition at line 78 of file papi_array.hpp.

79  {
80  if(!is_configured<common_type>())
81  papi_common::initialize<common_type>();
82  }

Referenced by tim::component::papi_array< MaxNumEvents >::initialize(), tim::component::papi_array< MaxNumEvents >::sample(), and tim::component::papi_array< MaxNumEvents >::start().

◆ description()

template<size_t MaxNumEvents>
static std::string tim::component::papi_array< MaxNumEvents >::description ( )
inlinestatic

Definition at line 218 of file papi_array.hpp.

218 { return "Fixed-size array of PAPI HW counters"; }

◆ description_array()

template<size_t MaxNumEvents>
std::vector<std::string> tim::component::papi_array< MaxNumEvents >::description_array ( ) const
inline

Definition at line 288 of file papi_array.hpp.

289  {
290  std::vector<std::string> arr(events.size());
291  for(size_type i = 0; i < events.size(); ++i)
292  arr[i] = papi::get_event_info(events[i]).long_descr;
293  return arr;
294  }

References tim::component::papi_array< MaxNumEvents >::events.

◆ display_unit_array()

template<size_t MaxNumEvents>
std::vector<std::string> tim::component::papi_array< MaxNumEvents >::display_unit_array ( ) const
inline

Definition at line 299 of file papi_array.hpp.

300  {
301  std::vector<std::string> arr(events.size());
302  for(size_type i = 0; i < events.size(); ++i)
303  arr[i] = papi::get_event_info(events[i]).units;
304  return arr;
305  }

References tim::component::papi_array< MaxNumEvents >::events.

◆ finalize()

template<size_t MaxNumEvents>
static void tim::component::papi_array< MaxNumEvents >::finalize ( )
inlinestatic

Definition at line 89 of file papi_array.hpp.

89 { papi_common::finalize<common_type>(); }

◆ get()

template<size_t MaxNumEvents>
template<typename Tp = double>
std::vector<Tp> tim::component::papi_array< MaxNumEvents >::get ( ) const
inline

Definition at line 120 of file papi_array.hpp.

121  {
122  std::vector<Tp> values;
123  auto& _data = load();
124  values.reserve(_data.size());
125  for(auto& itr : _data)
126  values.emplace_back(itr);
127  values.resize(events.size());
128  return values;
129  }

References tim::component::papi_array< MaxNumEvents >::events, and tim::component::base< papi_array< MaxNumEvents >, std::array< long long, MaxNumEvents > >::load().

◆ get_display() [1/2]

template<size_t MaxNumEvents>
string_t tim::component::papi_array< MaxNumEvents >::get_display ( ) const
inline

Definition at line 320 of file papi_array.hpp.

321  {
322  if(events.size() == 0)
323  return "";
324  auto val = load();
325  auto _get_display = [&](std::ostream& os, size_type idx) {
326  auto _obj_value = val[idx];
327  auto _evt_type = events[idx];
328  string_t _label = papi::get_event_info(_evt_type).short_descr;
329  string_t _disp = papi::get_event_info(_evt_type).units;
330  auto _prec = base_type::get_precision();
331  auto _width = base_type::get_width();
332  auto _flags = base_type::get_format_flags();
333 
334  std::stringstream ss;
335  std::stringstream ssv;
336  std::stringstream ssi;
337  ssv.setf(_flags);
338  ssv << std::setw(_width) << std::setprecision(_prec) << _obj_value;
339  if(!_disp.empty())
340  ssv << " " << _disp;
341  if(!_label.empty())
342  ssi << " " << _label;
343  ss << ssv.str() << ssi.str();
344  os << ss.str();
345  };
346 
347  std::stringstream ss;
348  for(size_type i = 0; i < events.size(); ++i)
349  {
350  _get_display(ss, i);
351  if(i + 1 < events.size())
352  ss << ", ";
353  }
354  return ss.str();
355  }
std::string string_t
Definition: library.cpp:56
static short get_precision()
static short get_width()
static fmtflags get_format_flags()

References tim::component::papi_array< MaxNumEvents >::events, tim::component::base< Tp, Value >::get_format_flags(), tim::component::base< Tp, Value >::get_precision(), tim::component::base< Tp, Value >::get_width(), and tim::component::base< papi_array< MaxNumEvents >, std::array< long long, MaxNumEvents > >::load().

Referenced by tim::component::papi_array< MaxNumEvents >::save().

◆ get_display() [2/2]

template<size_t MaxNumEvents>
entry_type tim::component::papi_array< MaxNumEvents >::get_display ( int  evt_type) const
inline

Definition at line 220 of file papi_array.hpp.

221  {
222  return accum.at(evt_type);
223  }

◆ get_initializer()

template<size_t MaxNumEvents>
static auto& tim::component::papi_array< MaxNumEvents >::get_initializer ( )
inlinestatic

Definition at line 77 of file papi_array.hpp.

77 { return papi_common::get_initializer<common_type>(); }

◆ initialize()

template<size_t MaxNumEvents>
static void tim::component::papi_array< MaxNumEvents >::initialize ( )
inlinestatic

Definition at line 83 of file papi_array.hpp.

83 { configure(); }

References tim::component::papi_array< MaxNumEvents >::configure().

◆ label()

template<size_t MaxNumEvents>
static std::string tim::component::papi_array< MaxNumEvents >::label ( )
inlinestatic

Definition at line 211 of file papi_array.hpp.

212  {
213  return "papi_array" + std::to_string((event_set<common_type>() < 0)
214  ? 0
215  : event_set<common_type>());
216  }

◆ label_array()

template<size_t MaxNumEvents>
std::vector<std::string> tim::component::papi_array< MaxNumEvents >::label_array ( ) const
inline

Definition at line 252 of file papi_array.hpp.

253  {
254  std::vector<std::string> arr(events.size());
255  for(size_type i = 0; i < events.size(); ++i)
256  arr[i] = papi::get_event_info(events[i]).short_descr;
257 
258  for(auto& itr : arr)
259  {
260  size_t n = std::string::npos;
261  while((n = itr.find("L/S")) != std::string::npos)
262  itr.replace(n, 3, "Loads_Stores");
263  }
264 
265  for(auto& itr : arr)
266  {
267  size_t n = std::string::npos;
268  while((n = itr.find('/')) != std::string::npos)
269  itr.replace(n, 1, "_per_");
270  }
271 
272  for(auto& itr : arr)
273  {
274  size_t n = std::string::npos;
275  while((n = itr.find(' ')) != std::string::npos)
276  itr.replace(n, 1, "_");
277 
278  while((n = itr.find("__")) != std::string::npos)
279  itr.replace(n, 2, "_");
280  }
281 
282  return arr;
283  }

References tim::component::papi_array< MaxNumEvents >::events.

◆ load()

template<size_t MaxNumEvents>
template<typename Archive >
void tim::component::papi_array< MaxNumEvents >::load ( Archive &  ar,
const unsigned int   
)
inline

Definition at line 229 of file papi_array.hpp.

230  {
231  ar(cereal::make_nvp("laps", laps), cereal::make_nvp("value", value),
232  cereal::make_nvp("accum", accum), cereal::make_nvp("events", events));
233  }

References tim::component::papi_array< MaxNumEvents >::events, and tim::component::base< papi_array< MaxNumEvents >, std::array< long long, MaxNumEvents > >::laps.

◆ operator+=()

template<size_t MaxNumEvents>
this_type& tim::component::papi_array< MaxNumEvents >::operator+= ( const this_type rhs)
inline

Definition at line 170 of file papi_array.hpp.

171  {
172  for(size_type i = 0; i < events.size(); ++i)
173  accum[i] += rhs.accum[i];
174  for(size_type i = 0; i < events.size(); ++i)
175  value[i] += rhs.value[i];
176  return *this;
177  }

References tim::component::papi_array< MaxNumEvents >::events.

◆ operator-=()

template<size_t MaxNumEvents>
this_type& tim::component::papi_array< MaxNumEvents >::operator-= ( const this_type rhs)
inline

Definition at line 181 of file papi_array.hpp.

182  {
183  for(size_type i = 0; i < events.size(); ++i)
184  accum[i] -= rhs.accum[i];
185  for(size_type i = 0; i < events.size(); ++i)
186  value[i] -= rhs.value[i];
187  return *this;
188  }

◆ operator=() [1/2]

template<size_t MaxNumEvents>
papi_array& tim::component::papi_array< MaxNumEvents >::operator= ( const papi_array< MaxNumEvents > &  )
default

◆ operator=() [2/2]

template<size_t MaxNumEvents>
papi_array& tim::component::papi_array< MaxNumEvents >::operator= ( papi_array< MaxNumEvents > &&  )
defaultnoexcept

◆ record()

template<size_t MaxNumEvents>
static value_type tim::component::papi_array< MaxNumEvents >::record ( )
inlinestatic

Definition at line 108 of file papi_array.hpp.

109  {
110  value_type read_value{};
111  read_value.fill(0);
112  if(is_configured<common_type>())
113  papi::read(event_set<common_type>(), read_value.data());
114  return read_value;
115  }
std::array< long long, MaxNumEvents > value_type
Definition: papi_array.hpp:54

Referenced by tim::component::papi_array< MaxNumEvents >::sample(), tim::component::papi_array< MaxNumEvents >::start(), and tim::component::papi_array< MaxNumEvents >::stop().

◆ sample()

template<size_t MaxNumEvents>
void tim::component::papi_array< MaxNumEvents >::sample ( )
inline

Definition at line 134 of file papi_array.hpp.

135  {
136  if(tracker_type::get_thread_started() == 0)
137  configure();
138  if(events.empty())
139  events = get_events<common_type>();
140 
142  value = record();
143  }
void start(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:298
static value_type record()
Definition: papi_array.hpp:108

References tim::component::papi_array< MaxNumEvents >::configure(), tim::component::papi_array< MaxNumEvents >::events, tim::component::papi_array< MaxNumEvents >::record(), and tim::invoke::start().

◆ save()

template<size_t MaxNumEvents>
template<typename Archive >
void tim::component::papi_array< MaxNumEvents >::save ( Archive &  ar,
const unsigned int   
) const
inline

Definition at line 239 of file papi_array.hpp.

240  {
241  array_t<double> _disp;
242  for(size_type i = 0; i < events.size(); ++i)
243  _disp[i] = get_display(i);
244  ar(cereal::make_nvp("laps", laps), cereal::make_nvp("repr_data", _disp),
245  cereal::make_nvp("value", value), cereal::make_nvp("accum", accum),
246  cereal::make_nvp("display", _disp), cereal::make_nvp("events", events));
247  }
string_t get_display() const
Definition: papi_array.hpp:320

References tim::component::papi_array< MaxNumEvents >::events, tim::component::papi_array< MaxNumEvents >::get_display(), and tim::component::base< papi_array< MaxNumEvents >, std::array< long long, MaxNumEvents > >::laps.

◆ size()

template<size_t MaxNumEvents>
size_t tim::component::papi_array< MaxNumEvents >::size ( )
inline

Definition at line 104 of file papi_array.hpp.

104 { return events.size(); }

References tim::component::papi_array< MaxNumEvents >::events.

◆ start()

template<size_t MaxNumEvents>
void tim::component::papi_array< MaxNumEvents >::start ( )
inline

Definition at line 148 of file papi_array.hpp.

149  {
150  if(tracker_type::get_thread_started() == 0 || events.size() == 0)
151  configure();
152 
153  events = get_events<common_type>();
155  value = record();
156  }

References tim::component::papi_array< MaxNumEvents >::configure(), tim::component::papi_array< MaxNumEvents >::events, tim::component::papi_array< MaxNumEvents >::record(), and tim::invoke::start().

◆ stop()

template<size_t MaxNumEvents>
void tim::component::papi_array< MaxNumEvents >::stop ( )
inline

Definition at line 160 of file papi_array.hpp.

161  {
163  using namespace tim::component::operators;
164  value = (record() - value);
165  accum += value;
166  }
void stop(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:368

References tim::component::papi_array< MaxNumEvents >::record(), and tim::invoke::stop().

◆ thread_finalize()

template<size_t MaxNumEvents>
static void tim::component::papi_array< MaxNumEvents >::thread_finalize ( )
inlinestatic

Definition at line 84 of file papi_array.hpp.

85  {
86  papi_common::finalize<common_type>();
88  }

References tim::component::papi_common::finalize_papi().

◆ unit_array()

template<size_t MaxNumEvents>
std::vector<int64_t> tim::component::papi_array< MaxNumEvents >::unit_array ( ) const
inline

Definition at line 310 of file papi_array.hpp.

311  {
312  std::vector<int64_t> arr(events.size());
313  for(size_type i = 0; i < events.size(); ++i)
314  arr[i] = 1;
315  return arr;
316  }

References tim::component::papi_array< MaxNumEvents >::events.

Friends And Related Function Documentation

◆ impl::storage< this_type, trait::uses_value_storage< this_type, value_type >::value >

template<size_t MaxNumEvents>
friend class impl::storage< this_type, trait::uses_value_storage< this_type, value_type >::value >
friend

Definition at line 181 of file papi_array.hpp.

◆ operation::record< this_type >

template<size_t MaxNumEvents>
friend struct operation::record< this_type >
friend

Definition at line 64 of file papi_array.hpp.

◆ operation::set_started< this_type >

template<size_t MaxNumEvents>
friend struct operation::set_started< this_type >
friend

Definition at line 64 of file papi_array.hpp.

◆ operation::set_stopped< this_type >

template<size_t MaxNumEvents>
friend struct operation::set_stopped< this_type >
friend

Definition at line 64 of file papi_array.hpp.

◆ operation::start< this_type >

template<size_t MaxNumEvents>
friend struct operation::start< this_type >
friend

Definition at line 64 of file papi_array.hpp.

◆ operation::stop< this_type >

template<size_t MaxNumEvents>
friend struct operation::stop< this_type >
friend

Definition at line 64 of file papi_array.hpp.

◆ operator<<

template<size_t MaxNumEvents>
std::ostream& operator<< ( std::ostream &  os,
const this_type obj 
)
friend

Definition at line 359 of file papi_array.hpp.

360  {
361  if(obj.events.size() == 0)
362  return os;
363  // output the metrics
364  auto _value = obj.get_display();
365  auto _label = this_type::get_label();
366  auto _disp = this_type::display_unit();
367  auto _prec = this_type::get_precision();
368  auto _width = this_type::get_width();
369  auto _flags = this_type::get_format_flags();
370 
371  std::stringstream ss_value;
372  std::stringstream ss_extra;
373  ss_value.setf(_flags);
374  ss_value << std::setw(_width) << std::setprecision(_prec) << _value;
375  if(!_disp.empty())
376  {
377  ss_extra << " " << _disp;
378  }
379  else if(!_label.empty())
380  {
381  ss_extra << " " << _label;
382  }
383  os << ss_value.str() << ss_extra.str();
384  return os;
385  }

Member Data Documentation

◆ events

◆ precision

template<size_t MaxNumEvents>
const short tim::component::papi_array< MaxNumEvents >::precision = 3
static

Definition at line 63 of file papi_array.hpp.

◆ width

template<size_t MaxNumEvents>
const short tim::component::papi_array< MaxNumEvents >::width = 8
static

Definition at line 64 of file papi_array.hpp.


The documentation for this struct was generated from the following file: