HEBench
hebench_utilities_harness.inl
Go to the documentation of this file.
1 
2 // Copyright (C) 2021 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef _HEBench_Harness_Utilities_SRC_0596d40a3cce4b108a81595c50eb286d
6 #define _HEBench_Harness_Utilities_SRC_0596d40a3cce4b108a81595c50eb286d
7 
8 #include <algorithm>
9 
10 #include "../hebench_utilities_harness.h"
11 #include "hebench/modules/general/include/hebench_utilities.h"
12 
13 namespace hebench {
14 namespace Utilities {
15 
16 template <typename T>
17 void printArraysAsColumns(std::ostream &os,
18  const hebench::APIBridge::NativeDataBuffer **p_buffers, std::size_t count,
19  bool output_row_index,
20  const char *separator)
21 {
22  std::uint64_t max_rows = 0;
23  if (p_buffers && count > 0)
24  {
25  auto it = std::max_element(p_buffers, p_buffers + count,
27  return lhs->size < rhs->size;
28  });
29  max_rows = (*it)->size / sizeof(T);
30  } // end if
31 
32  for (std::uint64_t row_i = 0; row_i < max_rows; ++row_i)
33  {
34  // print next row
35  if (output_row_index)
36  os << row_i << separator;
37  for (std::size_t buffer_i = 0; buffer_i < count; ++buffer_i)
38  {
39  if (buffer_i > 0)
40  os << separator;
41  if (p_buffers[buffer_i]->p && row_i < p_buffers[buffer_i]->size / sizeof(T))
42  os << reinterpret_cast<T *>(p_buffers[buffer_i]->p)[row_i];
43  } // end for
44  os << std::endl;
45  } // end for
46 }
47 
48 template <class TimeInterval>
49 inline void TimingReportEx::addEvent(hebench::Common::TimingReportEvent::Ptr p_event)
50 {
51  this->addEvent<TimeInterval>(p_event, nullptr);
52 }
53 
54 template <class TimeInterval>
55 inline void TimingReportEx::addEvent(hebench::Common::TimingReportEvent::Ptr p_event,
56  const std::string &event_type_name)
57 {
58  this->addEvent<TimeInterval>(p_event, event_type_name.c_str());
59 }
60 
61 template <class TimeInterval>
62 inline void TimingReportEx::addEvent(hebench::Common::TimingReportEvent::Ptr p_event,
63  const char *event_type_name)
64 {
65  if (event_type_name)
66  this->addEventType(p_event->id, event_type_name);
68  convert2C<TimeInterval>(*p_event);
69  this->addEvent(tre_c);
70 }
71 
72 template <class TimeInterval>
74 TimingReportEx::convert2C(const hebench::Common::TimingReportEvent &timing_event)
75 {
77  retval.time_interval_ratio_num = TimeInterval::num;
78  retval.time_interval_ratio_den = TimeInterval::den;
79  retval.event_type_id = timing_event.id;
80  retval.cpu_time_start = timing_event.timeStartCPU<TimeInterval>();
81  retval.cpu_time_end = timing_event.timeEndCPU<TimeInterval>();
82  retval.wall_time_start = timing_event.timeStartWall<TimeInterval>();
83  retval.wall_time_end = timing_event.timeEndWall<TimeInterval>();
84  retval.input_sample_count = timing_event.iterations();
85  copyString(retval.description, MAX_TIME_REPORT_EVENT_DESCRIPTION_SIZE, timing_event.description);
86 
87  return retval;
88 }
89 
90 } // namespace Utilities
91 } // namespace hebench
92 
93 #endif // defined _HEBench_Harness_Utilities_SRC_0596d40a3cce4b108a81595c50eb286d
void addEventType(uint32_t event_type_id, const std::string &event_type_header, bool is_main_event=false)
Adds a new event type to the types of events.
static hebench::ReportGen::TimingReportEventC convert2C(const hebench::Common::TimingReportEvent &timing_event)
void addEvent(const TimingReportEventC &p_event)
#define MAX_TIME_REPORT_EVENT_DESCRIPTION_SIZE
std::uint64_t size
Size of underlying data.
Definition: types.h:564
Structure to contain flexible data.
Definition: types.h:552
int64_t time_interval_ratio_num
Scale of time interval used for this event.
uint32_t event_type_id
ID specifying the event type.
int64_t time_interval_ratio_den
Scale of time interval used for this event.
char description[MAX_TIME_REPORT_EVENT_DESCRIPTION_SIZE]
Description attached to this event.
void printArraysAsColumns(std::ostream &os, const hebench::APIBridge::NativeDataBuffer **p_buffers, std::size_t count, hebench::APIBridge::DataType data_type, bool output_row_index=false, const char *separator=" ")
Writes the collection of NativeDataBuffer as columns to the specified output stream.
std::uint64_t copyString(char *dst, std::uint64_t size, const std::string &src)
Copies a C++ string object into a C-style string.
Definition: utilities.cpp:13