ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
cuda.h
Go to the documentation of this file.
1#ifndef BASE_MACROS_CUDA_H_
2#define BASE_MACROS_CUDA_H_
3
4#include <cublas_v2.h>
5#include <cuda_runtime.h>
6#include <cusolverDn.h>
7#include <thrust/complex.h>
8
10
11#define THREADS_PER_BLOCK 256
12
13template <typename T>
15{
16 using type = T;
17};
18
19template <>
20struct GetTypeThrust<std::complex<float>>
21{
22 using type = thrust::complex<float>;
23};
24
25template <>
26struct GetTypeThrust<std::complex<double>>
27{
28 using type = thrust::complex<double>;
29};
30
31static inline cublasOperation_t GetCublasOperation(const char& trans)
32{
33 cublasOperation_t cutrans = {};
34 if (trans == 'N')
35 {
36 cutrans = CUBLAS_OP_N;
37 }
38 else if (trans == 'T')
39 {
40 cutrans = CUBLAS_OP_T;
41 }
42 else if (trans == 'C')
43 {
44 cutrans = CUBLAS_OP_C;
45 }
46 return cutrans;
47}
48
49template <typename T>
51{
52 static constexpr cudaDataType cuda_data_type = cudaDataType::CUDA_R_32F;
53};
54// Specializations of DataTypeToEnum for supported types.
55template <>
56struct GetTypeCuda<int>
57{
58 static constexpr cudaDataType cuda_data_type = cudaDataType::CUDA_R_32I;
59};
60template <>
61struct GetTypeCuda<float>
62{
63 static constexpr cudaDataType cuda_data_type = cudaDataType::CUDA_R_32F;
64};
65template <>
66struct GetTypeCuda<double>
67{
68 static constexpr cudaDataType cuda_data_type = cudaDataType::CUDA_R_64F;
69};
70template <>
71struct GetTypeCuda<int64_t>
72{
73 static constexpr cudaDataType cuda_data_type = cudaDataType::CUDA_R_64I;
74};
75template <>
76struct GetTypeCuda<std::complex<float>>
77{
78 static constexpr cudaDataType cuda_data_type = cudaDataType::CUDA_C_32F;
79};
80template <>
81struct GetTypeCuda<std::complex<double>>
82{
83 static constexpr cudaDataType cuda_data_type = cudaDataType::CUDA_C_64F;
84};
85
86static inline cublasFillMode_t cublas_fill_mode(const char& uplo)
87{
88 if (uplo == 'U' || uplo == 'u')
89 return CUBLAS_FILL_MODE_UPPER;
90 else if (uplo == 'L' || uplo == 'l')
91 return CUBLAS_FILL_MODE_LOWER;
92 else
93 throw std::runtime_error("cublas_fill_mode: unknown uplo");
94}
95
96static inline cublasDiagType_t cublas_diag_type(const char& diag)
97{
98 if (diag == 'U' || diag == 'u')
99 return CUBLAS_DIAG_UNIT;
100 else if (diag == 'N' || diag == 'n')
101 return CUBLAS_DIAG_NON_UNIT;
102 else
103 throw std::runtime_error("cublas_diag_type: unknown diag");
104}
105
106static inline cusolverEigMode_t cublas_eig_mode(const char& jobz)
107{
108 if (jobz == 'N' || jobz == 'n')
109 return CUSOLVER_EIG_MODE_NOVECTOR;
110 else if (jobz == 'V' || jobz == 'v')
111 return CUSOLVER_EIG_MODE_VECTOR;
112 else
113 throw std::runtime_error("cublas_eig_mode: unknown diag");
114}
115
116static inline cusolverEigType_t cublas_eig_type(const int& itype)
117{
118 if (itype == 1)
119 return CUSOLVER_EIG_TYPE_1;
120 else if (itype == 2)
121 return CUSOLVER_EIG_TYPE_2;
122 else
123 throw std::runtime_error("cublas_eig_mode: unknown diag");
124}
125
137static inline cusolverEigRange_t cublas_eig_range(const char& range)
138{
139 if (range == 'A' || range == 'a')
140 return CUSOLVER_EIG_RANGE_ALL;
141 else if (range == 'V' || range == 'v')
142 return CUSOLVER_EIG_RANGE_V;
143 else if (range == 'I' || range == 'i')
144 return CUSOLVER_EIG_RANGE_I;
145 else
146 throw std::runtime_error("cublas_eig_range: unknown range '" + std::string(1, range) + "'");
147}
148
149#endif // BASE_MACROS_CUDA_H_
std::complex< double > complex
Definition diago_cusolver.cpp:15
#define T
Definition exp.cpp:237
Definition cuda.h:51
static constexpr cudaDataType cuda_data_type
Definition cuda.h:52
thrust::complex< double > type
Definition cuda.h:28
thrust::complex< float > type
Definition cuda.h:22
Definition cuda.h:15
T type
Definition cuda.h:16