52 #ifndef AMESOS2_KOKKOS_VIEW_COPY_ASSIGN_HPP
53 #define AMESOS2_KOKKOS_VIEW_COPY_ASSIGN_HPP
58 template<
class dst_t,
class src_t>
59 typename std::enable_if<static_cast<int>(dst_t::Rank) == 1>::type
60 update_dst_size(dst_t & dst,
const src_t & src) {
61 if(dst.extent(0) != src.extent(0)) {
62 dst = dst_t(Kokkos::ViewAllocateWithoutInitializing(
"dst"),
67 template<
class dst_t,
class src_t>
68 typename std::enable_if<static_cast<int>(dst_t::Rank) == 2>::type
69 update_dst_size(dst_t & dst,
const src_t & src) {
70 if(dst.extent(0) != src.extent(0) || dst.extent(1) != src.extent(1)) {
71 dst = dst_t(Kokkos::ViewAllocateWithoutInitializing(
"dst"),
72 src.extent(0), src.extent(1));
77 template<
class dst_t,
class src_t>
78 typename std::enable_if<std::is_same<
typename dst_t::value_type,
79 typename src_t::value_type>::value>::type
80 implement_copy_or_assign_same_mem_check_types(dst_t & dst,
const src_t & src) {
85 template<
class dst_t,
class src_t>
86 typename std::enable_if<!std::is_same<
typename dst_t::value_type,
87 typename src_t::value_type>::value>::type
88 implement_copy_or_assign_same_mem_check_types(dst_t & dst,
const src_t & src) {
89 update_dst_size(dst, src);
90 Kokkos::deep_copy(dst, src);
97 template<
class dst_t,
class src_t>
98 typename std::enable_if<std::is_same<
typename dst_t::memory_space,
99 typename src_t::memory_space>::value>::type
100 deep_copy_or_assign_view(dst_t & dst,
const src_t & src) {
101 implement_copy_or_assign_same_mem_check_types(dst, src);
104 template<
class dst_t,
class src_t>
105 typename std::enable_if<std::is_same<
typename dst_t::value_type,
106 typename src_t::value_type>::value>::type
107 implement_copy_or_assign_diff_mem_check_types(dst_t & dst,
const src_t & src) {
108 update_dst_size(dst, src);
109 Kokkos::deep_copy(dst, src);
112 template<
class dst_t,
class src_t>
113 typename std::enable_if<static_cast<int>(dst_t::Rank) == 1>::type
114 implement_copy_or_assign_diff_mem_diff_types_check_dim(dst_t & dst,
const src_t & src) {
115 Kokkos::View<typename dst_t::value_type*, typename src_t::execution_space>
116 intermediate(Kokkos::ViewAllocateWithoutInitializing(
"intermediate"), src.extent(0));
117 Kokkos::deep_copy(intermediate, src);
118 Kokkos::deep_copy(dst, intermediate);
121 template<
class dst_t,
class src_t>
122 typename std::enable_if<static_cast<int>(dst_t::Rank) == 2>::type
123 implement_copy_or_assign_diff_mem_diff_types_check_dim(dst_t & dst,
const src_t & src) {
124 Kokkos::View<typename dst_t::value_type**, Kokkos::LayoutLeft, typename src_t::execution_space>
125 intermediate(Kokkos::ViewAllocateWithoutInitializing(
"intermediate"), src.extent(0), src.extent(1));
126 Kokkos::deep_copy(intermediate, src);
127 Kokkos::deep_copy(dst, intermediate);
130 template<
class dst_t,
class src_t>
131 typename std::enable_if<!std::is_same<
typename dst_t::value_type,
132 typename src_t::value_type>::value>::type
133 implement_copy_or_assign_diff_mem_check_types(dst_t & dst,
const src_t & src) {
134 update_dst_size(dst, src);
137 implement_copy_or_assign_diff_mem_diff_types_check_dim(dst, src);
140 template<
class dst_t,
class src_t>
141 typename std::enable_if<!std::is_same<
typename dst_t::memory_space,
142 typename src_t::memory_space>::value>::type
143 deep_copy_or_assign_view(dst_t & dst,
const src_t & src) {
144 implement_copy_or_assign_diff_mem_check_types(dst, src);
149 #endif // AMESOS2_KOKKOS_VIEW_COPY_ASSIGN_HPP