OmniSciDB  8a228a1076
OverlapsJoinHashTable.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
20 #include "QueryEngine/Execute.h"
25 
26 std::map<OverlapsJoinHashTable::HashTableCacheKey, double>
29 
31 std::shared_ptr<OverlapsJoinHashTable> OverlapsJoinHashTable::getInstance(
32  const std::shared_ptr<Analyzer::BinOper> condition,
33  const std::vector<InputTableInfo>& query_infos,
34  const Data_Namespace::MemoryLevel memory_level,
35  const int device_count,
36  ColumnCacheMap& column_cache,
37  Executor* executor) {
38  decltype(std::chrono::steady_clock::now()) ts1, ts2;
39  auto inner_outer_pairs = normalize_column_pairs(
40  condition.get(), *executor->getCatalog(), executor->getTemporaryTables());
41 
42  const auto getHashTableType = [](const std::shared_ptr<Analyzer::BinOper> condition,
43  const std::vector<InnerOuter>& inner_outer_pairs)
46  if (condition->is_overlaps_oper()) {
47  CHECK_EQ(inner_outer_pairs.size(), size_t(1));
48  if (inner_outer_pairs[0].first->get_type_info().is_array() &&
49  inner_outer_pairs[0].second->get_type_info().is_array()) {
51  }
52  }
53  return layout;
54  };
55 
56  auto layout = getHashTableType(condition, inner_outer_pairs);
57 
58  if (VLOGGING(1)) {
59  VLOG(1) << "Building geo hash table " << getHashTypeString(layout)
60  << " for qual: " << condition->toString();
61  ts1 = std::chrono::steady_clock::now();
62  }
63 
64  const auto qi_0 = query_infos[0].info.getNumTuplesUpperBound();
65  const auto qi_1 = query_infos[1].info.getNumTuplesUpperBound();
66 
67  VLOG(1) << "table_id = " << query_infos[0].table_id << " has " << qi_0 << " tuples.";
68  VLOG(1) << "table_id = " << query_infos[1].table_id << " has " << qi_1 << " tuples.";
69 
70  const auto& query_info =
71  get_inner_query_info(getInnerTableId(inner_outer_pairs), query_infos).info;
72  const auto total_entries = 2 * query_info.getNumTuplesUpperBound();
73  if (total_entries > static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
74  throw TooManyHashEntries();
75  }
76  const auto shard_count = memory_level == Data_Namespace::GPU_LEVEL
78  condition.get(), executor, inner_outer_pairs)
79  : 0;
80  const auto entries_per_device =
81  get_entries_per_device(total_entries, shard_count, device_count, memory_level);
82  auto join_hash_table = std::make_shared<OverlapsJoinHashTable>(condition,
83  query_infos,
84  memory_level,
85  layout,
86  entries_per_device,
87  column_cache,
88  executor,
89  inner_outer_pairs,
90  device_count);
91  join_hash_table->checkHashJoinReplicationConstraint(getInnerTableId(inner_outer_pairs));
92  try {
93  join_hash_table->reify();
94  } catch (const HashJoinFail& e) {
95  throw HashJoinFail(std::string("Could not build a 1-to-1 correspondence for columns "
96  "involved in equijoin | ") +
97  e.what());
98  } catch (const ColumnarConversionNotSupported& e) {
99  throw HashJoinFail(std::string("Could not build hash tables for equijoin | ") +
100  e.what());
101  } catch (const std::exception& e) {
102  LOG(FATAL) << "Fatal error while attempting to build hash tables for join: "
103  << e.what();
104  }
105  if (VLOGGING(1)) {
106  ts2 = std::chrono::steady_clock::now();
107  VLOG(1) << "Built geo hash table " << getHashTypeString(layout) << " in "
108  << std::chrono::duration_cast<std::chrono::milliseconds>(ts2 - ts1).count()
109  << " ms";
110  }
111  return join_hash_table;
112 }
113 
115  const JoinHashTableInterface::HashType layout) {
116  auto timer = DEBUG_TIMER(__func__);
118  layout_ = layout;
119  const auto& query_info = get_inner_query_info(getInnerTableId(), query_infos_).info;
120  VLOG(1) << "Reify with layout " << getHashTypeString(layout_)
121  << "for table_id: " << getInnerTableId();
122  if (query_info.fragments.empty()) {
123  return;
124  }
125  std::vector<BaselineJoinHashTable::ColumnsForDevice> columns_per_device;
126  auto& data_mgr = catalog_->getDataMgr();
127  std::vector<std::unique_ptr<CudaAllocator>> dev_buff_owners;
129  for (int device_id = 0; device_id < device_count_; ++device_id) {
130  dev_buff_owners.emplace_back(std::make_unique<CudaAllocator>(&data_mgr, device_id));
131  }
132  }
133  const auto shard_count = shardCount();
134  for (int device_id = 0; device_id < device_count_; ++device_id) {
135  const auto fragments =
136  shard_count
137  ? only_shards_for_device(query_info.fragments, device_id, device_count_)
138  : query_info.fragments;
139  const auto columns_for_device =
140  fetchColumnsForDevice(fragments,
141  device_id,
143  ? dev_buff_owners[device_id].get()
144  : nullptr);
145  columns_per_device.push_back(columns_for_device);
146  }
147 
148  // Prepare to calculate the size of the hash table.
149  const auto composite_key_info = getCompositeKeyInfo();
150  HashTableCacheKey cache_key{columns_per_device.front().join_columns.front().num_elems,
151  composite_key_info.cache_key_chunks,
152  condition_->get_optype()};
154 
155  auto cache_key_contains_intermediate_table = [](const auto cache_key) {
156  for (auto key : cache_key.chunk_keys) {
157  CHECK_GE(key.size(), size_t(2));
158  if (key[1] < 0) {
159  return true;
160  }
161  }
162  return false;
163  };
164 
165  // Auto-tuner: Pre-calculate some possible hash table sizes.
166  std::lock_guard<std::mutex> guard(auto_tuner_cache_mutex_);
167  auto atc = auto_tuner_cache_.find(cache_key);
168  if (atc != auto_tuner_cache_.end()) {
170  VLOG(1) << "Auto tuner using cached overlaps hash table size of: "
172  } else {
173  VLOG(1) << "Auto tuning for the overlaps hash table size:";
174  // TODO(jclay): Currently, joining on large poly sets
175  // will lead to lengthy construction times (and large hash tables)
176  // tune this to account for the characteristics of the data being joined.
177  const double min_threshold{1e-5};
178  const double max_threshold{1};
179  double good_threshold{max_threshold};
180  for (double threshold = max_threshold; threshold >= min_threshold;
181  threshold /= 10.0) {
183  size_t entry_count;
184  size_t emitted_keys_count;
185  std::tie(entry_count, emitted_keys_count) =
186  calculateCounts(shard_count, query_info, columns_per_device);
187  size_t hash_table_size = calculateHashTableSize(
188  bucket_sizes_for_dimension_.size(), emitted_keys_count, entry_count);
190  VLOG(1) << "Calculated bin threshold of " << std::fixed << threshold
191  << " giving: entry count " << entry_count << " hash table size "
192  << hash_table_size;
193  if (hash_table_size <= g_overlaps_max_table_size_bytes) {
194  good_threshold = overlaps_hashjoin_bucket_threshold_;
195  } else {
196  VLOG(1) << "Rejected bin threshold of " << std::fixed << threshold;
197  break;
198  }
199  }
200  overlaps_hashjoin_bucket_threshold_ = good_threshold;
201  if (!cache_key_contains_intermediate_table(cache_key)) {
203  }
204  }
205 
206  // Calculate the final size of the hash table.
207  VLOG(1) << "Accepted bin threshold of " << std::fixed
209  // NOTE: Setting entry_count_ here overrides when entry_count_ was set in getInstance()
210  // from entries_per_device.
211  std::tie(entry_count_, emitted_keys_count_) =
212  calculateCounts(shard_count, query_info, columns_per_device);
213  size_t hash_table_size = calculateHashTableSize(
215  VLOG(1) << "Finalized overlaps hashjoin bucket threshold of " << std::fixed
216  << overlaps_hashjoin_bucket_threshold_ << " giving: entry count "
217  << entry_count_ << " hash table size " << hash_table_size;
218 
219  std::vector<std::future<void>> init_threads;
220  for (int device_id = 0; device_id < device_count_; ++device_id) {
221  const auto fragments =
222  shard_count
223  ? only_shards_for_device(query_info.fragments, device_id, device_count_)
224  : query_info.fragments;
225  init_threads.push_back(std::async(std::launch::async,
227  this,
228  columns_per_device[device_id],
229  layout,
230  device_id,
231  logger::thread_id()));
232  }
233  for (auto& init_thread : init_threads) {
234  init_thread.wait();
235  }
236  for (auto& init_thread : init_threads) {
237  init_thread.get();
238  }
239 }
240 
241 std::pair<size_t, size_t> OverlapsJoinHashTable::calculateCounts(
242  size_t shard_count,
243  const Fragmenter_Namespace::TableInfo& query_info,
244  std::vector<BaselineJoinHashTable::ColumnsForDevice>& columns_per_device) {
245  // re-compute bucket counts per device based on global bucket size
246  CHECK_EQ(columns_per_device.size(), size_t(device_count_));
247  for (int device_id = 0; device_id < device_count_; ++device_id) {
248  auto& columns_for_device = columns_per_device[device_id];
249  columns_for_device.join_buckets = computeBucketInfo(
250  columns_for_device.join_columns, columns_for_device.join_column_types, device_id);
251  }
252  size_t tuple_count;
253  size_t emitted_keys_count;
254  std::tie(tuple_count, emitted_keys_count) = approximateTupleCount(columns_per_device);
255  const auto entry_count = 2 * std::max(tuple_count, size_t(1));
256 
257  return std::make_pair(
258  get_entries_per_device(entry_count, shard_count, device_count_, memory_level_),
259  emitted_keys_count);
260 }
261 
262 size_t OverlapsJoinHashTable::calculateHashTableSize(size_t number_of_dimensions,
263  size_t emitted_keys_count,
264  size_t entry_count) const {
265  const auto key_component_width = getKeyComponentWidth();
266  const auto key_component_count = number_of_dimensions;
267  const auto entry_size = key_component_count * key_component_width;
268  const auto keys_for_all_rows = emitted_keys_count;
269  const size_t one_to_many_hash_entries = 2 * entry_count + keys_for_all_rows;
270  const size_t hash_table_size =
271  entry_size * entry_count + one_to_many_hash_entries * sizeof(int32_t);
272  return hash_table_size;
273 }
274 
276  const std::vector<Fragmenter_Namespace::FragmentInfo>& fragments,
277  const int device_id,
278  DeviceAllocator* dev_buff_owner) {
279  const auto& catalog = *executor_->getCatalog();
280  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
281 
282  std::vector<JoinColumn> join_columns;
283  std::vector<std::shared_ptr<Chunk_NS::Chunk>> chunks_owner;
284  std::vector<JoinColumnTypeInfo> join_column_types;
285  std::vector<std::shared_ptr<void>> malloc_owner;
286  for (const auto& inner_outer_pair : inner_outer_pairs_) {
287  const auto inner_col = inner_outer_pair.first;
288  const auto inner_cd = get_column_descriptor_maybe(
289  inner_col->get_column_id(), inner_col->get_table_id(), catalog);
290  if (inner_cd && inner_cd->isVirtualCol) {
292  }
293  join_columns.emplace_back(fetchJoinColumn(inner_col,
294  fragments,
295  effective_memory_level,
296  device_id,
297  chunks_owner,
298  dev_buff_owner,
299  malloc_owner,
300  executor_,
301  &column_cache_));
302  const auto& ti = inner_col->get_type_info();
303  join_column_types.emplace_back(JoinColumnTypeInfo{static_cast<size_t>(ti.get_size()),
304  0,
305  0,
306  inline_int_null_value<int64_t>(),
307  isBitwiseEq(),
308  0,
310  CHECK(ti.is_array()) << "Overlaps join currently only supported for arrays.";
311  }
312  // compute initial bucket info
313  auto join_bucket_info = computeBucketInfo(join_columns, join_column_types, device_id);
314  return {join_columns, join_column_types, chunks_owner, join_bucket_info, malloc_owner};
315 }
316 
317 std::vector<JoinBucketInfo> OverlapsJoinHashTable::computeBucketInfo(
318  const std::vector<JoinColumn>& join_columns,
319  const std::vector<JoinColumnTypeInfo>& join_column_types,
320  const int device_id) {
321  std::vector<JoinBucketInfo> join_bucket_info;
322  CHECK_EQ(inner_outer_pairs_.size(), join_columns.size());
323  CHECK_EQ(join_columns.size(), join_column_types.size());
324  for (size_t i = 0; i < join_columns.size(); i++) {
325  const auto& inner_outer_pair = inner_outer_pairs_[i];
326  const auto inner_col = inner_outer_pair.first;
327  const auto& ti = inner_col->get_type_info();
328  const auto elem_ti = ti.get_elem_type();
329  CHECK(elem_ti.is_fp());
330 
331  if (bucket_sizes_for_dimension_.empty()) {
333  join_columns[i],
334  join_column_types[i],
336  }
337  join_bucket_info.emplace_back(
338  JoinBucketInfo{bucket_sizes_for_dimension_, elem_ti.get_type() == kDOUBLE});
339  }
340  return join_bucket_info;
341 }
342 
344  const std::vector<ColumnsForDevice>& columns_per_device) const {
345  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs_);
346  CountDistinctDescriptor count_distinct_desc{
348  0,
349  11,
350  true,
351  effective_memory_level == Data_Namespace::MemoryLevel::GPU_LEVEL
354  1};
355  const auto padded_size_bytes = count_distinct_desc.bitmapPaddedSizeBytes();
356 
357  CHECK(!columns_per_device.empty() && !columns_per_device.front().join_columns.empty());
358  // Number of keys must match dimension of buckets
359  CHECK_EQ(columns_per_device.front().join_columns.size(),
360  columns_per_device.front().join_buckets.size());
361  if (effective_memory_level == Data_Namespace::MemoryLevel::CPU_LEVEL) {
362  const auto composite_key_info = getCompositeKeyInfo();
363  HashTableCacheKey cache_key{columns_per_device.front().join_columns.front().num_elems,
364  composite_key_info.cache_key_chunks,
365  condition_->get_optype(),
367  const auto cached_count_info = getApproximateTupleCountFromCache(cache_key);
368  if (cached_count_info.first >= 0) {
369  VLOG(1) << "Using a cached tuple count: " << cached_count_info.first
370  << ", emitted keys count: " << cached_count_info.second;
371  return std::make_pair(cached_count_info.first, cached_count_info.second);
372  }
373  int thread_count = cpu_threads();
374  std::vector<uint8_t> hll_buffer_all_cpus(thread_count * padded_size_bytes);
375  auto hll_result = &hll_buffer_all_cpus[0];
376 
377  std::vector<int32_t> num_keys_for_row;
378  // TODO(adb): support multi-column overlaps join
379  CHECK_EQ(columns_per_device.size(), 1u);
380  num_keys_for_row.resize(columns_per_device.front().join_columns[0].num_elems);
381 
383  num_keys_for_row,
384  count_distinct_desc.bitmap_sz_bits,
385  padded_size_bytes,
386  columns_per_device.front().join_columns,
387  columns_per_device.front().join_column_types,
388  columns_per_device.front().join_buckets,
389  thread_count);
390  for (int i = 1; i < thread_count; ++i) {
391  hll_unify(hll_result,
392  hll_result + i * padded_size_bytes,
393  1 << count_distinct_desc.bitmap_sz_bits);
394  }
395  return std::make_pair(hll_size(hll_result, count_distinct_desc.bitmap_sz_bits),
396  num_keys_for_row.size() > 0 ? num_keys_for_row.back() : 0);
397  }
398 #ifdef HAVE_CUDA
399  auto& data_mgr = executor_->getCatalog()->getDataMgr();
400  std::vector<std::vector<uint8_t>> host_hll_buffers(device_count_);
401  for (auto& host_hll_buffer : host_hll_buffers) {
402  host_hll_buffer.resize(count_distinct_desc.bitmapPaddedSizeBytes());
403  }
404  std::vector<size_t> emitted_keys_count_device_threads(device_count_, 0);
405  std::vector<std::future<void>> approximate_distinct_device_threads;
406  for (int device_id = 0; device_id < device_count_; ++device_id) {
407  approximate_distinct_device_threads.emplace_back(std::async(
408  std::launch::async,
409  [device_id,
410  &columns_per_device,
411  &count_distinct_desc,
412  &data_mgr,
413  &host_hll_buffers,
414  &emitted_keys_count_device_threads,
415  this] {
416  CudaAllocator allocator(&data_mgr, device_id);
417  auto device_hll_buffer =
418  allocator.alloc(count_distinct_desc.bitmapPaddedSizeBytes());
419  data_mgr.getCudaMgr()->zeroDeviceMem(
420  device_hll_buffer, count_distinct_desc.bitmapPaddedSizeBytes(), device_id);
421  const auto& columns_for_device = columns_per_device[device_id];
422  auto join_columns_gpu = transfer_vector_of_flat_objects_to_gpu(
423  columns_for_device.join_columns, allocator);
424 
425  CHECK_GT(columns_for_device.join_buckets.size(), 0u);
426  const auto& bucket_sizes_for_dimension =
427  columns_for_device.join_buckets[0].bucket_sizes_for_dimension;
428  auto bucket_sizes_gpu =
429  allocator.alloc(bucket_sizes_for_dimension.size() * sizeof(double));
430  copy_to_gpu(&data_mgr,
431  reinterpret_cast<CUdeviceptr>(bucket_sizes_gpu),
432  bucket_sizes_for_dimension.data(),
433  bucket_sizes_for_dimension.size() * sizeof(double),
434  device_id);
435  const size_t row_counts_buffer_sz =
436  columns_per_device.front().join_columns[0].num_elems * sizeof(int32_t);
437  auto row_counts_buffer = allocator.alloc(row_counts_buffer_sz);
438  data_mgr.getCudaMgr()->zeroDeviceMem(
439  row_counts_buffer, row_counts_buffer_sz, device_id);
440  const auto key_handler =
441  OverlapsKeyHandler(bucket_sizes_for_dimension.size(),
442  join_columns_gpu,
443  reinterpret_cast<double*>(bucket_sizes_gpu));
444  const auto key_handler_gpu =
445  transfer_flat_object_to_gpu(key_handler, allocator);
447  reinterpret_cast<uint8_t*>(device_hll_buffer),
448  count_distinct_desc.bitmap_sz_bits,
449  reinterpret_cast<int32_t*>(row_counts_buffer),
450  key_handler_gpu,
451  columns_for_device.join_columns[0].num_elems,
452  executor_->blockSize(),
453  executor_->gridSize());
454 
455  auto& host_emitted_keys_count = emitted_keys_count_device_threads[device_id];
456  copy_from_gpu(&data_mgr,
457  &host_emitted_keys_count,
458  reinterpret_cast<CUdeviceptr>(
459  row_counts_buffer +
460  (columns_per_device.front().join_columns[0].num_elems - 1) *
461  sizeof(int32_t)),
462  sizeof(int32_t),
463  device_id);
464 
465  auto& host_hll_buffer = host_hll_buffers[device_id];
466  copy_from_gpu(&data_mgr,
467  &host_hll_buffer[0],
468  reinterpret_cast<CUdeviceptr>(device_hll_buffer),
469  count_distinct_desc.bitmapPaddedSizeBytes(),
470  device_id);
471  }));
472  }
473  for (auto& child : approximate_distinct_device_threads) {
474  child.get();
475  }
476  CHECK_EQ(Data_Namespace::MemoryLevel::GPU_LEVEL, effective_memory_level);
477  auto& result_hll_buffer = host_hll_buffers.front();
478  auto hll_result = reinterpret_cast<int32_t*>(&result_hll_buffer[0]);
479  for (int device_id = 1; device_id < device_count_; ++device_id) {
480  auto& host_hll_buffer = host_hll_buffers[device_id];
481  hll_unify(hll_result,
482  reinterpret_cast<int32_t*>(&host_hll_buffer[0]),
483  1 << count_distinct_desc.bitmap_sz_bits);
484  }
485  size_t emitted_keys_count = 0;
486  for (auto& emitted_keys_count_device : emitted_keys_count_device_threads) {
487  emitted_keys_count += emitted_keys_count_device;
488  }
489  return std::make_pair(hll_size(hll_result, count_distinct_desc.bitmap_sz_bits),
490  emitted_keys_count);
491 #else
492  UNREACHABLE();
493  return {0, 0};
494 #endif // HAVE_CUDA
495 }
496 
498  return 8;
499 }
500 
502  return bucket_sizes_for_dimension_.size();
503 }
504 
506  const std::vector<JoinColumn>& join_columns,
507  const std::vector<JoinColumnTypeInfo>& join_column_types,
508  const std::vector<JoinBucketInfo>& join_bucket_info,
509  const JoinHashTableInterface::HashType layout) {
510  auto timer = DEBUG_TIMER(__func__);
511  const auto composite_key_info = getCompositeKeyInfo();
512  CHECK(!join_columns.empty());
513  CHECK(!join_bucket_info.empty());
514  HashTableCacheKey cache_key{join_columns.front().num_elems,
515  composite_key_info.cache_key_chunks,
516  condition_->get_optype(),
518  initHashTableOnCpuFromCache(cache_key);
519  if (cpu_hash_table_buff_) {
520  // See if a hash table of a different layout was returned.
521  // If it was OneToMany, we can reuse it on ManyToMany.
522  if (layout != layout_) {
526  }
527  }
528  return 0;
529  }
531  const auto key_component_width = getKeyComponentWidth();
532  const auto key_component_count = join_bucket_info[0].bucket_sizes_for_dimension.size();
533  const auto entry_size = key_component_count * key_component_width;
534  const auto keys_for_all_rows = emitted_keys_count_;
535  const size_t one_to_many_hash_entries = 2 * entry_count_ + keys_for_all_rows;
536  const size_t hash_table_size =
537  calculateHashTableSize(join_bucket_info[0].bucket_sizes_for_dimension.size(),
539  entry_count_);
540 
541  VLOG(1) << "Initializing CPU Overlaps Join Hash Table with " << entry_count_
542  << " hash entries and " << one_to_many_hash_entries
543  << " entries in the one to many buffer";
544  VLOG(1) << "Total hash table size: " << hash_table_size << " Bytes";
545 
546  cpu_hash_table_buff_.reset(new std::vector<int8_t>(hash_table_size));
547  int thread_count = cpu_threads();
548  std::vector<std::future<void>> init_cpu_buff_threads;
549  for (int thread_idx = 0; thread_idx < thread_count; ++thread_idx) {
550  init_cpu_buff_threads.emplace_back(std::async(
551  std::launch::async,
552  [this, key_component_count, key_component_width, thread_idx, thread_count] {
553  switch (key_component_width) {
554  case 4:
556  entry_count_,
557  key_component_count,
558  false,
559  -1,
560  thread_idx,
561  thread_count);
562  break;
563  case 8:
565  entry_count_,
566  key_component_count,
567  false,
568  -1,
569  thread_idx,
570  thread_count);
571  break;
572  default:
573  CHECK(false);
574  }
575  }));
576  }
577  for (auto& child : init_cpu_buff_threads) {
578  child.get();
579  }
580  std::vector<std::future<int>> fill_cpu_buff_threads;
581  for (int thread_idx = 0; thread_idx < thread_count; ++thread_idx) {
582  fill_cpu_buff_threads.emplace_back(std::async(
583  std::launch::async,
584  [this,
585  &join_columns,
586  &join_bucket_info,
587  key_component_count,
588  key_component_width,
589  thread_idx,
590  thread_count] {
591  switch (key_component_width) {
592  case 4: {
593  const auto key_handler = OverlapsKeyHandler(
594  key_component_count,
595  &join_columns[0],
596  join_bucket_info[0].bucket_sizes_for_dimension.data());
598  entry_count_,
599  -1,
600  key_component_count,
601  false,
602  &key_handler,
603  join_columns[0].num_elems,
604  thread_idx,
605  thread_count);
606  }
607  case 8: {
608  const auto key_handler = OverlapsKeyHandler(
609  key_component_count,
610  &join_columns[0],
611  join_bucket_info[0].bucket_sizes_for_dimension.data());
613  entry_count_,
614  -1,
615  key_component_count,
616  false,
617  &key_handler,
618  join_columns[0].num_elems,
619  thread_idx,
620  thread_count);
621  }
622  default:
623  CHECK(false);
624  }
625  return -1;
626  }));
627  }
628  int err = 0;
629  for (auto& child : fill_cpu_buff_threads) {
630  int partial_err = child.get();
631  if (partial_err) {
632  err = partial_err;
633  }
634  }
635  if (err) {
636  cpu_hash_table_buff_.reset();
637  return err;
638  }
639  auto one_to_many_buff =
640  reinterpret_cast<int32_t*>(&(*cpu_hash_table_buff_)[0] + entry_count_ * entry_size);
641  init_hash_join_buff(one_to_many_buff, entry_count_, -1, 0, 1);
642  switch (key_component_width) {
643  case 4: {
644  const auto composite_key_dict =
645  reinterpret_cast<int32_t*>(&(*cpu_hash_table_buff_)[0]);
647  composite_key_dict,
648  entry_count_,
649  -1,
650  key_component_count,
651  join_columns,
652  join_column_types,
653  join_bucket_info,
654  composite_key_info.sd_inner_proxy_per_key,
655  composite_key_info.sd_outer_proxy_per_key,
656  thread_count);
657  break;
658  }
659  case 8: {
660  const auto composite_key_dict =
661  reinterpret_cast<int64_t*>(&(*cpu_hash_table_buff_)[0]);
663  composite_key_dict,
664  entry_count_,
665  -1,
666  key_component_count,
667  join_columns,
668  join_column_types,
669  join_bucket_info,
670  composite_key_info.sd_inner_proxy_per_key,
671  composite_key_info.sd_outer_proxy_per_key,
672  thread_count);
673  break;
674  }
675  default:
676  CHECK(false);
677  }
678  if (!err && getInnerTableId() > 0) {
679  putHashTableOnCpuToCache(cache_key);
680  }
681  return err;
682 }
683 
685  const std::vector<JoinColumn>& join_columns,
686  const std::vector<JoinColumnTypeInfo>& join_column_types,
687  const std::vector<JoinBucketInfo>& join_bucket_info,
689  const size_t key_component_width,
690  const size_t key_component_count,
691  const int device_id) {
692  auto timer = DEBUG_TIMER(__func__);
693  int err = 0;
694  // TODO(adb): 4 byte keys
695  CHECK_EQ(key_component_width, size_t(8));
697 #ifdef HAVE_CUDA
698  const auto catalog = executor_->getCatalog();
699  auto& data_mgr = catalog->getDataMgr();
700  CudaAllocator allocator(&data_mgr, device_id);
701  auto dev_err_buff = reinterpret_cast<CUdeviceptr>(allocator.alloc(sizeof(int)));
702  copy_to_gpu(&data_mgr, dev_err_buff, &err, sizeof(err), device_id);
703  switch (key_component_width) {
704  case 4:
706  reinterpret_cast<int8_t*>(gpu_hash_table_buff_[device_id]->getMemoryPtr()),
707  entry_count_,
708  key_component_count,
709  false,
710  -1,
711  executor_->blockSize(),
712  executor_->gridSize());
713  break;
714  case 8:
716  reinterpret_cast<int8_t*>(gpu_hash_table_buff_[device_id]->getMemoryPtr()),
717  entry_count_,
718  key_component_count,
719  false,
720  -1,
721  executor_->blockSize(),
722  executor_->gridSize());
723  break;
724  default:
725  CHECK(false);
726  }
727  auto join_columns_gpu = transfer_vector_of_flat_objects_to_gpu(join_columns, allocator);
728  auto hash_buff = gpu_hash_table_buff_[device_id]->getMemoryPtr();
729  CHECK_EQ(join_columns.size(), 1u);
730  auto& bucket_sizes_for_dimension = join_bucket_info[0].bucket_sizes_for_dimension;
731  auto bucket_sizes_gpu =
732  transfer_vector_of_flat_objects_to_gpu(bucket_sizes_for_dimension, allocator);
733  const auto key_handler = OverlapsKeyHandler(
734  bucket_sizes_for_dimension.size(), join_columns_gpu, bucket_sizes_gpu);
735  const auto key_handler_gpu = transfer_flat_object_to_gpu(key_handler, allocator);
736  switch (key_component_width) {
737  case 8: {
739  hash_buff,
740  entry_count_,
741  -1,
742  key_component_count,
743  false,
744  reinterpret_cast<int*>(dev_err_buff),
745  key_handler_gpu,
746  join_columns.front().num_elems,
747  executor_->blockSize(),
748  executor_->gridSize());
749  copy_from_gpu(&data_mgr, &err, dev_err_buff, sizeof(err), device_id);
750  break;
751  }
752  default:
753  UNREACHABLE();
754  }
755  if (err) {
756  return err;
757  }
758  const auto entry_size = key_component_count * key_component_width;
759  auto one_to_many_buff = reinterpret_cast<int32_t*>(
760  gpu_hash_table_buff_[device_id]->getMemoryPtr() + entry_count_ * entry_size);
761  switch (key_component_width) {
762  case 8: {
763  const auto composite_key_dict =
764  reinterpret_cast<int64_t*>(gpu_hash_table_buff_[device_id]->getMemoryPtr());
765  init_hash_join_buff_on_device(one_to_many_buff,
766  entry_count_,
767  -1,
768  executor_->blockSize(),
769  executor_->gridSize());
771  one_to_many_buff,
772  composite_key_dict,
773  entry_count_,
774  -1,
775  key_handler_gpu,
776  join_columns.front().num_elems,
777  executor_->blockSize(),
778  executor_->gridSize());
779  break;
780  }
781  default:
782  UNREACHABLE();
783  }
784 #else
785  UNREACHABLE();
786 #endif
787  return err;
788 }
789 
790 #define LL_CONTEXT executor_->cgen_state_->context_
791 #define LL_BUILDER executor_->cgen_state_->ir_builder_
792 #define LL_INT(v) executor_->cgen_state_->llInt(v)
793 #define LL_FP(v) executor_->cgen_state_->llFp(v)
794 #define ROW_FUNC executor_->cgen_state_->row_func_
795 
797  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
798  const auto key_component_width = getKeyComponentWidth();
799  CHECK(key_component_width == 4 || key_component_width == 8);
800  const auto key_size_lv = LL_INT(getKeyComponentCount() * key_component_width);
801  llvm::Value* key_buff_lv{nullptr};
802  switch (key_component_width) {
803  case 4:
804  key_buff_lv =
805  LL_BUILDER.CreateAlloca(llvm::Type::getInt32Ty(LL_CONTEXT), key_size_lv);
806  break;
807  case 8:
808  key_buff_lv =
809  LL_BUILDER.CreateAlloca(llvm::Type::getInt64Ty(LL_CONTEXT), key_size_lv);
810  break;
811  default:
812  CHECK(false);
813  }
814 
815  const auto& inner_outer_pair = inner_outer_pairs_[0];
816  const auto outer_col = inner_outer_pair.second;
817  const auto outer_col_ti = outer_col->get_type_info();
818 
819  if (outer_col_ti.is_geometry()) {
820  CodeGenerator code_generator(executor_);
821  // TODO(adb): for points we will use the coords array, but for other geometries we
822  // will need to use the bounding box. For now only support points.
823  CHECK_EQ(outer_col_ti.get_type(), kPOINT);
824  CHECK_EQ(bucket_sizes_for_dimension_.size(), static_cast<size_t>(2));
825 
826  const auto col_lvs = code_generator.codegen(outer_col, true, co);
827  CHECK_EQ(col_lvs.size(), size_t(1));
828 
829  const auto outer_col_var = dynamic_cast<const Analyzer::ColumnVar*>(outer_col);
830  CHECK(outer_col_var);
831  const auto coords_cd = executor_->getCatalog()->getMetadataForColumn(
832  outer_col_var->get_table_id(), outer_col_var->get_column_id() + 1);
833  CHECK(coords_cd);
834 
835  const auto array_ptr = executor_->cgen_state_->emitExternalCall(
836  "array_buff",
837  llvm::Type::getInt8PtrTy(executor_->cgen_state_->context_),
838  {col_lvs.front(), code_generator.posArg(outer_col)});
839  CHECK(coords_cd->columnType.get_elem_type().get_type() == kTINYINT)
840  << "Only TINYINT coordinates columns are supported in geo overlaps hash join.";
841  const auto arr_ptr =
842  code_generator.castArrayPointer(array_ptr, coords_cd->columnType.get_elem_type());
843 
844  for (size_t i = 0; i < 2; i++) {
845  const auto key_comp_dest_lv = LL_BUILDER.CreateGEP(key_buff_lv, LL_INT(i));
846 
847  // Note that get_bucket_key_for_range_compressed will need to be specialized for
848  // future compression schemes
849  auto bucket_key =
850  outer_col_ti.get_compression() == kENCODING_GEOINT
851  ? executor_->cgen_state_->emitExternalCall(
852  "get_bucket_key_for_range_compressed",
854  {arr_ptr, LL_INT(i), LL_FP(bucket_sizes_for_dimension_[i])})
855  : executor_->cgen_state_->emitExternalCall(
856  "get_bucket_key_for_range_double",
858  {arr_ptr, LL_INT(i), LL_FP(bucket_sizes_for_dimension_[i])});
859  const auto col_lv = LL_BUILDER.CreateSExt(
860  bucket_key, get_int_type(key_component_width * 8, LL_CONTEXT));
861  LL_BUILDER.CreateStore(col_lv, key_comp_dest_lv);
862  }
863  } else {
864  LOG(FATAL) << "Overlaps key currently only supported for geospatial types.";
865  }
866  return key_buff_lv;
867 }
868 
869 std::vector<llvm::Value*> OverlapsJoinHashTable::codegenManyKey(
870  const CompilationOptions& co) {
871  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
872  const auto key_component_width = getKeyComponentWidth();
873  CHECK(key_component_width == 4 || key_component_width == 8);
875 
876  VLOG(1) << "Performing codgen for ManyToMany";
877  const auto& inner_outer_pair = inner_outer_pairs_[0];
878  const auto outer_col = inner_outer_pair.second;
879 
880  CodeGenerator code_generator(executor_);
881  const auto col_lvs = code_generator.codegen(outer_col, true, co);
882  CHECK_EQ(col_lvs.size(), size_t(1));
883 
884  const auto outer_col_var = dynamic_cast<const Analyzer::ColumnVar*>(outer_col);
885  CHECK(outer_col_var);
886  const auto coords_cd = executor_->getCatalog()->getMetadataForColumn(
887  outer_col_var->get_table_id(), outer_col_var->get_column_id());
888  CHECK(coords_cd);
889 
890  const auto array_ptr = executor_->cgen_state_->emitExternalCall(
891  "array_buff",
892  llvm::Type::getInt8PtrTy(executor_->cgen_state_->context_),
893  {col_lvs.front(), code_generator.posArg(outer_col)});
894 
895  // TODO(jclay): this seems to cast to double, and causes the GPU build to fail.
896  // const auto arr_ptr =
897  // code_generator.castArrayPointer(array_ptr,
898  // coords_cd->columnType.get_elem_type());
899  array_ptr->setName("array_ptr");
900 
901  auto num_keys_lv =
902  executor_->cgen_state_->emitExternalCall("get_num_buckets_for_bounds",
904  {array_ptr,
905  LL_INT(0),
908  num_keys_lv->setName("num_keys_lv");
909 
910  return {num_keys_lv, array_ptr};
911 }
912 
914  const CompilationOptions& co,
915  const size_t index) {
916  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
918  VLOG(1) << "Building codegenMatchingSet for ManyToMany";
919  const auto key_component_width = getKeyComponentWidth();
920  CHECK(key_component_width == 4 || key_component_width == 8);
921  auto many_to_many_args = codegenManyKey(co);
922  auto hash_ptr = JoinHashTable::codegenHashTableLoad(index, executor_);
923  const auto composite_dict_ptr_type =
924  llvm::Type::getIntNPtrTy(LL_CONTEXT, key_component_width * 8);
925  const auto composite_key_dict =
926  hash_ptr->getType()->isPointerTy()
927  ? LL_BUILDER.CreatePointerCast(hash_ptr, composite_dict_ptr_type)
928  : LL_BUILDER.CreateIntToPtr(hash_ptr, composite_dict_ptr_type);
929  const auto key_component_count = getKeyComponentCount();
930 
931  auto one_to_many_ptr = hash_ptr;
932 
933  if (one_to_many_ptr->getType()->isPointerTy()) {
934  one_to_many_ptr =
935  LL_BUILDER.CreatePtrToInt(hash_ptr, llvm::Type::getInt64Ty(LL_CONTEXT));
936  } else {
937  CHECK(one_to_many_ptr->getType()->isIntegerTy(64));
938  }
939 
940  const auto composite_key_dict_size = offsetBufferOff();
941  one_to_many_ptr =
942  LL_BUILDER.CreateAdd(one_to_many_ptr, LL_INT(composite_key_dict_size));
943 
944  // NOTE(jclay): A fixed array of size 200 is allocated on the stack.
945  // this is likely the maximum value we can do that is safe to use across
946  // all supported GPU architectures.
947  const int max_array_size = 200;
948  const auto arr_type = get_int_array_type(32, max_array_size, LL_CONTEXT);
949  const auto out_arr_lv = LL_BUILDER.CreateAlloca(arr_type);
950  out_arr_lv->setName("out_arr");
951 
952  const auto casted_out_arr_lv =
953  LL_BUILDER.CreatePointerCast(out_arr_lv, arr_type->getPointerTo());
954 
955  const auto element_ptr = LL_BUILDER.CreateGEP(arr_type, casted_out_arr_lv, LL_INT(0));
956 
957  auto rowid_ptr_i32 =
958  LL_BUILDER.CreatePointerCast(element_ptr, llvm::Type::getInt32PtrTy(LL_CONTEXT));
959 
960  const auto candidate_count_lv = executor_->cgen_state_->emitExternalCall(
961  "get_candidate_rows",
962  llvm::Type::getInt64Ty(LL_CONTEXT),
963  {
964  rowid_ptr_i32,
965  LL_INT(max_array_size),
966  many_to_many_args[1],
967  LL_INT(0),
970  many_to_many_args[0],
971  LL_INT(key_component_count), // key_component_count
972  composite_key_dict, // ptr to hash table
973  LL_INT(entry_count_), // entry_count
974  LL_INT(composite_key_dict_size), // offset_buffer_ptr_offset
975  LL_INT(entry_count_ * sizeof(int32_t)) // sub_buff_size
976  });
977 
978  const auto slot_lv = LL_INT(int64_t(0));
979 
980  return {rowid_ptr_i32, candidate_count_lv, slot_lv};
981  } else {
982  VLOG(1) << "Building codegenMatchingSet for Baseline";
984  }
985  UNREACHABLE();
986  return HashJoinMatchingSet{};
987 }
988 
990  std::vector<double>& bucket_sizes_for_dimension,
991  const JoinColumn& join_column,
992  const JoinColumnTypeInfo& join_column_type,
993  const std::vector<InnerOuter>& inner_outer_pairs) {
994  // No coalesced keys for overlaps joins yet
995  CHECK_EQ(inner_outer_pairs.size(), 1u);
996 
997  const auto col = inner_outer_pairs[0].first;
998  CHECK(col);
999  const auto col_ti = col->get_type_info();
1000  CHECK(col_ti.is_array());
1001 
1002  // TODO: Compute the number of dimensions for this overlaps key
1003  const int num_dims = 2;
1004  std::vector<double> local_bucket_sizes(num_dims, std::numeric_limits<double>::max());
1005 
1006  VLOG(1) << "Computing bucketed hashjoin with minimum bucket size "
1008 
1009  const auto effective_memory_level = getEffectiveMemoryLevel(inner_outer_pairs);
1010  if (effective_memory_level == Data_Namespace::MemoryLevel::CPU_LEVEL) {
1011  const int thread_count = cpu_threads();
1012  compute_bucket_sizes(local_bucket_sizes,
1013  join_column,
1014  join_column_type,
1016  thread_count);
1017  }
1018 #ifdef HAVE_CUDA
1019  else {
1020  // Note that we compute the bucket sizes using only a single GPU
1021  const int device_id = 0;
1022  auto& data_mgr = executor_->getCatalog()->getDataMgr();
1023  CudaAllocator allocator(&data_mgr, device_id);
1024  auto device_bucket_sizes_gpu =
1025  transfer_vector_of_flat_objects_to_gpu(local_bucket_sizes, allocator);
1026  auto join_column_gpu = transfer_flat_object_to_gpu(join_column, allocator);
1027  auto join_column_type_gpu = transfer_flat_object_to_gpu(join_column_type, allocator);
1028 
1029  compute_bucket_sizes_on_device(device_bucket_sizes_gpu,
1030  join_column_gpu,
1031  join_column_type_gpu,
1033  executor_->blockSize(),
1034  executor_->gridSize());
1035  allocator.copyFromDevice(reinterpret_cast<int8_t*>(local_bucket_sizes.data()),
1036  reinterpret_cast<int8_t*>(device_bucket_sizes_gpu),
1037  local_bucket_sizes.size() * sizeof(double));
1038  }
1039 #endif
1040 
1041  size_t ctr = 0;
1042  for (auto& bucket_sz : local_bucket_sizes) {
1043  VLOG(1) << "Computed bucket size for dim[" << ctr++ << "]: " << bucket_sz;
1044  bucket_sizes_for_dimension.push_back(1.0 / bucket_sz);
1045  }
1046 
1047  return;
1048 }
void fill_one_to_many_baseline_hash_table_32(int32_t *buff, const int32_t *composite_key_dict, const size_t hash_entry_count, const int32_t invalid_slot_val, const size_t key_component_count, const std::vector< JoinColumn > &join_column_per_key, const std::vector< JoinColumnTypeInfo > &type_info_per_key, const std::vector< JoinBucketInfo > &join_bucket_info, const std::vector< const void *> &sd_inner_proxy_per_key, const std::vector< const void *> &sd_outer_proxy_per_key, const int32_t cpu_thread_count)
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::vector< double > bucket_sizes_for_dimension_
int overlaps_fill_baseline_hash_join_buff_32(int8_t *hash_buff, const size_t entry_count, const int32_t invalid_slot_val, const size_t key_component_count, const bool with_val_slot, const OverlapsKeyHandler *key_handler, const size_t num_elems, const int32_t cpu_thread_idx, const int32_t cpu_thread_count)
std::pair< ssize_t, size_t > getApproximateTupleCountFromCache(const HashTableCacheKey &) const
int initHashTableOnGpu(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_bucket_info, const JoinHashTableInterface::HashType layout, const size_t key_component_width, const size_t key_component_count, const int device_id) override
Fragmenter_Namespace::TableInfo info
Definition: InputMetadata.h:35
void overlaps_fill_baseline_hash_join_buff_on_device_64(int8_t *hash_buff, const size_t entry_count, const int32_t invalid_slot_val, const size_t key_component_count, const bool with_val_slot, int *dev_err_buff, const OverlapsKeyHandler *key_handler, const size_t num_elems, const size_t block_size_x, const size_t grid_size_x)
void copyFromDevice(int8_t *host_dst, const int8_t *device_src, const size_t num_bytes) const override
void putHashTableOnCpuToCache(const HashTableCacheKey &)
void compute_bucket_sizes(std::vector< double > &bucket_sizes_for_dimension, const JoinColumn &join_column, const JoinColumnTypeInfo &type_info, const double bucket_size_threshold, const int thread_count)
std::vector< InnerOuter > normalize_column_pairs(const Analyzer::BinOper *condition, const Catalog_Namespace::Catalog &cat, const TemporaryTables *temporary_tables)
std::shared_ptr< std::vector< int8_t > > cpu_hash_table_buff_
DEVICE void SUFFIX() init_hash_join_buff(int32_t *groups_buffer, const int32_t hash_entry_count, const int32_t invalid_slot_val, const int32_t cpu_thread_idx, const int32_t cpu_thread_count)
static std::mutex auto_tuner_cache_mutex_
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:196
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > >> ColumnCacheMap
void init_baseline_hash_join_buff_64(int8_t *hash_join_buff, const int32_t entry_count, const size_t key_component_count, const bool with_val_slot, const int32_t invalid_slot_val, const int32_t cpu_thread_idx, const int32_t cpu_thread_count)
#define LOG(tag)
Definition: Logger.h:188
static std::shared_ptr< OverlapsJoinHashTable > getInstance(const std::shared_ptr< Analyzer::BinOper > condition, const std::vector< InputTableInfo > &query_infos, const Data_Namespace::MemoryLevel memory_level, const int device_count, ColumnCacheMap &column_cache, Executor *executor)
Make hash table from an in-flight SQL query&#39;s parse tree etc.
HashJoinMatchingSet codegenMatchingSet(const CompilationOptions &, const size_t) override
void hll_unify(T1 *lhs, T2 *rhs, const size_t m)
Definition: HyperLogLog.h:109
ColumnsForDevice fetchColumnsForDevice(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, DeviceAllocator *dev_buff_owner) override
unsigned long long CUdeviceptr
Definition: nocuda.h:27
#define LL_FP(v)
llvm::Value * castArrayPointer(llvm::Value *ptr, const SQLTypeInfo &elem_ti)
#define UNREACHABLE()
Definition: Logger.h:241
#define CHECK_GE(x, y)
Definition: Logger.h:210
void fill_one_to_many_baseline_hash_table_64(int32_t *buff, const int64_t *composite_key_dict, const size_t hash_entry_count, const int32_t invalid_slot_val, const size_t key_component_count, const std::vector< JoinColumn > &join_column_per_key, const std::vector< JoinColumnTypeInfo > &type_info_per_key, const std::vector< JoinBucketInfo > &join_bucket_info, const std::vector< const void *> &sd_inner_proxy_per_key, const std::vector< const void *> &sd_outer_proxy_per_key, const int32_t cpu_thread_count)
bool layoutRequiresAdditionalBuffers(JoinHashTableInterface::HashType layout) const noexcept override
void compute_bucket_sizes_on_device(double *bucket_sizes_buffer, const JoinColumn *join_column, const JoinColumnTypeInfo *type_info, const double bucket_sz_threshold, const size_t block_size_x, const size_t grid_size_x)
int initHashTableOnCpu(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const std::vector< JoinBucketInfo > &join_bucket_info, const JoinHashTableInterface::HashType layout) override
JoinHashTableInterface::HashType layout_
size_t get_entries_per_device(const size_t total_entries, const size_t shard_count, const size_t device_count, const Data_Namespace::MemoryLevel memory_level)
CompositeKeyInfo getCompositeKeyInfo() const
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
size_t hll_size(const T *M, const size_t bitmap_sz_bits)
Definition: HyperLogLog.h:90
#define CHECK_GT(x, y)
Definition: Logger.h:209
std::vector< Fragmenter_Namespace::FragmentInfo > only_shards_for_device(const std::vector< Fragmenter_Namespace::FragmentInfo > &fragments, const int device_id, const int device_count)
static std::map< HashTableCacheKey, double > auto_tuner_cache_
std::string to_string(char const *&&v)
const std::vector< InputTableInfo > & query_infos_
std::vector< JoinBucketInfo > computeBucketInfo(const std::vector< JoinColumn > &join_columns, const std::vector< JoinColumnTypeInfo > &join_column_types, const int device_id)
llvm::Value * codegenKey(const CompilationOptions &) override
std::vector< InnerOuter > inner_outer_pairs_
void reifyForDevice(const ColumnsForDevice &columns_for_device, const JoinHashTableInterface::HashType layout, const int device_id, const logger::ThreadId parent_thread_id)
size_t calculateHashTableSize(size_t number_of_dimensions, size_t emitted_keys_count, size_t entry_count) const
void copy_to_gpu(Data_Namespace::DataMgr *data_mgr, CUdeviceptr dst, const void *src, const size_t num_bytes, const int device_id)
Definition: GpuMemUtils.cpp:30
const ColumnDescriptor * get_column_descriptor_maybe(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:149
void computeBucketSizes(std::vector< double > &bucket_sizes_for_dimension, const JoinColumn &join_column, const JoinColumnTypeInfo &join_column_type, const std::vector< InnerOuter > &inner_outer_pairs)
ColumnCacheMap & column_cache_
void copy_from_gpu(Data_Namespace::DataMgr *data_mgr, void *dst, const CUdeviceptr src, const size_t num_bytes, const int device_id)
T * transfer_flat_object_to_gpu(const T &object, CudaAllocator &allocator)
int overlaps_fill_baseline_hash_join_buff_64(int8_t *hash_buff, const size_t entry_count, const int32_t invalid_slot_val, const size_t key_component_count, const bool with_val_slot, const OverlapsKeyHandler *key_handler, const size_t num_elems, const int32_t cpu_thread_idx, const int32_t cpu_thread_count)
void init_baseline_hash_join_buff_on_device_32(int8_t *hash_join_buff, const int32_t entry_count, const size_t key_component_count, const bool with_val_slot, const int32_t invalid_slot_val, const size_t block_size_x, const size_t grid_size_x)
int getInnerTableId() const noexcept override
#define LL_BUILDER
size_t g_overlaps_max_table_size_bytes
Definition: Execute.cpp:94
std::vector< llvm::Value * > codegenManyKey(const CompilationOptions &)
#define AUTOMATIC_IR_METADATA(CGENSTATE)
std::pair< size_t, size_t > calculateCounts(size_t shard_count, const Fragmenter_Namespace::TableInfo &query_info, std::vector< BaselineJoinHashTable::ColumnsForDevice > &columns_per_device)
#define VLOGGING(n)
Definition: Logger.h:195
void init_baseline_hash_join_buff_on_device_64(int8_t *hash_join_buff, const int32_t entry_count, const size_t key_component_count, const bool with_val_slot, const int32_t invalid_slot_val, const size_t block_size_x, const size_t grid_size_x)
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
Definition: IRCodegen.cpp:26
int8_t * alloc(const size_t num_bytes) override
void approximate_distinct_tuples_overlaps(uint8_t *hll_buffer_all_cpus, std::vector< int32_t > &row_counts, const uint32_t b, const size_t padded_size_bytes, const std::vector< JoinColumn > &join_column_per_key, const std::vector< JoinColumnTypeInfo > &type_info_per_key, const std::vector< JoinBucketInfo > &join_buckets_per_key, const int thread_count)
#define LL_INT(v)
void reifyWithLayout(const JoinHashTableInterface::HashType layout) override
JoinColumn fetchJoinColumn(const Analyzer::ColumnVar *hash_col, const std::vector< Fragmenter_Namespace::FragmentInfo > &fragment_info, const Data_Namespace::MemoryLevel effective_memory_level, const int device_id, std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner, DeviceAllocator *dev_buff_owner, std::vector< std::shared_ptr< void >> &malloc_owner, Executor *executor, ColumnCacheMap *column_cache)
const Catalog_Namespace::Catalog * catalog_
static llvm::Value * codegenHashTableLoad(const size_t table_idx, Executor *executor)
HashJoinMatchingSet codegenMatchingSet(const CompilationOptions &, const size_t) override
size_t offsetBufferOff() const noexcept override
void init_hash_join_buff_on_device(int32_t *buff, const int32_t entry_count, const int32_t invalid_slot_val, const size_t block_size_x, const size_t grid_size_x)
const Data_Namespace::MemoryLevel memory_level_
size_t getKeyComponentCount() const override
ThreadId thread_id()
Definition: Logger.cpp:731
ColumnType get_join_column_type_kind(const SQLTypeInfo &ti)
void initHashTableOnCpuFromCache(const HashTableCacheKey &)
#define CHECK(condition)
Definition: Logger.h:197
T * transfer_vector_of_flat_objects_to_gpu(const std::vector< T > &vec, CudaAllocator &allocator)
#define DEBUG_TIMER(name)
Definition: Logger.h:313
Data_Namespace::MemoryLevel getEffectiveMemoryLevel(const std::vector< InnerOuter > &inner_outer_pairs) const
void approximate_distinct_tuples_on_device_overlaps(uint8_t *hll_buffer, const uint32_t b, int32_t *row_counts_buffer, const OverlapsKeyHandler *key_handler, const size_t num_elems, const size_t block_size_x, const size_t grid_size_x)
std::pair< size_t, size_t > approximateTupleCount(const std::vector< ColumnsForDevice > &) const override
static std::string getHashTypeString(HashType ht) noexcept
void overlaps_fill_one_to_many_baseline_hash_table_on_device_64(int32_t *buff, const int64_t *composite_key_dict, const size_t hash_entry_count, const int32_t invalid_slot_val, const OverlapsKeyHandler *key_handler, const size_t num_elems, const size_t block_size_x, const size_t grid_size_x)
static size_t getShardCountForCondition(const Analyzer::BinOper *condition, const Executor *executor, const std::vector< InnerOuter > &inner_outer_pairs)
#define LL_CONTEXT
JoinHashTableInterface::HashType getHashType() const noexcept override
int cpu_threads()
Definition: thread_count.h:24
llvm::ArrayType * get_int_array_type(int const width, int count, llvm::LLVMContext &context)
const InputTableInfo & get_inner_query_info(const int inner_table_id, const std::vector< InputTableInfo > &query_infos)
#define VLOG(n)
Definition: Logger.h:291
const std::shared_ptr< Analyzer::BinOper > condition_
void init_baseline_hash_join_buff_32(int8_t *hash_join_buff, const int32_t entry_count, const size_t key_component_count, const bool with_val_slot, const int32_t invalid_slot_val, const int32_t cpu_thread_idx, const int32_t cpu_thread_count)
size_t getKeyComponentWidth() const override