Skip to content

Commit e01978b

Browse files
committed
doc improvements
1 parent 3906909 commit e01978b

File tree

5 files changed

+152
-88
lines changed

5 files changed

+152
-88
lines changed

benchmarks/hash_table/dynamic_map_bench.cu

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static void BM_dynamic_erase_none(::benchmark::State& state)
254254
state.SetBytesProcessed((sizeof(Key) + sizeof(Value)) * int64_t(state.iterations()) *
255255
int64_t(state.range(0)));
256256
}
257-
/*
257+
258258
BENCHMARK_TEMPLATE(BM_dynamic_insert, int32_t, int32_t, dist_type::UNIQUE)
259259
->Unit(benchmark::kMillisecond)
260260
->Apply(gen_final_size)
@@ -264,84 +264,8 @@ BENCHMARK_TEMPLATE(BM_dynamic_search_all, int32_t, int32_t, dist_type::UNIQUE)
264264
->Unit(benchmark::kMillisecond)
265265
->Apply(gen_final_size)
266266
->UseManualTime();
267-
*/
268-
BENCHMARK_TEMPLATE(BM_dynamic_erase_all, int32_t, int32_t, dist_type::UNIQUE)
269-
->Unit(benchmark::kMillisecond)
270-
->Apply(gen_final_size)
271-
->UseManualTime();
272-
/*
273-
BENCHMARK_TEMPLATE(BM_dynamic_insert, int32_t, int32_t, dist_type::UNIFORM)
274-
->Unit(benchmark::kMillisecond)
275-
->Apply(gen_final_size)
276-
->UseManualTime();
277-
278-
BENCHMARK_TEMPLATE(BM_dynamic_search_all, int32_t, int32_t, dist_type::UNIFORM)
279-
->Unit(benchmark::kMillisecond)
280-
->Apply(gen_final_size)
281-
->UseManualTime();
282-
283-
BENCHMARK_TEMPLATE(BM_dynamic_insert, int32_t, int32_t, dist_type::GAUSSIAN)
284-
->Unit(benchmark::kMillisecond)
285-
->Apply(gen_final_size)
286-
->UseManualTime();
287-
288-
BENCHMARK_TEMPLATE(BM_dynamic_search_all, int32_t, int32_t, dist_type::GAUSSIAN)
289-
->Unit(benchmark::kMillisecond)
290-
->Apply(gen_final_size)
291-
->UseManualTime();
292-
293-
BENCHMARK_TEMPLATE(BM_dynamic_erase_all, int32_t, int32_t, dist_type::GAUSSIAN)
294-
->Unit(benchmark::kMillisecond)
295-
->Apply(gen_final_size)
296-
->UseManualTime();
297-
298-
BENCHMARK_TEMPLATE(BM_dynamic_insert, int64_t, int64_t, dist_type::UNIQUE)
299-
->Unit(benchmark::kMillisecond)
300-
->Apply(gen_final_size)
301-
->UseManualTime();
302267

303-
BENCHMARK_TEMPLATE(BM_dynamic_search_all, int64_t, int64_t, dist_type::UNIQUE)
304-
->Unit(benchmark::kMillisecond)
305-
->Apply(gen_final_size)
306-
->UseManualTime();
307-
*/
308-
BENCHMARK_TEMPLATE(BM_dynamic_erase_none, int32_t, int32_t, dist_type::UNIQUE)
309-
->Unit(benchmark::kMillisecond)
310-
->Apply(gen_final_size)
311-
->UseManualTime();
312-
/*
313-
BENCHMARK_TEMPLATE(BM_dynamic_erase_none, int32_t, int32_t, dist_type::GAUSSIAN)
314-
->Unit(benchmark::kMillisecond)
315-
->Apply(gen_final_size)
316-
->UseManualTime();
317-
318-
BENCHMARK_TEMPLATE(BM_dynamic_search_none, int32_t, int32_t, dist_type::GAUSSIAN)
319-
->Unit(benchmark::kMillisecond)
320-
->Apply(gen_final_size)
321-
->UseManualTime();
322-
323-
BENCHMARK_TEMPLATE(BM_dynamic_erase_all, int64_t, int64_t, dist_type::UNIQUE)
324-
->Unit(benchmark::kMillisecond)
325-
->Apply(gen_final_size)
326-
->UseManualTime();
327-
328-
BENCHMARK_TEMPLATE(BM_dynamic_insert, int64_t, int64_t, dist_type::UNIFORM)
329-
->Unit(benchmark::kMillisecond)
330-
->Apply(gen_final_size)
331-
->UseManualTime();
332-
333-
BENCHMARK_TEMPLATE(BM_dynamic_search_all, int64_t, int64_t, dist_type::UNIFORM)
334-
->Unit(benchmark::kMillisecond)
335-
->Apply(gen_final_size)
336-
->UseManualTime();
337-
338-
BENCHMARK_TEMPLATE(BM_dynamic_insert, int64_t, int64_t, dist_type::GAUSSIAN)
339-
->Unit(benchmark::kMillisecond)
340-
->Apply(gen_final_size)
341-
->UseManualTime();
342-
343-
BENCHMARK_TEMPLATE(BM_dynamic_search_all, int64_t, int64_t, dist_type::GAUSSIAN)
268+
BENCHMARK_TEMPLATE(BM_dynamic_erase_all, int32_t, int32_t, dist_type::UNIQUE)
344269
->Unit(benchmark::kMillisecond)
345270
->Apply(gen_final_size)
346-
->UseManualTime();
347-
*/
271+
->UseManualTime();

include/cuco/detail/dynamic_map.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ void dynamic_map<Key, Value, Scope, Allocator>::erase(InputIt first,
203203
<<<grid_size, block_size, temp_storage_size>>>(
204204
first,
205205
first + num_keys,
206-
submap_views_.data().get(),
207206
submap_mutable_views_.data().get(),
208207
num_successes_,
209208
d_submap_num_successes_.data().get(),

include/cuco/detail/dynamic_map_kernels.cuh

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,40 @@ __global__ void insert(InputIt first,
179179
if (threadIdx.x == 0) { *num_successes += block_num_successes; }
180180
}
181181

182+
/**
183+
* @brief Erases the key/value pairs corresponding to all keys in the range `[first, last)`.
184+
*
185+
* If the key `*(first + i)` exists in the map, its slot is erased and made available for future
186+
insertions.
187+
* Else, no effect.
188+
* @tparam block_size The size of the thread block
189+
* @tparam pair_type Type of the pairs contained in the map
190+
* @tparam InputIt Device accessible input iterator whose `value_type` is
191+
* convertible to the map's `key_type`
192+
* @tparam mutableViewT Type of device view allowing modification of hash map storage
193+
* @tparam atomicT Type of atomic storage
194+
* @tparam Hash Unary callable type
195+
* @tparam KeyEqual Binary callable type
196+
* @param first Beginning of the sequence of keys
197+
* @param last End of the sequence of keys
198+
* @param submap_mutable_views Array of `static_map::mutable_device_view` objects used to
199+
* perform `erase` operations on each underlying `static_map`
200+
* @param num_successes The number of successfully erased key/value pairs
201+
* @param submap_num_successes The number of successfully erased key/value pairs
202+
* in each submap
203+
* @param num_submaps The number of submaps in the map
204+
* @param hash The unary function to apply to hash each key
205+
* @param key_equal The binary function to compare two keys for equality
206+
*/
182207
template <uint32_t block_size,
183208
typename pair_type,
184209
typename InputIt,
185-
typename viewT,
186210
typename mutableViewT,
187211
typename atomicT,
188212
typename Hash,
189213
typename KeyEqual>
190214
__global__ void erase(InputIt first,
191215
InputIt last,
192-
viewT* submap_views,
193216
mutableViewT* submap_mutable_views,
194217
atomicT* num_successes,
195218
atomicT** submap_num_successes,
@@ -245,18 +268,42 @@ __global__ void erase(InputIt first,
245268
}
246269
}
247270

271+
/**
272+
* @brief Erases the key/value pairs corresponding to all keys in the range `[first, last)`.
273+
*
274+
* If the key `*(first + i)` exists in the map, its slot is erased and made available for future
275+
insertions.
276+
* Else, no effect.
277+
* @tparam block_size The size of the thread block
278+
* @tparam tile_size The number of threads in the Cooperative Groups used to perform erase
279+
* @tparam pair_type Type of the pairs contained in the map
280+
* @tparam InputIt Device accessible input iterator whose `value_type` is
281+
* convertible to the map's `key_type`
282+
* @tparam mutableViewT Type of device view allowing modification of hash map storage
283+
* @tparam atomicT Type of atomic storage
284+
* @tparam Hash Unary callable type
285+
* @tparam KeyEqual Binary callable type
286+
* @param first Beginning of the sequence of keys
287+
* @param last End of the sequence of keys
288+
* @param submap_mutable_views Array of `static_map::mutable_device_view` objects used to
289+
* perform `erase` operations on each underlying `static_map`
290+
* @param num_successes The number of successfully erased key/value pairs
291+
* @param submap_num_successes The number of successfully erased key/value pairs
292+
* in each submap
293+
* @param num_submaps The number of submaps in the map
294+
* @param hash The unary function to apply to hash each key
295+
* @param key_equal The binary function to compare two keys for equality
296+
*/
248297
template <uint32_t block_size,
249298
uint32_t tile_size,
250299
typename pair_type,
251300
typename InputIt,
252-
typename viewT,
253301
typename mutableViewT,
254302
typename atomicT,
255303
typename Hash,
256304
typename KeyEqual>
257305
__global__ void erase(InputIt first,
258306
InputIt last,
259-
viewT* submap_views,
260307
mutableViewT* submap_mutable_views,
261308
atomicT* num_successes,
262309
atomicT** submap_num_successes,

include/cuco/detail/static_map_kernels.cuh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ __global__ void insert(
156156
if (threadIdx.x == 0) { *num_successes += block_num_successes; }
157157
}
158158

159+
/**
160+
* @brief Erases the key/value pairs corresponding to all keys in the range `[first, last)`.
161+
*
162+
* If the key `*(first + i)` exists in the map, its slot is erased and made available for future
163+
insertions.
164+
* Else, no effect.
165+
* @tparam block_size The size of the thread block
166+
* @tparam InputIt Device accessible input iterator whose `value_type` is
167+
* convertible to the map's `key_type`
168+
* @tparam atomicT Type of atomic storage
169+
* @tparam viewT Type of device view allowing access of hash map storage
170+
* @tparam Hash Unary callable type
171+
* @tparam KeyEqual Binary callable type
172+
* @param first Beginning of the sequence of keys
173+
* @param last End of the sequence of keys
174+
* @param num_successes The number of successfully erased key/value pairs
175+
* @param view Device view used to access the hash map's slot storage
176+
* @param hash The unary function to apply to hash each key
177+
* @param key_equal The binary function to compare two keys for equality
178+
*/
159179
template <std::size_t block_size,
160180
typename InputIt,
161181
typename atomicT,
@@ -185,6 +205,27 @@ __global__ void erase(
185205
}
186206
}
187207

208+
/**
209+
* @brief Erases the key/value pairs corresponding to all keys in the range `[first, last)`.
210+
*
211+
* If the key `*(first + i)` exists in the map, its slot is erased and made available for future
212+
insertions.
213+
* Else, no effect.
214+
* @tparam block_size The size of the thread block
215+
* @tparam tile_size The number of threads in the Cooperative Groups used to perform erase
216+
* @tparam InputIt Device accessible input iterator whose `value_type` is
217+
* convertible to the map's `key_type`
218+
* @tparam atomicT Type of atomic storage
219+
* @tparam viewT Type of device view allowing access of hash map storage
220+
* @tparam Hash Unary callable type
221+
* @tparam KeyEqual Binary callable type
222+
* @param first Beginning of the sequence of keys
223+
* @param last End of the sequence of keys
224+
* @param num_successes The number of successfully erased key/value pairs
225+
* @param view Device view used to access the hash map's slot storage
226+
* @param hash The unary function to apply to hash each key
227+
* @param key_equal The binary function to compare two keys for equality
228+
*/
188229
template <std::size_t block_size,
189230
uint32_t tile_size,
190231
typename InputIt,

include/cuco/dynamic_map.cuh

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,31 @@ class dynamic_map {
137137
sentinel::empty_key<Key> empty_key_sentinel,
138138
sentinel::empty_value<Value> empty_value_sentinel,
139139
Allocator const& alloc = Allocator{});
140-
140+
141+
/**
142+
* @brief Construct a dynamically-sized map with erase capability.
143+
*
144+
* The capacity of the map will automatically increase as the user adds key/value pairs using
145+
* `insert`.
146+
*
147+
* Capacity increases by a factor of growth_factor each time the size of the map exceeds a
148+
* threshold occupancy. The performance of `find` and `contains` decreases somewhat each time the
149+
* map's capacity grows.
150+
*
151+
* The `empty_key_sentinel` and `empty_value_sentinel` values are reserved and
152+
* undefined behavior results from attempting to insert any key/value pair
153+
* that contains either.
154+
*
155+
* @param initial_capacity The initial number of slots in the map
156+
* @param growth_factor The factor by which the capacity increases when resizing
157+
* @param empty_key_sentinel The reserved key value for empty slots
158+
* @param empty_value_sentinel The reserved mapped value for empty slots
159+
* @param erased_key_sentinel The reserved key value for erased slots
160+
* @param alloc Allocator used to allocate submap device storage
161+
*
162+
* @throw std::runtime error if the empty key sentinel and erased key sentinel
163+
* are the same value
164+
*/
141165
dynamic_map(std::size_t initial_capacity,
142166
sentinel::empty_key<Key> empty_key_sentinel,
143167
sentinel::empty_value<Value> empty_value_sentinel,
@@ -178,7 +202,36 @@ class dynamic_map {
178202
typename Hash = cuco::detail::MurmurHash3_32<key_type>,
179203
typename KeyEqual = thrust::equal_to<key_type>>
180204
void insert(InputIt first, InputIt last, Hash hash = Hash{}, KeyEqual key_equal = KeyEqual{});
181-
205+
206+
/**
207+
* @brief Erases keys in the range `[first, last)`.
208+
*
209+
* For each key `k` in `[first, last)`, if `contains(k) == true), removes `k` and it's
210+
* associated value from the map. Else, no effect.
211+
*
212+
* Side-effects:
213+
* - `contains(k) == false`
214+
* - `find(k) == end()`
215+
* - `insert({k,v}) == true`
216+
* - `get_size()` is reduced by the total number of erased keys
217+
*
218+
* This function synchronizes `stream`.
219+
*
220+
* Keep in mind that `erase` does not cause the map to shrink its memory allocation.
221+
*
222+
* @tparam InputIt Device accessible input iterator whose `value_type` is
223+
* convertible to the map's `value_type`
224+
* @tparam Hash Unary callable type
225+
* @tparam KeyEqual Binary callable type
226+
* @param first Beginning of the sequence of keys
227+
* @param last End of the sequence of keys
228+
* @param hash The unary function to apply to hash each key
229+
* @param key_equal The binary function to compare two keys for equality
230+
* @param stream Stream used for executing the kernels
231+
*
232+
* @throw std::runtime_error if a unique erased key sentinel value was not
233+
* provided at construction
234+
*/
182235
template <typename InputIt,
183236
typename Hash = cuco::detail::MurmurHash3_32<key_type>,
184237
typename KeyEqual = thrust::equal_to<key_type>>
@@ -263,7 +316,7 @@ class dynamic_map {
263316
private:
264317
key_type empty_key_sentinel_{}; ///< Key value that represents an empty slot
265318
mapped_type empty_value_sentinel_{}; ///< Initial value of empty slot
266-
key_type erased_key_sentinel_{};
319+
key_type erased_key_sentinel_{}; ///< Key value that represents an erased slot
267320

268321
// TODO: initialize this
269322
std::size_t size_{}; ///< Number of keys in the map
@@ -278,7 +331,7 @@ class dynamic_map {
278331
std::size_t min_insert_size_{}; ///< min remaining capacity of submap for insert
279332
atomic_ctr_type* num_successes_; ///< number of successfully inserted keys on insert
280333
std::vector<atomic_ctr_type*> submap_num_successes_; ///< number of succesfully erased keys for each submap
281-
thrust::device_vector<atomic_ctr_type*> d_submap_num_successes_;
334+
thrust::device_vector<atomic_ctr_type*> d_submap_num_successes_; ///< device-side number of successfully erased keys for each submap
282335
Allocator alloc_{}; ///< Allocator passed to submaps to allocate their device storage
283336
counter_allocator_type counter_allocator_{}; ///< Allocator used to allocate `num_successes_`
284337
};

0 commit comments

Comments
 (0)