cuSBF
Loading...
Searching...
No Matches
Functions | Variables
cusbf::detail::xxhash Namespace Reference

XXHash_64 implementation from. More...

Functions

constexpr __host__ __device__ __forceinline__ uint64_t rotl64 (uint64_t x, int8_t r)
 Rotates x left by r bits.
 
template<typename T >
__host__ __device__ __forceinline__ T load_chunk (const uint8_t *data, uint64_t index)
 Loads a chunk of type T from data at byte offset index*sizeof(T).
 
constexpr __host__ __device__ __forceinline__ uint64_t finalize (uint64_t h)
 Applies the xxHash-64 final mixing (avalanche) step.
 
template<typename T >
__host__ __device__ uint64_t xxhash64 (const T &key, uint64_t seed=0)
 Computes the xxHash-64 digest of a value.
 

Variables

constexpr uint64_t PRIME64_1 = 11400714785074694791ULL
 
constexpr uint64_t PRIME64_2 = 14029467366897019727ULL
 
constexpr uint64_t PRIME64_3 = 1609587929392839161ULL
 
constexpr uint64_t PRIME64_4 = 9650029242287828579ULL
 
constexpr uint64_t PRIME64_5 = 2870177450012600261ULL
 

Detailed Description

XXHash_64 implementation from.

https://github.com/Cyan4973/xxHash

xxHash - Extremely Fast Hash algorithm Header File Copyright (C) 2012-2021 Yann Collet

BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

You can contact the author at:

Function Documentation

◆ finalize()

constexpr __host__ __device__ __forceinline__ uint64_t cusbf::detail::xxhash::finalize ( uint64_t  h)
constexpr

Applies the xxHash-64 final mixing (avalanche) step.

Definition at line 69 of file hashutil.cuh.

69 {
70 h ^= h >> 33;
71 h *= PRIME64_2;
72 h ^= h >> 29;
73 h *= PRIME64_3;
74 h ^= h >> 32;
75 return h;
76}
constexpr uint64_t PRIME64_3
Definition hashutil.cuh:51
constexpr uint64_t PRIME64_2
Definition hashutil.cuh:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_chunk()

template<typename T >
__host__ __device__ __forceinline__ T cusbf::detail::xxhash::load_chunk ( const uint8_t data,
uint64_t  index 
)

Loads a chunk of type T from data at byte offset index*sizeof(T).

Definition at line 62 of file hashutil.cuh.

62 {
63 T chunk;
64 memcpy(&chunk, data + index * sizeof(T), sizeof(T));
65 return chunk;
66}
Here is the call graph for this function:

◆ rotl64()

constexpr __host__ __device__ __forceinline__ uint64_t cusbf::detail::xxhash::rotl64 ( uint64_t  x,
int8_t  r 
)
constexpr

Rotates x left by r bits.

Definition at line 56 of file hashutil.cuh.

56 {
57 return cuda::std::rotl(x, static_cast<int>(r));
58}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xxhash64()

template<typename T >
__host__ __device__ uint64_t cusbf::detail::xxhash::xxhash64 ( const T key,
uint64_t  seed = 0 
)
inline

Computes the xxHash-64 digest of a value.

Template Parameters
TType of the value; hashed as raw bytes.
Parameters
keyValue to hash.
seedOptional seed (default 0).
Returns
64-bit hash digest.

Definition at line 87 of file hashutil.cuh.

87 {
88 const auto* bytes = reinterpret_cast<const uint8_t*>(&key);
89 uint64_t size = sizeof(T);
90 uint64_t offset = 0;
91 uint64_t h64;
92
93 // Process 32-byte chunks
94 if (size >= 32) {
95 uint64_t limit = size - 32;
96 uint64_t v1 = seed + PRIME64_1 + PRIME64_2;
97 uint64_t v2 = seed + PRIME64_2;
98 uint64_t v3 = seed;
99 uint64_t v4 = seed - PRIME64_1;
100
101 do {
102 const uint64_t pipeline_offset = offset / 8;
103 v1 += load_chunk<uint64_t>(bytes, pipeline_offset + 0) * PRIME64_2;
104 v1 = rotl64(v1, 31);
105 v1 *= PRIME64_1;
106 v2 += load_chunk<uint64_t>(bytes, pipeline_offset + 1) * PRIME64_2;
107 v2 = rotl64(v2, 31);
108 v2 *= PRIME64_1;
109 v3 += load_chunk<uint64_t>(bytes, pipeline_offset + 2) * PRIME64_2;
110 v3 = rotl64(v3, 31);
111 v3 *= PRIME64_1;
112 v4 += load_chunk<uint64_t>(bytes, pipeline_offset + 3) * PRIME64_2;
113 v4 = rotl64(v4, 31);
114 v4 *= PRIME64_1;
115 offset += 32;
116 } while (offset <= limit);
117
118 h64 = rotl64(v1, 1) + rotl64(v2, 7) + rotl64(v3, 12) + rotl64(v4, 18);
119
120 v1 *= PRIME64_2;
121 v1 = rotl64(v1, 31);
122 v1 *= PRIME64_1;
123 h64 ^= v1;
124 h64 = h64 * PRIME64_1 + PRIME64_4;
125
126 v2 *= PRIME64_2;
127 v2 = rotl64(v2, 31);
128 v2 *= PRIME64_1;
129 h64 ^= v2;
130 h64 = h64 * PRIME64_1 + PRIME64_4;
131
132 v3 *= PRIME64_2;
133 v3 = rotl64(v3, 31);
134 v3 *= PRIME64_1;
135 h64 ^= v3;
136 h64 = h64 * PRIME64_1 + PRIME64_4;
137
138 v4 *= PRIME64_2;
139 v4 = rotl64(v4, 31);
140 v4 *= PRIME64_1;
141 h64 ^= v4;
142 h64 = h64 * PRIME64_1 + PRIME64_4;
143 } else {
144 h64 = seed + PRIME64_5;
145 }
146
147 h64 += size;
148
149 // Process remaining 8-byte chunks
150 if ((size % 32) >= 8) {
151 for (; offset <= size - 8; offset += 8) {
152 uint64_t k1 = load_chunk<uint64_t>(bytes, offset / 8) * PRIME64_2;
153 k1 = rotl64(k1, 31) * PRIME64_1;
154 h64 ^= k1;
155 h64 = rotl64(h64, 27) * PRIME64_1 + PRIME64_4;
156 }
157 }
158
159 // Process remaining 4-byte chunks
160 if ((size % 8) >= 4) {
161 for (; offset <= size - 4; offset += 4) {
162 h64 ^= (load_chunk<uint32_t>(bytes, offset / 4) & 0xffffffffULL) * PRIME64_1;
163 h64 = rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
164 }
165 }
166
167 // Process remaining bytes
168 if (size % 4) {
169 while (offset < size) {
170 h64 ^= (bytes[offset] & 0xff) * PRIME64_5;
171 h64 = rotl64(h64, 11) * PRIME64_1;
172 ++offset;
173 }
174 }
175
176 return finalize(h64);
177}
constexpr uint64_t PRIME64_1
Definition hashutil.cuh:49
constexpr __host__ __device__ __forceinline__ uint64_t rotl64(uint64_t x, int8_t r)
Rotates x left by r bits.
Definition hashutil.cuh:56
constexpr __host__ __device__ __forceinline__ uint64_t finalize(uint64_t h)
Applies the xxHash-64 final mixing (avalanche) step.
Definition hashutil.cuh:69
Here is the call graph for this function:

Variable Documentation

◆ PRIME64_1

constexpr uint64_t cusbf::detail::xxhash::PRIME64_1 = 11400714785074694791ULL
constexpr

Definition at line 49 of file hashutil.cuh.

◆ PRIME64_2

constexpr uint64_t cusbf::detail::xxhash::PRIME64_2 = 14029467366897019727ULL
constexpr

Definition at line 50 of file hashutil.cuh.

◆ PRIME64_3

constexpr uint64_t cusbf::detail::xxhash::PRIME64_3 = 1609587929392839161ULL
constexpr

Definition at line 51 of file hashutil.cuh.

◆ PRIME64_4

constexpr uint64_t cusbf::detail::xxhash::PRIME64_4 = 9650029242287828579ULL
constexpr

Definition at line 52 of file hashutil.cuh.

◆ PRIME64_5

constexpr uint64_t cusbf::detail::xxhash::PRIME64_5 = 2870177450012600261ULL
constexpr

Definition at line 53 of file hashutil.cuh.