Skip to content

Commit e3aec27

Browse files
authored
Add make_copy and initialize for multiset ref (#693)
This PR adds `make_copy` and `initialize` member functions for multiset ref.
1 parent dddc7a3 commit e3aec27

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

include/cuco/detail/static_multiset/static_multiset_ref.inl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,45 @@ static_multiset_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators..
305305
{},
306306
this->storage_ref()};
307307
}
308+
template <typename Key,
309+
cuda::thread_scope Scope,
310+
typename KeyEqual,
311+
typename ProbingScheme,
312+
typename StorageRef,
313+
typename... Operators>
314+
template <typename CG, cuda::thread_scope NewScope>
315+
__device__ constexpr auto
316+
static_multiset_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::make_copy(
317+
CG const& tile,
318+
bucket_type* const memory_to_use,
319+
cuda_thread_scope<NewScope> scope) const noexcept
320+
{
321+
auto const storage_ref = this->storage_ref().make_copy(tile, memory_to_use);
322+
return static_multiset_ref<Key,
323+
NewScope,
324+
KeyEqual,
325+
ProbingScheme,
326+
decltype(storage_ref),
327+
Operators...>{cuco::empty_key<Key>{this->empty_key_sentinel()},
328+
this->key_eq(),
329+
this->probing_scheme(),
330+
scope,
331+
storage_ref};
332+
}
333+
334+
template <typename Key,
335+
cuda::thread_scope Scope,
336+
typename KeyEqual,
337+
typename ProbingScheme,
338+
typename StorageRef,
339+
typename... Operators>
340+
template <typename CG>
341+
__device__ constexpr void
342+
static_multiset_ref<Key, Scope, KeyEqual, ProbingScheme, StorageRef, Operators...>::initialize(
343+
CG const& tile) noexcept
344+
{
345+
this->storage_ref().initialize(tile, this->empty_key_sentinel());
346+
}
308347

309348
namespace detail {
310349

include/cuco/static_multiset_ref.cuh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,43 @@ class static_multiset_ref
243243
template <typename NewHash>
244244
[[nodiscard]] __host__ __device__ constexpr auto rebind_hash_function(NewHash const& hash) const;
245245

246+
/**
247+
* @brief Makes a copy of the current device reference using non-owned memory
248+
*
249+
* This function is intended to be used to create shared memory copies of small static sets,
250+
* although global memory can be used as well.
251+
*
252+
* @note This function synchronizes the group `tile`.
253+
* @note By-default the thread scope of the copy will be the same as the scope of the parent ref.
254+
*
255+
* @tparam CG The type of the cooperative thread group
256+
* @tparam NewScope The thread scope of the newly created device ref
257+
*
258+
* @param tile The cooperative thread group used to copy the data structure
259+
* @param memory_to_use Array large enough to support `capacity` elements. Object does not take
260+
* the ownership of the memory
261+
* @param scope The thread scope of the newly created device ref
262+
*
263+
* @return Copy of the current device ref
264+
*/
265+
template <typename CG, cuda::thread_scope NewScope = thread_scope>
266+
[[nodiscard]] __device__ constexpr auto make_copy(
267+
CG const& tile,
268+
bucket_type* const memory_to_use,
269+
cuda_thread_scope<NewScope> scope = {}) const noexcept;
270+
271+
/**
272+
* @brief Initializes the set storage using the threads in the group `tile`.
273+
*
274+
* @note This function synchronizes the group `tile`.
275+
*
276+
* @tparam CG The type of the cooperative thread group
277+
*
278+
* @param tile The cooperative thread group used to initialize the set
279+
*/
280+
template <typename CG>
281+
__device__ constexpr void initialize(CG const& tile) noexcept;
282+
246283
private:
247284
impl_type impl_;
248285

0 commit comments

Comments
 (0)