upgpkg: wordpress 6.2.1-1
[ArchLinux/community.git] / rocrand / repos / community-x86_64 / test.cpp
blob4f9ace82138a822dc152195a47f299f9f05278da
1 #include <hiprand/hiprand.hpp>
2 #include <vector>
3 #include <numeric>
4 #include <cmath>
5 #include <iostream>
7 int main()
9 size_t size = 1024 * 1024;
10 float mean = -1.24f;
11 float std = 0.43f;
12 hiprandGenerator_t gen;
13 hiprandCreateGenerator(&gen, HIPRAND_RNG_PSEUDO_DEFAULT);
15 float *x;
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
25 float tol = 3e-1;
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;
30 return 1;
32 std::cout << "TESTS PASSED!" << std::endl;
34 hiprandDestroyGenerator(gen);
35 hipFree(x);