Repository navigation
Expand file tree
/
Copy pathmath_kernel_op.cpp
More file actions
144 lines (134 loc) · 4.49 KB
/
Copy pathmath_kernel_op.cpp
File metadata and controls
144 lines (134 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "source_base/kernels/math_kernel_op.h"
#include "source_base/module_external/blas_connector.h"
#include <iomanip>
#include <iostream>
namespace ModuleBase
{
template <typename T>
struct gemv_op<T, base_device::DEVICE_CPU>
{
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)
{
BlasConnector::gemv(trans, m, n, *alpha, A, lda, X, incx, *beta, Y, incy);
}
};
template <typename T>
struct gemm_op<T, base_device::DEVICE_CPU>
{
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)
{
BlasConnector::gemm(transb, transa, n, m, k, *alpha, b, ldb, a, lda, *beta, c, ldc);
}
};
#ifdef __DSP
template <typename T>
struct gemm_op_mt<T, base_device::DEVICE_CPU>
{
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)
{
BlasConnector::gemm(transb, transa, n, m, k, *alpha, b, ldb, a, lda, *beta, c, ldc, base_device::AbacusDevice_t::DspDevice);
}
};
#endif
template <typename T>
struct matrixTranspose_op<T, base_device::DEVICE_CPU>
{
void operator()(const int& row,
const int& col,
const T* input_matrix,
T* output_matrix)
{
T* temp = nullptr;
base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(temp, row * col, "MTransOp");
#ifdef _OPENMP
#pragma omp parallel for collapse(2) schedule(static, 8192 / sizeof(T))
#endif
for (int j = 0; j < col; j++)
{
for (int i = 0; i < row; i++)
{
temp[j * row + i] = input_matrix[i * col + j];
}
}
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 8192 / sizeof(T))
#endif
for (int i = 0; i < row * col; i++)
{
output_matrix[i] = temp[i];
}
base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(temp);
}
};
template <typename T>
struct matrixCopy<T, base_device::DEVICE_CPU>
{
void operator()(const int& n1, const int& n2, const T* A, const int& LDA, T* B, const int& LDB)
{
#ifdef _OPENMP
#pragma omp parallel for collapse(2) schedule(static, 8192 / sizeof(T))
#endif
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n2; j++)
{
B[i * LDB + j] = A[i * LDA + j];
}
}
}
};
template struct gemv_op<std::complex<float>, base_device::DEVICE_CPU>;
template struct gemv_op<float, base_device::DEVICE_CPU>;
template struct gemm_op<std::complex<float>, base_device::DEVICE_CPU>;
template struct gemm_op<float, base_device::DEVICE_CPU>;
template struct matrixTranspose_op<std::complex<float>, base_device::DEVICE_CPU>;
template struct matrixCopy<std::complex<float>, base_device::DEVICE_CPU>;
template struct gemv_op<std::complex<double>, base_device::DEVICE_CPU>;
template struct gemv_op<double, base_device::DEVICE_CPU>;
template struct gemm_op<std::complex<double>, base_device::DEVICE_CPU>;
template struct gemm_op<double, base_device::DEVICE_CPU>;
template struct matrixTranspose_op<std::complex<double>, base_device::DEVICE_CPU>;
template struct matrixCopy<double, base_device::DEVICE_CPU>;
template struct matrixCopy<std::complex<double>, base_device::DEVICE_CPU>;
#ifdef __LCAO
template struct matrixTranspose_op<double, base_device::DEVICE_CPU>;
#endif
#ifdef __DSP
template struct gemm_op_mt<std::complex<float>, base_device::DEVICE_CPU>;
template struct gemm_op_mt<std::complex<double>, base_device::DEVICE_CPU>;
#endif
} // namespace hsolver