Skip to content

Commit 5b8d055

Browse files
Add rehash for multiset and multimap (#634)
This PR adds `rehash` APIs for multiset and multimap. It also adds `size` to multimap. --------- Co-authored-by: Daniel Jünger <[email protected]>
1 parent 93d6172 commit 5b8d055

File tree

4 files changed

+247
-0
lines changed

4 files changed

+247
-0
lines changed

include/cuco/detail/static_multimap/static_multimap.inl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,79 @@ static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Stora
398398
return impl_->count(first, last, ref(op::count), stream);
399399
}
400400

401+
template <class Key,
402+
class T,
403+
class Extent,
404+
cuda::thread_scope Scope,
405+
class KeyEqual,
406+
class ProbingScheme,
407+
class Allocator,
408+
class Storage>
409+
void static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::rehash(
410+
cuda::stream_ref stream)
411+
{
412+
impl_->rehash(*this, stream);
413+
}
414+
415+
template <class Key,
416+
class T,
417+
class Extent,
418+
cuda::thread_scope Scope,
419+
class KeyEqual,
420+
class ProbingScheme,
421+
class Allocator,
422+
class Storage>
423+
void static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::rehash(
424+
size_type capacity, cuda::stream_ref stream)
425+
{
426+
auto const extent = make_bucket_extent<static_multimap>(capacity);
427+
impl_->rehash(extent, *this, stream);
428+
}
429+
430+
template <class Key,
431+
class T,
432+
class Extent,
433+
cuda::thread_scope Scope,
434+
class KeyEqual,
435+
class ProbingScheme,
436+
class Allocator,
437+
class Storage>
438+
void static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::
439+
rehash_async(cuda::stream_ref stream)
440+
{
441+
impl_->rehash_async(*this, stream);
442+
}
443+
444+
template <class Key,
445+
class T,
446+
class Extent,
447+
cuda::thread_scope Scope,
448+
class KeyEqual,
449+
class ProbingScheme,
450+
class Allocator,
451+
class Storage>
452+
void static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::
453+
rehash_async(size_type capacity, cuda::stream_ref stream)
454+
{
455+
auto const extent = make_bucket_extent<static_multimap>(capacity);
456+
impl_->rehash_async(extent, *this, stream);
457+
}
458+
459+
template <class Key,
460+
class T,
461+
class Extent,
462+
cuda::thread_scope Scope,
463+
class KeyEqual,
464+
class ProbingScheme,
465+
class Allocator,
466+
class Storage>
467+
static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::size_type
468+
static_multimap<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::size(
469+
cuda::stream_ref stream) const
470+
{
471+
return impl_->size(stream);
472+
}
473+
401474
template <class Key,
402475
class T,
403476
class Extent,

include/cuco/detail/static_multiset/static_multiset.inl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,60 @@ static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>
474474
return impl_->retrieve_outer(first, last, output_probe, output_match, probe_ref, stream);
475475
}
476476

477+
template <class Key,
478+
class Extent,
479+
cuda::thread_scope Scope,
480+
class KeyEqual,
481+
class ProbingScheme,
482+
class Allocator,
483+
class Storage>
484+
void static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::rehash(
485+
cuda::stream_ref stream)
486+
{
487+
impl_->rehash(*this, stream);
488+
}
489+
490+
template <class Key,
491+
class Extent,
492+
cuda::thread_scope Scope,
493+
class KeyEqual,
494+
class ProbingScheme,
495+
class Allocator,
496+
class Storage>
497+
void static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::rehash(
498+
size_type capacity, cuda::stream_ref stream)
499+
{
500+
auto const extent = make_bucket_extent<static_multiset>(capacity);
501+
impl_->rehash(extent, *this, stream);
502+
}
503+
504+
template <class Key,
505+
class Extent,
506+
cuda::thread_scope Scope,
507+
class KeyEqual,
508+
class ProbingScheme,
509+
class Allocator,
510+
class Storage>
511+
void static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::rehash_async(
512+
cuda::stream_ref stream)
513+
{
514+
impl_->rehash_async(*this, stream);
515+
}
516+
517+
template <class Key,
518+
class Extent,
519+
cuda::thread_scope Scope,
520+
class KeyEqual,
521+
class ProbingScheme,
522+
class Allocator,
523+
class Storage>
524+
void static_multiset<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::rehash_async(
525+
size_type capacity, cuda::stream_ref stream)
526+
{
527+
auto const extent = make_bucket_extent<static_multiset>(capacity);
528+
impl_->rehash_async(extent, *this, stream);
529+
}
530+
477531
template <class Key,
478532
class Extent,
479533
cuda::thread_scope Scope,

include/cuco/static_multimap.cuh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,71 @@ class static_multimap {
602602
template <typename InputIt>
603603
size_type count(InputIt first, InputIt last, cuda::stream_ref stream = {}) const;
604604

605+
/**
606+
* @brief Regenerates the container.
607+
*
608+
* @note This function synchronizes the given stream. For asynchronous execution use
609+
* `rehash_async`.
610+
*
611+
* @param stream CUDA stream used for this operation
612+
*/
613+
void rehash(cuda::stream_ref stream = {});
614+
615+
/**
616+
* @brief Reserves at least the specified number of slots and regenerates the container
617+
*
618+
* @note Changes the number of slots to a value that is not less than `capacity`, then
619+
* rehashes the container, i.e. puts the elements into appropriate slots considering
620+
* that the total number of slots has changed.
621+
*
622+
* @note This function synchronizes the given stream. For asynchronous execution use
623+
* `rehash_async`.
624+
*
625+
* @note Behavior is undefined if the desired `capacity` is insufficient to store all of the
626+
* contained elements.
627+
*
628+
* @note This function is not available if the conatiner's `extent_type` is static.
629+
*
630+
* @param capacity New capacity of the container
631+
* @param stream CUDA stream used for this operation
632+
*/
633+
void rehash(size_type capacity, cuda::stream_ref stream = {});
634+
635+
/**
636+
* @brief Asynchronously regenerates the container.
637+
*
638+
* @param stream CUDA stream used for this operation
639+
*/
640+
void rehash_async(cuda::stream_ref stream = {});
641+
642+
/**
643+
* @brief Asynchronously reserves at least the specified number of slots and regenerates the
644+
* container
645+
*
646+
* @note Changes the number of slots to a value that is not less than `capacity`, then
647+
* rehashes the container, i.e. puts the elements into appropriate slots considering
648+
* that the total number of slots has changed.
649+
*
650+
* @note Behavior is undefined if the desired `capacity` is insufficient to store all of the
651+
* contained elements.
652+
*
653+
* @note This function is not available if the conatiner's `extent_type` is static.
654+
*
655+
* @param capacity New capacity of the container
656+
* @param stream CUDA stream used for this operation
657+
*/
658+
void rehash_async(size_type capacity, cuda::stream_ref stream = {});
659+
660+
/**
661+
* @brief Gets the number of elements in the container.
662+
*
663+
* @note This function synchronizes the given stream.
664+
*
665+
* @param stream CUDA stream used to get the number of inserted elements
666+
* @return The number of elements in the container
667+
*/
668+
[[nodiscard]] size_type size(cuda::stream_ref stream = {}) const;
669+
605670
/**
606671
* @brief Gets the maximum number of elements the hash map can hold.
607672
*

include/cuco/static_multiset.cuh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,61 @@ class static_multiset {
738738
OutputMatchIt output_match,
739739
cuda::stream_ref stream = {}) const;
740740

741+
/**
742+
* @brief Regenerates the container.
743+
*
744+
* @note This function synchronizes the given stream. For asynchronous execution use
745+
* `rehash_async`.
746+
*
747+
* @param stream CUDA stream used for this operation
748+
*/
749+
void rehash(cuda::stream_ref stream = {});
750+
751+
/**
752+
* @brief Reserves at least the specified number of slots and regenerates the container
753+
*
754+
* @note Changes the number of slots to a value that is not less than `capacity`, then
755+
* rehashes the container, i.e. puts the elements into appropriate slots considering
756+
* that the total number of slots has changed.
757+
*
758+
* @note This function synchronizes the given stream. For asynchronous execution use
759+
* `rehash_async`.
760+
*
761+
* @note Behavior is undefined if the desired `capacity` is insufficient to store all of the
762+
* contained elements.
763+
*
764+
* @note This function is not available if the conatiner's `extent_type` is static.
765+
*
766+
* @param capacity New capacity of the container
767+
* @param stream CUDA stream used for this operation
768+
*/
769+
void rehash(size_type capacity, cuda::stream_ref stream = {});
770+
771+
/**
772+
* @brief Asynchronously regenerates the container.
773+
*
774+
* @param stream CUDA stream used for this operation
775+
*/
776+
void rehash_async(cuda::stream_ref stream = {});
777+
778+
/**
779+
* @brief Asynchronously reserves at least the specified number of slots and regenerates the
780+
* container
781+
*
782+
* @note Changes the number of slots to a value that is not less than `capacity`, then
783+
* rehashes the container, i.e. puts the elements into appropriate slots considering
784+
* that the total number of slots has changed.
785+
*
786+
* @note Behavior is undefined if the desired `capacity` is insufficient to store all of the
787+
* contained elements.
788+
*
789+
* @note This function is not available if the conatiner's `extent_type` is static.
790+
*
791+
* @param capacity New capacity of the container
792+
* @param stream CUDA stream used for this operation
793+
*/
794+
void rehash_async(size_type capacity, cuda::stream_ref stream = {});
795+
741796
/**
742797
* @brief Gets the number of elements in the container.
743798
*

0 commit comments

Comments
 (0)