monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
xpay.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace monolish {
4 
5 namespace {
6 template <typename F1, typename F2, typename F3>
7 void Dxpay_core(const F1 alpha, const F2 &x, F3 &y) {
8  Logger &logger = Logger::get_instance();
9  logger.func_in(monolish_func);
10 
11  // err
12  assert(util::is_same_size(x, y));
13  assert(util::is_same_device_mem_stat(x, y));
14 
15  const double *xd = x.data();
16  double *yd = y.data();
17  size_t size = x.size();
18  const size_t xoffset = x.get_offset();
19  const size_t yoffset = y.get_offset();
20 
21  if (x.get_device_mem_stat() == true) {
22 #if MONOLISH_USE_GPU
23 #pragma omp target teams distribute parallel for
24  for (size_t i = 0; i < size; i++) {
25  yd[i + yoffset] = xd[i + xoffset] + alpha * yd[i + yoffset];
26  }
27 #else
28  throw std::runtime_error(
29  "error USE_GPU is false, but get_device_mem_stat() == true");
30 #endif
31  } else {
32 #pragma omp parallel for
33  for (size_t i = 0; i < size; i++) {
34  yd[i + yoffset] = xd[i + xoffset] + alpha * yd[i + yoffset];
35  }
36  }
37  logger.func_out();
38 }
39 
40 template <typename F1, typename F2, typename F3>
41 void Sxpay_core(const F1 alpha, const F2 &x, F3 &y) {
42  Logger &logger = Logger::get_instance();
43  logger.func_in(monolish_func);
44 
45  // err
46  assert(util::is_same_size(x, y));
47  assert(util::is_same_device_mem_stat(x, y));
48 
49  const float *xd = x.data();
50  float *yd = y.data();
51  size_t size = x.size();
52  const size_t xoffset = x.get_offset();
53  const size_t yoffset = y.get_offset();
54 
55  if (x.get_device_mem_stat() == true) {
56 #if MONOLISH_USE_GPU
57 #pragma omp target teams distribute parallel for
58  for (size_t i = 0; i < size; i++) {
59  yd[i + yoffset] = xd[i + xoffset] + alpha * yd[i + yoffset];
60  }
61 #else
62  throw std::runtime_error(
63  "error USE_GPU is false, but get_device_mem_stat() == true");
64 #endif
65  } else {
66 #pragma omp parallel for
67  for (size_t i = 0; i < size; i++) {
68  yd[i + yoffset] = xd[i + xoffset] + alpha * yd[i + yoffset];
69  }
70  }
71  logger.func_out();
72 }
73 
74 } // namespace
75 
76 } // namespace monolish
monolish::util::is_same_size
bool is_same_size(const T &x, const U &y)
compare size of vector or 1Dview (same as is_same_structure())
Definition: monolish_common.hpp:358
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::util::is_same_device_mem_stat
bool is_same_device_mem_stat(const T &arg1, const U &arg2)
compare same device memory status
Definition: monolish_common.hpp:431
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42