11 #include "../include/datagen_helper.h"
15 namespace TestHarness {
17 std::mutex DataGeneratorHelper::m_mtx_rand;
26 throw std::logic_error(IL_LOG_MSG_CLASS(
"Not initialized."));
37 std::shared_ptr<std::vector<std::shared_ptr<hebench::APIBridge::DataPack>>> p_tmp_packs =
39 std::vector<std::shared_ptr<hebench::APIBridge::DataPack>> &tmp_packs = *p_tmp_packs;
41 std::vector<hebench::APIBridge::NativeDataBuffer *> result(tmp_packs.size());
42 for (std::size_t result_component_i = 0; result_component_i < result.size(); ++result_component_i)
44 assert(tmp_packs[result_component_i]
45 && tmp_packs[result_component_i]->buffer_count > 0
46 && tmp_packs[result_component_i]->p_buffers
47 && tmp_packs[result_component_i]->p_buffers[0].p
48 && tmp_packs[result_component_i]->p_buffers[0].size > 0);
49 result[result_component_i] = &(tmp_packs[result_component_i]->p_buffers[0]);
55 p_retval->result.assign(result.begin(), result.end());
56 p_retval->sample_index = r_i;
57 p_retval->reserved0 = p_tmp_packs;
71 std::uniform_real_distribution<double> rnd(min_val, max_val);
72 for (std::uint64_t i = 0; i < elem_count; ++i)
74 std::lock_guard<std::mutex> lock(m_mtx_rand);
83 std::normal_distribution<double> rnd(mean, stddev);
84 for (std::uint64_t i = 0; i < elem_count; ++i)
86 std::lock_guard<std::mutex> lock(m_mtx_rand);
92 void *result, std::uint64_t elem_count,
93 double min_val,
double max_val)
98 generateRandomVectorU<std::int32_t>(
reinterpret_cast<std::int32_t *
>(result), elem_count,
99 static_cast<std::int32_t
>(min_val),
static_cast<std::int32_t
>(max_val));
103 generateRandomVectorU<std::int64_t>(
reinterpret_cast<std::int64_t *
>(result), elem_count,
104 static_cast<std::int64_t
>(min_val),
static_cast<std::int64_t
>(max_val));
108 generateRandomVectorU<float>(
reinterpret_cast<float *
>(result), elem_count,
109 static_cast<float>(min_val),
static_cast<float>(max_val));
113 generateRandomVectorU<double>(
reinterpret_cast<double *
>(result), elem_count,
114 static_cast<double>(min_val),
static_cast<double>(max_val));
118 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Unknown data type."));
124 void *result, std::uint64_t elem_count,
125 double mean,
double stddev)
130 generateRandomVectorN<std::int32_t>(
reinterpret_cast<std::int32_t *
>(result), elem_count,
131 static_cast<std::int32_t
>(mean),
static_cast<std::int32_t
>(stddev));
135 generateRandomVectorN<std::int64_t>(
reinterpret_cast<std::int64_t *
>(result), elem_count,
136 static_cast<std::int64_t
>(mean),
static_cast<std::int64_t
>(stddev));
140 generateRandomVectorN<float>(
reinterpret_cast<float *
>(result), elem_count,
141 static_cast<float>(mean),
static_cast<float>(stddev));
145 generateRandomVectorN<double>(
reinterpret_cast<double *
>(result), elem_count,
146 static_cast<double>(mean),
static_cast<double>(stddev));
150 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Unknown data type."));
157 std::uniform_int_distribution<std::uint64_t> rnd(min_val, max_val);
163 std::vector<std::uint64_t> retval;
165 if (indices_count <= 0)
168 retval.resize(elem_count);
169 std::iota(retval.begin(), retval.end(), 0);
172 return std::vector<std::uint64_t>(retval.begin(), retval.begin() + indices_count);
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
bool isInitialized() const
ResultDataPtr getResultFor(const std::uint64_t *param_data_pack_indices) override
getResultFor
bool hasResults() const
Retrieves whether buffers to contain output data have been allocated or not.
std::vector< std::shared_ptr< hebench::APIBridge::DataPack > > getResultTempDataPacks() const
Retrieves a pre-allocated result providing memory space to store a single operation result sample.
hebench::APIBridge::DataType getDataType() const
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.
static decltype(m_rand) & get()
@ Float64
64 bits IEEE 754 standard floating point real numbers.
@ Int64
64 bits signed integers.
DataType
Defines data types for a workload.
@ Float32
32 bits IEEE 754 standard floating point real numbers.
@ Int32
32 bits signed integers.