GPU-Accelerated Cuckoo Filter
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize > Struct Template Reference

Offset-based alternate bucket policy from "Smaller and More Flexible Cuckoo Filters" by Schmitz, Zentgraf, and Rahmann. More...

Static Public Member Functions

template<typename H >
static __host__ __device__ uint64_t hash64 (const H &key)
 Computes a 64-bit hash of the key.
 
static __host__ __device__ TagType getPureFingerprint (TagType fp)
 Extracts the pure fingerprint (without choice bit).
 
static __host__ __device__ TagType getChoiceBit (TagType fp)
 Extracts the choice bit (0 or 1).
 
static __host__ __device__ TagType setChoiceBit (TagType fp, TagType choice)
 Sets the choice bit in a fingerprint.
 
static __host__ __device__ size_t computeOffset (TagType pureFp, size_t numBuckets)
 Computes a non-zero offset from a fingerprint (uses pure fp).
 
static __host__ __device__ cuda::std::tuple< size_t, size_t, TagType, TagType > getCandidateBucketsAndFPs (const KeyType &key, size_t numBuckets)
 Computes the primary and alternate bucket indices for a given key.
 
static __host__ __device__ size_t getAlternateBucket (size_t bucket, TagType fp, size_t numBuckets)
 Computes the alternate bucket index using asymmetric offset.
 
static __host__ __device__ cuda::std::tuple< size_t, TagType > getAlternateBucketWithNewFp (size_t bucket, TagType fp, size_t numBuckets)
 Computes alternate bucket AND updated fingerprint for eviction.
 
static size_t calculateNumBuckets (size_t capacity)
 Calculates number of buckets without requiring power of two.
 

Static Public Attributes

static constexpr size_t choiceBitPos = bitsPerTag - 1
 
static constexpr TagType choiceBitMask = TagType(1) << choiceBitPos
 
static constexpr TagType pureFpMask = (TagType(1) << choiceBitPos) - 1
 
static constexpr size_t fpMask = (1ULL << bitsPerTag) - 1
 
static constexpr bool usesChoiceBit = true
 
static constexpr char name [] = "OffsetAltBucketPolicy"
 

Detailed Description

template<typename KeyType, typename TagType, size_t bitsPerTag, size_t bucketSize>
struct cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >

Offset-based alternate bucket policy from "Smaller and More Flexible Cuckoo Filters" by Schmitz, Zentgraf, and Rahmann.

Uses an asymmetric offset with a choice bit:

The choice bit is stored in the MSB of the fingerprint:

This allows non-power-of-two bucket counts with proper symmetry.

Definition at line 201 of file bucket_policies.cuh.

Member Function Documentation

◆ calculateNumBuckets()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static size_t cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::calculateNumBuckets ( size_t  capacity)
inlinestatic

Calculates number of buckets without requiring power of two.

Definition at line 348 of file bucket_policies.cuh.

348 {
349 auto requiredBuckets = std::ceil(static_cast<double>(capacity) / bucketSize);
350 return static_cast<size_t>(requiredBuckets);
351 }

◆ computeOffset()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ size_t cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::computeOffset ( TagType  pureFp,
size_t  numBuckets 
)
inlinestatic

Computes a non-zero offset from a fingerprint (uses pure fp).

Parameters
pureFpPure fingerprint (without choice bit)
numBucketsTotal number of buckets
Returns
Non-zero offset value in [1, numBuckets-1]

Definition at line 250 of file bucket_policies.cuh.

250 {
251 const uint64_t fpHash = hash64(pureFp);
252 const uint64_t offset = fpHash % numBuckets;
253 return offset == 0 ? 1 : offset;
254 }
static __host__ __device__ uint64_t hash64(const H &key)
Computes a 64-bit hash of the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAlternateBucket()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ size_t cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::getAlternateBucket ( size_t  bucket,
TagType  fp,
size_t  numBuckets 
)
inlinestatic

Computes the alternate bucket index using asymmetric offset.

The choice bit determines direction:

  • choice=0: we're at primary bucket, add offset to get alternate
  • choice=1: we're at alternate bucket, subtract offset to get primary
Parameters
bucketCurrent bucket index.
fpFingerprint (with choice bit).
numBucketsTotal number of buckets.
Returns
Alternate bucket index.

Definition at line 305 of file bucket_policies.cuh.

305 {
306 const TagType pureFp = getPureFingerprint(fp);
307 const TagType choice = getChoiceBit(fp);
308 const size_t offset = computeOffset(pureFp, numBuckets);
309
310 if (choice == 0) {
311 return (bucket + offset) % numBuckets;
312 } else {
313 return (bucket + numBuckets - offset) % numBuckets;
314 }
315 }
static __host__ __device__ TagType getChoiceBit(TagType fp)
Extracts the choice bit (0 or 1).
static __host__ __device__ TagType getPureFingerprint(TagType fp)
Extracts the pure fingerprint (without choice bit).
static __host__ __device__ size_t computeOffset(TagType pureFp, size_t numBuckets)
Computes a non-zero offset from a fingerprint (uses pure fp).
Here is the call graph for this function:

◆ getAlternateBucketWithNewFp()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ cuda::std::tuple< size_t, TagType > cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::getAlternateBucketWithNewFp ( size_t  bucket,
TagType  fp,
size_t  numBuckets 
)
inlinestatic

Computes alternate bucket AND updated fingerprint for eviction.

Returns what the alternate bucket would be AND what the new fp would be (with flipped choice bit). This is used during eviction when we need both.

Parameters
bucketCurrent bucket index.
fpFingerprint (with choice bit).
numBucketsTotal number of buckets.
Returns
Tuple of (alternate bucket index, new fingerprint with flipped choice bit).

Definition at line 329 of file bucket_policies.cuh.

329 {
330 const TagType pureFp = getPureFingerprint(fp);
331 const TagType choice = getChoiceBit(fp);
332 const size_t offset = computeOffset(pureFp, numBuckets);
333
334 size_t alt;
335 if (choice == 0) {
336 alt = (bucket + offset) % numBuckets;
337 } else {
338 alt = (bucket + numBuckets - offset) % numBuckets;
339 }
340
341 TagType newFp = setChoiceBit(pureFp, 1 - choice);
342 return {alt, newFp};
343 }
static __host__ __device__ TagType setChoiceBit(TagType fp, TagType choice)
Sets the choice bit in a fingerprint.
Here is the call graph for this function:

◆ getCandidateBucketsAndFPs()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ cuda::std::tuple< size_t, size_t, TagType, TagType > cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::getCandidateBucketsAndFPs ( const KeyType &  key,
size_t  numBuckets 
)
inlinestatic

Computes the primary and alternate bucket indices for a given key.

Returns both fingerprint variants to avoid redundant computations:

  • fp1: fingerprint with choice=0 for primary bucket
  • fp2: fingerprint with choice=1 for alternate bucket
Parameters
keyKey to hash
numBucketsNumber of buckets in the filter
Returns
A tuple of (bucket1, bucket2, fingerprintForBucket1, fingerprintForBucket2)

Definition at line 268 of file bucket_policies.cuh.

268 {
269 const uint64_t h = hash64(key);
270
271 // Upper 32 bits for the fingerprint (use bitsPerTag-1 bits)
272 const uint32_t h_fp = h >> 32;
273 const uint32_t masked = h_fp & pureFpMask;
274 // Ensure non-zero (0 is reserved for empty)
275 const TagType pureFp = TagType(masked == 0 ? 1 : masked);
276
277 // Create both fingerprint variants (choice=0 and choice=1)
278 const TagType fp1 = setChoiceBit(pureFp, 0);
279 const TagType fp2 = setChoiceBit(pureFp, 1);
280
281 // Lower 32 bits for the bucket index
282 const uint32_t h_bucket = h & 0xFFFFFFFF;
283 const size_t i1 = h_bucket % numBuckets;
284
285 // Compute i2 using the fingerprint offset
286 const size_t offset = computeOffset(pureFp, numBuckets);
287 const size_t i2 = (i1 + offset) % numBuckets;
288
289 return {i1, i2, fp1, fp2};
290 }
static constexpr TagType pureFpMask
Here is the call graph for this function:

◆ getChoiceBit()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ TagType cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::getChoiceBit ( TagType  fp)
inlinestatic

Extracts the choice bit (0 or 1).

Definition at line 232 of file bucket_policies.cuh.

232 {
233 return (fp >> choiceBitPos) & 1;
234 }
static constexpr size_t choiceBitPos
Here is the caller graph for this function:

◆ getPureFingerprint()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ TagType cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::getPureFingerprint ( TagType  fp)
inlinestatic

Extracts the pure fingerprint (without choice bit).

Definition at line 225 of file bucket_policies.cuh.

225 {
226 return fp & pureFpMask;
227 }
Here is the caller graph for this function:

◆ hash64()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
template<typename H >
static __host__ __device__ uint64_t cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::hash64 ( const H &  key)
inlinestatic

Computes a 64-bit hash of the key.

Definition at line 218 of file bucket_policies.cuh.

218 {
219 return xxhash::xxhash64(key);
220 }
__host__ __device__ uint64_t xxhash64(const T &key, uint64_t seed=0)
Definition hashutil.cuh:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setChoiceBit()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ TagType cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::setChoiceBit ( TagType  fp,
TagType  choice 
)
inlinestatic

Sets the choice bit in a fingerprint.

Definition at line 239 of file bucket_policies.cuh.

239 {
240 return (fp & pureFpMask) | (choice << choiceBitPos);
241 }
Here is the caller graph for this function:

Member Data Documentation

◆ choiceBitMask

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr TagType cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::choiceBitMask = TagType(1) << choiceBitPos
staticconstexpr

Definition at line 206 of file bucket_policies.cuh.

◆ choiceBitPos

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr size_t cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::choiceBitPos = bitsPerTag - 1
staticconstexpr

Definition at line 205 of file bucket_policies.cuh.

◆ fpMask

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr size_t cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::fpMask = (1ULL << bitsPerTag) - 1
staticconstexpr

Definition at line 208 of file bucket_policies.cuh.

◆ name

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr char cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::name[] = "OffsetAltBucketPolicy"
staticconstexpr

Definition at line 212 of file bucket_policies.cuh.

◆ pureFpMask

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr TagType cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::pureFpMask = (TagType(1) << choiceBitPos) - 1
staticconstexpr

Definition at line 207 of file bucket_policies.cuh.

◆ usesChoiceBit

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr bool cuckoogpu::OffsetAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::usesChoiceBit = true
staticconstexpr

Definition at line 210 of file bucket_policies.cuh.


The documentation for this struct was generated from the following file: