HEBench
hebench_idata_loader.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_IDataLoader_H_0596d40a3cce4b108a81595c50eb286d
6 #define _HEBench_Harness_IDataLoader_H_0596d40a3cce4b108a81595c50eb286d
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "hebench/modules/general/include/nocopy.h"
13 #include "hebench/modules/logging/include/logging.h"
14 
16 #include "hebench_types_harness.h"
17 
18 namespace hebench {
19 namespace TestHarness {
20 
22 {
23 public:
24  DISABLE_COPY(IDataLoader)
25  DISABLE_MOVE(IDataLoader)
26 private:
27  IL_DECLARE_CLASS_NAME(IDataLoader)
28 
29 public:
30  template <typename T>
32 
33  struct ResultData
34  {
39  std::vector<const hebench::APIBridge::NativeDataBuffer *> result;
43  std::uint64_t sample_index;
44  std::shared_ptr<void> reserved0; // use for RAII if needed
45  };
46  typedef std::shared_ptr<ResultData> ResultDataPtr;
47 
48  typedef std::shared_ptr<IDataLoader> Ptr;
49 
50  virtual ~IDataLoader() {}
51 
52  static std::size_t sizeOf(hebench::APIBridge::DataType data_type);
53 
66  createDataPackCollection(std::uint64_t data_pack_count);
80  createDataPack(std::uint64_t buffer_count, std::uint64_t param_position);
82  createDataBuffer(std::uint64_t size, std::int64_t tag);
83 
89  virtual std::uint64_t getParameterCount() const = 0;
103  virtual const hebench::APIBridge::DataPack &getParameterData(std::uint64_t param_position) const = 0;
114  virtual std::uint64_t getResultCount() const = 0;
121  virtual const hebench::APIBridge::DataPack &getResultData(std::uint64_t param_position) const = 0;
122 
141  virtual ResultDataPtr getResultFor(const std::uint64_t *param_data_pack_indices) = 0;
205  virtual std::uint64_t getResultIndex(const std::uint64_t *param_data_pack_indices) const = 0;
206 
210  virtual std::uint64_t getTotalDataLoaded() const = 0;
211 
212 protected:
214 };
215 
232 {
233 public:
234  DISABLE_COPY(PartialDataLoader)
235  DISABLE_MOVE(PartialDataLoader)
236 private:
237  IL_DECLARE_CLASS_NAME(PartialDataLoader)
238 
239  template <typename>
241 
242 public:
243  typedef std::shared_ptr<PartialDataLoader> Ptr;
244 
245  ~PartialDataLoader() override {}
246 
247  std::uint64_t getParameterCount() const override { return m_input_data.size(); }
248  const hebench::APIBridge::DataPack &getParameterData(std::uint64_t param_position) const override;
249  std::uint64_t getResultCount() const override { return m_output_data.size(); }
250  const hebench::APIBridge::DataPack &getResultData(std::uint64_t param_position) const override;
251  ResultDataPtr getResultFor(const std::uint64_t *param_data_pack_indices) override;
252  std::uint64_t getResultIndex(const std::uint64_t *param_data_pack_indices) const override;
253  std::uint64_t getTotalDataLoaded() const override { return m_raw_buffer.size(); }
268  bool hasResults() const { return m_b_is_output_allocated; }
269  bool isInitialized() const { return m_b_initialized; }
270  hebench::APIBridge::DataType getDataType() const { return m_data_type; }
271 
272 protected:
302  void init(hebench::APIBridge::DataType data_type,
303  std::size_t input_dim,
304  const std::size_t *input_sample_count_per_dim,
305  const std::uint64_t *input_count_per_dim,
306  std::size_t output_dim,
307  const std::uint64_t *output_count_per_dim,
308  bool allocate_output);
335  void init(const std::string &filename,
337  std::size_t expected_input_dim,
338  const std::size_t *max_input_sample_count_per_dim,
339  const std::uint64_t *expected_input_count_per_dim,
340  std::size_t expected_output_dim,
341  const std::uint64_t *expected_output_count_per_dim);
342 
364  std::vector<std::shared_ptr<hebench::APIBridge::DataPack>> getResultTempDataPacks(std::uint64_t result_index) const;
387  std::vector<std::shared_ptr<hebench::APIBridge::DataPack>> getResultTempDataPacks(const std::uint64_t *param_data_pack_indices) const
388  {
389  return getResultTempDataPacks(getResultIndex(param_data_pack_indices));
390  }
411  std::vector<std::shared_ptr<hebench::APIBridge::DataPack>> getResultTempDataPacks() const
412  {
413  return getResultTempDataPacks(0UL);
414  }
415 
416 private:
436  void allocate(const std::uint64_t *input_buffer_sizes,
437  std::size_t input_buffer_sizes_count,
438  const std::uint64_t *output_buffer_sizes,
439  std::size_t output_buffer_sizes_count,
440  bool allocate_output);
441 
442  std::vector<unique_ptr_custom_deleter<hebench::APIBridge::DataPack>> m_input_data;
443  // output data is ordered such that each element of the data pack
444  // is the result of the input parameters picked in row major order
445  std::vector<unique_ptr_custom_deleter<hebench::APIBridge::DataPack>> m_output_data;
446  // RAII storage for native data buffers
447  std::vector<std::uint8_t> m_raw_buffer; // used to store all the data in contiguous memory
448  hebench::APIBridge::DataType m_data_type;
449  bool m_b_is_output_allocated;
450  bool m_b_initialized;
451 };
452 
453 } // namespace TestHarness
454 } // namespace hebench
455 
456 #endif // defined _HEBench_Harness_IDataLoader_H_0596d40a3cce4b108a81595c50eb286d
static std::size_t sizeOf(hebench::APIBridge::DataType data_type)
std::vector< const hebench::APIBridge::NativeDataBuffer * > result
Points to the NativeDataBuffer s containing the result sample for an input sample.
std::uint64_t sample_index
Index of the result sample.
static unique_ptr_custom_deleter< hebench::APIBridge::NativeDataBuffer > createDataBuffer(std::uint64_t size, std::int64_t tag)
virtual ResultDataPtr getResultFor(const std::uint64_t *param_data_pack_indices)=0
getResultFor
virtual std::uint64_t getParameterCount() const =0
Number of parameter components (operands) for the represented operation.
static unique_ptr_custom_deleter< hebench::APIBridge::DataPackCollection > createDataPackCollection(std::uint64_t data_pack_count)
Creates shallow packed data that self cleans up.
std::shared_ptr< ResultData > ResultDataPtr
std::shared_ptr< IDataLoader > Ptr
hebench::TestHarness::unique_ptr_custom_deleter< T > unique_ptr_custom_deleter
virtual std::uint64_t getResultCount() const =0
Number of components in a result for the represented operation.
virtual const hebench::APIBridge::DataPack & getParameterData(std::uint64_t param_position) const =0
Data pack for specified operation parameter (operand).
static unique_ptr_custom_deleter< hebench::APIBridge::DataPack > createDataPack(std::uint64_t buffer_count, std::uint64_t param_position)
Creates shallow data pack that self cleans up.
virtual const hebench::APIBridge::DataPack & getResultData(std::uint64_t param_position) const =0
Data pack corresponding to the specified component of the result.
virtual std::uint64_t getResultIndex(const std::uint64_t *param_data_pack_indices) const =0
Computes the index of the result NativeDataBuffer given the indices of the input data.
virtual std::uint64_t getTotalDataLoaded() const =0
Total data loaded by this loader in bytes.
Base class for data loaders and data generators.
ResultDataPtr getResultFor(const std::uint64_t *param_data_pack_indices) override
getResultFor
std::vector< std::shared_ptr< hebench::APIBridge::DataPack > > getResultTempDataPacks(const std::uint64_t *param_data_pack_indices) const
Retrieves a pre-allocated result providing memory space to store a single operation result sample.
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.
std::uint64_t getResultCount() const override
Number of components in a result for the represented operation.
const hebench::APIBridge::DataPack & getResultData(std::uint64_t param_position) const override
Data pack corresponding to the specified component of the result.
std::uint64_t getParameterCount() const override
Number of parameter components (operands) for the represented operation.
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 getTotalDataLoaded() const override
Total data loaded by this loader in bytes.
hebench::APIBridge::DataType getDataType() const
std::shared_ptr< PartialDataLoader > Ptr
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.
DataType
Defines data types for a workload.
Definition: types.h:379
Defines a data package for an operation.
Definition: types.h:611
std::unique_ptr< T, std::function< void(T *)> > unique_ptr_custom_deleter