HEBench
benchmark.cpp
Go to the documentation of this file.
1 
2 // Copyright (C) 2021 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #include <cstring>
6 #include <stdexcept>
7 
9 
10 namespace hebench {
11 namespace cpp {
12 
13 //----------------------------
14 // class BenchmarkDescription
15 //----------------------------
16 
18 {
19  (void)p_w_params;
20  return std::string();
21 }
22 
24 {
25  return m_default_params.empty() ? 0 : m_default_params.front().size();
26 }
27 
29 {
30  bench_desc = getBenchmarkDescriptor();
31 }
32 
34 {
35  addDefaultParameters(default_params_set.getParams());
36 }
37 
38 void BenchmarkDescription::addDefaultParameters(const std::vector<hebench::APIBridge::WorkloadParam> &default_params_set)
39 {
40  if (!m_default_params.empty())
41  {
42  if (m_default_params.front().size() != default_params_set.size())
43  throw std::invalid_argument("Size of new default set of arguments differs from other existing default sets.");
44  } // end if
45  m_default_params.push_back(default_params_set);
46 }
47 
48 //---------------------
49 // class BaseBenchmark
50 //---------------------
51 
53  const hebench::APIBridge::BenchmarkDescriptor &bench_desc) :
54  m_engine(engine),
55  m_bench_description(bench_desc)
56 {
57 }
58 
61  const hebench::APIBridge::WorkloadParams &bench_params) :
62  BaseBenchmark(engine, bench_desc)
63 {
64  if (bench_params.count > 0)
65  m_bench_params.assign(bench_params.params, bench_params.params + bench_params.count);
66 }
67 
69 {
70  (void)bench_desc_concrete;
71 }
72 
74  std::uint64_t param_position)
75 {
76  std::uint64_t retval = parameters.pack_count;
77 
78  if (parameters.p_data_packs)
79  {
80  if (param_position < parameters.pack_count
81  && parameters.p_data_packs[param_position].param_position == param_position)
82  retval = param_position;
83  else
84  {
85  for (std::uint64_t i = 0; retval >= parameters.pack_count && i < parameters.pack_count; ++i)
86  if (parameters.p_data_packs[i].param_position == param_position)
87  retval = i;
88  } // end else
89  } // end if
90 
91  return retval;
92 }
93 
95  std::uint64_t param_position)
96 {
97  std::uint64_t tmp_u64 = findDataPackIndex(parameters, param_position);
98  if (tmp_u64 >= parameters.pack_count)
99  throw hebench::cpp::HEBenchError(HEBERROR_MSG_CLASS("DataPack for component " + std::to_string(param_position) + " not found."),
101  return parameters.p_data_packs[tmp_u64];
102 }
103 
105  std::uint64_t param_position)
106 {
107  std::uint64_t tmp_u64 = findDataPackIndex(parameters, param_position);
108  if (tmp_u64 >= parameters.pack_count)
109  throw hebench::cpp::HEBenchError(HEBERROR_MSG_CLASS("DataPack for component " + std::to_string(param_position) + " not found."),
111  return parameters.p_data_packs[tmp_u64];
112 }
113 
114 } // namespace cpp
115 } // namespace hebench
Top level opaque benchmark class.
Definition: benchmark.hpp:143
static const hebench::APIBridge::DataPack & findDataPack(const hebench::APIBridge::DataPackCollection &parameters, std::uint64_t param_position)
Searches the specified DataPackCollection for the DataPack in the corresponding position.
Definition: benchmark.cpp:94
static std::uint64_t findDataPackIndex(const hebench::APIBridge::DataPackCollection &parameters, std::uint64_t param_position)
Searches the specified DataPackCollection for the DataPack in the corresponding position.
Definition: benchmark.cpp:73
virtual void initialize(const hebench::APIBridge::BenchmarkDescriptor &bench_desc_concrete)
Called by Test Harness with the concrete values for the benchmark description.
Definition: benchmark.cpp:68
BaseBenchmark(BaseEngine &engine, const hebench::APIBridge::BenchmarkDescriptor &bench_desc, const hebench::APIBridge::WorkloadParams &bench_params)
Constructs a new BaseBenchmark object for benchmarking a workload with flexible parameters.
Definition: benchmark.cpp:59
Base class that encapsulates common behavior of backend engines.
Definition: engine.hpp:70
void addDefaultParameters(const WorkloadParams::Common &default_params_set)
Adds a new set of default arguments for the parameters for this benchmark's workload.
Definition: benchmark.cpp:33
const hebench::APIBridge::BenchmarkDescriptor & getBenchmarkDescriptor() const
Retrieves the HEBench benchmark descriptor represented by this BenchmarkDescription object.
Definition: benchmark.hpp:58
virtual std::string getBenchmarkDescription(const hebench::APIBridge::WorkloadParams *p_w_params) const
Retrieves human-readable description specific to the represented benchmark.
Definition: benchmark.cpp:17
std::size_t getWorkloadParameterCount() const
Retrieves the number of flexible parameters for this benchmark's workload.
Definition: benchmark.cpp:23
Base wrapper around the flexible workload parameters.
const std::vector< hebench::APIBridge::WorkloadParam > & getParams() const
#define HEBERROR_MSG_CLASS(message)
std::uint64_t count
Number of workload parameters.
Definition: types.h:371
DataPack * p_data_packs
Collection of data packs.
Definition: types.h:625
std::uint64_t pack_count
Number of data packs in the collection.
Definition: types.h:626
WorkloadParam * params
Parameters for the workload.
Definition: types.h:367
std::uint64_t param_position
The 0-based position of this parameter in the corresponding function call.
Definition: types.h:614
Defines a benchmark test.
Definition: types.h:527
Defines a data package for an operation.
Definition: types.h:611
Defines a collection of data packs.
Definition: types.h:624
Specifies the parameters for a workload.
Definition: types.h:363
std::string to_string(const std::string_view &s)
#define HEBENCH_ECODE_CRITICAL_ERROR
Specifies a critical error.
Definition: types.h:50