11 #ifndef GENIE_MATCH_DEVICE_UTILS_H 12 #define GENIE_MATCH_DEVICE_UTILS_H 30 static const uint32_t h_offsets[] =
31 { 0u, 3949349u, 8984219u, 9805709u, 7732727u, 1046459u, 9883879u, 4889399u,
32 2914183u, 3503623u, 1734349u, 8860463u, 1326319u, 1613597u, 8604269u, 9647369u};
34 static __device__ __constant__
u32 d_offsets[16];
43 return ((key) >> (ATTACH_ID_TYPE_BITS + KEY_TYPE_BITS));
46 __host__ __forceinline__ __device__
51 __host__ __forceinline__ __device__
54 return ((p) & KEY_TYPE_MASK);
56 __host__ __forceinline__ __device__
60 ((
u64(a) << (ATTACH_ID_TYPE_BITS + KEY_TYPE_BITS)))
61 + ((
u64(i) & ATTACH_ID_TYPE_MASK) << (KEY_TYPE_BITS))
62 +
u64(p & KEY_TYPE_MASK));
68 return (d_offsets[age] + key) % hash_table_size;
71 __forceinline__ __device__ __host__
74 for (
int i = 31; i >= 0; i--)
75 b[31 - i] = ((data >> i) & 1) == 1 ?
'1' :
'0';
79 __forceinline__ __device__ __host__
u32 82 return (data >> offset) & ((1u << bits) - 1u);
85 __forceinline__ __device__ __host__
u32 89 r = data & (~(((1u << bits) - 1u) << offset));
90 r |= (count << offset);
93 __forceinline__ __device__
101 location =
hash(
id, age, hash_table_size);
105 out_key = htable[location];
112 float old_value_plus = *
reinterpret_cast<float*
>(&attach_id) + q.
weight;
114 *
reinterpret_cast<u32*
>(&old_value_plus),
116 if(atomicCAS(&htable[location], out_key, new_key) == out_key)
128 while (age < MAX_AGE)
131 location =
hash(
id, age, hash_table_size);
132 out_key = htable[location];
139 float old_value_plus = *
reinterpret_cast<float*
>(&attach_id) + q.
weight;
141 *
reinterpret_cast<u32*
>(&old_value_plus),
143 if(atomicCAS(&htable[location], out_key, new_key) == out_key)
160 __device__ __forceinline__
void 163 bool * pass_threshold
170 location =
hash(
id, age, hash_table_size);
173 out_key = htable[location];
180 float value_1 = *
reinterpret_cast<float*
>(&attach_id);
181 float value_plus = count;
182 if(value_plus <value_1)
184 *pass_threshold =
true;
189 *reinterpret_cast<u32*>(&value_plus),
191 if(value_plus<*my_threshold)
193 *pass_threshold =
false;
197 if(atomicCAS(&htable[location], out_key, new_key) == out_key)
198 { *pass_threshold =
true;
209 while (age < MAX_AGE)
212 location =
hash(
id, age, hash_table_size);
213 out_key = htable[location];
221 float value_1 = *
reinterpret_cast<float*
>(&attach_id);
222 float value_plus = count;
223 if(value_plus <value_1)
225 *pass_threshold =
true;
231 *reinterpret_cast<u32*>(&value_plus),
233 if(value_plus<*my_threshold)
235 *pass_threshold =
false;
239 if(atomicCAS(&htable[location], out_key, new_key) == out_key)
241 *pass_threshold =
true;
255 *pass_threshold =
false;
259 __device__ __forceinline__
void 264 u32 * my_noiih,
bool * overflow,
bool* pass_threshold)
269 float count_value = count;
272 *reinterpret_cast<u32*>(&count_value), KEY_TYPE_INIT_AGE);
274 while (age < MAX_AGE)
280 float key_value = *
reinterpret_cast<float*
>(&key_attach_id);
281 if (key_value < *my_threshold)
285 *pass_threshold =
false;
289 *pass_threshold =
true;
297 if (*my_noiih > hash_table_size)
303 peek_key = htable[location];
305 float peek_key_value =
306 *
reinterpret_cast<float*
>(&peek_key_attach_id);
314 if (key_value < peek_key_value)
316 *pass_threshold =
true;
322 *reinterpret_cast<u32*>(&key_value),
325 if (key_value < *my_threshold)
329 *pass_threshold =
false;
333 *pass_threshold =
true;
337 if (atomicCAS(&htable[location], peek_key, new_key) == peek_key)
340 *pass_threshold =
true;
351 && peek_key_value < *my_threshold))
355 if (key_value < *my_threshold)
359 *pass_threshold =
false;
363 *pass_threshold =
true;
368 evicted_key = atomicCAS(&htable[location], peek_key, key);
370 if (evicted_key != peek_key)
376 if (peek_key_value < *my_threshold)
379 *pass_threshold =
true;
391 if (*my_noiih >= hash_table_size)
394 atomicAdd(my_noiih, 1u);
399 atomicAdd(my_noiih, 1u);
401 *pass_threshold =
true;
417 *pass_threshold =
true;
422 __device__ __forceinline__
u32 426 u32 value, count = 0, new_value;
434 value = bitmap[access_id / (32 / bits)];
435 offset = (access_id % (32 / bits)) * bits;
438 *key_eligible = count >= my_threshold;
439 new_value =
pack_count(value, offset, bits, count);
440 if (atomicCAS(&bitmap[access_id / (32 / bits)], value, new_value)
448 __device__ __forceinline__
void 452 if (count < *my_threshold)
456 atomicAdd(&my_passCount[count], 1);
458 u32 this_threshold = (*my_threshold);
462 this_threshold = *my_threshold;
463 if (my_passCount[this_threshold] >= my_topk)
465 this_threshold = atomicCAS(my_threshold, this_threshold,
__device__ __forceinline__ void access_kernel_AT(u32 id, T_HASHTABLE *htable, int hash_table_size, genie::query::Query::dim &q, u32 count, bool *key_found, u32 *my_threshold, bool *pass_threshold)
const uint32_t KEY_TYPE_INIT_AGE
This is the top-level namespace of the project.
__forceinline__ __device__ u32 hash(T_KEY key, T_AGE age, int hash_table_size)
__device__ __forceinline__ void hash_kernel_AT(u32 id, T_HASHTABLE *htable, int hash_table_size, genie::query::Query::dim &q, u32 count, u32 *my_threshold, u32 *my_noiih, bool *overflow, bool *pass_threshold)
__host__ __forceinline__ __device__ T_HASHTABLE pack_key_pos(T_KEY p)
__forceinline__ __device__ __host__ void print_binary(char *b, u32 data)
const uint32_t ATTACH_ID_TYPE_MASK
const uint32_t ATTACH_ID_TYPE_BITS
Declaration of query class.
__host__ __forceinline__ __device__ u32 get_key_attach_id(T_HASHTABLE key)
__forceinline__ __device__ __host__ u32 pack_count(u32 data, int offset, int bits, u32 count)
__forceinline__ __host__ __device__ T_AGE get_key_age(T_HASHTABLE key)
__forceinline__ __host__ __device__ T_KEY get_key_pos(T_HASHTABLE key)
__forceinline__ __device__ __host__ u32 get_count(u32 data, int offset, int bits)
const uint32_t KEY_TYPE_MASK
__forceinline__ __device__ void access_kernel(u32 id, T_HASHTABLE *htable, int hash_table_size, genie::query::Query::dim &q, bool *key_found)
__device__ __forceinline__ u32 bitmap_kernel_AT(u32 access_id, u32 *bitmap, int bits, int my_threshold, bool *key_eligible)
unsigned long long u64
A type definition for a 64-bit unsigned integer.
The second-step struct for processing queries.
__host__ __forceinline__ __device__ T_HASHTABLE pack_key_pos_and_attach_id_and_age(T_KEY p, u32 i, T_AGE a)
Basic utility functions to be used in matching kernels.
const uint32_t KEY_TYPE_NULL_AGE
const uint32_t KEY_TYPE_BITS
__device__ __forceinline__ void updateThreshold(u32 *my_passCount, u32 *my_threshold, u32 my_topk, u32 count)