9 #include "../include/hebench_matmult.h"
12 namespace TestHarness {
33 std::array<std::pair<std::uint64_t, std::uint64_t>,
OpParameterCount> retval;
39 <<
", but " << w_params.size() <<
"received.";
40 throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
48 ss <<
"Invalid type for workload parameter " << i
49 <<
". Expected type ID " <<
WorkloadParameterType[i] <<
", but " << w_params[i].data_type <<
" received.";
50 throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
52 else if (w_params[i].u_param <= 0)
55 ss <<
"Invalid matrix size in workload parameter " << i
56 <<
". Expected positive integer, but " << w_params[i].u_param <<
" received.";
57 throw std::invalid_argument(IL_LOG_MSG_CLASS(ss.str()));
60 retval.at(0) = std::make_pair(w_params.at(0).u_param, w_params.at(1).u_param);
61 retval.at(1) = std::make_pair(w_params.at(1).u_param, w_params.at(2).u_param);
84 << mat_dims[0].first <<
"x" << mat_dims[0].second <<
") x ("
85 << mat_dims[1].first <<
"x" << mat_dims[1].second <<
")";
93 const std::vector<hebench::APIBridge::WorkloadParam> &w_params)
const
129 void *mat_result, std::uint64_t rows, std::uint64_t cols,
130 double mean,
double stddev);
132 void *mat_result,
const void *mat_a,
const void *mat_b,
133 std::uint64_t rows_a, std::uint64_t cols_a, std::uint64_t cols_b);
140 static void matMul(T *mat_result,
const T *mat_a,
const T *mat_b,
141 std::uint64_t rows_a, std::uint64_t cols_a, std::uint64_t cols_b)
144 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null `mat_result`"));
146 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null `mat_a`"));
148 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null `mat_b`"));
151 for (std::uint64_t row_a = 0; row_a < rows_a; ++row_a)
152 for (std::uint64_t col_b = 0; col_b < cols_b; ++col_b)
154 mat_result[row_a * cols_b + col_b] = 0;
155 for (std::uint64_t col_a = 0; col_a < cols_a; ++col_a)
157 std::uint64_t row_b = col_a;
158 mat_result[row_a * cols_b + col_b] += mat_a[row_a * cols_a + col_a] * mat_b[row_b * cols_b + col_b];
165 void *mat_result, std::uint64_t rows, std::uint64_t cols,
166 double mean,
double stddev)
169 mat_result, rows * cols,
175 const void *mat_a,
const void *mat_b,
176 uint64_t rows_a, uint64_t cols_a, uint64_t cols_b)
181 matMul<std::int32_t>(
reinterpret_cast<std::int32_t *
>(mat_result),
182 reinterpret_cast<const std::int32_t *
>(mat_a),
reinterpret_cast<const std::int32_t *
>(mat_b),
183 rows_a, cols_a, cols_b);
187 matMul<std::int64_t>(
reinterpret_cast<std::int64_t *
>(mat_result),
188 reinterpret_cast<const std::int64_t *
>(mat_a),
reinterpret_cast<const std::int64_t *
>(mat_b),
189 rows_a, cols_a, cols_b);
193 matMul<float>(
reinterpret_cast<float *
>(mat_result),
194 reinterpret_cast<const float *
>(mat_a),
reinterpret_cast<const float *
>(mat_b),
195 rows_a, cols_a, cols_b);
199 matMul<double>(
reinterpret_cast<double *
>(mat_result),
200 reinterpret_cast<const double *
>(mat_a),
reinterpret_cast<const double *
>(mat_b),
201 rows_a, cols_a, cols_b);
205 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Unknown data type."));
215 std::uint64_t batch_size_mat_a,
216 std::uint64_t batch_size_mat_b,
220 retval->init(rows_a, cols_a, cols_b, batch_size_mat_a, batch_size_mat_b, data_type);
225 std::uint64_t expected_sample_size_mat_a,
226 std::uint64_t expected_sample_size_mat_b,
228 const std::string &dataset_filename)
231 retval->init(rows_a, cols_a, cols_b,
232 expected_sample_size_mat_a, expected_sample_size_mat_b,
238 DataLoader::DataLoader() :
239 m_rows_a(0), m_cols_a(0), m_cols_b(0)
243 void DataLoader::init(std::uint64_t rows_a, std::uint64_t cols_a, std::uint64_t cols_b,
244 std::uint64_t batch_size_mat_a,
245 std::uint64_t batch_size_mat_b,
252 std::size_t batch_sizes[InputDim0 + OutputDim0] = {
255 batch_size_mat_a * batch_size_mat_b
259 std::pair<std::uint64_t, std::uint64_t> mat_dims[InputDim0 + OutputDim0];
260 mat_dims[0] = std::make_pair(rows_a, cols_a);
261 mat_dims[1] = std::make_pair(cols_a, cols_b);
262 mat_dims[2] = std::make_pair(rows_a, cols_b);
270 std::uint64_t sample_vector_sizes[InputDim0 + OutputDim0];
271 for (std::size_t i = 0; i < InputDim0 + OutputDim0; ++i)
273 sample_vector_sizes[i] = mat_dims[i].first * mat_dims[i].second;
278 InputDim0, batch_sizes, sample_vector_sizes,
279 OutputDim0, sample_vector_sizes + InputDim0,
287 for (std::size_t mat_i = 0; mat_i < InputDim0; ++mat_i)
289 for (std::uint64_t i = 0; i < batch_sizes[mat_i]; ++i)
294 mat_dims[mat_i].first,
295 mat_dims[mat_i].second,
302 for (std::uint64_t m0_i = 0; m0_i < batch_sizes[0]; ++m0_i)
304 for (std::uint64_t m1_i = 0; m1_i < batch_sizes[1]; ++m1_i)
307 std::uint64_t ppi[] = { m0_i, m1_i };
315 mat_dims[0].first, mat_dims[0].second,
323 void DataLoader::init(std::uint64_t rows_a, std::uint64_t cols_a, std::uint64_t cols_b,
324 std::uint64_t max_sample_size_mat_a,
325 std::uint64_t max_sample_size_mat_b,
327 const std::string &dataset_filename)
333 std::size_t max_sample_sizes[InputDim0 + OutputDim0] = {
334 max_sample_size_mat_a,
335 max_sample_size_mat_b,
336 max_sample_size_mat_a * max_sample_size_mat_b
340 std::pair<std::uint64_t, std::uint64_t> mat_dims[InputDim0 + OutputDim0];
341 mat_dims[0] = std::make_pair(rows_a, cols_a);
342 mat_dims[1] = std::make_pair(cols_a, cols_b);
343 mat_dims[2] = std::make_pair(rows_a, cols_b);
351 std::uint64_t sample_vector_sizes[InputDim0 + OutputDim0];
352 for (std::size_t i = 0; i < InputDim0 + OutputDim0; ++i)
354 sample_vector_sizes[i] = mat_dims[i].first * mat_dims[i].second;
358 InputDim0, max_sample_sizes, sample_vector_sizes,
359 OutputDim0, sample_vector_sizes + InputDim0);
366 const std::uint64_t *param_data_pack_indices,
374 this->getParameterData(0).p_buffers[param_data_pack_indices[0]].p,
375 this->getParameterData(1).p_buffers[param_data_pack_indices[1]].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.
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::array< std::pair< std::uint64_t, std::uint64_t >, OpParameterCount > fetchMatrixSizes(const std::vector< hebench::APIBridge::WorkloadParam > &w_params)
fetchMatrixSizes
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
static constexpr std::uint64_t WorkloadParameterCount
static constexpr std::uint64_t OpParameterCount
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 hebench::APIBridge::WorkloadParamType::WorkloadParamType WorkloadParameterType[WorkloadParameterCount]
static constexpr std::uint64_t OpResultCount
Static helper class to generate matrix data for all supported data types.
static void generateRandomMatrixN(hebench::APIBridge::DataType data_type, void *mat_result, std::uint64_t rows, std::uint64_t cols, double mean, double stddev)
static void matMul(hebench::APIBridge::DataType data_type, void *mat_result, const void *mat_a, const void *mat_b, std::uint64_t rows_a, std::uint64_t cols_a, std::uint64_t cols_b)
static DataLoader::Ptr create(std::uint64_t rows_a, std::uint64_t cols_a, std::uint64_t cols_b, std::uint64_t batch_size_mat_a, std::uint64_t batch_size_mat_b, hebench::APIBridge::DataType data_type)
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.
std::shared_ptr< DataLoader > Ptr
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().
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.
@ Int64
64 bits signed integers.
@ UInt64
64 bits unsigned integers.
DataType
Defines data types for a workload.
@ Float32
32 bits IEEE 754 standard floating point real numbers.
@ Int32
32 bits signed integers.
Workload workload
Workload for the benchmark.
Defines a benchmark test.