cuSBF
Loading...
Searching...
No Matches
filter_common.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda_runtime.h>
4
5#include <cstdint>
6#include <limits>
7#include <utility>
8
9#include <cusbf/config.cuh>
10
11namespace cusbf::detail {
12
14template <typename T>
15struct BitwiseOr {
19};
20
22inline constexpr uint32_t kContainsSequenceStride = 4;
23
25inline constexpr uint64_t kInvalidHash = std::numeric_limits<uint64_t>::max();
26
27template <uint64_t Index>
29
30template <>
31struct SaltLiteral<0> {
32 static constexpr uint64_t value = 0x9E37'79B9'7F4A'7C15ULL;
33};
34template <>
35struct SaltLiteral<1> {
36 static constexpr uint64_t value = 0xC2B2'AE3D'27D4'EB4FULL;
37};
38template <>
39struct SaltLiteral<2> {
40 static constexpr uint64_t value = 0x1656'67B1'9E37'79F9ULL;
41};
42template <>
43struct SaltLiteral<3> {
44 static constexpr uint64_t value = 0x85EB'CA77'C2B2'AE63ULL;
45};
46template <>
47struct SaltLiteral<4> {
48 static constexpr uint64_t value = 0x27D4'EB2F'1656'67C5ULL;
49};
50template <>
51struct SaltLiteral<5> {
52 static constexpr uint64_t value = 0x94D0'49BB'1331'11EFULL;
53};
54template <>
55struct SaltLiteral<6> {
56 static constexpr uint64_t value = 0xBF58'476D'1CE4'E5B9ULL;
57};
58template <>
59struct SaltLiteral<7> {
60 static constexpr uint64_t value = 0xD6E8'FEB8'6659'FD93ULL;
61};
62template <>
63struct SaltLiteral<8> {
64 static constexpr uint64_t value = 0xA076'1D64'78BD'642FULL;
65};
66template <>
67struct SaltLiteral<9> {
68 static constexpr uint64_t value = 0xE703'7ED1'A0B4'28DBULL;
69};
70template <>
71struct SaltLiteral<10> {
72 static constexpr uint64_t value = 0x8EBC'6AF0'9C88'C6E3ULL;
73};
74template <>
75struct SaltLiteral<11> {
76 static constexpr uint64_t value = 0x5899'65CC'7537'4CC3ULL;
77};
78template <>
79struct SaltLiteral<12> {
80 static constexpr uint64_t value = 0x1D8E'4E27'C47D'124FULL;
81};
82template <>
83struct SaltLiteral<13> {
84 static constexpr uint64_t value = 0xEB44'9C93'FBBE'A6B5ULL;
85};
86template <>
87struct SaltLiteral<14> {
88 static constexpr uint64_t value = 0xDB4F'0B91'75AE'2165ULL;
89};
90template <>
91struct SaltLiteral<15> {
92 static constexpr uint64_t value = 0xBBE0'56FD'ADE1'4B91ULL;
93};
94
96template <uint64_t Index>
98 static_assert(Index < 16, "Salt index out of range");
100}
101
103template <typename Config, typename Fn, uint64_t... HashIndices>
105forEachHashIndexImpl(Fn&& fn, std::index_sequence<HashIndices...>) {
106 (fn(std::integral_constant<uint64_t, HashIndices>{}), ...);
107}
108
110template <typename Config, typename Fn>
113 static_cast<Fn&&>(fn), std::make_index_sequence<Config::hashCount>{}
114 );
115}
116
118template <typename Config, uint64_t Length>
120 if constexpr (Length * Config::symbolBits >= 64) {
121 return std::numeric_limits<uint64_t>::max();
122 } else {
123 return (uint64_t{1} << (Config::symbolBits * Length)) - 1;
124 }
125}
126
128template <typename Config, uint64_t WindowLength, uint64_t K>
131 static_assert(WindowLength <= K, "WindowLength must not exceed K");
132 return (packed_kmer >> (Config::symbolBits * (K - (start + WindowLength)))) &
134}
135
138 atomicOr(reinterpret_cast<unsigned long long*>(ptr), static_cast<unsigned long long>(value));
139}
140
141} // namespace cusbf::detail
__host__ __device__ __forceinline__ constexpr uint64_t extractPackedSubwindow(uint64_t packed_kmer, uint64_t start)
Extracts an m-mer or s-mer subwindow from a packed k-mer at start.
__host__ __device__ __forceinline__ void forEachHashIndexImpl(Fn &&fn, std::index_sequence< HashIndices... >)
Unrolled invocation of fn for each Bloom hash index in Config.
__host__ __device__ __forceinline__ void forEachHashIndex(Fn &&fn)
Invokes fn once per Bloom hash index (compile-time unrolled).
constexpr uint32_t kContainsSequenceStride
K-mers processed per query thread per inner loop iteration.
__device__ __forceinline__ void atomicOrWord(uint64_t *ptr, uint64_t value)
64-bit atomic OR used for sectorized Bloom inserts.
constexpr uint64_t kInvalidHash
Sentinel hash value indicating "no valid minimizer found".
__host__ __device__ __forceinline__ constexpr uint64_t multiplicativeSaltLiteral()
Compile-time multiplicative salt for Bloom hash index Index.
consteval bool separatorPositionAlwaysEncodesInvalid(char *input, uint64_t separatorPosition, uint64_t index)
Recursively tests whether placing the separator byte at any position in an input of valid bytes alway...
Definition Alphabet.cuh:37
__host__ __device__ __forceinline__ constexpr uint64_t packedWindowMask()
Bit mask retaining the low Length symbols of a packed k-mer.
Compile-time configuration for a cusbf::filter.
Definition config.cuh:35
static constexpr uint64_t symbolBits
Bits per packed symbol in a uint64_t k-mer.
Definition config.cuh:51
Device functor for bitwise OR reduction (CUB WarpReduce).
__host__ __device__ __forceinline__ T operator()(T lhs, T rhs) const