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_tuple< EventTypes > Struct Template Reference

This component is useful for bundling together a fixed set of hardware counter identifiers which require no runtime configuration. More...

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

+ Collaboration diagram for tim::component::papi_tuple< EventTypes >:

Public Types

using size_type = std::size_t
 
using value_type = std::array< long long, sizeof...(EventTypes)>
 
using entry_type = typename value_type::value_type
 
using this_type = papi_tuple< EventTypes... >
 
using base_type = base< this_type, value_type >
 
using storage_type = typename base_type::storage_type
 
using tracker_type = policy::instance_tracker< papi_tuple< EventTypes... > >
 
using common_type = this_type
 
template<typename Tp >
using array_t = std::array< Tp, num_events >
 

Public Member Functions

void sample ()
 
void start ()
 
void stop ()
 
this_typeoperator+= (const this_type &rhs)
 
this_typeoperator-= (const this_type &rhs)
 
template<typename Archive >
void serialize (Archive &ar, const unsigned int)
 
entry_type get_display (int evt_type) const
 
string_t get_display () const
 
template<typename Tp = double>
auto get () const
 

Static Public Member Functions

static void configure ()
 
static void thread_init ()
 
static void thread_finalize ()
 
static void initialize ()
 
static void finalize ()
 
static value_type record ()
 
static std::string label ()
 
static std::string description ()
 
static std::string display_unit ()
 
static int64_t unit ()
 
template<typename Lhs , typename Rhs , size_t N, size_t... Idx>
static void convert (std::array< Lhs, N > &lhs, const std::array< Rhs, N > &rhs, std::index_sequence< Idx... >)
 
static array_t< std::string > label_array ()
 
static array_t< std::string > description_array ()
 
static array_t< std::string > display_unit_array ()
 
static array_t< int64_t > unit_array ()
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

Static Public Attributes

static const size_type num_events = sizeof...(EventTypes)
 
static const short precision = 3
 
static const short width = 12
 

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 >
 

Detailed Description

template<int... EventTypes>
struct tim::component::papi_tuple< EventTypes >

This component is useful for bundling together a fixed set of hardware counter identifiers which require no runtime configuration.

Template Parameters
EventTypesCompile-time constant list of PAPI event identifiers
// the "Instructions" alias below explicitly collects the total instructions,
// the number of load instructions, the number of store instructions
using Instructions = papi_tuple<PAPI_TOT_INS, PAPI_LD_INS, PAPI_SR_INS>;
Instructions inst{};
inst.start();
...
inst.stop();
std::vector<double> data = inst.get();
static common_data & data()

Definition at line 65 of file papi_tuple.hpp.

Member Typedef Documentation

◆ array_t

template<int... EventTypes>
template<typename Tp >
using tim::component::papi_tuple< EventTypes >::array_t = std::array<Tp, num_events>

Definition at line 81 of file papi_tuple.hpp.

◆ base_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::base_type = base<this_type, value_type>

Definition at line 74 of file papi_tuple.hpp.

◆ common_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::common_type = this_type

Definition at line 77 of file papi_tuple.hpp.

◆ entry_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::entry_type = typename value_type::value_type

Definition at line 72 of file papi_tuple.hpp.

◆ size_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::size_type = std::size_t

Definition at line 70 of file papi_tuple.hpp.

◆ storage_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::storage_type = typename base_type::storage_type

Definition at line 75 of file papi_tuple.hpp.

◆ this_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::this_type = papi_tuple<EventTypes...>

Definition at line 73 of file papi_tuple.hpp.

◆ tracker_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::tracker_type = policy::instance_tracker<papi_tuple<EventTypes...> >

Definition at line 76 of file papi_tuple.hpp.

◆ value_type

template<int... EventTypes>
using tim::component::papi_tuple< EventTypes >::value_type = std::array<long long, sizeof...(EventTypes)>

Definition at line 71 of file papi_tuple.hpp.

Member Function Documentation

◆ configure()

template<int... EventTypes>
static void tim::component::papi_tuple< EventTypes >::configure ( )
inlinestatic

Definition at line 92 of file papi_tuple.hpp.

93 {
94 if(!is_configured<common_type>())
95 {
96 papi_common::get_initializer<common_type>() = []() {
97 return std::vector<int>({ EventTypes... });
98 };
99 papi_common::get_events<common_type>() = { EventTypes... };
100 papi_common::initialize<common_type>();
101 }
102 }

Referenced by tim::component::papi_rate_tuple< RateT, EventTypes >::configure(), tim::component::papi_tuple< EventTypes >::initialize(), tim::component::papi_tuple< EventTypes >::sample(), tim::component::papi_tuple< EventTypes >::start(), and tim::component::papi_tuple< EventTypes >::thread_init().

◆ convert()

template<int... EventTypes>
template<typename Lhs , typename Rhs , size_t N, size_t... Idx>
static void tim::component::papi_tuple< EventTypes >::convert ( std::array< Lhs, N > &  lhs,
const std::array< Rhs, N > &  rhs,
std::index_sequence< Idx... >   
)
inlinestatic

Definition at line 294 of file papi_tuple.hpp.

296 {
297 TIMEMORY_FOLD_EXPRESSION(std::get<Idx>(lhs) =
298 static_cast<Lhs>(std::get<Idx>(rhs)));
299 }
#define TIMEMORY_FOLD_EXPRESSION(...)
Definition: types.hpp:56

References TIMEMORY_FOLD_EXPRESSION.

Referenced by tim::component::papi_tuple< EventTypes >::get().

◆ description()

template<int... EventTypes>
static std::string tim::component::papi_tuple< EventTypes >::description ( )
inlinestatic

Definition at line 229 of file papi_tuple.hpp.

229{ return ""; }

◆ description_array()

template<int... EventTypes>
static array_t< std::string > tim::component::papi_tuple< EventTypes >::description_array ( )
inlinestatic

Definition at line 323 of file papi_tuple.hpp.

324 {
325 array_t<std::string> arr;
326 for(size_type i = 0; i < num_events; ++i)
327 arr[i] = papi::get_event_info(get_events<common_type>().at(i)).long_descr;
328 return arr;
329 }
_args at(0)
static const size_type num_events
Definition: papi_tuple.hpp:79

References tim::at(), and tim::component::papi_tuple< EventTypes >::num_events.

Referenced by tim::component::papi_rate_tuple< RateT, EventTypes >::description_array().

◆ display_unit()

template<int... EventTypes>
static std::string tim::component::papi_tuple< EventTypes >::display_unit ( )
inlinestatic

Definition at line 230 of file papi_tuple.hpp.

230{ return ""; }

◆ display_unit_array()

template<int... EventTypes>
static array_t< std::string > tim::component::papi_tuple< EventTypes >::display_unit_array ( )
inlinestatic

Definition at line 334 of file papi_tuple.hpp.

335 {
336 array_t<std::string> arr;
337 for(size_type i = 0; i < num_events; ++i)
338 arr[i] = papi::get_event_info(get_events<common_type>().at(i)).units;
339 return arr;
340 }

References tim::at(), and tim::component::papi_tuple< EventTypes >::num_events.

◆ finalize()

template<int... EventTypes>
static void tim::component::papi_tuple< EventTypes >::finalize ( )
inlinestatic

Definition at line 110 of file papi_tuple.hpp.

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

Referenced by tim::component::papi_rate_tuple< RateT, EventTypes >::finalize().

◆ get()

template<int... EventTypes>
template<typename Tp = double>
auto tim::component::papi_tuple< EventTypes >::get ( ) const
inline

Definition at line 301 of file papi_tuple.hpp.

302 {
303 std::array<Tp, num_events> values;
304 auto& _data = load();
305 convert(values, _data, std::make_index_sequence<num_events>{});
306 return values;
307 }
static void convert(std::array< Lhs, N > &lhs, const std::array< Rhs, N > &rhs, std::index_sequence< Idx... >)
Definition: papi_tuple.hpp:294

References tim::component::papi_tuple< EventTypes >::convert(), and tim::component::base< papi_tuple< EventTypes... >, std::array< long long, sizeof...(EventTypes)> >::load().

◆ get_display() [1/2]

template<int... EventTypes>
string_t tim::component::papi_tuple< EventTypes >::get_display ( ) const
inline

Definition at line 255 of file papi_tuple.hpp.

256 {
257 auto val = load();
258 auto _get_display = [&](std::ostream& os, size_type idx) {
259 auto _obj_value = val[idx];
260 auto _evt_type = std::vector<int>({ EventTypes... }).at(idx);
261 string_t _label = papi::get_event_info(_evt_type).short_descr;
262 string_t _disp = papi::get_event_info(_evt_type).units;
263 auto _prec = base_type::get_precision();
264 auto _width = base_type::get_width();
265 auto _flags = base_type::get_format_flags();
266
267 std::stringstream ss;
268 std::stringstream ssv;
269 std::stringstream ssi;
270 ssv.setf(_flags);
271 ssv << std::setw(_width) << std::setprecision(_prec) << _obj_value;
272 if(!_disp.empty())
273 {
274 ssv << " " << _disp;
275 }
276 else if(!_label.empty())
277 {
278 ssi << " " << _label;
279 }
280 ss << ssv.str() << ssi.str();
281 os << ss.str();
282 };
283 std::stringstream ss;
284 for(size_type i = 0; i < num_events; ++i)
285 {
286 _get_display(ss, i);
287 if(i + 1 < num_events)
288 ss << ", ";
289 }
290 return ss.str();
291 }
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::at(), 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_tuple< EventTypes... >, std::array< long long, sizeof...(EventTypes)> >::load(), tim::component::papi_tuple< EventTypes >::num_events, and tim::os.

Referenced by tim::component::papi_tuple< EventTypes >::serialize().

◆ get_display() [2/2]

template<int... EventTypes>
entry_type tim::component::papi_tuple< EventTypes >::get_display ( int  evt_type) const
inline

Definition at line 253 of file papi_tuple.hpp.

253{ return accum[evt_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<int... EventTypes>
static void tim::component::papi_tuple< EventTypes >::initialize ( )
inlinestatic

◆ label()

template<int... EventTypes>
static std::string tim::component::papi_tuple< EventTypes >::label ( )
inlinestatic

Definition at line 225 of file papi_tuple.hpp.

226 {
227 return "papi" + std::to_string(event_set<common_type>());
228 }

Referenced by tim::component::papi_rate_tuple< RateT, EventTypes >::label().

◆ label_array()

template<int... EventTypes>
static array_t< std::string > tim::component::papi_tuple< EventTypes >::label_array ( )
inlinestatic

Definition at line 312 of file papi_tuple.hpp.

313 {
314 array_t<std::string> arr;
315 for(size_type i = 0; i < num_events; ++i)
316 arr[i] = papi::get_event_info(get_events<common_type>().at(i)).short_descr;
317 return arr;
318 }

References tim::at(), and tim::component::papi_tuple< EventTypes >::num_events.

Referenced by tim::component::papi_rate_tuple< RateT, EventTypes >::display_unit_array(), and tim::component::papi_rate_tuple< RateT, EventTypes >::label_array().

◆ operator+=()

template<int... EventTypes>
this_type & tim::component::papi_tuple< EventTypes >::operator+= ( const this_type rhs)
inline

Definition at line 197 of file papi_tuple.hpp.

198 {
199 for(size_type i = 0; i < num_events; ++i)
200 accum[i] += rhs.accum[i];
201 for(size_type i = 0; i < num_events; ++i)
202 value[i] += rhs.value[i];
203 return *this;
204 }

References tim::component::papi_tuple< EventTypes >::num_events.

◆ operator-=()

template<int... EventTypes>
this_type & tim::component::papi_tuple< EventTypes >::operator-= ( const this_type rhs)
inline

Definition at line 206 of file papi_tuple.hpp.

207 {
208 for(size_type i = 0; i < num_events; ++i)
209 accum[i] -= rhs.accum[i];
210 for(size_type i = 0; i < num_events; ++i)
211 value[i] -= rhs.value[i];
212 return *this;
213 }

References tim::component::papi_tuple< EventTypes >::num_events.

◆ record()

template<int... EventTypes>
static value_type tim::component::papi_tuple< EventTypes >::record ( )
inlinestatic

Definition at line 114 of file papi_tuple.hpp.

115 {
116 if(is_configured<common_type>())
117 tim::papi::read(event_set<common_type>(), get_read_values().data());
118 return get_read_values();
119 }

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

Referenced by tim::component::papi_tuple< EventTypes >::sample(), tim::component::papi_tuple< EventTypes >::start(), and tim::component::papi_tuple< EventTypes >::stop().

◆ sample()

template<int... EventTypes>
void tim::component::papi_tuple< EventTypes >::sample ( )
inline

Definition at line 157 of file papi_tuple.hpp.

158 {
159 if(tracker_type::get_thread_started() == 0)
160 configure();
161 if(events.empty())
162 events = get_events<common_type>();
163
165 value = record();
166 }
void start(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:316
static value_type record()
Definition: papi_tuple.hpp:114

References tim::component::papi_tuple< EventTypes >::configure(), tim::component::papi_common::events, tim::component::papi_tuple< EventTypes >::record(), and tim::invoke::start().

◆ serialize()

template<int... EventTypes>
template<typename Archive >
void tim::component::papi_tuple< EventTypes >::serialize ( Archive &  ar,
const unsigned int   
)
inline

Definition at line 237 of file papi_tuple.hpp.

238 {
239 array_t<double> _disp;
240 array_t<double> _value;
241 array_t<double> _accum;
242 for(size_type i = 0; i < num_events; ++i)
243 {
244 _disp[i] = get_display(i);
245 _value[i] = value[i];
246 _accum[i] = accum[i];
247 }
248 ar(cereal::make_nvp("laps", laps), cereal::make_nvp("repr_data", _disp),
249 cereal::make_nvp("value", _value), cereal::make_nvp("accum", _accum),
250 cereal::make_nvp("display", _disp));
251 }
string_t get_display() const
Definition: papi_tuple.hpp:255

References tim::component::papi_tuple< EventTypes >::get_display(), tim::component::base< papi_tuple< EventTypes... >, std::array< long long, sizeof...(EventTypes)> >::laps, and tim::component::papi_tuple< EventTypes >::num_events.

◆ start()

template<int... EventTypes>
void tim::component::papi_tuple< EventTypes >::start ( )
inline

Definition at line 171 of file papi_tuple.hpp.

172 {
173 if(tracker_type::get_thread_started() == 0 || events.size() == 0)
174 {
175 configure();
176 events = get_events<common_type>();
177 }
178
180 value = record();
181 }

References tim::component::papi_tuple< EventTypes >::configure(), tim::component::papi_common::events, tim::component::papi_tuple< EventTypes >::record(), and tim::invoke::start().

◆ stop()

template<int... EventTypes>
void tim::component::papi_tuple< EventTypes >::stop ( )
inline

Definition at line 186 of file papi_tuple.hpp.

187 {
189 using namespace tim::component::operators;
190 value = (record() - value);
191 accum += value;
192 }
void stop(TupleT< Tp... > &obj, Args &&... args)
Definition: functional.cpp:386

References tim::component::papi_tuple< EventTypes >::record(), and tim::invoke::stop().

◆ thread_finalize()

template<int... EventTypes>
static void tim::component::papi_tuple< EventTypes >::thread_finalize ( )
inlinestatic

Definition at line 104 of file papi_tuple.hpp.

105 {
106 papi_common::finalize<common_type>();
108 }

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

◆ thread_init()

template<int... EventTypes>
static void tim::component::papi_tuple< EventTypes >::thread_init ( )
inlinestatic

◆ unit()

template<int... EventTypes>
static int64_t tim::component::papi_tuple< EventTypes >::unit ( )
inlinestatic

Definition at line 231 of file papi_tuple.hpp.

231{ return 1; }

◆ unit_array()

template<int... EventTypes>
static array_t< int64_t > tim::component::papi_tuple< EventTypes >::unit_array ( )
inlinestatic

Definition at line 345 of file papi_tuple.hpp.

346 {
347 array_t<int64_t> arr;
348 for(size_type i = 0; i < num_events; ++i)
349 arr[i] = 1;
350 return arr;
351 }

References tim::component::papi_tuple< EventTypes >::num_events.

Referenced by tim::component::papi_rate_tuple< RateT, EventTypes >::unit_array().

Friends And Related Function Documentation

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

template<int... EventTypes>
friend class impl::storage< this_type, trait::uses_value_storage< this_type, value_type >::value >
friend

Definition at line 122 of file papi_tuple.hpp.

◆ operation::record< this_type >

template<int... EventTypes>
friend struct operation::record< this_type >
friend

Definition at line 79 of file papi_tuple.hpp.

◆ operation::set_started< this_type >

template<int... EventTypes>
friend struct operation::set_started< this_type >
friend

Definition at line 79 of file papi_tuple.hpp.

◆ operation::set_stopped< this_type >

template<int... EventTypes>
friend struct operation::set_stopped< this_type >
friend

Definition at line 79 of file papi_tuple.hpp.

◆ operation::start< this_type >

template<int... EventTypes>
friend struct operation::start< this_type >
friend

Definition at line 79 of file papi_tuple.hpp.

◆ operation::stop< this_type >

template<int... EventTypes>
friend struct operation::stop< this_type >
friend

Definition at line 79 of file papi_tuple.hpp.

Member Data Documentation

◆ num_events

◆ precision

template<int... EventTypes>
const short tim::component::papi_tuple< EventTypes >::precision = 3
static

Definition at line 221 of file papi_tuple.hpp.

◆ width

template<int... EventTypes>
const short tim::component::papi_tuple< EventTypes >::width = 12
static

Definition at line 222 of file papi_tuple.hpp.


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