DFT-EFE
 
Loading...
Searching...
No Matches
BlasLapackTypedef.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22/*
23 * @author Sambit Das, Vishal Subramanian, Avirup Sircar
24 */
25
26#ifndef dftefeBlasWrapperTypedef_h
27#define dftefeBlasWrapperTypedef_h
28
29#include <utils/MemoryStorage.h>
30#include <complex>
31#include <cstdarg>
32
33namespace dftefe
34{
35 namespace linearAlgebra
36 {
37 namespace blasLapack
38 {
39 namespace typeInternal
40 {
41 // Adapted from include/blas/util.hh
42 // (https://github.com/icl-utk-edu/blaspp/blob/b5d0761a0c3a45ed1bad73b697125c2e46ac1617/include/blas/util.hh#L309)
43
44 // -----------------------------------------------------------------------------
45 // Based on C++14 common_type implementation from
46 // http://www.cplusplus.com/reference/type_traits/common_type/
47 // Adds promotion of complex types based on the common type of the
48 // associated real types. This fixes various cases:
49 //
50 // std::std::common_type_t< double, complex<float> > is complex<float>
51 // (wrong)
52 // scalar_type< double, complex<float> > is complex<double>
53 // (right)
54 //
55 // std::std::common_type_t< int, complex<long> > is not defined (compile
56 // error)
57 // scalar_type< int, complex<long> > is complex<long> (right)
58
59 // for zero types
60 template <typename... Types>
62
63 // define scalar_type<> type alias
64 template <typename... Types>
65 using scalar_type = typename scalar_type_traits<Types...>::type;
66
67 // for one type
68 template <typename T>
70 {
71 using type = std::decay_t<T>;
72 };
73
74 // for two types
75 // relies on type of ?: operator being the common type of its two
76 // arguments
77 template <typename T1, typename T2>
78 struct scalar_type_traits<T1, T2>
79 {
80 using type = std::decay_t<decltype(true ? std::declval<T1>() :
81 std::declval<T2>())>;
82 };
83
84 // for either or both complex,
85 // find common type of associated real types, then add complex
86 template <typename T1, typename T2>
87 struct scalar_type_traits<std::complex<T1>, T2>
88 {
89 using type = std::complex<std::common_type_t<T1, T2>>;
90 };
91
92 template <typename T1, typename T2>
93 struct scalar_type_traits<T1, std::complex<T2>>
94 {
95 using type = std::complex<std::common_type_t<T1, T2>>;
96 };
97
98 template <typename T1, typename T2>
99 struct scalar_type_traits<std::complex<T1>, std::complex<T2>>
100 {
101 using type = std::complex<std::common_type_t<T1, T2>>;
102 };
103
104 // for three or more types
105 template <typename T1, typename T2, typename... Types>
106 struct scalar_type_traits<T1, T2, Types...>
107 {
109 };
110
111 // -----------------------------------------------------------------------------
112 // for any combination of types, determine associated real, scalar,
113 // and complex types.
114 //
115 // real_type< float > is float
116 // real_type< float, double, complex<float> > is double
117 //
118 // scalar_type< float > is float
119 // scalar_type< float, complex<float> > is complex<float>
120 // scalar_type< float, double, complex<float> > is complex<double>
121 //
122 // complex_type< float > is complex<float>
123 // complex_type< float, double > is complex<double>
124 // complex_type< float, double, complex<float> > is complex<double>
125
126 // for zero types
127 template <typename... Types>
129
130 // define real_type<> type alias
131 template <typename... Types>
132 using real_type = typename real_type_traits<Types...>::real_t;
133
134 // define complex_type<> type alias
135 template <typename... Types>
136 using complex_type = std::complex<real_type<Types...>>;
137
138 // for one type
139 template <typename T>
141 {
142 using real_t = T;
143 };
144
145 // for one complex type, strip complex
146 template <typename T>
147 struct real_type_traits<std::complex<T>>
148 {
149 using real_t = T;
150 };
151
152 // for two or more types
153 template <typename T1, typename... Types>
154 struct real_type_traits<T1, Types...>
155 {
157 };
158 } // namespace typeInternal
159
160 enum class Layout
161 {
162 ColMajor,
164 };
165
166 using LapackInt = int64_t;
167
168 enum class ScalarOp
169 {
170 Identity,
171 Conj
172 };
173
174 // real_type< float > is float
175 // real_type< float, double, complex<float> > is double
176 template <typename ValueType>
178
179 // scalar_type< float > is float
180 // scalar_type< float, complex<float> > is complex<float>
181 // scalar_type< float, double, complex<float> > is complex<double>
182 template <typename ValueType1, typename ValueType2>
184
185 // template <dftefe::utils::MemorySpace memorySpace>
186 // struct BlasQueueTypedef
187 // {
188 // typedef void TYPE; // default
189 // };
190
191 // // template specified mapping
192 // template <>
193 // struct BlasQueueTypedef<dftefe::utils::MemorySpace::HOST>
194 // {
195 // typedef int TYPE;
196 // };
197
198 // template <>
199 // struct BlasQueueTypedef<dftefe::utils::MemorySpace::HOST_PINNED>
200 // {
201 // typedef int TYPE;
202 // };
203
204 // template <>
205 // struct BlasQueueTypedef<dftefe::utils::MemorySpace::DEVICE>
206 // {
207 // typedef int TYPE;
208 // };
209
210 // template <dftefe::utils::MemorySpace memorySpace>
211 // using BlasQueue = typename BlasQueueTypedef<memorySpace>::TYPE;
212
213 // template <dftefe::utils::MemorySpace memorySpace>
214 // struct LapackQueueTypedef
215 // {
216 // typedef void LAPACKTYPE; // default
217 // };
218
219 // // template specified mapping
220 // template <>
221 // struct LapackQueueTypedef<dftefe::utils::MemorySpace::HOST>
222 // {
223 // typedef int LAPACKTYPE;
224 // };
225
226 // template <>
227 // struct LapackQueueTypedef<dftefe::utils::MemorySpace::HOST_PINNED>
228 // {
229 // typedef int LAPACKTYPE;
230 // };
231
232 // template <>
233 // struct LapackQueueTypedef<dftefe::utils::MemorySpace::DEVICE>
234 // {
235 // typedef int LAPACKTYPE;
236 // };
237
238 // template <dftefe::utils::MemorySpace memorySpace>
239 // using LapackQueue = typename
240 // LapackQueueTypedef<memorySpace>::LAPACKTYPE;
241
242 } // namespace blasLapack
243
244 } // namespace linearAlgebra
245
246} // namespace dftefe
247
248#endif // define blasWrapperTypedef
typename scalar_type_traits< Types... >::type scalar_type
Definition: BlasLapackTypedef.h:65
std::complex< real_type< Types... > > complex_type
Definition: BlasLapackTypedef.h:136
typename real_type_traits< Types... >::real_t real_type
Definition: BlasLapackTypedef.h:132
typeInternal::real_type< ValueType > real_type
Definition: BlasLapackTypedef.h:177
Layout
Definition: BlasLapackTypedef.h:161
int64_t LapackInt
Definition: BlasLapackTypedef.h:166
typeInternal::scalar_type< ValueType1, ValueType2 > scalar_type
Definition: BlasLapackTypedef.h:183
ScalarOp
Definition: BlasLapackTypedef.h:169
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
scalar_type< real_type< T1 >, real_type< Types... > > real_t
Definition: BlasLapackTypedef.h:156
scalar_type< scalar_type< T1, T2 >, Types... > type
Definition: BlasLapackTypedef.h:108
std::decay_t< decltype(true ? std::declval< T1 >() :std::declval< T2 >())> type
Definition: BlasLapackTypedef.h:81
std::complex< std::common_type_t< T1, T2 > > type
Definition: BlasLapackTypedef.h:95
std::decay_t< T > type
Definition: BlasLapackTypedef.h:71
std::complex< std::common_type_t< T1, T2 > > type
Definition: BlasLapackTypedef.h:101
std::complex< std::common_type_t< T1, T2 > > type
Definition: BlasLapackTypedef.h:89