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 <regex>
9#include <string>
10#include <vector>
11#include <numeric>
12#include <complex>
13#include <utility>
14#include <iomanip>
15#include <iostream>
16#include <stdexcept>
17#include <algorithm>
18#include <unordered_map>
19#include <initializer_list>
20
22
23#if defined(__CUDACC__)
24#include <base/macros/cuda.h>
25#elif defined(__HIPCC__)
26#include <base/macros/rocm.h>
27#endif // defined(__CUDACC__) || defined(__HIPCC__)
28
29namespace container {
30
31template <typename T, int Accuracy>
32static inline bool element_compare(T& a, T& b) {
33 if (Accuracy <= 4) {
34 return (a == b) || (std::norm(a - b) < 1e-7);
35 }
36 else if (Accuracy <= 8) {
37 return (a == b) || (std::norm(a - b) < 1e-15);
38 }
39 else {
40 return (a == b);
41 }
42}
43
50enum class DataType {
51 DT_INVALID = 0,
52 DT_FLOAT = 1,
53 DT_DOUBLE = 2,
54 DT_INT = 3,
55 DT_INT64 = 4,
56 DT_COMPLEX = 5,
58// ... other data types
59};
60
65struct DEVICE_CPU;
66struct DEVICE_GPU;
67
68struct DEVICE_CPU {};
69struct DEVICE_GPU {};
73enum class DeviceType {
74 UnKnown = 0,
75 CpuDevice = 1,
76 GpuDevice = 2,
77};
78
87template <typename T>
89 using type = T;
90};
91
97template <>
98struct GetTypeReal<std::complex<float>> {
99 using type = float;
100};
101
107template <>
108struct GetTypeReal<std::complex<double>> {
109 using type = double;
110};
111
112template <typename T>
114 using type = T;
115};
116
117template <>
122
123template <>
128
129template <typename T>
131 using type = T;
132};
133
134template <>
136 using type = base_device::DEVICE_CPU;
137};
138
139template <>
141 using type = base_device::DEVICE_GPU;
142};
143
144
157template <typename T>
159 static constexpr DeviceType value = {};
160};
161// Specializations of DeviceTypeToEnum for supported devices.
162template <>
166template <>
170template <>
175template <>
180
193template <typename T>
195 static constexpr DataType value = {};
196};
197// Specializations of DataTypeToEnum for supported types.
198template <>
199struct DataTypeToEnum<int> {
200 static constexpr DataType value = DataType::DT_INT;
201};
202template <>
203struct DataTypeToEnum<float> {
205};
206template <>
207struct DataTypeToEnum<double> {
209};
210template <>
211struct DataTypeToEnum<int64_t> {
213};
214template <>
215struct DataTypeToEnum<std::complex<float>> {
217};
218template <>
219struct DataTypeToEnum<std::complex<double>> {
221};
222
223#if defined(__CUDACC__) || defined(__HIPCC__)
224template <>
225struct DataTypeToEnum<thrust::complex<float>> {
226 static constexpr DataType value = DataType::DT_COMPLEX;
227};
228
229template <>
230struct DataTypeToEnum<thrust::complex<double>> {
231 static constexpr DataType value = DataType::DT_COMPLEX_DOUBLE;
232};
233#endif // defined(__CUDACC__) || defined(__HIPCC__)
234
245std::ostream& operator<<(std::ostream& os, const DataType& data_type);
246
257std::ostream& operator<<(std::ostream& os, const DeviceType& memory_type);
258
259} // namespace container
260#endif // ATEN_CORE_TENSOR_TYPES_H_
std::complex< double > complex
Definition diago_cusolver.cpp:13
#define T
Definition exp.cpp:237
Definition device.cpp:21
Definition tensor.cpp:8
DataType
Enumeration of data types for tensors. The DataType enum lists the supported data types for tensors....
Definition tensor_types.h:50
@ DT_COMPLEX
32-bit complex *‍/
@ DT_INT64
64-bit integer *‍/
@ DT_FLOAT
Single-precision floating point *‍/.
@ DT_INT
32-bit integer *‍/
@ DT_DOUBLE
Double-precision floating point *‍/.
@ DT_INVALID
Invalid data type *‍/.
DeviceType
The type of memory used by an allocator.
Definition tensor_types.h:73
@ UnKnown
Memory type is unknown.
@ CpuDevice
Memory type is CPU.
@ GpuDevice
Memory type is GPU(CUDA or ROCm).
std::ostream & operator<<(std::ostream &os, const Tensor &tensor)
Overloaded operator<< for the Tensor class.
Definition tensor.cpp:329
base_device::DEVICE_CPU type
Definition tensor_types.h:136
base_device::DEVICE_GPU type
Definition tensor_types.h:141
Definition tensor_types.h:130
T type
Definition tensor_types.h:131
A tag type for identifying CPU and GPU devices.
Definition tensor_types.h:68
Definition tensor_types.h:69
Template struct for mapping a DataType to its corresponding enum value.
Definition tensor_types.h:194
static constexpr DataType value
Definition tensor_types.h:195
Template struct for mapping a Device Type to its corresponding enum value.
Definition tensor_types.h:158
static constexpr DeviceType value
Definition tensor_types.h:159
double type
Definition tensor_types.h:109
float type
Definition tensor_types.h:99
Template struct to determine the return type based on the input type.
Definition tensor_types.h:88
T type
Definition tensor_types.h:89
Definition tensor_types.h:113
T type
Definition tensor_types.h:114