cuDDL
Loading...
Searching...
No Matches
sketch_view.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda/algorithm>
4#include <cuda/std/cstdint>
5#include <cuda/stream>
6
10#include <cuddl/device_span.cuh>
11#include <cuddl/error.hpp>
14
15namespace cuddl::detail {
16
24template <uint32_t K, size_t BucketCount, typename Layout = default_register_layout>
26 static_assert(K >= 1 && K <= 31);
27 static_assert(BucketCount >= (size_t{1} << 11) && BucketCount <= (size_t{1} << 13));
28 static_assert((BucketCount & (BucketCount - 1)) == 0);
29
30 public:
31 using register_type = uint32_t;
33
35 __host__ __device__ constexpr explicit sketch_view(
37 cuda::std::optional<blacklist_view> blacklist = cuda::std::nullopt
38 ) noexcept
39 : registers_(registers), blacklist_(blacklist) {}
40
42 [[nodiscard]] __host__ __device__ constexpr device_span<register_type> data() const noexcept {
43 return registers_;
44 }
45
47 [[nodiscard]] static constexpr size_t bucket_count() noexcept {
48 return BucketCount;
49 }
50
52 [[nodiscard]] static constexpr uint32_t kmer_length() noexcept {
53 return K;
54 }
55
57 [[nodiscard]] Result<void> clear_async(cuda::stream_ref stream) const noexcept {
58 return cuda_try([&] {
59 cuda::fill_bytes(stream, cuda::std::span{registers_.data(), registers_.size()}, 0);
60 });
61 }
62
66 [[nodiscard]] Result<void>
67 add_async(device_span<uint64_t const> input, cuda::stream_ref stream) const noexcept {
68 return detail::launch_construction<BucketCount, Layout>(
69 input, registers_, stream, blacklist_
70 );
71 }
72
81 [[nodiscard]] Result<void>
82 add_sequence_async(device_span<char const> sequence, cuda::stream_ref stream) const noexcept {
83 return detail::launch_sequence_add<BucketCount, Layout>(
84 sequence, K, registers_, stream, blacklist_
85 );
86 }
87
91 template <bool IncludeCardinality = false>
93 sketch_view other,
94 pairwise_summary& output,
95 cuda::stream_ref stream
96 ) const noexcept {
97 detail::summary_kernel<BucketCount, IncludeCardinality, Layout>
98 <<<1, detail::block_size, 0, stream.get()>>>(
99 registers_.data(), other.registers_.data(), output
100 );
101 return cuda_try(cudaGetLastError());
102 }
103
108 uint64_t* empty_out,
109 double* estimate_out,
110 cuda::stream_ref stream
111 ) const noexcept {
112 detail::cardinality_kernel<BucketCount, Layout><<<1, detail::block_size, 0, stream.get()>>>(
113 registers_.data(), empty_out, estimate_out
114 );
115 return cuda_try(cudaGetLastError());
116 }
117
121 cuda::stream_ref stream
122 ) const noexcept {
123 detail::hybrid_cardinality_kernel<BucketCount, Layout>
124 <<<1, detail::block_size, 0, stream.get()>>>(registers_.data(), output);
125 return cuda_try(cudaGetLastError());
126 }
127
128 private:
130 cuda::std::optional<blacklist_view> blacklist_;
131};
132
133} // namespace cuddl::detail
Non-owning implementation view of a DDL sketch.
static constexpr size_t bucket_count() noexcept
Number of registers in the sketch.
Result< void > add_sequence_async(device_span< char const > sequence, cuda::stream_ref stream) const noexcept
Accumulates device-resident raw ASCII bases without clearing.
Result< void > add_async(device_span< uint64_t const > input, cuda::stream_ref stream) const noexcept
Accumulates packed device k-mers into the existing sketch without clearing it.
__host__ __device__ constexpr device_span< register_type > data() const noexcept
Device registers.
__host__ __device__ constexpr sketch_view(device_span< register_type > registers, cuda::std::optional< blacklist_view > blacklist=cuda::std::nullopt) noexcept
Constructs a reference over registers.
Result< void > clear_async(cuda::stream_ref stream) const noexcept
Resets every register to zero.
Result< void > summary_async(sketch_view other, pairwise_summary &output, cuda::stream_ref stream) const noexcept
Computes the raw pairwise summary into caller-owned device storage.
Result< void > hybrid_cardinality_async(hybrid_cardinality_estimates *output, cuda::stream_ref stream) const noexcept
Computes BBTools and paper-style HybridDDL estimates in one GPU register scan.
static constexpr uint32_t kmer_length() noexcept
Compile-time k-mer length.
Result< void > cardinality_async(uint64_t *empty_out, double *estimate_out, cuda::stream_ref stream) const noexcept
Computes this sketch's cardinality reduction on the GPU.
__global__ size_t uint32_t bool blacklist_view bool Layout
Definition kernels.cuh:155
__global__ size_t uint32_t bool blacklist_view blacklist
Definition kernels.cuh:96
constexpr uint32_t block_size
Threads per CTA for the single-pair and cardinality reduction kernels.
Definition kernels.cuh:28
__global__ size_t uint32_t * registers
Definition kernels.cuh:94
Result< void > cuda_try(cudaError_t error, std::source_location location=std::source_location::current())
Checks a CUDA runtime call and returns an error on failure.
Definition error.hpp:187
Fallible API result: cuda::std::expected<T, Error> with cuDDL factories.
Definition error.hpp:118
A span that is assumed to point to device-accessible memory.
Experimental DDL cardinality estimates computed from one register scan.
Pairwise counts with an optional compile-time cardinality field.