4#include <ginkgo/ginkgo.hpp>
5#include <hip/hip_runtime.h>
6#include <hip/hip_runtime_api.h>
12 hipGetDevice(&backupDeviceId);
13 hipSetDevice(deviceId);
19 hipMalloc((
void **) &dWork,
sizeof(
double));
20 hipMalloc((
void **) &devInfo,
sizeof(
int));
22 hipsolverDnHandle_t solverHandle;
23 hipsolverDnCreate(&solverHandle);
26 auto A_T = gko::share(gko::matrix::Dense<>::create(exec, gko::dim<2>(A_Q->get_size()[1], A_Q->get_size()[0])));
27 A_Q->transpose(gko::lend(A_T));
30 const unsigned int M = A_T->get_size()[1];
31 const unsigned int N = A_T->get_size()[0];
33 const int lda =
max(1, M);
34 const int k =
max(M, N);
41 hipMalloc((
void **) &dTau,
sizeof(
double) * M);
44 hipsolverStatus_t hipsolverStatus = hipsolverDnDgeqrf_bufferSize(solverHandle, M, N, A_T->get_values(), lda, &lwork_geqrf);
45 assert(hipsolverStatus == HIPSOLVER_STATUS_SUCCESS);
46 hipsolverStatus = hipsolverDnDorgqr_bufferSize(solverHandle, M, N, k, A_T->get_values(), lda, dTau, &lwork_orgqr);
47 assert(hipsolverStatus == HIPSOLVER_STATUS_SUCCESS);
48 lwork = (lwork_geqrf > lwork_orgqr) ? lwork_geqrf : lwork_orgqr;
49 hipError_t hipErrorCode = hipMalloc((
void **) &dWork,
sizeof(
double) * lwork);
50 assert(hipSuccess == hipErrorCode);
54 hipsolverStatus = hipsolverDnDgeqrf(solverHandle, M, N, A_T->get_values(), lda, dTau, (
double *) dWork, lwork, devInfo);
55 hipErrorCode = hipDeviceSynchronize();
56 assert(hipsolverStatus == HIPSOLVER_STATUS_SUCCESS);
57 assert(hipSuccess == hipErrorCode);
60 A_T->transpose(gko::lend(R));
63 hipsolverStatus = hipsolverDnDorgqr(solverHandle, M, N, k, A_T->get_values(), lda, dTau, (
double *) dWork, lwork, devInfo);
64 hipErrorCode = hipDeviceSynchronize();
65 assert(hipsolverStatus == HIPSOLVER_STATUS_SUCCESS);
66 assert(hipSuccess == hipErrorCode);
68 A_T->transpose(gko::lend(A_Q));
70 hipDeviceSynchronize();
76 hipsolverDnDestroy(solverHandle);
79 hipSetDevice(backupDeviceId);