OmniSciDB  cde582ebc3
 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  : data_mgr_(data_mgr)
34  , layout_(layout)
35  , entry_count_(entry_count)
36  , emitted_keys_count_(emitted_keys_count) {
37  if (device_type == ExecutorDeviceType::CPU) {
39  ? entry_count_
42  }
43  }
44 
45  ~PerfectHashTable() override {
49  }
50  }
51 
52  size_t gpuReservedSize() const {
55  }
56 
57  void allocateGpuMemory(const size_t entries, const int device_id) {
58  CHECK_GE(device_id, 0);
61  data_mgr_, entries * sizeof(int32_t), device_id);
62  }
63 
64  size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override {
65  if (device_type == ExecutorDeviceType::CPU) {
67  sizeof(decltype(cpu_hash_table_buff_)::element_type);
68  } else {
70  }
71  }
72 
73  HashType getLayout() const override { return layout_; }
74 
75  int8_t* getCpuBuffer() override {
76  return reinterpret_cast<int8_t*>(cpu_hash_table_buff_.get());
77  }
78 
79  int8_t* getGpuBuffer() const override {
81  }
82 
83  size_t getEntryCount() const override { return entry_count_; }
84 
85  size_t getEmittedKeysCount() const override { return emitted_keys_count_; }
86 
87  void setHashEntryInfo(HashEntryInfo& hash_entry_info) {
88  hash_entry_info_ = hash_entry_info;
89  }
90 
91  void setColumnNumElems(size_t elem) { column_num_elems_ = elem; }
92 
94 
95  size_t getColumnNumElems() const { return column_num_elems_; }
96 
97  private:
100  std::unique_ptr<int32_t[]> cpu_hash_table_buff_;
102 
104  size_t entry_count_; // number of keys in the hash table
105  size_t emitted_keys_count_; // number of keys emitted across all rows
106 
109 };
HashEntryInfo 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:235
virtual size_t reservedSize() const =0
Data_Namespace::AbstractBuffer * gpu_hash_table_buff_
size_t getEntryCount() const override
PerfectHashTable(Data_Namespace::DataMgr *data_mgr, const HashType layout, const ExecutorDeviceType device_type, const size_t entry_count, const size_t emitted_keys_count)
size_t getEmittedKeysCount() const override
void setColumnNumElems(size_t elem)
An AbstractBuffer is a unit of data management for a data manager.
size_t gpuReservedSize() const
HashEntryInfo 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:222
~PerfectHashTable() override
size_t getColumnNumElems() const
void setHashEntryInfo(HashEntryInfo &hash_entry_info)
Allocate GPU memory using GpuBuffers via DataMgr.
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:528
void allocateGpuMemory(const size_t entries, const int device_id)
Data_Namespace::DataMgr * data_mgr_
HashType
Definition: HashTable.h:19