Skip to content

Commit

Permalink
Remove entry count state from perfect hash table
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbaden authored and andrewseidl committed Jan 25, 2021
1 parent cd22149 commit e4d26ea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
31 changes: 23 additions & 8 deletions QueryEngine/JoinHashTable/PerfectJoinHashTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,6 @@ int PerfectJoinHashTable::initHashTableForDevice(
#ifndef HAVE_CUDA
CHECK_EQ(Data_Namespace::CPU_LEVEL, effective_memory_level);
#endif
if (!device_id) {
hash_entry_count_ = hash_entry_info.getNormalizedHashEntryCount();
}

int err{0};
const int32_t hash_join_invalid_val{-1};
if (effective_memory_level == Data_Namespace::CPU_LEVEL) {
Expand Down Expand Up @@ -801,18 +797,29 @@ size_t PerfectJoinHashTable::payloadBufferOff() const noexcept {
}

size_t PerfectJoinHashTable::getComponentBufferSize() const noexcept {
if (hash_type_ == HashType::OneToMany) {
return hash_entry_count_ * sizeof(int32_t);
if (hash_tables_for_device_.empty()) {
return 0;
}
auto hash_table = hash_tables_for_device_.front();
CHECK(hash_table);
if (hash_table->getLayout() == HashType::OneToMany) {
return hash_table->getEntryCount() * sizeof(int32_t);
} else {
return 0;
}
}

HashTable* PerfectJoinHashTable::getHashTableForDevice(const size_t device_id) const {
CHECK_LT(device_id, hash_tables_for_device_.size());
return hash_tables_for_device_[device_id].get();
}

std::string PerfectJoinHashTable::toString(const ExecutorDeviceType device_type,
const int device_id,
bool raw) const {
auto buffer = getJoinHashBuffer(device_type, device_id);
auto buffer_size = getJoinHashBufferSize(device_type, device_id);
auto hash_table = getHashTableForDevice(device_id);
#ifdef HAVE_CUDA
std::unique_ptr<int8_t[]> buffer_copy;
if (device_type == ExecutorDeviceType::GPU) {
Expand All @@ -835,7 +842,7 @@ std::string PerfectJoinHashTable::toString(const ExecutorDeviceType device_type,
getHashTypeString(hash_type_),
0,
0,
hash_entry_count_,
hash_table ? hash_table->getEntryCount() : 0,
ptr1,
ptr2,
ptr3,
Expand All @@ -849,6 +856,7 @@ std::set<DecodedJoinHashBufferEntry> PerfectJoinHashTable::toSet(
const int device_id) const {
auto buffer = getJoinHashBuffer(device_type, device_id);
auto buffer_size = getJoinHashBufferSize(device_type, device_id);
auto hash_table = getHashTableForDevice(device_id);
#ifdef HAVE_CUDA
std::unique_ptr<int8_t[]> buffer_copy;
if (device_type == ExecutorDeviceType::GPU) {
Expand All @@ -867,7 +875,14 @@ std::set<DecodedJoinHashBufferEntry> PerfectJoinHashTable::toSet(
auto ptr2 = ptr1 + offsetBufferOff();
auto ptr3 = ptr1 + countBufferOff();
auto ptr4 = ptr1 + payloadBufferOff();
return HashTable::toSet(0, 0, hash_entry_count_, ptr1, ptr2, ptr3, ptr4, buffer_size);
return HashTable::toSet(0,
0,
hash_table ? hash_table->getEntryCount() : 0,
ptr1,
ptr2,
ptr3,
ptr4,
buffer_size);
}

llvm::Value* PerfectJoinHashTable::codegenSlot(const CompilationOptions& co,
Expand Down
4 changes: 2 additions & 2 deletions QueryEngine/JoinHashTable/PerfectJoinHashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class PerfectJoinHashTable : public HashJoin {
, query_infos_(query_infos)
, memory_level_(memory_level)
, hash_type_(preferred_hash_type)
, hash_entry_count_(0)
, col_range_(col_range)
, executor_(executor)
, column_cache_(column_cache)
Expand Down Expand Up @@ -185,12 +184,13 @@ class PerfectJoinHashTable : public HashJoin {

size_t getComponentBufferSize() const noexcept override;

HashTable* getHashTableForDevice(const size_t device_id) const;

std::shared_ptr<Analyzer::BinOper> qual_bin_oper_;
std::shared_ptr<Analyzer::ColumnVar> col_var_;
const std::vector<InputTableInfo>& query_infos_;
const Data_Namespace::MemoryLevel memory_level_;
HashType hash_type_;
size_t hash_entry_count_;

std::mutex cpu_hash_table_buff_mutex_;
ExpressionRange col_range_;
Expand Down

0 comments on commit e4d26ea

Please sign in to comment.