Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dynamic-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeepyjack committed Jul 11, 2023
2 parents b821589 + c00debe commit d2a2538
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 7 deletions.
31 changes: 29 additions & 2 deletions include/cuco/detail/open_addressing_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ class open_addressing_impl {
* window size and it's computed via `make_valid_extent` factory. Insert operations will not
* automatically grow the container. Attempting to insert more unique keys than the capacity of
* the container results in undefined behavior.
* @note The `empty_key_sentinel` is reserved and behavior is undefined when attempting to insert
* @note Any `*_sentinel`s are reserved and behavior is undefined when attempting to insert
* this sentinel value.
* @note If a non-default CUDA stream is provided, the caller is responsible for synchronizing the
* stream before the object is first used.
*
* @param capacity The requested lower-bound size
* @param empty_key_sentinel The reserved key value for empty slots
Expand All @@ -125,11 +127,35 @@ class open_addressing_impl {
Allocator const& alloc,
cuda_stream_ref stream) noexcept
: empty_key_sentinel_{empty_key_sentinel},
empty_slot_sentinel_{empty_slot_sentinel},
predicate_{pred},
probing_scheme_{probing_scheme},
storage_{make_valid_extent<cg_size, window_size>(capacity), alloc}
{
storage_.initialize(empty_slot_sentinel, stream);
this->clear_async(stream);
}

/**
* @brief Erases all elements from the container. After this call, `size()` returns zero.
* Invalidates any references, pointers, or iterators referring to contained elements.
*
* @param stream CUDA stream this operation is executed in
*/
void clear(cuda_stream_ref stream) noexcept
{
this->clear_async(stream);
stream.synchronize();
}

/**
* @brief Asynchronously erases all elements from the container. After this call, `size()` returns
* zero. Invalidates any references, pointers, or iterators referring to contained elements.
*
* @param stream CUDA stream this operation is executed in
*/
void clear_async(cuda_stream_ref stream) noexcept
{
storage_.initialize(empty_slot_sentinel_, stream);
}

/**
Expand Down Expand Up @@ -526,6 +552,7 @@ class open_addressing_impl {

protected:
key_type empty_key_sentinel_; ///< Key value that represents an empty slot
value_type empty_slot_sentinel_; ///< Slot value that represents an empty slot
key_equal predicate_; ///< Key equality binary predicate
probing_scheme_type probing_scheme_; ///< Probing scheme
storage_type storage_; ///< Slot window storage
Expand Down
28 changes: 28 additions & 0 deletions include/cuco/detail/static_map/static_map.inl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ constexpr static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator,
{
}

template <class Key,
class T,
class Extent,
cuda::thread_scope Scope,
class KeyEqual,
class ProbingScheme,
class Allocator,
class Storage>
void static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::clear(
cuda_stream_ref stream) noexcept
{
impl_->clear(stream);
}

template <class Key,
class T,
class Extent,
cuda::thread_scope Scope,
class KeyEqual,
class ProbingScheme,
class Allocator,
class Storage>
void static_map<Key, T, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::clear_async(
cuda_stream_ref stream) noexcept
{
impl_->clear_async(stream);
}

template <class Key,
class T,
class Extent,
Expand Down
26 changes: 26 additions & 0 deletions include/cuco/detail/static_set/static_set.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ constexpr static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Sto
{
}

template <class Key,
class Extent,
cuda::thread_scope Scope,
class KeyEqual,
class ProbingScheme,
class Allocator,
class Storage>
void static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::clear(
cuda_stream_ref stream) noexcept
{
impl_->clear(stream);
}

template <class Key,
class Extent,
cuda::thread_scope Scope,
class KeyEqual,
class ProbingScheme,
class Allocator,
class Storage>
void static_set<Key, Extent, Scope, KeyEqual, ProbingScheme, Allocator, Storage>::clear_async(
cuda_stream_ref stream) noexcept
{
impl_->clear_async(stream);
}

template <class Key,
class Extent,
cuda::thread_scope Scope,
Expand Down
20 changes: 19 additions & 1 deletion include/cuco/static_map.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ class static_map {
* automatically grow the map. Attempting to insert more unique keys than the capacity of the map
* results in undefined behavior.
*
* The `empty_key_sentinel` is reserved and behavior is undefined when attempting to insert
* @note Any `*_sentinel`s are reserved and behavior is undefined when attempting to insert
* this sentinel value.
* @note If a non-default CUDA stream is provided, the caller is responsible for synchronizing the
* stream before the object is first used.
*
* @param capacity The requested lower-bound map size
* @param empty_key_sentinel The reserved key value for empty slots
Expand All @@ -181,6 +183,22 @@ class static_map {
Allocator const& alloc = {},
cuda_stream_ref stream = {});

/**
* @brief Erases all elements from the container. After this call, `size()` returns zero.
* Invalidates any references, pointers, or iterators referring to contained elements.
*
* @param stream CUDA stream this operation is executed in
*/
void clear(cuda_stream_ref stream = {}) noexcept;

/**
* @brief Asynchronously erases all elements from the container. After this call, `size()` returns
* zero. Invalidates any references, pointers, or iterators referring to contained elements.
*
* @param stream CUDA stream this operation is executed in
*/
void clear_async(cuda_stream_ref stream = {}) noexcept;

/**
* @brief Inserts all keys in the range `[first, last)` and returns the number of successful
* insertions.
Expand Down
20 changes: 19 additions & 1 deletion include/cuco/static_set.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ class static_set {
* automatically grow the set. Attempting to insert more unique keys than the capacity of the map
* results in undefined behavior.
*
* The `empty_key_sentinel` is reserved and behavior is undefined when attempting to insert
* @note Any `*_sentinel`s are reserved and behavior is undefined when attempting to insert
* this sentinel value.
* @note If a non-default CUDA stream is provided, the caller is responsible for synchronizing the
* stream before the object is first used.
*
* @param capacity The requested lower-bound set size
* @param empty_key_sentinel The reserved key value for empty slots
Expand All @@ -155,6 +157,22 @@ class static_set {
Allocator const& alloc = {},
cuda_stream_ref stream = {});

/**
* @brief Erases all elements from the container. After this call, `size()` returns zero.
* Invalidates any references, pointers, or iterators referring to contained elements.
*
* @param stream CUDA stream this operation is executed in
*/
void clear(cuda_stream_ref stream = {}) noexcept;

/**
* @brief Asynchronously erases all elements from the container. After this call, `size()` returns
* zero. Invalidates any references, pointers, or iterators referring to contained elements.
*
* @param stream CUDA stream this operation is executed in
*/
void clear_async(cuda_stream_ref stream = {}) noexcept;

/**
* @brief Inserts all keys in the range `[first, last)` and returns the number of successful
* insertions.
Expand Down
8 changes: 5 additions & 3 deletions tests/static_set/size_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ TEST_CASE("Size computation", "")

auto const num_successes = set.insert(d_keys.begin(), d_keys.end());

auto const size = set.size();

REQUIRE(size == num_keys);
REQUIRE(set.size() == num_keys);
REQUIRE(num_successes == num_keys);

set.clear();

REQUIRE(set.size() == 0);
}

0 comments on commit d2a2538

Please sign in to comment.