OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaselineHashTable.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 "Catalog/Catalog.h"
20 #include "DataMgr/AbstractBuffer.h"
24 
26 
27 class BaselineHashTable : public HashTable {
28  public:
29  // CPU constructor
31  HashType layout,
32  const size_t entry_count,
33  const size_t emitted_keys_count,
34  const size_t hash_table_size)
35  : gpu_hash_table_buff_(nullptr)
36 #ifdef HAVE_CUDA
37  , device_id_(0)
38  , catalog_(catalog)
39 #endif
40  , layout_(layout)
41  , entry_count_(entry_count)
42  , emitted_keys_count_(emitted_keys_count) {
43  cpu_hash_table_buff_.resize(hash_table_size);
44  }
45 
46  // GPU constructor
48  HashType layout,
49  const size_t entry_count,
50  const size_t emitted_keys_count,
51  const size_t hash_table_size,
52  const size_t device_id)
53  : gpu_hash_table_buff_(nullptr)
54 #ifdef HAVE_CUDA
55  , device_id_(device_id)
56  , catalog_(catalog)
57 #endif
58  , layout_(layout)
59  , entry_count_(entry_count)
60  , emitted_keys_count_(emitted_keys_count) {
61 #ifdef HAVE_CUDA
62  CHECK(catalog_);
63  auto& data_mgr = catalog_->getDataMgr();
65  CudaAllocator::allocGpuAbstractBuffer(&data_mgr, hash_table_size, device_id_);
66 #else
67  UNREACHABLE();
68 #endif
69  }
70 
72 #ifdef HAVE_CUDA
73  CHECK(catalog_);
74  auto& data_mgr = catalog_->getDataMgr();
76  data_mgr.free(gpu_hash_table_buff_);
77  }
78 #endif
79  }
80 
81  int8_t* getGpuBuffer() const override {
83  }
84 
85  size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override {
86  if (device_type == ExecutorDeviceType::CPU) {
87  return cpu_hash_table_buff_.size() *
88  sizeof(decltype(cpu_hash_table_buff_)::value_type);
89  } else {
91  }
92  }
93 
94  int8_t* getCpuBuffer() override {
95  return reinterpret_cast<int8_t*>(cpu_hash_table_buff_.data());
96  }
97 
98  HashType getLayout() const override { return layout_; }
99  size_t getEntryCount() const override { return entry_count_; }
100  size_t getEmittedKeysCount() const override { return emitted_keys_count_; }
101 
102  private:
103  std::vector<int8_t> cpu_hash_table_buff_;
105 
106 #ifdef HAVE_CUDA
107  const size_t device_id_;
109 #endif
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 };
catalog_(nullptr)
int8_t * getGpuBuffer() const override
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:102
size_t getEntryCount() const override
ExecutorDeviceType
virtual int8_t * getMemoryPtr()=0
HashType getLayout() const override
#define UNREACHABLE()
Definition: Logger.h:247
size_t getEmittedKeysCount() const override
virtual size_t reservedSize() const =0
std::vector< int8_t > cpu_hash_table_buff_
size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const override
This file contains the class specification and related data structures for Catalog.
An AbstractBuffer is a unit of data management for a data manager.
BaselineHashTable(const Catalog_Namespace::Catalog *catalog, HashType layout, const size_t entry_count, const size_t emitted_keys_count, const size_t hash_table_size, const size_t device_id)
BaselineHashTable(const Catalog_Namespace::Catalog *catalog, HashType layout, const size_t entry_count, const size_t emitted_keys_count, const size_t hash_table_size)
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)
int8_t * getCpuBuffer() override
#define CHECK(condition)
Definition: Logger.h:203
Allocate GPU memory using GpuBuffers via DataMgr.
HashType
Definition: HashTable.h:19