cuSBF
Loading...
Searching...
No Matches
fastx_pipeline_core.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <string_view>
5#include <utility>
6
7#include <cuda/stream>
8
14#include <cusbf/error.hpp>
15
16namespace cusbf::detail {
17
31
32template <typename Config, typename FastxReaderType, typename Adapter>
35 std::string_view source_name,
36 double fill_fraction,
37 cuda::stream_ref stream,
41) {
43
45 if (!gpu_memory) {
46 return Err(Error::resource(gpu_memory.error().message()));
47 }
48
49 const size_t staging_budget_bytes =
54
57
58 auto collect_all = [&](auto&& maybe_flush) -> Result<void> {
59 for (;;) {
60 const uint64_t local_index = chunk.recordCount();
62 break;
63 }
64 adapter.on_record_collected(record, local_index, chunk);
66 }
67 return {};
68 };
69
71 CUSBF_TRY(collect_all([&]() -> Result<void> { return {}; }));
72 CUSBF_TRY(adapter.flush_sync(chunk, stream));
73 return adapter.finish();
74 }
75
76 if (stream.get() == nullptr && adapter.supports_pipelined()) {
77 const size_t pipelined_chunk_budget =
80 size_t ping = 0;
81 bool has_inflight = false;
82
85 adapter.chunk_mode(),
88 chunk.raw_sequence_bytes(),
89 chunk.recordCount()
90 )) {
91 return {};
92 }
93 return adapter.flush_pipelined(chunk, chunk_streams, ping, has_inflight);
94 }));
95
97 CUSBF_TRY(chunk_streams.sync_all());
98 CUSBF_TRY(adapter.finish_pipelined(chunk_streams, ping, has_inflight));
99 return adapter.finish();
100 }
101
102 const size_t sync_chunk_budget =
103 stream.get() == nullptr && !adapter.supports_pipelined()
106
109 adapter.chunk_mode(),
112 chunk.raw_sequence_bytes(),
113 chunk.recordCount()
114 )) {
115 return {};
116 }
117 return adapter.flush_sync(chunk, stream);
118 }));
119
120 CUSBF_TRY(adapter.flush_sync(chunk, stream));
121 return adapter.finish();
122}
123
124} // namespace cusbf::detail
Accumulates parsed FASTX records into a dense RecordBatchView.
Definition Fastx.hpp:46
Two non-blocking CUDA streams for overlapping chunk H2D and kernel work.
FastxPipelineReleaseGuard(FastxPipelineState &state)
FastxPipelineReleaseGuard(const FastxPipelineReleaseGuard &)=delete
FastxPipelineReleaseGuard & operator=(const FastxPipelineReleaseGuard &)=delete
#define CUSBF_TRY(expr)
Propagates a cusbf::Result failure from the enclosing function (GNU statement expression).
Definition error.hpp:246
size_t fastx_host_chunk_max_bytes()
Optional host assembly byte cap before flush (debug / low-RAM safety valve).
Result< cuda_free_memory > query_cuda_free_memory()
Queries current device free memory via cudaMemGetInfo.
uint64_t fastx_file_bytes(const std::filesystem::path &path)
constexpr size_t fastx_pipelined_chunk_budget(fastx_chunk_mode mode, size_t staging_budget_bytes) noexcept
Per-chunk flush budget for dual-stream ping-pong (two device sequence buffers).
fastx_dispatch_path
How a FASTX file is read and chunked for GPU processing.
constexpr bool fastx_is_single_chunk_path(fastx_dispatch_path path) noexcept
True for fastx_dispatch_path::single_chunk_stream or fastx_dispatch_path::single_chunk_mmap.
constexpr bool fastx_uses_mmap_reader(fastx_dispatch_path path) noexcept
True when dispatch uses FastxBufferReader over an mmap'd file.
Result< typename Adapter::report_type > run_fastx_pipeline(FastxReaderType &reader, std::string_view source_name, double fill_fraction, cuda::stream_ref stream, fastx_dispatch_path dispatch_path, FastxPipelineState &state, Adapter &&adapter)
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
Result< bool > collect_next_fastx_record(FastxReaderType &reader, FastxRecord &record, DenseRecordBatchBuilder &chunk)
Appends the next FASTX record from reader into chunk.
cuda::std::unexpected< Error > Err(Error error)
Failure return; converts to any Result<T> via cuda::std::unexpected.
Definition error.hpp:219
static Error resource(std::string message)
Definition error.hpp:135
Fallible API result: cuda::std::expected<T, Error> with cuSBF factories.
Definition error.hpp:152
A single sequence record extracted from a FASTA/FASTQ stream.
Definition Fastx.hpp:253