HEBench
hebench_genericwl.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 <cassert>
6 #include <sstream>
7 
8 #include "../include/hebench_genericwl.h"
9 
10 namespace hebench {
11 namespace TestHarness {
12 namespace GenericWL {
13 
14 //------------------------------------
15 // class BenchmarkDescriptionCategory
16 //------------------------------------
17 
18 std::pair<std::vector<std::uint64_t>, std::vector<std::uint64_t>>
19 BenchmarkDescriptorCategory::fetchIOVectorSizes(const std::vector<hebench::APIBridge::WorkloadParam> &w_params)
20 {
21  std::pair<std::vector<std::uint64_t>, std::vector<std::uint64_t>> retval;
22 
23  if (w_params.size() < WorkloadParameterMinCount)
24  {
25  std::stringstream ss;
26  ss << "Insufficient workload parameters in 'w_params'. Expected, at least, " << WorkloadParameterMinCount
27  << ", but " << w_params.size() << "received.";
28  throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
29  } // end if
30  for (std::size_t i = 0; i < w_params.size(); ++i)
31  {
32  if (w_params[i].data_type != WorkloadParameterType)
33  {
34  std::stringstream ss;
35  ss << "Invalid type for workload parameter " << i
36  << ". Expected type ID " << WorkloadParameterType << ", but " << w_params[i].data_type << " received.";
37  throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
38  } // end if
39  else if (w_params[i].u_param <= 0)
40  {
41  std::stringstream ss;
42  ss << "Invalid value in workload parameter " << i
43  << ". Expected positive integer, but " << w_params[i].u_param << " received.";
44  throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
45  } // end if
46  } // end for
47 
48  std::vector<std::uint64_t> &input_sizes = retval.first;
49  std::vector<std::uint64_t> &output_sizes = retval.second;
50 
51  input_sizes.resize(w_params[0].u_param);
52  output_sizes.resize(w_params[1].u_param);
53 
54  const std::size_t NumWorkloadParams = input_sizes.size() + output_sizes.size() + 2;
55 
56  if (input_sizes.size() > HEBENCH_MAX_OP_PARAMS)
57  {
58  std::stringstream ss;
59  ss << "Number of input parameters for the operation must be, at most, " << HEBENCH_MAX_OP_PARAMS
60  << ", but " << input_sizes.size() << "received.";
61  throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
62  } // end if
63 
64  if (w_params.size() < NumWorkloadParams)
65  {
66  std::stringstream ss;
67  ss << "Insufficient workload parameters in 'w_params'. Expected " << NumWorkloadParams
68  << ", but " << w_params.size() << "received.";
69  throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
70  } // end if
71 
72  for (std::size_t i = 0; i < input_sizes.size(); ++i)
73  input_sizes[i] = w_params[i + 2].u_param;
74  for (std::size_t i = 0; i < output_sizes.size(); ++i)
75  output_sizes[i] = w_params[input_sizes.size() + i + 2].u_param;
76 
77  return retval;
78 }
79 
81  const std::vector<hebench::APIBridge::WorkloadParam> &w_params) const
82 {
83  bool retval = false;
84 
85  // return true if benchmark is supported
87  {
88  try
89  {
90  fetchIOVectorSizes(w_params);
91  retval = true;
92  }
93  catch (...)
94  {
95  // workload not supported
96  retval = false;
97  }
98  } // end if
99 
100  return retval;
101 }
102 
104  const Engine &engine,
105  const BenchmarkDescription::Backend &backend_desc,
106  const BenchmarkDescription::Configuration &config) const
107 {
108  (void)engine;
109  std::stringstream ss;
110 
111  output.concrete_descriptor = backend_desc.descriptor;
113  backend_desc.descriptor,
114  config,
116 
117  // workload name
118 
119  auto op_info = fetchIOVectorSizes(config.w_params);
120  ss << BaseWorkloadName << ", " << op_info.first.size() << " Inputs, " << op_info.second.size() << " Outputs";
121 
122  output.workload_name = ss.str();
124  output.operation_params_count = op_info.first.size();
125 }
126 
127 //---------------------
128 // class DataLoader
129 //---------------------
130 
131 DataLoader::Ptr DataLoader::create(const std::vector<std::uint64_t> &input_sizes,
132  const std::vector<std::uint64_t> &max_batch_sizes,
133  const std::vector<std::uint64_t> &output_sizes,
135  const std::string &dataset_filename)
136 {
138  retval->init(input_sizes, max_batch_sizes, output_sizes, data_type, dataset_filename);
139  return retval;
140 }
141 
142 DataLoader::DataLoader()
143 {
144 }
145 
146 void DataLoader::init(const std::vector<std::uint64_t> &input_sizes,
147  const std::vector<std::uint64_t> &max_batch_sizes,
148  const std::vector<std::uint64_t> &output_sizes,
150  const std::string &dataset_filename)
151 {
152  // Load the data for generic operation:
153 
154  if (input_sizes.size() != max_batch_sizes.size())
155  throw std::invalid_argument(IL_LOG_MSG_CLASS("Number of elements in `input_sizes` must match number of elements in `max_batch_sizes`."));
156 
157  PartialDataLoader::init(dataset_filename, data_type,
158  input_sizes.size(),
159  max_batch_sizes.data(),
160  input_sizes.data(),
161  output_sizes.size(),
162  output_sizes.data());
163 
164  // at this point all NativeDataBuffers have been allocated, pointed to the correct locations
165  // and filled with data from the specified dataset file
166 }
167 
168 void DataLoader::computeResult(std::vector<hebench::APIBridge::NativeDataBuffer *> &result,
169  const std::uint64_t *param_data_pack_indices,
171 {
172  // as protected method, parameters should be valid when called
173 
174  (void)result;
175  (void)param_data_pack_indices;
176  (void)data_type;
177 
178  // cannot generate output
179  throw std::logic_error(IL_LOG_MSG_CLASS("Unable to compute output for generic workload operation."));
180 }
181 
182 } // namespace GenericWL
183 } // namespace TestHarness
184 } // namespace hebench
const hebench::APIBridge::BenchmarkDescriptor & descriptor
Benchmark backend descriptor, as retrieved by backend, corresponding to the registration handle h_des...
std::vector< hebench::APIBridge::WorkloadParam > w_params
Set of arguments for workload parameters.
void completeWorkloadDescription(WorkloadDescriptionOutput &output, const Engine &engine, const BenchmarkDescription::Backend &backend_desc, const BenchmarkDescription::Configuration &config) const override
Completes the description for the matched benchmark.
static std::pair< std::vector< std::uint64_t >, std::vector< std::uint64_t > > fetchIOVectorSizes(const std::vector< hebench::APIBridge::WorkloadParam > &w_params)
Retrieves details about the input parameters and results of the generic operation based on the specif...
bool matchBenchmarkDescriptor(const hebench::APIBridge::BenchmarkDescriptor &bench_desc, const std::vector< hebench::APIBridge::WorkloadParam > &w_params) const override
Determines if the represented benchmark can perform the workload described by a specified HEBench ben...
static constexpr hebench::APIBridge::WorkloadParamType::WorkloadParamType WorkloadParameterType
static DataLoader::Ptr create(const std::vector< std::uint64_t > &input_sizes, const std::vector< std::uint64_t > &max_batch_sizes, const std::vector< std::uint64_t > &output_sizes, hebench::APIBridge::DataType data_type, const std::string &dataset_filename)
void computeResult(std::vector< hebench::APIBridge::NativeDataBuffer * > &result, const std::uint64_t *param_data_pack_indices, hebench::APIBridge::DataType data_type) override
Computes result of the operation on the input data given the of the input sample.
static void completeCategoryParams(hebench::APIBridge::BenchmarkDescriptor &out_descriptor, const hebench::APIBridge::BenchmarkDescriptor &in_descriptor, const BenchmarkDescription::Configuration &config, bool force_config)
Completes common elements of category parameters in a descriptor using the specified configuration.
static bool getForceConfigValues()
Specifies whether frontend will override backend descriptors using configuration data or not.
std::size_t operation_params_count
Number of parameters for the represented workload operation.
std::string workload_name
Human-readable friendly name for the represented workload to be used for its description on the repor...
hebench::APIBridge::BenchmarkDescriptor concrete_descriptor
Benchmark descriptor completed with concrete values assigned to configurable fields.
std::string workload_base_name
Human-readable friendly name for the represented workload to be used for its description on the repor...
Bundles values that need to be filled by a workload during completeWorkloadDescription().
void init(hebench::APIBridge::DataType data_type, std::size_t input_dim, const std::size_t *input_sample_count_per_dim, const std::uint64_t *input_count_per_dim, std::size_t output_dim, const std::uint64_t *output_count_per_dim, bool allocate_output)
Initializes dimensions of inputs and outputs. No allocation is performed.
DataType
Defines data types for a workload.
Definition: types.h:379
Workload workload
Workload for the benchmark.
Definition: types.h:529
Defines a benchmark test.
Definition: types.h:527
#define HEBENCH_MAX_OP_PARAMS
Maximum number of parameters supported by an operation.
Definition: types.h:63