Skip to content

Commit

Permalink
Rebase 8.6.7: Fix compilation of Speedb's Paired Block Bloom (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
udi-speedb committed Dec 3, 2023
1 parent 5c6f913 commit 4364f02
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
30 changes: 20 additions & 10 deletions plugin/speedb/paired_filter/speedb_db_bloom_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#include <sstream>
#include <string>

#include "cache/cache_entry_roles.h"
#include "cache/cache_reservation_manager.h"
#include "db/db_test_util.h"
#include "options/options_helper.h"
#include "plugin/speedb/paired_filter/speedb_paired_bloom.h"
#include "port/stack_trace.h"
#include "rocksdb/advanced_options.h"
#include "rocksdb/cache.h"
#include "rocksdb/convenience.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/perf_context.h"
Expand Down Expand Up @@ -889,13 +889,12 @@ class FilterConstructResPeakTrackingCache : public CacheWrapper {
last_peak_tracked_(false),
cache_res_increments_sum_(0) {}

using Cache::Insert;
Status Insert(const Slice& key, void* value, size_t charge,
void (*deleter)(const Slice& key, void* value),
Status Insert(const Slice& key, ObjectPtr value,
const CacheItemHelper* helper, size_t charge,
Handle** handle = nullptr,
Priority priority = Priority::LOW) override {
Status s = target_->Insert(key, value, charge, deleter, handle, priority);
if (deleter == kNoopDeleterForFilterConstruction) {
Status s = target_->Insert(key, value, helper, charge, handle, priority);
if (helper->del_cb == kNoopDeleterForFilterConstruction) {
if (last_peak_tracked_) {
cache_res_peak_ = 0;
cache_res_increment_ = 0;
Expand All @@ -910,8 +909,8 @@ class FilterConstructResPeakTrackingCache : public CacheWrapper {

using Cache::Release;
bool Release(Handle* handle, bool erase_if_last_ref = false) override {
auto deleter = GetDeleter(handle);
if (deleter == kNoopDeleterForFilterConstruction) {
auto helper = GetCacheItemHelper(handle);
if (helper->del_cb == kNoopDeleterForFilterConstruction) {
if (!last_peak_tracked_) {
cache_res_peaks_.push_back(cache_res_peak_);
cache_res_increments_sum_ += cache_res_increment_;
Expand All @@ -929,8 +928,14 @@ class FilterConstructResPeakTrackingCache : public CacheWrapper {
return cache_res_increments_sum_;
}

static const char* kClassName() {
return "FilterConstructResPeakTrackingCache";
}
const char* Name() const override { return kClassName(); }

private:
static const Cache::DeleterFn kNoopDeleterForFilterConstruction;
static const Cache::CacheItemHelper kHelper;

std::size_t cur_cache_res_;
std::size_t cache_res_peak_;
Expand All @@ -940,10 +945,15 @@ class FilterConstructResPeakTrackingCache : public CacheWrapper {
std::size_t cache_res_increments_sum_;
};

const Cache::CacheItemHelper FilterConstructResPeakTrackingCache::kHelper{
CacheEntryRole::kFilterConstruction,
FilterConstructResPeakTrackingCache::kNoopDeleterForFilterConstruction};

const Cache::DeleterFn
FilterConstructResPeakTrackingCache::kNoopDeleterForFilterConstruction =
CacheReservationManagerImpl<
CacheEntryRole::kFilterConstruction>::TEST_GetNoopDeleterForRole();
CacheReservationManagerImpl<CacheEntryRole::kFilterConstruction>::
TEST_GetCacheItemHelperForRole()
->del_cb;

// To align with the type of hash entry being reserved in implementation.
using FilterConstructionReserveMemoryHash = uint64_t;
Expand Down
10 changes: 5 additions & 5 deletions plugin/speedb/paired_filter/speedb_paired_bloom_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "util/bloom_impl.h"
#include "util/fastrange.h"

#ifdef HAVE_AVX2
#ifdef __AVX2__
#include <immintrin.h>
#endif

Expand Down Expand Up @@ -216,7 +216,7 @@ class ReadBlock {
size_t hash_set_size) const;

private:
#ifdef HAVE_AVX2
#ifdef __AVX2__
bool AreAllBlockBloomBitsSetAvx2(uint32_t hash, uint32_t set_idx,
size_t hash_set_size) const;
#endif
Expand All @@ -241,7 +241,7 @@ inline uint8_t ReadBlock::GetInBatchBlockIdxOfPair() const {

bool ReadBlock::AreAllBlockBloomBitsSet(uint32_t hash, uint32_t set_idx,
size_t hash_set_size) const {
#ifdef HAVE_AVX2
#ifdef __AVX2__
// The AVX2 code currently supports only cache-line / block sizes of 64 bytes
// (512 bits)
if (kBlockSizeInBits == 512) {
Expand All @@ -254,7 +254,7 @@ bool ReadBlock::AreAllBlockBloomBitsSet(uint32_t hash, uint32_t set_idx,
#endif
}

#ifdef HAVE_AVX2
#ifdef __AVX2__
const __m256i mask_vec = _mm256_set1_epi32(0x007FC000);
const __m256i max_bitpos_vec = _mm256_set1_epi32(7);
const __m256i fast_range_vec = _mm256_set1_epi32(KNumBitsInBlockBloom);
Expand Down Expand Up @@ -346,7 +346,7 @@ bool ReadBlock::AreAllBlockBloomBitsSetAvx2(uint32_t hash, uint32_t set_idx,
}
}

#endif // HAVE_AVX2
#endif // __AVX2__

bool ReadBlock::AreAllBlockBloomBitsSetNonAvx2(uint32_t hash, uint32_t set_idx,
size_t hash_set_size) const {
Expand Down
4 changes: 2 additions & 2 deletions util/bloom_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class FastLocalBloomImpl {
return HashMayMatchPrepared(h2, num_probes, data + bytes_to_cache_line);
}

#ifdef HAVE_AVX2
#ifdef __AVX2__
// Receives an intrinsic (__m256i) hash_vector comprised of num_probes (1-8)
// 32-bits bit positions (0-511) to test within a 512 bits bloom block
//
Expand Down Expand Up @@ -338,7 +338,7 @@ class FastLocalBloomImpl {
}
return {false, false};
}
#endif // HAVE_AVX2
#endif // __AVX2__

static inline bool HashMayMatchPrepared(uint32_t h2, int num_probes,
const char *data_at_cache_line) {
Expand Down

0 comments on commit 4364f02

Please sign in to comment.