OmniSciDB  5ade3759e0
anonymous_namespace{ProfileTest.cpp} Namespace Reference

Classes

class  AggregateEmulator
 
class  Deduplicater
 

Functions

size_t get_gpu_count ()
 
bool is_gpu_present ()
 
template<typename T = int64_t>
bool generate_numbers (int8_t *random_numbers, const unsigned num_random_numbers, const T min_number, const T max_number, const DIST_KIND dist, const size_t stride=sizeof(T))
 
bool generate_columns_on_host (int8_t *buffers, const size_t row_count, const size_t col_count, const std::vector< size_t > &col_widths, const std::vector< std::pair< int64_t, int64_t >> &ranges, const bool is_columnar, const std::vector< DIST_KIND > &dists)
 
void init_groups_on_host (int8_t *groups, const size_t group_count, const size_t col_count, const std::vector< size_t > &col_widths, const std::vector< size_t > &init_vals, const bool is_columnar)
 
template<typename ValT = int64_t>
ValT get_default_value (OP_KIND op)
 
DIST_KIND get_default_dist (OP_KIND op)
 
template<typename ValT = int64_t>
std::pair< ValT, ValT > get_default_range (OP_KIND op)
 
template<class T >
void hash_combine (std::size_t &seed, T const &v)
 
template<typename KeyT = int64_t>
bool is_empty_slot (const KeyT k)
 
template<typename KeyT = int64_t>
void reset_entry (KeyT *entry_ptr)
 

Function Documentation

◆ generate_columns_on_host()

bool anonymous_namespace{ProfileTest.cpp}::generate_columns_on_host ( int8_t *  buffers,
const size_t  row_count,
const size_t  col_count,
const std::vector< size_t > &  col_widths,
const std::vector< std::pair< int64_t, int64_t >> &  ranges,
const bool  is_columnar,
const std::vector< DIST_KIND > &  dists 
)

Definition at line 144 of file ProfileTest.cpp.

References CHECK, CHECK_EQ, CHECK_LE, and INVALID.

Referenced by TEST().

150  {
151  if (buffers == nullptr) {
152  return false;
153  }
154  CHECK_EQ(col_widths.size(), col_count);
155  CHECK_EQ(ranges.size(), col_count);
156  size_t row_size = 0;
157  for (auto& wid : col_widths) {
158  row_size += wid;
159  }
160  std::vector<std::future<bool>> child_threads;
161  for (size_t i = 0; i < col_count;
162  buffers += (is_columnar ? row_count : 1) * col_widths[i++]) {
163  if (dists[i] == DIST_KIND::INVALID) {
164  continue;
165  }
166  CHECK_LE(ranges[i].first, ranges[i].second);
167  switch (col_widths[i]) {
168  case 4:
169  child_threads.push_back(std::async(std::launch::async,
170  generate_numbers<int32_t>,
171  buffers,
172  row_count,
173  static_cast<int32_t>(ranges[i].first),
174  static_cast<int32_t>(ranges[i].second),
175  dists[i],
176  (is_columnar ? 4 : row_size)));
177  break;
178  case 8:
179  child_threads.push_back(std::async(std::launch::async,
180  generate_numbers<int64_t>,
181  buffers,
182  row_count,
183  ranges[i].first,
184  ranges[i].second,
185  dists[i],
186  (is_columnar ? 8 : row_size)));
187  break;
188  default:
189  CHECK(false);
190  }
191  }
192  for (auto& child : child_threads) {
193  child.get();
194  }
195  return true;
196 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
#define CHECK_LE(x, y)
Definition: Logger.h:198
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ generate_numbers()

template<typename T = int64_t>
bool anonymous_namespace{ProfileTest.cpp}::generate_numbers ( int8_t *  random_numbers,
const unsigned  num_random_numbers,
const T  min_number,
const T  max_number,
const DIST_KIND  dist,
const size_t  stride = sizeof(T) 
)

Definition at line 82 of file ProfileTest.cpp.

References CHECK, anonymous_namespace{ImportTest.cpp}::d(), EXP1, EXP2, NRM, POI, and UNI.

87  {
88  if (random_numbers == nullptr) {
89  return false;
90  }
91 
92  std::random_device rd;
93  std::mt19937 gen(rd());
94 
95  // values near the mean are the most likely
96  // standard deviation affects the dispersion of generated values from the mean
97  switch (dist) {
98  case NRM: {
99  std::normal_distribution<> d((max_number + min_number) / 2, 1);
100  for (unsigned i = 0; i < num_random_numbers; ++i) {
101  *reinterpret_cast<T*>(random_numbers + i * stride) =
102  std::max<T>(min_number, std::min<T>(max_number, std::round(d(gen))));
103  }
104  break;
105  }
106  case EXP1: {
107  std::exponential_distribution<> d(1);
108  for (unsigned i = 0; i < num_random_numbers; ++i) {
109  *reinterpret_cast<T*>(random_numbers + i * stride) =
110  std::max<T>(min_number, std::min<T>(max_number, std::round(d(gen))));
111  }
112  break;
113  }
114  case EXP2: {
115  std::exponential_distribution<> d(2);
116  for (unsigned i = 0; i < num_random_numbers; ++i) {
117  *reinterpret_cast<T*>(random_numbers + i * stride) =
118  std::max<T>(min_number, std::min<T>(max_number, std::round(d(gen))));
119  }
120  break;
121  }
122  case UNI: {
123  std::uniform_int_distribution<T> d(min_number, max_number);
124  for (unsigned i = 0; i < num_random_numbers; ++i) {
125  *reinterpret_cast<T*>(random_numbers + i * stride) = d(gen);
126  }
127  break;
128  }
129  case POI: {
130  std::poisson_distribution<T> d(4);
131  for (unsigned i = 0; i < num_random_numbers; ++i) {
132  *reinterpret_cast<T*>(random_numbers + i * stride) =
133  std::max<T>(min_number, std::min(max_number, d(gen)));
134  }
135  break;
136  }
137  default:
138  CHECK(false);
139  }
140 
141  return true;
142 }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ get_default_dist()

DIST_KIND anonymous_namespace{ProfileTest.cpp}::get_default_dist ( OP_KIND  op)

Definition at line 329 of file ProfileTest.cpp.

References CHECK, INVALID, OP_COUNT, OP_MAX, OP_MIN, OP_SUM, and UNI.

Referenced by TEST().

329  {
330  switch (op) {
331  case OP_COUNT:
332  return DIST_KIND::INVALID;
333  case OP_SUM:
334  case OP_MIN:
335  case OP_MAX:
336  return DIST_KIND::UNI;
337  default:
338  CHECK(false);
339  }
340  return DIST_KIND::INVALID;
341 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ get_default_range()

template<typename ValT = int64_t>
std::pair<ValT, ValT> anonymous_namespace{ProfileTest.cpp}::get_default_range ( OP_KIND  op)

Definition at line 344 of file ProfileTest.cpp.

References CHECK, OP_COUNT, OP_MAX, OP_MIN, and OP_SUM.

Referenced by TEST().

344  {
345  switch (op) {
346  case OP_COUNT:
347  return {ValT(0), ValT(0)};
348  case OP_SUM:
349  case OP_MIN:
350  case OP_MAX:
351  return {std::numeric_limits<ValT>::min(), std::numeric_limits<ValT>::max()};
352  default:
353  CHECK(false);
354  }
355  CHECK(false);
356  return {ValT(0), ValT(0)};
357 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ get_default_value()

template<typename ValT = int64_t>
ValT anonymous_namespace{ProfileTest.cpp}::get_default_value ( OP_KIND  op)

Definition at line 314 of file ProfileTest.cpp.

References CHECK, OP_COUNT, OP_MAX, OP_MIN, and OP_SUM.

Referenced by TEST().

314  {
315  switch (op) {
316  case OP_COUNT:
317  case OP_SUM:
318  return ValT(0);
319  case OP_MIN:
320  return std::numeric_limits<ValT>::max();
321  case OP_MAX:
322  return std::numeric_limits<ValT>::min();
323  default:
324  CHECK(false);
325  }
326  return ValT(0);
327 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ get_gpu_count()

size_t anonymous_namespace{ProfileTest.cpp}::get_gpu_count ( )
inline

Definition at line 58 of file ProfileTest.cpp.

Referenced by is_gpu_present(), and TEST().

58  {
59 #if defined(HAVE_CUDA) && CUDA_VERSION >= 8000
60  int num_gpus = 0;
61  try {
62  check_error(cuInit(0));
63  check_error(cuDeviceGetCount(&num_gpus));
64  } catch (std::runtime_error&) {
65  return 0;
66  }
67  return num_gpus;
68 #else
69  return 0;
70 #endif
71 }
+ Here is the caller graph for this function:

◆ hash_combine()

template<class T >
void anonymous_namespace{ProfileTest.cpp}::hash_combine ( std::size_t &  seed,
T const &  v 
)
inline

Definition at line 360 of file ProfileTest.cpp.

Referenced by std::hash< vector< T > >::operator()(), random_fill_dates(), random_fill_double(), random_fill_float(), random_fill_int16(), random_fill_int16array(), random_fill_int32(), random_fill_int32array(), random_fill_int64(), random_fill_int8array(), random_fill_string(), and scan_chunk().

360  {
361  seed ^= std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
362 }
T v(const TargetValue &r)
+ Here is the caller graph for this function:

◆ init_groups_on_host()

void anonymous_namespace{ProfileTest.cpp}::init_groups_on_host ( int8_t *  groups,
const size_t  group_count,
const size_t  col_count,
const std::vector< size_t > &  col_widths,
const std::vector< size_t > &  init_vals,
const bool  is_columnar 
)
inline

Definition at line 198 of file ProfileTest.cpp.

References CHECK, CHECK_EQ, and cpu_threads().

Referenced by TEST().

203  {
204  CHECK_EQ(col_count, col_widths.size());
205  CHECK_EQ(col_count, init_vals.size());
206  std::vector<std::future<void>> child_threads;
207  const size_t cpu_count = cpu_threads();
208  const auto stride = (group_count + cpu_count - 1) / cpu_count;
209  size_t row_size = 0;
210  for (auto wid : col_widths) {
211  row_size += wid;
212  }
213 
214  for (size_t start_group = 0; start_group < group_count; start_group += stride) {
215  const auto end_group = std::min(group_count, start_group + stride);
216  if (is_columnar) {
217  child_threads.push_back(
218  std::async(std::launch::async, [&, start_group, end_group]() {
219  auto col_base = groups;
220  for (size_t j = 0; j < col_count; col_base += col_widths[j++] * group_count) {
221  for (size_t i = start_group; i < end_group; ++i) {
222  switch (col_widths[j]) {
223  case 4: {
224  auto col_ptr = reinterpret_cast<uint32_t*>(col_base);
225  std::fill(col_ptr,
226  col_ptr + group_count,
227  static_cast<uint32_t>(init_vals[j]));
228  break;
229  }
230  case 8: {
231  auto col_ptr = reinterpret_cast<size_t*>(col_base);
232  std::fill(col_ptr, col_ptr + group_count, init_vals[j]);
233  break;
234  }
235  default:
236  CHECK(false);
237  }
238  }
239  }
240  }));
241  } else {
242  child_threads.push_back(
243  std::async(std::launch::async, [&, start_group, end_group]() {
244  for (size_t i = start_group; i < end_group; ++i) {
245  auto row_base = groups + i * row_size;
246  for (size_t j = 0; j < col_count; row_base += col_widths[j++]) {
247  switch (col_widths[j]) {
248  case 4:
249  *reinterpret_cast<uint32_t*>(row_base) =
250  static_cast<uint32_t>(init_vals[j]);
251  break;
252  case 8:
253  *reinterpret_cast<size_t*>(row_base) = init_vals[j];
254  break;
255  default:
256  CHECK(false);
257  }
258  }
259  }
260  }));
261  }
262  }
263  for (auto& child : child_threads) {
264  child.get();
265  }
266 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
#define CHECK(condition)
Definition: Logger.h:187
const int64_t * init_vals
int cpu_threads()
Definition: thread_count.h:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_empty_slot()

template<typename KeyT = int64_t>
bool anonymous_namespace{ProfileTest.cpp}::is_empty_slot ( const KeyT  k)
inline

Definition at line 385 of file ProfileTest.cpp.

References EMPTY_KEY_64.

Referenced by anonymous_namespace{ProfileTest.cpp}::AggregateEmulator< KeyT, ValT >::compareDispatch(), anonymous_namespace{ProfileTest.cpp}::AggregateEmulator< KeyT, ValT >::reduce(), and anonymous_namespace{ProfileTest.cpp}::AggregateEmulator< KeyT, ValT >::runDispatch().

385  {
386  static_assert(std::is_same<KeyT, int64_t>::value,
387  "Unsupported template parameter other than int64_t for now");
388  return k == EMPTY_KEY_64;
389 }
#define EMPTY_KEY_64
+ Here is the caller graph for this function:

◆ is_gpu_present()

bool anonymous_namespace{ProfileTest.cpp}::is_gpu_present ( )
inline

Definition at line 73 of file ProfileTest.cpp.

References get_gpu_count().

Referenced by main().

73  {
74 #if defined(HAVE_CUDA) && CUDA_VERSION >= 8000
75  return (get_gpu_count() > 0);
76 #else
77  return false;
78 #endif // HAVE_CUDA
79 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_entry()

template<typename KeyT = int64_t>
void anonymous_namespace{ProfileTest.cpp}::reset_entry ( KeyT *  entry_ptr)

Definition at line 1159 of file ProfileTest.cpp.

References EMPTY_KEY_64.

Referenced by anonymous_namespace{ProfileTest.cpp}::Deduplicater< isColumnar, KeyT >::runDispatch().

1159  {
1160  static_assert(std::is_same<KeyT, int64_t>::value,
1161  "Unsupported template parameter other than int64_t for now");
1162  *entry_ptr = static_cast<KeyT>(EMPTY_KEY_64);
1163 }
#define EMPTY_KEY_64
+ Here is the caller graph for this function: