HEBench
hebench_dataset_loader_functional_test.cpp
Go to the documentation of this file.
1 // Copyright (C) 2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
5 
6 using namespace hebench::DataLoader;
7 
8 void signal_error(const char *msg, bool usage)
9 {
10  std::cerr << msg;
11  if (usage)
12  {
13  std::cerr << check_usage;
14  }
15  std::cerr << std::endl;
16  exit(EXIT_FAILURE);
17 }
18 
19 std::uint8_t get_type_from_data(std::string data)
20 {
21  std::map<std::string, std::uint8_t> dataTypeMap = { { "i32", i32 }, { "i64", i64 }, { "f32", f32 }, { "f64", f64 } };
22  try
23  {
24  return dataTypeMap.at(data);
25  }
26  catch (const std::out_of_range &missing_key)
27  {
28  return data_fail;
29  }
30 }
31 
32 void load_from_csv(std::string data, std::filesystem::path file_path, std::uint64_t max_loaded_size)
33 {
34  std::uint8_t data_load_type_evaluated = get_type_from_data(data);
35  switch (data_load_type_evaluated)
36  {
37  case i32:
38  {
39  ExternalDataset<std::int32_t> data_set_i32 =
40  ExternalDatasetLoader<std::int32_t>::loadFromCSV(file_path.string(), max_loaded_size);
41  break;
42  }
43  case i64:
44  {
45  ExternalDataset<std::int64_t> data_set_i64 =
46  ExternalDatasetLoader<std::int64_t>::loadFromCSV(file_path.string(), max_loaded_size);
47  break;
48  }
49  case f32:
50  {
51  ExternalDataset<float> data_set_f32 =
52  ExternalDatasetLoader<float>::loadFromCSV(file_path.string(), max_loaded_size);
53  break;
54  }
55  case f64:
56  {
57  ExternalDataset<double> data_set_f64 =
58  ExternalDatasetLoader<double>::loadFromCSV(file_path.string(), max_loaded_size);
59  break;
60  }
61  case data_fail:
62  {
63  signal_error("Unknown 'data_type' has been specified.");
64  break;
65  }
66  }
67 }
static ExternalDataset< T > loadFromCSV(const std::string &filename, std::uint64_t max_loaded_size=0)
Loads a dataset from an external csv file that follows the defined structure.
void load_from_csv(std::string data, std::filesystem::path file_path, std::uint64_t max_loaded_size)
void signal_error(const char *msg, bool usage)
std::uint8_t get_type_from_data(std::string data)
constexpr const char * check_usage