1 #include <hiprand/hiprand.hpp>
9 size_t size
= 1024 * 1024;
12 hiprandGenerator_t gen
;
13 hiprandCreateGenerator(&gen
, HIPRAND_RNG_PSEUDO_DEFAULT
);
16 hipMalloc((void**)&x
, sizeof *x
* size
);
17 hiprandGenerateNormal(gen
, x
, size
, mean
, std
);
19 std::vector
<float> x_d(size
);
20 hipMemcpy(x_d
.data(), x
, sizeof *x
* size
, hipMemcpyDeviceToHost
);
22 float mean_hat
= std::accumulate(x_d
.begin(), x_d
.end(), 0.0f
) / size
;
24 // Tolerance set so that test may at most fail in 1 of 10,000 runs
26 if(std::abs(mean
- mean_hat
) > tol
){
27 std::cout
<< "Tolerance in mean not reached:\n"
28 << mean_hat
<< " differs more than " << tol
29 << " from " << mean
<< std::endl
;
32 std::cout
<< "TESTS PASSED!" << std::endl
;
34 hiprandDestroyGenerator(gen
);