cuDDL
Loading...
Searching...
No Matches
pairwise_counts.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda/std/cstdint>
4
5namespace cuddl {
6
10 uint32_t lower{};
12 uint32_t equal{};
14 uint32_t higher{};
16 uint32_t both_empty{};
17
19 __host__ __device__ pairwise_counts& operator+=(pairwise_counts const other) noexcept {
20 lower += other.lower;
21 equal += other.equal;
22 higher += other.higher;
23 both_empty += other.both_empty;
24 return *this;
25 }
26
28 friend __host__ __device__ pairwise_counts
29 operator+(pairwise_counts left, pairwise_counts const right) noexcept {
30 return left += right;
31 }
32
34 [[nodiscard]] __host__ __device__ constexpr pairwise_counts mirrored() const noexcept {
35 return {.lower = higher, .equal = equal, .higher = lower, .both_empty = both_empty};
36 }
37
38 friend bool operator==(pairwise_counts const&, pairwise_counts const&) = default;
39};
40
49 uint64_t bits{};
50
51 [[nodiscard]] static __host__ __device__ constexpr packed_pairwise_counts
52 pack(uint32_t lower, uint32_t equal, uint32_t higher) noexcept {
53 return {
54 static_cast<uint64_t>(lower) | (static_cast<uint64_t>(equal) << 21U) |
55 (static_cast<uint64_t>(higher) << 42U)
56 };
57 }
58
59 [[nodiscard]] __host__ __device__ constexpr pairwise_counts unpack(
60 uint32_t bucket_count
61 ) const noexcept {
62 constexpr uint64_t field = (uint64_t{1} << 21U) - 1U;
63 auto const lower = static_cast<uint32_t>(bits & field);
64 auto const equal = static_cast<uint32_t>((bits >> 21U) & field);
65 auto const higher = static_cast<uint32_t>(bits >> 42U);
66 return {
67 .lower = lower,
68 .equal = equal,
69 .higher = higher,
70 .both_empty = bucket_count - lower - equal - higher,
71 };
72 }
73
74 friend bool operator==(packed_pairwise_counts const&, packed_pairwise_counts const&) = default;
75};
76
83[[nodiscard]] __host__ __device__ constexpr float weighted_kmer_identity(
85) noexcept {
86 auto const divisor =
87 counts.equal + (counts.lower < counts.higher ? counts.lower : counts.higher);
88 if (divisor == 0U) return 0.0F;
89 return static_cast<float>(counts.equal) / static_cast<float>(divisor < 6U ? 6U : divisor);
90}
91
95 double cardinality{};
96
97 friend bool operator==(pairwise_summary const&, pairwise_summary const&) = default;
98};
99
100} // namespace cuddl
Batch operations over contiguous device rows.
Definition a48.hpp:14
@ counts
One 24-byte batch_search_result per pair: query ID, reference ID and the lower, equal,...
__host__ __device__ constexpr float weighted_kmer_identity(pairwise_counts const &counts) noexcept
Weighted k-mer identity of a pair, equal / max(equal + min(lower, higher), 6), as sketch::wkid comput...
One pair's exact bucket comparison counts in 64 bits, the storage and transfer form of batch-search r...
static __host__ __device__ constexpr packed_pairwise_counts pack(uint32_t lower, uint32_t equal, uint32_t higher) noexcept
__host__ __device__ constexpr pairwise_counts unpack(uint32_t bucket_count) const noexcept
friend bool operator==(packed_pairwise_counts const &, packed_pairwise_counts const &)=default
Raw per-bucket classification counts for one sketch pair comparison.
friend bool operator==(pairwise_counts const &, pairwise_counts const &)=default
uint32_t both_empty
Both registers are empty in that bucket.
__host__ __device__ constexpr pairwise_counts mirrored() const noexcept
The same comparison seen from the other sketch: lower and higher swap.
uint32_t equal
this register equals the other's in that bucket.
friend __host__ __device__ pairwise_counts operator+(pairwise_counts left, pairwise_counts const right) noexcept
Sums two count sets for device reductions.
uint32_t lower
this register is strictly lower than the other's in that bucket.
__host__ __device__ pairwise_counts & operator+=(pairwise_counts const other) noexcept
Accumulates other into this instance (used for device reductions).
uint32_t higher
this register is strictly higher than the other's in that bucket.
Pairwise counts with an optional compile-time cardinality field.
friend bool operator==(pairwise_summary const &, pairwise_summary const &)=default