18 #ifndef AMESOS2_KOKKOS_VIEW_COPY_ASSIGN_HPP
19 #define AMESOS2_KOKKOS_VIEW_COPY_ASSIGN_HPP
24 template<
class dst_t,
class src_t>
25 typename std::enable_if<static_cast<int>(dst_t::rank) == 1>::type
26 update_dst_size(dst_t & dst,
const src_t & src) {
27 if(dst.extent(0) != src.extent(0)) {
28 dst = dst_t(Kokkos::ViewAllocateWithoutInitializing(
"dst"),
33 template<
class dst_t,
class src_t>
34 typename std::enable_if<static_cast<int>(dst_t::rank) == 2>::type
35 update_dst_size(dst_t & dst,
const src_t & src) {
36 if(dst.extent(0) != src.extent(0) || dst.extent(1) != src.extent(1)) {
37 dst = dst_t(Kokkos::ViewAllocateWithoutInitializing(
"dst"),
38 src.extent(0), src.extent(1));
49 template<
class dst_t,
class src_t>
50 typename std::enable_if<std::is_same<
typename dst_t::value_type,
51 typename src_t::value_type>::value>::type
52 implement_copy_or_assign_same_mem_check_types(
53 [[maybe_unused]]
bool bInitialize,
71 template<
class dst_t,
class src_t>
72 void deep_copy_only(
bool bInitialize, dst_t & dst,
const src_t & src,
bool & bAssigned) {
73 update_dst_size(dst, src);
75 Kokkos::deep_copy(dst, src);
80 template<
class dst_t,
class src_t>
81 void deep_copy_only(dst_t & dst,
const src_t & src) {
83 deep_copy_only(
true, dst, src, bAssigned);
94 template<
class dst_t,
class src_t>
95 typename std::enable_if<!std::is_same<
typename dst_t::value_type,
96 typename src_t::value_type>::value>::type
97 implement_copy_or_assign_same_mem_check_types(
bool bInitialize, dst_t & dst,
const src_t & src,
bool & bAssigned) {
98 update_dst_size(dst, src);
100 Kokkos::deep_copy(dst, src);
109 template<
class dst_t,
class src_t>
110 typename std::enable_if<std::is_same<
typename dst_t::memory_space,
111 typename src_t::memory_space>::value>::type
112 deep_copy_or_assign_view(
bool bInitialize, dst_t & dst,
const src_t & src,
bool & bAssigned) {
113 implement_copy_or_assign_same_mem_check_types(bInitialize, dst, src, bAssigned);
118 template<
class dst_t,
class src_t>
119 typename std::enable_if<std::is_same<
typename dst_t::memory_space,
120 typename src_t::memory_space>::value>::type
121 deep_copy_or_assign_view(dst_t & dst,
const src_t & src) {
123 implement_copy_or_assign_same_mem_check_types(
true, dst, src, bAssigned);
126 template<
class dst_t,
class src_t>
127 typename std::enable_if<std::is_same<
typename dst_t::value_type,
128 typename src_t::value_type>::value>::type
129 implement_copy_or_assign_diff_mem_check_types(
bool bInitialize, dst_t & dst,
const src_t & src,
bool & bAssigned) {
130 update_dst_size(dst, src);
132 Kokkos::deep_copy(dst, src);
137 template<
class dst_t,
class src_t>
138 typename std::enable_if<static_cast<int>(dst_t::rank) == 1>::type
139 implement_copy_or_assign_diff_mem_diff_types_check_dim(dst_t & dst,
const src_t & src) {
140 Kokkos::View<typename dst_t::value_type*, typename src_t::execution_space>
141 intermediate(Kokkos::ViewAllocateWithoutInitializing(
"intermediate"), src.extent(0));
142 Kokkos::deep_copy(intermediate, src);
143 Kokkos::deep_copy(dst, intermediate);
146 template<
class dst_t,
class src_t>
147 typename std::enable_if<static_cast<int>(dst_t::rank) == 2>::type
148 implement_copy_or_assign_diff_mem_diff_types_check_dim(dst_t & dst,
const src_t & src) {
149 Kokkos::View<typename dst_t::value_type**, Kokkos::LayoutLeft, typename src_t::execution_space>
150 intermediate(Kokkos::ViewAllocateWithoutInitializing(
"intermediate"), src.extent(0), src.extent(1));
151 Kokkos::deep_copy(intermediate, src);
152 Kokkos::deep_copy(dst, intermediate);
155 template<
class dst_t,
class src_t>
156 typename std::enable_if<!std::is_same<
typename dst_t::value_type,
157 typename src_t::value_type>::value>::type
158 implement_copy_or_assign_diff_mem_check_types(
bool bInitialize, dst_t & dst,
const src_t & src,
bool & bAssigned) {
159 update_dst_size(dst, src);
164 implement_copy_or_assign_diff_mem_diff_types_check_dim(dst, src);
168 template<
class dst_t,
class src_t>
169 typename std::enable_if<!std::is_same<
typename dst_t::memory_space,
170 typename src_t::memory_space>::value>::type
171 deep_copy_or_assign_view(
bool bInitialize, dst_t & dst,
const src_t & src,
bool & bAssigned) {
172 implement_copy_or_assign_diff_mem_check_types(bInitialize, dst, src, bAssigned);
177 template<
class dst_t,
class src_t>
178 typename std::enable_if<!std::is_same<
typename dst_t::memory_space,
179 typename src_t::memory_space>::value>::type
180 deep_copy_or_assign_view(dst_t & dst,
const src_t & src) {
182 implement_copy_or_assign_diff_mem_check_types(
true, dst, src, bAssigned);
187 #endif // AMESOS2_KOKKOS_VIEW_COPY_ASSIGN_HPP