1 #include <rocsolver/rocsolver.h>
2 #include <hip/hip_runtime.h>
14 std::random_device rd
;
15 std::mt19937
gen(rd());
16 std::uniform_real_distribution
<float> dist(-1.0, 1.0);
17 auto myrand
= [&](){return dist(gen
);};
21 hipMalloc((void**)&a
, sizeof *a
* size
);
22 hipMalloc((void**)&x
, sizeof *x
* n
);
24 std::vector
<float> ain(size
);
25 std::vector
<float> xin(n
);
26 std::generate(ain
.begin(), ain
.end(), myrand
);
27 std::generate(xin
.begin(), xin
.end(), myrand
);
29 hipMemcpy(a
, ain
.data(), sizeof *a
* size
, hipMemcpyHostToDevice
);
30 hipMemcpy(x
, xin
.data(), sizeof *x
* n
, hipMemcpyHostToDevice
);
32 rocblas_handle handle
;
33 rocblas_create_handle(&handle
);
36 hipMalloc((void**)&info
, sizeof *info
);
37 rocsolver_sgels(handle
, rocblas_operation_none
,
38 n
, n
, 1, a
, n
, x
, n
, info
);
40 std::vector
<float> xout(n
);
41 hipMemcpy(xout
.data(), x
, sizeof *x
* n
, hipMemcpyDeviceToHost
);
43 hipMemcpy(&hinfo
, info
, sizeof *info
, hipMemcpyDeviceToHost
);
46 std::cout
<< "Matrix is rank deficient!\n";
51 for(size_t i
= 0; i
< n
; i
++){
52 for(size_t j
= 0; j
< n
; j
++){
53 xin
[i
] -= ain
[i
+ j
* n
] * xout
[j
];
55 if(std::abs(xin
[i
]) > tol
){
56 std::cout
<< "Missmatch at index " << i
<< "\n"
57 << "Desired: 0" << "\n"
58 << "Actual : " << xin
[i
] << std::endl
;
63 std::cout
<< "TESTS PASSED!" << std::endl
;
67 rocblas_destroy_handle(handle
);