OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BaselineHashTable.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 "DataMgr/AbstractBuffer.h"
23 
25 
26 class BaselineHashTable : public HashTable {
27  public:
28  // CPU constructor
30  const size_t entry_count,
31  const size_t emitted_keys_count,
32  const size_t hash_table_size)
33  : cpu_hash_table_buff_size_(hash_table_size)
34  , gpu_hash_table_buff_(nullptr)
35 #ifdef HAVE_CUDA
36  , device_id_(0)
37  , data_mgr_(nullptr)
38 #endif
39  , layout_(layout)
40  , entry_count_(entry_count)
41  , emitted_keys_count_(emitted_keys_count) {
43  }
44 
45  // GPU constructor
47  HashType layout,
48  const size_t entry_count,
49  const size_t emitted_keys_count,
50  const size_t hash_table_size,
51  const size_t device_id)
52  : gpu_hash_table_buff_(nullptr)
53 #ifdef HAVE_CUDA
54  , device_id_(device_id)
55  , data_mgr_(data_mgr)
56 #endif
57  , layout_(layout)
58  , entry_count_(entry_count)
59  , emitted_keys_count_(emitted_keys_count) {
60 #ifdef HAVE_CUDA
63  CudaAllocator::allocGpuAbstractBuffer(data_mgr_, hash_table_size, device_id_);
64 #else
65  UNREACHABLE();
66 #endif
67  }
68 
69  ~BaselineHashTable() override {
70 #ifdef HAVE_CUDA
74  }
75 #endif
76  }
77 
78  int8_t* getGpuBuffer() const override {
80  }
81 
82  size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override {
83  if (device_type == ExecutorDeviceType::CPU) {
85  sizeof(decltype(cpu_hash_table_buff_)::element_type);
86  } else {
88  }
89  }
90 
91  int8_t* getCpuBuffer() override {
92  return reinterpret_cast<int8_t*>(cpu_hash_table_buff_.get());
93  }
94 
95  HashType getLayout() const override { return layout_; }
96  size_t getEntryCount() const override { return entry_count_; }
97  size_t getEmittedKeysCount() const override { return emitted_keys_count_; }
98 
99  private:
100  std::unique_ptr<int8_t[]> cpu_hash_table_buff_;
103 
104 #ifdef HAVE_CUDA
105  const size_t device_id_;
107 #endif
108 
110  size_t entry_count_; // number of keys in the hash table
111  size_t emitted_keys_count_; // number of keys emitted across all rows
112 };
int8_t * getGpuBuffer() const override
size_t getEntryCount() const override
ExecutorDeviceType
BaselineHashTable(Data_Namespace::DataMgr *data_mgr, HashType layout, const size_t entry_count, const size_t emitted_keys_count, const size_t hash_table_size, const size_t device_id)
virtual int8_t * getMemoryPtr()=0
HashType getLayout() const override
#define UNREACHABLE()
Definition: Logger.h:337
size_t getEmittedKeysCount() const override
virtual size_t reservedSize() const =0
size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override
BaselineHashTable(HashType layout, const size_t entry_count, const size_t emitted_keys_count, const size_t hash_table_size)
An AbstractBuffer is a unit of data management for a data manager.
std::unique_ptr< int8_t[]> cpu_hash_table_buff_
~BaselineHashTable() override
Data_Namespace::AbstractBuffer * gpu_hash_table_buff_
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
data_mgr_(data_mgr)
int8_t * getCpuBuffer() override
#define CHECK(condition)
Definition: Logger.h:291
Allocate GPU memory using GpuBuffers via DataMgr.
HashType
Definition: HashTable.h:19