17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22#ifndef KOKKOS_COPYVIEWS_HPP_
23#define KOKKOS_COPYVIEWS_HPP_
26#include <KokkosExp_MDRangePolicy.hpp>
36template <
class Layout>
37struct ViewFillLayoutSelector {};
40struct ViewFillLayoutSelector<Kokkos::LayoutLeft> {
41 static const Kokkos::Iterate iterate = Kokkos::Iterate::Left;
45struct ViewFillLayoutSelector<Kokkos::LayoutRight> {
46 static const Kokkos::Iterate iterate = Kokkos::Iterate::Right;
55template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
56struct ViewFill<ViewType, Layout, ExecSpace, 0, iType> {
57 using ST =
typename ViewType::non_const_value_type;
58 ViewFill(
const ViewType& a,
const ST& val,
const ExecSpace& space) {
60 ExecSpace>(space, a.data(), &val,
sizeof(ST));
64template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
65struct ViewFill<ViewType, Layout, ExecSpace, 1, iType> {
67 typename ViewType::const_value_type val;
70 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
71 const ExecSpace& space)
73 Kokkos::parallel_for(
"Kokkos::ViewFill-1D",
74 policy_type(space, 0, a.extent(0)), *
this);
77 KOKKOS_INLINE_FUNCTION
78 void operator()(
const iType& i)
const { a(i) = val; };
81template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
82struct ViewFill<ViewType, Layout, ExecSpace, 2, iType> {
84 typename ViewType::const_value_type val;
86 using iterate_type = Kokkos::Rank<2, ViewFillLayoutSelector<Layout>::iterate,
87 ViewFillLayoutSelector<Layout>::iterate>;
89 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
91 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
92 const ExecSpace& space)
94 Kokkos::parallel_for(
"Kokkos::ViewFill-2D",
95 policy_type(space, {0, 0}, {a.extent(0), a.extent(1)}),
99 KOKKOS_INLINE_FUNCTION
100 void operator()(
const iType& i0,
const iType& i1)
const { a(i0, i1) = val; };
103template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
104struct ViewFill<ViewType, Layout, ExecSpace, 3, iType> {
106 typename ViewType::const_value_type val;
108 using iterate_type = Kokkos::Rank<3, ViewFillLayoutSelector<Layout>::iterate,
109 ViewFillLayoutSelector<Layout>::iterate>;
111 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
113 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
114 const ExecSpace& space)
116 Kokkos::parallel_for(
117 "Kokkos::ViewFill-3D",
118 policy_type(space, {0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2)}),
122 KOKKOS_INLINE_FUNCTION
123 void operator()(
const iType& i0,
const iType& i1,
const iType& i2)
const {
128template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
129struct ViewFill<ViewType, Layout, ExecSpace, 4, iType> {
131 typename ViewType::const_value_type val;
133 using iterate_type = Kokkos::Rank<4, ViewFillLayoutSelector<Layout>::iterate,
134 ViewFillLayoutSelector<Layout>::iterate>;
136 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
138 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
139 const ExecSpace& space)
141 Kokkos::parallel_for(
142 "Kokkos::ViewFill-4D",
143 policy_type(space, {0, 0, 0, 0},
144 {a.extent(0), a.extent(1), a.extent(2), a.extent(3)}),
148 KOKKOS_INLINE_FUNCTION
149 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
150 const iType& i3)
const {
151 a(i0, i1, i2, i3) = val;
155template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
156struct ViewFill<ViewType, Layout, ExecSpace, 5, iType> {
158 typename ViewType::const_value_type val;
160 using iterate_type = Kokkos::Rank<5, ViewFillLayoutSelector<Layout>::iterate,
161 ViewFillLayoutSelector<Layout>::iterate>;
163 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
165 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
166 const ExecSpace& space)
168 Kokkos::parallel_for(
"Kokkos::ViewFill-5D",
169 policy_type(space, {0, 0, 0, 0, 0},
170 {a.extent(0), a.extent(1), a.extent(2),
171 a.extent(3), a.extent(4)}),
175 KOKKOS_INLINE_FUNCTION
176 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
177 const iType& i3,
const iType& i4)
const {
178 a(i0, i1, i2, i3, i4) = val;
182template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
183struct ViewFill<ViewType, Layout, ExecSpace, 6, iType> {
185 typename ViewType::const_value_type val;
187 using iterate_type = Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
188 ViewFillLayoutSelector<Layout>::iterate>;
190 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
192 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
193 const ExecSpace& space)
195 Kokkos::parallel_for(
"Kokkos::ViewFill-6D",
196 policy_type(space, {0, 0, 0, 0, 0, 0},
197 {a.extent(0), a.extent(1), a.extent(2),
198 a.extent(3), a.extent(4), a.extent(5)}),
202 KOKKOS_INLINE_FUNCTION
203 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
204 const iType& i3,
const iType& i4,
const iType& i5)
const {
205 a(i0, i1, i2, i3, i4, i5) = val;
209template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
210struct ViewFill<ViewType, Layout, ExecSpace, 7, iType> {
212 typename ViewType::const_value_type val;
214 using iterate_type = Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
215 ViewFillLayoutSelector<Layout>::iterate>;
217 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
219 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
220 const ExecSpace& space)
222 Kokkos::parallel_for(
"Kokkos::ViewFill-7D",
223 policy_type(space, {0, 0, 0, 0, 0, 0},
224 {a.extent(0), a.extent(1), a.extent(2),
225 a.extent(3), a.extent(5), a.extent(6)}),
229 KOKKOS_INLINE_FUNCTION
230 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
231 const iType& i4,
const iType& i5,
const iType& i6)
const {
232 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
233 a(i0, i1, i2, i3, i4, i5, i6) = val;
237template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
238struct ViewFill<ViewType, Layout, ExecSpace, 8, iType> {
240 typename ViewType::const_value_type val;
242 using iterate_type = Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
243 ViewFillLayoutSelector<Layout>::iterate>;
245 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
247 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
248 const ExecSpace& space)
250 Kokkos::parallel_for(
"Kokkos::ViewFill-8D",
251 policy_type(space, {0, 0, 0, 0, 0, 0},
252 {a.extent(0), a.extent(1), a.extent(3),
253 a.extent(5), a.extent(6), a.extent(7)}),
257 KOKKOS_INLINE_FUNCTION
258 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
259 const iType& i5,
const iType& i6,
const iType& i7)
const {
260 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
261 for (iType i4 = 0; i4 < iType(a.extent(4)); i4++)
262 a(i0, i1, i2, i3, i4, i5, i6, i7) = val;
266template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
268struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 1, iType> {
273 using value_type =
typename ViewTypeA::value_type;
275 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
276 const ExecSpace space = ExecSpace())
278 Kokkos::parallel_for(
"Kokkos::ViewCopy-1D",
279 policy_type(space, 0, a.extent(0)), *
this);
282 KOKKOS_INLINE_FUNCTION
283 void operator()(
const iType& i0)
const {
284 a(i0) =
static_cast<value_type
>(b(i0));
288template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
290struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 2, iType> {
293 static const Kokkos::Iterate outer_iteration_pattern =
294 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
295 static const Kokkos::Iterate inner_iteration_pattern =
296 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
298 Kokkos::Rank<2, outer_iteration_pattern, inner_iteration_pattern>;
300 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
301 using value_type =
typename ViewTypeA::value_type;
303 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
304 const ExecSpace space = ExecSpace())
306 Kokkos::parallel_for(
"Kokkos::ViewCopy-2D",
307 policy_type(space, {0, 0}, {a.extent(0), a.extent(1)}),
311 KOKKOS_INLINE_FUNCTION
312 void operator()(
const iType& i0,
const iType& i1)
const {
313 a(i0, i1) =
static_cast<value_type
>(b(i0, i1));
317template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
319struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 3, iType> {
323 static const Kokkos::Iterate outer_iteration_pattern =
324 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
325 static const Kokkos::Iterate inner_iteration_pattern =
326 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
328 Kokkos::Rank<3, outer_iteration_pattern, inner_iteration_pattern>;
330 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
331 using value_type =
typename ViewTypeA::value_type;
333 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
334 const ExecSpace space = ExecSpace())
336 Kokkos::parallel_for(
337 "Kokkos::ViewCopy-3D",
338 policy_type(space, {0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2)}),
342 KOKKOS_INLINE_FUNCTION
343 void operator()(
const iType& i0,
const iType& i1,
const iType& i2)
const {
344 a(i0, i1, i2) =
static_cast<value_type
>(b(i0, i1, i2));
348template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
350struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 4, iType> {
354 static const Kokkos::Iterate outer_iteration_pattern =
355 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
356 static const Kokkos::Iterate inner_iteration_pattern =
357 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
359 Kokkos::Rank<4, outer_iteration_pattern, inner_iteration_pattern>;
361 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
363 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
364 const ExecSpace space = ExecSpace())
366 Kokkos::parallel_for(
367 "Kokkos::ViewCopy-4D",
368 policy_type(space, {0, 0, 0, 0},
369 {a.extent(0), a.extent(1), a.extent(2), a.extent(3)}),
373 KOKKOS_INLINE_FUNCTION
374 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
375 const iType& i3)
const {
376 a(i0, i1, i2, i3) = b(i0, i1, i2, i3);
380template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
382struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 5, iType> {
386 static const Kokkos::Iterate outer_iteration_pattern =
387 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
388 static const Kokkos::Iterate inner_iteration_pattern =
389 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
391 Kokkos::Rank<5, outer_iteration_pattern, inner_iteration_pattern>;
393 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
395 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
396 const ExecSpace space = ExecSpace())
398 Kokkos::parallel_for(
"Kokkos::ViewCopy-5D",
399 policy_type(space, {0, 0, 0, 0, 0},
400 {a.extent(0), a.extent(1), a.extent(2),
401 a.extent(3), a.extent(4)}),
405 KOKKOS_INLINE_FUNCTION
406 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
407 const iType& i3,
const iType& i4)
const {
408 a(i0, i1, i2, i3, i4) = b(i0, i1, i2, i3, i4);
412template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
414struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 6, iType> {
418 static const Kokkos::Iterate outer_iteration_pattern =
419 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
420 static const Kokkos::Iterate inner_iteration_pattern =
421 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
423 Kokkos::Rank<6, outer_iteration_pattern, inner_iteration_pattern>;
425 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
427 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
428 const ExecSpace space = ExecSpace())
430 Kokkos::parallel_for(
"Kokkos::ViewCopy-6D",
431 policy_type(space, {0, 0, 0, 0, 0, 0},
432 {a.extent(0), a.extent(1), a.extent(2),
433 a.extent(3), a.extent(4), a.extent(5)}),
437 KOKKOS_INLINE_FUNCTION
438 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
439 const iType& i3,
const iType& i4,
const iType& i5)
const {
440 a(i0, i1, i2, i3, i4, i5) = b(i0, i1, i2, i3, i4, i5);
444template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
446struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 7, iType> {
450 static const Kokkos::Iterate outer_iteration_pattern =
451 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
452 static const Kokkos::Iterate inner_iteration_pattern =
453 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
455 Kokkos::Rank<6, outer_iteration_pattern, inner_iteration_pattern>;
457 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
459 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
460 const ExecSpace space = ExecSpace())
462 Kokkos::parallel_for(
"Kokkos::ViewCopy-7D",
463 policy_type(space, {0, 0, 0, 0, 0, 0},
464 {a.extent(0), a.extent(1), a.extent(3),
465 a.extent(4), a.extent(5), a.extent(6)}),
469 KOKKOS_INLINE_FUNCTION
470 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
471 const iType& i4,
const iType& i5,
const iType& i6)
const {
472 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
473 a(i0, i1, i2, i3, i4, i5, i6) = b(i0, i1, i2, i3, i4, i5, i6);
477template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
479struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 8, iType> {
483 static const Kokkos::Iterate outer_iteration_pattern =
484 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
485 static const Kokkos::Iterate inner_iteration_pattern =
486 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
488 Kokkos::Rank<6, outer_iteration_pattern, inner_iteration_pattern>;
490 Kokkos::MDRangePolicy<ExecSpace, iterate_type, Kokkos::IndexType<iType>>;
492 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
493 const ExecSpace space = ExecSpace())
495 Kokkos::parallel_for(
"Kokkos::ViewCopy-8D",
496 policy_type(space, {0, 0, 0, 0, 0, 0},
497 {a.extent(0), a.extent(1), a.extent(3),
498 a.extent(5), a.extent(6), a.extent(7)}),
502 KOKKOS_INLINE_FUNCTION
503 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
504 const iType& i5,
const iType& i6,
const iType& i7)
const {
505 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
506 for (iType i4 = 0; i4 < iType(a.extent(4)); i4++)
507 a(i0, i1, i2, i3, i4, i5, i6, i7) = b(i0, i1, i2, i3, i4, i5, i6, i7);
517template <
class ExecutionSpace,
class DstType,
class SrcType>
518void view_copy(
const ExecutionSpace& space,
const DstType& dst,
519 const SrcType& src) {
520 using dst_memory_space =
typename DstType::memory_space;
521 using src_memory_space =
typename SrcType::memory_space;
532 if (!(ExecCanAccessSrc && ExecCanAccessDst)) {
533 Kokkos::Impl::throw_runtime_exception(
534 "Kokkos::Impl::view_copy called with invalid execution space");
537 int64_t strides[DstType::Rank + 1];
539 Kokkos::Iterate iterate;
540 if (Kokkos::is_layouttiled<typename DstType::array_layout>::value) {
541 iterate = Kokkos::layout_iterate_type_selector<
542 typename DstType::array_layout>::outer_iteration_pattern;
543 }
else if (std::is_same<
typename DstType::array_layout,
545 iterate = Kokkos::Iterate::Right;
546 }
else if (std::is_same<
typename DstType::array_layout,
548 iterate = Kokkos::Iterate::Left;
549 }
else if (std::is_same<
typename DstType::array_layout,
551 if (strides[0] > strides[DstType::Rank - 1])
552 iterate = Kokkos::Iterate::Right;
554 iterate = Kokkos::Iterate::Left;
556 if (std::is_same<
typename DstType::execution_space::array_layout,
558 iterate = Kokkos::Iterate::Right;
560 iterate = Kokkos::Iterate::Left;
563 if ((dst.span() >=
size_t(std::numeric_limits<int>::max())) ||
564 (src.span() >=
size_t(std::numeric_limits<int>::max()))) {
565 if (iterate == Kokkos::Iterate::Right)
566 Kokkos::Impl::ViewCopy<
567 typename DstType::uniform_runtime_nomemspace_type,
568 typename SrcType::uniform_runtime_const_nomemspace_type,
572 Kokkos::Impl::ViewCopy<
573 typename DstType::uniform_runtime_nomemspace_type,
574 typename SrcType::uniform_runtime_const_nomemspace_type,
578 if (iterate == Kokkos::Iterate::Right)
579 Kokkos::Impl::ViewCopy<
580 typename DstType::uniform_runtime_nomemspace_type,
581 typename SrcType::uniform_runtime_const_nomemspace_type,
585 Kokkos::Impl::ViewCopy<
586 typename DstType::uniform_runtime_nomemspace_type,
587 typename SrcType::uniform_runtime_const_nomemspace_type,
594template <
class DstType,
class SrcType>
595void view_copy(
const DstType& dst,
const SrcType& src) {
596 using dst_execution_space =
typename DstType::execution_space;
597 using src_execution_space =
typename SrcType::execution_space;
598 using dst_memory_space =
typename DstType::memory_space;
599 using src_memory_space =
typename SrcType::memory_space;
602 DstExecCanAccessSrc =
604 src_memory_space>::accessible
608 SrcExecCanAccessDst =
610 dst_memory_space>::accessible
613 if (!DstExecCanAccessSrc && !SrcExecCanAccessDst) {
615 "Error: Kokkos::deep_copy with no available copy mechanism: ");
616 message += src.label();
618 message += dst.label();
619 Kokkos::Impl::throw_runtime_exception(message);
623 int64_t strides[DstType::Rank + 1];
625 Kokkos::Iterate iterate;
626 if (Kokkos::is_layouttiled<typename DstType::array_layout>::value) {
627 iterate = Kokkos::layout_iterate_type_selector<
628 typename DstType::array_layout>::outer_iteration_pattern;
629 }
else if (std::is_same<
typename DstType::array_layout,
631 iterate = Kokkos::Iterate::Right;
632 }
else if (std::is_same<
typename DstType::array_layout,
634 iterate = Kokkos::Iterate::Left;
635 }
else if (std::is_same<
typename DstType::array_layout,
637 if (strides[0] > strides[DstType::Rank - 1])
638 iterate = Kokkos::Iterate::Right;
640 iterate = Kokkos::Iterate::Left;
642 if (std::is_same<
typename DstType::execution_space::array_layout,
644 iterate = Kokkos::Iterate::Right;
646 iterate = Kokkos::Iterate::Left;
649 if ((dst.span() >=
size_t(std::numeric_limits<int>::max())) ||
650 (src.span() >=
size_t(std::numeric_limits<int>::max()))) {
651 if (DstExecCanAccessSrc) {
652 if (iterate == Kokkos::Iterate::Right)
653 Kokkos::Impl::ViewCopy<
654 typename DstType::uniform_runtime_nomemspace_type,
655 typename SrcType::uniform_runtime_const_nomemspace_type,
659 Kokkos::Impl::ViewCopy<
660 typename DstType::uniform_runtime_nomemspace_type,
661 typename SrcType::uniform_runtime_const_nomemspace_type,
665 if (iterate == Kokkos::Iterate::Right)
666 Kokkos::Impl::ViewCopy<
667 typename DstType::uniform_runtime_nomemspace_type,
668 typename SrcType::uniform_runtime_const_nomemspace_type,
672 Kokkos::Impl::ViewCopy<
673 typename DstType::uniform_runtime_nomemspace_type,
674 typename SrcType::uniform_runtime_const_nomemspace_type,
679 if (DstExecCanAccessSrc) {
680 if (iterate == Kokkos::Iterate::Right)
681 Kokkos::Impl::ViewCopy<
682 typename DstType::uniform_runtime_nomemspace_type,
683 typename SrcType::uniform_runtime_const_nomemspace_type,
687 Kokkos::Impl::ViewCopy<
688 typename DstType::uniform_runtime_nomemspace_type,
689 typename SrcType::uniform_runtime_const_nomemspace_type,
693 if (iterate == Kokkos::Iterate::Right)
694 Kokkos::Impl::ViewCopy<
695 typename DstType::uniform_runtime_nomemspace_type,
696 typename SrcType::uniform_runtime_const_nomemspace_type,
700 Kokkos::Impl::ViewCopy<
701 typename DstType::uniform_runtime_nomemspace_type,
702 typename SrcType::uniform_runtime_const_nomemspace_type,
709template <
class DstType,
class SrcType,
int Rank,
class... Args>
712template <
class DstType,
class SrcType,
class Arg0,
class... Args>
713struct CommonSubview<DstType, SrcType, 1, Arg0, Args...> {
714 using dst_subview_type =
typename Kokkos::Subview<DstType, Arg0>;
715 using src_subview_type =
typename Kokkos::Subview<SrcType, Arg0>;
716 dst_subview_type dst_sub;
717 src_subview_type src_sub;
718 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
720 : dst_sub(dst, arg0), src_sub(src, arg0) {}
723template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class... Args>
724struct CommonSubview<DstType, SrcType, 2, Arg0, Arg1, Args...> {
725 using dst_subview_type =
typename Kokkos::Subview<DstType, Arg0, Arg1>;
726 using src_subview_type =
typename Kokkos::Subview<SrcType, Arg0, Arg1>;
727 dst_subview_type dst_sub;
728 src_subview_type src_sub;
729 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
730 const Arg1& arg1, Args...)
731 : dst_sub(dst, arg0, arg1), src_sub(src, arg0, arg1) {}
734template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
736struct CommonSubview<DstType, SrcType, 3, Arg0, Arg1, Arg2, Args...> {
737 using dst_subview_type =
typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2>;
738 using src_subview_type =
typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2>;
739 dst_subview_type dst_sub;
740 src_subview_type src_sub;
741 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
742 const Arg1& arg1,
const Arg2& arg2, Args...)
743 : dst_sub(dst, arg0, arg1, arg2), src_sub(src, arg0, arg1, arg2) {}
746template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
747 class Arg3,
class... Args>
748struct CommonSubview<DstType, SrcType, 4, Arg0, Arg1, Arg2, Arg3, Args...> {
749 using dst_subview_type =
750 typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3>;
751 using src_subview_type =
752 typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3>;
753 dst_subview_type dst_sub;
754 src_subview_type src_sub;
755 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
756 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
758 : dst_sub(dst, arg0, arg1, arg2, arg3),
759 src_sub(src, arg0, arg1, arg2, arg3) {}
762template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
763 class Arg3,
class Arg4,
class... Args>
764struct CommonSubview<DstType, SrcType, 5, Arg0, Arg1, Arg2, Arg3, Arg4,
766 using dst_subview_type =
767 typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4>;
768 using src_subview_type =
769 typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4>;
770 dst_subview_type dst_sub;
771 src_subview_type src_sub;
772 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
773 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
774 const Arg4& arg4,
const Args...)
775 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4),
776 src_sub(src, arg0, arg1, arg2, arg3, arg4) {}
779template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
780 class Arg3,
class Arg4,
class Arg5,
class... Args>
781struct CommonSubview<DstType, SrcType, 6, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
783 using dst_subview_type =
784 typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5>;
785 using src_subview_type =
786 typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5>;
787 dst_subview_type dst_sub;
788 src_subview_type src_sub;
789 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
790 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
791 const Arg4& arg4,
const Arg5& arg5,
const Args...)
792 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4, arg5),
793 src_sub(src, arg0, arg1, arg2, arg3, arg4, arg5) {}
796template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
797 class Arg3,
class Arg4,
class Arg5,
class Arg6,
class... Args>
798struct CommonSubview<DstType, SrcType, 7, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
800 using dst_subview_type =
typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2,
801 Arg3, Arg4, Arg5, Arg6>;
802 using src_subview_type =
typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2,
803 Arg3, Arg4, Arg5, Arg6>;
804 dst_subview_type dst_sub;
805 src_subview_type src_sub;
806 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
807 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
808 const Arg4& arg4,
const Arg5& arg5,
const Arg6& arg6, Args...)
809 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4, arg5, arg6),
810 src_sub(src, arg0, arg1, arg2, arg3, arg4, arg5, arg6) {}
813template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
814 class Arg3,
class Arg4,
class Arg5,
class Arg6,
class Arg7>
815struct CommonSubview<DstType, SrcType, 8, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
817 using dst_subview_type =
818 typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
820 using src_subview_type =
821 typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
823 dst_subview_type dst_sub;
824 src_subview_type src_sub;
825 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
826 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
827 const Arg4& arg4,
const Arg5& arg5,
const Arg6& arg6,
829 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7),
830 src_sub(src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {}
833template <
class DstType,
class SrcType,
834 class ExecSpace =
typename DstType::execution_space,
835 int Rank = DstType::Rank>
838template <
class DstType,
class SrcType,
class ExecSpace>
839struct ViewRemap<DstType, SrcType, ExecSpace, 1> {
842 template <
typename... OptExecSpace>
843 ViewRemap(
const DstType& dst,
const SrcType& src,
844 const OptExecSpace&... exec_space) {
846 sizeof...(OptExecSpace) <= 1,
847 "OptExecSpace must be either empty or be an execution space!");
849 if (dst.extent(0) == src.extent(0)) {
850 view_copy(exec_space..., dst, src);
852 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
853 using sv_adapter_type = CommonSubview<DstType, SrcType, 1, p_type>;
854 sv_adapter_type common_subview(dst, src, ext0);
855 view_copy(exec_space..., common_subview.dst_sub, common_subview.src_sub);
860template <
class DstType,
class SrcType,
class ExecSpace>
861struct ViewRemap<DstType, SrcType, ExecSpace, 2> {
864 template <
typename... OptExecSpace>
865 ViewRemap(
const DstType& dst,
const SrcType& src,
866 const OptExecSpace&... exec_space) {
868 sizeof...(OptExecSpace) <= 1,
869 "OptExecSpace must be either empty or be an execution space!");
871 if (dst.extent(0) == src.extent(0)) {
872 if (dst.extent(1) == src.extent(1)) {
873 view_copy(exec_space..., dst, src);
875 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
876 using sv_adapter_type =
877 CommonSubview<DstType, SrcType, 2, Kokkos::Impl::ALL_t, p_type>;
878 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1);
879 view_copy(exec_space..., common_subview.dst_sub,
880 common_subview.src_sub);
883 if (dst.extent(1) == src.extent(1)) {
884 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
885 using sv_adapter_type =
886 CommonSubview<DstType, SrcType, 2, p_type, Kokkos::Impl::ALL_t>;
887 sv_adapter_type common_subview(dst, src, ext0, Kokkos::ALL);
888 view_copy(exec_space..., common_subview.dst_sub,
889 common_subview.src_sub);
891 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
892 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
893 using sv_adapter_type =
894 CommonSubview<DstType, SrcType, 2, p_type, p_type>;
895 sv_adapter_type common_subview(dst, src, ext0, ext1);
896 view_copy(exec_space..., common_subview.dst_sub,
897 common_subview.src_sub);
903template <
class DstType,
class SrcType,
class ExecSpace>
904struct ViewRemap<DstType, SrcType, ExecSpace, 3> {
907 template <
typename... OptExecSpace>
908 ViewRemap(
const DstType& dst,
const SrcType& src,
909 const OptExecSpace&... exec_space) {
911 sizeof...(OptExecSpace) <= 1,
912 "OptExecSpace must be either empty or be an execution space!");
914 if (dst.extent(0) == src.extent(0)) {
915 if (dst.extent(2) == src.extent(2)) {
916 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
917 using sv_adapter_type =
918 CommonSubview<DstType, SrcType, 3, Kokkos::Impl::ALL_t, p_type,
919 Kokkos::Impl::ALL_t>;
920 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1,
922 view_copy(exec_space..., common_subview.dst_sub,
923 common_subview.src_sub);
925 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
926 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
927 using sv_adapter_type =
928 CommonSubview<DstType, SrcType, 3, Kokkos::Impl::ALL_t, p_type,
930 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2);
931 view_copy(exec_space..., common_subview.dst_sub,
932 common_subview.src_sub);
935 if (dst.extent(2) == src.extent(2)) {
936 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
937 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
938 using sv_adapter_type = CommonSubview<DstType, SrcType, 3, p_type,
939 p_type, Kokkos::Impl::ALL_t>;
940 sv_adapter_type common_subview(dst, src, ext0, ext1, Kokkos::ALL);
941 view_copy(exec_space..., common_subview.dst_sub,
942 common_subview.src_sub);
944 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
945 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
946 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
947 using sv_adapter_type =
948 CommonSubview<DstType, SrcType, 3, p_type, p_type, p_type>;
949 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2);
950 view_copy(exec_space..., common_subview.dst_sub,
951 common_subview.src_sub);
957template <
class DstType,
class SrcType,
class ExecSpace>
958struct ViewRemap<DstType, SrcType, ExecSpace, 4> {
961 template <
typename... OptExecSpace>
962 ViewRemap(
const DstType& dst,
const SrcType& src,
963 const OptExecSpace&... exec_space) {
965 sizeof...(OptExecSpace) <= 1,
966 "OptExecSpace must be either empty or be an execution space!");
968 if (dst.extent(0) == src.extent(0)) {
969 if (dst.extent(3) == src.extent(3)) {
970 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
971 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
972 using sv_adapter_type =
973 CommonSubview<DstType, SrcType, 4, Kokkos::Impl::ALL_t, p_type,
974 p_type, Kokkos::Impl::ALL_t>;
975 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2,
977 view_copy(exec_space..., common_subview.dst_sub,
978 common_subview.src_sub);
980 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
981 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
982 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
983 using sv_adapter_type =
984 CommonSubview<DstType, SrcType, 4, Kokkos::Impl::ALL_t, p_type,
986 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3);
987 view_copy(exec_space..., common_subview.dst_sub,
988 common_subview.src_sub);
991 if (dst.extent(7) == src.extent(7)) {
992 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
993 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
994 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
995 using sv_adapter_type =
996 CommonSubview<DstType, SrcType, 4, p_type, p_type, p_type,
997 Kokkos::Impl::ALL_t>;
998 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, Kokkos::ALL);
999 view_copy(exec_space..., common_subview.dst_sub,
1000 common_subview.src_sub);
1002 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1003 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1004 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1005 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1006 using sv_adapter_type =
1007 CommonSubview<DstType, SrcType, 4, p_type, p_type, p_type, p_type>;
1008 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3);
1009 view_copy(exec_space..., common_subview.dst_sub,
1010 common_subview.src_sub);
1016template <
class DstType,
class SrcType,
class ExecSpace>
1017struct ViewRemap<DstType, SrcType, ExecSpace, 5> {
1020 template <
typename... OptExecSpace>
1021 ViewRemap(
const DstType& dst,
const SrcType& src,
1022 const OptExecSpace&... exec_space) {
1024 sizeof...(OptExecSpace) <= 1,
1025 "OptExecSpace must be either empty or be an execution space!");
1027 if (dst.extent(0) == src.extent(0)) {
1028 if (dst.extent(4) == src.extent(4)) {
1029 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1030 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1031 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1032 using sv_adapter_type =
1033 CommonSubview<DstType, SrcType, 5, Kokkos::Impl::ALL_t, p_type,
1034 p_type, p_type, Kokkos::Impl::ALL_t>;
1035 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1037 view_copy(exec_space..., common_subview.dst_sub,
1038 common_subview.src_sub);
1040 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1041 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1042 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1043 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1044 using sv_adapter_type =
1045 CommonSubview<DstType, SrcType, 5, Kokkos::Impl::ALL_t, p_type,
1046 p_type, p_type, p_type>;
1047 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1049 view_copy(exec_space..., common_subview.dst_sub,
1050 common_subview.src_sub);
1053 if (dst.extent(4) == src.extent(4)) {
1054 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1055 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1056 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1057 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1058 using sv_adapter_type =
1059 CommonSubview<DstType, SrcType, 5, p_type, p_type, p_type, p_type,
1060 Kokkos::Impl::ALL_t>;
1061 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3,
1063 view_copy(exec_space..., common_subview.dst_sub,
1064 common_subview.src_sub);
1066 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1067 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1068 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1069 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1070 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1071 using sv_adapter_type = CommonSubview<DstType, SrcType, 5, p_type,
1072 p_type, p_type, p_type, p_type>;
1073 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4);
1074 view_copy(exec_space..., common_subview.dst_sub,
1075 common_subview.src_sub);
1080template <
class DstType,
class SrcType,
class ExecSpace>
1081struct ViewRemap<DstType, SrcType, ExecSpace, 6> {
1084 template <
typename... OptExecSpace>
1085 ViewRemap(
const DstType& dst,
const SrcType& src,
1086 const OptExecSpace&... exec_space) {
1088 sizeof...(OptExecSpace) <= 1,
1089 "OptExecSpace must be either empty or be an execution space!");
1091 if (dst.extent(0) == src.extent(0)) {
1092 if (dst.extent(5) == src.extent(5)) {
1093 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1094 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1095 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1096 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1097 using sv_adapter_type =
1098 CommonSubview<DstType, SrcType, 6, Kokkos::Impl::ALL_t, p_type,
1099 p_type, p_type, p_type, Kokkos::Impl::ALL_t>;
1100 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1102 view_copy(exec_space..., common_subview.dst_sub,
1103 common_subview.src_sub);
1105 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1106 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1107 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1108 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1109 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1110 using sv_adapter_type =
1111 CommonSubview<DstType, SrcType, 6, Kokkos::Impl::ALL_t, p_type,
1112 p_type, p_type, p_type, p_type>;
1113 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1115 view_copy(exec_space..., common_subview.dst_sub,
1116 common_subview.src_sub);
1119 if (dst.extent(5) == src.extent(5)) {
1120 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1121 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1122 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1123 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1124 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1126 using sv_adapter_type =
1127 CommonSubview<DstType, SrcType, 6, p_type, p_type, p_type, p_type,
1128 p_type, Kokkos::Impl::ALL_t>;
1129 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1131 view_copy(exec_space..., common_subview.dst_sub,
1132 common_subview.src_sub);
1134 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1135 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1136 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1137 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1138 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1139 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1141 using sv_adapter_type =
1142 CommonSubview<DstType, SrcType, 6, p_type, p_type, p_type, p_type,
1144 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1146 view_copy(exec_space..., common_subview.dst_sub,
1147 common_subview.src_sub);
1153template <
class DstType,
class SrcType,
class ExecSpace>
1154struct ViewRemap<DstType, SrcType, ExecSpace, 7> {
1157 template <
typename... OptExecSpace>
1158 ViewRemap(
const DstType& dst,
const SrcType& src,
1159 const OptExecSpace&... exec_space) {
1161 sizeof...(OptExecSpace) <= 1,
1162 "OptExecSpace must be either empty or be an execution space!");
1164 if (dst.extent(0) == src.extent(0)) {
1165 if (dst.extent(6) == src.extent(6)) {
1166 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1167 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1168 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1169 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1170 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1171 using sv_adapter_type =
1172 CommonSubview<DstType, SrcType, 7, Kokkos::Impl::ALL_t, p_type,
1173 p_type, p_type, p_type, p_type, Kokkos::Impl::ALL_t>;
1174 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1175 ext4, ext5, Kokkos::ALL);
1176 view_copy(exec_space..., common_subview.dst_sub,
1177 common_subview.src_sub);
1179 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1180 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1181 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1182 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1183 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1184 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1185 using sv_adapter_type =
1186 CommonSubview<DstType, SrcType, 7, Kokkos::Impl::ALL_t, p_type,
1187 p_type, p_type, p_type, p_type, p_type>;
1188 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1190 view_copy(exec_space..., common_subview.dst_sub,
1191 common_subview.src_sub);
1194 if (dst.extent(6) == src.extent(6)) {
1195 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1196 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1197 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1198 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1199 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1200 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1201 using sv_adapter_type =
1202 CommonSubview<DstType, SrcType, 7, p_type, p_type, p_type, p_type,
1203 p_type, p_type, Kokkos::Impl::ALL_t>;
1204 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1206 view_copy(exec_space..., common_subview.dst_sub,
1207 common_subview.src_sub);
1209 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1210 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1211 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1212 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1213 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1214 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1215 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1216 using sv_adapter_type =
1217 CommonSubview<DstType, SrcType, 7, p_type, p_type, p_type, p_type,
1218 p_type, p_type, p_type>;
1219 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1221 view_copy(exec_space..., common_subview.dst_sub,
1222 common_subview.src_sub);
1228template <
class DstType,
class SrcType,
class ExecSpace>
1229struct ViewRemap<DstType, SrcType, ExecSpace, 8> {
1232 template <
typename... OptExecSpace>
1233 ViewRemap(
const DstType& dst,
const SrcType& src,
1234 const OptExecSpace&... exec_space) {
1236 sizeof...(OptExecSpace) <= 1,
1237 "OptExecSpace must be either empty or be an execution space!");
1239 if (dst.extent(0) == src.extent(0)) {
1240 if (dst.extent(7) == src.extent(7)) {
1241 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1242 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1243 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1244 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1245 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1246 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1247 using sv_adapter_type =
1248 CommonSubview<DstType, SrcType, 8, Kokkos::Impl::ALL_t, p_type,
1249 p_type, p_type, p_type, p_type, p_type,
1250 Kokkos::Impl::ALL_t>;
1251 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1252 ext4, ext5, ext6, Kokkos::ALL);
1253 view_copy(exec_space..., common_subview.dst_sub,
1254 common_subview.src_sub);
1256 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1257 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1258 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1259 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1260 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1261 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1262 p_type ext7(0, std::min(dst.extent(7), src.extent(7)));
1263 using sv_adapter_type =
1264 CommonSubview<DstType, SrcType, 8, Kokkos::Impl::ALL_t, p_type,
1265 p_type, p_type, p_type, p_type, p_type, p_type>;
1266 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1267 ext4, ext5, ext6, ext7);
1268 view_copy(exec_space..., common_subview.dst_sub,
1269 common_subview.src_sub);
1272 if (dst.extent(7) == src.extent(7)) {
1273 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1274 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1275 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1276 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1277 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1278 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1279 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1280 using sv_adapter_type =
1281 CommonSubview<DstType, SrcType, 8, p_type, p_type, p_type, p_type,
1282 p_type, p_type, p_type, Kokkos::Impl::ALL_t>;
1283 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1284 ext5, ext6, Kokkos::ALL);
1285 view_copy(exec_space..., common_subview.dst_sub,
1286 common_subview.src_sub);
1288 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1289 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1290 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1291 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1292 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1293 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1294 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1295 p_type ext7(0, std::min(dst.extent(7), src.extent(7)));
1296 using sv_adapter_type =
1297 CommonSubview<DstType, SrcType, 8, p_type, p_type, p_type, p_type,
1298 p_type, p_type, p_type, p_type>;
1299 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1301 view_copy(exec_space..., common_subview.dst_sub,
1302 common_subview.src_sub);
1308template <
typename ExecutionSpace,
class DT,
class... DP>
1309inline void contiguous_fill(
1310 const ExecutionSpace& exec_space,
const View<DT, DP...>& dst,
1311 typename ViewTraits<DT, DP...>::const_value_type& value) {
1312 using ViewType =
View<DT, DP...>;
1315 Kokkos::Device<
typename ViewType::execution_space,
1316 std::conditional_t<ViewType::Rank == 0,
1317 typename ViewType::memory_space,
1318 Kokkos::AnonymousSpace>>,
1319 Kokkos::MemoryTraits<0>>;
1321 ViewTypeFlat dst_flat(dst.data(), dst.size());
1322 if (dst.span() <
static_cast<size_t>(std::numeric_limits<int>::max())) {
1324 ViewTypeFlat::Rank,
int>(dst_flat, value,
1328 ViewTypeFlat::Rank, int64_t>(dst_flat, value,
1332template <
typename ExecutionSpace,
class DT,
class... DP>
1334 ZeroMemset(
const ExecutionSpace& exec_space,
const View<DT, DP...>& dst,
1335 typename ViewTraits<DT, DP...>::const_value_type& value) {
1336 contiguous_fill(exec_space, dst, value);
1339 ZeroMemset(
const View<DT, DP...>& dst,
1340 typename ViewTraits<DT, DP...>::const_value_type& value) {
1341 contiguous_fill(ExecutionSpace(), dst, value);
1345template <
typename ExecutionSpace,
class DT,
class... DP>
1346inline std::enable_if_t<
1347 std::is_trivial<
typename ViewTraits<DT, DP...>::value_type>::value &&
1348 std::is_trivially_copy_assignable<
1349 typename ViewTraits<DT, DP...>::value_type>::value>
1350contiguous_fill_or_memset(
1351 const ExecutionSpace& exec_space,
const View<DT, DP...>& dst,
1352 typename ViewTraits<DT, DP...>::const_value_type& value) {
1355#ifndef KOKKOS_ARCH_A64FX
1356 if (Impl::is_zero_byte(value))
1357 ZeroMemset<ExecutionSpace, DT, DP...>(exec_space, dst, value);
1360 contiguous_fill(exec_space, dst, value);
1363template <
typename ExecutionSpace,
class DT,
class... DP>
1364inline std::enable_if_t<
1365 !(std::is_trivial<
typename ViewTraits<DT, DP...>::value_type>::value &&
1366 std::is_trivially_copy_assignable<
1367 typename ViewTraits<DT, DP...>::value_type>::value)>
1368contiguous_fill_or_memset(
1369 const ExecutionSpace& exec_space,
const View<DT, DP...>& dst,
1370 typename ViewTraits<DT, DP...>::const_value_type& value) {
1371 contiguous_fill(exec_space, dst, value);
1374template <
class DT,
class... DP>
1375inline std::enable_if_t<
1376 std::is_trivial<
typename ViewTraits<DT, DP...>::value_type>::value &&
1377 std::is_trivially_copy_assignable<
1378 typename ViewTraits<DT, DP...>::value_type>::value>
1379contiguous_fill_or_memset(
1380 const View<DT, DP...>& dst,
1381 typename ViewTraits<DT, DP...>::const_value_type& value) {
1382 using ViewType =
View<DT, DP...>;
1383 using exec_space_type =
typename ViewType::execution_space;
1387#ifndef KOKKOS_ARCH_A64FX
1388 if (Impl::is_zero_byte(value))
1389 ZeroMemset<exec_space_type, DT, DP...>(dst, value);
1392 contiguous_fill(exec_space_type(), dst, value);
1395template <
class DT,
class... DP>
1396inline std::enable_if_t<
1397 !(std::is_trivial<
typename ViewTraits<DT, DP...>::value_type>::value &&
1398 std::is_trivially_copy_assignable<
1399 typename ViewTraits<DT, DP...>::value_type>::value)>
1400contiguous_fill_or_memset(
1401 const View<DT, DP...>& dst,
1402 typename ViewTraits<DT, DP...>::const_value_type& value) {
1403 using ViewType =
View<DT, DP...>;
1404 using exec_space_type =
typename ViewType::execution_space;
1406 contiguous_fill(exec_space_type(), dst, value);
1411template <
class DT,
class... DP>
1412inline void deep_copy(
1413 const View<DT, DP...>& dst,
1414 typename ViewTraits<DT, DP...>::const_value_type& value,
1415 std::enable_if_t<std::is_same<
typename ViewTraits<DT, DP...>::specialize,
1416 void>::value>* =
nullptr) {
1417 using ViewType =
View<DT, DP...>;
1418 using exec_space_type =
typename ViewType::execution_space;
1420 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
1421 Kokkos::Profiling::beginDeepCopy(
1422 Kokkos::Profiling::make_space_handle(ViewType::memory_space::name()),
1423 dst.label(), dst.data(),
1425 "Scalar", &value, dst.span() *
sizeof(
typename ViewType::value_type));
1428 if (dst.data() ==
nullptr) {
1430 "Kokkos::deep_copy: scalar copy, fence because destination is null");
1431 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1432 Kokkos::Profiling::endDeepCopy();
1437 Kokkos::fence(
"Kokkos::deep_copy: scalar copy, pre copy fence");
1438 static_assert(std::is_same<
typename ViewType::non_const_value_type,
1439 typename ViewType::value_type>::value,
1440 "deep_copy requires non-const type");
1443 if (dst.span_is_contiguous()) {
1444 Impl::contiguous_fill_or_memset(dst, value);
1445 Kokkos::fence(
"Kokkos::deep_copy: scalar copy, post copy fence");
1446 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1447 Kokkos::Profiling::endDeepCopy();
1453 int64_t strides[ViewType::Rank + 1];
1454 dst.stride(strides);
1455 Kokkos::Iterate iterate;
1456 if (std::is_same<
typename ViewType::array_layout,
1458 iterate = Kokkos::Iterate::Right;
1459 }
else if (std::is_same<
typename ViewType::array_layout,
1461 iterate = Kokkos::Iterate::Left;
1462 }
else if (std::is_same<
typename ViewType::array_layout,
1464 if (strides[0] > strides[ViewType::Rank > 0 ? ViewType::Rank - 1 : 0])
1465 iterate = Kokkos::Iterate::Right;
1467 iterate = Kokkos::Iterate::Left;
1469 if (std::is_same<
typename ViewType::execution_space::array_layout,
1471 iterate = Kokkos::Iterate::Right;
1473 iterate = Kokkos::Iterate::Left;
1478 using ViewTypeUniform =
1479 std::conditional_t<ViewType::Rank == 0,
1480 typename ViewType::uniform_runtime_type,
1481 typename ViewType::uniform_runtime_nomemspace_type>;
1482 if (dst.span() >
static_cast<size_t>(std::numeric_limits<int>::max())) {
1483 if (iterate == Kokkos::Iterate::Right)
1485 exec_space_type, ViewType::Rank, int64_t>(
1486 dst, value, exec_space_type());
1489 exec_space_type, ViewType::Rank, int64_t>(
1490 dst, value, exec_space_type());
1492 if (iterate == Kokkos::Iterate::Right)
1494 exec_space_type, ViewType::Rank,
int>(
1495 dst, value, exec_space_type());
1498 exec_space_type, ViewType::Rank,
int>(
1499 dst, value, exec_space_type());
1501 Kokkos::fence(
"Kokkos::deep_copy: scalar copy, post copy fence");
1503 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1504 Kokkos::Profiling::endDeepCopy();
1509template <
class ST,
class... SP>
1510inline void deep_copy(
1511 typename ViewTraits<ST, SP...>::non_const_value_type& dst,
1512 const View<ST, SP...>& src,
1513 std::enable_if_t<std::is_same<
typename ViewTraits<ST, SP...>::specialize,
1514 void>::value>* =
nullptr) {
1515 using src_traits = ViewTraits<ST, SP...>;
1516 using src_memory_space =
typename src_traits::memory_space;
1518 static_assert(src_traits::rank == 0,
1519 "ERROR: Non-rank-zero view in deep_copy( value , View )");
1521 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
1522 Kokkos::Profiling::beginDeepCopy(
1525 Kokkos::Profiling::make_space_handle(src_memory_space::name()),
1526 src.label(), src.data(),
1527 src.span() *
sizeof(
typename src_traits::value_type));
1530 if (src.data() ==
nullptr) {
1531 Kokkos::fence(
"Kokkos::deep_copy: copy into scalar, src is null");
1533 Kokkos::fence(
"Kokkos::deep_copy: copy into scalar, pre copy fence");
1534 Kokkos::Impl::DeepCopy<HostSpace, src_memory_space>(&dst, src.data(),
1536 Kokkos::fence(
"Kokkos::deep_copy: copy into scalar, post copy fence");
1539 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1540 Kokkos::Profiling::endDeepCopy();
1546template <
class DT,
class... DP,
class ST,
class... SP>
1547inline void deep_copy(
1548 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
1550 (std::is_void<
typename ViewTraits<DT, DP...>::specialize>::value &&
1551 std::is_void<
typename ViewTraits<ST, SP...>::specialize>::value &&
1552 (
unsigned(ViewTraits<DT, DP...>::rank) ==
unsigned(0) &&
1553 unsigned(ViewTraits<ST, SP...>::rank) ==
unsigned(0)))>* =
nullptr) {
1554 using dst_type =
View<DT, DP...>;
1555 using src_type =
View<ST, SP...>;
1557 using value_type =
typename dst_type::value_type;
1558 using dst_memory_space =
typename dst_type::memory_space;
1559 using src_memory_space =
typename src_type::memory_space;
1561 static_assert(std::is_same<
typename dst_type::value_type,
1562 typename src_type::non_const_value_type>::value,
1563 "deep_copy requires matching non-const destination type");
1565 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
1566 Kokkos::Profiling::beginDeepCopy(
1567 Kokkos::Profiling::make_space_handle(dst_memory_space::name()),
1568 dst.label(), dst.data(),
1569 Kokkos::Profiling::make_space_handle(src_memory_space::name()),
1570 src.label(), src.data(),
1571 src.span() *
sizeof(
typename dst_type::value_type));
1574 if (dst.data() ==
nullptr && src.data() ==
nullptr) {
1576 "Kokkos::deep_copy: scalar to scalar copy, both pointers null");
1577 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1578 Kokkos::Profiling::endDeepCopy();
1583 Kokkos::fence(
"Kokkos::deep_copy: scalar to scalar copy, pre copy fence");
1584 if (dst.data() != src.data()) {
1585 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1586 dst.data(), src.data(),
sizeof(value_type));
1587 Kokkos::fence(
"Kokkos::deep_copy: scalar to scalar copy, post copy fence");
1589 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1590 Kokkos::Profiling::endDeepCopy();
1598template <
class DT,
class... DP,
class ST,
class... SP>
1599inline void deep_copy(
1600 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
1602 (std::is_void<
typename ViewTraits<DT, DP...>::specialize>::value &&
1603 std::is_void<
typename ViewTraits<ST, SP...>::specialize>::value &&
1604 (
unsigned(ViewTraits<DT, DP...>::rank) != 0 ||
1605 unsigned(ViewTraits<ST, SP...>::rank) != 0))>* =
nullptr) {
1606 using dst_type =
View<DT, DP...>;
1607 using src_type =
View<ST, SP...>;
1608 using dst_execution_space =
typename dst_type::execution_space;
1609 using src_execution_space =
typename src_type::execution_space;
1610 using dst_memory_space =
typename dst_type::memory_space;
1611 using src_memory_space =
typename src_type::memory_space;
1612 using dst_value_type =
typename dst_type::value_type;
1613 using src_value_type =
typename src_type::value_type;
1615 static_assert(std::is_same<
typename dst_type::value_type,
1616 typename dst_type::non_const_value_type>::value,
1617 "deep_copy requires non-const destination type");
1619 static_assert((unsigned(dst_type::rank) == unsigned(src_type::rank)),
1620 "deep_copy requires Views of equal rank");
1622 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
1623 Kokkos::Profiling::beginDeepCopy(
1624 Kokkos::Profiling::make_space_handle(dst_memory_space::name()),
1625 dst.label(), dst.data(),
1626 Kokkos::Profiling::make_space_handle(src_memory_space::name()),
1627 src.label(), src.data(),
1628 src.span() *
sizeof(
typename dst_type::value_type));
1631 if (dst.data() ==
nullptr || src.data() ==
nullptr) {
1633 if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
1634 (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
1635 (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
1636 (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
1637 std::string message(
1638 "Deprecation Error: Kokkos::deep_copy extents of views don't "
1640 message += dst.label();
1642 for (
int r = 0; r < dst_type::Rank - 1; r++) {
1643 message += std::to_string(dst.extent(r));
1646 message += std::to_string(dst.extent(dst_type::Rank - 1));
1648 message += src.label();
1650 for (
int r = 0; r < src_type::Rank - 1; r++) {
1651 message += std::to_string(src.extent(r));
1654 message += std::to_string(src.extent(src_type::Rank - 1));
1657 Kokkos::Impl::throw_runtime_exception(message);
1660 "Kokkos::deep_copy: copy between contiguous views, fence due to null "
1662 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1663 Kokkos::Profiling::endDeepCopy();
1669 DstExecCanAccessSrc =
1671 src_memory_space>::accessible
1675 SrcExecCanAccessDst =
1677 dst_memory_space>::accessible
1681 dst_value_type* dst_start = dst.data();
1682 dst_value_type* dst_end = dst.data() + dst.span();
1683 src_value_type* src_start = src.data();
1684 src_value_type* src_end = src.data() + src.span();
1685 if (((std::ptrdiff_t)dst_start == (std::ptrdiff_t)src_start) &&
1686 ((std::ptrdiff_t)dst_end == (std::ptrdiff_t)src_end) &&
1687 (dst.span_is_contiguous() && src.span_is_contiguous())) {
1689 "Kokkos::deep_copy: copy between contiguous views, fence due to same "
1691 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1692 Kokkos::Profiling::endDeepCopy();
1697 if ((((std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end) &&
1698 ((std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start)) &&
1699 ((dst.span_is_contiguous() && src.span_is_contiguous()))) {
1700 std::string message(
"Error: Kokkos::deep_copy of overlapping views: ");
1701 message += dst.label();
1703 message += std::to_string((std::ptrdiff_t)dst_start);
1705 message += std::to_string((std::ptrdiff_t)dst_end);
1707 message += src.label();
1709 message += std::to_string((std::ptrdiff_t)src_start);
1711 message += std::to_string((std::ptrdiff_t)src_end);
1713 Kokkos::Impl::throw_runtime_exception(message);
1717 if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
1718 (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
1719 (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
1720 (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
1721 std::string message(
1722 "Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1723 message += dst.label();
1725 for (
int r = 0; r < dst_type::Rank - 1; r++) {
1726 message += std::to_string(dst.extent(r));
1729 message += std::to_string(dst.extent(dst_type::Rank - 1));
1731 message += src.label();
1733 for (
int r = 0; r < src_type::Rank - 1; r++) {
1734 message += std::to_string(src.extent(r));
1737 message += std::to_string(src.extent(src_type::Rank - 1));
1740 Kokkos::Impl::throw_runtime_exception(message);
1746 if (std::is_same<
typename dst_type::value_type,
1747 typename src_type::non_const_value_type>::value &&
1748 (std::is_same<
typename dst_type::array_layout,
1749 typename src_type::array_layout>::value ||
1750 (dst_type::rank == 1 && src_type::rank == 1)) &&
1751 dst.span_is_contiguous() && src.span_is_contiguous() &&
1752 ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1753 ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1754 ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1755 ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1756 ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1757 ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1758 ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1759 ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))) {
1760 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1762 "Kokkos::deep_copy: copy between contiguous views, pre view equality "
1764 if ((
void*)dst.data() != (
void*)src.data()) {
1765 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1766 dst.data(), src.data(), nbytes);
1768 "Kokkos::deep_copy: copy between contiguous views, post deep copy "
1773 "Kokkos::deep_copy: copy between contiguous views, pre copy fence");
1774 Impl::view_copy(dst, src);
1776 "Kokkos::deep_copy: copy between contiguous views, post copy fence");
1778 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
1779 Kokkos::Profiling::endDeepCopy();
1789template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1790void KOKKOS_INLINE_FUNCTION
1791local_deep_copy_contiguous(
const TeamType& team,
const View<DT, DP...>& dst,
1792 const View<ST, SP...>& src) {
1793 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, src.span()),
1794 [&](
const int& i) { dst.data()[i] = src.data()[i]; });
1797template <
class DT,
class... DP,
class ST,
class... SP>
1798void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
1799 const View<DT, DP...>& dst,
const View<ST, SP...>& src) {
1800 for (
size_t i = 0; i < src.span(); ++i) {
1801 dst.data()[i] = src.data()[i];
1805template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1806void KOKKOS_INLINE_FUNCTION local_deep_copy(
1807 const TeamType& team,
const View<DT, DP...>& dst,
1808 const View<ST, SP...>& src,
1809 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 1 &&
1810 unsigned(ViewTraits<ST, SP...>::rank) == 1)>* =
nullptr) {
1811 if (dst.data() ==
nullptr) {
1815 const size_t N = dst.extent(0);
1817 team.team_barrier();
1818 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N),
1819 [&](
const int& i) { dst(i) = src(i); });
1820 team.team_barrier();
1823template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1824void KOKKOS_INLINE_FUNCTION local_deep_copy(
1825 const TeamType& team,
const View<DT, DP...>& dst,
1826 const View<ST, SP...>& src,
1827 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 2 &&
1828 unsigned(ViewTraits<ST, SP...>::rank) == 2)>* =
nullptr) {
1829 if (dst.data() ==
nullptr) {
1833 const size_t N = dst.extent(0) * dst.extent(1);
1835 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
1836 team.team_barrier();
1837 local_deep_copy_contiguous(team, dst, src);
1838 team.team_barrier();
1840 team.team_barrier();
1841 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
1842 int i0 = i % dst.extent(0);
1843 int i1 = i / dst.extent(0);
1844 dst(i0, i1) = src(i0, i1);
1846 team.team_barrier();
1850template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1851void KOKKOS_INLINE_FUNCTION local_deep_copy(
1852 const TeamType& team,
const View<DT, DP...>& dst,
1853 const View<ST, SP...>& src,
1854 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 3 &&
1855 unsigned(ViewTraits<ST, SP...>::rank) == 3)>* =
nullptr) {
1856 if (dst.data() ==
nullptr) {
1860 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
1862 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
1863 team.team_barrier();
1864 local_deep_copy_contiguous(team, dst, src);
1865 team.team_barrier();
1867 team.team_barrier();
1868 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
1869 int i0 = i % dst.extent(0);
1870 int itmp = i / dst.extent(0);
1871 int i1 = itmp % dst.extent(1);
1872 int i2 = itmp / dst.extent(1);
1873 dst(i0, i1, i2) = src(i0, i1, i2);
1875 team.team_barrier();
1879template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1880void KOKKOS_INLINE_FUNCTION local_deep_copy(
1881 const TeamType& team,
const View<DT, DP...>& dst,
1882 const View<ST, SP...>& src,
1883 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 4 &&
1884 unsigned(ViewTraits<ST, SP...>::rank) == 4)>* =
nullptr) {
1885 if (dst.data() ==
nullptr) {
1890 dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
1892 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
1893 team.team_barrier();
1894 local_deep_copy_contiguous(team, dst, src);
1895 team.team_barrier();
1897 team.team_barrier();
1898 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
1899 int i0 = i % dst.extent(0);
1900 int itmp = i / dst.extent(0);
1901 int i1 = itmp % dst.extent(1);
1902 itmp = itmp / dst.extent(1);
1903 int i2 = itmp % dst.extent(2);
1904 int i3 = itmp / dst.extent(2);
1905 dst(i0, i1, i2, i3) = src(i0, i1, i2, i3);
1907 team.team_barrier();
1911template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1912void KOKKOS_INLINE_FUNCTION local_deep_copy(
1913 const TeamType& team,
const View<DT, DP...>& dst,
1914 const View<ST, SP...>& src,
1915 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 5 &&
1916 unsigned(ViewTraits<ST, SP...>::rank) == 5)>* =
nullptr) {
1917 if (dst.data() ==
nullptr) {
1921 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
1922 dst.extent(3) * dst.extent(4);
1924 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
1925 team.team_barrier();
1926 local_deep_copy_contiguous(team, dst, src);
1927 team.team_barrier();
1929 team.team_barrier();
1930 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
1931 int i0 = i % dst.extent(0);
1932 int itmp = i / dst.extent(0);
1933 int i1 = itmp % dst.extent(1);
1934 itmp = itmp / dst.extent(1);
1935 int i2 = itmp % dst.extent(2);
1936 itmp = itmp / dst.extent(2);
1937 int i3 = itmp % dst.extent(3);
1938 int i4 = itmp / dst.extent(3);
1939 dst(i0, i1, i2, i3, i4) = src(i0, i1, i2, i3, i4);
1941 team.team_barrier();
1945template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1946void KOKKOS_INLINE_FUNCTION local_deep_copy(
1947 const TeamType& team,
const View<DT, DP...>& dst,
1948 const View<ST, SP...>& src,
1949 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 6 &&
1950 unsigned(ViewTraits<ST, SP...>::rank) == 6)>* =
nullptr) {
1951 if (dst.data() ==
nullptr) {
1955 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
1956 dst.extent(3) * dst.extent(4) * dst.extent(5);
1958 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
1959 team.team_barrier();
1960 local_deep_copy_contiguous(team, dst, src);
1961 team.team_barrier();
1963 team.team_barrier();
1964 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
1965 int i0 = i % dst.extent(0);
1966 int itmp = i / dst.extent(0);
1967 int i1 = itmp % dst.extent(1);
1968 itmp = itmp / dst.extent(1);
1969 int i2 = itmp % dst.extent(2);
1970 itmp = itmp / dst.extent(2);
1971 int i3 = itmp % dst.extent(3);
1972 itmp = itmp / dst.extent(3);
1973 int i4 = itmp % dst.extent(4);
1974 int i5 = itmp / dst.extent(4);
1975 dst(i0, i1, i2, i3, i4, i5) = src(i0, i1, i2, i3, i4, i5);
1977 team.team_barrier();
1981template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1982void KOKKOS_INLINE_FUNCTION local_deep_copy(
1983 const TeamType& team,
const View<DT, DP...>& dst,
1984 const View<ST, SP...>& src,
1985 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 7 &&
1986 unsigned(ViewTraits<ST, SP...>::rank) == 7)>* =
nullptr) {
1987 if (dst.data() ==
nullptr) {
1991 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
1992 dst.extent(3) * dst.extent(4) * dst.extent(5) *
1995 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
1996 team.team_barrier();
1997 local_deep_copy_contiguous(team, dst, src);
1998 team.team_barrier();
2000 team.team_barrier();
2001 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
2002 int i0 = i % dst.extent(0);
2003 int itmp = i / dst.extent(0);
2004 int i1 = itmp % dst.extent(1);
2005 itmp = itmp / dst.extent(1);
2006 int i2 = itmp % dst.extent(2);
2007 itmp = itmp / dst.extent(2);
2008 int i3 = itmp % dst.extent(3);
2009 itmp = itmp / dst.extent(3);
2010 int i4 = itmp % dst.extent(4);
2011 itmp = itmp / dst.extent(4);
2012 int i5 = itmp % dst.extent(5);
2013 int i6 = itmp / dst.extent(5);
2014 dst(i0, i1, i2, i3, i4, i5, i6) = src(i0, i1, i2, i3, i4, i5, i6);
2016 team.team_barrier();
2020template <
class DT,
class... DP,
class ST,
class... SP>
2021void KOKKOS_INLINE_FUNCTION local_deep_copy(
2022 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2023 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 1 &&
2024 unsigned(ViewTraits<ST, SP...>::rank) == 1)>* =
nullptr) {
2025 if (dst.data() ==
nullptr) {
2029 const size_t N = dst.extent(0);
2031 for (
size_t i = 0; i < N; ++i) {
2036template <
class DT,
class... DP,
class ST,
class... SP>
2037void KOKKOS_INLINE_FUNCTION local_deep_copy(
2038 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2039 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 2 &&
2040 unsigned(ViewTraits<ST, SP...>::rank) == 2)>* =
nullptr) {
2041 if (dst.data() ==
nullptr) {
2045 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2046 local_deep_copy_contiguous(dst, src);
2048 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2049 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1) dst(i0, i1) = src(i0, i1);
2053template <
class DT,
class... DP,
class ST,
class... SP>
2054void KOKKOS_INLINE_FUNCTION local_deep_copy(
2055 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2056 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 3 &&
2057 unsigned(ViewTraits<ST, SP...>::rank) == 3)>* =
nullptr) {
2058 if (dst.data() ==
nullptr) {
2062 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2063 local_deep_copy_contiguous(dst, src);
2065 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2066 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2067 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2068 dst(i0, i1, i2) = src(i0, i1, i2);
2072template <
class DT,
class... DP,
class ST,
class... SP>
2073void KOKKOS_INLINE_FUNCTION local_deep_copy(
2074 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2075 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 4 &&
2076 unsigned(ViewTraits<ST, SP...>::rank) == 4)>* =
nullptr) {
2077 if (dst.data() ==
nullptr) {
2081 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2082 local_deep_copy_contiguous(dst, src);
2084 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2085 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2086 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2087 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2088 dst(i0, i1, i2, i3) = src(i0, i1, i2, i3);
2092template <
class DT,
class... DP,
class ST,
class... SP>
2093void KOKKOS_INLINE_FUNCTION local_deep_copy(
2094 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2095 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 5 &&
2096 unsigned(ViewTraits<ST, SP...>::rank) == 5)>* =
nullptr) {
2097 if (dst.data() ==
nullptr) {
2101 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2102 local_deep_copy_contiguous(dst, src);
2104 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2105 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2106 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2107 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2108 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2109 dst(i0, i1, i2, i3, i4) = src(i0, i1, i2, i3, i4);
2113template <
class DT,
class... DP,
class ST,
class... SP>
2114void KOKKOS_INLINE_FUNCTION local_deep_copy(
2115 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2116 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 6 &&
2117 unsigned(ViewTraits<ST, SP...>::rank) == 6)>* =
nullptr) {
2118 if (dst.data() ==
nullptr) {
2122 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2123 local_deep_copy_contiguous(dst, src);
2125 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2126 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2127 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2128 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2129 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2130 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2131 dst(i0, i1, i2, i3, i4, i5) = src(i0, i1, i2, i3, i4, i5);
2135template <
class DT,
class... DP,
class ST,
class... SP>
2136void KOKKOS_INLINE_FUNCTION local_deep_copy(
2137 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2138 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 7 &&
2139 unsigned(ViewTraits<ST, SP...>::rank) == 7)>* =
nullptr) {
2140 if (dst.data() ==
nullptr) {
2144 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2145 local_deep_copy_contiguous(dst, src);
2147 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2148 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2149 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2150 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2151 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2152 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2153 for (
size_t i6 = 0; i6 < dst.extent(6); ++i6)
2154 dst(i0, i1, i2, i3, i4, i5, i6) =
2155 src(i0, i1, i2, i3, i4, i5, i6);
2161template <
class TeamType,
class DT,
class... DP>
2162void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
2163 const TeamType& team,
const View<DT, DP...>& dst,
2164 typename ViewTraits<DT, DP...>::const_value_type& value,
2165 std::enable_if_t<std::is_same<
typename ViewTraits<DT, DP...>::specialize,
2166 void>::value>* =
nullptr) {
2167 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, dst.span()),
2168 [&](
const int& i) { dst.data()[i] = value; });
2171template <
class DT,
class... DP>
2172void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
2173 const View<DT, DP...>& dst,
2174 typename ViewTraits<DT, DP...>::const_value_type& value,
2175 std::enable_if_t<std::is_same<
typename ViewTraits<DT, DP...>::specialize,
2176 void>::value>* =
nullptr) {
2177 for (
size_t i = 0; i < dst.span(); ++i) {
2178 dst.data()[i] = value;
2182template <
class TeamType,
class DT,
class... DP>
2183void KOKKOS_INLINE_FUNCTION local_deep_copy(
2184 const TeamType& team,
const View<DT, DP...>& dst,
2185 typename ViewTraits<DT, DP...>::const_value_type& value,
2186 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 1)>* =
nullptr) {
2187 if (dst.data() ==
nullptr) {
2191 const size_t N = dst.extent(0);
2193 team.team_barrier();
2194 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N),
2195 [&](
const int& i) { dst(i) = value; });
2196 team.team_barrier();
2199template <
class TeamType,
class DT,
class... DP>
2200void KOKKOS_INLINE_FUNCTION local_deep_copy(
2201 const TeamType& team,
const View<DT, DP...>& dst,
2202 typename ViewTraits<DT, DP...>::const_value_type& value,
2203 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 2)>* =
nullptr) {
2204 if (dst.data() ==
nullptr) {
2208 const size_t N = dst.extent(0) * dst.extent(1);
2210 if (dst.span_is_contiguous()) {
2211 team.team_barrier();
2212 local_deep_copy_contiguous(team, dst, value);
2213 team.team_barrier();
2215 team.team_barrier();
2216 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
2217 int i0 = i % dst.extent(0);
2218 int i1 = i / dst.extent(0);
2219 dst(i0, i1) = value;
2221 team.team_barrier();
2225template <
class TeamType,
class DT,
class... DP>
2226void KOKKOS_INLINE_FUNCTION local_deep_copy(
2227 const TeamType& team,
const View<DT, DP...>& dst,
2228 typename ViewTraits<DT, DP...>::const_value_type& value,
2229 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 3)>* =
nullptr) {
2230 if (dst.data() ==
nullptr) {
2234 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
2236 if (dst.span_is_contiguous()) {
2237 team.team_barrier();
2238 local_deep_copy_contiguous(team, dst, value);
2239 team.team_barrier();
2241 team.team_barrier();
2242 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
2243 int i0 = i % dst.extent(0);
2244 int itmp = i / dst.extent(0);
2245 int i1 = itmp % dst.extent(1);
2246 int i2 = itmp / dst.extent(1);
2247 dst(i0, i1, i2) = value;
2249 team.team_barrier();
2253template <
class TeamType,
class DT,
class... DP>
2254void KOKKOS_INLINE_FUNCTION local_deep_copy(
2255 const TeamType& team,
const View<DT, DP...>& dst,
2256 typename ViewTraits<DT, DP...>::const_value_type& value,
2257 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 4)>* =
nullptr) {
2258 if (dst.data() ==
nullptr) {
2263 dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
2265 if (dst.span_is_contiguous()) {
2266 team.team_barrier();
2267 local_deep_copy_contiguous(team, dst, value);
2268 team.team_barrier();
2270 team.team_barrier();
2271 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
2272 int i0 = i % dst.extent(0);
2273 int itmp = i / dst.extent(0);
2274 int i1 = itmp % dst.extent(1);
2275 itmp = itmp / dst.extent(1);
2276 int i2 = itmp % dst.extent(2);
2277 int i3 = itmp / dst.extent(2);
2278 dst(i0, i1, i2, i3) = value;
2280 team.team_barrier();
2284template <
class TeamType,
class DT,
class... DP>
2285void KOKKOS_INLINE_FUNCTION local_deep_copy(
2286 const TeamType& team,
const View<DT, DP...>& dst,
2287 typename ViewTraits<DT, DP...>::const_value_type& value,
2288 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 5)>* =
nullptr) {
2289 if (dst.data() ==
nullptr) {
2293 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2294 dst.extent(3) * dst.extent(4);
2296 if (dst.span_is_contiguous()) {
2297 team.team_barrier();
2298 local_deep_copy_contiguous(team, dst, value);
2299 team.team_barrier();
2301 team.team_barrier();
2302 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
2303 int i0 = i % dst.extent(0);
2304 int itmp = i / dst.extent(0);
2305 int i1 = itmp % dst.extent(1);
2306 itmp = itmp / dst.extent(1);
2307 int i2 = itmp % dst.extent(2);
2308 itmp = itmp / dst.extent(2);
2309 int i3 = itmp % dst.extent(3);
2310 int i4 = itmp / dst.extent(3);
2311 dst(i0, i1, i2, i3, i4) = value;
2313 team.team_barrier();
2317template <
class TeamType,
class DT,
class... DP>
2318void KOKKOS_INLINE_FUNCTION local_deep_copy(
2319 const TeamType& team,
const View<DT, DP...>& dst,
2320 typename ViewTraits<DT, DP...>::const_value_type& value,
2321 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 6)>* =
nullptr) {
2322 if (dst.data() ==
nullptr) {
2326 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2327 dst.extent(3) * dst.extent(4) * dst.extent(5);
2329 if (dst.span_is_contiguous()) {
2330 team.team_barrier();
2331 local_deep_copy_contiguous(team, dst, value);
2332 team.team_barrier();
2334 team.team_barrier();
2335 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
2336 int i0 = i % dst.extent(0);
2337 int itmp = i / dst.extent(0);
2338 int i1 = itmp % dst.extent(1);
2339 itmp = itmp / dst.extent(1);
2340 int i2 = itmp % dst.extent(2);
2341 itmp = itmp / dst.extent(2);
2342 int i3 = itmp % dst.extent(3);
2343 itmp = itmp / dst.extent(3);
2344 int i4 = itmp % dst.extent(4);
2345 int i5 = itmp / dst.extent(4);
2346 dst(i0, i1, i2, i3, i4, i5) = value;
2348 team.team_barrier();
2352template <
class TeamType,
class DT,
class... DP>
2353void KOKKOS_INLINE_FUNCTION local_deep_copy(
2354 const TeamType& team,
const View<DT, DP...>& dst,
2355 typename ViewTraits<DT, DP...>::const_value_type& value,
2356 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 7)>* =
nullptr) {
2357 if (dst.data() ==
nullptr) {
2361 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2362 dst.extent(3) * dst.extent(4) * dst.extent(5) *
2365 if (dst.span_is_contiguous()) {
2366 team.team_barrier();
2367 local_deep_copy_contiguous(team, dst, value);
2368 team.team_barrier();
2370 team.team_barrier();
2371 Kokkos::parallel_for(Kokkos::TeamVectorRange(team, N), [&](
const int& i) {
2372 int i0 = i % dst.extent(0);
2373 int itmp = i / dst.extent(0);
2374 int i1 = itmp % dst.extent(1);
2375 itmp = itmp / dst.extent(1);
2376 int i2 = itmp % dst.extent(2);
2377 itmp = itmp / dst.extent(2);
2378 int i3 = itmp % dst.extent(3);
2379 itmp = itmp / dst.extent(3);
2380 int i4 = itmp % dst.extent(4);
2381 itmp = itmp / dst.extent(4);
2382 int i5 = itmp % dst.extent(5);
2383 int i6 = itmp / dst.extent(5);
2384 dst(i0, i1, i2, i3, i4, i5, i6) = value;
2386 team.team_barrier();
2390template <
class DT,
class... DP>
2391void KOKKOS_INLINE_FUNCTION local_deep_copy(
2392 const View<DT, DP...>& dst,
2393 typename ViewTraits<DT, DP...>::const_value_type& value,
2394 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 1)>* =
nullptr) {
2395 if (dst.data() ==
nullptr) {
2399 const size_t N = dst.extent(0);
2401 for (
size_t i = 0; i < N; ++i) {
2406template <
class DT,
class... DP>
2407void KOKKOS_INLINE_FUNCTION local_deep_copy(
2408 const View<DT, DP...>& dst,
2409 typename ViewTraits<DT, DP...>::const_value_type& value,
2410 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 2)>* =
nullptr) {
2411 if (dst.data() ==
nullptr) {
2415 if (dst.span_is_contiguous()) {
2416 local_deep_copy_contiguous(dst, value);
2418 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2419 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1) dst(i0, i1) = value;
2423template <
class DT,
class... DP>
2424void KOKKOS_INLINE_FUNCTION local_deep_copy(
2425 const View<DT, DP...>& dst,
2426 typename ViewTraits<DT, DP...>::const_value_type& value,
2427 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 3)>* =
nullptr) {
2428 if (dst.data() ==
nullptr) {
2432 if (dst.span_is_contiguous()) {
2433 local_deep_copy_contiguous(dst, value);
2435 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2436 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2437 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2) dst(i0, i1, i2) = value;
2441template <
class DT,
class... DP>
2442void KOKKOS_INLINE_FUNCTION local_deep_copy(
2443 const View<DT, DP...>& dst,
2444 typename ViewTraits<DT, DP...>::const_value_type& value,
2445 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 4)>* =
nullptr) {
2446 if (dst.data() ==
nullptr) {
2450 if (dst.span_is_contiguous()) {
2451 local_deep_copy_contiguous(dst, value);
2453 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2454 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2455 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2456 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2457 dst(i0, i1, i2, i3) = value;
2461template <
class DT,
class... DP>
2462void KOKKOS_INLINE_FUNCTION local_deep_copy(
2463 const View<DT, DP...>& dst,
2464 typename ViewTraits<DT, DP...>::const_value_type& value,
2465 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 5)>* =
nullptr) {
2466 if (dst.data() ==
nullptr) {
2470 if (dst.span_is_contiguous()) {
2471 local_deep_copy_contiguous(dst, value);
2473 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2474 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2475 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2476 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2477 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2478 dst(i0, i1, i2, i3, i4) = value;
2482template <
class DT,
class... DP>
2483void KOKKOS_INLINE_FUNCTION local_deep_copy(
2484 const View<DT, DP...>& dst,
2485 typename ViewTraits<DT, DP...>::const_value_type& value,
2486 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 6)>* =
nullptr) {
2487 if (dst.data() ==
nullptr) {
2491 if (dst.span_is_contiguous()) {
2492 local_deep_copy_contiguous(dst, value);
2494 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2495 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2496 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2497 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2498 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2499 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2500 dst(i0, i1, i2, i3, i4, i5) = value;
2504template <
class DT,
class... DP>
2505void KOKKOS_INLINE_FUNCTION local_deep_copy(
2506 const View<DT, DP...>& dst,
2507 typename ViewTraits<DT, DP...>::const_value_type& value,
2508 std::enable_if_t<(
unsigned(ViewTraits<DT, DP...>::rank) == 7)>* =
nullptr) {
2509 if (dst.data() ==
nullptr) {
2513 if (dst.span_is_contiguous()) {
2514 local_deep_copy_contiguous(dst, value);
2516 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2517 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2518 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2519 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2520 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2521 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2522 for (
size_t i6 = 0; i6 < dst.extent(6); ++i6)
2523 dst(i0, i1, i2, i3, i4, i5, i6) = value;
2536template <
class ExecSpace,
class DT,
class... DP>
2537inline void deep_copy(
2538 const ExecSpace& space,
const View<DT, DP...>& dst,
2539 typename ViewTraits<DT, DP...>::const_value_type& value,
2541 Kokkos::is_execution_space<ExecSpace>::value &&
2542 std::is_void<
typename ViewTraits<DT, DP...>::specialize>::value &&
2544 memory_space>::accessible>* =
2546 using dst_traits = ViewTraits<DT, DP...>;
2547 static_assert(std::is_same<
typename dst_traits::non_const_value_type,
2548 typename dst_traits::value_type>::value,
2549 "deep_copy requires non-const type");
2550 using dst_memory_space =
typename dst_traits::memory_space;
2551 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
2552 Kokkos::Profiling::beginDeepCopy(
2553 Kokkos::Profiling::make_space_handle(dst_memory_space::name()),
2554 dst.label(), dst.data(),
2556 "(none)", &value, dst.span() *
sizeof(
typename dst_traits::value_type));
2558 if (dst.data() ==
nullptr) {
2559 space.fence(
"Kokkos::deep_copy: scalar copy on space, dst data is null");
2560 }
else if (dst.span_is_contiguous()) {
2561 Impl::contiguous_fill_or_memset(space, dst, value);
2563 using ViewType =
View<DT, DP...>;
2565 int64_t strides[ViewType::Rank + 1];
2566 dst.stride(strides);
2567 Kokkos::Iterate iterate;
2568 if (std::is_same<
typename ViewType::array_layout,
2570 iterate = Kokkos::Iterate::Right;
2571 }
else if (std::is_same<
typename ViewType::array_layout,
2573 iterate = Kokkos::Iterate::Left;
2574 }
else if (std::is_same<
typename ViewType::array_layout,
2576 if (strides[0] > strides[ViewType::Rank > 0 ? ViewType::Rank - 1 : 0])
2577 iterate = Kokkos::Iterate::Right;
2579 iterate = Kokkos::Iterate::Left;
2581 if (std::is_same<
typename ViewType::execution_space::array_layout,
2583 iterate = Kokkos::Iterate::Right;
2585 iterate = Kokkos::Iterate::Left;
2590 using ViewTypeUniform =
2591 std::conditional_t<ViewType::Rank == 0,
2592 typename ViewType::uniform_runtime_type,
2593 typename ViewType::uniform_runtime_nomemspace_type>;
2594 if (dst.span() >
static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
2595 if (iterate == Kokkos::Iterate::Right)
2597 ViewType::Rank, int64_t>(dst, value, space);
2600 ViewType::Rank, int64_t>(dst, value, space);
2602 if (iterate == Kokkos::Iterate::Right)
2604 ViewType::Rank, int32_t>(dst, value, space);
2607 ViewType::Rank, int32_t>(dst, value, space);
2610 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2611 Kokkos::Profiling::endDeepCopy();
2617template <
class ExecSpace,
class DT,
class... DP>
2618inline void deep_copy(
2619 const ExecSpace& space,
const View<DT, DP...>& dst,
2620 typename ViewTraits<DT, DP...>::const_value_type& value,
2622 Kokkos::is_execution_space<ExecSpace>::value &&
2623 std::is_void<
typename ViewTraits<DT, DP...>::specialize>::value &&
2625 memory_space>::accessible>* =
2627 using dst_traits = ViewTraits<DT, DP...>;
2628 static_assert(std::is_same<
typename dst_traits::non_const_value_type,
2629 typename dst_traits::value_type>::value,
2630 "deep_copy requires non-const type");
2631 using dst_memory_space =
typename dst_traits::memory_space;
2632 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
2633 Kokkos::Profiling::beginDeepCopy(
2634 Kokkos::Profiling::make_space_handle(dst_memory_space::name()),
2635 dst.label(), dst.data(),
2637 "(none)", &value, dst.span() *
sizeof(
typename dst_traits::value_type));
2639 if (dst.data() ==
nullptr) {
2641 "Kokkos::deep_copy: scalar-to-view copy on space, dst data is null");
2643 space.fence(
"Kokkos::deep_copy: scalar-to-view copy on space, pre copy");
2644 using fill_exec_space =
typename dst_traits::memory_space::execution_space;
2645 if (dst.span_is_contiguous()) {
2646 Impl::contiguous_fill_or_memset(fill_exec_space(), dst, value);
2648 using ViewTypeUniform = std::conditional_t<
2649 View<DT, DP...>::Rank == 0,
2650 typename View<DT, DP...>::uniform_runtime_type,
2651 typename View<DT, DP...>::uniform_runtime_nomemspace_type>;
2652 Kokkos::Impl::ViewFill<ViewTypeUniform,
typename dst_traits::array_layout,
2653 fill_exec_space>(dst, value, fill_exec_space());
2655 fill_exec_space().fence(
2656 "Kokkos::deep_copy: scalar-to-view copy on space, fence after fill");
2658 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2659 Kokkos::Profiling::endDeepCopy();
2664template <
class ExecSpace,
class ST,
class... SP>
2665inline void deep_copy(
2666 const ExecSpace& exec_space,
2667 typename ViewTraits<ST, SP...>::non_const_value_type& dst,
2668 const View<ST, SP...>& src,
2669 std::enable_if_t<Kokkos::is_execution_space<ExecSpace>::value &&
2670 std::is_same<
typename ViewTraits<ST, SP...>::specialize,
2671 void>::value>* =
nullptr) {
2672 using src_traits = ViewTraits<ST, SP...>;
2673 using src_memory_space =
typename src_traits::memory_space;
2674 static_assert(src_traits::rank == 0,
2675 "ERROR: Non-rank-zero view in deep_copy( value , View )");
2676 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
2677 Kokkos::Profiling::beginDeepCopy(
2680 Kokkos::Profiling::make_space_handle(src_memory_space::name()),
2681 src.label(), src.data(),
sizeof(ST));
2684 if (src.data() ==
nullptr) {
2686 "Kokkos::deep_copy: view-to-scalar copy on space, src data is null");
2687 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2688 Kokkos::Profiling::endDeepCopy();
2693 Kokkos::Impl::DeepCopy<HostSpace, src_memory_space, ExecSpace>(
2694 exec_space, &dst, src.data(),
sizeof(ST));
2695 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2696 Kokkos::Profiling::endDeepCopy();
2702template <
class ExecSpace,
class DT,
class... DP,
class ST,
class... SP>
2703inline void deep_copy(
2704 const ExecSpace& exec_space,
const View<DT, DP...>& dst,
2705 const View<ST, SP...>& src,
2707 (Kokkos::is_execution_space<ExecSpace>::value &&
2708 std::is_void<
typename ViewTraits<DT, DP...>::specialize>::value &&
2709 std::is_void<
typename ViewTraits<ST, SP...>::specialize>::value &&
2710 (
unsigned(ViewTraits<DT, DP...>::rank) ==
unsigned(0) &&
2711 unsigned(ViewTraits<ST, SP...>::rank) ==
unsigned(0)))>* =
nullptr) {
2712 using src_traits = ViewTraits<ST, SP...>;
2713 using dst_traits = ViewTraits<DT, DP...>;
2715 using src_memory_space =
typename src_traits::memory_space;
2716 using dst_memory_space =
typename dst_traits::memory_space;
2717 static_assert(std::is_same<
typename dst_traits::value_type,
2718 typename src_traits::non_const_value_type>::value,
2719 "deep_copy requires matching non-const destination type");
2721 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
2722 Kokkos::Profiling::beginDeepCopy(
2723 Kokkos::Profiling::make_space_handle(dst_memory_space::name()),
2724 dst.label(), dst.data(),
2725 Kokkos::Profiling::make_space_handle(src_memory_space::name()),
2726 src.label(), src.data(),
sizeof(DT));
2729 if (dst.data() ==
nullptr && src.data() ==
nullptr) {
2731 "Kokkos::deep_copy: view-to-view copy on space, data is null");
2732 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2733 Kokkos::Profiling::endDeepCopy();
2738 if (dst.data() != src.data()) {
2739 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space, ExecSpace>(
2740 exec_space, dst.data(), src.data(),
2741 sizeof(
typename dst_traits::value_type));
2743 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2744 Kokkos::Profiling::endDeepCopy();
2752template <
class ExecSpace,
class DT,
class... DP,
class ST,
class... SP>
2753inline void deep_copy(
2754 const ExecSpace& exec_space,
const View<DT, DP...>& dst,
2755 const View<ST, SP...>& src,
2757 (Kokkos::is_execution_space<ExecSpace>::value &&
2758 std::is_void<
typename ViewTraits<DT, DP...>::specialize>::value &&
2759 std::is_void<
typename ViewTraits<ST, SP...>::specialize>::value &&
2760 (
unsigned(ViewTraits<DT, DP...>::rank) != 0 ||
2761 unsigned(ViewTraits<ST, SP...>::rank) != 0))>* =
nullptr) {
2762 using dst_type =
View<DT, DP...>;
2763 using src_type =
View<ST, SP...>;
2765 static_assert(std::is_same<
typename dst_type::value_type,
2766 typename dst_type::non_const_value_type>::value,
2767 "deep_copy requires non-const destination type");
2769 static_assert((unsigned(dst_type::rank) == unsigned(src_type::rank)),
2770 "deep_copy requires Views of equal rank");
2772 using dst_execution_space =
typename dst_type::execution_space;
2773 using src_execution_space =
typename src_type::execution_space;
2774 using dst_memory_space =
typename dst_type::memory_space;
2775 using src_memory_space =
typename src_type::memory_space;
2776 using dst_value_type =
typename dst_type::value_type;
2777 using src_value_type =
typename src_type::value_type;
2779 if (Kokkos::Tools::Experimental::get_callbacks().begin_deep_copy !=
nullptr) {
2780 Kokkos::Profiling::beginDeepCopy(
2781 Kokkos::Profiling::make_space_handle(dst_memory_space::name()),
2782 dst.label(), dst.data(),
2783 Kokkos::Profiling::make_space_handle(src_memory_space::name()),
2784 src.label(), src.data(), dst.span() *
sizeof(dst_value_type));
2787 dst_value_type* dst_start = dst.data();
2788 dst_value_type* dst_end = dst.data() + dst.span();
2789 src_value_type* src_start = src.data();
2790 src_value_type* src_end = src.data() + src.span();
2793 if ((dst_start ==
nullptr || src_start ==
nullptr) ||
2794 ((std::ptrdiff_t(dst_start) == std::ptrdiff_t(src_start)) &&
2795 (std::ptrdiff_t(dst_end) == std::ptrdiff_t(src_end)))) {
2797 if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
2798 (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
2799 (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
2800 (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
2801 std::string message(
2802 "Deprecation Error: Kokkos::deep_copy extents of views don't "
2804 message += dst.label();
2806 for (
int r = 0; r < dst_type::Rank - 1; r++) {
2807 message += std::to_string(dst.extent(r));
2810 message += std::to_string(dst.extent(dst_type::Rank - 1));
2812 message += src.label();
2814 for (
int r = 0; r < src_type::Rank - 1; r++) {
2815 message += std::to_string(src.extent(r));
2818 message += std::to_string(src.extent(src_type::Rank - 1));
2821 Kokkos::Impl::throw_runtime_exception(message);
2823 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2824 Kokkos::Profiling::endDeepCopy();
2830 ExecCanAccessSrcDst =
2835 DstExecCanAccessSrc =
2837 src_memory_space>::accessible
2841 SrcExecCanAccessDst =
2843 dst_memory_space>::accessible
2847 if ((((std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end) &&
2848 ((std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start)) &&
2849 ((dst.span_is_contiguous() && src.span_is_contiguous()))) {
2850 std::string message(
"Error: Kokkos::deep_copy of overlapping views: ");
2851 message += dst.label();
2853 message += std::to_string((std::ptrdiff_t)dst_start);
2855 message += std::to_string((std::ptrdiff_t)dst_end);
2857 message += src.label();
2859 message += std::to_string((std::ptrdiff_t)src_start);
2861 message += std::to_string((std::ptrdiff_t)src_end);
2863 Kokkos::Impl::throw_runtime_exception(message);
2867 if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
2868 (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
2869 (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
2870 (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
2871 std::string message(
2872 "Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
2873 message += dst.label();
2875 for (
int r = 0; r < dst_type::Rank - 1; r++) {
2876 message += std::to_string(dst.extent(r));
2879 message += std::to_string(dst.extent(dst_type::Rank - 1));
2881 message += src.label();
2883 for (
int r = 0; r < src_type::Rank - 1; r++) {
2884 message += std::to_string(src.extent(r));
2887 message += std::to_string(src.extent(src_type::Rank - 1));
2890 Kokkos::Impl::throw_runtime_exception(message);
2896 if (std::is_same<
typename dst_type::value_type,
2897 typename src_type::non_const_value_type>::value &&
2898 (std::is_same<
typename dst_type::array_layout,
2899 typename src_type::array_layout>::value ||
2900 (dst_type::rank == 1 && src_type::rank == 1)) &&
2901 dst.span_is_contiguous() && src.span_is_contiguous() &&
2902 ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
2903 ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
2904 ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
2905 ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
2906 ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
2907 ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
2908 ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
2909 ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))) {
2910 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
2911 if ((
void*)dst.data() != (
void*)src.data()) {
2912 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space, ExecSpace>(
2913 exec_space, dst.data(), src.data(), nbytes);
2918 if (ExecCanAccessSrcDst) {
2919 Impl::view_copy(exec_space, dst, src);
2920 }
else if (DstExecCanAccessSrc || SrcExecCanAccessDst) {
2921 using cpy_exec_space =
2922 std::conditional_t<DstExecCanAccessSrc, dst_execution_space,
2923 src_execution_space>;
2925 "Kokkos::deep_copy: view-to-view noncontiguous copy on space, pre "
2927 Impl::view_copy(cpy_exec_space(), dst, src);
2928 cpy_exec_space().fence(
2929 "Kokkos::deep_copy: view-to-view noncontiguous copy on space, post "
2932 Kokkos::Impl::throw_runtime_exception(
2933 "deep_copy given views that would require a temporary allocation");
2936 if (Kokkos::Tools::Experimental::get_callbacks().end_deep_copy !=
nullptr) {
2937 Kokkos::Profiling::endDeepCopy();
2949template <
typename ViewType>
2950bool size_mismatch(
const ViewType& view,
unsigned int max_extent,
2951 const size_t new_extents[8]) {
2952 for (
unsigned int dim = 0; dim < max_extent; ++dim)
2953 if (new_extents[dim] != view.extent(dim)) {
2956 for (
unsigned int dim = max_extent; dim < 8; ++dim)
2957 if (new_extents[dim] != KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
2967template <
class T,
class... P,
class... ViewCtorArgs>
2968inline typename std::enable_if<
2969 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
2971 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
2973impl_resize(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2975 const size_t n2,
const size_t n3,
const size_t n4,
const size_t n5,
2976 const size_t n6,
const size_t n7) {
2978 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
2981 "Can only resize managed views");
2982 static_assert(!alloc_prop_input::has_label,
2983 "The view constructor arguments passed to Kokkos::resize "
2984 "must not include a label!");
2985 static_assert(!alloc_prop_input::has_pointer,
2986 "The view constructor arguments passed to Kokkos::resize must "
2987 "not include a pointer!");
2988 static_assert(!alloc_prop_input::has_memory_space,
2989 "The view constructor arguments passed to Kokkos::resize must "
2990 "not include a memory space instance!");
2999 const size_t new_extents[8] = {n0, n1, n2, n3, n4, n5, n6, n7};
3000 const bool sizeMismatch = Impl::size_mismatch(v, v.rank_dynamic, new_extents);
3003 auto prop_copy = Impl::with_properties_if_unset(
3004 arg_prop,
typename view_type::execution_space{}, v.label());
3006 view_type v_resized(prop_copy, n0, n1, n2, n3, n4, n5, n6, n7);
3008 if constexpr (alloc_prop_input::has_execution_space)
3009 Kokkos::Impl::ViewRemap<view_type, view_type>(
3010 v_resized, v, Impl::get_property<Impl::ExecutionSpaceTag>(prop_copy));
3012 Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3013 Kokkos::fence(
"Kokkos::resize(View)");
3020template <
class T,
class... P,
class... ViewCtorArgs>
3021inline std::enable_if_t<
3022 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3024 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3026resize(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3028 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3029 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3030 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3031 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3032 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3033 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3034 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3035 impl_resize(arg_prop, v, n0, n1, n2, n3, n4, n5, n6, n7);
3038template <
class T,
class... P>
3039inline std::enable_if_t<
3040 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3042 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3045 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3046 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3047 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3048 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3049 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3050 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3051 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3052 impl_resize(Impl::ViewCtorProp<>{}, v, n0, n1, n2, n3, n4, n5, n6, n7);
3055template <
class I,
class T,
class... P>
3056inline std::enable_if_t<
3057 (Impl::is_view_ctor_property<I>::value ||
3058 Kokkos::is_execution_space<I>::value) &&
3059 (std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3061 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3064 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3065 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3066 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3067 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3068 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3069 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3070 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3071 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3072 impl_resize(Kokkos::view_alloc(arg_prop), v, n0, n1, n2, n3, n4, n5, n6, n7);
3075template <
class T,
class... P,
class... ViewCtorArgs>
3076inline std::enable_if_t<
3077 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3079 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3081 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3083 is_layouttiled<
typename Kokkos::View<T, P...>::array_layout>::value>
3084impl_resize(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3086 const typename Kokkos::View<T, P...>::array_layout& layout) {
3088 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3091 "Can only resize managed views");
3092 static_assert(!alloc_prop_input::has_label,
3093 "The view constructor arguments passed to Kokkos::resize "
3094 "must not include a label!");
3095 static_assert(!alloc_prop_input::has_pointer,
3096 "The view constructor arguments passed to Kokkos::resize must "
3097 "not include a pointer!");
3098 static_assert(!alloc_prop_input::has_memory_space,
3099 "The view constructor arguments passed to Kokkos::resize must "
3100 "not include a memory space instance!");
3102 if (v.layout() != layout) {
3103 auto prop_copy = Impl::with_properties_if_unset(arg_prop, v.label());
3105 view_type v_resized(prop_copy, layout);
3107 if constexpr (alloc_prop_input::has_execution_space)
3108 Kokkos::Impl::ViewRemap<view_type, view_type>(
3109 v_resized, v, Impl::get_property<Impl::ExecutionSpaceTag>(arg_prop));
3111 Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3112 Kokkos::fence(
"Kokkos::resize(View)");
3122template <
class T,
class... P,
class... ViewCtorArgs>
3123inline std::enable_if_t<
3124 !(std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3126 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3128 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3130 is_layouttiled<
typename Kokkos::View<T, P...>::array_layout>::value)>
3131impl_resize(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3133 const typename Kokkos::View<T, P...>::array_layout& layout) {
3135 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3138 "Can only resize managed views");
3139 static_assert(!alloc_prop_input::has_label,
3140 "The view constructor arguments passed to Kokkos::resize "
3141 "must not include a label!");
3142 static_assert(!alloc_prop_input::has_pointer,
3143 "The view constructor arguments passed to Kokkos::resize must "
3144 "not include a pointer!");
3145 static_assert(!alloc_prop_input::has_memory_space,
3146 "The view constructor arguments passed to Kokkos::resize must "
3147 "not include a memory space instance!");
3149 auto prop_copy = Impl::with_properties_if_unset(arg_prop, v.label());
3151 view_type v_resized(prop_copy, layout);
3153 if constexpr (alloc_prop_input::has_execution_space)
3154 Kokkos::Impl::ViewRemap<view_type, view_type>(
3155 v_resized, v, Impl::get_property<Impl::ExecutionSpaceTag>(arg_prop));
3157 Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3158 Kokkos::fence(
"Kokkos::resize(View)");
3164template <
class T,
class... P,
class... ViewCtorArgs>
3165inline void resize(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3167 const typename Kokkos::View<T, P...>::array_layout& layout) {
3168 impl_resize(arg_prop, v, layout);
3171template <
class I,
class T,
class... P>
3172inline std::enable_if_t<Impl::is_view_ctor_property<I>::value ||
3173 Kokkos::is_execution_space<I>::value>
3175 const typename Kokkos::View<T, P...>::array_layout& layout) {
3176 impl_resize(arg_prop, v, layout);
3179template <
class ExecutionSpace,
class T,
class... P>
3181 const typename Kokkos::View<T, P...>::array_layout& layout) {
3182 impl_resize(Impl::ViewCtorProp<>(), exec_space, v, layout);
3185template <
class T,
class... P>
3187 const typename Kokkos::View<T, P...>::array_layout& layout) {
3188 impl_resize(Impl::ViewCtorProp<>{}, v, layout);
3192template <
class T,
class... P,
class... ViewCtorArgs>
3193inline std::enable_if_t<
3194 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3196 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3199 const size_t n2,
const size_t n3,
const size_t n4,
const size_t n5,
3200 const size_t n6,
const size_t n7,
3201 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
3203 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3206 "Can only realloc managed views");
3207 static_assert(!alloc_prop_input::has_label,
3208 "The view constructor arguments passed to Kokkos::realloc must "
3209 "not include a label!");
3210 static_assert(!alloc_prop_input::has_pointer,
3211 "The view constructor arguments passed to Kokkos::realloc must "
3212 "not include a pointer!");
3213 static_assert(!alloc_prop_input::has_memory_space,
3214 "The view constructor arguments passed to Kokkos::realloc must "
3215 "not include a memory space instance!");
3217 const size_t new_extents[8] = {n0, n1, n2, n3, n4, n5, n6, n7};
3218 const bool sizeMismatch = Impl::size_mismatch(v, v.rank_dynamic, new_extents);
3221 auto arg_prop_copy = Impl::with_properties_if_unset(arg_prop, v.label());
3224 v = view_type(arg_prop_copy, n0, n1, n2, n3, n4, n5, n6, n7);
3225 }
else if (alloc_prop_input::initialize) {
3226 if constexpr (alloc_prop_input::has_execution_space) {
3227 const auto& exec_space =
3228 Impl::get_property<Impl::ExecutionSpaceTag>(arg_prop);
3229 Kokkos::deep_copy(exec_space, v,
typename view_type::value_type{});
3231 Kokkos::deep_copy(v,
typename view_type::value_type{});
3235template <
class T,
class... P,
class... ViewCtorArgs>
3236inline std::enable_if_t<
3237 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3239 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3241realloc(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3243 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3244 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3245 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3246 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3247 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3248 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3249 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3250 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3251 impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7, arg_prop);
3254template <
class T,
class... P>
3255inline std::enable_if_t<
3256 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3258 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3261 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3262 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3263 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3264 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3265 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3266 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3267 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3268 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3269 impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7, Impl::ViewCtorProp<>{});
3272template <
class I,
class T,
class... P>
3273inline std::enable_if_t<
3274 Impl::is_view_ctor_property<I>::value &&
3275 (std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3277 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3280 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3281 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3282 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3283 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3284 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3285 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3286 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3287 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3288 impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7, Kokkos::view_alloc(arg_prop));
3291template <
class T,
class... P,
class... ViewCtorArgs>
3292inline std::enable_if_t<
3293 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3295 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3297 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3299 is_layouttiled<
typename Kokkos::View<T, P...>::array_layout>::value>
3301 const typename Kokkos::View<T, P...>::array_layout& layout,
3302 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
3304 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3307 "Can only realloc managed views");
3308 static_assert(!alloc_prop_input::has_label,
3309 "The view constructor arguments passed to Kokkos::realloc must "
3310 "not include a label!");
3311 static_assert(!alloc_prop_input::has_pointer,
3312 "The view constructor arguments passed to Kokkos::realloc must "
3313 "not include a pointer!");
3314 static_assert(!alloc_prop_input::has_memory_space,
3315 "The view constructor arguments passed to Kokkos::realloc must "
3316 "not include a memory space instance!");
3318 if (v.layout() != layout) {
3320 v = view_type(arg_prop, layout);
3321 }
else if (alloc_prop_input::initialize) {
3322 if constexpr (alloc_prop_input::has_execution_space) {
3323 const auto& exec_space =
3324 Impl::get_property<Impl::ExecutionSpaceTag>(arg_prop);
3325 Kokkos::deep_copy(exec_space, v,
typename view_type::value_type{});
3327 Kokkos::deep_copy(v,
typename view_type::value_type{});
3334template <
class T,
class... P,
class... ViewCtorArgs>
3335inline std::enable_if_t<
3336 !(std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3338 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3340 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3342 is_layouttiled<
typename Kokkos::View<T, P...>::array_layout>::value)>
3344 const typename Kokkos::View<T, P...>::array_layout& layout,
3345 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
3347 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3350 "Can only realloc managed views");
3351 static_assert(!alloc_prop_input::has_label,
3352 "The view constructor arguments passed to Kokkos::realloc must "
3353 "not include a label!");
3354 static_assert(!alloc_prop_input::has_pointer,
3355 "The view constructor arguments passed to Kokkos::realloc must "
3356 "not include a pointer!");
3357 static_assert(!alloc_prop_input::has_memory_space,
3358 "The view constructor arguments passed to Kokkos::realloc must "
3359 "not include a memory space instance!");
3361 auto arg_prop_copy = Impl::with_properties_if_unset(arg_prop, v.label());
3364 v = view_type(arg_prop_copy, layout);
3367template <
class T,
class... P,
class... ViewCtorArgs>
3369 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3371 const typename Kokkos::View<T, P...>::array_layout& layout) {
3372 impl_realloc(v, layout, arg_prop);
3375template <
class I,
class T,
class... P>
3376inline std::enable_if_t<Impl::is_view_ctor_property<I>::value> realloc(
3378 const typename Kokkos::View<T, P...>::array_layout& layout) {
3379 impl_realloc(v, layout, Kokkos::view_alloc(arg_prop));
3382template <
class T,
class... P>
3385 const typename Kokkos::View<T, P...>::array_layout& layout) {
3386 impl_realloc(v, layout, Impl::ViewCtorProp<>{});
3398template <
class Space,
class T,
class... P>
3399struct MirrorViewType {
3403 using memory_space =
typename Space::memory_space;
3407 std::is_same<memory_space, typename src_view_type::memory_space>::value
3410 using array_layout =
typename src_view_type::array_layout;
3413 using data_type =
typename src_view_type::non_const_data_type;
3419 std::conditional_t<is_same_memspace, src_view_type, dest_view_type>;
3422template <
class Space,
class T,
class... P>
3427 using memory_space =
typename Space::memory_space;
3431 std::is_same<memory_space, typename src_view_type::memory_space>::value
3434 using array_layout =
typename src_view_type::array_layout;
3437 using data_type =
typename src_view_type::non_const_data_type;
3442template <
class T,
class... P,
class... ViewCtorArgs>
3443inline std::enable_if_t<!Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space,
3446 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
3447 using src_type =
View<T, P...>;
3448 using dst_type =
typename src_type::HostMirror;
3449 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3452 !alloc_prop_input::has_label,
3453 "The view constructor arguments passed to Kokkos::create_mirror "
3454 "must not include a label!");
3456 !alloc_prop_input::has_pointer,
3457 "The view constructor arguments passed to Kokkos::create_mirror must "
3458 "not include a pointer!");
3460 !alloc_prop_input::allow_padding,
3461 "The view constructor arguments passed to Kokkos::create_mirror must "
3462 "not explicitly allow padding!");
3464 auto prop_copy = Impl::with_properties_if_unset(
3465 arg_prop, std::string(src.label()).append(
"_mirror"));
3467 return dst_type(prop_copy, src.layout());
3471template <
class T,
class... P,
class... ViewCtorArgs,
3472 class Enable = std::enable_if_t<
3473 Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
3475 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
3476 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3479 !alloc_prop_input::has_label,
3480 "The view constructor arguments passed to Kokkos::create_mirror "
3481 "must not include a label!");
3483 !alloc_prop_input::has_pointer,
3484 "The view constructor arguments passed to Kokkos::create_mirror must "
3485 "not include a pointer!");
3487 !alloc_prop_input::allow_padding,
3488 "The view constructor arguments passed to Kokkos::create_mirror must "
3489 "not explicitly allow padding!");
3491 auto prop_copy = Impl::with_properties_if_unset(
3492 arg_prop, std::string(src.label()).append(
"_mirror"));
3493 using alloc_prop =
decltype(prop_copy);
3495 return typename Impl::MirrorType<
typename alloc_prop::memory_space, T,
3496 P...>::view_type(prop_copy, src.layout());
3500template <
class T,
class... P>
3501std::enable_if_t<std::is_void<
typename ViewTraits<T, P...>::specialize>::value,
3504 return Impl::create_mirror(v, Impl::ViewCtorProp<>{});
3507template <
class T,
class... P>
3508std::enable_if_t<std::is_void<
typename ViewTraits<T, P...>::specialize>::value,
3510create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
3512 return Impl::create_mirror(v, view_alloc(wi));
3515template <
class Space,
class T,
class... P,
3516 typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
3517std::enable_if_t<std::is_void<
typename ViewTraits<T, P...>::specialize>::value,
3518 typename Impl::MirrorType<Space, T, P...>::view_type>
3520 return Impl::create_mirror(v, view_alloc(
typename Space::memory_space{}));
3523template <
class T,
class... P,
class... ViewCtorArgs,
3524 typename Enable = std::enable_if_t<
3525 std::is_void<
typename ViewTraits<T, P...>::specialize>::value &&
3526 Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
3527auto create_mirror(Impl::ViewCtorProp<ViewCtorArgs...>
const& arg_prop,
3529 return Impl::create_mirror(v, arg_prop);
3532template <
class T,
class... P,
class... ViewCtorArgs>
3534 std::is_void<
typename ViewTraits<T, P...>::specialize>::value &&
3535 !Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space,
3537create_mirror(Impl::ViewCtorProp<ViewCtorArgs...>
const& arg_prop,
3539 return Impl::create_mirror(v, arg_prop);
3542template <
class Space,
class T,
class... P,
3543 typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
3544std::enable_if_t<std::is_void<
typename ViewTraits<T, P...>::specialize>::value,
3545 typename Impl::MirrorType<Space, T, P...>::view_type>
3546create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space
const&,
3548 return Impl::create_mirror(v, view_alloc(
typename Space::memory_space{}, wi));
3553template <
class T,
class... P,
class... ViewCtorArgs>
3554inline std::enable_if_t<
3555 !Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space &&
3558 typename Kokkos::View<T, P...>::HostMirror::memory_space>::value &&
3561 typename Kokkos::View<T, P...>::HostMirror::data_type>::value),
3564 const Impl::ViewCtorProp<ViewCtorArgs...>&) {
3568template <
class T,
class... P,
class... ViewCtorArgs>
3569inline std::enable_if_t<
3570 !Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space &&
3571 !(std::is_same<
typename Kokkos::View<T, P...>::memory_space,
3573 T, P...>::HostMirror::memory_space>::value &&
3576 typename Kokkos::View<T, P...>::HostMirror::data_type>::value),
3579 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
3580 return Kokkos::Impl::create_mirror(src, arg_prop);
3584template <
class T,
class... P,
class... ViewCtorArgs,
3585 class = std::enable_if_t<
3586 Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
3587std::enable_if_t<Impl::MirrorViewType<
3588 typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space,
3589 T, P...>::is_same_memspace,
3590 typename Impl::MirrorViewType<
3591 typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space,
3592 T, P...>::view_type>
3594 const Impl::ViewCtorProp<ViewCtorArgs...>&) {
3599template <
class T,
class... P,
class... ViewCtorArgs,
3600 class = std::enable_if_t<
3601 Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
3602std::enable_if_t<!Impl::MirrorViewType<
3603 typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space,
3604 T, P...>::is_same_memspace,
3605 typename Impl::MirrorViewType<
3606 typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space,
3607 T, P...>::view_type>
3609 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
3610 return Kokkos::Impl::create_mirror(src, arg_prop);
3614template <
class T,
class... P>
3618 typename Kokkos::View<T, P...>::HostMirror::memory_space>::value &&
3621 typename Kokkos::View<T, P...>::HostMirror::data_type>::value,
3627template <
class T,
class... P>
3631 typename Kokkos::View<T, P...>::HostMirror::memory_space>::value &&
3634 typename Kokkos::View<T, P...>::HostMirror::data_type>::value),
3637 return Kokkos::create_mirror(src);
3640template <
class T,
class... P>
3641typename Kokkos::View<T, P...>::HostMirror create_mirror_view(
3643 return Impl::create_mirror_view(v, view_alloc(wi));
3647template <
class Space,
class T,
class... P,
3648 class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
3649typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3651 std::enable_if_t<Impl::MirrorViewType<Space, T, P...>::is_same_memspace>* =
3657template <
class Space,
class T,
class... P,
3658 class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
3659typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3661 std::enable_if_t<!Impl::MirrorViewType<Space, T, P...>::is_same_memspace>* =
3663 return Kokkos::create_mirror(space, src);
3666template <
class Space,
class T,
class... P,
3667 typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
3668typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3669 Kokkos::Impl::WithoutInitializing_t wi, Space
const&,
3671 return Impl::create_mirror_view(
3672 v, view_alloc(
typename Space::memory_space{}, wi));
3675template <
class T,
class... P,
class... ViewCtorArgs>
3676auto create_mirror_view(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3678 return Impl::create_mirror_view(v, arg_prop);
3681template <
class... ViewCtorArgs,
class T,
class... P>
3682auto create_mirror_view_and_copy(
3683 const Impl::ViewCtorProp<ViewCtorArgs...>&,
3686 std::is_void<
typename ViewTraits<T, P...>::specialize>::value &&
3687 Impl::MirrorViewType<
3688 typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
3689 P...>::is_same_memspace>* =
nullptr) {
3690 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3692 alloc_prop_input::has_memory_space,
3693 "The view constructor arguments passed to "
3694 "Kokkos::create_mirror_view_and_copy must include a memory space!");
3695 static_assert(!alloc_prop_input::has_pointer,
3696 "The view constructor arguments passed to "
3697 "Kokkos::create_mirror_view_and_copy must "
3698 "not include a pointer!");
3699 static_assert(!alloc_prop_input::allow_padding,
3700 "The view constructor arguments passed to "
3701 "Kokkos::create_mirror_view_and_copy must "
3702 "not explicitly allow padding!");
3705 if (!alloc_prop_input::has_execution_space)
3707 "Kokkos::create_mirror_view_and_copy: fence before returning src view");
3711template <
class... ViewCtorArgs,
class T,
class... P>
3712auto create_mirror_view_and_copy(
3713 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
3716 std::is_void<
typename ViewTraits<T, P...>::specialize>::value &&
3717 !Impl::MirrorViewType<
3718 typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
3719 P...>::is_same_memspace>* =
nullptr) {
3720 using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
3722 alloc_prop_input::has_memory_space,
3723 "The view constructor arguments passed to "
3724 "Kokkos::create_mirror_view_and_copy must include a memory space!");
3725 static_assert(!alloc_prop_input::has_pointer,
3726 "The view constructor arguments passed to "
3727 "Kokkos::create_mirror_view_and_copy must "
3728 "not include a pointer!");
3729 static_assert(!alloc_prop_input::allow_padding,
3730 "The view constructor arguments passed to "
3731 "Kokkos::create_mirror_view_and_copy must "
3732 "not explicitly allow padding!");
3733 using Space =
typename alloc_prop_input::memory_space;
3734 using Mirror =
typename Impl::MirrorViewType<Space, T, P...>::view_type;
3736 auto arg_prop_copy = Impl::with_properties_if_unset(
3737 arg_prop, std::string{}, WithoutInitializing,
3738 typename Space::execution_space{});
3740 std::string& label = Impl::get_property<Impl::LabelTag>(arg_prop_copy);
3741 if (label.empty()) label = src.label();
3742 auto mirror =
typename Mirror::non_const_type{arg_prop_copy, src.layout()};
3743 if constexpr (alloc_prop_input::has_execution_space) {
3744 deep_copy(Impl::get_property<Impl::ExecutionSpaceTag>(arg_prop_copy),
3747 deep_copy(mirror, src);
3754template <
class Space,
class T,
class... P,
3755 typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
3756typename Impl::MirrorViewType<Space, T, P...>::view_type
3757create_mirror_view_and_copy(
3759 std::string
const& name =
"",
3761 std::is_void<
typename ViewTraits<T, P...>::specialize>::value>* =
3763 return create_mirror_view_and_copy(
3764 Kokkos::view_alloc(
typename Space::memory_space{}, name), src);
Declaration of various MemoryLayout options.
Declaration of parallel operators.
Memory management for host memory.
static constexpr const char * name()
Return Name of the MemorySpace.
Execution policy for work over a range of an integral type.
View to an array of data.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory.
Can AccessSpace access MemorySpace ?
Traits class for accessing attributes of a View.
Replacement for std::pair that works on CUDA devices.