HEBench
hebench_ibenchmark.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_IBenchmark_H_0596d40a3cce4b108a81595c50eb286d
6 #define _HEBench_Harness_IBenchmark_H_0596d40a3cce4b108a81595c50eb286d
7 
8 #include <memory>
9 #include <string>
10 #include <unordered_set>
11 #include <vector>
12 
13 #include "hebench/modules/general/include/nocopy.h"
14 #include "hebench/modules/logging/include/logging.h"
15 
18 #include "hebench_idata_loader.h"
20 
21 namespace hebench {
22 namespace TestHarness {
23 
24 class Engine;
25 class IBenchmark;
26 class PartialBenchmark;
27 
44 {
45 public:
46  DISABLE_COPY(IBenchmarkDescriptor)
47  DISABLE_MOVE(IBenchmarkDescriptor)
48 
49 public:
60  {
61  public:
63  {
64  public:
65  friend class IBenchmarkDescriptor;
66 
67  private:
69  };
70  typedef std::shared_ptr<DescriptionToken> Ptr;
71 
72  public:
74  const BenchmarkDescription::Backend &backend_desc,
76  const BenchmarkDescription::Description &text_desc,
77  const FriendKeyCreation &) :
78  m_p_caller(&caller),
79  m_backend_desc(backend_desc), m_config(config), m_description(text_desc)
80  {
81  }
82 
83  IBenchmarkDescriptor *getDescriptor() { return m_p_caller; }
84  const BenchmarkDescription::Backend &getBackendDescription() const { return m_backend_desc; }
86  const BenchmarkDescription::Description &getDescription() const { return m_description; }
87 
88  private:
89  IBenchmarkDescriptor *m_p_caller;
90  BenchmarkDescription::Backend m_backend_desc;
93  };
94 
95 public:
96  IBenchmarkDescriptor() = default;
97  virtual ~IBenchmarkDescriptor() = default;
98 
120  const BenchmarkDescription::Backend &backend_desc,
121  const BenchmarkDescription::Configuration &config) const = 0;
122 
140  virtual PartialBenchmark *createBenchmark(std::shared_ptr<Engine> p_engine,
141  const DescriptionToken &description_token) = 0;
147  virtual void destroyBenchmark(PartialBenchmark *p_bench) = 0;
148 
149 protected:
156  const BenchmarkDescription::Description &text_desc) const;
157 
158 private:
160 };
161 
183 {
184 public:
185  DISABLE_COPY(PartialBenchmarkDescriptor)
186  DISABLE_MOVE(PartialBenchmarkDescriptor)
187 private:
188  IL_DECLARE_CLASS_NAME(PartialBenchmarkDescriptor)
189 
190 public:
205  static bool getForceConfigValues() { return m_b_force_config_value; }
219  static void setForceConfigValues(bool value) { m_b_force_config_value = value; }
220 
256  static std::uint64_t computeSampleSizes(std::uint64_t *sample_sizes,
257  std::size_t param_count,
258  const std::vector<std::uint64_t> &config_sample_sizes,
259  const hebench::APIBridge::BenchmarkDescriptor &bench_desc,
260  std::uint64_t default_sample_size_fallback,
261  bool force_config);
262 
263 public:
265  ~PartialBenchmarkDescriptor() override;
266 
279  const BenchmarkDescription::Backend &backend_desc,
280  const BenchmarkDescription::Configuration &config) const override final;
281 
282 protected:
283  static std::unordered_set<std::size_t> getCipherParamPositions(std::uint32_t cipher_param_mask);
284  static std::string getCategoryName(hebench::APIBridge::Category category);
285  static std::string getDataTypeName(hebench::APIBridge::DataType data_type);
286 
287 protected:
294  {
307  std::string workload_base_name;
312  std::string workload_name;
318  std::string workload_header;
319  };
320 
334  const std::vector<hebench::APIBridge::WorkloadParam> &w_params) const = 0;
335 
384  const Engine &engine,
385  const BenchmarkDescription::Backend &backend_desc,
386  const BenchmarkDescription::Configuration &config) const = 0;
387 
403  const hebench::APIBridge::BenchmarkDescriptor &in_descriptor,
405  bool force_config);
406 
407 private:
408  static bool m_b_force_config_value;
409 
424  void describe(BenchmarkDescription::Backend &concrete_backend_desc,
425  BenchmarkDescription::Configuration &concrete_config,
427  const Engine &engine,
428  const BenchmarkDescription::Backend &backend_desc,
429  const BenchmarkDescription::Configuration &config) const;
430 };
431 
440 {
441 public:
442  DISABLE_COPY(IBenchmark)
443  DISABLE_MOVE(IBenchmark)
444 private:
445  IL_DECLARE_CLASS_NAME(IBenchmark)
446 
447 public:
448  typedef std::shared_ptr<IBenchmark> Ptr;
452  struct RunConfig
453  {
461  };
462 
463  virtual ~IBenchmark() = default;
464 
480  virtual bool run(hebench::Utilities::TimingReportEx &out_report, RunConfig &config) = 0;
481 
482  virtual std::weak_ptr<Engine> getEngine() const = 0;
483  virtual const hebench::APIBridge::Handle &handle() const = 0;
484 
485 protected:
486  IBenchmark() = default;
487 };
488 
500 {
501 public:
502  DISABLE_COPY(PartialBenchmark)
503  DISABLE_MOVE(PartialBenchmark)
504 private:
505  IL_DECLARE_CLASS_NAME(PartialBenchmark)
506 
507 public:
509  {
510  friend class BenchmarkFactory;
511 
512  private:
513  FriendPrivateKey() {}
514  };
515 
516 public:
517  typedef std::shared_ptr<PartialBenchmark> Ptr;
518 
519  ~PartialBenchmark() override;
520 
521  std::weak_ptr<Engine> getEngine() const override { return m_p_engine; }
522  const hebench::APIBridge::Handle &handle() const override { return m_handle; }
534  virtual std::uint32_t getEventIDStart() const { return 0; }
543  std::uint32_t getEventIDNext()
544  {
545  if (m_b_constructed && m_current_event_id < getEventIDStart())
546  m_current_event_id = getEventIDStart();
547  return ++m_current_event_id;
548  }
549 
560  virtual void init() = 0;
567 
582  virtual void postInit();
583 
602  void checkInitializationState(const FriendPrivateKey &) const;
603 
604 protected:
608  const BenchmarkDescription::Backend &getBackendDescription() const { return m_backend_desc; }
616  const BenchmarkDescription::Description &getDescription() const { return m_text_description; }
617 
618  PartialBenchmark(std::shared_ptr<Engine> p_engine,
619  const IBenchmarkDescriptor::DescriptionToken &description_token);
620 
632  void validateRetCode(hebench::APIBridge::ErrorCode err_code, bool last_error = true) const;
633 
634 private:
635  void internalInit(const IBenchmarkDescriptor::DescriptionToken &description_token);
636 
637  std::shared_ptr<Engine> m_p_engine;
639  BenchmarkDescription::Backend m_backend_desc;
641  BenchmarkDescription::Description m_text_description;
642  std::uint32_t m_current_event_id;
643  bool m_b_constructed;
644  bool m_b_initialized;
645 };
646 
647 } // namespace TestHarness
648 } // namespace hebench
649 
650 #endif // defined _HEBench_Harness_IBenchmark_H_0596d40a3cce4b108a81595c50eb286d
Token returned by a successful call to IBenchmarkDescriptor::matchBenchmarkDescriptor().
const BenchmarkDescription::Backend & getBackendDescription() const
const BenchmarkDescription::Description & getDescription() const
DescriptionToken(IBenchmarkDescriptor &caller, const BenchmarkDescription::Backend &backend_desc, const BenchmarkDescription::Configuration &config, const BenchmarkDescription::Description &text_desc, const FriendKeyCreation &)
const BenchmarkDescription::Configuration & getBenchmarkConfiguration() const
Base interface for Benchmark Descriptors.
virtual void destroyBenchmark(PartialBenchmark *p_bench)=0
Destroys an object returned by createBenchmark().
DescriptionToken::Ptr createToken(const BenchmarkDescription::Backend &backend_desc, const BenchmarkDescription::Configuration &config, const BenchmarkDescription::Description &text_desc) const
Creates a DescriptionToken object associated to this IBenchmarkDescription object using the specified...
virtual DescriptionToken::Ptr matchDescriptor(const Engine &engine, const BenchmarkDescription::Backend &backend_desc, const BenchmarkDescription::Configuration &config) const =0
Determines if the represented benchmark can perform the workload described by a specified HEBench ben...
virtual PartialBenchmark * createBenchmark(std::shared_ptr< Engine > p_engine, const DescriptionToken &description_token)=0
Creates the represented IBenchmark object that can perform the workload specified by the HEBench benc...
virtual bool run(hebench::Utilities::TimingReportEx &out_report, RunConfig &config)=0
Executes the benchmark operations.
virtual const hebench::APIBridge::Handle & handle() const =0
std::shared_ptr< IBenchmark > Ptr
bool b_validate_results
Specifies whether the benchmark will validate backend results (true) or it will simply benchmark with...
virtual std::weak_ptr< Engine > getEngine() const =0
Provides configuration to and retrieves data from a benchmark run.
Provides boilerplate implementation to common methods of interface IBenchmarkDescription and implemen...
std::string workload_header
Workload specific information to be added to the report header.
static std::unordered_set< std::size_t > getCipherParamPositions(std::uint32_t cipher_param_mask)
static void setForceConfigValues(bool value)
Sets whether frontend will override backend descriptors using configuration data or not.
static std::string getDataTypeName(hebench::APIBridge::DataType data_type)
virtual void completeWorkloadDescription(WorkloadDescriptionOutput &output, const Engine &engine, const BenchmarkDescription::Backend &backend_desc, const BenchmarkDescription::Configuration &config) const =0
Completes the description for the matched benchmark.
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 std::string getCategoryName(hebench::APIBridge::Category category)
static std::uint64_t computeSampleSizes(std::uint64_t *sample_sizes, std::size_t param_count, const std::vector< std::uint64_t > &config_sample_sizes, const hebench::APIBridge::BenchmarkDescriptor &bench_desc, std::uint64_t default_sample_size_fallback, bool force_config)
Extracts the batch sizes for a workload from a specified HEBench API benchmark descriptor.
static bool getForceConfigValues()
Specifies whether frontend will override backend descriptors using configuration data or not.
DescriptionToken::Ptr matchDescriptor(const Engine &engine, const BenchmarkDescription::Backend &backend_desc, const BenchmarkDescription::Configuration &config) const override final
Implementation of IBenchmarkDescriptor::matchDescriptor().
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...
virtual bool matchBenchmarkDescriptor(const hebench::APIBridge::BenchmarkDescriptor &bench_desc, const std::vector< hebench::APIBridge::WorkloadParam > &w_params) const =0
Determines if the represented benchmark can perform the workload described by a specified HEBench ben...
Bundles values that need to be filled by a workload during completeWorkloadDescription().
const BenchmarkDescription::Backend & getBackendDescription() const
Allows read-only access to this benchmark backend description.
virtual void init()=0
Initializes the partial benchmark members.
std::shared_ptr< PartialBenchmark > Ptr
virtual void postInit()
Called automatically during initialization after the backend has been initialized.
const BenchmarkDescription::Configuration & getBenchmarkConfiguration() const
Allows read-only access to this benchmark configuration.
virtual std::uint32_t getEventIDStart() const
An ID to identify the first event during the benchmark run.
const hebench::APIBridge::Handle & handle() const override
std::uint32_t getEventIDNext()
Returns the next available event ID.
const BenchmarkDescription::Description & getDescription() const
Allows read-only access to this benchmark text description.
void validateRetCode(hebench::APIBridge::ErrorCode err_code, bool last_error=true) const
Validates whether the specified HEBench API return code represents a success or error.
void checkInitializationState(const FriendPrivateKey &) const
Used to check that initialization steps have been completed successfully.
std::weak_ptr< Engine > getEngine() const override
PartialBenchmark(std::shared_ptr< Engine > p_engine, const IBenchmarkDescriptor::DescriptionToken &description_token)
void initBackend(hebench::Utilities::TimingReportEx &out_report, const FriendPrivateKey &)
Initializes backend benchmark.
DataType
Defines data types for a workload.
Definition: types.h:379
Category
Defines all possible categories for each workload.
Definition: types.h:391
std::int32_t ErrorCode
Return value for API bridge functions.
Definition: types.h:34
Defines a benchmark test.
Definition: types.h:527
Structure to contain flexible data.
Definition: types.h:552