16 #include "../include/generic_wl_benchmark.h"
17 #include "../include/generic_wl_engine.h"
33 m_descriptor.category = category;
36 m_descriptor.cat_params.min_test_time_ms = 0;
37 m_descriptor.cat_params.latency.warmup_iterations_count = 1;
41 m_descriptor.scheme = HEBENCH_HE_SCHEME_PLAIN;
42 m_descriptor.security = HEBENCH_HE_SECURITY_NONE;
43 m_descriptor.other = 0;
50 default_workload_params.length_InputParam(0) = 2;
51 default_workload_params.length_InputParam(1) = 2;
52 default_workload_params.length_ResultComponent(0) = 2;
53 default_workload_params.length_ResultComponent(1) = 2;
54 default_workload_params.length_ResultComponent(2) = 1;
55 this->addDefaultParameters(default_workload_params);
58 ExampleBenchmarkDescription::~ExampleBenchmarkDescription()
70 ExampleEngine &ex_engine =
dynamic_cast<ExampleEngine &
>(engine);
71 return new ExampleBenchmark(ex_engine, m_descriptor, *p_params);
79 ExampleBenchmark *p_tmp =
dynamic_cast<ExampleBenchmark *
>(p_bench);
88 ExampleBenchmark::ExampleBenchmark(ExampleEngine &engine,
91 hebench::cpp::BaseBenchmark(engine, bench_desc, bench_params)
96 if (bench_params.
count < ExampleBenchmarkDescription::NumWorkloadParams)
104 if (w_params.n() != ParametersCount
105 || w_params.m() != ResultComponentsCount)
108 if (w_params.length_InputParam(0) != 2
109 || w_params.length_InputParam(1) != 2)
112 if (w_params.length_ResultComponent(0) != 2
113 || w_params.length_ResultComponent(1) != 2
114 || w_params.length_ResultComponent(2) != 1)
119 ExampleBenchmark::~ExampleBenchmark()
126 if (p_parameters->
pack_count != ParametersCount)
132 InternalInputData input_data;
134 for (std::size_t param_i = 0; param_i < input_data.size(); ++param_i)
136 std::vector<std::vector<double>> &input_param_batch = input_data[param_i];
139 for (std::size_t sample_i = 0; sample_i < input_param_batch.size(); ++sample_i)
142 if (!sample_buffer.
p)
145 const double *p_raw_buffer =
reinterpret_cast<const double *
>(sample_buffer.
p);
146 input_param_batch[sample_i].assign(p_raw_buffer, p_raw_buffer + (sample_buffer.
size /
sizeof(
double)));
151 return this->getEngine().template createHandle<decltype(input_data)>(
sizeof(InternalInputData), 0,
152 std::move(input_data));
162 const InternalResultData &encoded =
163 this->getEngine().template retrieveFromHandle<InternalResultData>(encoded_data);
169 std::uint64_t min_component_count = std::min(p_native->
pack_count,
static_cast<std::uint64_t
>(ResultComponentsCount));
170 for (std::size_t component_i = 0; component_i < min_component_count; ++component_i)
176 std::uint64_t min_sample_count = std::min(p_native_param->
buffer_count, encoded.size());
177 for (std::size_t sample_i = 0; sample_i < min_sample_count; ++sample_i)
181 if (native_sample.
p && native_sample.
size > 0)
183 std::uint64_t min_size = std::min(native_sample.
size /
sizeof(
double),
184 encoded[sample_i][component_i].size());
185 double *p_raw_buffer =
reinterpret_cast<double *
>(native_sample.
p);
186 std::copy(encoded[sample_i][component_i].begin(), encoded[sample_i][component_i].begin() + min_size,
197 return this->getEngine().duplicateHandle(encoded_data);
203 return this->getEngine().duplicateHandle(encrypted_data);
218 return this->getEngine().duplicateHandle(p_local_data[0]);
224 if (count > 0 && !p_local_data)
236 p_local_data[0] = this->getEngine().duplicateHandle(remote_data);
246 const InternalInputData &InputParams = this->getEngine().template retrieveFromHandle<InternalInputData>(h_remote_packed);
247 assert(InputParams.size() == ParametersCount);
249 for (std::size_t i = 0; i < InputParams.size(); ++i)
252 if (p_param_indexers[i].value_index != 0 || p_param_indexers[i].batch_size != InputParams[i].size())
257 InternalResultData retval;
258 retval.reserve(InputParams[0].size() * InputParams[1].size());
262 for (std::size_t sample_0_i = 0; sample_0_i < InputParams[0].size(); ++sample_0_i)
264 for (std::size_t sample_1_i = 0; sample_1_i < InputParams[1].size(); ++sample_1_i)
266 assert(InputParams[0][sample_0_i].size() == w_params.length_InputParam(0));
267 assert(InputParams[1][sample_0_i].size() == w_params.length_InputParam(1));
268 std::array<std::vector<double>, ResultComponentsCount> ResultComponents;
271 ResultComponents[0].resize(w_params.length_ResultComponent(0));
272 std::transform(InputParams[0][sample_0_i].begin(), InputParams[0][sample_0_i].end(),
273 InputParams[1][sample_1_i].begin(), ResultComponents[0].begin(),
274 std::plus<double>());
277 ResultComponents[1].resize(w_params.length_ResultComponent(1));
278 std::transform(InputParams[0][sample_0_i].begin(), InputParams[0][sample_0_i].end(),
279 InputParams[1][sample_1_i].begin(), ResultComponents[1].begin(),
280 std::minus<double>());
283 ResultComponents[2].resize(w_params.length_ResultComponent(2));
284 ResultComponents[2].front() = std::inner_product(InputParams[0][sample_0_i].begin(), InputParams[0][sample_0_i].end(),
285 InputParams[1][sample_1_i].begin(), 0.0);
287 retval.emplace_back(std::move(ResultComponents));
292 return this->getEngine().template createHandle<decltype(retval)>(
sizeof(retval), 0,
Top level opaque benchmark class.
Base class that encapsulates common behavior of backend engines.
Wraps around flexible workload parameters required for a generic workload.
#define HEBERROR_MSG_CLASS(message)
@ Float64
64 bits IEEE 754 standard floating point real numbers.
ErrorCode encrypt(Handle h_benchmark, Handle h_plaintext, Handle *h_ciphertext)
Encrypts a plain text into a cipher text.
Category
Defines all possible categories for each workload.
ErrorCode operate(Handle h_benchmark, Handle h_remote_packed_params, const ParameterIndexer *p_param_indexers, uint64_t indexers_count, Handle *h_remote_output)
Performs the workload operation of the benchmark.
std::uint64_t count
Number of workload parameters.
DataPack * p_data_packs
Collection of data packs.
ErrorCode encode(Handle h_benchmark, const DataPackCollection *p_parameters, Handle *h_plaintext)
Given a pack of parameters in raw, native data format, encodes them into plain text suitable for back...
ErrorCode decrypt(Handle h_benchmark, Handle h_ciphertext, Handle *h_plaintext)
Decrypts a cipher text into corresponding plain text.
ErrorCode store(Handle h_benchmark, Handle h_remote, Handle *h_local_packed_params, std::uint64_t local_count)
Retrieves the specified data from the backend.
std::uint64_t pack_count
Number of data packs in the collection.
ErrorCode createBenchmark(Handle h_engine, Handle h_bench_desc, const WorkloadParams *p_params, Handle *h_benchmark)
Instantiates a benchmark on the backend.
std::uint64_t size
Size of underlying data.
void * p
Pointer to underlying data.
ErrorCode load(Handle h_benchmark, const Handle *h_local_packed_params, std::uint64_t local_count, Handle *h_remote)
Loads the specified data from the local host into the remote backend to use as parameter during a cal...
std::uint64_t buffer_count
Number of data buffers in p_buffers.
ErrorCode decode(Handle h_benchmark, Handle h_plaintext, DataPackCollection *p_native)
Decodes plaintext data into the appropriate raw, native format.
NativeDataBuffer * p_buffers
Array of data buffers for parameter.
Defines a benchmark test.
Defines a data package for an operation.
Defines a collection of data packs.
Specifies the parameters for a workload.
Structure to contain flexible data.
std::string to_string(const std::string_view &s)
#define HEBENCH_HE_PARAM_FLAGS_ALL_PLAIN
#define HEBENCH_ECODE_INVALID_ARGS
Indicates invalid arguments to function call.
#define HEBENCH_ECODE_CRITICAL_ERROR
Specifies a critical error.