monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
asum.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace monolish {
4 namespace {
5 template <typename F1> double Dasum_core(const F1 &x) {
6  Logger &logger = Logger::get_instance();
7  logger.func_in(monolish_func);
8 
9  double ans = 0;
10  const double *xd = x.data();
11  size_t size = x.size();
12  const size_t xoffset = x.get_offset();
13 
14  if (x.get_device_mem_stat() == true) {
15 #if MONOLISH_USE_GPU
16  cublasHandle_t h;
17  internal::check_CUDA(cublasCreate(&h));
18 #pragma omp target data use_device_ptr(xd)
19  { internal::check_CUDA(cublasDasum(h, size, xd + xoffset, 1, &ans)); }
20  cublasDestroy(h);
21 #else
22  throw std::runtime_error(
23  "error USE_GPU is false, but get_device_mem_stat() == true");
24 #endif
25  } else {
26  ans = cblas_dasum(size, xd + xoffset, 1);
27  }
28  logger.func_out();
29  return ans;
30 }
31 
32 template <typename F1> float Sasum_core(const F1 &x) {
33  Logger &logger = Logger::get_instance();
34  logger.func_in(monolish_func);
35 
36  float ans = 0;
37  const float *xd = x.data();
38  size_t size = x.size();
39  const size_t xoffset = x.get_offset();
40 
41  if (x.get_device_mem_stat() == true) {
42 #if MONOLISH_USE_GPU
43  cublasHandle_t h;
44  internal::check_CUDA(cublasCreate(&h));
45 #pragma omp target data use_device_ptr(xd)
46  { internal::check_CUDA(cublasSasum(h, size, xd + xoffset, 1, &ans)); }
47  cublasDestroy(h);
48 #else
49  throw std::runtime_error(
50  "error USE_GPU is false, but get_device_mem_stat() == true");
51 #endif
52  } else {
53  ans = cblas_sasum(size, xd + xoffset, 1);
54  }
55  logger.func_out();
56  return ans;
57 }
58 
59 } // namespace
60 } // namespace monolish
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42