Skip to content

Commit

Permalink
For fixing the cuGraph test failures with PCG (#690)
Browse files Browse the repository at this point in the history
RAFT's RNG class provides methods that fill a buffer with random numbers belonging to various probability distribution functions. For example`uniform`, `normal` etc. In this methods, multiple instances of random number generator are used in parallel. Each cuda thread gets it own instance of generator. The instance is initialized with three values `seed`, `subsequence` and `offset`. The  value for `seed` is common for all threads and thread id is used for `subsequence`. The `offset`  is kept `0` for all instances. To fill the buffer, the threads work in grid strided fashion  demonstrated by loop below:

```
  for (size_t i = tid; i < buffer_length; i += total_number_of_threads) {
    buffer[i] = rng.next();
  }
```

Due to grid-striding of loops, consecutive elements in the buffer are `ith` element in consecutive subsequences. For example, 10th and 11th elements in the buffer would be 0th element in 10th and 11th subsequences. In the unit tests for cugraph, this scheme seems to introduce a slight bias in certain cases. Easy fix to the issue is to break the lock step increment of individual subsequences. 

This PR sets different offset value for each subsequence by setting `offset = subsequence`. Note that this change has no effect on the period of the random number generator.

This should fix the cuGraph issue rapidsai/cugraph#2266 for now.

Authors:
  - Vinay Deshpande (https://github.com/vinaydes)

Approvers:
  - Thejaswi. N. S (https://github.com/teju85)

URL: #690
  • Loading branch information
vinaydes authored May 26, 2022
1 parent 8c2d2c5 commit d8989b7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions cpp/include/raft/random/detail/rng_device.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ struct PCGenerator {
next(discard);
pcg_state += rng_state.seed;
next(discard);
skipahead(subsequence);
}

// Based on "Random Number Generation with Arbitrary Strides" F. B. Brown
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/linalg/gemm_layout.cu
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class GemmLayoutTest : public ::testing::TestWithParam<GemmLayoutInputs<T>> {
};

const std::vector<GemmLayoutInputs<float>> inputsf = {
{80, 70, 80, true, true, true, 76433ULL},
{80, 70, 80, true, true, true, 76430ULL},
{80, 100, 40, true, true, false, 426646ULL},
{20, 100, 20, true, false, true, 237703ULL},
{100, 60, 30, true, false, false, 538004ULL},
Expand Down

0 comments on commit d8989b7

Please sign in to comment.