Skip to content

Commit

Permalink
Rename philox (#18)
Browse files Browse the repository at this point in the history
* Lower min CMake version

* document testu01 building options

* Corrected Squares' seed type; then fixed a whole bunch of compiler warnings related to type conversions

* Moved examples/readme to tests/

* Philox: Expose another counter through constructor

* Renamed Phillox to Philox; a long standing typo

* forgot to cntrl+S in editor :)
  • Loading branch information
Shihab-Shahriar authored Dec 14, 2023
1 parent a675320 commit 4d83582
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ If you're building OpenRAND and want to build the TestU01 statistical test suite
Here's a simple example of how to generate random numbers using OpenRAND:

```
#include <openrand/phillox.h>
#include <openrand/philox.h>
int main() {
using RNG = openrand::Phillox; // Or, for example, Tyche
using RNG = openrand::Philox; // Or, for example, Tyche
// Initialize RNG with seed and counter
RNG rng(1, 0);
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/raw_speed_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// This compares the raw speed of all the generators on both CPU and GPU.

#include <benchmark/benchmark.h>
#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/threefry.h>
#include <openrand/tyche.h>
Expand Down Expand Up @@ -56,7 +56,7 @@ static void bench_cpp(benchmark::State& state) {
#define TUnit benchmark::kNanosecond

// Register the function as a benchmark
BENCHMARK(bench_rng<openrand::Phillox>)
BENCHMARK(bench_rng<openrand::Philox>)
->Unit(TUnit)
->Arg(10)
->Arg(100)
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/raw_speed_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <cuda.h>


#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/threefry.h>
#include <openrand/squares.h>
#include <openrand/tyche.h>
Expand Down Expand Up @@ -117,8 +117,8 @@ int main(){
std::cout << "Number of Streaming Multiprocessors (SMs): " << deviceProp.multiProcessorCount << std::endl;


std::cout << "====Phillox====" << std::endl;
measure_speed_cuda<openrand::Phillox>(deviceProp.multiProcessorCount);
std::cout << "====Philox====" << std::endl;
measure_speed_cuda<openrand::Philox>(deviceProp.multiProcessorCount);

std::cout << "====Threefry====" << std::endl;
measure_speed_cuda<openrand::Threefry>(deviceProp.multiProcessorCount);
Expand Down
6 changes: 3 additions & 3 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# A Quick Introduction to OpenRAND

OpenRAND comes with four generator classes: `Phillox`, `Tyche`, `Threefry` and `Squares`. They all have a similar interface: given a `seed` and `counter`, the generator can produce a stream of random numbers (upto 2^32 numbers per object). `seed` should be self-explanatory, we'll introduce `counter` later.
OpenRAND comes with four generator classes: `Philox`, `Tyche`, `Threefry` and `Squares`. They all have a similar interface: given a `seed` and `counter`, the generator can produce a stream of random numbers (upto 2^32 numbers per object). `seed` should be self-explanatory, we'll introduce `counter` later.

```
#include <phillox.h>
#include <Philox.h>
int main() {
using RNG = Phillox; // You can swap with Tyche, Threefry or Squares
using RNG = Philox; // You can swap with Tyche, Threefry or Squares
// Initialize RNG with seed and counter
RNG rng(/*seed*/ 42, /*counter*/ 0);
Expand Down
6 changes: 3 additions & 3 deletions docs/statistical_results.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
OpenRAND generators has been tested with two statistical suites: TestU01 and PractRand.

There are two ways to test the generators:
+ Single stream: we use PractRand to test a single random number stream to their theoratical limit of 2^32 numbers (2^34 bytes). See the files [practrand_[tyche|squares|threefry|phillox].txt](https://github.com/msu-sparta/OpenRAND/tree/gh-pages/results) for details.
+ Single stream: we use PractRand to test a single random number stream to their theoratical limit of 2^32 numbers (2^34 bytes). See the files [practrand_[tyche|squares|threefry|Philox].txt](https://github.com/msu-sparta/OpenRAND/tree/gh-pages/results) for details.

+ Parallel Streams: This tests for correlation among parallel streams. This is not quite straightforward in those statistical frameworks- as they are designed to work on a single stream. To stitch parallel streams to a single one, we use the following approach:
+ Start with a set of `N` random number generators.
Expand All @@ -16,7 +16,7 @@ In this document, our primary focus is on parallel streams, as single streams ar
## Practrand
Practrand can consume practically infinite amount of data. Given that each stream contains 2^32 numbers, and each number is 4 bytes (2^2), with 100 streams (or 2^6.64), the combined buffer is little over 2^40 bytes long. Put another way, we shouldn't expect to see any failures in Practrand before reaching the 2^40 bytes (1-terabyte) mark.

None of the generators failed this test. For detailed output from the practrand suite for for each generator, see: [practrandm_[tyche|squares|threefry|phillox].txt](https://github.com/msu-sparta/OpenRAND/tree/gh-pages/results).
None of the generators failed this test. For detailed output from the practrand suite for for each generator, see: [practrandm_[tyche|squares|threefry|Philox].txt](https://github.com/msu-sparta/OpenRAND/tree/gh-pages/results).


## TestU01
Expand All @@ -43,4 +43,4 @@ Some generators do fail one or two BigCRush tests. For example, this is the outp

This is not unusual on some runs, authors of curand also [observed](https://docs.nvidia.com/cuda/curand/testing.html) some failures on Bigcrush. It also depends on the configuration we used.

For detailed output from Bigcrush suite, see [testu01m_[tyche|squares|threefry|phillox].txt](https://github.com/msu-sparta/OpenRAND/tree/gh-pages/results).
For detailed output from Bigcrush suite, see [testu01m_[tyche|squares|threefry|Philox].txt](https://github.com/msu-sparta/OpenRAND/tree/gh-pages/results).
6 changes: 3 additions & 3 deletions examples/basic_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//********************************************************************************
// @HEADER

#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/tyche.h>

Expand All @@ -43,7 +43,7 @@ struct Particle {
}; // class Particle

int main() {
using RNG = openrand::Phillox; // Or, for example, Tyche
using RNG = openrand::Philox; // Or, for example, Tyche

RNG rng(1ULL, 0);

Expand All @@ -53,7 +53,7 @@ int main() {
double c = rng.rand<double>();
float f = rng.rand<float>();

if constexpr (std::is_same_v<RNG, typename openrand::Phillox>) {
if constexpr (std::is_same_v<RNG, typename openrand::Philox>) {
// this function is not availabe for all generators.
openrand::float4 f4 = rng.draw_float4();

Expand Down
4 changes: 2 additions & 2 deletions examples/pi_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/

#include <curand_kernel.h>
#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/threefry.h>
#include <openrand/tyche.h>
Expand All @@ -45,7 +45,7 @@ const int SAMPLES_PER_THREAD = 1000; // Number of samples per thread
const int NTHREADS = N / SAMPLES_PER_THREAD; // Number of threads
const int THREADS_PER_BLOCK = 256; // Number of threads per block

typedef openrand::Phillox RNG;
typedef openrand::Philox RNG;

__global__ void monteCarloPi(int *d_sum) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
Expand Down
4 changes: 2 additions & 2 deletions examples/pi_openmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// @HEADER

#include <omp.h>
#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/tyche.h>

#include <atomic>
Expand All @@ -37,7 +37,7 @@
#include <vector>

double compute_pi() {
using RNG = openrand::Phillox;
using RNG = openrand::Philox;
const int nsamples = 10000000;
int total_samples;
int total_hits = 0;
Expand Down
20 changes: 10 additions & 10 deletions include/openrand/phillox.h → include/openrand/philox.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
//********************************************************************************
// @HEADER

#ifndef OPENRAND_PHILLOX_H_
#define OPENRAND_PHILLOX_H_
#ifndef OPENRAND_Philox_H_
#define OPENRAND_Philox_H_

#include <openrand/base_state.h>

Expand All @@ -43,15 +43,15 @@
namespace openrand {

/**
* @class Phillox
* @brief Phillox generator
* @note This is a modified version of Phillox generator from Random123 library.
* @class Philox
* @brief Philox generator
* @note This is a modified version of Philox generator from Random123 library.
* This uses 4x 32-bit counter, 2x 32-bit key along with 10 rounds.
*/
class Phillox : public BaseRNG<Phillox> {
class Philox : public BaseRNG<Philox> {
public:
/**
* @brief Construct a new Phillox object
* @brief Construct a new Philox generator
*
* @note Internally, global_seed is treated in the same way as other counters,
* and can be treated as such depending on the application needs.
Expand All @@ -61,7 +61,7 @@ class Phillox : public BaseRNG<Phillox> {
* @param global_seed (Optional) 32-bit global seed.
* @param ctr1 (Optional) Another 32-bit counter exposed for advanced use.
*/
DEVICE Phillox(uint64_t seed, uint32_t ctr,
DEVICE Philox(uint64_t seed, uint32_t ctr,
uint32_t global_seed = openrand::DEFAULT_GLOBAL_SEED,
uint32_t ctr1 = 0x12345)
: seed_hi((uint32_t)(seed >> 32)),
Expand Down Expand Up @@ -150,8 +150,8 @@ class Phillox : public BaseRNG<Phillox> {
// private counter to keep track of numbers generated by this instance of rng
uint32_t ctr3 = 0;
uint32_t _out[4];
}; // class Phillox
}; // class Philox

} // namespace openrand

#endif // OPENRAND_PHILLOX_H_
#endif // OPENRAND_Philox_H_
4 changes: 2 additions & 2 deletions tests/pract_rand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//********************************************************************************
// @HEADER

#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/threefry.h>
#include <openrand/tyche.h>
Expand Down Expand Up @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) {
std::cout << "Generating stream for: " << arg << std::endl;

if (arg == "philox") {
generate_stream<openrand::Phillox>();
generate_stream<openrand::Philox>();
} else if (arg == "tyche") {
generate_stream<openrand::Tyche>();
} else if (arg == "threefry") {
Expand Down
4 changes: 2 additions & 2 deletions tests/pract_rand_multistream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
//********************************************************************************
// @HEADER

#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/threefry.h>
#include <openrand/tyche.h>
Expand Down Expand Up @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
std::cout << "Generating multi-stream for: " << arg << std::endl;

if (arg == "philox") {
generate_multi_stream<openrand::Phillox>();
generate_multi_stream<openrand::Philox>();
} else if (arg == "tyche") {
generate_multi_stream<openrand::Tyche>();
} else if (arg == "threefry") {
Expand Down
6 changes: 3 additions & 3 deletions tests/test_normal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// @HEADER

#include <gtest/gtest.h>
#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/threefry.h>
#include <openrand/tyche.h>
Expand Down Expand Up @@ -88,8 +88,8 @@ void test_normalcy() {
ASSERT_TRUE(!reject_null);
}

TEST(normal, phillox) {
test_normalcy<openrand::Phillox>();
TEST(normal, Philox) {
test_normalcy<openrand::Philox>();
}

TEST(normal, tyche) {
Expand Down
14 changes: 7 additions & 7 deletions tests/test_uniform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// @HEADER

#include <gtest/gtest.h>
#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/threefry.h>
#include <openrand/tyche.h>
Expand All @@ -36,14 +36,14 @@
// std::is_trivially_copyable and std::is_trivially_destructible tests
// for all generator types
TEST(RNG, trivially_copyable) {
EXPECT_TRUE(std::is_trivially_copyable<openrand::Phillox>::value);
EXPECT_TRUE(std::is_trivially_copyable<openrand::Philox>::value);
EXPECT_TRUE(std::is_trivially_copyable<openrand::Tyche>::value);
EXPECT_TRUE(std::is_trivially_copyable<openrand::Threefry>::value);
EXPECT_TRUE(std::is_trivially_copyable<openrand::Squares>::value);
}

TEST(RNG, trivially_destructible) {
EXPECT_TRUE(std::is_trivially_destructible<openrand::Phillox>::value);
EXPECT_TRUE(std::is_trivially_destructible<openrand::Philox>::value);
EXPECT_TRUE(std::is_trivially_destructible<openrand::Tyche>::value);
EXPECT_TRUE(std::is_trivially_destructible<openrand::Threefry>::value);
EXPECT_TRUE(std::is_trivially_destructible<openrand::Squares>::value);
Expand All @@ -67,7 +67,7 @@ void test_basic() {
}

TEST(RNG, basic) {
test_basic<openrand::Phillox>();
test_basic<openrand::Philox>();
test_basic<openrand::Tyche>();
test_basic<openrand::Threefry>();
test_basic<openrand::Squares>();
Expand Down Expand Up @@ -104,7 +104,7 @@ void test_range() {
}

TEST(RNG, range) {
test_range<openrand::Phillox>();
test_range<openrand::Philox>();
test_range<openrand::Tyche>();
test_range<openrand::Threefry>();
test_range<openrand::Squares>();
Expand All @@ -125,7 +125,7 @@ void test_mean() {
}

TEST(Uniform, mean) {
test_mean<openrand::Phillox>();
test_mean<openrand::Philox>();
test_mean<openrand::Tyche>();
test_mean<openrand::Threefry>();
test_mean<openrand::Squares>();
Expand Down Expand Up @@ -155,7 +155,7 @@ void test_cpp_engine() {
}

TEST(CPP11, engine) {
test_cpp_engine<openrand::Phillox>();
test_cpp_engine<openrand::Philox>();
test_cpp_engine<openrand::Tyche>();
test_cpp_engine<openrand::Threefry>();
test_cpp_engine<openrand::Squares>();
Expand Down
4 changes: 2 additions & 2 deletions tests/testu01-multistream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern "C" {
#include "TestU01.h"
}

#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/threefry.h>
#include <openrand/tyche.h>
Expand Down Expand Up @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) {
if (arg == "philox") {
gen = unif01_CreateExternGenBits(
(char*)arg.c_str(),
reverseBits ? gen32<openrand::Phillox> : gen32_rev<openrand::Phillox>);
reverseBits ? gen32<openrand::Philox> : gen32_rev<openrand::Philox>);
} else if (arg == "tyche") {
gen = unif01_CreateExternGenBits(
(char*)arg.c_str(),
Expand Down
6 changes: 3 additions & 3 deletions tests/testu01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ extern "C" {
#include "TestU01.h"
}

#include <openrand/phillox.h>
#include <openrand/philox.h>
#include <openrand/squares.h>
#include <openrand/tyche.h>

// based on: https://www.pcg-random.org/posts/how-to-test-with-testu01.html

const char* gen_name = "Phillox";
using RNG = openrand::Phillox;
const char* gen_name = "Philox";
using RNG = openrand::Philox;

uint32_t gen32() {
static RNG rng(42, 0);
Expand Down

0 comments on commit 4d83582

Please sign in to comment.