Skip to content

Commit b53e67d

Browse files
committed
Using a better 64-bit RNG for bijection round keys
1 parent 9202ad9 commit b53e67d

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

cpp/include/raft/random/detail/permute.cuh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,36 @@
1313
#include <cooperative_groups.h>
1414
#include <cuda/iterator>
1515
#include <cuda/std/random>
16-
#include <thrust/random.h>
1716

1817
namespace raft {
1918
namespace random {
2019
namespace detail {
2120

21+
// SplitMix64 reference: https://prng.di.unimi.it/splitmix64.c
22+
struct splitmix64 {
23+
using result_type = uint64_t;
24+
25+
RAFT_INLINE_FUNCTION explicit splitmix64(result_type seed) : state_{seed} {}
26+
27+
[[nodiscard]] RAFT_INLINE_FUNCTION static constexpr result_type min() noexcept { return 0; }
28+
29+
[[nodiscard]] RAFT_INLINE_FUNCTION static constexpr result_type max() noexcept
30+
{
31+
return ~result_type{0};
32+
}
33+
34+
RAFT_INLINE_FUNCTION result_type operator()() noexcept
35+
{
36+
auto z = (state_ += 0x9e3779b97f4a7c15ULL);
37+
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
38+
z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
39+
return z ^ (z >> 31);
40+
}
41+
42+
private:
43+
result_type state_;
44+
};
45+
2246
/**
2347
* @brief Generate permutation indices without copying input data.
2448
*
@@ -212,11 +236,8 @@ void permute(IntType* perms,
212236
uint64_t key)
213237
{
214238
if (N <= 0 || (perms == nullptr && out == nullptr)) { return; }
215-
thrust::random::ranlux48 rng(key);
216-
cuda::shuffle_iterator shuffled_indices
217-
{
218-
cuda::random_bijection { N, rng }
219-
}
239+
splitmix64 rng(key);
240+
cuda::shuffle_iterator shuffled_indices{cuda::random_bijection{N, rng}};
220241

221242
if (out == nullptr) {
222243
constexpr int ITEMS_PER_THREAD = 8;

0 commit comments

Comments
 (0)