test/test_rocrand_philox_prng.cpp
// Checks if generators with the same seed and in the same state generate
// the same numbers
Checks if generators with the same seed and in the same state generate
the same numbers
Checks if generators with the same seed and in the same state generate the same numbers
TEST(rocrand_philox_prng_tests, different_seed_test)
{
    const unsigned long long seed0 = 0xdeadbeefdeadbeefULL;
    const unsigned long long seed1 = 0xbeefdeadbeefdeadULL;
    const size_t size = 1024;
    unsigned int * data;
    HIP_CHECK(hipMallocHelper(&data, sizeof(unsigned int) * size));
    rocrand_philox4x32_10 g0, g1;
    g0.set_seed(seed0);
    g1.set_seed(seed1);
    ASSERT_NE(g0.get_seed(), g1.get_seed());
    ROCRAND_CHECK(g0.generate(data, size));
    HIP_CHECK(hipDeviceSynchronize());
    unsigned int g0_host_data[size];
    HIP_CHECK(hipMemcpy(g0_host_data, data, sizeof(unsigned int) * size, hipMemcpyDeviceToHost));
    HIP_CHECK(hipDeviceSynchronize());
    ROCRAND_CHECK(g1.generate(data, size));
    HIP_CHECK(hipDeviceSynchronize());
    unsigned int g1_host_data[size];
    HIP_CHECK(hipMemcpy(g1_host_data, data, sizeof(unsigned int) * size, hipMemcpyDeviceToHost));
    HIP_CHECK(hipDeviceSynchronize());
    size_t same = 0;
    for(size_t i = 0; i < size; i++)
    {
        if(g1_host_data[i] == g0_host_data[i]) same++;
    }
    EXPECT_LT(same, static_cast<size_t>(0.01f * size));
    HIP_CHECK(hipFree(data));
}
TEST ( rocrand_philox_prng_tests , different_seed_test ) { const unsigned long long seed0 = 0xdeadbeefdeadbeefULL ; const unsigned long long seed1 = 0xbeefdeadbeefdeadULL ; const size_t size = 1024 ; unsigned int * data ; HIP_CHECK ( hipMallocHelper ( & data , sizeof ( unsigned int ) * size ) ) ; rocrand_philox4x32_10 g0 , g1 ; g0 . set_seed ( seed0 ) ; g1 . set_seed ( seed1 ) ; ASSERT_NE ( g0 . get_seed ( ) , g1 . get_seed ( ) ) ; ROCRAND_CHECK ( g0 . generate ( data , size ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; unsigned int g0_host_data [ size ] ; HIP_CHECK ( hipMemcpy ( g0_host_data , data , sizeof ( unsigned int ) * size , hipMemcpyDeviceToHost ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; ROCRAND_CHECK ( g1 . generate ( data , size ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; unsigned int g1_host_data [ size ] ; HIP_CHECK ( hipMemcpy ( g1_host_data , data , sizeof ( unsigned int ) * size , hipMemcpyDeviceToHost ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; size_t same = 0 ; for ( size_t i = 0 ; i < size ; i ++ ) { if ( g1_host_data [ i ] == g0_host_data [ i ] ) same ++ ; } EXPECT_LT ( same , static_cast < size_t > ( 0.01f * size ) ) ; HIP_CHECK ( hipFree ( data ) ) ; }
Checks if generators with the same seed and in the same state generate
the same numbers
Checks if generators with the same seed and in the same state generate the same numbers
// Device side data // Generators // Set different seeds // Generate using g0 and copy to host // Generate using g1 and copy to host // It may happen that numbers are the same, so we // just make sure that most of them are different.