monolish  0.14.0
MONOlithic LIner equation Solvers for Highly-parallel architecture
copy_vector.cpp
Go to the documentation of this file.
1 #include "../../../include/common/monolish_common.hpp"
2 #include "../../../include/common/monolish_dense.hpp"
3 #include "../../../include/common/monolish_logger.hpp"
4 #include "../../../include/common/monolish_matrix.hpp"
5 #include "../../../include/monolish_vml.hpp"
6 #include "../../internal/monolish_internal.hpp"
7 
8 namespace monolish {
9 
10 template <typename T> void vector<T>::operator=(const std::vector<T> &vec) {
11  Logger &logger = Logger::get_instance();
12  logger.util_in(monolish_func);
13 
14  resize(vec.size());
15  std::copy(vec.begin(), vec.end(), val.begin());
16 
17  logger.util_out();
18 }
19 
20 template void vector<double>::operator=(const std::vector<double> &vec);
21 template void vector<float>::operator=(const std::vector<float> &vec);
22 
23 template <typename T> void vector<T>::operator=(const vector<T> &vec) {
24  Logger &logger = Logger::get_instance();
25  logger.util_in(monolish_func);
26 
27  // err
28  assert(monolish::util::is_same_size(*this, vec));
29  assert(monolish::util::is_same_device_mem_stat(*this, vec));
30 
31  // gpu copy and recv
32  if (vec.get_device_mem_stat()) {
33 #if MONOLISH_USE_GPU
34  internal::vcopy(vec.val.size(), vec.val.data(), val.data(), true);
35 #endif
36  } else {
37  internal::vcopy(vec.val.size(), vec.val.data(), val.data(), false);
38  }
39 
40  logger.util_out();
41 }
42 
43 template void vector<double>::operator=(const vector<double> &vec);
44 template void vector<float>::operator=(const vector<float> &vec);
45 
46 template <typename T>
47 void vector<T>::operator=(const view1D<vector<T>, T> &vec) {
48  Logger &logger = Logger::get_instance();
49  logger.util_in(monolish_func);
50 
51  // err
52  assert(monolish::util::is_same_size(*this, vec));
53  assert(monolish::util::is_same_device_mem_stat(*this, vec));
54 
55  // gpu copy and recv
56  if (vec.get_device_mem_stat()) {
57 #if MONOLISH_USE_GPU
58  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(),
59  true);
60 #endif
61  } else {
62  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(),
63  false);
64  }
65 
66  logger.util_out();
67 }
68 
69 template void
70 vector<double>::operator=(const view1D<vector<double>, double> &vec);
71 template void vector<float>::operator=(const view1D<vector<float>, float> &vec);
72 
73 template <typename T>
74 void vector<T>::operator=(const view1D<matrix::Dense<T>, T> &vec) {
75  Logger &logger = Logger::get_instance();
76  logger.util_in(monolish_func);
77 
78  // err
79  assert(monolish::util::is_same_size(*this, vec));
80  assert(monolish::util::is_same_device_mem_stat(*this, vec));
81 
82  // gpu copy and recv
83  if (vec.get_device_mem_stat()) {
84 #if MONOLISH_USE_GPU
85  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(),
86  true);
87 #endif
88  } else {
89  internal::vcopy(vec.size(), vec.data() + vec.get_offset(), val.data(),
90  false);
91  }
92 
93  logger.util_out();
94 }
95 
96 template void
97 vector<double>::operator=(const view1D<matrix::Dense<double>, double> &vec);
98 template void
99 vector<float>::operator=(const view1D<matrix::Dense<float>, float> &vec);
100 } // 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::vector::operator=
void operator=(const vector< Float > &vec)
copy vector, It is same as copy ( Copy the memory on CPU and GPU )
monolish::blas::copy
void copy(const matrix::Dense< double > &A, matrix::Dense< double > &C)
Dense matrix copy (C=A)
Definition: dense_copy.cpp:25
monolish
Definition: monolish_matrix_blas.hpp:9
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42