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/hash_functions.cuh>
20+ #include < cuco/static_map.cuh>
21+
22+ #include < thrust/device_vector.h>
23+ #include < thrust/functional.h>
24+ #include < thrust/iterator/counting_iterator.h>
25+ #include < thrust/iterator/transform_iterator.h>
26+
27+ #include < catch2/catch_template_test_macros.hpp>
28+
29+ using size_type = std::size_t ;
30+
31+ template <typename Key, typename Hash>
32+ void test_hash_function ()
33+ {
34+ using Value = int64_t ;
35+
36+ constexpr size_type num_keys{400 };
37+
38+ auto map = cuco::static_map<Key,
39+ Value,
40+ cuco::extent<size_type>,
41+ cuda::thread_scope_device,
42+ thrust::equal_to<Key>,
43+ cuco::linear_probing<1 , Hash>,
44+ cuco::cuda_allocator<std::byte>,
45+ cuco::storage<2 >>{
46+ num_keys, cuco::empty_key<Key>{-1 }, cuco::empty_value<Value>{-1 }};
47+
48+ auto keys_begin = thrust::counting_iterator<Key>(1 );
49+
50+ auto pairs_begin = thrust::make_transform_iterator (
51+ keys_begin, cuda::proclaim_return_type<cuco::pair<Key, Value>>([] __device__ (auto i) {
52+ return cuco::pair<Key, Value>(i, i);
53+ }));
54+
55+ thrust::device_vector<bool > d_keys_exist (num_keys);
56+
57+ map.insert (pairs_begin, pairs_begin + num_keys);
58+
59+ REQUIRE (map.size () == num_keys);
60+
61+ map.contains (keys_begin, keys_begin + num_keys, d_keys_exist.begin ());
62+
63+ REQUIRE (cuco::test::all_of (d_keys_exist.begin (), d_keys_exist.end (), thrust::identity{}));
64+ }
65+
66+ TEMPLATE_TEST_CASE_SIG (" static_map hash tests" , " " , ((typename Key)), (int32_t ), (int64_t ))
67+ {
68+ test_hash_function<Key, cuco::murmurhash3_32<Key>>();
69+ test_hash_function<Key, cuco::murmurhash3_x64_128<Key>>();
70+ test_hash_function<Key, cuco::xxhash_32<Key>>();
71+ test_hash_function<Key, cuco::xxhash_64<Key>>();
72+ }
0 commit comments