Skip to content

Commit 3f68e2e

Browse files
committed
Move HLL strong types to HLL header
1 parent c7b9bb3 commit 3f68e2e

File tree

4 files changed

+47
-43
lines changed

4 files changed

+47
-43
lines changed

include/cuco/detail/hyperloglog/hyperloglog_impl.cuh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include <cuco/detail/error.hpp>
2020
#include <cuco/detail/hyperloglog/finalizer.cuh>
2121
#include <cuco/detail/hyperloglog/kernels.cuh>
22+
#include <cuco/detail/utility/strong_type.cuh>
2223
#include <cuco/detail/utils.hpp>
2324
#include <cuco/hash_functions.cuh>
24-
#include <cuco/types.cuh>
2525
#include <cuco/utility/cuda_thread_scope.cuh>
2626
#include <cuco/utility/traits.hpp>
2727

@@ -42,6 +42,9 @@
4242
#include <vector>
4343

4444
namespace cuco::detail {
45+
CUCO_DEFINE_STRONG_TYPE(sketch_size_kb, double);
46+
CUCO_DEFINE_STRONG_TYPE(standard_deviation, double);
47+
CUCO_DEFINE_STRONG_TYPE(precision, int32_t);
4548

4649
/**
4750
* @brief A GPU-accelerated utility for approximating the number of distinct items in a multiset.
@@ -84,9 +87,9 @@ class hyperloglog_impl {
8487
__host__ __device__ constexpr hyperloglog_impl(cuda::std::span<cuda::std::byte> sketch_span,
8588
Hash const& hash)
8689
: hash_{hash},
87-
precision_{cuda::std::countr_zero(
88-
sketch_bytes(cuco::sketch_size_kb(static_cast<double>(sketch_span.size() / 1024.0))) /
89-
sizeof(register_type))},
90+
precision_{cuda::std::countr_zero(sketch_bytes(cuco::detail::sketch_size_kb(
91+
static_cast<double>(sketch_span.size() / 1024.0))) /
92+
sizeof(register_type))},
9093
sketch_{reinterpret_cast<register_type*>(sketch_span.data()),
9194
this->sketch_bytes() / sizeof(register_type)}
9295
{
@@ -520,7 +523,7 @@ class hyperloglog_impl {
520523
* @return The number of bytes required for the sketch
521524
*/
522525
[[nodiscard]] __host__ __device__ static constexpr cuda::std::size_t sketch_bytes(
523-
cuco::sketch_size_kb sketch_size_kb) noexcept
526+
cuco::detail::sketch_size_kb sketch_size_kb) noexcept
524527
{
525528
// minimum precision is 4 or 64 bytes
526529
return cuda::std::max(
@@ -536,7 +539,7 @@ class hyperloglog_impl {
536539
* @return The number of bytes required for the sketch
537540
*/
538541
[[nodiscard]] __host__ __device__ static constexpr cuda::std::size_t sketch_bytes(
539-
cuco::standard_deviation standard_deviation) noexcept
542+
cuco::detail::standard_deviation standard_deviation) noexcept
540543
{
541544
// implementation taken from
542545
// https://github.com/apache/spark/blob/6a27789ad7d59cd133653a49be0bb49729542abe/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/HyperLogLogPlusPlusHelper.scala#L43
@@ -561,7 +564,7 @@ class hyperloglog_impl {
561564
* @return The number of bytes required for the sketch
562565
*/
563566
[[nodiscard]] __host__ __device__ static constexpr cuda::std::size_t sketch_bytes(
564-
cuco::precision precision) noexcept
567+
cuco::detail::precision precision) noexcept
565568
{
566569
// minimum precision is 4 or 64 bytes
567570
auto const clamped_precision =

include/cuco/hyperloglog.cuh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <cuco/detail/storage/storage_base.cuh>
1919
#include <cuco/hash_functions.cuh>
2020
#include <cuco/hyperloglog_ref.cuh>
21-
#include <cuco/types.cuh>
2221
#include <cuco/utility/allocator.hpp>
2322
#include <cuco/utility/cuda_thread_scope.cuh>
2423

include/cuco/hyperloglog_ref.cuh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,50 @@
1717

1818
#include <cuco/detail/hyperloglog/hyperloglog_impl.cuh>
1919
#include <cuco/hash_functions.cuh>
20-
#include <cuco/types.cuh>
2120
#include <cuco/utility/cuda_thread_scope.cuh>
2221

2322
#include <cuda/std/cstddef>
2423
#include <cuda/stream_ref>
2524

2625
#include <cooperative_groups.h>
2726

27+
namespace cuco {
28+
/**
29+
* @brief A strong type wrapper for specifying the upper-bound sketch size of
30+
* `cuco::hyperloglog(_ref)` in KB.
31+
*
32+
* @note Underlying type is `double`. Values can also be specified as literals, e.g., 64.3_KB.
33+
*/
34+
using sketch_size_kb = detail::sketch_size_kb;
35+
36+
/**
37+
* @brief A strong type wrapper for specifying the desired standard deviation for the cardinality
38+
* estimate of `cuco::hyperloglog(_ref)`.
39+
*
40+
* @note Underlying type is `double`.
41+
*/
42+
using standard_deviation = detail::standard_deviation;
43+
44+
/**
45+
* @brief A strong type wrapper for specifying the HyperLogLog precision parameter of
46+
* `cuco::hyperloglog(_ref)`.
47+
*
48+
* @note Underlying type is `int32_t`. Precision `p` determines the number of registers as `2^p`.
49+
* Valid range is typically [4, 18].
50+
*/
51+
using precision = detail::precision;
52+
} // namespace cuco
53+
54+
__host__ __device__ constexpr cuco::sketch_size_kb operator""_KB(long double value)
55+
{
56+
return cuco::sketch_size_kb{static_cast<double>(value)};
57+
}
58+
59+
__host__ __device__ constexpr cuco::sketch_size_kb operator""_KB(unsigned long long int value)
60+
{
61+
return cuco::sketch_size_kb{static_cast<double>(value)};
62+
}
63+
2864
namespace cuco {
2965
/**
3066
* @brief A GPU-accelerated utility for approximating the number of distinct items in a multiset.

include/cuco/types.cuh

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,4 @@ CUCO_DEFINE_TEMPLATE_STRONG_TYPE(empty_value);
4444
*/
4545
CUCO_DEFINE_TEMPLATE_STRONG_TYPE(erased_key);
4646

47-
/**
48-
* @brief A strong type wrapper `cuco::sketch_size_kb` for specifying the upper-bound sketch size of
49-
* `cuco::hyperloglog(_ref)` in KB.
50-
*
51-
* @note Values can also be specified as literals, e.g., 64.3_KB.
52-
*/
53-
CUCO_DEFINE_STRONG_TYPE(sketch_size_kb, double);
54-
55-
/**
56-
* @brief A strong type wrapper `cuco::standard_deviation` for specifying the desired standard
57-
* deviation for the cardinality estimate of `cuco::hyperloglog(_ref)`.
58-
*/
59-
CUCO_DEFINE_STRONG_TYPE(standard_deviation, double);
60-
61-
/**
62-
* @brief A strong type wrapper `cuco::precision` for specifying the HyperLogLog precision
63-
* parameter of `cuco::hyperloglog(_ref)`.
64-
*
65-
* @note Precision `p` determines the number of registers as `2^p`. Valid range is typically [4,
66-
* 18].
67-
*/
68-
CUCO_DEFINE_STRONG_TYPE(precision, int32_t);
69-
7047
} // namespace cuco
71-
72-
// User-defined literal operators for `cuco::sketch_size_KB`
73-
__host__ __device__ constexpr cuco::sketch_size_kb operator""_KB(long double value)
74-
{
75-
return cuco::sketch_size_kb{static_cast<double>(value)};
76-
}
77-
78-
__host__ __device__ constexpr cuco::sketch_size_kb operator""_KB(unsigned long long int value)
79-
{
80-
return cuco::sketch_size_kb{static_cast<double>(value)};
81-
}

0 commit comments

Comments
 (0)