monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
gpu_comm.cpp
Go to the documentation of this file.
1 #include "../../../include/monolish_blas.hpp"
2 #include "../../internal/monolish_internal.hpp"
3 
4 namespace monolish {
5 // vec ///////////////////////////////////////
6 
7 // send
8 template <typename T> void vector<T>::send() const {
9  Logger &logger = Logger::get_instance();
10  logger.util_in(monolish_func);
11 
12 #if MONOLISH_USE_GPU
13  const T *d = val.data();
14  const size_t N = val.size();
15 
16  if (gpu_status == true) {
17 #pragma omp target update to(d [0:N])
18  } else {
19 #pragma omp target enter data map(to : d [0:N])
20  gpu_status = true;
21  }
22 #endif
23  logger.util_out();
24 }
25 
26 // recv
27 template <typename T> void vector<T>::recv() {
28  Logger &logger = Logger::get_instance();
29  logger.util_in(monolish_func);
30 
31 #if MONOLISH_USE_GPU
32  if (gpu_status == true) {
33  T *d = val.data();
34  const size_t N = val.size();
35 
36 #pragma omp target exit data map(from : d [0:N])
37 
38  gpu_status = false;
39  }
40 #endif
41  logger.util_out();
42 }
43 
44 // nonfree_recv
45 template <typename T> void vector<T>::nonfree_recv() {
46  Logger &logger = Logger::get_instance();
47  logger.util_in(monolish_func);
48 
49 #if MONOLISH_USE_GPU
50  if (gpu_status == true) {
51  T *d = val.data();
52  const size_t N = val.size();
53 #pragma omp target update from(d [0:N])
54  }
55 #endif
56  logger.util_out();
57 }
58 
59 // device_free
60 template <typename T> void vector<T>::device_free() const {
61  Logger &logger = Logger::get_instance();
62  logger.util_in(monolish_func);
63 
64 #if MONOLISH_USE_GPU
65  if (gpu_status == true) {
66  const T *d = val.data();
67  const size_t N = val.size();
68 #pragma omp target exit data map(release : d [0:N])
69  gpu_status = false;
70  }
71 #endif
72  logger.util_out();
73 }
74 
75 template void vector<float>::send() const;
76 template void vector<double>::send() const;
77 
78 template void vector<float>::recv();
79 template void vector<double>::recv();
80 
81 template void vector<float>::nonfree_recv();
82 template void vector<double>::nonfree_recv();
83 
84 template void vector<float>::device_free() const;
85 template void vector<double>::device_free() const;
86 
87 // CRS ///////////////////////////////////
88 // send
89 template <typename T> void matrix::CRS<T>::send() const {
90  Logger &logger = Logger::get_instance();
91  logger.util_in(monolish_func);
92 
93 #if MONOLISH_USE_GPU
94  const T *vald = val.data();
95  const int *cold = col_ind.data();
96  const int *rowd = row_ptr.data();
97  const size_t N = get_row();
98  const size_t nnz = get_nnz();
99 
100  if (gpu_status == true) {
101 #pragma omp target update to(vald [0:nnz], cold [0:nnz], rowd [0:N + 1])
102  } else {
103 #pragma omp target enter data map(to \
104  : \
105  vald [0:nnz], cold [0:nnz], rowd [0:N + 1])
106  gpu_status = true;
107  }
108 #endif
109  logger.util_out();
110 }
111 
112 // recv
113 template <typename T> void matrix::CRS<T>::recv() {
114  Logger &logger = Logger::get_instance();
115  logger.util_in(monolish_func);
116 
117 #if MONOLISH_USE_GPU
118  if (gpu_status == true) {
119  T *vald = val.data();
120  int *cold = col_ind.data();
121  int *rowd = row_ptr.data();
122  size_t N = get_row();
123  size_t nnz = get_nnz();
124 
125 #pragma omp target exit data map(from \
126  : vald [0:nnz], cold [0:nnz], rowd [0:N + 1])
127  gpu_status = false;
128  }
129 #endif
130  logger.util_out();
131 }
132 
133 // nonfree_recv
134 template <typename T> void matrix::CRS<T>::nonfree_recv() {
135  Logger &logger = Logger::get_instance();
136  logger.util_in(monolish_func);
137 
138 #if MONOLISH_USE_GPU
139  if (gpu_status == true) {
140  T *vald = val.data();
141  int *cold = col_ind.data();
142  int *rowd = row_ptr.data();
143  size_t N = get_row();
144  size_t nnz = get_nnz();
145 
146 #pragma omp target update from(vald [0:nnz], cold [0:nnz], rowd [0:N + 1])
147  }
148 #endif
149  logger.util_out();
150 }
151 
152 // device_free
153 template <typename T> void matrix::CRS<T>::device_free() const {
154  Logger &logger = Logger::get_instance();
155  logger.util_in(monolish_func);
156 
157 #if MONOLISH_USE_GPU
158  if (gpu_status == true) {
159  const T *vald = val.data();
160  const int *cold = col_ind.data();
161  const int *rowd = row_ptr.data();
162  const size_t N = get_row();
163  const size_t nnz = get_nnz();
164 
165 #pragma omp target exit data map(release \
166  : vald [0:nnz], cold [0:nnz], rowd [0:N + 1])
167 
168  gpu_status = false;
169  }
170 #endif
171  logger.util_out();
172 }
173 template void matrix::CRS<float>::send() const;
174 template void matrix::CRS<double>::send() const;
175 
176 template void matrix::CRS<float>::recv();
177 template void matrix::CRS<double>::recv();
178 
179 template void matrix::CRS<float>::nonfree_recv();
180 template void matrix::CRS<double>::nonfree_recv();
181 
182 template void matrix::CRS<float>::device_free() const;
183 template void matrix::CRS<double>::device_free() const;
184 // Dense ///////////////////////////////////
185 // send
186 template <typename T> void matrix::Dense<T>::send() const {
187  Logger &logger = Logger::get_instance();
188  logger.util_in(monolish_func);
189 
190 #if MONOLISH_USE_GPU
191  const T *vald = val.data();
192  const size_t nnz = get_nnz();
193 
194  if (gpu_status == true) {
195 #pragma omp target update to(vald [0:nnz])
196  } else {
197 #pragma omp target enter data map(to : vald [0:nnz])
198  gpu_status = true;
199  }
200 #endif
201  logger.util_out();
202 }
203 
204 // recv
205 template <typename T> void matrix::Dense<T>::recv() {
206  Logger &logger = Logger::get_instance();
207  logger.util_in(monolish_func);
208 
209 #if MONOLISH_USE_GPU
210  if (gpu_status == true) {
211  T *vald = val.data();
212  size_t nnz = get_nnz();
213 
214 #pragma omp target exit data map(from : vald [0:nnz])
215  gpu_status = false;
216  }
217 #endif
218  logger.util_out();
219 }
220 
221 // nonfree_recv
222 template <typename T> void matrix::Dense<T>::nonfree_recv() {
223  Logger &logger = Logger::get_instance();
224  logger.util_in(monolish_func);
225 
226 #if MONOLISH_USE_GPU
227  if (gpu_status == true) {
228  T *vald = val.data();
229  size_t nnz = get_nnz();
230 
231 #pragma omp target update from(vald [0:nnz])
232  }
233 #endif
234  logger.util_out();
235 }
236 
237 // device_free
238 template <typename T> void matrix::Dense<T>::device_free() const {
239  Logger &logger = Logger::get_instance();
240  logger.util_in(monolish_func);
241 
242 #if MONOLISH_USE_GPU
243  if (gpu_status == true) {
244  const T *vald = val.data();
245  const size_t nnz = get_nnz();
246 
247 #pragma omp target exit data map(release : vald [0:nnz])
248 
249  gpu_status = false;
250  }
251 #endif
252  logger.util_out();
253 }
254 template void matrix::Dense<float>::send() const;
255 template void matrix::Dense<double>::send() const;
256 
257 template void matrix::Dense<float>::recv();
258 template void matrix::Dense<double>::recv();
259 
260 template void matrix::Dense<float>::nonfree_recv();
262 
263 template void matrix::Dense<float>::device_free() const;
264 template void matrix::Dense<double>::device_free() const;
265 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::matrix::CRS::nonfree_recv
void nonfree_recv()
recv. data to GPU (w/o free)
Definition: gpu_comm.cpp:134
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::Logger::util_out
void util_out()
Definition: logger_utils.cpp:123
monolish::matrix::Dense::nonfree_recv
void nonfree_recv()
recv. data to GPU (w/o free)
Definition: gpu_comm.cpp:222
monolish::Logger::util_in
void util_in(const std::string func_name)
Definition: logger_utils.cpp:113
monolish::vector::nonfree_recv
void nonfree_recv()
recv data from GPU (w/o free)
Definition: gpu_comm.cpp:45
monolish::matrix::Dense::recv
void recv()
recv. data to GPU, and free data on GPU
Definition: gpu_comm.cpp:205
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::matrix::Dense::device_free
void device_free() const
free data on GPU
Definition: gpu_comm.cpp:238
monolish::matrix::CRS::recv
void recv()
recv. data to GPU, and free data on GPU
Definition: gpu_comm.cpp:113
monolish::vector::device_free
void device_free() const
free data on GPU
Definition: gpu_comm.cpp:60
monolish::matrix::CRS::send
void send() const
send data to GPU
Definition: gpu_comm.cpp:89
monolish::vector::send
void send() const
send data to GPU
Definition: gpu_comm.cpp:8
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::vector::recv
void recv()
recv data from GPU, and free data on GPU
Definition: gpu_comm.cpp:27
monolish::matrix::CRS::device_free
void device_free() const
free data on GPU
Definition: gpu_comm.cpp:153
monolish::matrix::Dense::send
void send() const
send data to GPU
Definition: gpu_comm.cpp:186