11 #include <type_traits>
15 #include "../include/hebench_logreg.h"
16 #include "hebench/modules/general/include/hebench_math_utils.h"
19 namespace TestHarness {
43 <<
", but " << w_params.size() <<
"received.";
44 throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
51 ss <<
"Invalid type for workload parameter " << i
52 <<
". Expected type ID " <<
WorkloadParameterType[i] <<
", but " << w_params[i].data_type <<
" received.";
53 throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
55 else if (w_params[i].u_param <= 0)
58 ss <<
"Invalid number of elements for vector in workload parameter " << i
59 <<
". Expected positive integer, but " << w_params[i].u_param <<
" received.";
60 throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
63 retval = w_params.at(0).u_param;
69 const std::vector<hebench::APIBridge::WorkloadParam> &w_params)
const
100 std::stringstream ss;
139 ss <<
" " << vector_size <<
" features";
159 void *result,
const void *w,
const void *b,
const void *input,
160 std::uint64_t feature_count);
166 template <
class T,
class Container>
167 static double evaluatePolynomial(T x,
const Container &coeff);
169 template <
unsigned int degree>
170 static double sigmoid(
double x);
174 T &result,
const T *p_w,
const T &b,
const T *p_input,
175 std::uint64_t feature_count);
178 template <
class T,
class Container>
179 inline double DataGeneratorHelper::evaluatePolynomial(T x,
const Container &coeff)
184 auto it = std::rbegin(coeff);
186 for (++it; it != std::rend(coeff); ++it)
187 retval = retval * x + *it;
193 inline double DataGeneratorHelper::sigmoid<0>(
double x)
195 return 1.0 / (1.0 + std::exp(-x));
199 inline double DataGeneratorHelper::sigmoid<3>(
double x)
202 static const std::array<double, 4> poly = { 0.5, 0.15012, 0.0, -0.0015930078125 };
203 return evaluatePolynomial(x, poly);
207 inline double DataGeneratorHelper::sigmoid<5>(
double x)
210 static const std::array<double, 6> poly = { 0.5, 0.19131, 0.0, -0.0045963, 0.0, 0.0000412332000732421875 };
211 return evaluatePolynomial(x, poly);
215 inline double DataGeneratorHelper::sigmoid<7>(
double x)
218 static const std::array<double, 8> poly = { 0.5, 0.21687, 0.0, -0.00819154296875, 0.0, 0.0001658331298828125, 0.0, -0.00000119561672210693359375 };
219 return evaluatePolynomial(x, poly);
224 T &result,
const T *p_w,
const T &b,
const T *p_input,
225 std::uint64_t feature_count)
228 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null 'p_w'."));
230 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null 'p_input'."));
232 T linear_regression = std::inner_product(p_w, p_w + feature_count, p_input,
static_cast<T
>(0))
237 result =
static_cast<T
>(sigmoid<3>(
static_cast<double>(linear_regression)));
241 result =
static_cast<T
>(sigmoid<5>(
static_cast<double>(linear_regression)));
245 result =
static_cast<T
>(sigmoid<7>(
static_cast<double>(linear_regression)));
249 result =
static_cast<T
>(sigmoid<0>(
static_cast<double>(linear_regression)));
256 void *p_result,
const void *p_w,
const void *p_bias,
const void *p_input,
257 std::uint64_t feature_count)
260 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null 'p_result'."));
262 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null 'p_bias'."));
267 logisticRegressionInference<float>(poly_deg,
268 *
reinterpret_cast<float *
>(p_result),
269 reinterpret_cast<const float *
>(p_w),
270 *
reinterpret_cast<const float *
>(p_bias),
271 reinterpret_cast<const float *
>(p_input),
276 logisticRegressionInference<double>(poly_deg,
277 *
reinterpret_cast<double *
>(p_result),
278 reinterpret_cast<const double *
>(p_w),
279 *
reinterpret_cast<const double *
>(p_bias),
280 reinterpret_cast<const double *
>(p_input),
285 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Data type not supported."));
295 std::uint64_t vector_size,
296 std::uint64_t batch_size_input,
300 retval->init(polynomial_degree, vector_size, batch_size_input, data_type);
305 std::uint64_t vector_size,
306 std::uint64_t batch_size_input,
308 const std::string &dataset_filename)
311 retval->init(polynomial_degree, vector_size, batch_size_input, data_type, dataset_filename);
315 DataLoader::DataLoader() :
316 m_polynomial_degree(PolynomialDegree::None),
321 void DataLoader::init(PolynomialDegree polynomial_degree,
322 std::uint64_t vector_size,
323 std::uint64_t batch_size_input,
328 assert(InputDim0 + OutputDim0 >= 4);
331 std::size_t batch_sizes[InputDim0 + OutputDim0] = {
337 m_polynomial_degree = polynomial_degree;
338 m_vector_size = vector_size;
341 std::uint64_t vector_sample_sizes[InputDim0 + OutputDim0] = {
354 vector_sample_sizes + InputDim0,
362 for (std::size_t vector_i = 0; vector_i < InputDim0; ++vector_i)
364 for (std::uint64_t i = 0; i < batch_sizes[vector_i]; ++i)
376 for (std::uint64_t input_i = 0; input_i < batch_sizes[2]; ++input_i)
379 std::uint64_t ppi[] = { 0, 0, input_i };
394 void DataLoader::init(PolynomialDegree polynomial_degree,
395 std::uint64_t expected_vector_size,
396 std::uint64_t max_batch_size_input,
398 const std::string &dataset_filename)
402 assert(InputDim0 + OutputDim0 >= 4);
405 std::size_t batch_sizes[InputDim0 + OutputDim0] = {
408 max_batch_size_input,
411 m_polynomial_degree = polynomial_degree;
412 m_vector_size = expected_vector_size;
415 std::uint64_t vector_sample_sizes[InputDim0 + OutputDim0] = {
416 expected_vector_size,
418 expected_vector_size,
428 vector_sample_sizes + InputDim0);
435 const std::uint64_t *param_data_pack_indices,
440 assert(param_data_pack_indices[
Index_W] == 0 && param_data_pack_indices[
Index_b] == 0);
445 this->getParameterData(
Index_W).p_buffers[0].p,
446 this->getParameterData(
Index_b).p_buffers[0].p,
447 this->getParameterData(
Index_X).p_buffers[param_data_pack_indices[
Index_X]].p,
const hebench::APIBridge::BenchmarkDescriptor & descriptor
Benchmark backend descriptor, as retrieved by backend, corresponding to the registration handle h_des...
Specifies a benchmark configuration.
std::vector< hebench::APIBridge::WorkloadParam > w_params
Set of arguments for workload parameters.
std::uint64_t default_min_test_time_ms
Default minimum test time in milliseconds.
Static helper class to generate vector data for all supported data types.
static void generateRandomVectorN(hebench::APIBridge::DataType data_type, void *result, std::uint64_t elem_count, double mean, double stddev)
Generates normally distributed random data of the specified type.
static std::size_t sizeOf(hebench::APIBridge::DataType data_type)
static hebench::APIBridge::WorkloadParamType::WorkloadParamType WorkloadParameterType[WorkloadParameterCount]
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 const char * BaseWorkloadName
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 constexpr std::uint64_t OpParameterCount
static constexpr std::uint64_t OpResultCount
static std::uint64_t fetchVectorSize(const std::vector< hebench::APIBridge::WorkloadParam > &w_params)
static constexpr std::uint64_t WorkloadParameterCount
Static helper class to generate data for all supported data types.
static void logisticRegressionInference(hebench::APIBridge::DataType data_type, DataLoader::PolynomialDegree poly_deg, void *result, const void *w, const void *b, const void *input, std::uint64_t feature_count)
DataGeneratorHelper()=default
static constexpr std::size_t Index_W
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 constexpr std::size_t Index_b
std::shared_ptr< DataLoader > Ptr
static constexpr std::size_t Index_X
static DataLoader::Ptr create(PolynomialDegree polynomial_degree, std::uint64_t vector_size, std::uint64_t batch_size_input, hebench::APIBridge::DataType data_type)
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().
const hebench::APIBridge::DataPack & getResultData(std::uint64_t param_position) const override
Data pack corresponding to the specified component of the result.
const hebench::APIBridge::DataPack & getParameterData(std::uint64_t param_position) const override
Data pack for specified operation parameter (operand).
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.
std::uint64_t getResultIndex(const std::uint64_t *param_data_pack_indices) const override
Computes the index of the result NativeDataBuffer given the indices of the input data.
WorkloadParamType
Defines the possible data types for a workload flexible parameter.
@ Float64
64 bits IEEE 754 standard floating point real numbers.
@ UInt64
64 bits unsigned integers.
DataType
Defines data types for a workload.
@ Float32
32 bits IEEE 754 standard floating point real numbers.
std::uint64_t min_test_time_ms
Specifies the minimum time, in milliseconds, to run the test.
CategoryParams cat_params
Parameters for the category.
Workload workload
Workload for the benchmark.
@ LogisticRegression_PolyD3
@ LogisticRegression_PolyD7
@ LogisticRegression_PolyD5
Defines a benchmark test.
VectorSize LogisticRegression