HEBench
datagen_helper.h
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_DataGenHelper_H_0596d40a3cce4b108a81595c50eb286d
6 #define _HEBench_Harness_DataGenHelper_H_0596d40a3cce4b108a81595c50eb286d
7 
8 #include <cmath>
9 #include <mutex>
10 #include <set>
11 #include <string>
12 #include <type_traits>
13 
14 #include "hebench/modules/logging/include/logging.h"
15 
18 
19 namespace hebench {
20 namespace TestHarness {
21 
23 {
24 public:
25  DISABLE_COPY(DataLoaderCompute)
26  DISABLE_MOVE(DataLoaderCompute)
27 private:
28  IL_DECLARE_CLASS_NAME(DataLoaderCompute)
29 public:
30  ~DataLoaderCompute() override {}
31  ResultDataPtr getResultFor(const std::uint64_t *param_data_pack_indices) override;
32 
33 protected:
35 
46  virtual void computeResult(std::vector<hebench::APIBridge::NativeDataBuffer *> &result,
47  const std::uint64_t *param_data_pack_indices,
48  hebench::APIBridge::DataType data_type) = 0;
49 
50 private:
51  // can we find a thread friendly/safe solution?
52  std::vector<std::shared_ptr<hebench::APIBridge::DataPack>> &getLocalTempResult();
53  std::shared_ptr<std::vector<std::shared_ptr<hebench::APIBridge::DataPack>>> m_p_temp_result;
54 };
55 
62 {
63 private:
64  IL_DECLARE_CLASS_NAME(DataGeneratorHelper)
65 
66 public:
67  virtual ~DataGeneratorHelper() = default;
68 
78  void *result, std::uint64_t elem_count,
79  double min_val, double max_val);
80 
90  void *result, std::uint64_t elem_count,
91  double mean, double stddev);
92 
93  static std::uint64_t generateRandomIntU(std::uint64_t min_val, std::uint64_t max_val);
94 
101  static std::vector<std::uint64_t> generateRandomIntersectionIndicesU(std::uint64_t elem_count, std::uint64_t indices_count = 0);
102 
103 protected:
104  DataGeneratorHelper() = default;
105 
106 private:
107  template <class T>
108  static void generateRandomVectorU(T *result, std::uint64_t elem_count,
109  T min_val, T max_val);
110  template <class T>
111  static void generateRandomVectorN(T *result, std::uint64_t elem_count,
112  T mean, T stddev);
113 
114 private:
115  static std::mutex m_mtx_rand;
116 };
117 
118 } // namespace TestHarness
119 } // namespace hebench
120 
121 #endif // defined _HEBench_Harness_DataGenerator_H_0596d40a3cce4b108a81595c50eb286d
Static helper class to generate vector data for all supported data types.
static std::vector< std::uint64_t > generateRandomIntersectionIndicesU(std::uint64_t elem_count, std::uint64_t indices_count=0)
Generates uniform random amount of indices.
static std::uint64_t generateRandomIntU(std::uint64_t min_val, std::uint64_t max_val)
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 void generateRandomVectorU(hebench::APIBridge::DataType data_type, void *result, std::uint64_t elem_count, double min_val, double max_val)
Generates uniform random data of the specified type.
virtual void computeResult(std::vector< hebench::APIBridge::NativeDataBuffer * > &result, const std::uint64_t *param_data_pack_indices, hebench::APIBridge::DataType data_type)=0
Computes result of the operation on the input data given the of the input sample.
ResultDataPtr getResultFor(const std::uint64_t *param_data_pack_indices) override
getResultFor
std::shared_ptr< ResultData > ResultDataPtr
Base class for data loaders and data generators.
DataType
Defines data types for a workload.
Definition: types.h:379