1+ /*
2+ * Copyright (c) 2024, 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/detail/utility/cuda.hpp>
20+ #include < cuco/extent.cuh>
21+ #include < cuco/hash_functions.cuh>
22+ #include < cuco/probing_scheme.cuh>
23+
24+ #include < thrust/device_vector.h>
25+
26+ #include < cooperative_groups.h>
27+
28+ #include < catch2/catch_template_test_macros.hpp>
29+
30+ #include < cstddef>
31+ #include < cstdint>
32+
33+ template <class ProbingScheme , class Key , class Extent , class OutputIt >
34+ __global__ void generate_scalar_probing_sequence (Key key,
35+ Extent upper_bound,
36+ size_t seq_length,
37+ OutputIt out_seq)
38+ {
39+ auto constexpr cg_size = ProbingScheme::cg_size;
40+ static_assert (cg_size == 1 , " Invalid CG size" );
41+
42+ auto const tid = blockIdx .x * blockDim .x + threadIdx .x ;
43+ auto probing_scheme = ProbingScheme{};
44+
45+ if (tid == 0 ) {
46+ auto iter = probing_scheme (key, upper_bound);
47+
48+ for (size_t i = 0 ; i < seq_length; ++i) {
49+ out_seq[i] = *iter;
50+ iter++;
51+ }
52+ }
53+ }
54+
55+ template <class ProbingScheme , class Key , class Extent , class OutputIt >
56+ __global__ void generate_cg_probing_sequence (Key key,
57+ Extent upper_bound,
58+ size_t seq_length,
59+ OutputIt out_seq)
60+ {
61+ auto constexpr cg_size = ProbingScheme::cg_size;
62+
63+ auto const tid = blockIdx .x * blockDim .x + threadIdx .x ;
64+ auto probing_scheme = ProbingScheme{};
65+
66+ if (tid < cg_size) {
67+ auto const tile =
68+ cooperative_groups::tiled_partition<cg_size>(cooperative_groups::this_thread_block ());
69+
70+ auto iter = probing_scheme (tile, key, upper_bound);
71+
72+ for (size_t i = tile.thread_rank (); i < seq_length; ++i) {
73+ out_seq[i] = *iter;
74+ iter++;
75+ }
76+ }
77+ }
78+
79+ TEMPLATE_TEST_CASE_SIG (
80+ " probing_scheme scalar vs CGSize 1 test" ,
81+ " " ,
82+ ((typename Key, cuco::test::probe_sequence Probe, int32_t WindowSize), Key, Probe, WindowSize),
83+ (int32_t , cuco::test::probe_sequence::double_hashing, 1 ),
84+ (int32_t , cuco::test::probe_sequence::double_hashing, 2 ),
85+ (int64_t , cuco::test::probe_sequence::double_hashing, 1 ),
86+ (int64_t , cuco::test::probe_sequence::double_hashing, 2 ),
87+ (int32_t , cuco::test::probe_sequence::linear_probing, 1 ),
88+ (int32_t , cuco::test::probe_sequence::linear_probing, 2 ),
89+ (int64_t , cuco::test::probe_sequence::linear_probing, 1 ),
90+ (int64_t , cuco::test::probe_sequence::linear_probing, 2 ))
91+ {
92+ auto const upper_bound = cuco::make_window_extent<1 , WindowSize>(cuco::extent<std::size_t >{10 });
93+ constexpr size_t seq_length{8 };
94+ constexpr Key key{42 };
95+
96+ using probe = std::conditional_t <Probe == cuco::test::probe_sequence::linear_probing,
97+ cuco::linear_probing<1 , cuco::default_hash_function<Key>>,
98+ cuco::double_hashing<1 , cuco::default_hash_function<Key>>>;
99+
100+ thrust::device_vector<size_t > scalar_seq (seq_length);
101+ generate_scalar_probing_sequence<probe>
102+ <<<1 , 1 >>> (key, upper_bound, seq_length, scalar_seq.begin ());
103+ thrust::device_vector<size_t > cg_seq (seq_length);
104+ generate_cg_probing_sequence<probe><<<1 , 1 >>> (key, upper_bound, seq_length, cg_seq.begin ());
105+
106+ REQUIRE (cuco::test::equal (
107+ scalar_seq.begin (), scalar_seq.end (), cg_seq.begin (), thrust::equal_to<std::size_t >{}));
108+ }
0 commit comments