cuSBF
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
cusbf::filter< Config > Class Template Reference

GPU Super Bloom filter (defined in filter.cuh). More...

Public Types

using block_type = filter_block< Config >
 One 256-bit filter block stored as an array of Config::blockWordCount words.
 
using Shard = block_type
 Alias for block_type (one 256-bit shard).
 

Public Member Functions

 filter (uint64_t requestedFilterBits)
 Constructs a Filter with at least requestedFilterBits bits of storage.
 
 filter (const filter &)=delete
 Non-copyable (owns device shard storage).
 
filteroperator= (const filter &)=delete
 
 filter (filter &&) noexcept=default
 Move-constructs, transfers shard vectors and staging buffers.
 
filteroperator= (filter &&) noexcept=default
 Move-assigns shard storage and staging buffers.
 
 ~filter ()=default
 Destroys device allocations and releases staging scratch.
 
filter_ref< Configref () const noexcept
 Non-owning device reference to this filter's shard storage.
 
Result< uint64_t > insert_sequence (std::string_view sequence, cuda::stream_ref stream=cudaStream_t{})
 Inserts all valid k-mers from a host-resident sequence.
 
Result< uint64_t > insert_sequence_async (device_span< const char > d_sequence, cuda::stream_ref stream=cudaStream_t{})
 Async insert of k-mers from a device-resident sequence.
 
Result< uint64_t > insert_dense_packed_async (device_span< const uint64_t > d_words, uint64_t num_symbols, cuda::stream_ref stream=cudaStream_t{})
 Inserts all k-mers from a dense packed symbol buffer on the device.
 
Result< uint64_t > insert_dense_packed (std::span< const uint64_t > words, uint64_t num_symbols, cuda::stream_ref stream=cudaStream_t{})
 Inserts all k-mers from a host-resident dense packed symbol buffer.
 
Result< void > contains_dense_packed_async (device_span< const uint64_t > d_words, uint64_t num_symbols, device_span< uint8_t > d_output, cuda::stream_ref stream=cudaStream_t{}) const
 Async query of k-mers from a dense packed symbol buffer on the device.
 
Result< void > contains_dense_packed (std::span< const uint64_t > words, uint64_t num_symbols, device_span< uint8_t > d_output, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all k-mers from a host-resident dense packed symbol buffer into device memory.
 
Result< std::vector< uint8_t > > contains_dense_packed (std::span< const uint64_t > words, uint64_t num_symbols, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all k-mers from a host-resident dense packed symbol buffer.
 
constexpr uint64_t dense_packed_kmer_count (uint64_t num_symbols) const
 Number of k-mer windows in a dense packed sequence of num_symbols symbols.
 
Result< FastxInsertReportinsert_record_batch (RecordBatchView batch, cuda::stream_ref stream=cudaStream_t{})
 Inserts a dense host-resident record batch.
 
Result< uint64_t > insert_record_batch_async (device_span< const char > d_sequence, std::span< const RecordRange > records, cuda::stream_ref stream=cudaStream_t{})
 Async insert of k-mers from a device-resident record batch.
 
Result< FastxInsertReportinsert_fastx (std::istream &input, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{})
 Inserts all k-mers from a FASTA/FASTQ input stream.
 
Result< FastxInsertReportinsert_fastx_file (const std::filesystem::path &path, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{})
 Inserts all k-mers from a FASTA/FASTQ file.
 
Result< void > contains_sequence_async (device_span< const char > d_sequence, device_span< uint8_t > d_output, cuda::stream_ref stream=cudaStream_t{}) const
 Async query of k-mers from a device-resident sequence.
 
Result< void > contains_sequence (std::string_view sequence, device_span< uint8_t > d_output, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all valid k-mers from a host-resident sequence into device memory.
 
Result< std::vector< uint8_t > > contains_sequence (std::string_view sequence, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all valid k-mers from a host-resident sequence.
 
Result< FastxQueryReportquery_record_batch (RecordBatchView batch, cuda::stream_ref stream=cudaStream_t{}) const
 Queries a dense host-resident record batch and returns aggregate counts.
 
template<RecordQueryConsumer Consumer>
Result< FastxQueryReportquery_record_batch (RecordBatchView batch, Consumer &&consume, cuda::stream_ref stream=cudaStream_t{}) const
 Queries a dense host-resident record batch and streams per-record results.
 
Result< void > contains_record_batch_async (device_span< const char > d_sequence, std::span< const RecordRange > records, device_span< uint8_t > d_output, cuda::stream_ref stream=cudaStream_t{}) const
 Async query of k-mers from a device-resident record batch.
 
Result< FastxQueryReportquery_fastx (std::istream &input, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all k-mers from a FASTA/FASTQ input stream via chunked streaming.
 
Result< FastxQueryReportquery_fastx_file (const std::filesystem::path &path, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all k-mers from a FASTA/FASTQ file.
 
template<FastxRecordConsumer Consumer>
Result< FastxQueryReportquery_fastx_records (std::istream &input, Consumer &&consume, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{}) const
 Queries a FASTA/FASTQ stream and emits one record result per parsed record.
 
template<FastxRecordConsumer Consumer>
Result< FastxQueryReportquery_fastx_file_records (const std::filesystem::path &path, Consumer &&consume, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{}) const
 Queries a FASTA/FASTQ file and emits one record result per parsed record.
 
Result< FastxDetailedQueryReportquery_fastx_detailed (std::istream &input, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all k-mers from a FASTA/FASTQ input stream via chunked streaming and preserves per-record hit vectors.
 
Result< FastxDetailedQueryReportquery_fastx_file_detailed (const std::filesystem::path &path, double fill_fraction=0.7, cuda::stream_ref stream=cudaStream_t{}) const
 Queries all k-mers from a FASTA/FASTQ file via chunked streaming and preserves per-record hit vectors.
 
Result< void > clear (cuda::stream_ref stream=cudaStream_t{})
 Resets all filter bits to zero and synchronises the stream.
 
float load_factor () const
 Computes the fraction of set bits in the filter.
 
uint64_t filter_bits () const
 Returns the total allocated capacity of the filter in bits.
 
uint64_t num_shards () const
 Returns the number of shards.
 

Static Public Member Functions

static constexpr uint64_t dense_packed_word_count (uint64_t num_symbols)
 Number of uint64_t words for num_symbols dense packed symbols.
 

Detailed Description

template<typename Config>
class cusbf::filter< Config >

GPU Super Bloom filter (defined in filter.cuh).

GPU-resident Super Bloom filter for batch k-mer insert and query.

Config fixes k-mer length, minimizer and s-mer widths, hash count, CUDA block size, and alphabet at compile time. Host bulk APIs synchronize before returning, device-span *_async methods do not.

FASTX and record-batch paths inject alphabet separator bytes between records so cross-record k-mers are never formed.

Template Parameters
ConfigCompile-time filter configuration (cusbf::Config).

Definition at line 69 of file filter.cuh.

Member Typedef Documentation

◆ block_type

template<typename Config >
using cusbf::filter< Config >::block_type = filter_block<Config>

One 256-bit filter block stored as an array of Config::blockWordCount words.

Each shard is addressed as a unit: a minimizer hash selects the shard, and the s-mer-derived hashes set/test bits within it.

The struct is 32-byte aligned to enable vectorised loads via cusbf::detail::load256BitGlobalNC.

Definition at line 86 of file filter.cuh.

◆ Shard

template<typename Config >
using cusbf::filter< Config >::Shard = block_type

Alias for block_type (one 256-bit shard).

Definition at line 88 of file filter.cuh.

Constructor & Destructor Documentation

◆ filter() [1/3]

template<typename Config >
cusbf::filter< Config >::filter ( uint64_t  requestedFilterBits)
inlineexplicit

Constructs a Filter with at least requestedFilterBits bits of storage.

The actual allocated capacity is rounded up to the next power-of-two number of shards.

Parameters
requestedFilterBitsDesired filter capacity in bits.

Definition at line 108 of file filter.cuh.

109 : num_shards_(
110 cuda::std::bit_ceil(
111 std::max<uint64_t>(
112 1,
113 cuda::ceil_div(requestedFilterBits, Config::filterBlockBits)
114 )
115 )
116 ),
117 filter_bits_(num_shards_ * Config::filterBlockBits),
118 d_shards_(num_shards_) {
120 }
Result< void > clear(cuda::stream_ref stream=cudaStream_t{})
Resets all filter bits to zero and synchronises the stream.
Definition filter.cuh:793
#define CUSBF_UNWRAP(expr)
Unwraps a cusbf::Result or throws std::runtime_error on failure (tests and apps).
Definition error.hpp:256
static constexpr uint64_t filterBlockBits
Bits per shard (filter block).
Definition config.cuh:55
Here is the call graph for this function:

◆ filter() [2/3]

template<typename Config >
cusbf::filter< Config >::filter ( const filter< Config > &  )
delete

Non-copyable (owns device shard storage).

◆ filter() [3/3]

template<typename Config >
cusbf::filter< Config >::filter ( filter< Config > &&  )
defaultnoexcept

Move-constructs, transfers shard vectors and staging buffers.

◆ ~filter()

template<typename Config >
cusbf::filter< Config >::~filter ( )
default

Destroys device allocations and releases staging scratch.

Member Function Documentation

◆ clear()

template<typename Config >
Result< void > cusbf::filter< Config >::clear ( cuda::stream_ref  stream = cudaStream_t{})
inline

Resets all filter bits to zero and synchronises the stream.

Parameters
streamCUDA stream to use.

Definition at line 793 of file filter.cuh.

793 {}) {
794 CUSBF_CUDA_TRY(cudaMemsetAsync(
795 thrust::raw_pointer_cast(d_shards_.data()),
796 0,
797 d_shards_.size() * sizeof(block_type),
798 stream.get()
799 ));
800
801 CUSBF_CUDA_TRY(cudaStreamSynchronize(stream.get()));
802 return {};
803 }
filter_block< Config > block_type
One 256-bit filter block stored as an array of Config::blockWordCount words.
Definition filter.cuh:86
#define CUSBF_CUDA_TRY(expr)
Propagates a CUDA error wrapped in cusbf::Result<void>.
Definition error.hpp:269
Here is the caller graph for this function:

◆ contains_dense_packed() [1/2]

template<typename Config >
Result< std::vector< uint8_t > > cusbf::filter< Config >::contains_dense_packed ( std::span< const uint64_t >  words,
uint64_t  num_symbols,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all k-mers from a host-resident dense packed symbol buffer.

Copies d_words to device, queries, copies results back, and synchronises.

Definition at line 289 of file filter.cuh.

292 {}
293 ) const {
294 const uint64_t numKmers = dense_packed_kmer_count(num_symbols);
295 if (numKmers == 0) {
296 return std::vector<uint8_t>{};
297 }
298
299 std::vector<uint8_t> output(numKmers);
300 fastx_state_.ensure_result_capacity(output.size());
301 const device_span<uint8_t> d_output{
302 thrust::raw_pointer_cast(fastx_state_.result_buffer_device().data()), output.size()
303 };
304 CUSBF_TRY(contains_dense_packed(words, num_symbols, d_output, stream));
305 CUSBF_CUDA_TRY(cudaMemcpy(
306 output.data(),
307 thrust::raw_pointer_cast(fastx_state_.result_buffer_device().data()),
308 output.size() * sizeof(uint8_t),
309 cudaMemcpyDeviceToHost
310 ));
311 return output;
312 }
thrust::device_vector< uint8_t > & result_buffer_device() noexcept
constexpr uint64_t dense_packed_kmer_count(uint64_t num_symbols) const
Number of k-mer windows in a dense packed sequence of num_symbols symbols.
Definition filter.cuh:320
Result< void > contains_dense_packed(std::span< const uint64_t > words, uint64_t num_symbols, device_span< uint8_t > d_output, cuda::stream_ref stream=cudaStream_t{}) const
Queries all k-mers from a host-resident dense packed symbol buffer into device memory.
Definition filter.cuh:267
#define CUSBF_TRY(expr)
Propagates a cusbf::Result failure from the enclosing function (GNU statement expression).
Definition error.hpp:246

◆ contains_dense_packed() [2/2]

template<typename Config >
Result< void > cusbf::filter< Config >::contains_dense_packed ( std::span< const uint64_t >  words,
uint64_t  num_symbols,
device_span< uint8_t >  d_output,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all k-mers from a host-resident dense packed symbol buffer into device memory.

Copies words to device, launches the query kernel into d_output, and synchronises. Does not allocate the result buffer or copy hits back to the host.

Definition at line 267 of file filter.cuh.

271 {}
272 ) const {
273 const uint64_t numKmers = dense_packed_kmer_count(num_symbols);
274 if (numKmers == 0) {
275 return {};
276 }
277
278 const auto staged = CUSBF_TRY(fastx_state_.staged_dense_packed_view(words, stream));
279 CUSBF_TRY(launch_contains_dense_packed(staged, num_symbols, d_output, stream));
280 CUSBF_CUDA_TRY(cudaStreamSynchronize(stream.get()));
281 return {};
282 }
Result< device_span< const uint64_t > > staged_dense_packed_view(std::span< const uint64_t > words, cuda::stream_ref stream)

◆ contains_dense_packed_async()

template<typename Config >
Result< void > cusbf::filter< Config >::contains_dense_packed_async ( device_span< const uint64_t >  d_words,
uint64_t  num_symbols,
device_span< uint8_t >  d_output,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Async query of k-mers from a dense packed symbol buffer on the device.

d_output receives one byte per k-mer (1 = present, 0 = absent). Does not synchronise the stream.

Definition at line 248 of file filter.cuh.

252 {}
253 ) const {
254 if (dense_packed_kmer_count(num_symbols) == 0) {
255 return {};
256 }
257
258 return launch_contains_dense_packed(d_words, num_symbols, d_output, stream);
259 }

◆ contains_record_batch_async()

template<typename Config >
Result< void > cusbf::filter< Config >::contains_record_batch_async ( device_span< const char >  d_sequence,
std::span< const RecordRange records,
device_span< uint8_t >  d_output,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Async query of k-mers from a device-resident record batch.

The device sequence is assumed to already contain alphabet separator bytes between records: the caller is responsible for embedding them. records provides ordered, non-overlapping byte ranges into d_sequence.

d_output receives one byte per k-mer across all records (1 = present, 0 = absent). The buffer must hold at least the total k-mer count.

Does not synchronise the stream.

Parameters
d_sequenceDevice-resident sequence (records concatenated with separators already in place).
recordsOrdered, non-overlapping record byte ranges.
d_outputPer-k-mer result buffer.
streamCUDA stream to use.

Definition at line 603 of file filter.cuh.

607 {}
608 ) const {
609 CUSBF_TRY(validate_device_record_batch(d_sequence, records));
610 const uint64_t totalKmers = sequence_kmer_count(d_sequence);
611 if (totalKmers == 0) {
612 return {};
613 }
614 if (d_output.size() < totalKmers) {
615 return Err(Error::invalid_argument("record batch query output span is too small"));
616 }
617 return launch_contains_sequence(d_sequence, d_output, stream);
618 }
cuda::std::unexpected< Error > Err(Error error)
Failure return; converts to any Result<T> via cuda::std::unexpected.
Definition error.hpp:219
static Error invalid_argument(std::string message)
Definition error.hpp:131

◆ contains_sequence() [1/2]

template<typename Config >
Result< std::vector< uint8_t > > cusbf::filter< Config >::contains_sequence ( std::string_view  sequence,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all valid k-mers from a host-resident sequence.

Copies the sequence to device, queries, copies results back, and synchronises. The returned vector has one byte per k-mer: 1 = present, 0 = absent.

Parameters
sequenceRaw nucleotide sequence.
streamCUDA stream to use.
Returns
Per-k-mer membership results (empty if sequence length < k).

Definition at line 515 of file filter.cuh.

515 {}) const {
516 if (record_symbol_count(sequence.size()) < Config::k) {
517 return std::vector<uint8_t>{};
518 }
519
520 std::vector<uint8_t> output(record_kmer_count(sequence.size()));
521 fastx_state_.ensure_result_capacity(output.size());
522 const device_span<uint8_t> d_output{
523 thrust::raw_pointer_cast(fastx_state_.result_buffer_device().data()), output.size()
524 };
525 CUSBF_TRY(contains_sequence(sequence, d_output, stream));
526 CUSBF_CUDA_TRY(cudaMemcpy(
527 output.data(),
528 thrust::raw_pointer_cast(fastx_state_.result_buffer_device().data()),
529 output.size() * sizeof(uint8_t),
530 cudaMemcpyDeviceToHost
531 ));
532 return output;
533 }
Result< void > contains_sequence(std::string_view sequence, device_span< uint8_t > d_output, cuda::stream_ref stream=cudaStream_t{}) const
Queries all valid k-mers from a host-resident sequence into device memory.
Definition filter.cuh:486
static constexpr uint16_t k
K-mer length in symbols.
Definition config.cuh:39

◆ contains_sequence() [2/2]

template<typename Config >
Result< void > cusbf::filter< Config >::contains_sequence ( std::string_view  sequence,
device_span< uint8_t >  d_output,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all valid k-mers from a host-resident sequence into device memory.

Copies the sequence to device, launches the query kernel into d_output, and synchronises. Does not allocate the result buffer or copy hits back to the host.

Parameters
sequenceRaw nucleotide sequence.
d_outputPer-k-mer result buffer (must hold kmerCount() bytes).
streamCUDA stream to use.

Definition at line 486 of file filter.cuh.

489 {}
490 ) const {
491 if (record_symbol_count(sequence.size()) < Config::k) {
492 return {};
493 }
494
495 const auto d_sequence = CUSBF_TRY(
496 fastx_state_.staged_sequence_view({sequence.data(), sequence.size()}, stream)
497 );
498 CUSBF_TRY(launch_contains_sequence(d_sequence, d_output, stream));
499 CUSBF_CUDA_TRY(cudaStreamSynchronize(stream.get()));
500 return {};
501 }
Result< device_span< const char > > staged_sequence_view(std::span< const char > sequence, cuda::stream_ref stream)

◆ contains_sequence_async()

template<typename Config >
Result< void > cusbf::filter< Config >::contains_sequence_async ( device_span< const char >  d_sequence,
device_span< uint8_t >  d_output,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Async query of k-mers from a device-resident sequence.

Does not synchronise the stream. Results are written to d_output (one byte per k-mer: 1 = present, 0 = absent).

Parameters
d_sequenceDevice-resident nucleotide sequence.
d_outputPer-k-mer result buffer (must hold kmerCount() bytes).
streamCUDA stream to use.

Definition at line 464 of file filter.cuh.

467 {}
468 ) const {
469 if (sequence_kmer_count(d_sequence) == 0) {
470 return {};
471 }
472
473 return launch_contains_sequence(d_sequence, d_output, stream);
474 }

◆ dense_packed_kmer_count()

template<typename Config >
constexpr uint64_t cusbf::filter< Config >::dense_packed_kmer_count ( uint64_t  num_symbols) const
inlineconstexpr

Number of k-mer windows in a dense packed sequence of num_symbols symbols.

Definition at line 320 of file filter.cuh.

320 {
321 return detail::dense_packed_kmer_count<Config>(num_symbols);
322 }
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
Here is the call graph for this function:

◆ dense_packed_word_count()

template<typename Config >
static constexpr uint64_t cusbf::filter< Config >::dense_packed_word_count ( uint64_t  num_symbols)
inlinestaticconstexpr

Number of uint64_t words for num_symbols dense packed symbols.

Definition at line 315 of file filter.cuh.

315 {
316 return detail::dense_packed_word_count<Config>(num_symbols);
317 }
Here is the call graph for this function:

◆ filter_bits()

template<typename Config >
uint64_t cusbf::filter< Config >::filter_bits ( ) const
inline

Returns the total allocated capacity of the filter in bits.

Definition at line 826 of file filter.cuh.

826 {
827 return filter_bits_;
828 }

◆ insert_dense_packed()

template<typename Config >
Result< uint64_t > cusbf::filter< Config >::insert_dense_packed ( std::span< const uint64_t >  words,
uint64_t  num_symbols,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Inserts all k-mers from a host-resident dense packed symbol buffer.

Copies d_words to device staging, launches the insert kernel, and synchronises.

Definition at line 226 of file filter.cuh.

229 {}
230 ) {
231 const uint64_t totalKmers = dense_packed_kmer_count(num_symbols);
232 if (totalKmers == 0) {
233 return 0;
234 }
235
236 const auto staged = CUSBF_TRY(fastx_state_.staged_dense_packed_view(words, stream));
237 CUSBF_TRY(launch_insert_dense_packed(staged, num_symbols, stream));
238 CUSBF_CUDA_TRY(cudaStreamSynchronize(stream.get()));
239 return totalKmers;
240 }

◆ insert_dense_packed_async()

template<typename Config >
Result< uint64_t > cusbf::filter< Config >::insert_dense_packed_async ( device_span< const uint64_t >  d_words,
uint64_t  num_symbols,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Inserts all k-mers from a dense packed symbol buffer on the device.

d_words stores dense_packed_word_count(num_symbols) words using Config::symbolBits per encoded symbol. Adjacent k-mers overlap in the same uint64_t chunks; this path decodes a per-block symbol tile and slides packed k-mers like insert_sequence_async.

Does not synchronise the stream.

Parameters
d_wordsDevice-resident dense packed sequence.
num_symbolsNumber of valid encoded symbols in d_words.
streamCUDA stream to use.
Returns
Number of k-mers attempted.

Definition at line 207 of file filter.cuh.

210 {}
211 ) {
212 const uint64_t totalKmers = dense_packed_kmer_count(num_symbols);
213 if (totalKmers == 0) {
214 return 0;
215 }
216
217 CUSBF_TRY(launch_insert_dense_packed(d_words, num_symbols, stream));
218 return totalKmers;
219 }

◆ insert_fastx()

template<typename Config >
Result< FastxInsertReport > cusbf::filter< Config >::insert_fastx ( std::istream &  input,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Inserts all k-mers from a FASTA/FASTQ input stream.

Reads records in streaming fashion, accumulating them until the concatenated sequence approaches a GPU staging budget derived from free VRAM (fill_fraction of free memory minus a small slack reserve), then inserts each chunk independently. The budget accounts for normalized sequence device staging.

Parameters
inputInput stream containing FASTA or FASTQ records.
fill_fractionFraction of available GPU memory for per-chunk staging (default 0.7).
streamCUDA stream to use.
Returns
Report summarising records indexed, bases processed, and k-mers inserted.

Definition at line 416 of file filter.cuh.

419 {}
420 ) {
421 return insert_fastx_stream(input, "<stream>", fill_fraction, stream);
422 }

◆ insert_fastx_file()

template<typename Config >
Result< FastxInsertReport > cusbf::filter< Config >::insert_fastx_file ( const std::filesystem::path &  path,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Inserts all k-mers from a FASTA/FASTQ file.

Uses fill_fraction of free GPU memory to size chunks. When the file fits in a single chunk, reads via a lightweight stream (no mmap, no ping-pong). Larger files are mmap'd if they fit in host RAM, otherwise streamed, multi-chunk paths overlap host assembly with GPU work.

Parameters
pathPath to a FASTA or FASTQ file (optionally gzip-compressed).
fill_fractionFraction of free GPU memory for per-chunk staging (default 0.7).
streamOptional CUDA stream, default uses an internal pipelined path.
Returns
Report summarising records indexed, bases processed, and k-mers inserted.

Definition at line 437 of file filter.cuh.

440 {}
441 ) {
443 path,
445 fill_fraction,
446 [&](auto& reader, auto dispatch_path) {
447 return insert_fastx_reader(
448 reader, std::string_view{path.native()}, fill_fraction, stream, dispatch_path
449 );
450 }
451 );
452 }

◆ insert_record_batch()

template<typename Config >
Result< FastxInsertReport > cusbf::filter< Config >::insert_record_batch ( RecordBatchView  batch,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Inserts a dense host-resident record batch.

batch.sequence stores the raw record payloads back-to-back without separators. batch.records stores ordered, non-overlapping byte ranges into that dense buffer. The filter injects alphabet separators between records internally, so callers do not need to materialise separator bytes themselves.

Synchronises before returning.

Parameters
batchDense record batch to insert.
streamCUDA stream to use.
Returns
Report summarising records indexed, bases processed, and k-mers inserted.

Definition at line 339 of file filter.cuh.

339 {}) {
340 CUSBF_TRY(
341 normalize_record_batch_into<Config>(
342 batch,
343 fastx_state_.normalized_sequence_scratch(),
344 fastx_state_.normalized_records_scratch()
345 )
346 );
347 FastxInsertReport report;
348 report.recordsIndexed = fastx_state_.normalized_records_scratch().size();
349 for (const NormalizedRecord& record : fastx_state_.normalized_records_scratch()) {
350 report.indexedBases += record.size;
351 report.insertedKmers += record.valid_kmers;
352 }
353 if (!fastx_state_.normalized_sequence_scratch().empty()) {
354 const auto d_sequence = CUSBF_TRY(fastx_state_.staged_sequence_view(
355 {fastx_state_.normalized_sequence_scratch().data(),
356 fastx_state_.normalized_sequence_scratch().size()},
357 stream
358 ));
359 CUSBF_TRY(insert_sequence_async(d_sequence, stream));
360 CUSBF_CUDA_TRY(cudaStreamSynchronize(stream.get()));
361 }
362 fastx_state_.release_all();
363 return report;
364 }
std::vector< NormalizedRecord > & normalized_records_scratch() noexcept
std::string & normalized_sequence_scratch() noexcept
Result< uint64_t > insert_sequence_async(device_span< const char > d_sequence, cuda::stream_ref stream=cudaStream_t{})
Async insert of k-mers from a device-resident sequence.
Definition filter.cuh:179

◆ insert_record_batch_async()

template<typename Config >
Result< uint64_t > cusbf::filter< Config >::insert_record_batch_async ( device_span< const char >  d_sequence,
std::span< const RecordRange records,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Async insert of k-mers from a device-resident record batch.

The device sequence is assumed to already contain alphabet separator bytes between records, the caller is responsible for embedding them so that cross-record k-mers are not formed. records provides ordered, non-overlapping byte ranges into d_sequence.

The returned count is total attempted k-mers (maximum possible per record size). The kernel still skips k-mer windows that contain invalid symbols.

Does not synchronise the stream.

Parameters
d_sequenceDevice-resident sequence (records concatenated with separators already in place).
recordsOrdered, non-overlapping record byte ranges.
streamCUDA stream to use.
Returns
Total attempted k-mers across all records (0 if none).

Definition at line 385 of file filter.cuh.

388 {}
389 ) {
390 CUSBF_TRY(validate_device_record_batch(d_sequence, records));
391 uint64_t totalKmers = 0;
392 for (const RecordRange& record : records) {
393 totalKmers += record_kmer_count(record.sequenceBytes);
394 }
395 if (totalKmers == 0) {
396 return 0;
397 }
398 CUSBF_TRY(launch_insert_sequence(d_sequence, stream));
399 return totalKmers;
400 }

◆ insert_sequence()

template<typename Config >
Result< uint64_t > cusbf::filter< Config >::insert_sequence ( std::string_view  sequence,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Inserts all valid k-mers from a host-resident sequence.

Copies the sequence to device, launches the insert kernel, and synchronises before returning. K-mer windows containing alphabet-invalid symbols are skipped.

Parameters
sequenceHost-resident sequence bytes (alphabet-encoded width per symbol).
streamCUDA stream to use (default: null stream).
Returns
Number of k-mer windows attempted (sequences shorter than k yield 0).

Definition at line 155 of file filter.cuh.

155 {}) {
156 if (record_symbol_count(sequence.size()) < Config::k) {
157 return 0;
158 }
159
160 const uint64_t totalKmers = record_kmer_count(sequence.size());
161 const auto d_sequence = CUSBF_TRY(
162 fastx_state_.staged_sequence_view({sequence.data(), sequence.size()}, stream)
163 );
164 CUSBF_TRY(launch_insert_sequence(d_sequence, stream));
165 CUSBF_CUDA_TRY(cudaStreamSynchronize(stream.get()));
166 return totalKmers;
167 }

◆ insert_sequence_async()

template<typename Config >
Result< uint64_t > cusbf::filter< Config >::insert_sequence_async ( device_span< const char >  d_sequence,
cuda::stream_ref  stream = cudaStream_t{} 
)
inline

Async insert of k-mers from a device-resident sequence.

Does not synchronise the stream, the caller is responsible for ordering relative to downstream operations.

Parameters
d_sequenceDevice-resident nucleotide sequence.
streamCUDA stream to use.
Returns
Number of k-mers attempted.

Definition at line 179 of file filter.cuh.

181 {}
182 ) {
183 const uint64_t totalKmers = sequence_kmer_count(d_sequence);
184 if (totalKmers == 0) {
185 return 0;
186 }
187
188 CUSBF_TRY(launch_insert_sequence(d_sequence, stream));
189 return totalKmers;
190 }

◆ load_factor()

template<typename Config >
float cusbf::filter< Config >::load_factor ( ) const
inline

Computes the fraction of set bits in the filter.

Returns
Load factor in [0, 1].

Definition at line 810 of file filter.cuh.

810 {
811 const auto* wordsBegin =
812 reinterpret_cast<const uint64_t*>(thrust::raw_pointer_cast(d_shards_.data()));
813 const uint64_t totalWords = num_shards_ * Config::blockWordCount;
814 const uint64_t setBits = thrust::transform_reduce(
815 thrust::device,
816 wordsBegin,
817 wordsBegin + totalWords,
818 [] __device__(uint64_t w) -> uint64_t { return cuda::std::popcount(w); },
819 uint64_t{0},
820 cuda::std::plus<uint64_t>()
821 );
822 return static_cast<float>(setBits) / static_cast<float>(filter_bits_);
823 }
static constexpr uint64_t blockWordCount
64-bit words per 256-bit shard.
Definition config.cuh:62

◆ num_shards()

template<typename Config >
uint64_t cusbf::filter< Config >::num_shards ( ) const
inline

Returns the number of shards.

Definition at line 831 of file filter.cuh.

831 {
832 return num_shards_;
833 }

◆ operator=() [1/2]

template<typename Config >
filter & cusbf::filter< Config >::operator= ( const filter< Config > &  )
delete

◆ operator=() [2/2]

template<typename Config >
filter & cusbf::filter< Config >::operator= ( filter< Config > &&  )
defaultnoexcept

Move-assigns shard storage and staging buffers.

◆ query_fastx()

template<typename Config >
Result< FastxQueryReport > cusbf::filter< Config >::query_fastx ( std::istream &  input,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all k-mers from a FASTA/FASTQ input stream via chunked streaming.

Returns aggregate counts only (no per-record hit vectors). For per-record callbacks use query_fastx_records, for owning per-record hits use query_fastx_detailed.

Parameters
inputInput stream containing FASTA or FASTQ records.
fill_fractionFraction of free GPU memory for per-chunk staging (default 0.7).
streamCUDA stream to use.
Returns
Aggregate query summary for the whole stream.
See also
insert_fastx

Definition at line 632 of file filter.cuh.

635 {}
636 ) const {
637 return query_fastx_stream(input, "<stream>", fill_fraction, stream);
638 }

◆ query_fastx_detailed()

template<typename Config >
Result< FastxDetailedQueryReport > cusbf::filter< Config >::query_fastx_detailed ( std::istream &  input,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all k-mers from a FASTA/FASTQ input stream via chunked streaming and preserves per-record hit vectors.

The returned report keeps aggregate counts plus one detailed record result in source order. Each detailed hit vector contains one byte per k-mer window: 1 = present, 0 = absent. Invalid-symbol windows remain in the vector as 0 and are excluded from queriedKmers.

Parameters
inputInput stream containing FASTA or FASTQ records.
fill_fractionFraction of free GPU memory for per-chunk staging (default 0.7).
streamCUDA stream to use.
Returns
Aggregate and per-record query results.
See also
query_fastx

Definition at line 750 of file filter.cuh.

753 {}
754 ) const {
755 detail::FastxReader reader(input, "<stream>");
756 return query_fastx_detailed_stream(
757 reader, "<stream>", fill_fraction, stream, detail::fastx_dispatch_path::chunked_stream
758 );
759 }
@ chunked_stream
Multiple GPU chunks, stream via istream (gzip or larger than RAM).

◆ query_fastx_file()

template<typename Config >
Result< FastxQueryReport > cusbf::filter< Config >::query_fastx_file ( const std::filesystem::path &  path,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all k-mers from a FASTA/FASTQ file.

Returns aggregate counts only. See query_fastx_file_records and query_fastx_file_detailed for per-record results.

Parameters
pathPath to a FASTA or FASTQ file (optionally gzip-compressed).
fill_fractionFraction of free GPU memory for per-chunk staging (default 0.7).
streamCUDA stream to use.
Returns
Aggregate query summary for the whole file.
See also
insert_fastx_file for dispatch and chunking behavior.

Definition at line 652 of file filter.cuh.

655 {}
656 ) const {
658 path,
660 fill_fraction,
661 [&](auto& reader, auto dispatch_path) {
662 return query_fastx_reader(
663 reader, std::string_view{path.native()}, fill_fraction, stream, dispatch_path
664 );
665 }
666 );
667 }

◆ query_fastx_file_detailed()

template<typename Config >
Result< FastxDetailedQueryReport > cusbf::filter< Config >::query_fastx_file_detailed ( const std::filesystem::path &  path,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries all k-mers from a FASTA/FASTQ file via chunked streaming and preserves per-record hit vectors.

Parameters
pathPath to a FASTA or FASTQ file (optionally gzip-compressed).
fill_fractionFraction of free GPU memory for per-chunk staging (default 0.7).
streamCUDA stream to use.
Returns
Aggregate and per-record query results.
See also
query_fastx_detailed

Definition at line 771 of file filter.cuh.

774 {}
775 ) const {
777 path,
779 fill_fraction,
780 [&](auto& reader, auto dispatch_path) {
781 return query_fastx_detailed_stream(
782 reader, std::string_view{path.native()}, fill_fraction, stream, dispatch_path
783 );
784 }
785 );
786 }

◆ query_fastx_file_records()

template<typename Config >
template<FastxRecordConsumer Consumer>
Result< FastxQueryReport > cusbf::filter< Config >::query_fastx_file_records ( const std::filesystem::path &  path,
Consumer &&  consume,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries a FASTA/FASTQ file and emits one record result per parsed record.

Parameters
pathPath to a FASTA or FASTQ file (optionally gzip-compressed).
consumePer-record callback.
fill_fractionFraction of free GPU memory for per-chunk staging (default 0.7).
streamCUDA stream to use.
Returns
Aggregate query summary for the whole file.
See also
query_fastx_records

Definition at line 712 of file filter.cuh.

716 {}
717 ) const {
719 path,
721 fill_fraction,
722 [&](auto& reader, auto dispatch_path) {
723 return query_fastx_records_stream(
724 reader,
725 std::string_view{path.native()},
726 consume,
727 fill_fraction,
728 stream,
729 dispatch_path
730 );
731 }
732 );
733 }

◆ query_fastx_records()

template<typename Config >
template<FastxRecordConsumer Consumer>
Result< FastxQueryReport > cusbf::filter< Config >::query_fastx_records ( std::istream &  input,
Consumer &&  consume,
double  fill_fraction = 0.7,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries a FASTA/FASTQ stream and emits one record result per parsed record.

The callback receives record headers, record sequences, aggregate counts, and the per-window hit span for each record as soon as its chunk has been processed. The hit span remains valid only for the duration of the callback.

Parameters
inputInput stream containing FASTA or FASTQ records.
consumePer-record callback.
fill_fractionFraction of available GPU memory for per-chunk staging (default 0.7). Query mode reserves space for both sequence and per-k-mer hit buffers.
streamCUDA stream to use.
Returns
Aggregate query summary for the whole stream.

Definition at line 684 of file filter.cuh.

688 {}
689 ) const {
690 detail::FastxReader reader(input, "<stream>");
691 return query_fastx_records_stream(
692 reader,
693 "<stream>",
694 consume,
695 fill_fraction,
696 stream,
698 );
699 }

◆ query_record_batch() [1/2]

template<typename Config >
template<RecordQueryConsumer Consumer>
Result< FastxQueryReport > cusbf::filter< Config >::query_record_batch ( RecordBatchView  batch,
Consumer &&  consume,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries a dense host-resident record batch and streams per-record results.

The callback receives one RecordQueryView per input record in source order. The hit span remains valid only for the duration of the callback.

Synchronises before returning.

Parameters
batchDense record batch to query.
consumePer-record callback.
streamCUDA stream to use.
Returns
Aggregate query summary for the whole batch.

Definition at line 568 of file filter.cuh.

571 {}
572 ) const {
573 CUSBF_TRY(
574 normalize_record_batch_into<Config>(
575 batch,
576 fastx_state_.normalized_sequence_scratch(),
577 fastx_state_.normalized_records_scratch()
578 )
579 );
580 return query_normalized_record_batch_with_hits(
581 batch.sequence, std::forward<Consumer>(consume), stream
582 );
583 }

◆ query_record_batch() [2/2]

template<typename Config >
Result< FastxQueryReport > cusbf::filter< Config >::query_record_batch ( RecordBatchView  batch,
cuda::stream_ref  stream = cudaStream_t{} 
) const
inline

Queries a dense host-resident record batch and returns aggregate counts.

batch.sequence stores raw record payloads back-to-back without separators. batch.records stores ordered, non-overlapping byte ranges into that dense buffer. The filter injects alphabet separators between records internally, so cross-record k-mers are never formed.

Synchronises before returning.

Parameters
batchDense record batch to query.
streamCUDA stream to use.
Returns
Aggregate query summary for the whole batch.

Definition at line 550 of file filter.cuh.

550 {}) const {
551 return query_record_batch_aggregate(batch, stream);
552 }

◆ ref()

template<typename Config >
filter_ref< Config > cusbf::filter< Config >::ref ( ) const
inlinenoexcept

Non-owning device reference to this filter's shard storage.

Trivially copyable, intended to be passed by value into CUDA kernels.

Definition at line 137 of file filter.cuh.

137 {
138 return filter_ref<Config>{
139 thrust::raw_pointer_cast(d_shards_.data()),
140 num_shards_,
141 };
142 }

The documentation for this class was generated from the following files: