@@ -87,16 +87,24 @@ static void BM_static_map_insert(::benchmark::State& state)
8787 }
8888
8989 thrust::device_vector<cuco::pair_type<Key, Value>> d_pairs (h_pairs);
90+ thrust::device_vector<Key> d_keys (h_keys);
9091
9192 for (auto _ : state) {
92- state.ResumeTiming ();
93- state.PauseTiming ();
94- map_type map{size, -1 , -1 };
95- state.ResumeTiming ();
93+ map_type map{size, cuco::sentinel::empty_key<Key>{-1 }, cuco::sentinel::empty_value<Value>{-1 }};
9694
95+ cudaEvent_t start, stop;
96+ cudaEventCreate (&start);
97+ cudaEventCreate (&stop);
98+
99+ cudaEventRecord (start);
97100 map.insert (d_pairs.begin (), d_pairs.end ());
101+ cudaEventRecord (stop);
102+ cudaEventSynchronize (stop);
98103
99- state.PauseTiming ();
104+ float ms;
105+ cudaEventElapsedTime (&ms, start, stop);
106+
107+ state.SetIterationTime (ms / 1000 );
100108 }
101109
102110 state.SetBytesProcessed ((sizeof (Key) + sizeof (Value)) * int64_t (state.iterations ()) *
@@ -112,7 +120,7 @@ static void BM_static_map_search_all(::benchmark::State& state)
112120 float occupancy = state.range (1 ) / float {100 };
113121 std::size_t size = num_keys / occupancy;
114122
115- map_type map{size, - 1 , - 1 };
123+ map_type map{size, cuco::sentinel::empty_key<Key>{- 1 }, cuco::sentinel::empty_value<Value>{- 1 } };
116124 auto view = map.get_device_mutable_view ();
117125
118126 std::vector<Key> h_keys (num_keys);
@@ -143,50 +151,62 @@ static void BM_static_map_search_all(::benchmark::State& state)
143151 int64_t (state.range (0 )));
144152}
145153
146- BENCHMARK_TEMPLATE (BM_static_map_insert, int32_t , int32_t , dist_type::UNIQUE)
147- ->Unit(benchmark::kMillisecond )
148- ->Apply(generate_size_and_occupancy);
154+ template <typename Key, typename Value, dist_type Dist>
155+ static void BM_static_map_erase_all (::benchmark::State& state)
156+ {
157+ using map_type = cuco::static_map<Key, Value>;
149158
150- BENCHMARK_TEMPLATE (BM_static_map_search_all, int32_t , int32_t , dist_type::UNIQUE)
151- ->Unit(benchmark:: kMillisecond )
152- ->Apply(generate_size_and_occupancy) ;
159+ std:: size_t num_keys = state. range ( 0 );
160+ float occupancy = state. range ( 1 ) / float { 100 };
161+ std:: size_t size = num_keys / occupancy ;
153162
154- BENCHMARK_TEMPLATE (BM_static_map_insert, int32_t , int32_t , dist_type::UNIFORM)
155- ->Unit(benchmark::kMillisecond )
156- ->Apply(generate_size_and_occupancy);
163+ // static map with erase support
164+ map_type map{size,
165+ cuco::sentinel::empty_key<Key>{-1 },
166+ cuco::sentinel::empty_value<Value>{-1 },
167+ cuco::sentinel::erased_key<Key>{-2 }};
168+ auto view = map.get_device_mutable_view ();
157169
158- BENCHMARK_TEMPLATE (BM_static_map_search_all, int32_t , int32_t , dist_type::UNIFORM)
159- ->Unit(benchmark::kMillisecond )
160- ->Apply(generate_size_and_occupancy);
170+ std::vector<Key> h_keys (num_keys);
171+ std::vector<Value> h_values (num_keys);
172+ std::vector<cuco::pair_type<Key, Value>> h_pairs (num_keys);
173+ std::vector<Value> h_results (num_keys);
161174
162- BENCHMARK_TEMPLATE (BM_static_map_insert, int32_t , int32_t , dist_type::GAUSSIAN)
163- ->Unit(benchmark::kMillisecond )
164- ->Apply(generate_size_and_occupancy);
175+ generate_keys<Dist, Key>(h_keys.begin (), h_keys.end ());
165176
166- BENCHMARK_TEMPLATE (BM_static_map_search_all, int32_t , int32_t , dist_type::GAUSSIAN)
167- ->Unit(benchmark::kMillisecond )
168- ->Apply(generate_size_and_occupancy);
177+ for (auto i = 0 ; i < num_keys; ++i) {
178+ Key key = h_keys[i];
179+ Value val = h_keys[i];
180+ h_pairs[i].first = key;
181+ h_pairs[i].second = val;
182+ }
169183
170- BENCHMARK_TEMPLATE (BM_static_map_insert, int64_t , int64_t , dist_type::UNIQUE)
171- ->Unit(benchmark:: kMillisecond )
172- ->Apply(generate_size_and_occupancy );
184+ thrust::device_vector<Key> d_keys (h_keys);
185+ thrust::device_vector< bool > d_results (num_keys);
186+ thrust::device_vector<cuco::pair_type<Key, Value>> d_pairs (h_pairs );
173187
174- BENCHMARK_TEMPLATE (BM_static_map_search_all, int64_t , int64_t , dist_type::UNIQUE)
175- ->Unit(benchmark::kMillisecond )
176- ->Apply(generate_size_and_occupancy);
188+ for (auto _ : state) {
189+ state.PauseTiming ();
190+ map.insert (d_pairs.begin (), d_pairs.end ());
191+ state.ResumeTiming ();
177192
178- BENCHMARK_TEMPLATE (BM_static_map_insert, int64_t , int64_t , dist_type::UNIFORM)
179- ->Unit(benchmark::kMillisecond )
180- ->Apply(generate_size_and_occupancy);
193+ map.erase (d_keys.begin (), d_keys.end ());
194+ }
181195
182- BENCHMARK_TEMPLATE (BM_static_map_search_all, int64_t , int64_t , dist_type::UNIFORM)
196+ state.SetBytesProcessed ((sizeof (Key) + sizeof (Value)) * int64_t (state.iterations ()) *
197+ int64_t (state.range (0 )));
198+ }
199+
200+ BENCHMARK_TEMPLATE (BM_static_map_insert, int32_t , int32_t , dist_type::UNIQUE)
183201 ->Unit(benchmark::kMillisecond )
184- ->Apply(generate_size_and_occupancy);
202+ ->Apply(generate_size_and_occupancy)
203+ ->UseManualTime();
185204
186- BENCHMARK_TEMPLATE (BM_static_map_insert, int64_t , int64_t , dist_type::GAUSSIAN )
205+ BENCHMARK_TEMPLATE (BM_static_map_erase_all, int32_t , int32_t , dist_type::UNIQUE )
187206 ->Unit(benchmark::kMillisecond )
188207 ->Apply(generate_size_and_occupancy);
189208
190- BENCHMARK_TEMPLATE (BM_static_map_search_all, int64_t , int64_t , dist_type::GAUSSIAN )
209+ BENCHMARK_TEMPLATE (BM_static_map_insert, int32_t , int32_t , dist_type::UNIQUE )
191210 ->Unit(benchmark::kMillisecond )
192- ->Apply(generate_size_and_occupancy);
211+ ->Apply(generate_size_and_occupancy)
212+ ->UseManualTime();
0 commit comments