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

Add deterministic random number generator #857

Closed
stanmoore1 opened this issue Jun 2, 2017 · 6 comments
Closed

Add deterministic random number generator #857

stanmoore1 opened this issue Jun 2, 2017 · 6 comments
Assignees
Labels
Feature Request Create new capability; will potentially require voting

Comments

@stanmoore1
Copy link
Contributor

A deterministic random number generator (i.e. it gives the same random numbers regardless of how many threads) would be helpful for debugging, especially for CUDA. I don't care how slow it is.

@crtrott
Copy link
Member

crtrott commented Jun 2, 2017

Args, I knew you would ask for this. On CPUs it is already deterministic. I have to think about how to do that on the GPU without screwing with the whole GPU backend implementation.

@crtrott crtrott added the Feature Request Create new capability; will potentially require voting label Jun 2, 2017
@crtrott crtrott self-assigned this Jun 2, 2017
@crtrott
Copy link
Member

crtrott commented Jun 2, 2017

Would you terribly mind if the randomness of the numbers would degrade somewhat (i.e. if it doesn't reach quite as good a degree of randomness as with what it does during release mode)?

@stanmoore1
Copy link
Contributor Author

For debugging, correlations in the random numbers don't really matter. It would also be nice for regression testing if I always got the same results on CUDA and could use a tighter tolerance.

@stanmoore1
Copy link
Contributor Author

I need to think about this though--there may be other sources of non-determinism besides the RNG.

@timattox
Copy link

timattox commented Sep 1, 2017

To use the RNG's deterministicly via solution #1066 , the application has to do something like this code snippet to initialize the random pool:

Kokkos::Random_XorShift64_Pool<DeviceType> rand_pool;

if (maxWorkItemCt > maxRNG) {
  rand_pool.init(seed + comm->me, maxWorkItemCt);
  maxRNG = maxWorkItemCt;
}

And then use the workItemID as the index passed to get_state(), like this:

rand_type rand_gen = rand_pool.get_state(workItemID);
// use rand_gen here for this work item.
rand_pool.free_state(rand_gen);

So as long as each workItemID is guaranteed to be active in only one thread at a time, and in the range 0 to (maxWorkItemCt - 1). Thus, when a thread comes back in the future to the same work item, it can resume using the random number sequence where the sequence left off, regardless if it is the same thread doing the work. This does require the size of the pool to be larger than before, since presumably maxWorkItemCt is greater than threadCt.

Note: Depending on how many work items you have, you could have significantly more state saved than when letting Kokkos manage the number of RNG pool items to use.

@ibaned
Copy link
Contributor

ibaned commented Sep 1, 2017

The above text refers to the solution implemented in #1066.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Create new capability; will potentially require voting
Projects
None yet
Development

No branches or pull requests

4 participants