Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport array join probe opt #445

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions velox/exec/HashTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,7 @@ void HashTable<ignoreNullKeys>::arrayGroupProbe(HashLookup& lookup) {
template <bool ignoreNullKeys>
void HashTable<ignoreNullKeys>::joinProbe(HashLookup& lookup) {
if (hashMode_ == HashMode::kArray) {
for (auto row : lookup.rows) {
auto index = lookup.hashes[row];
DCHECK_LT(index, capacity_);
lookup.hits[row] = table_[index]; // NOLINT
}
arrayJoinProbe(lookup);
return;
}
if (hashMode_ == HashMode::kNormalizedKey) {
Expand Down Expand Up @@ -565,6 +561,48 @@ void HashTable<ignoreNullKeys>::joinProbe(HashLookup& lookup) {
}
}

template <bool ignoreNullKeys>
void HashTable<ignoreNullKeys>::arrayJoinProbe(HashLookup& lookup) {
// Rows are nearly always consecutive.
auto& rows = lookup.rows;
auto hashes = lookup.hashes.data();
auto hits = lookup.hits.data();
auto numRows = rows.size();
int32_t i = 0;
constexpr int32_t kBatchSize = xsimd::batch<int64_t>::size;
constexpr int32_t kStep = kBatchSize * 2;
// We loop 2 vectors at a time for fewer switches. The rows are in practice
// always contiguous.
for (; i + kStep <= numRows; i += kStep) {
auto firstRow = rows[i];
if (rows[i + kStep - 1] - firstRow == kStep - 1) {
// kStep consecutive.
simd::gather(
reinterpret_cast<const int64_t*>(table_),
reinterpret_cast<const int64_t*>(hashes + firstRow))
.store_unaligned(reinterpret_cast<int64_t*>(hits) + firstRow);
simd::gather(
reinterpret_cast<const int64_t*>(table_),
reinterpret_cast<const int64_t*>(hashes + firstRow + kBatchSize))
.store_unaligned(
reinterpret_cast<int64_t*>(hits) + firstRow + kBatchSize);
} else {
for (auto j = i; j < i + kStep; ++j) {
auto row = rows[j];
auto index = hashes[row];
VELOX_DCHECK_LT(index, capacity_);
hits[row] = table_[index]; // NOLINT
}
}
}
for (; i < numRows; ++i) {
auto row = rows[i];
auto index = hashes[row];
VELOX_DCHECK_LT(index, capacity_);
hits[row] = table_[index]; // NOLINT
}
}

template <bool ignoreNullKeys>
void HashTable<ignoreNullKeys>::joinNormalizedKeyProbe(HashLookup& lookup) {
int32_t probeIndex = 0;
Expand Down
3 changes: 3 additions & 0 deletions velox/exec/HashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,9 @@ class HashTable : public BaseHashTable {
template <bool isJoin>
void fullProbe(HashLookup& lookup, ProbeState& state, bool extraCheck);

// Array probe with SIMD.
void arrayJoinProbe(HashLookup& lookup);

// Shortcut for probe with normalized keys.
void joinNormalizedKeyProbe(HashLookup& lookup);

Expand Down
Loading