cuSBF
Loading...
Searching...
No Matches
sequence_kmer.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda_runtime.h>
4
5#include <cub/warp/warp_reduce.cuh>
6
7#include <cstdint>
8
9#include <cusbf/config.cuh>
12#include <cusbf/device_span.cuh>
13#include <cusbf/hashutil.cuh>
14#include <cusbf/helpers.cuh>
15
16namespace cusbf::detail {
17
21template <typename Config>
25
29 return symbols < Config::k ? 0 : (symbols - Config::k + 1);
30 }
31
35 return symbols < Config::s ? 0 : (symbols - Config::s + 1);
36 }
37};
38
40template <typename Config>
51
53template <typename Config>
60
62template <typename Config>
65#if __CUDA_ARCH__ >= 1000
66 load256BitGlobalNC(shards[shard_index].words, w[0], w[1], w[2], w[3]);
67#else
68 load128BitGlobalNC(shards[shard_index].words + 0, w[0], w[1]);
69 load128BitGlobalNC(shards[shard_index].words + 2, w[2], w[3]);
70#endif
71}
72
74template <typename Config, uint64_t K>
83
85template <typename Config, uint64_t K>
90
92template <typename Config>
94 _Pragma("unroll")
95 for (uint64_t i = 0; i < Config::k; ++i) {
96 if (tile[start + i] == Config::Alphabet::invalidSymbol) {
97 return false;
98 }
99 }
100 return true;
101}
102
108template <typename Config>
110 const char* sequence,
114) {
116
117 bool local_invalid_base = false;
119 const uint8_t encoded_base =
120 Config::Alphabet::encode(sequence + (block_start_kmer + idx) * Config::symbolWidth);
122 local_invalid_base |= (encoded_base == Config::Alphabet::invalidSymbol);
123 }
125}
126
128template <uint32_t k_stride, typename Config>
132 bool block_all_valid,
134) {
136 _Pragma("unroll")
137 for (uint32_t s = 0; s < k_stride; ++s) {
138 if ((thread_offset + s) < block_kmers) {
139 kmer_valid_mask |= (1u << s);
140 }
141 }
142
143 if (!block_all_valid) {
144 _Pragma("unroll")
145 for (uint32_t s = 0; s < k_stride; ++s) {
146 if (!(kmer_valid_mask & (1u << s))) {
147 continue;
148 }
149 const uint64_t local_idx = thread_offset + s;
151 kmer_valid_mask &= ~(1u << s);
152 }
153 }
154 }
155 return kmer_valid_mask;
156}
157
158} // namespace cusbf::detail
__device__ __forceinline__ bool prepare_sequence_hash_tiles(const char *sequence, uint64_t block_start_kmer, uint64_t block_kmers, uint8_t *sequence_tile)
Encodes a block's sequence slice into sequence_tile and reports global validity.
__device__ __forceinline__ void load128BitGlobalNC(const uint64_t *ptr, uint64_t &out0, uint64_t &out1)
Loads 128 bits from global memory using the non-coherent cache path.
Definition helpers.cuh:74
__device__ __forceinline__ uint64_t advance_packed_kmer(uint64_t packed, uint8_t new_base)
Slides a packed k-mer window by one encoded base.
__device__ __forceinline__ void load_shard_words4(const filter_block< Config > *shards, uint64_t shard_index, uint64_t *w)
Loads four 64-bit shard words with 256-bit (sm_100+) or 128-bit vector loads.
__device__ __forceinline__ uint64_t packed_kmer_smer_hash(uint64_t packed_kmer, uint64_t start)
Bloom hash for the s-mer at start within a packed k-mer.
__device__ __forceinline__ uint64_t packed_kmer_minimizer_hash(uint64_t packed_kmer)
Minimum minimizer hash over all m-mers in a packed k-mer.
constexpr __host__ __device__ __forceinline__ uint64_t minimizer_hash64(uint64_t key)
Fast 64-bit hash sufficient for uniform minimizer selection.
Definition hashutil.cuh:207
__device__ __forceinline__ uint64_t pack_kmer_from_tile(const uint8_t *tile, uint64_t start)
Packs K encoded symbols from a shared-memory tile starting at start.
__device__ __forceinline__ bool kmer_is_valid(const uint8_t *tile, uint64_t start)
True when no symbol in the k-mer window is the alphabet invalid sentinel.
__device__ __forceinline__ void load256BitGlobalNC(const T *ptr, T *out)
Loads 256 bits from global memory using the non-coherent cache path.
Definition helpers.cuh:32
__device__ __forceinline__ uint32_t build_stride_kmer_valid_mask(uint64_t thread_offset, uint64_t block_kmers, bool block_all_valid, const uint8_t *sequence_tile)
Builds the per-thread validity bitmask for strided query kernels.
constexpr uint64_t kInvalidHash
Sentinel hash value indicating "no valid minimizer found".
constexpr __host__ __device__ __forceinline__ uint64_t hash64(uint64_t key)
Fast 64-bit integer hash (non-cryptographic).
Definition hashutil.cuh:192
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
static constexpr uint64_t symbolWidth
Input bytes per symbol.
Definition config.cuh:49
static constexpr uint16_t s
S-mer width (Bloom hash seed) in symbols.
Definition config.cuh:43
static constexpr uint64_t symbolMask
Low symbolBits mask for one encoded symbol.
Definition config.cuh:53
static constexpr uint64_t minimizerSpan
M-mers evaluated per k-mer window.
Definition config.cuh:64
static constexpr uint64_t cudaBlockSize
CUDA threads per kernel block.
Definition config.cuh:57
static constexpr uint16_t k
K-mer length in symbols.
Definition config.cuh:39
static constexpr uint64_t symbolBits
Bits per packed symbol in a uint64_t k-mer.
Definition config.cuh:51
Device-side view of an encoded sequence for k-mer / s-mer counting.
constexpr __host__ __device__ uint64_t kmerCount() const
Number of k-mer windows in sequence.
constexpr __host__ __device__ uint64_t smerCount() const
Number of s-mer windows in sequence.
device_span< const char > sequence
Encoded sequence bytes (Config::symbolWidth per symbol).
A span that is assumed to point to device-accessible memory.
One 256-bit filter block stored as an array of Config::blockWordCount words.