test/test_rocrand_philox_prng.cpp
// Check if the numbers generated by first generate() call are different from
// the numbers generated by the 2nd call (same generator)
Check if the numbers generated by first generate() call are different from
the numbers generated by the 2nd call (same generator)
Check if the numbers generated by first generate () call are different from the numbers generated by the 2nd call ( same generator )
TEST(rocrand_philox_prng_tests, state_progress_test)
{
    const size_t size = 1025;
    unsigned int * data;
    HIP_CHECK(hipMallocHelper(&data, sizeof(unsigned int) * size));
    rocrand_philox4x32_10 g0;
    ROCRAND_CHECK(g0.generate(data, size));
    HIP_CHECK(hipDeviceSynchronize());
    unsigned int host_data1[size];
    HIP_CHECK(hipMemcpy(host_data1, data, sizeof(unsigned int) * size, hipMemcpyDeviceToHost));
    HIP_CHECK(hipDeviceSynchronize());
    ROCRAND_CHECK(g0.generate(data, size));
    HIP_CHECK(hipDeviceSynchronize());
    unsigned int host_data2[size];
    HIP_CHECK(hipMemcpy(host_data2, data, sizeof(unsigned int) * size, hipMemcpyDeviceToHost));
    HIP_CHECK(hipDeviceSynchronize());
    size_t same = 0;
    for(size_t i = 0; i < size; i++)
    {
        if(host_data1[i] == host_data2[i]) same++;
    }
    EXPECT_LT(same, static_cast<size_t>(0.01f * size));
    HIP_CHECK(hipFree(data));
}
TEST ( rocrand_philox_prng_tests , state_progress_test ) { const size_t size = 1025 ; unsigned int * data ; HIP_CHECK ( hipMallocHelper ( & data , sizeof ( unsigned int ) * size ) ) ; rocrand_philox4x32_10 g0 ; ROCRAND_CHECK ( g0 . generate ( data , size ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; unsigned int host_data1 [ size ] ; HIP_CHECK ( hipMemcpy ( host_data1 , data , sizeof ( unsigned int ) * size , hipMemcpyDeviceToHost ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; ROCRAND_CHECK ( g0 . generate ( data , size ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; unsigned int host_data2 [ size ] ; HIP_CHECK ( hipMemcpy ( host_data2 , data , sizeof ( unsigned int ) * size , hipMemcpyDeviceToHost ) ) ; HIP_CHECK ( hipDeviceSynchronize ( ) ) ; size_t same = 0 ; for ( size_t i = 0 ; i < size ; i ++ ) { if ( host_data1 [ i ] == host_data2 [ i ] ) same ++ ; } EXPECT_LT ( same , static_cast < size_t > ( 0.01f * size ) ) ; HIP_CHECK ( hipFree ( data ) ) ; }
Check if the numbers generated by first generate() call are different from
the numbers generated by the 2nd call (same generator)
Check if the numbers generated by first generate () call are different from the numbers generated by the 2nd call ( same generator )
// Device data // Generator // Generate using g0 and copy to host // Generate using g0 and copy to host // It may happen that numbers are the same, so we // just make sure that most of them are different.