Skip to content

Commit e445e99

Browse files
authored
Better tests for Bloom filter operations that allow varying CG sizes (#683)
Closes #676
1 parent a5c3861 commit e445e99

File tree

5 files changed

+128
-7
lines changed

5 files changed

+128
-7
lines changed

include/cuco/detail/bloom_filter/bloom_filter_impl.cuh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,12 @@ class bloom_filter_impl {
271271
auto const num_keys = cuco::detail::distance(first, last);
272272
if (num_keys == 0) { return; }
273273

274-
auto constexpr cg_size = add_optimal_cg_size();
275274
auto constexpr block_size = cuco::detail::default_block_size();
276275
void const* kernel = reinterpret_cast<void const*>(
277-
detail::bloom_filter_ns::add<cg_size, block_size, InputIt, bloom_filter_impl>);
276+
detail::bloom_filter_ns::add<block_size, InputIt, bloom_filter_impl>);
278277
auto const grid_size = cuco::detail::max_occupancy_grid_size(block_size, kernel);
279278

280-
detail::bloom_filter_ns::add<cg_size, block_size>
279+
detail::bloom_filter_ns::add<block_size>
281280
<<<grid_size, block_size, 0, stream.get()>>>(first, num_keys, *this);
282281
}
283282
}

include/cuco/detail/bloom_filter/kernels.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace cuco::detail::bloom_filter_ns {
2626

2727
CUCO_SUPPRESS_KERNEL_WARNINGS
2828

29-
template <int32_t CGSize, int32_t BlockSize, class InputIt, class Ref>
29+
template <int32_t BlockSize, class InputIt, class Ref>
3030
CUCO_KERNEL __launch_bounds__(BlockSize) void add(InputIt first,
3131
cuco::detail::index_type n,
3232
Ref ref)

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ ConfigureTest(HYPERLOGLOG_TEST
144144
ConfigureTest(BLOOM_FILTER_TEST
145145
bloom_filter/unique_sequence_test.cu
146146
bloom_filter/arrow_policy_test.cu
147-
)
147+
bloom_filter/variable_cg_test.cu)

tests/bloom_filter/unique_sequence_test.cu

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <catch2/catch_template_test_macros.hpp>
2828
#include <catch2/generators/catch_generators.hpp>
2929

30+
#include <exception>
31+
3032
using size_type = int32_t;
3133

3234
template <typename Filter>
@@ -96,8 +98,14 @@ TEMPLATE_TEST_CASE_SIG(
9698
cuco::bloom_filter<Key, cuco::extent<size_t>, cuda::thread_scope_device, Policy>;
9799
constexpr size_type num_keys{400};
98100

99-
uint32_t pattern_bits =
100-
GENERATE(Policy::words_per_block, Policy::words_per_block + 1, Policy::words_per_block + 2);
101+
uint32_t pattern_bits = Policy::words_per_block + GENERATE(0, 1, 2, 3, 4);
102+
103+
// some parameter combinations might be invalid so we skip them
104+
try {
105+
[[maybe_unused]] auto policy = Policy{pattern_bits};
106+
} catch (std::exception const& e) {
107+
SKIP(e.what());
108+
}
101109

102110
auto filter = filter_type{1000, {}, {pattern_bits}};
103111

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2025, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <test_utils.hpp>
18+
19+
#include <cuco/bloom_filter.cuh>
20+
21+
#include <cuda/functional>
22+
#include <thrust/device_vector.h>
23+
#include <thrust/execution_policy.h>
24+
#include <thrust/fill.h>
25+
#include <thrust/iterator/constant_iterator.h>
26+
#include <thrust/iterator/counting_iterator.h>
27+
#include <thrust/sequence.h>
28+
29+
#include <catch2/catch_template_test_macros.hpp>
30+
#include <catch2/generators/catch_generators.hpp>
31+
32+
#include <cstdint>
33+
#include <exception>
34+
35+
using size_type = int32_t;
36+
37+
template <int32_t AddCGSize, int32_t ContainsCGSize, typename Filter>
38+
void test_variable_cg_size(Filter& filter, size_type num_keys)
39+
{
40+
constexpr int32_t block_size = 128;
41+
constexpr int32_t grid_size = 128;
42+
43+
using Key = typename Filter::key_type;
44+
45+
auto ref = filter.ref();
46+
47+
// Generate keys
48+
thrust::device_vector<Key> keys(num_keys);
49+
thrust::sequence(thrust::device, keys.begin(), keys.end());
50+
51+
thrust::device_vector<bool> contained(num_keys, false);
52+
53+
auto const always_true = thrust::constant_iterator<bool>{true};
54+
55+
SECTION("Check if fallback kernels work for varying combinations of CG sizes.")
56+
{
57+
cuco::detail::bloom_filter_ns::add_if_n<AddCGSize, block_size>
58+
<<<grid_size, block_size>>>(keys.begin(), num_keys, always_true, cuda::std::identity{}, ref);
59+
cuco::detail::bloom_filter_ns::contains_if_n<ContainsCGSize, block_size>
60+
<<<grid_size, block_size>>>(
61+
keys.begin(), num_keys, always_true, cuda::std::identity{}, contained.begin(), ref);
62+
REQUIRE(cuco::test::all_of(contained.begin(), contained.end(), cuda::std::identity{}));
63+
}
64+
65+
filter.clear();
66+
thrust::fill(contained.begin(), contained.end(), false); // reset output vector
67+
68+
SECTION("Check if adaptive add kernel works with fallback contains kernel.")
69+
{
70+
cuco::detail::bloom_filter_ns::add<block_size>
71+
<<<grid_size, block_size>>>(keys.begin(), num_keys, ref);
72+
cuco::detail::bloom_filter_ns::contains_if_n<ContainsCGSize, block_size>
73+
<<<grid_size, block_size>>>(
74+
keys.begin(), num_keys, always_true, cuda::std::identity{}, contained.begin(), ref);
75+
REQUIRE(cuco::test::all_of(contained.begin(), contained.end(), cuda::std::identity{}));
76+
}
77+
78+
// TODO adaptive vs. adaptive and fallback add vs. adaptive contains (requires #673)
79+
}
80+
81+
TEMPLATE_TEST_CASE_SIG(
82+
"bloom_filter variable CG size tests",
83+
"",
84+
((int32_t AddCGSize, int32_t ContainsCGSize, class Key, class Policy),
85+
AddCGSize,
86+
ContainsCGSize,
87+
Key,
88+
Policy),
89+
(1, 4, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint32_t, 1>),
90+
(1, 4, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint32_t, 8>),
91+
(1, 4, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint64_t, 1>),
92+
(1, 4, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint64_t, 8>),
93+
(4, 1, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint32_t, 1>),
94+
(4, 1, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint32_t, 8>),
95+
(4, 1, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint64_t, 1>),
96+
(4, 1, int32_t, cuco::default_filter_policy<cuco::xxhash_64<int32_t>, uint64_t, 8>))
97+
{
98+
using filter_type =
99+
cuco::bloom_filter<Key, cuco::extent<size_t>, cuda::thread_scope_device, Policy>;
100+
constexpr size_type num_keys{400};
101+
102+
uint32_t pattern_bits = Policy::words_per_block + GENERATE(0, 1, 2, 3, 4);
103+
104+
// some parameter combinations might be invalid so we skip them
105+
try {
106+
[[maybe_unused]] auto policy = Policy{pattern_bits};
107+
} catch (std::exception const& e) {
108+
SKIP(e.what());
109+
}
110+
111+
auto filter = filter_type{1000, {}, {pattern_bits}};
112+
113+
test_variable_cg_size<AddCGSize, ContainsCGSize>(filter, num_keys);
114+
}

0 commit comments

Comments
 (0)