4 #define EIGEN_DONT_PARALLELIZE
7#if __has_include(<mkl_types.h>)
11 #ifndef EIGEN_USE_MKL_ALL
12 #define EIGEN_USE_MKL_ALL
15 #if __has_include(<Accelerate/Accelerate.h>)
22#define EIGEN_DEFAULT_IO_FORMAT \
23 Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ";\n", " ", "", "[", ";\n]")
25 #define EIGEN_USE_MKL_ALL
29#if defined(__NVCC__) && defined(MAGMA) && defined(MKL) && !defined(CPU)
30 #if !defined(CPU) && !defined(GPU)
33 #if defined(CPU) && !defined(DOUBLE)
63 #include <cuda/std/complex>
64 #include <magma_types.h>
67 using magmaFloatComplex::magmaFloatComplex;
68 template<
typename RealScalar>
70 this->x =
static_cast<float>(
real);
71 this->y =
static_cast<float>(
imag);
73 __host__ __device__
float&
real() {
return this->x; }
74 __host__ __device__
float real()
const {
return this->x; }
75 __host__ __device__
float&
imag() {
return this->y; }
76 __host__ __device__
float imag()
const {
return this->y; }
80 using magmaDoubleComplex::magmaDoubleComplex;
81 template<
typename RealScalar>
83 this->x =
static_cast<double>(
real);
84 this->y =
static_cast<double>(
imag);
86 __host__ __device__
double&
real() {
return this->x; }
87 __host__ __device__
double real()
const {
return this->x; }
88 __host__ __device__
double&
imag() {
return this->y; }
89 __host__ __device__
double imag()
const {
return this->y; }
96#elif !defined(MKL) && defined(ACCELERATE)
98 #include <Accelerate/Accelerate.h>
101 using __CLPK_complex::__CLPK_complex;
102 __host__ __device__
float&
real() {
return this->r; }
103 __host__ __device__
float real()
const {
return this->r; }
104 __host__ __device__
float&
imag() {
return this->i; }
105 __host__ __device__
float imag()
const {
return this->i; }
109 using __CLPK_doublecomplex::__CLPK_doublecomplex;
110 __host__ __device__
double&
real() {
return this->r; }
111 __host__ __device__
double real()
const {
return this->r; }
112 __host__ __device__
double&
imag() {
return this->i; }
113 __host__ __device__
double imag()
const {
return this->i; }
130template<
class T = Real_t>
136 template<
class U,
void* dummy = (&U::imag,
nullptr)>
137 static std::true_type
test(U*);
138 static std::false_type
test(...);
146template<
class T = Real_t>
156#if defined(GPU) && defined(MAGMA)
160#if defined(GPU) || defined(ACCELERATE)
174#define MKL_Complex8 Complex_t<float>
175#define MKL_Complex16 Complex_t<double>
178using cuda::std::conj;
180using cuda::std::fabs;
181using cuda::std::imag;
182using cuda::std::real;
191#if defined(GPU) || defined(ACCELERATE)
200template<
class T = Real_t>
202template<
class T = Real_t>
204template<
class T = Real_t>
213 struct NumTraits<
Complex_t<T>> : GenericNumTraits<Complex_t<T>> {
215 typedef typename NumTraits<T>::Literal
Literal;
218 RequireInitialization = NumTraits<Real>::RequireInitialization,
219 ReadCost = 2 * NumTraits<Real>::ReadCost,
220 AddCost = 2 * NumTraits<Real>::AddCost,
221 MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
225 return NumTraits<Real>::epsilon();
228 return NumTraits<Real>::dummy_precision();
230 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static inline int digits10() {
231 return NumTraits<Real>::digits10();
235 template<
typename charT,
typename traits,
typename RealType>
236 std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& strm,
238 constexpr size_t precision = 4;
239 constexpr size_t realWidth = precision + 7;
240 constexpr size_t imagWidth = realWidth;
241 constexpr size_t width = realWidth + imagWidth + 2;
242 constexpr double epsilon = 1.0e-8;
243 std::stringstream
buff(
"");
244 buff << std::showpos << std::scientific << std::setprecision(precision);
245 if(std::abs(c.real()) < epsilon && std::abs(c.imag()) < 1.0e-8)
247 else if(std::abs(c.real()) > epsilon && std::abs(c.imag()) < epsilon) {
buff << c.real(); }
248 else if(std::abs(c.real()) < epsilon && std::abs(c.imag()) > epsilon) {
249 buff << c.imag() <<
"*i";
251 else {
buff << c.real() << c.imag() <<
"*i"; }
252 strm << std::setw(width) <<
buff.str();
261 template<
class U,
void* dummy = (&U::onGPU,
nullptr)>
262 static std::true_type
test(U*);
263 static std::false_type
test(...);
281 GPUconfig(dim3 A, dim3 B,
size_t C = 0, magma_queue_t D = NULL)
303 cudaStream_t
stream()
const {
return magma_queue_get_cuda_stream(
m_queue); }
310 magma_int_t err_ = (err); \
312 std::cerr << "Error: " << #err << "\nfailed at " << __FILE__ << ":" \
313 << __LINE__ << ": error " << (long long)err_ << ": " \
314 << magma_strerror(err_) << std::endl; \
315 std::exit(EXIT_FAILURE); \
320 #define cuCHECK(call) \
322 const cudaError_t error = call; \
323 if(error != cudaSuccess) { \
324 printf("Error: %s:%d, ", __FILE__, __LINE__); \
325 printf("code:%d, reason: %s\n", error, cudaGetErrorString(error)); \
326 cudaDeviceSynchronize(); \
Real_t RealScalar
Definition Ensemble.cuh:14
Definition mytypes.hpp:147
__host__ __device__ Complex_t(magmaDoubleComplex const &z)
Definition mytypes.hpp:158
__host__ __device__ Complex_t(magmaFloatComplex const &z)
Definition mytypes.hpp:157
__host__ __device__ Complex_t(complex< T > const &z)
Definition mytypes.hpp:151
__host__ __device__ Complex_t(libDoubleComplex const &z)
Definition mytypes.hpp:162
__host__ __device__ Complex_t(Complex_t< U > const &z)
Definition mytypes.hpp:154
__host__ __device__ Complex_t(libFloatComplex const &z)
Definition mytypes.hpp:161
Definition mytypes.hpp:272
size_t m_shared
Definition mytypes.hpp:276
magma_queue_t m_queue
Definition mytypes.hpp:277
void dimBlock(int x, int y, int z)
Definition mytypes.hpp:291
dim3 m_dimGrid
Definition mytypes.hpp:274
dim3 dimGrid() const
Definition mytypes.hpp:299
dim3 dimBlock() const
Definition mytypes.hpp:300
GPUconfig(dim3 A, dim3 B, size_t C=0, magma_queue_t D=NULL)
Definition mytypes.hpp:281
void queue(magma_queue_t x)
Definition mytypes.hpp:297
magma_queue_t queue() const
Definition mytypes.hpp:302
void shared(size_t x)
Definition mytypes.hpp:296
dim3 m_dimBlock
Definition mytypes.hpp:275
size_t shared() const
Definition mytypes.hpp:301
GPUconfig(dim3 A, dim3 B, magma_queue_t D)
Definition mytypes.hpp:283
GPUconfig()
Definition mytypes.hpp:280
void dimGrid(int x, int y, int z)
Definition mytypes.hpp:286
cudaStream_t stream() const
Definition mytypes.hpp:303
Definition mytypes.hpp:135
static std::true_type test(U *)
static std::false_type test(...)
static constexpr bool value
Definition mytypes.hpp:141
Definition mytypes.hpp:78
__host__ __device__ double & imag()
Definition mytypes.hpp:88
__host__ __device__ double real() const
Definition mytypes.hpp:87
__host__ __device__ double imag() const
Definition mytypes.hpp:89
__host__ __device__ double & real()
Definition mytypes.hpp:86
__host__ __device__ libDoubleComplex(RealScalar real, RealScalar imag)
Definition mytypes.hpp:82
Definition mytypes.hpp:65
__host__ __device__ float imag() const
Definition mytypes.hpp:76
__host__ __device__ libFloatComplex(RealScalar real, RealScalar imag)
Definition mytypes.hpp:69
__host__ __device__ float & real()
Definition mytypes.hpp:73
__host__ __device__ float & imag()
Definition mytypes.hpp:75
__host__ __device__ float real() const
Definition mytypes.hpp:74
Definition mytypes.hpp:260
static constexpr bool value
Definition mytypes.hpp:266
static std::true_type test(U *)
static std::false_type test(...)
cuda::std::complex< double > myDoubleComplex
Definition mytypes.hpp:94
constexpr bool is_complex_v
Definition mytypes.hpp:144
double Real_t
Definition mytypes.hpp:37
MKL_INT Integer_t
Definition mytypes.hpp:359
__constant__ constexpr Complex_t< T > ComplexOne
Definition mytypes.hpp:203
__constant__ constexpr Complex_t< T > ComplexI
Definition mytypes.hpp:205
cuda::std::complex< float > myFloatComplex
Definition mytypes.hpp:93
__constant__ constexpr Complex_t< T > ComplexZero
Definition mytypes.hpp:201
cuda::std::complex< T > myComplex
Definition mytypes.hpp:92
constexpr bool on_GPU_v
Definition mytypes.hpp:269
std::conditional_t< std::is_same_v< T, float >, myFloatComplex, std::conditional_t< std::is_same_v< T, double >, myDoubleComplex, myComplex< T > > > complex
Definition mytypes.hpp:133
Definition OperatorSpace_test.cpp:3
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &strm, const std::complex< double > &c)
Definition OperatorSpace_test.cpp:6
T Real
Definition mytypes.hpp:214
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR int digits10()
Definition mytypes.hpp:230
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Real dummy_precision()
Definition mytypes.hpp:227
NumTraits< T >::Literal Literal
Definition mytypes.hpp:215
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR Real epsilon()
Definition mytypes.hpp:224
std::stringstream buff("")