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_vector Struct Reference

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

+ Collaboration diagram for tim::component::papi_vector:

Public Types

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

Public Member Functions

 papi_vector ()
 
 ~papi_vector ()=default
 
 papi_vector (const papi_vector &)=default
 
 papi_vector (papi_vector &&) noexcept=default
 
papi_vectoroperator= (const papi_vector &)=default
 
papi_vectoroperator= (papi_vector &&) noexcept=default
 
size_t size ()
 
value_type record ()
 
template<typename Tp = double>
vector_t< 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
 
vector_t< std::string > label_array () const
 
vector_t< std::string > description_array () const
 
vector_t< std::string > display_unit_array () const
 
vector_t< 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 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

template<typename... T>
struct cpu_roofline
 
template<typename... T>
struct gpu_roofline
 
std::ostream & operator<< (std::ostream &os, const this_type &obj)
 

Detailed Description

Definition at line 52 of file papi_vector.hpp.

Member Typedef Documentation

◆ base_type

◆ common_type

Definition at line 69 of file papi_vector.hpp.

◆ entry_type

using tim::component::papi_vector::entry_type = typename value_type::value_type

Definition at line 63 of file papi_vector.hpp.

◆ event_list

Definition at line 61 of file papi_vector.hpp.

◆ get_initializer_t

Definition at line 67 of file papi_vector.hpp.

◆ size_type

Definition at line 60 of file papi_vector.hpp.

◆ storage_type

using tim::component::papi_vector::storage_type = typename base_type::storage_type

Definition at line 66 of file papi_vector.hpp.

◆ this_type

◆ tracker_type

◆ value_type

Definition at line 62 of file papi_vector.hpp.

◆ vector_t

template<typename Tp >
using tim::component::papi_vector::vector_t = std::vector<Tp>

Definition at line 58 of file papi_vector.hpp.

Constructor & Destructor Documentation

◆ papi_vector() [1/3]

tim::component::papi_vector::papi_vector ( )
inline

Definition at line 100 of file papi_vector.hpp.

101  {
102  events = get_events<common_type>();
103  value.resize(events.size(), 0);
104  accum.resize(events.size(), 0);
105  }

References events.

◆ ~papi_vector()

tim::component::papi_vector::~papi_vector ( )
default

◆ papi_vector() [2/3]

tim::component::papi_vector::papi_vector ( const papi_vector )
default

◆ papi_vector() [3/3]

tim::component::papi_vector::papi_vector ( papi_vector &&  )
defaultnoexcept

Member Function Documentation

◆ configure()

static void tim::component::papi_vector::configure ( )
inlinestatic

Definition at line 85 of file papi_vector.hpp.

86  {
87  if(!is_configured<common_type>())
88  papi_common::initialize<common_type>();
89  }

Referenced by tim::component::cpu_roofline< Types >::configure(), initialize(), sample(), and start().

◆ description()

static std::string tim::component::papi_vector::description ( )
inlinestatic

Definition at line 221 of file papi_vector.hpp.

222  {
223  return "Dynamically allocated array of PAPI HW counters";
224  }

◆ description_array()

vector_t<std::string> tim::component::papi_vector::description_array ( ) const
inline

Definition at line 297 of file papi_vector.hpp.

298  {
299  vector_t<std::string> arr(events.size(), "");
300  for(size_type i = 0; i < events.size(); ++i)
301  arr[i] = papi::get_event_info(events[i]).long_descr;
302  return arr;
303  }

References events.

◆ display_unit_array()

vector_t<std::string> tim::component::papi_vector::display_unit_array ( ) const
inline

Definition at line 308 of file papi_vector.hpp.

309  {
310  vector_t<std::string> arr(events.size(), "");
311  for(size_type i = 0; i < events.size(); ++i)
312  arr[i] = papi::get_event_info(events[i]).units;
313  return arr;
314  }

References events.

◆ finalize()

static void tim::component::papi_vector::finalize ( )
inlinestatic

Definition at line 96 of file papi_vector.hpp.

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

◆ get()

template<typename Tp = double>
vector_t<Tp> tim::component::papi_vector::get ( ) const
inline

Definition at line 132 of file papi_vector.hpp.

133  {
134  std::vector<Tp> values;
135  const auto& _data = load();
136  for(const auto& itr : _data)
137  values.push_back(itr);
138  values.resize(events.size());
139  return values;
140  }

References events, and tim::component::base< papi_vector, std::vector< long long > >::load().

◆ get_display() [1/2]

string_t tim::component::papi_vector::get_display ( ) const
inline

Definition at line 329 of file papi_vector.hpp.

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

References 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_vector, std::vector< long long > >::load().

Referenced by save().

◆ get_display() [2/2]

entry_type tim::component::papi_vector::get_display ( int  evt_type) const
inline

Definition at line 226 of file papi_vector.hpp.

227  {
228  return accum.at(evt_type);
229  }

◆ get_initializer()

static auto& tim::component::papi_vector::get_initializer ( )
inlinestatic

Definition at line 84 of file papi_vector.hpp.

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

◆ initialize()

static void tim::component::papi_vector::initialize ( )
inlinestatic

Definition at line 90 of file papi_vector.hpp.

90 { configure(); }

References configure().

◆ label()

static std::string tim::component::papi_vector::label ( )
inlinestatic

Definition at line 214 of file papi_vector.hpp.

215  {
216  return "papi_vector" + std::to_string((event_set<common_type>() < 0)
217  ? 0
218  : event_set<common_type>());
219  }

◆ label_array()

vector_t<std::string> tim::component::papi_vector::label_array ( ) const
inline

Definition at line 261 of file papi_vector.hpp.

262  {
263  vector_t<std::string> arr(events.size(), "");
264  for(size_type i = 0; i < events.size(); ++i)
265  arr[i] = papi::get_event_info(events[i]).short_descr;
266 
267  for(auto& itr : arr)
268  {
269  size_t n = std::string::npos;
270  while((n = itr.find("L/S")) != std::string::npos)
271  itr.replace(n, 3, "Loads_Stores");
272  }
273 
274  for(auto& itr : arr)
275  {
276  size_t n = std::string::npos;
277  while((n = itr.find('/')) != std::string::npos)
278  itr.replace(n, 1, "_per_");
279  }
280 
281  for(auto& itr : arr)
282  {
283  size_t n = std::string::npos;
284  while((n = itr.find(' ')) != std::string::npos)
285  itr.replace(n, 1, "_");
286 
287  while((n = itr.find("__")) != std::string::npos)
288  itr.replace(n, 2, "_");
289  }
290 
291  return arr;
292  }

References events.

◆ load()

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

Definition at line 235 of file papi_vector.hpp.

236  {
237  ar(cereal::make_nvp("laps", laps), cereal::make_nvp("value", value),
238  cereal::make_nvp("accum", accum), cereal::make_nvp("events", events));
239  }

References events, and tim::component::base< papi_vector, std::vector< long long > >::laps.

◆ operator+=()

this_type& tim::component::papi_vector::operator+= ( const this_type rhs)
inline

Definition at line 185 of file papi_vector.hpp.

186  {
187  value += rhs.value;
188  accum += rhs.accum;
189  return *this;
190  }

◆ operator-=()

this_type& tim::component::papi_vector::operator-= ( const this_type rhs)
inline

Definition at line 194 of file papi_vector.hpp.

195  {
196  value -= rhs.value;
197  accum -= rhs.accum;
198  return *this;
199  }

◆ operator=() [1/2]

papi_vector& tim::component::papi_vector::operator= ( const papi_vector )
default

◆ operator=() [2/2]

papi_vector& tim::component::papi_vector::operator= ( papi_vector &&  )
defaultnoexcept

◆ record()

value_type tim::component::papi_vector::record ( )
inline

Definition at line 121 of file papi_vector.hpp.

122  {
123  value_type read_value(events.size(), 0);
124  if(is_configured<common_type>())
125  papi::read(event_set<common_type>(), read_value.data());
126  return read_value;
127  }
vector_t< long long > value_type
Definition: papi_vector.hpp:62

References events.

Referenced by sample(), start(), and stop().

◆ sample()

void tim::component::papi_vector::sample ( )
inline

Definition at line 145 of file papi_vector.hpp.

146  {
147  if(tracker_type::get_thread_started() == 0)
148  configure();
149  if(events.empty())
150  events = get_events<common_type>();
151 
153  value = record();
154  }
void start(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:298

References configure(), events, record(), and tim::invoke::start().

◆ save()

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

Definition at line 245 of file papi_vector.hpp.

246  {
247  auto sz = events.size();
248  vector_t<double> _disp(sz, 0.0);
249  for(size_type i = 0; i < sz; ++i)
250  {
251  _disp[i] = get_display(i);
252  }
253  ar(cereal::make_nvp("laps", laps), cereal::make_nvp("repr_data", _disp),
254  cereal::make_nvp("value", value), cereal::make_nvp("accum", accum),
255  cereal::make_nvp("display", _disp), cereal::make_nvp("events", events));
256  }
string_t get_display() const

References events, get_display(), and tim::component::base< papi_vector, std::vector< long long > >::laps.

◆ size()

size_t tim::component::papi_vector::size ( )
inline

Definition at line 117 of file papi_vector.hpp.

117 { return events.size(); }

References events.

◆ start()

void tim::component::papi_vector::start ( )
inline

Definition at line 159 of file papi_vector.hpp.

160  {
161  if(tracker_type::get_thread_started() == 0 || events.empty())
162  {
163  configure();
164  }
165 
166  events = get_events<common_type>();
167  value.resize(events.size(), 0);
168  accum.resize(events.size(), 0);
170  value = record();
171  }

References configure(), events, record(), and tim::invoke::start().

◆ stop()

void tim::component::papi_vector::stop ( )
inline

Definition at line 175 of file papi_vector.hpp.

176  {
177  using namespace tim::component::operators;
179  value = (record() - value);
180  accum += value;
181  }
void stop(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:368

References record(), and tim::invoke::stop().

◆ thread_finalize()

static void tim::component::papi_vector::thread_finalize ( )
inlinestatic

Definition at line 91 of file papi_vector.hpp.

92  {
93  papi_common::finalize<common_type>();
95  }

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

◆ unit_array()

vector_t<int64_t> tim::component::papi_vector::unit_array ( ) const
inline

Definition at line 319 of file papi_vector.hpp.

320  {
321  vector_t<int64_t> arr(events.size(), 0);
322  for(size_type i = 0; i < events.size(); ++i)
323  arr[i] = 1;
324  return arr;
325  }

References events.

Friends And Related Function Documentation

◆ cpu_roofline

template<typename... T>
friend struct cpu_roofline
friend

Definition at line 77 of file papi_vector.hpp.

◆ gpu_roofline

template<typename... T>
friend struct gpu_roofline
friend

Definition at line 80 of file papi_vector.hpp.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const this_type obj 
)
friend

Definition at line 368 of file papi_vector.hpp.

369  {
370  if(obj.events.empty())
371  return os;
372  // output the metrics
373  auto _value = obj.get_display();
374  auto _label = this_type::get_label();
375  auto _disp = this_type::display_unit();
376  auto _prec = this_type::get_precision();
377  auto _width = this_type::get_width();
378  auto _flags = this_type::get_format_flags();
379 
380  std::stringstream ss_value;
381  std::stringstream ss_extra;
382  ss_value.setf(_flags);
383  ss_value << std::setw(_width) << std::setprecision(_prec) << _value;
384  if(!_disp.empty())
385  {
386  ss_extra << " " << _disp;
387  }
388  else if(!_label.empty())
389  {
390  ss_extra << " " << _label;
391  }
392  os << ss_value.str() << ss_extra.str();
393  return os;
394  }

Member Data Documentation

◆ events

event_list tim::component::papi_common::events
protected

◆ precision

const short tim::component::papi_vector::precision = 3
static

Definition at line 73 of file papi_vector.hpp.

◆ width

const short tim::component::papi_vector::width = 8
static

Definition at line 74 of file papi_vector.hpp.


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