cuSBF
Loading...
Searching...
No Matches
fastx_pinned_buffer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cuda_runtime.h>
4
5#include <cstddef>
6#include <cstdint>
7#include <cstring>
8#include <string_view>
9
10#include <cusbf/cuda_error.hpp>
11
12namespace cusbf::detail {
13
16 public:
20
22 *this = std::move(other);
23 }
24
26 if (this != &other) {
27 release();
28 data_ = other.data_;
29 size_ = other.size_;
30 capacity_ = other.capacity_;
31 other.data_ = nullptr;
32 other.size_ = 0;
33 other.capacity_ = 0;
34 }
35 return *this;
36 }
37
41
43 [[nodiscard]] char* data() noexcept {
44 return data_;
45 }
46
48 [[nodiscard]] const char* data() const noexcept {
49 return data_;
50 }
51
54 return size_;
55 }
56
59 return capacity_;
60 }
61
63 [[nodiscard]] std::string_view view() const noexcept {
64 return std::string_view{data_, size_};
65 }
66
68 void clear() noexcept {
69 size_ = 0;
70 }
71
73 void release() {
74 if (data_ != nullptr) {
76 data_ = nullptr;
77 }
78 size_ = 0;
79 capacity_ = 0;
80 }
81
84 if (nbytes <= capacity_) {
85 return {};
86 }
87
88 char* reallocated = nullptr;
90 if (data_ != nullptr) {
91 if (size_ != 0) {
92 std::memcpy(reallocated, data_, size_);
93 }
95 }
96 data_ = reallocated;
97 capacity_ = nbytes;
98 return {};
99 }
100
103 if (nbytes > capacity_) {
105 }
106 size_ = nbytes;
107 return {};
108 }
109
110 private:
111 char* data_{nullptr};
112 size_t size_{0};
113 size_t capacity_{0};
114};
115
116} // namespace cusbf::detail
Page-locked host buffer for fused FASTX normalize + H2D staging.
FastxPinnedSequenceBuffer(FastxPinnedSequenceBuffer &&other) noexcept
size_t size() const noexcept
Logical byte length (≤ capacity).
std::string_view view() const noexcept
data() as a string view of length size().
Result< void > set_size(size_t nbytes)
Sets logical size to nbytes, reserving if needed.
FastxPinnedSequenceBuffer & operator=(FastxPinnedSequenceBuffer &&other) noexcept
size_t capacity() const noexcept
Allocated pinned bytes.
char * data() noexcept
Writable pinned host pointer (may be nullptr before reserve).
const char * data() const noexcept
Read-only view of data().
FastxPinnedSequenceBuffer(const FastxPinnedSequenceBuffer &)=delete
FastxPinnedSequenceBuffer & operator=(const FastxPinnedSequenceBuffer &)=delete
void clear() noexcept
Sets logical size to zero without freeing capacity.
void release()
Frees pinned host memory and resets size and capacity.
Result< void > reserve(size_t nbytes)
Grows pinned allocation to at least nbytes, preserving existing bytes.
#define CUSBF_CUDA_ABORT(expr)
Checks a CUDA call and aborts on failure (destructors and RAII only).
Definition error.hpp:266
#define CUSBF_TRY(expr)
Propagates a cusbf::Result failure from the enclosing function (GNU statement expression).
Definition error.hpp:246
#define CUSBF_CUDA_TRY(expr)
Propagates a CUDA error wrapped in cusbf::Result<void>.
Definition error.hpp:269
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
Fallible API result: cuda::std::expected<T, Error> with cuSBF factories.
Definition error.hpp:152