ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
tensor_types.h
Go to the documentation of this file.
1
5#ifndef ATEN_CORE_TENSOR_TYPES_H_
6#define ATEN_CORE_TENSOR_TYPES_H_
7
8#include <string>
9#include <complex>
10#include <iostream>
11#include <stdexcept>
12
15
16// NOTE: Previously this file included <base/macros/cuda.h> or <base/macros/rocm.h>,
17// which transitively provided GetTypeThrust, GetTypeCuda, GetTypeRocm, etc.
18// Now replaced with <thrust/complex.h> which only provides thrust::complex type.
19// If you need GetTypeThrust/GetTypeCuda/GetTypeRocm, include <base/macros/cuda.h>
20// or <base/macros/rocm.h> directly in your .cpp file.
21// mohan add 20260605
22#if defined(__CUDACC__) || defined(__HIPCC__)
23#include <thrust/complex.h>
24#endif
25
26namespace container {
27
28template <typename T, int Accuracy>
29static inline bool element_compare(T& a, T& b) {
30 if (Accuracy <= 4) {
31 return (a == b) || (std::norm(a - b) < 1e-7);
32 }
33 else if (Accuracy <= 8) {
34 return (a == b) || (std::norm(a - b) < 1e-15);
35 }
36 else {
37 return (a == b);
38 }
39}
40
49template <typename T>
51 using type = T;
52};
53
59template <>
60struct GetTypeReal<std::complex<float>> {
61 using type = float;
62};
63
69template <>
70struct GetTypeReal<std::complex<double>> {
71 using type = double;
72};
73
74template <typename T>
76 using type = T;
77};
78
79template <>
84
85template <>
90
91template <typename T>
93 using type = T;
94};
95
96template <>
98 using type = base_device::DEVICE_CPU;
99};
100
101template <>
103 using type = base_device::DEVICE_GPU;
104};
105
106#if defined(__CUDACC__) || defined(__HIPCC__)
107template <>
108struct DataTypeToEnum<thrust::complex<float>> {
109 static constexpr DataType value = DataType::DT_COMPLEX;
110};
111
112template <>
113struct DataTypeToEnum<thrust::complex<double>> {
114 static constexpr DataType value = DataType::DT_COMPLEX_DOUBLE;
115};
116#endif // defined(__CUDACC__) || defined(__HIPCC__)
117
128std::ostream& operator<<(std::ostream& os, const DataType& data_type);
129
140std::ostream& operator<<(std::ostream& os, const DeviceType& memory_type);
141
142} // namespace container
143#endif // ATEN_CORE_TENSOR_TYPES_H_
#define complex
Definition elpa_new.h:28
#define T
Definition exp.cpp:237
Definition device.cpp:21
Definition tensor.cpp:8
DataType
Definition tensor_enums.h:15
@ DT_COMPLEX
Definition tensor_enums.h:21
@ DT_COMPLEX_DOUBLE
Definition tensor_enums.h:22
DeviceType
Definition tensor_enums.h:28
std::ostream & operator<<(std::ostream &os, const Tensor &tensor)
Overloaded operator<< for the Tensor class.
Definition tensor.cpp:330
base_device::DEVICE_CPU type
Definition tensor_types.h:98
base_device::DEVICE_GPU type
Definition tensor_types.h:103
Definition tensor_types.h:92
T type
Definition tensor_types.h:93
Definition tensor_enums.h:25
Definition tensor_enums.h:26
Definition tensor_enums.h:60
static constexpr DataType value
Definition tensor_enums.h:61
double type
Definition tensor_types.h:71
float type
Definition tensor_types.h:61
Template struct to determine the return type based on the input type.
Definition tensor_types.h:50
T type
Definition tensor_types.h:51
container::DEVICE_CPU type
Definition tensor_types.h:82
container::DEVICE_GPU type
Definition tensor_types.h:88
Definition tensor_types.h:75
T type
Definition tensor_types.h:76