timemory 3.3.0
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)
 
this_typeoperator/= (size_t _val)
 
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 ()
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

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 229 of file papi_array.hpp.

229{ 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 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]).long_descr;
304 return arr;
305 }

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 310 of file papi_array.hpp.

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

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 331 of file papi_array.hpp.

332 {
333 if(events.size() == 0)
334 return "";
335 auto val = load();
336 auto _get_display = [&](std::ostream& os, size_type idx) {
337 auto _obj_value = val[idx];
338 auto _evt_type = events[idx];
339 string_t _label = papi::get_event_info(_evt_type).short_descr;
340 string_t _disp = papi::get_event_info(_evt_type).units;
341 auto _prec = base_type::get_precision();
342 auto _width = base_type::get_width();
343 auto _flags = base_type::get_format_flags();
344
345 std::stringstream ss;
346 std::stringstream ssv;
347 std::stringstream ssi;
348 ssv.setf(_flags);
349 ssv << std::setw(_width) << std::setprecision(_prec) << _obj_value;
350 if(!_disp.empty())
351 ssv << " " << _disp;
352 if(!_label.empty())
353 ssi << " " << _label;
354 ss << ssv.str() << ssi.str();
355 os << ss.str();
356 };
357
358 std::stringstream ss;
359 for(size_type i = 0; i < events.size(); ++i)
360 {
361 _get_display(ss, i);
362 if(i + 1 < events.size())
363 ss << ", ";
364 }
365 return ss.str();
366 }
std::string string_t
Definition: library.cpp:57
const std::string std::ostream * os
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(), tim::component::base< papi_array< MaxNumEvents >, std::array< long long, MaxNumEvents > >::load(), and tim::os.

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 231 of file papi_array.hpp.

232 {
233 return accum.at(evt_type);
234 }

◆ 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>(); }

◆ get_opaque()

template<typename... Args>
static opaque tim::component::empty_base::get_opaque ( Args &&  ...)
inlinestaticinherited

Definition at line 72 of file declaration.hpp.

73 {
74 return opaque{};
75 }

◆ 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 222 of file papi_array.hpp.

223 {
224 return "papi_array" + std::to_string((event_set<common_type>() < 0)
225 ? 0
226 : event_set<common_type>());
227 }

◆ label_array()

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

Definition at line 263 of file papi_array.hpp.

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

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 240 of file papi_array.hpp.

241 {
242 ar(cereal::make_nvp("laps", laps), cereal::make_nvp("value", value),
243 cereal::make_nvp("accum", accum), cereal::make_nvp("events", events));
244 }

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 }

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

◆ operator/=()

template<size_t MaxNumEvents>
this_type & tim::component::papi_array< MaxNumEvents >::operator/= ( size_t  _val)
inline

Definition at line 192 of file papi_array.hpp.

193 {
194 for(size_type i = 0; i < events.size(); ++i)
195 accum[i] /= _val;
196 for(size_type i = 0; i < events.size(); ++i)
197 value[i] /= _val;
198 return *this;
199 }

◆ 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:316
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 250 of file papi_array.hpp.

251 {
252 array_t<double> _disp;
253 for(size_type i = 0; i < events.size(); ++i)
254 _disp[i] = get_display(i);
255 ar(cereal::make_nvp("laps", laps), cereal::make_nvp("repr_data", _disp),
256 cereal::make_nvp("value", value), cereal::make_nvp("accum", accum),
257 cereal::make_nvp("display", _disp), cereal::make_nvp("events", events));
258 }
string_t get_display() const
Definition: papi_array.hpp:331

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:386

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 321 of file papi_array.hpp.

322 {
323 std::vector<int64_t> arr(events.size());
324 for(size_type i = 0; i < events.size(); ++i)
325 arr[i] = 1;
326 return arr;
327 }

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 192 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 370 of file papi_array.hpp.

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

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: