cuDDL
Loading...
Searching...
No Matches
cardinality.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda/std/cmath>
4#include <cuda/std/cstdint>
5#include <cuda/std/limits>
6
7namespace cuddl::detail {
8
10constexpr double hash_range = 0x1p64;
11
32__host__ __device__ inline double
33minimum_mle(double bucket_count, double empty_count, double sum_restored) noexcept {
34 auto const filled = bucket_count - empty_count;
35 if (filled <= 0.0) {
36 return 0.0;
37 }
38 return bucket_count * filled / (empty_count + sum_restored / hash_range);
39}
40
44__host__ __device__ inline double
45mean_m(double bucket_count, double filled, double sum_restored) noexcept {
46 if (filled <= 0.0 || sum_restored <= 0.0) {
47 return 0.0;
48 }
49 return bucket_count * filled * hash_range / sum_restored;
50}
51
58__host__ __device__ inline double
59cardinality(double bucket_count, double empty_count, double sum_restored) noexcept {
60 return minimum_mle(bucket_count, empty_count, sum_restored);
61}
62
70__host__ __device__ inline float
71minimum_mle_f32(float bucket_count, float empty_count, float sum_restored) noexcept {
72 auto const filled = bucket_count - empty_count;
73 if (filled <= 0.0f) {
74 return 0.0f;
75 }
76 return bucket_count * filled /
77 (empty_count + sum_restored / static_cast<float>(hash_range));
78}
79
81__host__ __device__ inline float
82mean_m_f32(float bucket_count, float filled, float sum_restored) noexcept {
83 if (filled <= 0.0f || sum_restored <= 0.0f) {
84 return 0.0f;
85 }
86 return bucket_count * filled * static_cast<float>(hash_range) / sum_restored;
87}
88
90__host__ __device__ inline float
91cardinality_f32(float bucket_count, float empty_count, float sum_restored) noexcept {
92 return minimum_mle_f32(bucket_count, empty_count, sum_restored);
93}
94
95} // namespace cuddl::detail
__host__ __device__ double mean_m(double bucket_count, double filled, double sum_restored) noexcept
MeanM estimate retained as the full-sketch form of minimum_mle.
__host__ __device__ float mean_m_f32(float bucket_count, float filled, float sum_restored) noexcept
Single-precision mean_m for the throughput-bound cardinality reduction.
__host__ __device__ float minimum_mle_f32(float bucket_count, float empty_count, float sum_restored) noexcept
Single-precision variants of the cardinality estimators.
constexpr double hash_range
2^64, the range of the 64-bit hash used by the sketch.
__host__ __device__ float cardinality_f32(float bucket_count, float empty_count, float sum_restored) noexcept
Single-precision cardinality for the throughput-bound cardinality reduction.
__host__ __device__ double minimum_mle(double bucket_count, double empty_count, double sum_restored) noexcept
Estimates the number of distinct hashes from the minimum hash in each bucket.
__host__ __device__ double cardinality(double bucket_count, double empty_count, double sum_restored) noexcept
Public DDL cardinality estimate.