OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PerfectHashTable.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
17 #pragma once
18 
19 #include <memory>
20 #include <vector>
21 
24 
25 class PerfectHashTable : public HashTable {
26  public:
27  // CPU + GPU constructor
29  const HashType layout,
30  const ExecutorDeviceType device_type,
31  const size_t entry_count,
32  const size_t emitted_keys_count,
33  const bool for_window_framing = false)
34  : data_mgr_(data_mgr)
35  , layout_(layout)
36  , entry_count_(entry_count)
37  , emitted_keys_count_(emitted_keys_count) {
38  std::string device_str = "GPU";
39  if (device_type == ExecutorDeviceType::CPU) {
40  device_str = "CPU";
43  ? entry_count_
44  : 2 * entry_count_ + ((1 + for_window_framing) * emitted_keys_count_);
46  }
47  VLOG(1) << "Initialize a " << device_str << " perfect hash table for join type "
48  << ::toString(layout) << " # hash entries: " << entry_count
49  << ", # entries stored in the payload buffer: " << emitted_keys_count
50  << ", hash table size : " << cpu_hash_table_buff_size_ * 4 << " Bytes";
51  }
52 
53  ~PerfectHashTable() override {
57  }
58  }
59 
60  size_t gpuReservedSize() const {
63  }
64 
65  void allocateGpuMemory(const size_t entries, const int device_id) {
66  CHECK_GE(device_id, 0);
69  data_mgr_, entries * sizeof(int32_t), device_id);
70  }
71 
72  size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override {
73  if (device_type == ExecutorDeviceType::CPU) {
75  sizeof(decltype(cpu_hash_table_buff_)::element_type);
76  } else {
78  }
79  }
80 
81  HashType getLayout() const override { return layout_; }
82 
83  int8_t* getCpuBuffer() override {
84  return reinterpret_cast<int8_t*>(cpu_hash_table_buff_.get());
85  }
86 
87  int8_t* getGpuBuffer() const override {
89  }
90 
91  size_t getEntryCount() const override { return entry_count_; }
92 
93  size_t getEmittedKeysCount() const override { return emitted_keys_count_; }
94 
95  void setHashEntryInfo(BucketizedHashEntryInfo& hash_entry_info) {
96  hash_entry_info_ = hash_entry_info;
97  }
98 
99  void setColumnNumElems(size_t elem) { column_num_elems_ = elem; }
100 
102 
103  size_t getColumnNumElems() const { return column_num_elems_; }
104 
105  private:
108  std::unique_ptr<int32_t[]> cpu_hash_table_buff_;
110 
112  size_t entry_count_; // number of keys in the hash table
113  size_t emitted_keys_count_; // number of keys emitted across all rows
114 
117 };
BucketizedHashEntryInfo getHashEntryInfo() const
ExecutorDeviceType
int8_t * getGpuBuffer() const override
int8_t * getCpuBuffer() override
HashType getLayout() const override
virtual int8_t * getMemoryPtr()=0
size_t cpu_hash_table_buff_size_
std::unique_ptr< int32_t[]> cpu_hash_table_buff_
size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override
#define CHECK_GE(x, y)
Definition: Logger.h:302
virtual size_t reservedSize() const =0
Data_Namespace::AbstractBuffer * gpu_hash_table_buff_
size_t getEntryCount() const override
size_t getEmittedKeysCount() const override
void setColumnNumElems(size_t elem)
An AbstractBuffer is a unit of data management for a data manager.
void setHashEntryInfo(BucketizedHashEntryInfo &hash_entry_info)
PerfectHashTable(Data_Namespace::DataMgr *data_mgr, const HashType layout, const ExecutorDeviceType device_type, const size_t entry_count, const size_t emitted_keys_count, const bool for_window_framing=false)
size_t gpuReservedSize() const
static std::string toString(const std::string &type, const std::string &layout_type, size_t key_component_count, size_t key_component_width, size_t entry_count, const int8_t *ptr1, const int8_t *ptr2, const int8_t *ptr3, const int8_t *ptr4, size_t buffer_size, bool raw=false)
Decode hash table into a human-readable string.
Definition: HashTable.cpp:226
BucketizedHashEntryInfo hash_entry_info_
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
#define CHECK(condition)
Definition: Logger.h:289
~PerfectHashTable() override
size_t getColumnNumElems() const
Allocate GPU memory using GpuBuffers via DataMgr.
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:525
void allocateGpuMemory(const size_t entries, const int device_id)
Data_Namespace::DataMgr * data_mgr_
HashType
Definition: HashTable.h:19
#define VLOG(n)
Definition: Logger.h:383