Demo const_cast
Loading...
Searching...
No Matches
processingunit_cpu.hpp
Go to the documentation of this file.
1template<class floating>
2Timer CPU<floating>::createTimer() const
3{
4 return std::make_unique<OMP_Timer>();
5}
6
7template<class floating>
8void CPU<floating>::display() const
9{
10 std::cout << "CPU" << std::endl;
11 return;
12}
13
14template<class floating>
15void CPU<floating>::xaxpy(const int n, const floating alpha, const floating * const x, const int incx, floating * const y, const int incy) const
16{
17 if constexpr(isFloat())
18 cblas_saxpy(n, alpha, x, incx, y, incy);
19 else if constexpr(isDouble())
20 cblas_daxpy(n, alpha, x, incx, y, incy);
21
22 return;
23}
24
25template<class floating>
26floating CPU<floating>::xdot(const int n, const floating * const x, const int incx, const floating * const y, const int incy) const
27{
28 floating result = 0;
29 if constexpr(isFloat())
30 result = cblas_sdot(n, x, incx, y, incy);
31 else if constexpr(isDouble())
32 result = cblas_ddot(n, x, incx, y, incy);
33
34 return result;
35}
36
37template<class floating>
38void CPU<floating>::xgemm(const OperationType TransA, const OperationType TransB,
39 const int M, const int N, const int K, const floating alpha, const floating * const A,
40 const int lda, const floating * const B, const int ldb, const floating beta, floating * const C, const int ldc) const
41{
42 if constexpr(isFloat())
43 cblas_sgemm(CblasColMajor, toInternalOperationBLAS.at(TransA), toInternalOperationBLAS.at(TransB),
44 M, N, K, alpha, A,
45 lda, B, ldb, beta, C, ldc);
46 else if constexpr(isDouble())
47 cblas_dgemm(CblasColMajor, toInternalOperationBLAS.at(TransA), toInternalOperationBLAS.at(TransB),
48 M, N, K, alpha, A,
49 lda, B, ldb, beta, C, ldc);
50 return;
51}
52
53template<class floating>
54void CPU<floating>::xgemv(const OperationType trans, const int m, const int n,
55 const floating alpha, floating const * const a, const int lda, floating const * const x, const int incx,
56 const floating beta, floating * const y, const int incy) const
57{
58 if constexpr(isFloat())
59 cblas_sgemv(CblasColMajor, toInternalOperationBLAS.at(trans), m, n,
60 alpha, a, lda, x, incx,
61 beta, y, incy);
62 else if constexpr(isDouble())
63 cblas_dgemv(CblasColMajor, toInternalOperationBLAS.at(trans), m, n,
64 alpha, a, lda, x, incx,
65 beta, y, incy);
66
67 return;
68}
69
70
71template<class floating>
72void CPU<floating>::xgetrf(int * const m, int * const n, floating * const a, int * const lda,
73 int * const ipiv, int * const info) const
74{
75 if constexpr(isFloat())
76 sgetrf_(m, n, a, lda, ipiv, info);
77 else if constexpr(isDouble())
78 dgetrf_(m, n, a, lda, ipiv, info);
79
80 return;
81}
82
83template<class floating>
84void CPU<floating>::xgetrs(const OperationType trans, const int * const n, const int * const nrhs,
85 const floating * const a, const int * const lda, const int * const ipiv,
86 floating * const b, const int * const ldb, int * const info) const
87{
88 if constexpr(isFloat())
89 sgetrs_(toInternalOperationLAPACK.at(trans), n, nrhs, a, lda, ipiv, b, ldb, info);
90 else if constexpr(isDouble())
91 //~ dgetrs_(const_cast<char*>(toInternalOperationLAPACK.at(trans)), n, nrhs, a, lda, ipiv, b, ldb, info);
92 dgetrs_(const_cast<char*>(toInternalOperationLAPACK.at(trans)), const_cast<int*>(n), const_cast<int*>(nrhs), a, const_cast<int*>(lda), const_cast<int*>(ipiv), b, const_cast<int*>(ldb), info);
93 return;
94}
95
96template<class floating>
97void CPU<floating>::xscal(const int N, const floating alpha, floating * const X, const int incX) const
98{
99 if constexpr(isFloat())
100 cblas_sscal(N, alpha, X, incX);
101 else if constexpr(isDouble())
102 cblas_dscal(N, alpha, X, incX);
103
104 return;
105}
106
107template<class floating>
108std::map<OperationType, CBLAS_TRANSPOSE> CPU<floating>::toInternalOperationBLAS = {
109 {OperationType::Identical, CblasNoTrans},
110 {OperationType::Transposed, CblasTrans},
111 {OperationType::Hermitian, CblasConjTrans}
112};
113
114template<class floating>
115std::map<OperationType, const char * const> CPU<floating>::toInternalOperationLAPACK = {
116 {OperationType::Identical, "N"},
117 {OperationType::Transposed, "T"},
118 {OperationType::Hermitian, "C"}
119};
Definition main.cpp:6