HEBench
hebench_logreg_l.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 <bitset>
6 #include <cassert>
7 #include <cstring>
8 #include <iomanip>
9 #include <iostream>
10 #include <sstream>
11 #include <stdexcept>
12 #include <utility>
13 
14 #include "hebench/modules/timer/include/timer.h"
15 
16 #include "hebench/api_bridge/api.h"
17 #include "include/hebench_engine.h"
18 
19 #include "../include/hebench_logreg_l.h"
20 
21 namespace hebench {
22 namespace TestHarness {
23 namespace LogisticRegression {
24 namespace Latency {
25 
26 //----------------------------
27 // class BenchmarkDescription
28 //----------------------------
29 
30 bool BenchmarkDescriptor::m_b_registered = // register the benchmark with the factory
31  hebench::TestHarness::BenchmarkFactory::registerSupportedBenchmark(std::make_shared<BenchmarkDescriptor>());
32 
34  const std::vector<hebench::APIBridge::WorkloadParam> &w_params) const
35 {
36  assert(m_b_registered);
37 
38  // return true if benchmark is supported
39 
40  bool retval =
43 
44  return retval;
45 }
46 
48  const Engine &engine,
49  const BenchmarkDescription::Backend &backend_desc,
50  const BenchmarkDescription::Configuration &config) const
51 {
52  // finish describing workload
53  assert(OpParameterCount == 3);
54  assert(DefaultBatchSize == 1);
55 
56  BenchmarkDescriptorCategory::completeWorkloadDescription(output, engine, backend_desc, config);
57 
58  assert(OpParameterCount == output.operation_params_count);
59 
60  // finish benchmark header description
61 
62  std::stringstream ss;
63  std::uint64_t batch_sizes[OpParameterCount] = { 1, 1, DefaultBatchSize }; // W, b, X
64  std::uint64_t vector_size = fetchVectorSize(config.w_params);
65 
66  std::uint64_t result_batch_size = 1;
67  for (std::size_t param_i = 0; param_i < OpParameterCount; ++param_i)
68  result_batch_size *= batch_sizes[param_i];
69 
70  // complete header with workload specifics
71  ss << ", , P(X = X') = sigmoid";
72  switch (backend_desc.descriptor.workload)
73  {
75  ss << "_pd3";
76  break;
78  ss << "_pd5";
79  break;
81  ss << "_pd7";
82  break;
83  default:
84  // standard sigmoid
85  break;
86  } // end switch
87  ss << "(W . X + b)" << std::endl
88  << ", , , Elements, Batch size" << std::endl;
89  ss << ", , W, " << vector_size << ", " << batch_sizes[DataLoader::Index_W] << std::endl;
90  ss << ", , b, 1, " << batch_sizes[DataLoader::Index_b] << std::endl;
91  ss << ", , X, " << vector_size << ", " << batch_sizes[DataLoader::Index_X] << std::endl;
92  ss << ", , P(X), 1, " << result_batch_size << std::endl;
93 
94  output.workload_header = ss.str();
95 }
96 
98  const DescriptionToken &description_token)
99 {
100  assert(m_b_registered);
101  Benchmark *retval = nullptr;
102 
103  try
104  {
105  retval = new Benchmark(p_engine, description_token);
106  }
107  catch (...)
108  {
109  if (retval)
110  delete retval;
111  throw;
112  }
113 
114  return retval;
115 }
116 
118 {
119  assert(m_b_registered);
120  if (p_bench)
121  delete p_bench;
122 }
123 
124 //-----------------
125 // class Benchmark
126 //-----------------
127 
128 Benchmark::Benchmark(std::shared_ptr<Engine> p_engine,
129  const IBenchmarkDescriptor::DescriptionToken &description_token) :
130  BenchmarkLatency(p_engine, description_token)
131 {
132 }
133 
135 {
136  hebench::Common::EventTimer timer;
137  hebench::Common::TimingReportEvent::Ptr p_timing_event;
138  std::uint64_t vector_size;
139  std::uint64_t batch_sizes[BenchmarkDescriptor::OpParameterCount] = { 1, 1, BenchmarkDescriptor::DefaultBatchSize }; // W, b, X
140  std::stringstream ss;
141 
142  vector_size = BenchmarkDescriptor::fetchVectorSize(this->getBenchmarkConfiguration().w_params);
143 
144  std::cout << IOS_MSG_INFO << hebench::Logging::GlobalLogger::log("Preparing workload.") << std::endl;
145 
147  switch (this->getBackendDescription().descriptor.workload)
148  {
151  break;
154  break;
157  break;
158  default:
160  break;
161  } // end switch
162 
163  timer.start();
164  if (this->getBenchmarkConfiguration().dataset_filename.empty())
165  {
166  // generates random values for input and generates (computes) ground truth
167  std::cout << IOS_MSG_INFO << hebench::Logging::GlobalLogger::log("Generating data...") << std::endl;
168  m_data = DataLoader::create(pd,
169  vector_size,
170  batch_sizes[DataLoader::Index_X],
171  this->getBackendDescription().descriptor.data_type);
172  } // end if
173  else
174  {
175  std::stringstream ss;
176  ss << "Loading data from external dataset: " << std::endl
177  << "\"" << this->getBenchmarkConfiguration().dataset_filename << "\"";
178  std::cout << IOS_MSG_INFO << hebench::Logging::GlobalLogger::log(ss.str()) << std::endl;
179  // load values for input and ground truth from file
180  m_data = DataLoader::create(pd,
181  vector_size,
182  batch_sizes[DataLoader::Index_X],
183  this->getBackendDescription().descriptor.data_type,
184  this->getBenchmarkConfiguration().dataset_filename);
185  } // end else
186  p_timing_event = timer.stop<std::milli>();
187 
188  ss = std::stringstream();
189  ss << "Total data loaded: " << m_data->getTotalDataLoaded() << " bytes";
190  std::cout << IOS_MSG_DONE << hebench::Logging::GlobalLogger::log(ss.str()) << std::endl;
191  ss = std::stringstream();
192  ss << "Elapsed wall time: " << p_timing_event->elapsedWallTime<std::milli>() << " ms";
193  std::cout << IOS_MSG_INFO << hebench::Logging::GlobalLogger::log(ss.str()) << std::endl;
194  ss = std::stringstream();
195  ss << "Elapsed CPU time: " << p_timing_event->elapsedCPUTime<std::milli>() << " ms";
196  std::cout << IOS_MSG_INFO << hebench::Logging::GlobalLogger::log(ss.str()) << std::endl;
197 }
198 
200  const std::uint64_t *param_data_pack_indices,
201  const std::vector<hebench::APIBridge::NativeDataBuffer *> &outputs,
202  hebench::APIBridge::DataType data_type) const
203 {
204  assert(dataset->getParameterCount() == BenchmarkDescriptorCategory::OpParameterCount
205  && dataset->getResultCount() == BenchmarkDescriptorCategory::OpResultCount);
206 
207  return BenchmarkLatency::validateResult(dataset, param_data_pack_indices, outputs, data_type);
208 }
209 
210 } // namespace Latency
211 } // namespace LogisticRegression
212 } // namespace TestHarness
213 } // 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.
std::string dataset_filename
File containing data for the benchmark. If empty string, benchmarks that can auto generate the datase...
static bool registerSupportedBenchmark(std::shared_ptr< IBenchmarkDescriptor > p_desc_obj)
Registers a benchmark description object that represents one of the supported workloads.
Base class for workload benchmarks in the latency category.
Token returned by a successful call to IBenchmarkDescriptor::matchBenchmarkDescriptor().
std::shared_ptr< IDataLoader > Ptr
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...
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::uint64_t fetchVectorSize(const std::vector< hebench::APIBridge::WorkloadParam > &w_params)
static DataLoader::Ptr create(PolynomialDegree polynomial_degree, std::uint64_t vector_size, std::uint64_t batch_size_input, hebench::APIBridge::DataType data_type)
hebench::TestHarness::PartialBenchmark * createBenchmark(std::shared_ptr< Engine > p_engine, const DescriptionToken &description_token) override
Creates the represented IBenchmark object that can perform the workload specified by the HEBench benc...
void destroyBenchmark(hebench::TestHarness::PartialBenchmark *p_bench) override
Destroys an object returned by createBenchmark().
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.
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...
bool validateResult(IDataLoader::Ptr dataset, const std::uint64_t *param_data_pack_indices, const std::vector< hebench::APIBridge::NativeDataBuffer * > &p_outputs, hebench::APIBridge::DataType data_type) const override
Validates the result of an operation against the ground truth.
void init() override
Initializes the partial benchmark members.
virtual bool validateResult(IDataLoader::Ptr dataset, const std::uint64_t *param_data_pack_indices, const std::vector< hebench::APIBridge::NativeDataBuffer * > &outputs, hebench::APIBridge::DataType data_type) const
Validates the result of an operation against the ground truth.
std::string workload_header
Workload specific information to be added to the report header.
std::size_t operation_params_count
Number of parameters for the represented workload operation.
Bundles values that need to be filled by a workload during completeWorkloadDescription().
const BenchmarkDescription::Backend & getBackendDescription() const
Allows read-only access to this benchmark backend description.
const BenchmarkDescription::Configuration & getBenchmarkConfiguration() const
Allows read-only access to this benchmark configuration.
#define IOS_MSG_DONE
#define IOS_MSG_INFO
DataType
Defines data types for a workload.
Definition: types.h:379
Category category
Category for the benchmark.
Definition: types.h:531
Workload workload
Workload for the benchmark.
Definition: types.h:529
@ LogisticRegression_PolyD3
Definition: types.h:203
@ LogisticRegression_PolyD7
Definition: types.h:247
@ LogisticRegression_PolyD5
Definition: types.h:225
Defines a benchmark test.
Definition: types.h:527