5 template <
typename F1>
double Dasum_core(
const F1 &x) {
10 const double *xd = x.data();
11 size_t size = x.size();
12 const size_t xoffset = x.get_offset();
14 if (x.get_device_mem_stat() ==
true) {
15 #if MONOLISH_USE_NVIDIA_GPU
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)); }
22 throw std::runtime_error(
23 "error USE_GPU is false, but get_device_mem_stat() == true");
26 ans = cblas_dasum(size, xd + xoffset, 1);
31 ans = comm.Allreduce(ans);
38 template <
typename F1>
float Sasum_core(
const F1 &x) {
43 const float *xd = x.data();
44 size_t size = x.size();
45 const size_t xoffset = x.get_offset();
47 if (x.get_device_mem_stat() ==
true) {
48 #if MONOLISH_USE_NVIDIA_GPU
50 internal::check_CUDA(cublasCreate(&h));
51 #pragma omp target data use_device_ptr(xd)
52 { internal::check_CUDA(cublasSasum(h, size, xd + xoffset, 1, &ans)); }
55 throw std::runtime_error(
56 "error USE_GPU is false, but get_device_mem_stat() == true");
59 ans = cblas_sasum(size, xd + xoffset, 1);
64 ans = comm.Allreduce(ans);