| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
/// \file KokkosLapack_Host_tpl.cpp |
| 17 |
/// \brief LAPACK wrapper for host tpls |
| 18 |
/// \author Kyungjoo Kim ([email protected]) |
| 19 |
|
| 20 |
#include "KokkosKernels_config.h" |
| 21 |
#include "KokkosLapack_Host_tpl.hpp" |
| 22 |
|
| 23 |
#if defined(KOKKOSKERNELS_ENABLE_TPL_LAPACK) |
| 24 |
|
| 25 |
/// Fortran headers |
| 26 |
extern "C" { |
| 27 |
|
| 28 |
/// |
| 29 |
/// Gesv |
| 30 |
/// |
| 31 |
|
| 32 |
void F77_BLAS_MANGLE(sgesv, SGESV)(int*, int*, float*, int*, int*, float*, int*, int*); |
| 33 |
void F77_BLAS_MANGLE(dgesv, DGESV)(int*, int*, double*, int*, int*, double*, int*, int*); |
| 34 |
void F77_BLAS_MANGLE(cgesv, CGESV)(int*, int*, std::complex<float>*, int*, int*, std::complex<float>*, int*, int*); |
| 35 |
void F77_BLAS_MANGLE(zgesv, ZGESV)(int*, int*, std::complex<double>*, int*, int*, std::complex<double>*, int*, int*); |
| 36 |
|
| 37 |
/// |
| 38 |
/// Gesvd |
| 39 |
/// |
| 40 |
|
| 41 |
void F77_BLAS_MANGLE(sgesvd, SGESVD)(const char*, const char*, const int*, const int*, float*, const int*, float*, |
| 42 |
float*, const int*, float*, const int*, float*, int*, int*); |
| 43 |
void F77_BLAS_MANGLE(dgesvd, DGESVD)(const char*, const char*, const int*, const int*, double*, const int*, double*, |
| 44 |
double*, const int*, double*, const int*, double*, int*, int*); |
| 45 |
void F77_BLAS_MANGLE(cgesvd, CGESVD)(const char*, const char*, const int*, const int*, std::complex<float>*, const int*, |
| 46 |
float*, std::complex<float>*, const int*, std::complex<float>*, const int*, |
| 47 |
std::complex<float>*, int*, float*, int*); |
| 48 |
void F77_BLAS_MANGLE(zgesvd, ZGESVD)(const char*, const char*, const int*, const int*, std::complex<double>*, |
| 49 |
const int*, double*, std::complex<double>*, const int*, std::complex<double>*, |
| 50 |
const int*, std::complex<double>*, int*, double*, int*); |
| 51 |
|
| 52 |
/// |
| 53 |
/// Trtri |
| 54 |
/// |
| 55 |
/* |
| 56 |
HostLapack<float>::trtri(const char uplo, const char diag, |
| 57 |
int n, const float *a, int lda) { |
| 58 |
int info = 0; |
| 59 |
F77_FUNC_STRTRI(&uplo, |
| 60 |
&diag, &n, |
| 61 |
a, &lda, &info); |
| 62 |
*/ |
| 63 |
void F77_BLAS_MANGLE(strtri, STRTRI)(const char*, const char*, int*, const float*, int*, int*); |
| 64 |
void F77_BLAS_MANGLE(dtrtri, DTRTRI)(const char*, const char*, int*, const double*, int*, int*); |
| 65 |
void F77_BLAS_MANGLE(ctrtri, CTRTRI)(const char*, const char*, int*, const std::complex<float>*, int*, int*); |
| 66 |
void F77_BLAS_MANGLE(ztrtri, ZTRTRI)(const char*, const char*, int*, const std::complex<double>*, int*, int*); |
| 67 |
} |
| 68 |
|
| 69 |
#define F77_FUNC_SGESV F77_BLAS_MANGLE(sgesv, SGESV) |
| 70 |
#define F77_FUNC_DGESV F77_BLAS_MANGLE(dgesv, DGESV) |
| 71 |
#define F77_FUNC_CGESV F77_BLAS_MANGLE(cgesv, CGESV) |
| 72 |
#define F77_FUNC_ZGESV F77_BLAS_MANGLE(zgesv, ZGESV) |
| 73 |
|
| 74 |
#define F77_FUNC_SGESVD F77_BLAS_MANGLE(sgesvd, SGESVD) |
| 75 |
#define F77_FUNC_DGESVD F77_BLAS_MANGLE(dgesvd, DGESVD) |
| 76 |
#define F77_FUNC_CGESVD F77_BLAS_MANGLE(cgesvd, CGESVD) |
| 77 |
#define F77_FUNC_ZGESVD F77_BLAS_MANGLE(zgesvd, ZGESVD) |
| 78 |
|
| 79 |
#define F77_FUNC_STRTRI F77_BLAS_MANGLE(strtri, STRTRI) |
| 80 |
#define F77_FUNC_DTRTRI F77_BLAS_MANGLE(dtrtri, DTRTRI) |
| 81 |
#define F77_FUNC_CTRTRI F77_BLAS_MANGLE(ctrtri, CTRTRI) |
| 82 |
#define F77_FUNC_ZTRTRI F77_BLAS_MANGLE(ztrtri, ZTRTRI) |
| 83 |
|
| 84 |
namespace KokkosLapack { |
| 85 |
namespace Impl { |
| 86 |
|
| 87 |
/// |
| 88 |
/// float |
| 89 |
/// |
| 90 |
|
| 91 |
template <> |
| 92 |
void HostLapack<float>::gesv(int n, int rhs, float* a, int lda, int* ipiv, float* b, int ldb, int info) { |
| 93 |
F77_FUNC_SGESV(&n, &rhs, a, &lda, ipiv, b, &ldb, &info); |
| 94 |
} |
| 95 |
template <> |
| 96 |
void HostLapack<float>::gesvd(const char jobu, const char jobvt, const int m, const int n, float* a, const int lda, |
| 97 |
float* s, float* u, const int ldu, float* vt, const int ldvt, float* work, int lwork, |
| 98 |
float* /*rwork*/, int info) { |
| 99 |
F77_FUNC_SGESVD(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork, &info); |
| 100 |
} |
| 101 |
template <> |
| 102 |
int HostLapack<float>::trtri(const char uplo, const char diag, int n, const float* a, int lda) { |
| 103 |
int info = 0; |
| 104 |
F77_FUNC_STRTRI(&uplo, &diag, &n, a, &lda, &info); |
| 105 |
return info; |
| 106 |
} |
| 107 |
|
| 108 |
/// |
| 109 |
/// double |
| 110 |
/// |
| 111 |
|
| 112 |
template <> |
| 113 |
void HostLapack<double>::gesv(int n, int rhs, double* a, int lda, int* ipiv, double* b, int ldb, int info) { |
| 114 |
F77_FUNC_DGESV(&n, &rhs, a, &lda, ipiv, b, &ldb, &info); |
| 115 |
} |
| 116 |
template <> |
| 117 |
void HostLapack<double>::gesvd(const char jobu, const char jobvt, const int m, const int n, double* a, const int lda, |
| 118 |
double* s, double* u, const int ldu, double* vt, const int ldvt, double* work, int lwork, |
| 119 |
double* /*rwork*/, int info) { |
| 120 |
F77_FUNC_DGESVD(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork, &info); |
| 121 |
} |
| 122 |
template <> |
| 123 |
int HostLapack<double>::trtri(const char uplo, const char diag, int n, const double* a, int lda) { |
| 124 |
int info = 0; |
| 125 |
F77_FUNC_DTRTRI(&uplo, &diag, &n, a, &lda, &info); |
| 126 |
return info; |
| 127 |
} |
| 128 |
|
| 129 |
/// |
| 130 |
/// std::complex<float> |
| 131 |
/// |
| 132 |
|
| 133 |
template <> |
| 134 |
void HostLapack<std::complex<float> >::gesv(int n, int rhs, std::complex<float>* a, int lda, int* ipiv, |
| 135 |
std::complex<float>* b, int ldb, int info) { |
| 136 |
F77_FUNC_CGESV(&n, &rhs, a, &lda, ipiv, b, &ldb, &info); |
| 137 |
} |
| 138 |
template <> |
| 139 |
void HostLapack<std::complex<float> >::gesvd(const char jobu, const char jobvt, const int m, const int n, |
| 140 |
std::complex<float>* a, const int lda, float* s, std::complex<float>* u, |
| 141 |
const int ldu, std::complex<float>* vt, const int ldvt, |
| 142 |
std::complex<float>* work, int lwork, float* rwork, int info) { |
| 143 |
F77_FUNC_CGESVD(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork, rwork, &info); |
| 144 |
} |
| 145 |
template <> |
| 146 |
int HostLapack<std::complex<float> >::trtri(const char uplo, const char diag, int n, const std::complex<float>* a, |
| 147 |
int lda) { |
| 148 |
int info = 0; |
| 149 |
F77_FUNC_CTRTRI(&uplo, &diag, &n, a, &lda, &info); |
| 150 |
return info; |
| 151 |
} |
| 152 |
|
| 153 |
/// |
| 154 |
/// std::complex<double> |
| 155 |
/// |
| 156 |
|
| 157 |
template <> |
| 158 |
void HostLapack<std::complex<double> >::gesv(int n, int rhs, std::complex<double>* a, int lda, int* ipiv, |
| 159 |
std::complex<double>* b, int ldb, int info) { |
| 160 |
F77_FUNC_ZGESV(&n, &rhs, a, &lda, ipiv, b, &ldb, &info); |
| 161 |
} |
| 162 |
template <> |
| 163 |
void HostLapack<std::complex<double> >::gesvd(const char jobu, const char jobvt, const int m, const int n, |
| 164 |
std::complex<double>* a, const int lda, double* s, |
| 165 |
std::complex<double>* u, const int ldu, std::complex<double>* vt, |
| 166 |
const int ldvt, std::complex<double>* work, int lwork, double* rwork, |
| 167 |
int info) { |
| 168 |
F77_FUNC_ZGESVD(&jobu, &jobvt, &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork, rwork, &info); |
| 169 |
} |
| 170 |
template <> |
| 171 |
int HostLapack<std::complex<double> >::trtri(const char uplo, const char diag, int n, const std::complex<double>* a, |
| 172 |
int lda) { |
| 173 |
int info = 0; |
| 174 |
F77_FUNC_ZTRTRI(&uplo, &diag, &n, a, &lda, &info); |
| 175 |
return info; |
| 176 |
} |
| 177 |
|
| 178 |
} // namespace Impl |
| 179 |
} // namespace KokkosLapack |
| 180 |
#endif // KOKKOSKERNELS_ENABLE_TPL_LAPACK |