3#ifndef MODULE_HSOLVER_MATH_KERNEL_H
4#define MODULE_HSOLVER_MATH_KERNEL_H
12#if defined(__CUDA) || defined(__UT_USE_CUDA)
13#include <cuda_runtime.h>
25void gram_herk_cpu(
int ld,
int dim,
int bands,
const std::complex<double>* x,
26 std::complex<double>*
output);
32 return {x.real(), 0.0};
36 return {x.real(), 0.0};
43inline std::complex<double>
get_conj(
const std::complex<double> &x) {
44 return {x.real(), -x.imag()};
47inline std::complex<float>
get_conj(
const std::complex<float> &x) {
48 return {x.real(), -x.imag()};
51inline double get_conj(
const double &x) {
return x; }
53inline float get_conj(
const float &x) {
return x; }
59template <
typename FPTYPE,
typename Device>
struct scal_op {
71 const std::complex<FPTYPE> *alpha, std::complex<FPTYPE> *X,
103 void operator()(
const int& dim,
T* result,
const T* vector1,
const Operand* vector2,
const bool& add);
106template <
typename T,
typename Operand>
109 const Operand *vector2,
const bool &add) {
115#pragma omp parallel for schedule(static)
117 for (
int i = 0; i < dim; i++) {
118 result[i] += vector1[i] * vector2[i];
122#pragma omp parallel for schedule(static)
124 for (
int i = 0; i < dim; i++) {
125 result[i] = vector1[i] * vector2[i];
158 const Operand *vector2);
161template <
typename T,
typename Operand>
164 const Operand *vector2) {
169#pragma omp parallel for schedule(static)
171 for (
int i = 0; i < dim; i++) {
172 result[i] = vector1[i] / vector2[i];
178template <
typename T,
typename Device>
struct axpy_op {
192 const int &incX,
T *Y,
const int &incY);
196template <
typename T,
typename Device,
typename Scalar>
210 const Scalar constant1,
const T *vector2,
const Scalar constant2);
213template <
typename T,
typename Scalar>
216 const Scalar constant1,
const T *vector2,
217 const Scalar constant2) {
222#pragma omp parallel for schedule(static)
224 for (
int i = 0; i < dim; i++) {
225 result[i] = vector1[i] * constant1 + vector2[i] * constant2;
245 const T *psi_R,
const bool reduce =
true);
254template <
typename T,
typename Device>
struct gemv_op {
273 const int &n,
const T *alpha,
const T *A,
const int &lda,
274 const T *X,
const int &incx,
const T *beta,
T *Y,
278template <
typename T,
typename Device>
struct trmm_op
292 void operator()(
const char& side,
const char& uplo,
const char& trans,
const char& diag,
293 const int& m,
const int& n,
const T* alpha,
const T* a,
const int& lda,
294 T* b,
const int& ldb);
298template <
typename T,
typename Device>
struct gemm_op {
319 const int &m,
const int &n,
const int &k,
const T *alpha,
320 const T *a,
const int &lda,
const T *b,
const int &ldb,
321 const T *beta,
T *c,
const int &ldc);
326template <
typename T,
typename Device>
struct gemv_op_mt {
344 void operator()(
const char &trans,
const int &m,
345 const int &n,
const T *alpha,
const T *A,
const int &lda,
346 const T *X,
const int &incx,
const T *beta,
T *Y,
351template <
typename T,
typename Device>
struct gemm_op_mt {
371 void operator()(
const char &transa,
const char &transb,
372 const int &m,
const int &n,
const int &k,
const T *alpha,
373 const T *a,
const int &lda,
const T *b,
const int &ldb,
374 const T *beta,
T *c,
const int &ldc);
389 const T *input_matrix,
T *output_matrix);
404 void operator()(
const int& n1,
const int& n2,
const T* A,
const int& LDA,
T* B,
const int& LDB);
407template <
typename T,
typename Device>
432template <
typename T,
typename Device>
436 void operator()(
const Device *d,
const int &nbase,
const int &nbase_x,
const int ¬conv,
437 T *result,
const T *vectors,
const Real *eigenvalues);
440template <
typename T,
typename Device>
448 const Real* precondition,
449 const Real* eigenvalues);
452template <
typename T,
typename Device>
460 Real* psi_norm =
nullptr);
474#if __CUDA || __UT_USE_CUDA || __ROCM || __UT_USE_ROCM
479 const T *psi_L,
const T *psi_R,
const bool reduce =
true);
491template <
typename T,
typename Operand>
493 void operator()(
const int& dim,
T* result,
const T* vector1,
const Operand* vector2,
const bool& add);
499 void operator()(
const int& dim,
T* result,
const T* vector,
const Real constant);
503template <
typename T,
typename Operand>
506 const T *vector1,
const Operand *vector2);
510template <
typename T,
typename Scalar>
513 const T *vector1,
const Scalar constant1,
const T *vector2,
514 const Scalar constant2);
517template <
typename T>
struct matrixCopy<
T, base_device::DEVICE_GPU> {
537void createGpuBlasHandle();
538void destoryBLAShandle();
544 void operator()(
const base_device::DEVICE_GPU *d,
const int &nbase,
const int &nbase_x,
const int ¬conv,
545 T *result,
const T *vectors,
const Real *eigenvalues);
551 void operator()(
const base_device::DEVICE_GPU* d,
556 const Real* precondition,
557 const Real* eigenvalues);
#define N
Definition exp.cpp:24
#define T
Definition exp.cpp:237
Definition clebsch_gordan_coeff.cpp:8
void gram_herk_cpu(int ld, int dim, int bands, const std::complex< double > *x, std::complex< double > *output)
Definition math_kernel_op.cpp:37
std::complex< double > set_real_tocomplex(const std::complex< double > &x)
Definition math_kernel_op.h:31
std::complex< double > get_conj(const std::complex< double > &x)
Definition math_kernel_op.h:43
T type
Definition macros.h:8
Definition math_kernel_op.h:433
void operator()(const Device *d, const int &nbase, const int &nbase_x, const int ¬conv, T *result, const T *vectors, const Real *eigenvalues)
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:434
Definition math_kernel_op.h:178
void operator()(const int &N, const T *alpha, const T *X, const int &incX, T *Y, const int &incY)
Y = alpha * X + Y.
Definition math_kernel_op.h:230
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:231
Real operator()(const int &dim, const T *psi_L, const T *psi_R, const bool reduce=true)
dot_real_op computes the dot product of the given complex arrays(treated as float arrays)....
Definition math_kernel_op.h:298
void operator()(const char &transa, const char &transb, const int &m, const int &n, const int &k, const T *alpha, const T *a, const int &lda, const T *b, const int &ldb, const T *beta, T *c, const int &ldc)
C = alpha * op(A) * op(B) + beta * C.
Definition math_kernel_op.h:254
void operator()(const char &trans, const int &m, const int &n, const T *alpha, const T *A, const int &lda, const T *X, const int &incx, const T *beta, T *Y, const int &incy)
y = alpha * op(A) * x + beta * y
Definition math_kernel_op.h:392
void operator()(const int &n1, const int &n2, const T *A, const int &LDA, T *B, const int &LDB)
copy matrix A to B, they can have different leading dimensions
Definition math_kernel_op.h:378
void operator()(const int &row, const int &col, const T *input_matrix, T *output_matrix)
transpose the input matrix
Definition math_kernel_op.h:408
void operator()(const int &m, const int &n, T *a, const int &lda, const Real *b, const Real alpha, T *c, const int &ldc)
a * b * beta by each column
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:409
void operator()(const base_device::DEVICE_GPU *d, const int &dim, T *psi_iter, const int &nbase, const int ¬conv, Real *psi_norm)
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:465
Definition math_kernel_op.h:453
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:454
void operator()(const Device *d, const int &dim, T *psi_iter, const int &nbase, const int ¬conv, Real *psi_norm=nullptr)
Definition math_kernel_op.h:441
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:442
void operator()(const Device *d, const int &dim, T *psi_iter, const int &nbase, const int ¬conv, const Real *precondition, const Real *eigenvalues)
Definition math_kernel_op.h:59
void operator()(const int &N, const std::complex< FPTYPE > *alpha, std::complex< FPTYPE > *X, const int &incx)
x = alpha * x, where alpha and x are complex numbers
Definition math_kernel_op.h:279
void operator()(const char &side, const char &uplo, const char &trans, const char &diag, const int &m, const int &n, const T *alpha, const T *a, const int &lda, T *b, const int &ldb)
In-place column-major B = alpha*op(A)*B or B = alpha*B*op(A).
void operator()(const int &dim, T *result, const T *vector1, const Scalar constant1, const T *vector2, const Scalar constant2)
Definition math_kernel_op.h:215
Definition math_kernel_op.h:197
void operator()(const int &dim, T *result, const T *vector1, const Scalar constant1, const T *vector2, const Scalar constant2)
result[i] = vector1[i] * constant1 + vector2[i] * constant2
Definition math_kernel_op.h:132
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:133
void operator()(const int &dim, T *result, const T *vector, const Real constant)
result[i] = vector[i] / constant
void operator()(const int &dim, T *result, const T *vector1, const Operand *vector2)
Definition math_kernel_op.h:163
Definition math_kernel_op.h:147
void operator()(const int &dim, T *result, const T *vector1, const Operand *vector2)
result[i] = vector1[i] / vector2[i]
Definition math_kernel_op.h:75
void operator()(const int dim, T *result, const T *vector, const Real constant)
result[i] = vector[i] * constant, where vector is complex number and constant is real number。 It is d...
typename GetTypeReal< T >::type Real
Definition math_kernel_op.h:76
void operator()(const int &dim, T *result, const T *vector1, const Operand *vector2, const bool &add)
Definition math_kernel_op.h:108
Definition math_kernel_op.h:92
void operator()(const int &dim, T *result, const T *vector1, const Operand *vector2, const bool &add)
result[i] = vector1[i] * vector2[i]
std::string output
Definition test_io_sys_var.cpp:60