OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
23 
24 class PerfectHashTable : public HashTable {
25  public:
26  // CPU + GPU constructor
28  const HashType layout,
29  const ExecutorDeviceType device_type,
30  const size_t entry_count,
31  const size_t emitted_keys_count)
32  : catalog_(catalog)
33  , layout_(layout)
34  , entry_count_(entry_count)
35  , emitted_keys_count_(emitted_keys_count) {
36  if (device_type == ExecutorDeviceType::CPU) {
38  ? entry_count_
40  }
41  }
42 
44  CHECK(catalog_);
45  auto& data_mgr = catalog_->getDataMgr();
47  data_mgr.free(gpu_hash_table_buff_);
48  }
49  }
50 
51  size_t gpuReservedSize() const {
54  }
55 
56  void allocateGpuMemory(const size_t entries, const int device_id) {
57  CHECK(catalog_);
58  auto& data_mgr = catalog_->getDataMgr();
59  CHECK_GE(device_id, 0);
62  &data_mgr, entries * sizeof(int32_t), device_id);
63  }
64 
65  size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override {
66  if (device_type == ExecutorDeviceType::CPU) {
67  return cpu_hash_table_buff_.size() *
68  sizeof(decltype(cpu_hash_table_buff_)::value_type);
69  } else {
71  }
72  }
73 
74  HashType getLayout() const override { return layout_; }
75 
76  int8_t* getCpuBuffer() override {
77  return reinterpret_cast<int8_t*>(cpu_hash_table_buff_.data());
78  }
79 
80  int8_t* getGpuBuffer() const override {
82  }
83 
84  size_t getEntryCount() const override { return entry_count_; }
85 
86  size_t getEmittedKeysCount() const override { return emitted_keys_count_; }
87 
88  private:
91  std::vector<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 };
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:101
ExecutorDeviceType
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:222
int8_t * getGpuBuffer() const override
int8_t * getCpuBuffer() override
HashType getLayout() const override
virtual int8_t * getMemoryPtr()=0
size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override
#define CHECK_GE(x, y)
Definition: Logger.h:210
virtual size_t reservedSize() const =0
Data_Namespace::AbstractBuffer * gpu_hash_table_buff_
size_t getEntryCount() const override
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:197
PerfectHashTable(const Catalog_Namespace::Catalog *catalog, const HashType layout, const ExecutorDeviceType device_type, const size_t entry_count, const size_t emitted_keys_count)
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:469
void allocateGpuMemory(const size_t entries, const int device_id)
HashType
Definition: HashTable.h:19
std::vector< int32_t > cpu_hash_table_buff_
const Catalog_Namespace::Catalog * catalog_