OmniSciDB  a7179b2938
 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  public:
27  // CPU constructor
30  const size_t entry_count,
31  const size_t emitted_keys_count,
32  const size_t hash_table_size)
33  : device_id_(0)
34  , catalog_(catalog)
35  , layout_(layout)
36  , entry_count_(entry_count)
37  , emitted_keys_count_(emitted_keys_count) {
38  cpu_hash_table_buff_.resize(hash_table_size);
39  }
40 
41  // GPU constructor
44  const size_t entry_count,
45  const size_t emitted_keys_count,
46  const size_t hash_table_size,
47  const size_t device_id)
48  : device_id_(device_id)
49  , catalog_(catalog)
50  , layout_(layout)
51  , entry_count_(entry_count)
52  , emitted_keys_count_(emitted_keys_count) {
53 #ifdef HAVE_CUDA
54  CHECK(catalog_);
55  auto& data_mgr = catalog_->getDataMgr();
56  gpu_hash_table_buff_ =
57  CudaAllocator::allocGpuAbstractBuffer(&data_mgr, hash_table_size, device_id_);
58 #else
59  UNREACHABLE();
60 #endif
61  }
62 
64 #ifdef HAVE_CUDA
65  CHECK(catalog_);
66  auto& data_mgr = catalog_->getDataMgr();
67  if (gpu_hash_table_buff_) {
68  data_mgr.free(gpu_hash_table_buff_);
69  }
70 #endif
71  }
72 
73  Data_Namespace::AbstractBuffer* getGpuBuffer() const { return gpu_hash_table_buff_; }
74 
75  size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const {
76  if (device_type == ExecutorDeviceType::CPU) {
77  return cpu_hash_table_buff_.size() *
78  sizeof(decltype(cpu_hash_table_buff_)::value_type);
79  } else {
80  const auto gpu_buff = getGpuBuffer();
81  return gpu_buff ? gpu_buff->reservedSize() : 0;
82  }
83  }
84 
85  int8_t* getCpuBuffer() { return cpu_hash_table_buff_.data(); }
86  size_t getCpuBufferSize() { return cpu_hash_table_buff_.size(); }
87 
88  auto getLayout() const { return layout_; }
89  size_t getEntryCount() const { return entry_count_; }
90  size_t getEmittedKeysCount() const { return emitted_keys_count_; }
91 
92  private:
93  std::vector<int8_t> cpu_hash_table_buff_;
94  Data_Namespace::AbstractBuffer* gpu_hash_table_buff_{nullptr};
95  const size_t device_id_;
96 
97  // TODO: only required for cuda
99 
101  // size_t key_component_count_;
102  // size_t key_component_width_;
103  size_t entry_count_; // number of keys in the hash table
104  size_t emitted_keys_count_; // number of keys emitted across all rows
105 };
size_t getEmittedKeysCount() const
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:97
JoinHashTableInterface::HashType layout_
ExecutorDeviceType
size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:209
BaselineHashTable(const Catalog_Namespace::Catalog *catalog, JoinHashTableInterface::HashType layout, const size_t entry_count, const size_t emitted_keys_count, const size_t hash_table_size, const size_t device_id)
#define UNREACHABLE()
Definition: Logger.h:241
const Catalog_Namespace::Catalog * catalog_
std::vector< int8_t > cpu_hash_table_buff_
BaselineHashTable(const Catalog_Namespace::Catalog *catalog, JoinHashTableInterface::HashType layout, const size_t entry_count, const size_t emitted_keys_count, const size_t hash_table_size)
const size_t device_id_
This file contains the class specification and related data structures for Catalog.
Data_Namespace::AbstractBuffer * getGpuBuffer() const
An AbstractBuffer is a unit of data management for a data manager.
size_t getEntryCount() 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
auto getLayout() const
Allocate GPU memory using GpuBuffers via DataMgr.
void free(AbstractBuffer *buffer)
Definition: DataMgr.cpp:464