OmniSciDB  6686921089
 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 2020 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 
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  private:
90  std::unique_ptr<int32_t[]> cpu_hash_table_buff_;
92 
94  size_t entry_count_; // number of keys in the hash table
95  size_t emitted_keys_count_; // number of keys emitted across all rows
96 };
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:222
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
An AbstractBuffer is a unit of data management for a data manager.
size_t gpuReservedSize() const
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:209
~PerfectHashTable() override
Allocate GPU memory using GpuBuffers via DataMgr.
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:530
void allocateGpuMemory(const size_t entries, const int device_id)
Data_Namespace::DataMgr * data_mgr_
HashType
Definition: HashTable.h:19