forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathmemory_impl.cpp
More file actions
210 lines (183 loc) · 9.39 KB
/
Copy pathmemory_impl.cpp
File metadata and controls
210 lines (183 loc) · 9.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include <iostream>
#include <complex>
#include <string.h>
#include <ATen/kernels/memory.h>
namespace container {
namespace kernels {
template <typename T>
struct resize_memory<T, DEVICE_CPU> {
void operator()(T*& arr, const size_t& size, const char* /*record_in*/) {
if (arr != nullptr) {
free(arr);
}
arr = (T*) malloc(sizeof(T) * size);
}
};
template <typename T>
struct set_memory<T, DEVICE_CPU> {
void operator()(T* arr, const T& var, const size_t& size) {
for (size_t ii = 0; ii < size; ii++) {
arr[ii] = var;
}
}
};
template <typename T>
struct synchronize_memory<T, DEVICE_CPU, DEVICE_CPU> {
void operator()(
T* arr_out,
const T* arr_in,
const size_t& size)
{
memcpy(arr_out, arr_in, sizeof(T) * size);
}
};
template <typename T_out, typename T_in>
struct cast_memory<T_out, T_in, DEVICE_CPU, DEVICE_CPU> {
void operator()(
T_out* arr_out,
const T_in* arr_in,
const size_t& size)
{
for (int ii = 0; ii < size; ii++) {
arr_out[ii] = static_cast<T_out>(arr_in[ii]);
}
}
};
template <typename T>
struct delete_memory<T, DEVICE_CPU> {
void operator()(T* arr) {
free(arr);
}
};
template struct resize_memory<int, DEVICE_CPU>;
template struct resize_memory<int64_t, DEVICE_CPU>;
template struct resize_memory<float, DEVICE_CPU>;
template struct resize_memory<double, DEVICE_CPU>;
template struct resize_memory<std::complex<float>, DEVICE_CPU>;
template struct resize_memory<std::complex<double>, DEVICE_CPU>;
template struct set_memory<int, DEVICE_CPU>;
template struct set_memory<int64_t, DEVICE_CPU>;
template struct set_memory<float, DEVICE_CPU>;
template struct set_memory<double, DEVICE_CPU>;
template struct set_memory<std::complex<float>, DEVICE_CPU>;
template struct set_memory<std::complex<double>, DEVICE_CPU>;
template struct synchronize_memory<int, DEVICE_CPU, DEVICE_CPU>;
template struct synchronize_memory<int64_t, DEVICE_CPU, DEVICE_CPU>;
template struct synchronize_memory<float, DEVICE_CPU, DEVICE_CPU>;
template struct synchronize_memory<double, DEVICE_CPU, DEVICE_CPU>;
template struct synchronize_memory<std::complex<float>, DEVICE_CPU, DEVICE_CPU>;
template struct synchronize_memory<std::complex<double>, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<float, float, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<double, double, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<float, double, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<double, float, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<std::complex<float>, std::complex<float>, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<std::complex<double>, std::complex<double>, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<std::complex<float>, std::complex<double>, DEVICE_CPU, DEVICE_CPU>;
template struct cast_memory<std::complex<double>, std::complex<float>, DEVICE_CPU, DEVICE_CPU>;
template struct delete_memory<int, DEVICE_CPU>;
template struct delete_memory<int64_t, DEVICE_CPU>;
template struct delete_memory<float, DEVICE_CPU>;
template struct delete_memory<double, DEVICE_CPU>;
template struct delete_memory<std::complex<float>, DEVICE_CPU>;
template struct delete_memory<std::complex<double>, DEVICE_CPU>;
#if !(defined(__CUDA) || defined(__ROCM))
template <typename T>
struct resize_memory<T, DEVICE_GPU> {
void operator()(T*& arr, const size_t& size, const char* record_in = nullptr) {}
};
template <typename T>
struct set_memory<T, DEVICE_GPU> {
void operator()(T* arr, const T& var, const size_t& size) {}
};
template <typename T>
struct synchronize_memory<T, DEVICE_GPU, DEVICE_GPU> {
void operator()(T* arr_out, const T* arr_in, const size_t& size) {}
};
template <typename T>
struct synchronize_memory<T, DEVICE_GPU, DEVICE_CPU> {
void operator()(T* arr_out, const T* arr_in, const size_t& size) {}
};
template <typename T>
struct synchronize_memory<T, DEVICE_CPU, DEVICE_GPU> {
void operator()(T* arr_out, const T* arr_in, const size_t& size) {}
};
template <typename T_out, typename T_in>
struct cast_memory<T_out, T_in, DEVICE_GPU, DEVICE_GPU> {
void operator()(T_out* arr_out, const T_in* arr_in, const size_t& size) {}
};
template <typename T_out, typename T_in>
struct cast_memory<T_out, T_in, DEVICE_GPU, DEVICE_CPU> {
void operator()(T_out* arr_out, const T_in* arr_in, const size_t& size) {}
};
template <typename T_out, typename T_in>
struct cast_memory<T_out, T_in, DEVICE_CPU, DEVICE_GPU> {
void operator()(T_out* arr_out, const T_in* arr_in, const size_t& size) {}
};
template <typename T>
struct delete_memory<T, DEVICE_GPU> {
void operator()(T* arr) {}
};
template struct resize_memory<int, DEVICE_GPU>;
template struct resize_memory<int64_t, DEVICE_GPU>;
template struct resize_memory<float, DEVICE_GPU>;
template struct resize_memory<double, DEVICE_GPU>;
template struct resize_memory<std::complex<float>, DEVICE_GPU>;
template struct resize_memory<std::complex<double>, DEVICE_GPU>;
template struct set_memory<int, DEVICE_GPU>;
template struct set_memory<int64_t, DEVICE_GPU>;
template struct set_memory<float, DEVICE_GPU>;
template struct set_memory<double, DEVICE_GPU>;
template struct set_memory<std::complex<float>, DEVICE_GPU>;
template struct set_memory<std::complex<double>, DEVICE_GPU>;
template struct synchronize_memory<int, DEVICE_CPU, DEVICE_GPU>;
template struct synchronize_memory<int, DEVICE_GPU, DEVICE_CPU>;
template struct synchronize_memory<int, DEVICE_GPU, DEVICE_GPU>;
template struct synchronize_memory<int64_t, DEVICE_CPU, DEVICE_GPU>;
template struct synchronize_memory<int64_t, DEVICE_GPU, DEVICE_CPU>;
template struct synchronize_memory<int64_t, DEVICE_GPU, DEVICE_GPU>;
template struct synchronize_memory<float, DEVICE_CPU, DEVICE_GPU>;
template struct synchronize_memory<float, DEVICE_GPU, DEVICE_CPU>;
template struct synchronize_memory<float, DEVICE_GPU, DEVICE_GPU>;
template struct synchronize_memory<double, DEVICE_CPU, DEVICE_GPU>;
template struct synchronize_memory<double, DEVICE_GPU, DEVICE_CPU>;
template struct synchronize_memory<double, DEVICE_GPU, DEVICE_GPU>;
template struct synchronize_memory<std::complex<float>, DEVICE_CPU, DEVICE_GPU>;
template struct synchronize_memory<std::complex<float>, DEVICE_GPU, DEVICE_CPU>;
template struct synchronize_memory<std::complex<float>, DEVICE_GPU, DEVICE_GPU>;
template struct synchronize_memory<std::complex<double>, DEVICE_CPU, DEVICE_GPU>;
template struct synchronize_memory<std::complex<double>, DEVICE_GPU, DEVICE_CPU>;
template struct synchronize_memory<std::complex<double>, DEVICE_GPU, DEVICE_GPU>;
template struct cast_memory<float, float, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<double, double, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<float, double, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<double, float, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<float>, std::complex<float>, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<double>, std::complex<double>, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<float>, std::complex<double>, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<double>, std::complex<float>, container::DEVICE_GPU, container::DEVICE_GPU>;
template struct cast_memory<float, float, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<double, double, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<float, double, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<double, float, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<std::complex<float>, std::complex<float>, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<std::complex<double>, std::complex<double>, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<std::complex<float>, std::complex<double>, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<std::complex<double>, std::complex<float>, container::DEVICE_GPU, container::DEVICE_CPU>;
template struct cast_memory<float, float, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct cast_memory<double, double, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct cast_memory<float, double, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct cast_memory<double, float, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<float>, std::complex<float>, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<double>, std::complex<double>, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<float>, std::complex<double>, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct cast_memory<std::complex<double>, std::complex<float>, container::DEVICE_CPU, container::DEVICE_GPU>;
template struct delete_memory<int, DEVICE_GPU>;
template struct delete_memory<int64_t, DEVICE_GPU>;
template struct delete_memory<float, DEVICE_GPU>;
template struct delete_memory<double, DEVICE_GPU>;
template struct delete_memory<std::complex<float>, DEVICE_GPU>;
template struct delete_memory<std::complex<double>, DEVICE_GPU>;
#endif
} // namespace kernels
} // namespace container