-
Notifications
You must be signed in to change notification settings - Fork 106
Add static_multiset::for_each and its OA impl #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f14f521
4108a41
099503c
ca41a48
e7a8e03
7053703
18c5f60
22dab49
ee3dae7
bd309c1
6f6e5ff
7cd072c
d2ade79
6343ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -962,6 +962,164 @@ class open_addressing_ref_impl { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @brief Executes a callback on every element in the container with key equivalent to the probe | ||
| * key. | ||
| * | ||
| * @note Passes an un-incrementable input iterator to the element whose key is equivalent to | ||
| * `key` to the callback. | ||
| * | ||
| * @tparam ProbeKey Input type which is convertible to 'key_type' | ||
| * @tparam CallbackOp Unary callback functor or device lambda | ||
| * | ||
| * @param key The key to search for | ||
| * @param callback_op Function to call on every element found | ||
| */ | ||
| template <class ProbeKey, class CallbackOp> | ||
| __device__ void for_each(ProbeKey const& key, CallbackOp&& callback_op) const noexcept | ||
| { | ||
| static_assert(cg_size == 1, "Non-CG operation is incompatible with the current probing scheme"); | ||
| auto probing_iter = this->probing_scheme_(key, this->storage_ref_.window_extent()); | ||
|
|
||
| while (true) { | ||
| // TODO atomic_ref::load if insert operator is present | ||
| auto const window_slots = this->storage_ref_[*probing_iter]; | ||
|
|
||
| for (int32_t i = 0; i < window_size; ++i) { | ||
| switch ( | ||
| this->predicate_.operator()<is_insert::NO>(key, this->extract_key(window_slots[i]))) { | ||
| case detail::equal_result::EMPTY: { | ||
| return; | ||
| } | ||
| case detail::equal_result::EQUAL: { | ||
| callback_op(const_iterator{&(*(this->storage_ref_.data() + *probing_iter))[i]}); | ||
| continue; | ||
| } | ||
| default: continue; | ||
| } | ||
| } | ||
| ++probing_iter; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @brief Executes a callback on every element in the container with key equivalent to the probe | ||
| * key. | ||
| * | ||
| * @note Passes an un-incrementable input iterator to the element whose key is equivalent to | ||
| * `key` to the callback. | ||
| * | ||
| * @note This function uses cooperative group semantics, meaning that any thread may call the | ||
| * callback if it finds a matching element. If multiple elements are found within the same group, | ||
| * each thread with a match will call the callback with its associated element. | ||
| * | ||
| * @note Synchronizing `group` within `callback_op` is undefined behavior. | ||
| * | ||
| * @tparam ProbeKey Input type which is convertible to 'key_type' | ||
| * @tparam CallbackOp Unary callback functor or device lambda | ||
| * | ||
| * @param group The Cooperative Group used to perform this operation | ||
| * @param key The key to search for | ||
| * @param callback_op Function to call on every element found | ||
| */ | ||
| template <class ProbeKey, class CallbackOp> | ||
| __device__ void for_each(cooperative_groups::thread_block_tile<cg_size> const& group, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why the unit test is failing. Seems like the logic in this function is flawed.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I found the problem. #509 should fix the issue. |
||
| ProbeKey const& key, | ||
| CallbackOp&& callback_op) const noexcept | ||
| { | ||
| auto probing_iter = this->probing_scheme_(group, key, this->storage_ref_.window_extent()); | ||
| bool empty = false; | ||
|
|
||
| while (true) { | ||
| // TODO atomic_ref::load if insert operator is present | ||
| auto const window_slots = this->storage_ref_[*probing_iter]; | ||
|
|
||
| for (int32_t i = 0; i < window_size and !empty; ++i) { | ||
| switch ( | ||
| this->predicate_.operator()<is_insert::NO>(key, this->extract_key(window_slots[i]))) { | ||
| case detail::equal_result::EMPTY: { | ||
| empty = true; | ||
| continue; | ||
| } | ||
| case detail::equal_result::EQUAL: { | ||
| callback_op(const_iterator{&(*(this->storage_ref_.data() + *probing_iter))[i]}); | ||
| continue; | ||
| } | ||
| default: { | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| if (group.any(empty)) { return; } | ||
|
|
||
| ++probing_iter; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @brief Executes a callback on every element in the container with key equivalent to the probe | ||
| * key and can additionally perform work that requires synchronizing the Cooperative Group | ||
| * performing this operation. | ||
| * | ||
| * @note Passes an un-incrementable input iterator to the element whose key is equivalent to | ||
| * `key` to the callback. | ||
| * | ||
| * @note This function uses cooperative group semantics, meaning that any thread may call the | ||
| * callback if it finds a matching element. If multiple elements are found within the same group, | ||
| * each thread with a match will call the callback with its associated element. | ||
| * | ||
| * @note Synchronizing `group` within `callback_op` is undefined behavior. | ||
| * | ||
| * @note The `sync_op` function can be used to perform work that requires synchronizing threads in | ||
| * `group` inbetween probing steps, where the number of probing steps performed between | ||
| * synchronization points is capped by `window_size * cg_size`. The functor will be called right | ||
| * after the current probing window has been traversed. | ||
| * | ||
| * @tparam ProbeKey Input type which is convertible to 'key_type' | ||
| * @tparam CallbackOp Unary callback functor or device lambda | ||
| * @tparam SyncOp Functor or device lambda which accepts the current `group` object | ||
| * | ||
| * @param group The Cooperative Group used to perform this operation | ||
| * @param key The key to search for | ||
| * @param callback_op Function to call on every element found | ||
| * @param sync_op Function that is allowed to synchronize `group` inbetween probing windows | ||
| */ | ||
| template <class ProbeKey, class CallbackOp, class SyncOp> | ||
| __device__ void for_each(cooperative_groups::thread_block_tile<cg_size> const& group, | ||
| ProbeKey const& key, | ||
| CallbackOp&& callback_op, | ||
| SyncOp&& sync_op) const noexcept | ||
| { | ||
| auto probing_iter = this->probing_scheme_(group, key, this->storage_ref_.window_extent()); | ||
| bool empty = false; | ||
|
|
||
| while (true) { | ||
| // TODO atomic_ref::load if insert operator is present | ||
| auto const window_slots = this->storage_ref_[*probing_iter]; | ||
|
|
||
| for (int32_t i = 0; i < window_size and !empty; ++i) { | ||
| switch ( | ||
| this->predicate_.operator()<is_insert::NO>(key, this->extract_key(window_slots[i]))) { | ||
| case detail::equal_result::EMPTY: { | ||
| empty = true; | ||
| continue; | ||
| } | ||
| case detail::equal_result::EQUAL: { | ||
| callback_op(const_iterator{&(*(this->storage_ref_.data() + *probing_iter))[i]}); | ||
| continue; | ||
| } | ||
| default: { | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| sync_op(group); | ||
| if (group.any(empty)) { return; } | ||
|
|
||
| ++probing_iter; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compares the content of the address `address` (old value) with the `expected` value and, | ||
| * only if they are the same, sets the content of `address` to `desired`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,12 @@ struct count_tag { | |
| struct find_tag { | ||
| } inline constexpr find; ///< `cuco::find` operator | ||
|
|
||
| /** | ||
| * @brief `for_each` operator tag | ||
| */ | ||
| struct for_each_tag { | ||
| } inline constexpr for_each; ///< `cuco::for_each` operator | ||
|
Comment on lines
+68
to
+69
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my standpoint I would treat it as an extension to the STL API that is more suitable for the GPU. Having a "cooperative iterator" instead, which would be closer to the spirit of modern C++ has its drawbacks. For example, how do we ensure users only increment the iterator with the same CG?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a side note I personally find this funtional approach, i.e., "for each found key do X" very appealing. Historic evidence that it is indeed useful comes from warpcore, where many downstream applications (mostly genomics stuff) implemented their custom lookup operations through |
||
|
|
||
| } // namespace op | ||
| } // namespace cuco | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.