Skip to content
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

matrix::select_k: move selection and warp-sort primitives #1085

Merged
merged 42 commits into from
Jan 23, 2023
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
39c10a9
Make warp-level bitonic sort public
achirkin Dec 9, 2022
6cda736
Move spatial::*::select_topk to matrix::select_k
achirkin Dec 9, 2022
c5631bf
Fix includes style
achirkin Dec 9, 2022
fb88433
Use cmake-format
achirkin Dec 9, 2022
f64325b
Refactored warpsort module and made tests for all implementations in …
achirkin Dec 13, 2022
20d01d7
Resort to UVM when radix buffers are too big
achirkin Dec 14, 2022
4813bae
Adjust the dummy_block_sort_t to the changes in the warpsort impl
achirkin Dec 14, 2022
6cdb79a
Fix incorrect include
achirkin Dec 14, 2022
870fc86
Add benchmarks
achirkin Dec 14, 2022
2af45bf
Update CMakeLists.txt style
achirkin Dec 14, 2022
5b336ee
Update CMakeLists.txt style
achirkin Dec 14, 2022
b3e5d9c
Add mdspanified interface
achirkin Dec 15, 2022
164157b
Remove benchmarks for the legacy interface
achirkin Dec 15, 2022
69c81dd
Remove a TODO comment about a seemingly resolved bug
achirkin Dec 15, 2022
d64b12b
Merge remote-tracking branch 'rapidsai/branch-23.02' into enh-matrix-…
achirkin Dec 15, 2022
9d4476a
Fix the changed include extension
achirkin Dec 15, 2022
3e40435
Fix includes in tests
achirkin Dec 16, 2022
e20578e
Merge remote-tracking branch 'rapidsai/branch-23.02' into enh-matrix-…
achirkin Dec 16, 2022
b2c79f5
Merge branch 'branch-23.02' into enh-matrix-topk
achirkin Dec 20, 2022
98e2c2a
Address comments: bitonic_sort
achirkin Dec 20, 2022
af4c146
Replace stream argument with handle_t
achirkin Dec 20, 2022
471828e
rename files to select.* -> select_k.*
achirkin Dec 20, 2022
f6ff223
Use raft macros
achirkin Dec 20, 2022
066208d
Try to pass null and non-null arguments to select_k
achirkin Dec 20, 2022
aeaa1ef
Remove raw-pointer api from the public namespace
achirkin Dec 20, 2022
685b6bf
Updates public docs (add example usage)
achirkin Dec 21, 2022
5c42209
Merge remote-tracking branch 'rapidsai/branch-23.02' into enh-matrix-…
achirkin Jan 9, 2023
2cea50d
Add device_mem_resource
achirkin Jan 9, 2023
a31e61e
Add Doxygen docs
achirkin Jan 10, 2023
a8c5a70
Merge remote-tracking branch 'rapidsai/branch-23.02' into enh-matrix-…
achirkin Jan 10, 2023
8a5978b
Revert the memory_resource param changes in the detail namespace to a…
achirkin Jan 10, 2023
8e58cab
Merge remote-tracking branch 'rapidsai/branch-23.02' into enh-matrix-…
achirkin Jan 11, 2023
a01a75f
Remove device_mem_resource
achirkin Jan 11, 2023
c6256b7
Merge branch 'branch-23.02' into enh-matrix-topk
achirkin Jan 16, 2023
c25e859
Merge branch 'branch-23.02' into enh-matrix-topk
cjnolet Jan 19, 2023
6e56106
Merge branch 'branch-23.02' into enh-matrix-topk
achirkin Jan 20, 2023
c78d9b0
Reference a TODO issue
achirkin Jan 20, 2023
a55a6cb
Merge branch 'enh-matrix-topk' of github.com:achirkin/raft into enh-m…
achirkin Jan 20, 2023
307b113
Deprecation notice
achirkin Jan 20, 2023
c0ce160
Add [in] annotation to all arguments
achirkin Jan 20, 2023
e2cc7ad
Merge branch 'branch-23.02' into enh-matrix-topk
achirkin Jan 23, 2023
dc3043c
Merge branch 'branch-23.02' into enh-matrix-topk
cjnolet Jan 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address comments: bitonic_sort
  • Loading branch information
achirkin committed Dec 20, 2022
commit 98e2c2a6ef848c56ba4905a1e9ab309891d032bb
52 changes: 33 additions & 19 deletions cpp/include/raft/util/bitonic_sort.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

#pragma once

#include <raft/core/detail/macros.hpp>
#include <raft/util/cuda_utils.cuh>

namespace raft::util {
achirkin marked this conversation as resolved.
Show resolved Hide resolved

namespace {

template <typename T>
__device__ __forceinline__ void swap(T& x, T& y)
_RAFT_DEVICE _RAFT_FORCEINLINE void swap(T& x, T& y)
{
T t = x;
x = y;
y = t;
}

template <typename T>
__device__ __forceinline__ void conditional_assign(bool cond, T& ptr, T x)
_RAFT_DEVICE _RAFT_FORCEINLINE void conditional_assign(bool cond, T& ptr, T x)
{
if (cond) { ptr = x; }
}
Expand Down Expand Up @@ -59,6 +60,19 @@ __device__ __forceinline__ void conditional_assign(bool cond, T& ptr, T x)
* 3 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 48 49 50 ...
* `
*
* Here is a small usage example of device code, which sorts the arrays of length 6 (= 3 * 2)
* grouped in pairs of threads in ascending order:
* @code{.cpp}
* // Fill an array of three ints in each thread of a warp.
* int i = laneId();
* int arr[3] = {i+1, i+5, i};
* // Sort the arrays in groups of two threads.
* bitonic<3>(ascending=true, warp_width=2).sort(arr);
* // As a result,
* // for every even thread (`i == 2j`): arr == {2j, 2j+1, 2j+5}
* // for every odd thread (`i == 2j+1`): arr == {2j+1, 2j+2, 2j+6}
* @endcode
*
* @tparam Size
* number of elements processed in each thread;
* i.e. the total data size is `Size * warp_width`.
Expand All @@ -80,7 +94,7 @@ class bitonic {
* the total size of the sorted data is `Size * warp_width`.
* Must be power-of-two, not larger than the WarpSize.
*/
__device__ __forceinline__ explicit bitonic(bool ascending, int warp_width = WarpSize)
_RAFT_DEVICE _RAFT_FORCEINLINE explicit bitonic(bool ascending, int warp_width = WarpSize)
: ascending_(ascending), warp_width_(warp_width)
{
}
Expand Down Expand Up @@ -108,8 +122,8 @@ class bitonic {
* the keys; must be at least `Size` elements long.
*/
template <typename KeyT, typename... PayloadTs>
__device__ __forceinline__ void merge(KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads) const
_RAFT_DEVICE _RAFT_FORCEINLINE void merge(KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads) const
{
return bitonic<Size>::merge_impl(ascending_, warp_width_, keys, payloads...);
}
Expand All @@ -127,8 +141,8 @@ class bitonic {
* the keys; must be at least `Size` elements long.
*/
template <typename KeyT, typename... PayloadTs>
__device__ __forceinline__ void sort(KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads) const
_RAFT_DEVICE _RAFT_FORCEINLINE void sort(KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads) const
{
return bitonic<Size>::sort_impl(ascending_, warp_width_, keys, payloads...);
}
Expand All @@ -141,8 +155,8 @@ class bitonic {
* @param payload
*/
template <typename KeyT, typename... PayloadTs, int S = Size>
__device__ __forceinline__ auto merge(KeyT& __restrict__ key,
PayloadTs& __restrict__... payload) const
_RAFT_DEVICE _RAFT_FORCEINLINE auto merge(KeyT& __restrict__ key,
PayloadTs& __restrict__... payload) const
-> std::enable_if_t<S == 1, void> // SFINAE to enable this for Size == 1 only
{
static_assert(S == Size);
Expand All @@ -157,8 +171,8 @@ class bitonic {
* @param payload
*/
template <typename KeyT, typename... PayloadTs, int S = Size>
__device__ __forceinline__ auto sort(KeyT& __restrict__ key,
PayloadTs& __restrict__... payload) const
_RAFT_DEVICE _RAFT_FORCEINLINE auto sort(KeyT& __restrict__ key,
PayloadTs& __restrict__... payload) const
-> std::enable_if_t<S == 1, void> // SFINAE to enable this for Size == 1 only
{
static_assert(S == Size);
Expand All @@ -173,10 +187,10 @@ class bitonic {
friend class bitonic;

template <typename KeyT, typename... PayloadTs>
static __device__ __forceinline__ void merge_impl(bool ascending,
int warp_width,
KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads)
static _RAFT_DEVICE _RAFT_FORCEINLINE void merge_impl(bool ascending,
int warp_width,
KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads)
{
#pragma unroll
for (int size = Size; size > 1; size >>= 1) {
Expand Down Expand Up @@ -213,10 +227,10 @@ class bitonic {
}

template <typename KeyT, typename... PayloadTs>
static __device__ __forceinline__ void sort_impl(bool ascending,
int warp_width,
KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads)
static _RAFT_DEVICE _RAFT_FORCEINLINE void sort_impl(bool ascending,
int warp_width,
KeyT* __restrict__ keys,
PayloadTs* __restrict__... payloads)
{
if constexpr (Size == 1) {
const int lane = laneId();
Expand Down