monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
scal.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 namespace monolish {
4 
5 namespace {
6 template <typename F1, typename F2> void Dscal_core(const F1 alpha, F2 &x) {
7  Logger &logger = Logger::get_instance();
8  logger.func_in(monolish_func);
9 
10  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(cublasDscal(h, size, &alpha, xd + xoffset, 1)); }
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  cblas_dscal(size, alpha, xd + xoffset, 1);
27  }
28  logger.func_out();
29 }
30 
31 template <typename F1, typename F2> void Sscal_core(const F1 alpha, F2 &x) {
32  Logger &logger = Logger::get_instance();
33  logger.func_in(monolish_func);
34 
35  float *xd = x.data();
36  size_t size = x.size();
37  const size_t xoffset = x.get_offset();
38 
39  if (x.get_device_mem_stat() == true) {
40 #if MONOLISH_USE_GPU
41  cublasHandle_t h;
42  internal::check_CUDA(cublasCreate(&h));
43 #pragma omp target data use_device_ptr(xd)
44  { internal::check_CUDA(cublasSscal(h, size, &alpha, xd + xoffset, 1)); }
45  cublasDestroy(h);
46 #else
47  throw std::runtime_error(
48  "error USE_GPU is false, but get_device_mem_stat() == true");
49 #endif
50  } else {
51  cblas_sscal(size, alpha, xd + xoffset, 1);
52  }
53  logger.func_out();
54 }
55 
56 } // namespace
57 } // 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