cuSBF
Loading...
Searching...
No Matches
kernels.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda/__cmath/ceil_div.h>
4#include <cuda_runtime.h>
5
6#include <cub/warp/warp_reduce.cuh>
7
8#include <cstdint>
9
10#include <cusbf/config.cuh>
15#include <cusbf/device_span.cuh>
16#include <cusbf/filter_ref.cuh>
17
18namespace cusbf::detail {
19
21template <typename Config>
26
28template <typename Config>
34
40template <typename Config, uint32_t k_stride>
45 bool block_all_valid,
48) {
49 const uint64_t thread_offset = static_cast<uint64_t>(threadIdx.x) * k_stride;
51 return;
52 }
53
56 );
57
60
61 for (uint32_t s = 0; s < k_stride; ++s) {
63 if (local_idx >= block_kmers) {
64 break;
65 }
66
68
69 if (s > 0) {
72 );
73 }
74
75 if (!(kmer_valid_mask & (1u << s))) {
76 output[kmer_index] = 0;
77 continue;
78 }
79
81
82 const auto shard_idx =
84 const uint32_t peers = __match_any_sync(0xFFFFFFFFu, shard_idx);
85 const int leader = __ffs(static_cast<int>(peers)) - 1;
86
87 uint64_t w[4];
88 if (static_cast<int>(threadIdx.x & 31u) == leader) {
90 }
91 w[0] = __shfl_sync(peers, w[0], leader);
92 w[1] = __shfl_sync(peers, w[1], leader);
93 w[2] = __shfl_sync(peers, w[2], leader);
94 w[3] = __shfl_sync(peers, w[3], leader);
95
98 }
99}
100
106template <typename Config, uint32_t warps_per_block>
108 const uint8_t* sequence_tile,
111 bool block_all_valid,
113 cub::WarpReduce<uint64_t>::TempStorage reduce_storage[warps_per_block][4]
114) {
115 constexpr uint32_t warp_size = 32;
116
117 const auto local_kmer_index = static_cast<uint64_t>(threadIdx.x);
119
120 bool active = in_range;
121 if (active && !block_all_valid) {
123 }
124
130
131 if (active) {
132 const uint64_t packed_kmer =
135
139 );
140 _Pragma("unroll")
145 );
146 }
147 }
148
149 const auto shard_idx =
150 static_cast<uint32_t>(active ? (minimizer_hash & (shards.size() - 1)) : ~threadIdx.x);
151
152 const uint32_t lane = threadIdx.x & (warp_size - 1);
154 const uint32_t prev_shard_idx = __shfl_up_sync(0xffffffff, shard_idx, 1);
155 const bool run_head = (lane == 0) || (shard_idx != prev_shard_idx);
157
158 using WarpReduceWord = cub::WarpReduce<uint64_t>;
160 .HeadSegmentedReduce(word_mask0, run_head, bitwise_or);
162 .HeadSegmentedReduce(word_mask1, run_head, bitwise_or);
164 .HeadSegmentedReduce(word_mask2, run_head, bitwise_or);
166 .HeadSegmentedReduce(word_mask3, run_head, bitwise_or);
167
168 if (run_head && active) {
171 }
172}
173
179template <typename Config>
208
214template <typename Config>
243
247template <typename Config>
278
282template <typename Config>
313
314} // namespace cusbf::detail
Non-owning device reference to sectorized filter storage.
__host__ static __device__ uint64_t shard_index(uint64_t minimizer_hash, uint64_t num_blocks) noexcept
Maps a minimizer hash to a shard index via low bits.
static __device__ bool sectorized_contains_packed_kmer(uint64_t packed_kmer, const uint64_t *shard_words)
Tests sectorized membership for a packed k-mer against shard words.
__device__ void apply_word_masks(block_type &block, uint64_t m0, uint64_t m1, uint64_t m2, uint64_t m3) const
Atomically ORs non-zero per-word Bloom masks into block.
__global__ void insert_sequence_kmers_kernel(SequenceKmerInput< Config > input, device_span< filter_block< Config > > shards)
Insert kernel: sectorized Bloom updates grouped by minimizer shard.
Definition kernels.cuh:215
__global__ void contains_sequence_kmers_kernel(SequenceKmerInput< Config > input, device_span< const filter_block< Config > > shards, device_span< uint8_t > output)
Query kernel: one byte per k-mer (1 = present, 0 = absent or invalid).
Definition kernels.cuh:180
__device__ __forceinline__ void insert_kmers_from_symbol_tile(const uint8_t *sequence_tile, uint64_t block_start_kmer, uint64_t block_kmers, bool block_all_valid, device_span< filter_block< Config > > shards, cub::WarpReduce< uint64_t >::TempStorage reduce_storage[warps_per_block][4])
Shared insert path after a block symbol tile has been prepared.
Definition kernels.cuh:107
constexpr uint64_t dense_packed_insert_word_tile_capacity()
Maximum uint64_t words loaded for a dense-packed insert block tile.
Definition kernels.cuh:22
constexpr uint32_t kContainsSequenceStride
K-mers processed per query thread per inner loop iteration.
constexpr uint64_t dense_packed_query_word_tile_capacity()
Maximum uint64_t words loaded for a dense-packed query block tile.
Definition kernels.cuh:29
__global__ void contains_dense_packed_kmers_kernel(DensePackedKmerInput< Config > input, device_span< const filter_block< Config > > shards, device_span< uint8_t > output)
Query kernel for a dense packed symbol buffer (DensePackedKmerInput).
Definition kernels.cuh:248
__device__ __forceinline__ void contains_kmers_from_symbol_tile(const uint8_t *sequence_tile, uint64_t block_start_kmer, uint64_t block_kmers, bool block_all_valid, device_span< const filter_block< Config > > shards, device_span< uint8_t > output)
Shared query path after a block symbol tile has been prepared.
Definition kernels.cuh:41
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
__global__ void insert_dense_packed_kmers_kernel(DensePackedKmerInput< Config > input, device_span< filter_block< Config > > shards)
Insert kernel for a dense packed symbol buffer (DensePackedKmerInput).
Definition kernels.cuh:283
Compile-time configuration for a cusbf::filter.
Definition config.cuh:35
static constexpr uint64_t cudaBlockSize
CUDA threads per kernel block.
Definition config.cuh:57
static constexpr uint64_t findereSpan
S-mers hashed per k-mer (findere).
Definition config.cuh:66
static constexpr uint16_t k
K-mer length in symbols.
Definition config.cuh:39
Device functor for bitwise OR reduction (CUB WarpReduce).
Device-side view of a dense packed symbol sequence.
Device-side view of an encoded sequence for k-mer / s-mer counting.
A span that is assumed to point to device-accessible memory.
One 256-bit filter block stored as an array of Config::blockWordCount words.
__device__ static __forceinline__ void sectorizedHashToMasks(uint64_t baseHash, uint64_t &mask0, uint64_t &mask1, uint64_t &mask2, uint64_t &mask3)
Accumulates Bloom bit masks for all hash indices into four shard words.