45 #ifndef KOKKOS_COPYVIEWS_HPP_
46 #define KOKKOS_COPYVIEWS_HPP_
52 #ifndef KOKKOS_IMPL_COMPILING_LIBRARY
53 #define KOKKOS_IMPL_COMPILING_LIBRARY false
60 template <
class Layout>
61 struct ViewFillLayoutSelector {};
64 struct ViewFillLayoutSelector<Kokkos::LayoutLeft> {
65 static const Kokkos::Iterate iterate = Kokkos::Iterate::Left;
69 struct ViewFillLayoutSelector<Kokkos::LayoutRight> {
70 static const Kokkos::Iterate iterate = Kokkos::Iterate::Right;
76 #include <impl/Kokkos_ViewFillCopyETIAvail.hpp>
81 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
83 struct ViewFill<ViewType, Layout, ExecSpace, 0, iType, ETIAvail> {
85 typename ViewType::const_value_type val;
86 typedef typename ViewType::non_const_value_type ST;
87 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
90 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
92 struct ViewFill<ViewType, Layout, ExecSpace, 1, iType, ETIAvail> {
94 typename ViewType::const_value_type val;
95 typedef typename ViewType::non_const_value_type ST;
96 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
97 KOKKOS_INLINE_FUNCTION
98 void operator()(
const iType&)
const;
101 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
103 struct ViewFill<ViewType, Layout, ExecSpace, 2, iType, ETIAvail> {
105 typename ViewType::const_value_type val;
106 typedef typename ViewType::non_const_value_type ST;
107 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
108 KOKKOS_INLINE_FUNCTION
109 void operator()(
const iType&,
const iType&)
const;
112 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
114 struct ViewFill<ViewType, Layout, ExecSpace, 3, iType, ETIAvail> {
116 typename ViewType::const_value_type val;
117 typedef typename ViewType::non_const_value_type ST;
118 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
119 KOKKOS_INLINE_FUNCTION
120 void operator()(
const iType&,
const iType&,
const iType&)
const;
123 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
125 struct ViewFill<ViewType, Layout, ExecSpace, 4, iType, ETIAvail> {
127 typename ViewType::const_value_type val;
128 typedef typename ViewType::non_const_value_type ST;
129 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
130 KOKKOS_INLINE_FUNCTION
131 void operator()(
const iType&,
const iType&,
const iType&,
const iType&)
const;
134 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
136 struct ViewFill<ViewType, Layout, ExecSpace, 5, iType, ETIAvail> {
138 typename ViewType::const_value_type val;
139 typedef typename ViewType::non_const_value_type ST;
140 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
141 KOKKOS_INLINE_FUNCTION
142 void operator()(
const iType&,
const iType&,
const iType&,
const iType&,
146 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
148 struct ViewFill<ViewType, Layout, ExecSpace, 6, iType, ETIAvail> {
150 typename ViewType::const_value_type val;
151 typedef typename ViewType::non_const_value_type ST;
152 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
153 KOKKOS_INLINE_FUNCTION
154 void operator()(
const iType&,
const iType&,
const iType&,
const iType&,
155 const iType&,
const iType&)
const;
158 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
160 struct ViewFill<ViewType, Layout, ExecSpace, 7, iType, ETIAvail> {
162 typename ViewType::const_value_type val;
163 typedef typename ViewType::non_const_value_type ST;
164 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
165 KOKKOS_INLINE_FUNCTION
166 void operator()(
const iType&,
const iType&,
const iType&,
const iType&,
167 const iType&,
const iType&,
const iType&)
const;
170 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType,
172 struct ViewFill<ViewType, Layout, ExecSpace, 8, iType, ETIAvail> {
174 typename ViewType::const_value_type val;
175 typedef typename ViewType::non_const_value_type ST;
176 ViewFill(
const ViewType&,
const ST&,
const ExecSpace&);
177 KOKKOS_INLINE_FUNCTION
178 void operator()(
const iType&,
const iType&,
const iType&,
const iType&,
179 const iType&,
const iType&,
const iType&,
const iType&)
const;
182 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
183 struct ViewFill<ViewType, Layout, ExecSpace, 0, iType,
184 KOKKOS_IMPL_COMPILING_LIBRARY> {
185 typedef typename ViewType::non_const_value_type ST;
186 ViewFill(
const ViewType& a,
const ST& val,
const ExecSpace& space) {
188 ExecSpace>(space, a.data(), &val,
sizeof(ST));
192 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
193 struct ViewFill<ViewType, Layout, ExecSpace, 1, iType,
194 KOKKOS_IMPL_COMPILING_LIBRARY> {
196 typename ViewType::const_value_type val;
199 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
200 const ExecSpace& space)
203 policy_type(space, 0, a.extent(0)), *
this);
206 KOKKOS_INLINE_FUNCTION
207 void operator()(
const iType& i)
const { a(i) = val; };
210 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
211 struct ViewFill<ViewType, Layout, ExecSpace, 2, iType,
212 KOKKOS_IMPL_COMPILING_LIBRARY> {
214 typename ViewType::const_value_type val;
216 typedef Kokkos::Rank<2, ViewFillLayoutSelector<Layout>::iterate,
217 ViewFillLayoutSelector<Layout>::iterate>
219 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
220 Kokkos::IndexType<iType>>
223 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
224 const ExecSpace& space)
227 policy_type(space, {0, 0}, {a.extent(0), a.extent(1)}),
231 KOKKOS_INLINE_FUNCTION
232 void operator()(
const iType& i0,
const iType& i1)
const { a(i0, i1) = val; };
235 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
236 struct ViewFill<ViewType, Layout, ExecSpace, 3, iType,
237 KOKKOS_IMPL_COMPILING_LIBRARY> {
239 typename ViewType::const_value_type val;
241 typedef Kokkos::Rank<3, ViewFillLayoutSelector<Layout>::iterate,
242 ViewFillLayoutSelector<Layout>::iterate>
244 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
245 Kokkos::IndexType<iType>>
248 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
249 const ExecSpace& space)
252 "Kokkos::ViewFill-3D",
253 policy_type(space, {0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2)}),
257 KOKKOS_INLINE_FUNCTION
258 void operator()(
const iType& i0,
const iType& i1,
const iType& i2)
const {
263 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
264 struct ViewFill<ViewType, Layout, ExecSpace, 4, iType,
265 KOKKOS_IMPL_COMPILING_LIBRARY> {
267 typename ViewType::const_value_type val;
269 typedef Kokkos::Rank<4, ViewFillLayoutSelector<Layout>::iterate,
270 ViewFillLayoutSelector<Layout>::iterate>
272 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
273 Kokkos::IndexType<iType>>
276 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
277 const ExecSpace& space)
280 "Kokkos::ViewFill-4D",
281 policy_type(space, {0, 0, 0, 0},
282 {a.extent(0), a.extent(1), a.extent(2), a.extent(3)}),
286 KOKKOS_INLINE_FUNCTION
287 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
288 const iType& i3)
const {
289 a(i0, i1, i2, i3) = val;
293 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
294 struct ViewFill<ViewType, Layout, ExecSpace, 5, iType,
295 KOKKOS_IMPL_COMPILING_LIBRARY> {
297 typename ViewType::const_value_type val;
299 typedef Kokkos::Rank<5, ViewFillLayoutSelector<Layout>::iterate,
300 ViewFillLayoutSelector<Layout>::iterate>
302 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
303 Kokkos::IndexType<iType>>
306 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
307 const ExecSpace& space)
310 policy_type(space, {0, 0, 0, 0, 0},
311 {a.extent(0), a.extent(1), a.extent(2),
312 a.extent(3), a.extent(4)}),
316 KOKKOS_INLINE_FUNCTION
317 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
318 const iType& i3,
const iType& i4)
const {
319 a(i0, i1, i2, i3, i4) = val;
323 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
324 struct ViewFill<ViewType, Layout, ExecSpace, 6, iType,
325 KOKKOS_IMPL_COMPILING_LIBRARY> {
327 typename ViewType::const_value_type val;
329 typedef Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
330 ViewFillLayoutSelector<Layout>::iterate>
332 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
333 Kokkos::IndexType<iType>>
336 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
337 const ExecSpace& space)
340 policy_type(space, {0, 0, 0, 0, 0, 0},
341 {a.extent(0), a.extent(1), a.extent(2),
342 a.extent(3), a.extent(4), a.extent(5)}),
346 KOKKOS_INLINE_FUNCTION
347 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
348 const iType& i3,
const iType& i4,
const iType& i5)
const {
349 a(i0, i1, i2, i3, i4, i5) = val;
353 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
354 struct ViewFill<ViewType, Layout, ExecSpace, 7, iType,
355 KOKKOS_IMPL_COMPILING_LIBRARY> {
357 typename ViewType::const_value_type val;
359 typedef Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
360 ViewFillLayoutSelector<Layout>::iterate>
362 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
363 Kokkos::IndexType<iType>>
366 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
367 const ExecSpace& space)
370 policy_type(space, {0, 0, 0, 0, 0, 0},
371 {a.extent(0), a.extent(1), a.extent(2),
372 a.extent(3), a.extent(5), a.extent(6)}),
376 KOKKOS_INLINE_FUNCTION
377 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
378 const iType& i4,
const iType& i5,
const iType& i6)
const {
379 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
380 a(i0, i1, i2, i3, i4, i5, i6) = val;
384 template <
class ViewType,
class Layout,
class ExecSpace,
typename iType>
385 struct ViewFill<ViewType, Layout, ExecSpace, 8, iType,
386 KOKKOS_IMPL_COMPILING_LIBRARY> {
388 typename ViewType::const_value_type val;
390 typedef Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
391 ViewFillLayoutSelector<Layout>::iterate>
393 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
394 Kokkos::IndexType<iType>>
397 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_,
398 const ExecSpace& space)
401 policy_type(space, {0, 0, 0, 0, 0, 0},
402 {a.extent(0), a.extent(1), a.extent(3),
403 a.extent(5), a.extent(6), a.extent(7)}),
407 KOKKOS_INLINE_FUNCTION
408 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
409 const iType& i5,
const iType& i6,
const iType& i7)
const {
410 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
411 for (iType i4 = 0; i4 < iType(a.extent(4)); i4++)
412 a(i0, i1, i2, i3, i4, i5, i6, i7) = val;
416 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
417 typename iType,
bool ETIAvail>
418 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 1, iType, ETIAvail> {
421 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
422 KOKKOS_INLINE_FUNCTION
423 void operator()(
const iType& i0)
const;
426 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
427 typename iType,
bool ETIAvail>
428 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 2, iType, ETIAvail> {
431 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
432 KOKKOS_INLINE_FUNCTION
433 void operator()(
const iType& i0,
const iType& i1)
const;
436 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
437 typename iType,
bool ETIAvail>
438 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 3, iType, ETIAvail> {
441 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
442 KOKKOS_INLINE_FUNCTION
443 void operator()(
const iType& i0,
const iType& i1,
const iType& i2)
const;
446 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
447 typename iType,
bool ETIAvail>
448 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 4, iType, ETIAvail> {
451 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
452 KOKKOS_INLINE_FUNCTION
453 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
454 const iType& i3)
const;
457 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
458 typename iType,
bool ETIAvail>
459 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 5, iType, ETIAvail> {
462 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
463 KOKKOS_INLINE_FUNCTION
464 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
465 const iType& i3,
const iType& i4)
const;
468 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
469 typename iType,
bool ETIAvail>
470 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 6, iType, ETIAvail> {
473 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
474 KOKKOS_INLINE_FUNCTION
475 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
476 const iType& i3,
const iType& i4,
const iType& i5)
const;
479 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
480 typename iType,
bool ETIAvail>
481 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 7, iType, ETIAvail> {
484 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
485 KOKKOS_INLINE_FUNCTION
486 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
487 const iType& i3,
const iType& i4,
const iType& i5,
488 const iType& i6)
const;
491 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
492 typename iType,
bool ETIAvail>
493 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 8, iType, ETIAvail> {
496 ViewCopy(
const ViewTypeA&,
const ViewTypeB&,
const ExecSpace&);
497 KOKKOS_INLINE_FUNCTION
498 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
499 const iType& i3,
const iType& i4,
const iType& i5,
500 const iType& i6,
const iType& i7)
const;
503 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
505 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 1, iType,
506 KOKKOS_IMPL_COMPILING_LIBRARY> {
512 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
513 const ExecSpace space = ExecSpace())
516 policy_type(space, 0, a.extent(0)), *
this);
519 KOKKOS_INLINE_FUNCTION
520 void operator()(
const iType& i0)
const { a(i0) = b(i0); };
523 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
525 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 2, iType,
526 KOKKOS_IMPL_COMPILING_LIBRARY> {
529 static const Kokkos::Iterate outer_iteration_pattern =
530 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
531 static const Kokkos::Iterate inner_iteration_pattern =
532 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
533 typedef Kokkos::Rank<2, outer_iteration_pattern, inner_iteration_pattern>
535 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
536 Kokkos::IndexType<iType>>
539 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
540 const ExecSpace space = ExecSpace())
543 policy_type(space, {0, 0}, {a.extent(0), a.extent(1)}),
547 KOKKOS_INLINE_FUNCTION
548 void operator()(
const iType& i0,
const iType& i1)
const {
549 a(i0, i1) = b(i0, i1);
553 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
555 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 3, iType,
556 KOKKOS_IMPL_COMPILING_LIBRARY> {
560 static const Kokkos::Iterate outer_iteration_pattern =
561 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
562 static const Kokkos::Iterate inner_iteration_pattern =
563 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
564 typedef Kokkos::Rank<3, outer_iteration_pattern, inner_iteration_pattern>
566 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
567 Kokkos::IndexType<iType>>
570 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
571 const ExecSpace space = ExecSpace())
574 "Kokkos::ViewCopy-3D",
575 policy_type(space, {0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2)}),
579 KOKKOS_INLINE_FUNCTION
580 void operator()(
const iType& i0,
const iType& i1,
const iType& i2)
const {
581 a(i0, i1, i2) = b(i0, i1, i2);
585 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
587 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 4, iType,
588 KOKKOS_IMPL_COMPILING_LIBRARY> {
592 static const Kokkos::Iterate outer_iteration_pattern =
593 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
594 static const Kokkos::Iterate inner_iteration_pattern =
595 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
596 typedef Kokkos::Rank<4, outer_iteration_pattern, inner_iteration_pattern>
598 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
599 Kokkos::IndexType<iType>>
602 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
603 const ExecSpace space = ExecSpace())
606 "Kokkos::ViewCopy-4D",
607 policy_type(space, {0, 0, 0, 0},
608 {a.extent(0), a.extent(1), a.extent(2), a.extent(3)}),
612 KOKKOS_INLINE_FUNCTION
613 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
614 const iType& i3)
const {
615 a(i0, i1, i2, i3) = b(i0, i1, i2, i3);
619 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
621 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 5, iType,
622 KOKKOS_IMPL_COMPILING_LIBRARY> {
626 static const Kokkos::Iterate outer_iteration_pattern =
627 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
628 static const Kokkos::Iterate inner_iteration_pattern =
629 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
630 typedef Kokkos::Rank<5, outer_iteration_pattern, inner_iteration_pattern>
632 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
633 Kokkos::IndexType<iType>>
636 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
637 const ExecSpace space = ExecSpace())
640 policy_type(space, {0, 0, 0, 0, 0},
641 {a.extent(0), a.extent(1), a.extent(2),
642 a.extent(3), a.extent(4)}),
646 KOKKOS_INLINE_FUNCTION
647 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
648 const iType& i3,
const iType& i4)
const {
649 a(i0, i1, i2, i3, i4) = b(i0, i1, i2, i3, i4);
653 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
655 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 6, iType,
656 KOKKOS_IMPL_COMPILING_LIBRARY> {
660 static const Kokkos::Iterate outer_iteration_pattern =
661 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
662 static const Kokkos::Iterate inner_iteration_pattern =
663 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
664 typedef Kokkos::Rank<6, outer_iteration_pattern, inner_iteration_pattern>
666 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
667 Kokkos::IndexType<iType>>
670 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
671 const ExecSpace space = ExecSpace())
674 policy_type(space, {0, 0, 0, 0, 0, 0},
675 {a.extent(0), a.extent(1), a.extent(2),
676 a.extent(3), a.extent(4), a.extent(5)}),
680 KOKKOS_INLINE_FUNCTION
681 void operator()(
const iType& i0,
const iType& i1,
const iType& i2,
682 const iType& i3,
const iType& i4,
const iType& i5)
const {
683 a(i0, i1, i2, i3, i4, i5) = b(i0, i1, i2, i3, i4, i5);
687 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
689 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 7, iType,
690 KOKKOS_IMPL_COMPILING_LIBRARY> {
694 static const Kokkos::Iterate outer_iteration_pattern =
695 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
696 static const Kokkos::Iterate inner_iteration_pattern =
697 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
698 typedef Kokkos::Rank<6, outer_iteration_pattern, inner_iteration_pattern>
700 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
701 Kokkos::IndexType<iType>>
704 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
705 const ExecSpace space = ExecSpace())
708 policy_type(space, {0, 0, 0, 0, 0, 0},
709 {a.extent(0), a.extent(1), a.extent(3),
710 a.extent(4), a.extent(5), a.extent(6)}),
714 KOKKOS_INLINE_FUNCTION
715 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
716 const iType& i4,
const iType& i5,
const iType& i6)
const {
717 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
718 a(i0, i1, i2, i3, i4, i5, i6) = b(i0, i1, i2, i3, i4, i5, i6);
722 template <
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
724 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 8, iType,
725 KOKKOS_IMPL_COMPILING_LIBRARY> {
729 static const Kokkos::Iterate outer_iteration_pattern =
730 Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
731 static const Kokkos::Iterate inner_iteration_pattern =
732 Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
733 typedef Kokkos::Rank<6, outer_iteration_pattern, inner_iteration_pattern>
735 typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
736 Kokkos::IndexType<iType>>
739 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_,
740 const ExecSpace space = ExecSpace())
743 policy_type(space, {0, 0, 0, 0, 0, 0},
744 {a.extent(0), a.extent(1), a.extent(3),
745 a.extent(5), a.extent(6), a.extent(7)}),
749 KOKKOS_INLINE_FUNCTION
750 void operator()(
const iType& i0,
const iType& i1,
const iType& i3,
751 const iType& i5,
const iType& i6,
const iType& i7)
const {
752 for (iType i2 = 0; i2 < iType(a.extent(2)); i2++)
753 for (iType i4 = 0; i4 < iType(a.extent(4)); i4++)
754 a(i0, i1, i2, i3, i4, i5, i6, i7) = b(i0, i1, i2, i3, i4, i5, i6, i7);
761 #include <impl/Kokkos_ViewFillCopyETIDecl.hpp>
766 template <
class ExecutionSpace,
class DstType,
class SrcType>
767 void view_copy(
const ExecutionSpace& space,
const DstType& dst,
768 const SrcType& src) {
769 typedef typename DstType::memory_space dst_memory_space;
770 typedef typename SrcType::memory_space src_memory_space;
775 src_memory_space>::accessible
780 dst_memory_space>::accessible
783 if (!(ExecCanAccessSrc && ExecCanAccessDst)) {
784 Kokkos::Impl::throw_runtime_exception(
785 "Kokkos::Impl::view_copy called with invalid execution space");
788 int64_t strides[DstType::Rank + 1];
790 Kokkos::Iterate iterate;
791 if (Kokkos::is_layouttiled<typename DstType::array_layout>::value) {
792 iterate = Kokkos::layout_iterate_type_selector<
793 typename DstType::array_layout>::outer_iteration_pattern;
794 }
else if (std::is_same<
typename DstType::array_layout,
796 iterate = Kokkos::Iterate::Right;
797 }
else if (std::is_same<
typename DstType::array_layout,
799 iterate = Kokkos::Iterate::Left;
800 }
else if (std::is_same<
typename DstType::array_layout,
802 if (strides[0] > strides[DstType::Rank - 1])
803 iterate = Kokkos::Iterate::Right;
805 iterate = Kokkos::Iterate::Left;
807 if (std::is_same<
typename DstType::execution_space::array_layout,
809 iterate = Kokkos::Iterate::Right;
811 iterate = Kokkos::Iterate::Left;
814 if ((dst.span() >= size_t(std::numeric_limits<int>::max())) ||
815 (src.span() >= size_t(std::numeric_limits<int>::max()))) {
816 if (iterate == Kokkos::Iterate::Right)
817 Kokkos::Impl::ViewCopy<
818 typename DstType::uniform_runtime_nomemspace_type,
819 typename SrcType::uniform_runtime_const_nomemspace_type,
823 Kokkos::Impl::ViewCopy<
824 typename DstType::uniform_runtime_nomemspace_type,
825 typename SrcType::uniform_runtime_const_nomemspace_type,
829 if (iterate == Kokkos::Iterate::Right)
830 Kokkos::Impl::ViewCopy<
831 typename DstType::uniform_runtime_nomemspace_type,
832 typename SrcType::uniform_runtime_const_nomemspace_type,
836 Kokkos::Impl::ViewCopy<
837 typename DstType::uniform_runtime_nomemspace_type,
838 typename SrcType::uniform_runtime_const_nomemspace_type,
845 template <
class DstType,
class SrcType>
846 void view_copy(
const DstType& dst,
const SrcType& src) {
847 typedef typename DstType::execution_space dst_execution_space;
848 typedef typename SrcType::execution_space src_execution_space;
849 typedef typename DstType::memory_space dst_memory_space;
850 typedef typename SrcType::memory_space src_memory_space;
853 DstExecCanAccessSrc =
855 src_memory_space>::accessible
859 SrcExecCanAccessDst =
861 dst_memory_space>::accessible
864 if (!DstExecCanAccessSrc && !SrcExecCanAccessDst) {
866 "Error: Kokkos::deep_copy with no available copy mechanism: ");
867 message += src.label();
869 message += dst.label();
870 Kokkos::Impl::throw_runtime_exception(message);
874 int64_t strides[DstType::Rank + 1];
876 Kokkos::Iterate iterate;
877 if (Kokkos::is_layouttiled<typename DstType::array_layout>::value) {
878 iterate = Kokkos::layout_iterate_type_selector<
879 typename DstType::array_layout>::outer_iteration_pattern;
880 }
else if (std::is_same<
typename DstType::array_layout,
882 iterate = Kokkos::Iterate::Right;
883 }
else if (std::is_same<
typename DstType::array_layout,
885 iterate = Kokkos::Iterate::Left;
886 }
else if (std::is_same<
typename DstType::array_layout,
888 if (strides[0] > strides[DstType::Rank - 1])
889 iterate = Kokkos::Iterate::Right;
891 iterate = Kokkos::Iterate::Left;
893 if (std::is_same<
typename DstType::execution_space::array_layout,
895 iterate = Kokkos::Iterate::Right;
897 iterate = Kokkos::Iterate::Left;
900 if ((dst.span() >= size_t(std::numeric_limits<int>::max())) ||
901 (src.span() >= size_t(std::numeric_limits<int>::max()))) {
902 if (DstExecCanAccessSrc) {
903 if (iterate == Kokkos::Iterate::Right)
904 Kokkos::Impl::ViewCopy<
905 typename DstType::uniform_runtime_nomemspace_type,
906 typename SrcType::uniform_runtime_const_nomemspace_type,
910 Kokkos::Impl::ViewCopy<
911 typename DstType::uniform_runtime_nomemspace_type,
912 typename SrcType::uniform_runtime_const_nomemspace_type,
916 if (iterate == Kokkos::Iterate::Right)
917 Kokkos::Impl::ViewCopy<
918 typename DstType::uniform_runtime_nomemspace_type,
919 typename SrcType::uniform_runtime_const_nomemspace_type,
923 Kokkos::Impl::ViewCopy<
924 typename DstType::uniform_runtime_nomemspace_type,
925 typename SrcType::uniform_runtime_const_nomemspace_type,
930 if (DstExecCanAccessSrc) {
931 if (iterate == Kokkos::Iterate::Right)
932 Kokkos::Impl::ViewCopy<
933 typename DstType::uniform_runtime_nomemspace_type,
934 typename SrcType::uniform_runtime_const_nomemspace_type,
938 Kokkos::Impl::ViewCopy<
939 typename DstType::uniform_runtime_nomemspace_type,
940 typename SrcType::uniform_runtime_const_nomemspace_type,
944 if (iterate == Kokkos::Iterate::Right)
945 Kokkos::Impl::ViewCopy<
946 typename DstType::uniform_runtime_nomemspace_type,
947 typename SrcType::uniform_runtime_const_nomemspace_type,
951 Kokkos::Impl::ViewCopy<
952 typename DstType::uniform_runtime_nomemspace_type,
953 typename SrcType::uniform_runtime_const_nomemspace_type,
960 template <
class DstType,
class SrcType,
int Rank,
class... Args>
961 struct CommonSubview;
963 template <
class DstType,
class SrcType,
class Arg0,
class... Args>
964 struct CommonSubview<DstType, SrcType, 1, Arg0, Args...> {
965 typedef typename Kokkos::Subview<DstType, Arg0> dst_subview_type;
966 typedef typename Kokkos::Subview<SrcType, Arg0> src_subview_type;
967 dst_subview_type dst_sub;
968 src_subview_type src_sub;
969 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
971 : dst_sub(dst, arg0), src_sub(src, arg0) {}
974 template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class... Args>
975 struct CommonSubview<DstType, SrcType, 2, Arg0, Arg1, Args...> {
976 typedef typename Kokkos::Subview<DstType, Arg0, Arg1> dst_subview_type;
977 typedef typename Kokkos::Subview<SrcType, Arg0, Arg1> src_subview_type;
978 dst_subview_type dst_sub;
979 src_subview_type src_sub;
980 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
981 const Arg1& arg1, Args...)
982 : dst_sub(dst, arg0, arg1), src_sub(src, arg0, arg1) {}
985 template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
987 struct CommonSubview<DstType, SrcType, 3, Arg0, Arg1, Arg2, Args...> {
988 typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2> dst_subview_type;
989 typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2> src_subview_type;
990 dst_subview_type dst_sub;
991 src_subview_type src_sub;
992 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
993 const Arg1& arg1,
const Arg2& arg2, Args...)
994 : dst_sub(dst, arg0, arg1, arg2), src_sub(src, arg0, arg1, arg2) {}
997 template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
998 class Arg3,
class... Args>
999 struct CommonSubview<DstType, SrcType, 4, Arg0, Arg1, Arg2, Arg3, Args...> {
1000 typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3>
1002 typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3>
1004 dst_subview_type dst_sub;
1005 src_subview_type src_sub;
1006 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
1007 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
1009 : dst_sub(dst, arg0, arg1, arg2, arg3),
1010 src_sub(src, arg0, arg1, arg2, arg3) {}
1013 template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
1014 class Arg3,
class Arg4,
class... Args>
1015 struct CommonSubview<DstType, SrcType, 5, Arg0, Arg1, Arg2, Arg3, Arg4,
1017 typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4>
1019 typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4>
1021 dst_subview_type dst_sub;
1022 src_subview_type src_sub;
1023 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
1024 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
1025 const Arg4& arg4,
const Args...)
1026 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4),
1027 src_sub(src, arg0, arg1, arg2, arg3, arg4) {}
1030 template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
1031 class Arg3,
class Arg4,
class Arg5,
class... Args>
1032 struct CommonSubview<DstType, SrcType, 6, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1034 typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5>
1036 typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5>
1038 dst_subview_type dst_sub;
1039 src_subview_type src_sub;
1040 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
1041 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
1042 const Arg4& arg4,
const Arg5& arg5,
const Args...)
1043 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4, arg5),
1044 src_sub(src, arg0, arg1, arg2, arg3, arg4, arg5) {}
1047 template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
1048 class Arg3,
class Arg4,
class Arg5,
class Arg6,
class... Args>
1049 struct CommonSubview<DstType, SrcType, 7, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1051 typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1054 typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1057 dst_subview_type dst_sub;
1058 src_subview_type src_sub;
1059 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
1060 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
1061 const Arg4& arg4,
const Arg5& arg5,
const Arg6& arg6, Args...)
1062 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4, arg5, arg6),
1063 src_sub(src, arg0, arg1, arg2, arg3, arg4, arg5, arg6) {}
1066 template <
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
1067 class Arg3,
class Arg4,
class Arg5,
class Arg6,
class Arg7>
1068 struct CommonSubview<DstType, SrcType, 8, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1070 typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1073 typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1076 dst_subview_type dst_sub;
1077 src_subview_type src_sub;
1078 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
1079 const Arg1& arg1,
const Arg2& arg2,
const Arg3& arg3,
1080 const Arg4& arg4,
const Arg5& arg5,
const Arg6& arg6,
1082 : dst_sub(dst, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7),
1083 src_sub(src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {}
1086 template <
class DstType,
class SrcType,
1087 class ExecSpace =
typename DstType::execution_space,
1088 int Rank = DstType::Rank>
1091 template <
class DstType,
class SrcType,
class ExecSpace>
1092 struct ViewRemap<DstType, SrcType, ExecSpace, 1> {
1095 ViewRemap(
const DstType& dst,
const SrcType& src) {
1096 if (dst.extent(0) == src.extent(0)) {
1097 view_copy(dst, src);
1099 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1100 typedef CommonSubview<DstType, SrcType, 1, p_type> sv_adapter_type;
1101 sv_adapter_type common_subview(dst, src, ext0);
1102 view_copy(common_subview.dst_sub, common_subview.src_sub);
1107 template <
class DstType,
class SrcType,
class ExecSpace>
1108 struct ViewRemap<DstType, SrcType, ExecSpace, 2> {
1111 ViewRemap(
const DstType& dst,
const SrcType& src) {
1112 if (dst.extent(0) == src.extent(0)) {
1113 if (dst.extent(1) == src.extent(1)) {
1114 view_copy(dst, src);
1116 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1117 typedef CommonSubview<DstType, SrcType, 2, Kokkos::Impl::ALL_t, p_type>
1119 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1);
1120 view_copy(common_subview.dst_sub, common_subview.src_sub);
1123 if (dst.extent(1) == src.extent(1)) {
1124 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1125 typedef CommonSubview<DstType, SrcType, 2, p_type, Kokkos::Impl::ALL_t>
1127 sv_adapter_type common_subview(dst, src, ext0, Kokkos::ALL);
1128 view_copy(common_subview.dst_sub, common_subview.src_sub);
1130 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1131 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1132 typedef CommonSubview<DstType, SrcType, 2, p_type, p_type>
1134 sv_adapter_type common_subview(dst, src, ext0, ext1);
1135 view_copy(common_subview.dst_sub, common_subview.src_sub);
1141 template <
class DstType,
class SrcType,
class ExecSpace>
1142 struct ViewRemap<DstType, SrcType, ExecSpace, 3> {
1145 ViewRemap(
const DstType& dst,
const SrcType& src) {
1146 if (dst.extent(0) == src.extent(0)) {
1147 if (dst.extent(2) == src.extent(2)) {
1148 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1149 typedef CommonSubview<DstType, SrcType, 3, Kokkos::Impl::ALL_t, p_type,
1150 Kokkos::Impl::ALL_t>
1152 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1,
1154 view_copy(common_subview.dst_sub, common_subview.src_sub);
1156 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1157 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1158 typedef CommonSubview<DstType, SrcType, 3, Kokkos::Impl::ALL_t, p_type,
1161 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2);
1162 view_copy(common_subview.dst_sub, common_subview.src_sub);
1165 if (dst.extent(2) == src.extent(2)) {
1166 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1167 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1168 typedef CommonSubview<DstType, SrcType, 3, p_type, p_type,
1169 Kokkos::Impl::ALL_t>
1171 sv_adapter_type common_subview(dst, src, ext0, ext1, Kokkos::ALL);
1172 view_copy(common_subview.dst_sub, common_subview.src_sub);
1174 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1175 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1176 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1177 typedef CommonSubview<DstType, SrcType, 3, p_type, p_type, p_type>
1179 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2);
1180 view_copy(common_subview.dst_sub, common_subview.src_sub);
1186 template <
class DstType,
class SrcType,
class ExecSpace>
1187 struct ViewRemap<DstType, SrcType, ExecSpace, 4> {
1190 ViewRemap(
const DstType& dst,
const SrcType& src) {
1191 if (dst.extent(0) == src.extent(0)) {
1192 if (dst.extent(3) == src.extent(3)) {
1193 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1194 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1195 typedef CommonSubview<DstType, SrcType, 4, Kokkos::Impl::ALL_t, p_type,
1196 p_type, Kokkos::Impl::ALL_t>
1198 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2,
1200 view_copy(common_subview.dst_sub, common_subview.src_sub);
1202 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1203 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1204 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1205 typedef CommonSubview<DstType, SrcType, 4, Kokkos::Impl::ALL_t, p_type,
1208 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3);
1209 view_copy(common_subview.dst_sub, common_subview.src_sub);
1212 if (dst.extent(7) == src.extent(7)) {
1213 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1214 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1215 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1216 typedef CommonSubview<DstType, SrcType, 4, p_type, p_type, p_type,
1217 Kokkos::Impl::ALL_t>
1219 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, Kokkos::ALL);
1220 view_copy(common_subview.dst_sub, common_subview.src_sub);
1222 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1223 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1224 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1225 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1226 typedef CommonSubview<DstType, SrcType, 4, p_type, p_type, p_type,
1229 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3);
1230 view_copy(common_subview.dst_sub, common_subview.src_sub);
1236 template <
class DstType,
class SrcType,
class ExecSpace>
1237 struct ViewRemap<DstType, SrcType, ExecSpace, 5> {
1240 ViewRemap(
const DstType& dst,
const SrcType& src) {
1241 if (dst.extent(0) == src.extent(0)) {
1242 if (dst.extent(4) == src.extent(4)) {
1243 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1244 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1245 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1246 typedef CommonSubview<DstType, SrcType, 5, Kokkos::Impl::ALL_t, p_type,
1247 p_type, p_type, Kokkos::Impl::ALL_t>
1249 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1251 view_copy(common_subview.dst_sub, common_subview.src_sub);
1253 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1254 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1255 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1256 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1257 typedef CommonSubview<DstType, SrcType, 5, Kokkos::Impl::ALL_t, p_type,
1258 p_type, p_type, p_type>
1260 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1262 view_copy(common_subview.dst_sub, common_subview.src_sub);
1265 if (dst.extent(4) == src.extent(4)) {
1266 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1267 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1268 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1269 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1270 typedef CommonSubview<DstType, SrcType, 5, p_type, p_type, p_type,
1271 p_type, Kokkos::Impl::ALL_t>
1273 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3,
1275 view_copy(common_subview.dst_sub, common_subview.src_sub);
1277 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1278 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1279 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1280 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1281 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1282 typedef CommonSubview<DstType, SrcType, 5, p_type, p_type, p_type,
1285 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4);
1286 view_copy(common_subview.dst_sub, common_subview.src_sub);
1291 template <
class DstType,
class SrcType,
class ExecSpace>
1292 struct ViewRemap<DstType, SrcType, ExecSpace, 6> {
1295 ViewRemap(
const DstType& dst,
const SrcType& src) {
1296 if (dst.extent(0) == src.extent(0)) {
1297 if (dst.extent(5) == src.extent(5)) {
1298 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1299 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1300 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1301 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1302 typedef CommonSubview<DstType, SrcType, 6, Kokkos::Impl::ALL_t, p_type,
1303 p_type, p_type, p_type, Kokkos::Impl::ALL_t>
1305 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1307 view_copy(common_subview.dst_sub, common_subview.src_sub);
1309 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1310 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1311 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1312 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1313 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1314 typedef CommonSubview<DstType, SrcType, 6, Kokkos::Impl::ALL_t, p_type,
1315 p_type, p_type, p_type, p_type>
1317 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1319 view_copy(common_subview.dst_sub, common_subview.src_sub);
1322 if (dst.extent(5) == src.extent(5)) {
1323 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1324 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1325 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1326 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1327 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1329 typedef CommonSubview<DstType, SrcType, 6, p_type, p_type, p_type,
1330 p_type, p_type, Kokkos::Impl::ALL_t>
1332 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1334 view_copy(common_subview.dst_sub, common_subview.src_sub);
1336 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1337 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1338 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1339 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1340 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1341 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1343 typedef CommonSubview<DstType, SrcType, 6, p_type, p_type, p_type,
1344 p_type, p_type, p_type>
1346 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1348 view_copy(common_subview.dst_sub, common_subview.src_sub);
1354 template <
class DstType,
class SrcType,
class ExecSpace>
1355 struct ViewRemap<DstType, SrcType, ExecSpace, 7> {
1358 ViewRemap(
const DstType& dst,
const SrcType& src) {
1359 if (dst.extent(0) == src.extent(0)) {
1360 if (dst.extent(6) == src.extent(6)) {
1361 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1362 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1363 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1364 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1365 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1366 typedef CommonSubview<DstType, SrcType, 7, Kokkos::Impl::ALL_t, p_type,
1367 p_type, p_type, p_type, p_type,
1368 Kokkos::Impl::ALL_t>
1370 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1371 ext4, ext5, Kokkos::ALL);
1372 view_copy(common_subview.dst_sub, common_subview.src_sub);
1374 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1375 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1376 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1377 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1378 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1379 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1380 typedef CommonSubview<DstType, SrcType, 7, Kokkos::Impl::ALL_t, p_type,
1381 p_type, p_type, p_type, p_type, p_type>
1383 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1385 view_copy(common_subview.dst_sub, common_subview.src_sub);
1388 if (dst.extent(6) == src.extent(6)) {
1389 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1390 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1391 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1392 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1393 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1394 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1395 typedef CommonSubview<DstType, SrcType, 7, p_type, p_type, p_type,
1396 p_type, p_type, p_type, Kokkos::Impl::ALL_t>
1398 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1400 view_copy(common_subview.dst_sub, common_subview.src_sub);
1402 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1403 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1404 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1405 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1406 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1407 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1408 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1409 typedef CommonSubview<DstType, SrcType, 7, p_type, p_type, p_type,
1410 p_type, p_type, p_type, p_type>
1412 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1414 view_copy(common_subview.dst_sub, common_subview.src_sub);
1420 template <
class DstType,
class SrcType,
class ExecSpace>
1421 struct ViewRemap<DstType, SrcType, ExecSpace, 8> {
1424 ViewRemap(
const DstType& dst,
const SrcType& src) {
1425 if (dst.extent(0) == src.extent(0)) {
1426 if (dst.extent(7) == src.extent(7)) {
1427 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1428 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1429 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1430 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1431 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1432 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1433 typedef CommonSubview<DstType, SrcType, 8, Kokkos::Impl::ALL_t, p_type,
1434 p_type, p_type, p_type, p_type, p_type,
1435 Kokkos::Impl::ALL_t>
1437 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1438 ext4, ext5, ext6, Kokkos::ALL);
1439 view_copy(common_subview.dst_sub, common_subview.src_sub);
1441 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1442 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1443 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1444 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1445 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1446 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1447 p_type ext7(0, std::min(dst.extent(7), src.extent(7)));
1448 typedef CommonSubview<DstType, SrcType, 8, Kokkos::Impl::ALL_t, p_type,
1449 p_type, p_type, p_type, p_type, p_type, p_type>
1451 sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1452 ext4, ext5, ext6, ext7);
1453 view_copy(common_subview.dst_sub, common_subview.src_sub);
1456 if (dst.extent(7) == src.extent(7)) {
1457 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1458 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1459 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1460 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1461 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1462 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1463 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1464 typedef CommonSubview<DstType, SrcType, 8, p_type, p_type, p_type,
1465 p_type, p_type, p_type, p_type,
1466 Kokkos::Impl::ALL_t>
1468 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1469 ext5, ext6, Kokkos::ALL);
1470 view_copy(common_subview.dst_sub, common_subview.src_sub);
1472 p_type ext0(0, std::min(dst.extent(0), src.extent(0)));
1473 p_type ext1(0, std::min(dst.extent(1), src.extent(1)));
1474 p_type ext2(0, std::min(dst.extent(2), src.extent(2)));
1475 p_type ext3(0, std::min(dst.extent(3), src.extent(3)));
1476 p_type ext4(0, std::min(dst.extent(4), src.extent(4)));
1477 p_type ext5(0, std::min(dst.extent(5), src.extent(5)));
1478 p_type ext6(0, std::min(dst.extent(6), src.extent(6)));
1479 p_type ext7(0, std::min(dst.extent(7), src.extent(7)));
1480 typedef CommonSubview<DstType, SrcType, 8, p_type, p_type, p_type,
1481 p_type, p_type, p_type, p_type, p_type>
1483 sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1485 view_copy(common_subview.dst_sub, common_subview.src_sub);
1494 template <
class DT,
class... DP>
1497 typename ViewTraits<DT, DP...>::const_value_type& value,
1498 typename std::enable_if<std::is_same<
1499 typename ViewTraits<DT, DP...>::specialize,
void>::value>::type* =
1501 typedef View<DT, DP...> ViewType;
1502 using exec_space_type =
typename ViewType::execution_space;
1504 #if defined(KOKKOS_ENABLE_PROFILING)
1505 if (Kokkos::Profiling::profileLibraryLoaded()) {
1506 Kokkos::Profiling::beginDeepCopy(
1507 Kokkos::Profiling::SpaceHandle(ViewType::memory_space::name()),
1508 dst.label(), dst.data(),
1510 &value, dst.span() *
sizeof(
typename ViewType::value_type));
1514 if (dst.data() ==
nullptr) {
1516 #if defined(KOKKOS_ENABLE_PROFILING)
1517 if (Kokkos::Profiling::profileLibraryLoaded()) {
1518 Kokkos::Profiling::endDeepCopy();
1525 static_assert(std::is_same<
typename ViewType::non_const_value_type,
1526 typename ViewType::value_type>::value,
1527 "deep_copy requires non-const type");
1530 if (dst.span_is_contiguous()) {
1533 Kokkos::Device<
typename ViewType::execution_space,
1534 typename std::conditional<
1535 ViewType::Rank == 0,
typename ViewType::memory_space,
1536 Kokkos::AnonymousSpace>::type>,
1537 Kokkos::MemoryTraits<0>>
1540 ViewTypeFlat dst_flat(dst.data(), dst.size());
1541 if (dst.span() <
static_cast<size_t>(std::numeric_limits<int>::max())) {
1542 Kokkos::Impl::ViewFill<ViewTypeFlat, Kokkos::LayoutRight, exec_space_type,
1543 ViewTypeFlat::Rank,
int>(dst_flat, value,
1546 Kokkos::Impl::ViewFill<ViewTypeFlat, Kokkos::LayoutRight, exec_space_type,
1547 ViewTypeFlat::Rank, int64_t>(dst_flat, value,
1550 #if defined(KOKKOS_ENABLE_PROFILING)
1551 if (Kokkos::Profiling::profileLibraryLoaded()) {
1552 Kokkos::Profiling::endDeepCopy();
1559 int64_t strides[ViewType::Rank + 1];
1560 dst.stride(strides);
1561 Kokkos::Iterate iterate;
1562 if (std::is_same<
typename ViewType::array_layout,
1564 iterate = Kokkos::Iterate::Right;
1565 }
else if (std::is_same<
typename ViewType::array_layout,
1567 iterate = Kokkos::Iterate::Left;
1568 }
else if (std::is_same<
typename ViewType::array_layout,
1570 if (strides[0] > strides[ViewType::Rank > 0 ? ViewType::Rank - 1 : 0])
1571 iterate = Kokkos::Iterate::Right;
1573 iterate = Kokkos::Iterate::Left;
1575 if (std::is_same<
typename ViewType::execution_space::array_layout,
1577 iterate = Kokkos::Iterate::Right;
1579 iterate = Kokkos::Iterate::Left;
1584 typedef typename std::conditional<
1585 ViewType::Rank == 0,
typename ViewType::uniform_runtime_type,
1586 typename ViewType::uniform_runtime_nomemspace_type>::type ViewTypeUniform;
1587 if (dst.span() >
static_cast<size_t>(std::numeric_limits<int>::max())) {
1588 if (iterate == Kokkos::Iterate::Right)
1590 exec_space_type, ViewType::Rank, int64_t>(
1591 dst, value, exec_space_type());
1594 exec_space_type, ViewType::Rank, int64_t>(
1595 dst, value, exec_space_type());
1597 if (iterate == Kokkos::Iterate::Right)
1599 exec_space_type, ViewType::Rank,
int>(
1600 dst, value, exec_space_type());
1603 exec_space_type, ViewType::Rank,
int>(
1604 dst, value, exec_space_type());
1608 #if defined(KOKKOS_ENABLE_PROFILING)
1609 if (Kokkos::Profiling::profileLibraryLoaded()) {
1610 Kokkos::Profiling::endDeepCopy();
1616 template <
class ST,
class... SP>
1618 typename ViewTraits<ST, SP...>::non_const_value_type& dst,
1620 typename std::enable_if<std::is_same<
1621 typename ViewTraits<ST, SP...>::specialize,
void>::value>::type* =
1624 typedef typename src_traits::memory_space src_memory_space;
1626 static_assert(src_traits::rank == 0,
1627 "ERROR: Non-rank-zero view in deep_copy( value , View )");
1629 #if defined(KOKKOS_ENABLE_PROFILING)
1630 if (Kokkos::Profiling::profileLibraryLoaded()) {
1631 Kokkos::Profiling::beginDeepCopy(
1633 &dst, Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
1634 src.label(), src.data(),
1635 src.span() *
sizeof(
typename src_traits::value_type));
1639 if (src.data() ==
nullptr) {
1641 #if defined(KOKKOS_ENABLE_PROFILING)
1642 if (Kokkos::Profiling::profileLibraryLoaded()) {
1643 Kokkos::Profiling::endDeepCopy();
1649 Kokkos::Impl::DeepCopy<HostSpace, src_memory_space>(&dst, src.data(),
1651 #if defined(KOKKOS_ENABLE_PROFILING)
1652 if (Kokkos::Profiling::profileLibraryLoaded()) {
1653 Kokkos::Profiling::endDeepCopy();
1660 template <
class DT,
class... DP,
class ST,
class... SP>
1663 typename std::enable_if<(
1664 std::is_same<
typename ViewTraits<DT, DP...>::specialize,
void>::value &&
1665 std::is_same<
typename ViewTraits<ST, SP...>::specialize,
void>::value &&
1669 typedef View<DT, DP...> dst_type;
1670 typedef View<ST, SP...> src_type;
1672 typedef typename dst_type::value_type value_type;
1673 typedef typename dst_type::memory_space dst_memory_space;
1674 typedef typename src_type::memory_space src_memory_space;
1676 static_assert(std::is_same<
typename dst_type::value_type,
1677 typename src_type::non_const_value_type>::value,
1678 "deep_copy requires matching non-const destination type");
1680 #if defined(KOKKOS_ENABLE_PROFILING)
1681 if (Kokkos::Profiling::profileLibraryLoaded()) {
1682 Kokkos::Profiling::beginDeepCopy(
1683 Kokkos::Profiling::SpaceHandle(dst_memory_space::name()), dst.label(),
1684 dst.data(), Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
1685 src.label(), src.data(),
1686 src.span() *
sizeof(
typename dst_type::value_type));
1690 if (dst.data() ==
nullptr && src.data() ==
nullptr) {
1692 #if defined(KOKKOS_ENABLE_PROFILING)
1693 if (Kokkos::Profiling::profileLibraryLoaded()) {
1694 Kokkos::Profiling::endDeepCopy();
1701 if (dst.data() != src.data()) {
1702 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1703 dst.data(), src.data(),
sizeof(value_type));
1706 #if defined(KOKKOS_ENABLE_PROFILING)
1707 if (Kokkos::Profiling::profileLibraryLoaded()) {
1708 Kokkos::Profiling::endDeepCopy();
1717 template <
class DT,
class... DP,
class ST,
class... SP>
1720 typename std::enable_if<(
1721 std::is_same<
typename ViewTraits<DT, DP...>::specialize,
void>::value &&
1722 std::is_same<
typename ViewTraits<ST, SP...>::specialize,
void>::value &&
1725 typedef View<DT, DP...> dst_type;
1726 typedef View<ST, SP...> src_type;
1727 typedef typename dst_type::execution_space dst_execution_space;
1728 typedef typename src_type::execution_space src_execution_space;
1729 typedef typename dst_type::memory_space dst_memory_space;
1730 typedef typename src_type::memory_space src_memory_space;
1731 typedef typename dst_type::value_type dst_value_type;
1732 typedef typename src_type::value_type src_value_type;
1734 static_assert(std::is_same<
typename dst_type::value_type,
1735 typename dst_type::non_const_value_type>::value,
1736 "deep_copy requires non-const destination type");
1738 static_assert((
unsigned(dst_type::rank) ==
unsigned(src_type::rank)),
1739 "deep_copy requires Views of equal rank");
1741 #if defined(KOKKOS_ENABLE_PROFILING)
1742 if (Kokkos::Profiling::profileLibraryLoaded()) {
1743 Kokkos::Profiling::beginDeepCopy(
1744 Kokkos::Profiling::SpaceHandle(dst_memory_space::name()), dst.label(),
1745 dst.data(), Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
1746 src.label(), src.data(),
1747 src.span() *
sizeof(
typename dst_type::value_type));
1751 if (dst.data() ==
nullptr || src.data() ==
nullptr) {
1752 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1760 std::string message(
1761 "Deprecation Error: Kokkos::deep_copy extents of views don't "
1763 message += dst.label();
1765 for (
int r = 0; r < dst_type::Rank - 1; r++) {
1766 message += std::to_string(dst.
extent(r));
1769 message += std::to_string(dst.
extent(dst_type::Rank - 1));
1771 message += src.label();
1773 for (
int r = 0; r < src_type::Rank - 1; r++) {
1774 message += std::to_string(src.
extent(r));
1777 message += std::to_string(src.
extent(src_type::Rank - 1));
1780 Kokkos::Impl::throw_runtime_exception(message);
1784 #if defined(KOKKOS_ENABLE_PROFILING)
1785 if (Kokkos::Profiling::profileLibraryLoaded()) {
1786 Kokkos::Profiling::endDeepCopy();
1793 DstExecCanAccessSrc =
1795 src_memory_space>::accessible
1799 SrcExecCanAccessDst =
1801 dst_memory_space>::accessible
1805 dst_value_type* dst_start = dst.data();
1806 dst_value_type* dst_end = dst.data() + dst.span();
1807 src_value_type* src_start = src.data();
1808 src_value_type* src_end = src.data() + src.span();
1809 if (((std::ptrdiff_t)dst_start == (std::ptrdiff_t)src_start) &&
1810 ((std::ptrdiff_t)dst_end == (std::ptrdiff_t)src_end) &&
1811 (dst.span_is_contiguous() && src.span_is_contiguous())) {
1813 #if defined(KOKKOS_ENABLE_PROFILING)
1814 if (Kokkos::Profiling::profileLibraryLoaded()) {
1815 Kokkos::Profiling::endDeepCopy();
1821 if ((((std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end) &&
1822 ((std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start)) &&
1823 ((dst.span_is_contiguous() && src.span_is_contiguous()))) {
1824 std::string message(
"Error: Kokkos::deep_copy of overlapping views: ");
1825 message += dst.label();
1827 message += std::to_string((std::ptrdiff_t)dst_start);
1829 message += std::to_string((std::ptrdiff_t)dst_end);
1831 message += src.label();
1833 message += std::to_string((std::ptrdiff_t)src_start);
1835 message += std::to_string((std::ptrdiff_t)src_end);
1837 Kokkos::Impl::throw_runtime_exception(message);
1845 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1847 if (DstExecCanAccessSrc) {
1850 Kokkos::Impl::ViewRemap<dst_type, src_type>(dst, src);
1851 }
else if (SrcExecCanAccessDst) {
1854 Kokkos::Impl::ViewRemap<dst_type, src_type, src_execution_space>(dst,
1857 Kokkos::Impl::throw_runtime_exception(
1858 "deep_copy given views that would require a temporary allocation");
1861 #if defined(KOKKOS_ENABLE_PROFILING)
1862 if (Kokkos::Profiling::profileLibraryLoaded()) {
1863 Kokkos::Profiling::endDeepCopy();
1868 std::string message(
1869 "Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1870 message += dst.label();
1872 for (
int r = 0; r < dst_type::Rank - 1; r++) {
1873 message += std::to_string(dst.
extent(r));
1876 message += std::to_string(dst.
extent(dst_type::Rank - 1));
1878 message += src.label();
1880 for (
int r = 0; r < src_type::Rank - 1; r++) {
1881 message += std::to_string(src.
extent(r));
1884 message += std::to_string(src.
extent(src_type::Rank - 1));
1887 Kokkos::Impl::throw_runtime_exception(message);
1894 if (std::is_same<
typename dst_type::value_type,
1895 typename src_type::non_const_value_type>::value &&
1896 (std::is_same<
typename dst_type::array_layout,
1897 typename src_type::array_layout>::value ||
1898 (dst_type::rank == 1 && src_type::rank == 1)) &&
1899 dst.span_is_contiguous() && src.span_is_contiguous() &&
1900 ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1901 ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1902 ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1903 ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1904 ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1905 ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1906 ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1907 ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))) {
1908 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1910 if ((
void*)dst.data() != (
void*)src.data()) {
1911 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1912 dst.data(), src.data(), nbytes);
1917 Impl::view_copy(dst, src);
1920 #if defined(KOKKOS_ENABLE_PROFILING)
1921 if (Kokkos::Profiling::profileLibraryLoaded()) {
1922 Kokkos::Profiling::endDeepCopy();
1929 namespace Experimental {
1933 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1934 void KOKKOS_INLINE_FUNCTION
1935 local_deep_copy_contiguous(
const TeamType& team,
const View<DT, DP...>& dst,
1936 const View<ST, SP...>& src) {
1938 [&](
const int& i) { dst.data()[i] = src.data()[i]; });
1941 template <
class DT,
class... DP,
class ST,
class... SP>
1942 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
1943 const View<DT, DP...>& dst,
const View<ST, SP...>& src) {
1944 for (
size_t i = 0; i < src.span(); ++i) {
1945 dst.data()[i] = src.data()[i];
1949 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1950 void KOKKOS_INLINE_FUNCTION local_deep_copy(
1951 const TeamType& team,
const View<DT, DP...>& dst,
1952 const View<ST, SP...>& src,
1953 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 1 &&
1954 unsigned(ViewTraits<ST, SP...>::rank) ==
1955 1)>::type* =
nullptr) {
1956 if (dst.data() ==
nullptr) {
1960 const size_t N = dst.extent(0);
1962 team.team_barrier();
1964 [&](
const int& i) { dst(i) = src(i); });
1965 team.team_barrier();
1968 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1969 void KOKKOS_INLINE_FUNCTION local_deep_copy(
1970 const TeamType& team,
const View<DT, DP...>& dst,
1971 const View<ST, SP...>& src,
1972 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 2 &&
1973 unsigned(ViewTraits<ST, SP...>::rank) ==
1974 2)>::type* =
nullptr) {
1975 if (dst.data() ==
nullptr) {
1979 const size_t N = dst.extent(0) * dst.extent(1);
1981 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
1982 team.team_barrier();
1983 local_deep_copy_contiguous(team, dst, src);
1984 team.team_barrier();
1986 team.team_barrier();
1988 int i0 = i % dst.extent(0);
1989 int i1 = i / dst.extent(0);
1990 dst(i0, i1) = src(i0, i1);
1992 team.team_barrier();
1996 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
1997 void KOKKOS_INLINE_FUNCTION local_deep_copy(
1998 const TeamType& team,
const View<DT, DP...>& dst,
1999 const View<ST, SP...>& src,
2000 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 3 &&
2001 unsigned(ViewTraits<ST, SP...>::rank) ==
2002 3)>::type* =
nullptr) {
2003 if (dst.data() ==
nullptr) {
2007 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
2009 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2010 team.team_barrier();
2011 local_deep_copy_contiguous(team, dst, src);
2012 team.team_barrier();
2014 team.team_barrier();
2016 int i0 = i % dst.extent(0);
2017 int itmp = i / dst.extent(0);
2018 int i1 = itmp % dst.extent(1);
2019 int i2 = itmp / dst.extent(1);
2020 dst(i0, i1, i2) = src(i0, i1, i2);
2022 team.team_barrier();
2026 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
2027 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2028 const TeamType& team,
const View<DT, DP...>& dst,
2029 const View<ST, SP...>& src,
2030 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 4 &&
2031 unsigned(ViewTraits<ST, SP...>::rank) ==
2032 4)>::type* =
nullptr) {
2033 if (dst.data() ==
nullptr) {
2038 dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
2040 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2041 team.team_barrier();
2042 local_deep_copy_contiguous(team, dst, src);
2043 team.team_barrier();
2045 team.team_barrier();
2047 int i0 = i % dst.extent(0);
2048 int itmp = i / dst.extent(0);
2049 int i1 = itmp % dst.extent(1);
2050 itmp = itmp / dst.extent(1);
2051 int i2 = itmp % dst.extent(2);
2052 int i3 = itmp / dst.extent(2);
2053 dst(i0, i1, i2, i3) = src(i0, i1, i2, i3);
2055 team.team_barrier();
2059 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
2060 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2061 const TeamType& team,
const View<DT, DP...>& dst,
2062 const View<ST, SP...>& src,
2063 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 5 &&
2064 unsigned(ViewTraits<ST, SP...>::rank) ==
2065 5)>::type* =
nullptr) {
2066 if (dst.data() ==
nullptr) {
2070 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2071 dst.extent(3) * dst.extent(4);
2073 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2074 team.team_barrier();
2075 local_deep_copy_contiguous(team, dst, src);
2076 team.team_barrier();
2078 team.team_barrier();
2080 int i0 = i % dst.extent(0);
2081 int itmp = i / dst.extent(0);
2082 int i1 = itmp % dst.extent(1);
2083 itmp = itmp / dst.extent(1);
2084 int i2 = itmp % dst.extent(2);
2085 itmp = itmp / dst.extent(2);
2086 int i3 = itmp % dst.extent(3);
2087 int i4 = itmp / dst.extent(3);
2088 dst(i0, i1, i2, i3, i4) = src(i0, i1, i2, i3, i4);
2090 team.team_barrier();
2094 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
2095 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2096 const TeamType& team,
const View<DT, DP...>& dst,
2097 const View<ST, SP...>& src,
2098 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 6 &&
2099 unsigned(ViewTraits<ST, SP...>::rank) ==
2100 6)>::type* =
nullptr) {
2101 if (dst.data() ==
nullptr) {
2105 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2106 dst.extent(3) * dst.extent(4) * dst.extent(5);
2108 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2109 team.team_barrier();
2110 local_deep_copy_contiguous(team, dst, src);
2111 team.team_barrier();
2113 team.team_barrier();
2115 int i0 = i % dst.extent(0);
2116 int itmp = i / dst.extent(0);
2117 int i1 = itmp % dst.extent(1);
2118 itmp = itmp / dst.extent(1);
2119 int i2 = itmp % dst.extent(2);
2120 itmp = itmp / dst.extent(2);
2121 int i3 = itmp % dst.extent(3);
2122 itmp = itmp / dst.extent(3);
2123 int i4 = itmp % dst.extent(4);
2124 int i5 = itmp / dst.extent(4);
2125 dst(i0, i1, i2, i3, i4, i5) = src(i0, i1, i2, i3, i4, i5);
2127 team.team_barrier();
2131 template <
class TeamType,
class DT,
class... DP,
class ST,
class... SP>
2132 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2133 const TeamType& team,
const View<DT, DP...>& dst,
2134 const View<ST, SP...>& src,
2135 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 7 &&
2136 unsigned(ViewTraits<ST, SP...>::rank) ==
2137 7)>::type* =
nullptr) {
2138 if (dst.data() ==
nullptr) {
2142 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2143 dst.extent(3) * dst.extent(4) * dst.extent(5) *
2146 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2147 team.team_barrier();
2148 local_deep_copy_contiguous(team, dst, src);
2149 team.team_barrier();
2151 team.team_barrier();
2153 int i0 = i % dst.extent(0);
2154 int itmp = i / dst.extent(0);
2155 int i1 = itmp % dst.extent(1);
2156 itmp = itmp / dst.extent(1);
2157 int i2 = itmp % dst.extent(2);
2158 itmp = itmp / dst.extent(2);
2159 int i3 = itmp % dst.extent(3);
2160 itmp = itmp / dst.extent(3);
2161 int i4 = itmp % dst.extent(4);
2162 itmp = itmp / dst.extent(4);
2163 int i5 = itmp % dst.extent(5);
2164 int i6 = itmp / dst.extent(5);
2165 dst(i0, i1, i2, i3, i4, i5, i6) = src(i0, i1, i2, i3, i4, i5, i6);
2167 team.team_barrier();
2171 template <
class DT,
class... DP,
class ST,
class... SP>
2172 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2173 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2174 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 1 &&
2175 unsigned(ViewTraits<ST, SP...>::rank) ==
2176 1)>::type* =
nullptr) {
2177 if (dst.data() ==
nullptr) {
2181 const size_t N = dst.extent(0);
2183 for (
size_t i = 0; i < N; ++i) {
2188 template <
class DT,
class... DP,
class ST,
class... SP>
2189 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2190 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2191 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 2 &&
2192 unsigned(ViewTraits<ST, SP...>::rank) ==
2193 2)>::type* =
nullptr) {
2194 if (dst.data() ==
nullptr) {
2198 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2199 local_deep_copy_contiguous(dst, src);
2201 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2202 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1) dst(i0, i1) = src(i0, i1);
2206 template <
class DT,
class... DP,
class ST,
class... SP>
2207 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2208 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2209 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 3 &&
2210 unsigned(ViewTraits<ST, SP...>::rank) ==
2211 3)>::type* =
nullptr) {
2212 if (dst.data() ==
nullptr) {
2216 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2217 local_deep_copy_contiguous(dst, src);
2219 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2220 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2221 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2222 dst(i0, i1, i2) = src(i0, i1, i2);
2226 template <
class DT,
class... DP,
class ST,
class... SP>
2227 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2228 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2229 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 4 &&
2230 unsigned(ViewTraits<ST, SP...>::rank) ==
2231 4)>::type* =
nullptr) {
2232 if (dst.data() ==
nullptr) {
2236 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2237 local_deep_copy_contiguous(dst, src);
2239 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2240 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2241 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2242 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2243 dst(i0, i1, i2, i3) = src(i0, i1, i2, i3);
2247 template <
class DT,
class... DP,
class ST,
class... SP>
2248 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2249 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2250 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 5 &&
2251 unsigned(ViewTraits<ST, SP...>::rank) ==
2252 5)>::type* =
nullptr) {
2253 if (dst.data() ==
nullptr) {
2257 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2258 local_deep_copy_contiguous(dst, src);
2260 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2261 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2262 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2263 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2264 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2265 dst(i0, i1, i2, i3, i4) = src(i0, i1, i2, i3, i4);
2269 template <
class DT,
class... DP,
class ST,
class... SP>
2270 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2271 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2272 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 6 &&
2273 unsigned(ViewTraits<ST, SP...>::rank) ==
2274 6)>::type* =
nullptr) {
2275 if (dst.data() ==
nullptr) {
2279 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2280 local_deep_copy_contiguous(dst, src);
2282 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2283 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2284 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2285 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2286 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2287 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2288 dst(i0, i1, i2, i3, i4, i5) = src(i0, i1, i2, i3, i4, i5);
2292 template <
class DT,
class... DP,
class ST,
class... SP>
2293 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2294 const View<DT, DP...>& dst,
const View<ST, SP...>& src,
2295 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) == 7 &&
2296 unsigned(ViewTraits<ST, SP...>::rank) ==
2297 7)>::type* =
nullptr) {
2298 if (dst.data() ==
nullptr) {
2302 if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2303 local_deep_copy_contiguous(dst, src);
2305 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2306 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2307 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2308 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2309 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2310 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2311 for (
size_t i6 = 0; i6 < dst.extent(6); ++i6)
2312 dst(i0, i1, i2, i3, i4, i5, i6) =
2313 src(i0, i1, i2, i3, i4, i5, i6);
2319 template <
class TeamType,
class DT,
class... DP>
2320 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
2321 const TeamType& team,
const View<DT, DP...>& dst,
2322 typename ViewTraits<DT, DP...>::const_value_type& value) {
2324 [&](
const int& i) { dst.data()[i] = value; });
2327 template <
class DT,
class... DP>
2328 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
2329 const View<DT, DP...>& dst,
2330 typename ViewTraits<DT, DP...>::const_value_type& value) {
2331 for (
size_t i = 0; i < dst.span(); ++i) {
2332 dst.data()[i] = value;
2336 template <
class TeamType,
class DT,
class... DP>
2337 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2338 const TeamType& team,
const View<DT, DP...>& dst,
2339 typename ViewTraits<DT, DP...>::const_value_type& value,
2340 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2341 1)>::type* =
nullptr) {
2342 if (dst.data() ==
nullptr) {
2346 const size_t N = dst.extent(0);
2348 team.team_barrier();
2350 [&](
const int& i) { dst(i) = value; });
2351 team.team_barrier();
2354 template <
class TeamType,
class DT,
class... DP>
2355 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2356 const TeamType& team,
const View<DT, DP...>& dst,
2357 typename ViewTraits<DT, DP...>::const_value_type& value,
2358 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2359 2)>::type* =
nullptr) {
2360 if (dst.data() ==
nullptr) {
2364 const size_t N = dst.extent(0) * dst.extent(1);
2366 if (dst.span_is_contiguous()) {
2367 team.team_barrier();
2368 local_deep_copy_contiguous(team, dst, value);
2369 team.team_barrier();
2371 team.team_barrier();
2373 int i0 = i % dst.extent(0);
2374 int i1 = i / dst.extent(0);
2375 dst(i0, i1) = value;
2377 team.team_barrier();
2381 template <
class TeamType,
class DT,
class... DP>
2382 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2383 const TeamType& team,
const View<DT, DP...>& dst,
2384 typename ViewTraits<DT, DP...>::const_value_type& value,
2385 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2386 3)>::type* =
nullptr) {
2387 if (dst.data() ==
nullptr) {
2391 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
2393 if (dst.span_is_contiguous()) {
2394 team.team_barrier();
2395 local_deep_copy_contiguous(team, dst, value);
2396 team.team_barrier();
2398 team.team_barrier();
2400 int i0 = i % dst.extent(0);
2401 int itmp = i / dst.extent(0);
2402 int i1 = itmp % dst.extent(1);
2403 int i2 = itmp / dst.extent(1);
2404 dst(i0, i1, i2) = value;
2406 team.team_barrier();
2410 template <
class TeamType,
class DT,
class... DP>
2411 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2412 const TeamType& team,
const View<DT, DP...>& dst,
2413 typename ViewTraits<DT, DP...>::const_value_type& value,
2414 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2415 4)>::type* =
nullptr) {
2416 if (dst.data() ==
nullptr) {
2421 dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
2423 if (dst.span_is_contiguous()) {
2424 team.team_barrier();
2425 local_deep_copy_contiguous(team, dst, value);
2426 team.team_barrier();
2428 team.team_barrier();
2430 int i0 = i % dst.extent(0);
2431 int itmp = i / dst.extent(0);
2432 int i1 = itmp % dst.extent(1);
2433 itmp = itmp / dst.extent(1);
2434 int i2 = itmp % dst.extent(2);
2435 int i3 = itmp / dst.extent(2);
2436 dst(i0, i1, i2, i3) = value;
2438 team.team_barrier();
2442 template <
class TeamType,
class DT,
class... DP>
2443 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2444 const TeamType& team,
const View<DT, DP...>& dst,
2445 typename ViewTraits<DT, DP...>::const_value_type& value,
2446 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2447 5)>::type* =
nullptr) {
2448 if (dst.data() ==
nullptr) {
2452 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2453 dst.extent(3) * dst.extent(4);
2455 if (dst.span_is_contiguous()) {
2456 team.team_barrier();
2457 local_deep_copy_contiguous(team, dst, value);
2458 team.team_barrier();
2460 team.team_barrier();
2462 int i0 = i % dst.extent(0);
2463 int itmp = i / dst.extent(0);
2464 int i1 = itmp % dst.extent(1);
2465 itmp = itmp / dst.extent(1);
2466 int i2 = itmp % dst.extent(2);
2467 itmp = itmp / dst.extent(2);
2468 int i3 = itmp % dst.extent(3);
2469 int i4 = itmp / dst.extent(3);
2470 dst(i0, i1, i2, i3, i4) = value;
2472 team.team_barrier();
2476 template <
class TeamType,
class DT,
class... DP>
2477 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2478 const TeamType& team,
const View<DT, DP...>& dst,
2479 typename ViewTraits<DT, DP...>::const_value_type& value,
2480 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2481 6)>::type* =
nullptr) {
2482 if (dst.data() ==
nullptr) {
2486 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2487 dst.extent(3) * dst.extent(4) * dst.extent(5);
2489 if (dst.span_is_contiguous()) {
2490 team.team_barrier();
2491 local_deep_copy_contiguous(team, dst, value);
2492 team.team_barrier();
2494 team.team_barrier();
2496 int i0 = i % dst.extent(0);
2497 int itmp = i / dst.extent(0);
2498 int i1 = itmp % dst.extent(1);
2499 itmp = itmp / dst.extent(1);
2500 int i2 = itmp % dst.extent(2);
2501 itmp = itmp / dst.extent(2);
2502 int i3 = itmp % dst.extent(3);
2503 itmp = itmp / dst.extent(3);
2504 int i4 = itmp % dst.extent(4);
2505 int i5 = itmp / dst.extent(4);
2506 dst(i0, i1, i2, i3, i4, i5) = value;
2508 team.team_barrier();
2512 template <
class TeamType,
class DT,
class... DP>
2513 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2514 const TeamType& team,
const View<DT, DP...>& dst,
2515 typename ViewTraits<DT, DP...>::const_value_type& value,
2516 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2517 7)>::type* =
nullptr) {
2518 if (dst.data() ==
nullptr) {
2522 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2523 dst.extent(3) * dst.extent(4) * dst.extent(5) *
2526 if (dst.span_is_contiguous()) {
2527 team.team_barrier();
2528 local_deep_copy_contiguous(team, dst, value);
2529 team.team_barrier();
2531 team.team_barrier();
2533 int i0 = i % dst.extent(0);
2534 int itmp = i / dst.extent(0);
2535 int i1 = itmp % dst.extent(1);
2536 itmp = itmp / dst.extent(1);
2537 int i2 = itmp % dst.extent(2);
2538 itmp = itmp / dst.extent(2);
2539 int i3 = itmp % dst.extent(3);
2540 itmp = itmp / dst.extent(3);
2541 int i4 = itmp % dst.extent(4);
2542 itmp = itmp / dst.extent(4);
2543 int i5 = itmp % dst.extent(5);
2544 int i6 = itmp / dst.extent(5);
2545 dst(i0, i1, i2, i3, i4, i5, i6) = value;
2547 team.team_barrier();
2551 template <
class DT,
class... DP>
2552 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2553 const View<DT, DP...>& dst,
2554 typename ViewTraits<DT, DP...>::const_value_type& value,
2555 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2556 1)>::type* =
nullptr) {
2557 if (dst.data() ==
nullptr) {
2561 const size_t N = dst.extent(0);
2563 for (
size_t i = 0; i < N; ++i) {
2568 template <
class DT,
class... DP>
2569 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2570 const View<DT, DP...>& dst,
2571 typename ViewTraits<DT, DP...>::const_value_type& value,
2572 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2573 2)>::type* =
nullptr) {
2574 if (dst.data() ==
nullptr) {
2578 if (dst.span_is_contiguous()) {
2579 local_deep_copy_contiguous(dst, value);
2581 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2582 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1) dst(i0, i1) = value;
2586 template <
class DT,
class... DP>
2587 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2588 const View<DT, DP...>& dst,
2589 typename ViewTraits<DT, DP...>::const_value_type& value,
2590 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2591 3)>::type* =
nullptr) {
2592 if (dst.data() ==
nullptr) {
2596 if (dst.span_is_contiguous()) {
2597 local_deep_copy_contiguous(dst, value);
2599 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2600 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2601 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2) dst(i0, i1, i2) = value;
2605 template <
class DT,
class... DP>
2606 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2607 const View<DT, DP...>& dst,
2608 typename ViewTraits<DT, DP...>::const_value_type& value,
2609 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2610 4)>::type* =
nullptr) {
2611 if (dst.data() ==
nullptr) {
2615 if (dst.span_is_contiguous()) {
2616 local_deep_copy_contiguous(dst, value);
2618 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2619 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2620 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2621 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2622 dst(i0, i1, i2, i3) = value;
2626 template <
class DT,
class... DP>
2627 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2628 const View<DT, DP...>& dst,
2629 typename ViewTraits<DT, DP...>::const_value_type& value,
2630 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2631 5)>::type* =
nullptr) {
2632 if (dst.data() ==
nullptr) {
2636 if (dst.span_is_contiguous()) {
2637 local_deep_copy_contiguous(dst, value);
2639 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2640 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2641 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2642 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2643 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2644 dst(i0, i1, i2, i3, i4) = value;
2648 template <
class DT,
class... DP>
2649 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2650 const View<DT, DP...>& dst,
2651 typename ViewTraits<DT, DP...>::const_value_type& value,
2652 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2653 6)>::type* =
nullptr) {
2654 if (dst.data() ==
nullptr) {
2658 if (dst.span_is_contiguous()) {
2659 local_deep_copy_contiguous(dst, value);
2661 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2662 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2663 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2664 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2665 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2666 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2667 dst(i0, i1, i2, i3, i4, i5) = value;
2671 template <
class DT,
class... DP>
2672 void KOKKOS_INLINE_FUNCTION local_deep_copy(
2673 const View<DT, DP...>& dst,
2674 typename ViewTraits<DT, DP...>::const_value_type& value,
2675 typename std::enable_if<(
unsigned(ViewTraits<DT, DP...>::rank) ==
2676 7)>::type* =
nullptr) {
2677 if (dst.data() ==
nullptr) {
2681 if (dst.span_is_contiguous()) {
2682 local_deep_copy_contiguous(dst, value);
2684 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
2685 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
2686 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
2687 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
2688 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
2689 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
2690 for (
size_t i6 = 0; i6 < dst.extent(6); ++i6)
2691 dst(i0, i1, i2, i3, i4, i5, i6) = value;
2704 template <
class ExecSpace,
class DT,
class... DP>
2707 typename ViewTraits<DT, DP...>::const_value_type& value,
2708 typename std::enable_if<
2709 Kokkos::Impl::is_execution_space<ExecSpace>::value &&
2710 std::is_same<
typename ViewTraits<DT, DP...>::specialize,
void>::value &&
2713 typename ViewTraits<DT, DP...>::memory_space>::accessible>::type* =
2716 static_assert(std::is_same<
typename dst_traits::non_const_value_type,
2717 typename dst_traits::value_type>::value,
2718 "deep_copy requires non-const type");
2719 #if defined(KOKKOS_ENABLE_PROFILING)
2720 typedef typename dst_traits::memory_space dst_memory_space;
2721 if (Kokkos::Profiling::profileLibraryLoaded()) {
2722 Kokkos::Profiling::beginDeepCopy(
2723 Kokkos::Profiling::SpaceHandle(dst_memory_space::name()), dst.label(),
2725 "(none)", &value, dst.span() *
sizeof(
typename dst_traits::value_type));
2728 if (dst.data() ==
nullptr) {
2731 using ViewTypeUniform =
typename std::conditional<
2732 View<DT, DP...>::Rank == 0,
2733 typename View<DT, DP...>::uniform_runtime_type,
2734 typename View<DT, DP...>::uniform_runtime_nomemspace_type>::type;
2735 Kokkos::Impl::ViewFill<ViewTypeUniform,
typename dst_traits::array_layout,
2736 ExecSpace>(dst, value, space);
2738 #if defined(KOKKOS_ENABLE_PROFILING)
2739 if (Kokkos::Profiling::profileLibraryLoaded()) {
2740 Kokkos::Profiling::endDeepCopy();
2747 template <
class ExecSpace,
class DT,
class... DP>
2750 typename ViewTraits<DT, DP...>::const_value_type& value,
2751 typename std::enable_if<
2752 Kokkos::Impl::is_execution_space<ExecSpace>::value &&
2753 std::is_same<
typename ViewTraits<DT, DP...>::specialize,
void>::value &&
2756 typename ViewTraits<DT, DP...>::memory_space>::accessible>::type* =
2759 static_assert(std::is_same<
typename dst_traits::non_const_value_type,
2760 typename dst_traits::value_type>::value,
2761 "deep_copy requires non-const type");
2762 #if defined(KOKKOS_ENABLE_PROFILING)
2763 typedef typename dst_traits::memory_space dst_memory_space;
2764 if (Kokkos::Profiling::profileLibraryLoaded()) {
2765 Kokkos::Profiling::beginDeepCopy(
2766 Kokkos::Profiling::SpaceHandle(dst_memory_space::name()), dst.label(),
2768 "(none)", &value, dst.span() *
sizeof(
typename dst_traits::value_type));
2771 if (dst.data() ==
nullptr) {
2775 using ViewTypeUniform =
typename std::conditional<
2776 View<DT, DP...>::Rank == 0,
2777 typename View<DT, DP...>::uniform_runtime_type,
2778 typename View<DT, DP...>::uniform_runtime_nomemspace_type>::type;
2779 using fill_exec_space =
typename dst_traits::memory_space::execution_space;
2780 Kokkos::Impl::ViewFill<ViewTypeUniform,
typename dst_traits::array_layout,
2781 fill_exec_space>(dst, value, fill_exec_space());
2782 fill_exec_space().fence();
2784 #if defined(KOKKOS_ENABLE_PROFILING)
2785 if (Kokkos::Profiling::profileLibraryLoaded()) {
2786 Kokkos::Profiling::endDeepCopy();
2792 template <
class ExecSpace,
class ST,
class... SP>
2794 const ExecSpace& exec_space,
2795 typename ViewTraits<ST, SP...>::non_const_value_type& dst,
2797 typename std::enable_if<
2798 Kokkos::Impl::is_execution_space<ExecSpace>::value &&
2799 std::is_same<
typename ViewTraits<ST, SP...>::specialize,
2800 void>::value>::type* = 0) {
2802 typedef typename src_traits::memory_space src_memory_space;
2803 static_assert(src_traits::rank == 0,
2804 "ERROR: Non-rank-zero view in deep_copy( value , View )");
2805 #if defined(KOKKOS_ENABLE_PROFILING)
2806 if (Kokkos::Profiling::profileLibraryLoaded()) {
2807 Kokkos::Profiling::beginDeepCopy(
2809 &dst, Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
2810 src.label(), src.data(),
sizeof(ST));
2814 if (src.data() ==
nullptr) {
2816 #if defined(KOKKOS_ENABLE_PROFILING)
2817 if (Kokkos::Profiling::profileLibraryLoaded()) {
2818 Kokkos::Profiling::endDeepCopy();
2824 Kokkos::Impl::DeepCopy<HostSpace, src_memory_space, ExecSpace>(
2825 exec_space, &dst, src.data(),
sizeof(ST));
2826 #if defined(KOKKOS_ENABLE_PROFILING)
2827 if (Kokkos::Profiling::profileLibraryLoaded()) {
2828 Kokkos::Profiling::endDeepCopy();
2835 template <
class ExecSpace,
class DT,
class... DP,
class ST,
class... SP>
2839 typename std::enable_if<(
2840 Kokkos::Impl::is_execution_space<ExecSpace>::value &&
2841 std::is_same<
typename ViewTraits<DT, DP...>::specialize,
void>::value &&
2842 std::is_same<
typename ViewTraits<ST, SP...>::specialize,
void>::value &&
2848 typedef typename src_traits::memory_space src_memory_space;
2849 typedef typename dst_traits::memory_space dst_memory_space;
2850 static_assert(std::is_same<
typename dst_traits::value_type,
2851 typename src_traits::non_const_value_type>::value,
2852 "deep_copy requires matching non-const destination type");
2854 #if defined(KOKKOS_ENABLE_PROFILING)
2855 if (Kokkos::Profiling::profileLibraryLoaded()) {
2856 Kokkos::Profiling::beginDeepCopy(
2857 Kokkos::Profiling::SpaceHandle(dst_memory_space::name()), dst.label(),
2858 dst.data(), Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
2859 src.label(), src.data(),
sizeof(DT));
2863 if (dst.data() ==
nullptr && src.data() ==
nullptr) {
2865 #if defined(KOKKOS_ENABLE_PROFILING)
2866 if (Kokkos::Profiling::profileLibraryLoaded()) {
2867 Kokkos::Profiling::endDeepCopy();
2873 if (dst.data() != src.data()) {
2874 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space, ExecSpace>(
2875 exec_space, dst.data(), src.data(),
2876 sizeof(
typename dst_traits::value_type));
2878 #if defined(KOKKOS_ENABLE_PROFILING)
2879 if (Kokkos::Profiling::profileLibraryLoaded()) {
2880 Kokkos::Profiling::endDeepCopy();
2889 template <
class ExecSpace,
class DT,
class... DP,
class ST,
class... SP>
2893 typename std::enable_if<(
2894 Kokkos::Impl::is_execution_space<ExecSpace>::value &&
2895 std::is_same<
typename ViewTraits<DT, DP...>::specialize,
void>::value &&
2896 std::is_same<
typename ViewTraits<ST, SP...>::specialize,
void>::value &&
2899 typedef View<DT, DP...> dst_type;
2900 typedef View<ST, SP...> src_type;
2902 static_assert(std::is_same<
typename dst_type::value_type,
2903 typename dst_type::non_const_value_type>::value,
2904 "deep_copy requires non-const destination type");
2906 static_assert((
unsigned(dst_type::rank) ==
unsigned(src_type::rank)),
2907 "deep_copy requires Views of equal rank");
2909 typedef typename dst_type::execution_space dst_execution_space;
2910 typedef typename src_type::execution_space src_execution_space;
2911 typedef typename dst_type::memory_space dst_memory_space;
2912 typedef typename src_type::memory_space src_memory_space;
2913 typedef typename dst_type::value_type dst_value_type;
2914 typedef typename src_type::value_type src_value_type;
2916 #if defined(KOKKOS_ENABLE_PROFILING)
2917 if (Kokkos::Profiling::profileLibraryLoaded()) {
2918 Kokkos::Profiling::beginDeepCopy(
2919 Kokkos::Profiling::SpaceHandle(dst_memory_space::name()), dst.label(),
2920 dst.data(), Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
2921 src.label(), src.data(), dst.span() *
sizeof(dst_value_type));
2925 dst_value_type* dst_start = dst.data();
2926 dst_value_type* dst_end = dst.data() + dst.span();
2927 src_value_type* src_start = src.data();
2928 src_value_type* src_end = src.data() + src.span();
2931 if ((dst_start ==
nullptr || src_start ==
nullptr) ||
2932 ((std::ptrdiff_t(dst_start) == std::ptrdiff_t(src_start)) &&
2933 (std::ptrdiff_t(dst_end) == std::ptrdiff_t(src_end)))) {
2934 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
2942 std::string message(
2943 "Deprecation Error: Kokkos::deep_copy extents of views don't "
2945 message += dst.label();
2947 for (
int r = 0; r < dst_type::Rank - 1; r++) {
2948 message += std::to_string(dst.
extent(r));
2951 message += std::to_string(dst.
extent(dst_type::Rank - 1));
2953 message += src.label();
2955 for (
int r = 0; r < src_type::Rank - 1; r++) {
2956 message += std::to_string(src.
extent(r));
2959 message += std::to_string(src.
extent(src_type::Rank - 1));
2962 Kokkos::Impl::throw_runtime_exception(message);
2965 #if defined(KOKKOS_ENABLE_PROFILING)
2966 if (Kokkos::Profiling::profileLibraryLoaded()) {
2967 Kokkos::Profiling::endDeepCopy();
2974 ExecCanAccessSrcDst =
2976 dst_memory_space>::accessible &&
2978 src_memory_space>::accessible
2981 DstExecCanAccessSrc =
2983 src_memory_space>::accessible
2987 SrcExecCanAccessDst =
2989 dst_memory_space>::accessible
2993 if ((((std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end) &&
2994 ((std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start)) &&
2995 ((dst.span_is_contiguous() && src.span_is_contiguous()))) {
2996 std::string message(
"Error: Kokkos::deep_copy of overlapping views: ");
2997 message += dst.label();
2999 message += std::to_string((std::ptrdiff_t)dst_start);
3001 message += std::to_string((std::ptrdiff_t)dst_end);
3003 message += src.label();
3005 message += std::to_string((std::ptrdiff_t)src_start);
3007 message += std::to_string((std::ptrdiff_t)src_end);
3009 Kokkos::Impl::throw_runtime_exception(message);
3017 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
3018 if (ExecCanAccessSrcDst) {
3019 Kokkos::Impl::ViewRemap<dst_type, src_type, ExecSpace>(dst, src);
3021 }
else if (DstExecCanAccessSrc) {
3025 Kokkos::Impl::ViewRemap<dst_type, src_type, dst_execution_space>(dst,
3027 dst_execution_space().fence();
3028 }
else if (SrcExecCanAccessDst) {
3032 Kokkos::Impl::ViewRemap<dst_type, src_type, src_execution_space>(dst,
3034 src_execution_space().fence();
3036 Kokkos::Impl::throw_runtime_exception(
3037 "deep_copy given views that would require a temporary allocation");
3039 #if defined(KOKKOS_ENABLE_PROFILING)
3040 if (Kokkos::Profiling::profileLibraryLoaded()) {
3041 Kokkos::Profiling::endDeepCopy();
3046 std::string message(
3047 "Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
3048 message += dst.label();
3050 for (
int r = 0; r < dst_type::Rank - 1; r++) {
3051 message += std::to_string(dst.
extent(r));
3054 message += std::to_string(dst.
extent(dst_type::Rank - 1));
3056 message += src.label();
3058 for (
int r = 0; r < src_type::Rank - 1; r++) {
3059 message += std::to_string(src.
extent(r));
3062 message += std::to_string(src.
extent(src_type::Rank - 1));
3065 Kokkos::Impl::throw_runtime_exception(message);
3072 if (std::is_same<
typename dst_type::value_type,
3073 typename src_type::non_const_value_type>::value &&
3074 (std::is_same<
typename dst_type::array_layout,
3075 typename src_type::array_layout>::value ||
3076 (dst_type::rank == 1 && src_type::rank == 1)) &&
3077 dst.span_is_contiguous() && src.span_is_contiguous() &&
3078 ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
3079 ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
3080 ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
3081 ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
3082 ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
3083 ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
3084 ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
3085 ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))) {
3086 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
3087 if ((
void*)dst.data() != (
void*)src.data()) {
3088 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space, ExecSpace>(
3089 exec_space, dst.data(), src.data(), nbytes);
3094 if (ExecCanAccessSrcDst) {
3095 Impl::view_copy(exec_space, dst, src);
3096 }
else if (DstExecCanAccessSrc || SrcExecCanAccessDst) {
3097 using cpy_exec_space =
3098 typename std::conditional<DstExecCanAccessSrc, dst_execution_space,
3099 src_execution_space>::type;
3101 Impl::view_copy(cpy_exec_space(), dst, src);
3102 cpy_exec_space().fence();
3104 Kokkos::Impl::throw_runtime_exception(
3105 "deep_copy given views that would require a temporary allocation");
3108 #if defined(KOKKOS_ENABLE_PROFILING)
3109 if (Kokkos::Profiling::profileLibraryLoaded()) {
3110 Kokkos::Profiling::endDeepCopy();
3124 template <
class T,
class... P>
3125 inline typename std::enable_if<
3126 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3128 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3131 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3132 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3133 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3134 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3135 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3136 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3137 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3141 "Can only resize managed views");
3148 if (view_type::Rank == 1 && n0 == static_cast<size_t>(v.
extent(0))) {
3151 if (view_type::Rank == 2 && n0 == static_cast<size_t>(v.
extent(0)) &&
3152 n1 == static_cast<size_t>(v.
extent(1))) {
3155 if (view_type::Rank == 3 && n0 == static_cast<size_t>(v.
extent(0)) &&
3156 n1 == static_cast<size_t>(v.
extent(1)) &&
3157 n2 == static_cast<size_t>(v.
extent(2))) {
3160 if (view_type::Rank == 4 && n0 == static_cast<size_t>(v.
extent(0)) &&
3161 n1 == static_cast<size_t>(v.
extent(1)) &&
3162 n2 == static_cast<size_t>(v.
extent(2)) &&
3163 n3 == static_cast<size_t>(v.
extent(3))) {
3166 if (view_type::Rank == 5 && n0 == static_cast<size_t>(v.
extent(0)) &&
3167 n1 == static_cast<size_t>(v.
extent(1)) &&
3168 n2 == static_cast<size_t>(v.
extent(2)) &&
3169 n3 == static_cast<size_t>(v.
extent(3)) &&
3170 n4 == static_cast<size_t>(v.
extent(4))) {
3173 if (view_type::Rank == 6 && n0 == static_cast<size_t>(v.
extent(0)) &&
3174 n1 == static_cast<size_t>(v.
extent(1)) &&
3175 n2 == static_cast<size_t>(v.
extent(2)) &&
3176 n3 == static_cast<size_t>(v.
extent(3)) &&
3177 n4 == static_cast<size_t>(v.
extent(4)) &&
3178 n5 == static_cast<size_t>(v.
extent(5))) {
3181 if (view_type::Rank == 7 && n0 == static_cast<size_t>(v.
extent(0)) &&
3182 n1 == static_cast<size_t>(v.
extent(1)) &&
3183 n2 == static_cast<size_t>(v.
extent(2)) &&
3184 n3 == static_cast<size_t>(v.
extent(3)) &&
3185 n4 == static_cast<size_t>(v.
extent(4)) &&
3186 n5 == static_cast<size_t>(v.
extent(5)) &&
3187 n6 == static_cast<size_t>(v.
extent(6))) {
3190 if (view_type::Rank == 8 && n0 == static_cast<size_t>(v.
extent(0)) &&
3191 n1 == static_cast<size_t>(v.
extent(1)) &&
3192 n2 == static_cast<size_t>(v.
extent(2)) &&
3193 n3 == static_cast<size_t>(v.
extent(3)) &&
3194 n4 == static_cast<size_t>(v.
extent(4)) &&
3195 n5 == static_cast<size_t>(v.
extent(5)) &&
3196 n6 == static_cast<size_t>(v.
extent(6)) &&
3197 n7 == static_cast<size_t>(v.
extent(7))) {
3211 view_type v_resized(v.label(), n0, n1, n2, n3, n4, n5, n6, n7);
3213 Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3220 template <
class I,
class T,
class... P>
3221 inline typename std::enable_if<
3222 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3224 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3227 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3228 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3229 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3230 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3231 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3232 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3233 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3234 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3238 "Can only resize managed views");
3245 if (view_type::Rank == 1 && n0 == static_cast<size_t>(v.
extent(0))) {
3248 if (view_type::Rank == 2 && n0 == static_cast<size_t>(v.
extent(0)) &&
3249 n1 == static_cast<size_t>(v.
extent(1))) {
3252 if (view_type::Rank == 3 && n0 == static_cast<size_t>(v.
extent(0)) &&
3253 n1 == static_cast<size_t>(v.
extent(1)) &&
3254 n2 == static_cast<size_t>(v.
extent(2))) {
3257 if (view_type::Rank == 4 && n0 == static_cast<size_t>(v.
extent(0)) &&
3258 n1 == static_cast<size_t>(v.
extent(1)) &&
3259 n2 == static_cast<size_t>(v.
extent(2)) &&
3260 n3 == static_cast<size_t>(v.
extent(3))) {
3263 if (view_type::Rank == 5 && n0 == static_cast<size_t>(v.
extent(0)) &&
3264 n1 == static_cast<size_t>(v.
extent(1)) &&
3265 n2 == static_cast<size_t>(v.
extent(2)) &&
3266 n3 == static_cast<size_t>(v.
extent(3)) &&
3267 n4 == static_cast<size_t>(v.
extent(4))) {
3270 if (view_type::Rank == 6 && n0 == static_cast<size_t>(v.
extent(0)) &&
3271 n1 == static_cast<size_t>(v.
extent(1)) &&
3272 n2 == static_cast<size_t>(v.
extent(2)) &&
3273 n3 == static_cast<size_t>(v.
extent(3)) &&
3274 n4 == static_cast<size_t>(v.
extent(4)) &&
3275 n5 == static_cast<size_t>(v.
extent(5))) {
3278 if (view_type::Rank == 7 && n0 == static_cast<size_t>(v.
extent(0)) &&
3279 n1 == static_cast<size_t>(v.
extent(1)) &&
3280 n2 == static_cast<size_t>(v.
extent(2)) &&
3281 n3 == static_cast<size_t>(v.
extent(3)) &&
3282 n4 == static_cast<size_t>(v.
extent(4)) &&
3283 n5 == static_cast<size_t>(v.
extent(5)) &&
3284 n6 == static_cast<size_t>(v.
extent(6))) {
3287 if (view_type::Rank == 8 && n0 == static_cast<size_t>(v.
extent(0)) &&
3288 n1 == static_cast<size_t>(v.
extent(1)) &&
3289 n2 == static_cast<size_t>(v.
extent(2)) &&
3290 n3 == static_cast<size_t>(v.
extent(3)) &&
3291 n4 == static_cast<size_t>(v.
extent(4)) &&
3292 n5 == static_cast<size_t>(v.
extent(5)) &&
3293 n6 == static_cast<size_t>(v.
extent(6)) &&
3294 n7 == static_cast<size_t>(v.
extent(7))) {
3308 view_type v_resized(
view_alloc(v.label(), std::forward<const I>(arg_prop)),
3309 n0, n1, n2, n3, n4, n5, n6, n7);
3311 Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3318 template <
class T,
class... P>
3320 const typename Kokkos::View<T, P...>::array_layout& layout) {
3324 "Can only resize managed views");
3326 view_type v_resized(v.label(), layout);
3328 Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3334 template <
class T,
class... P>
3335 inline typename std::enable_if<
3336 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3338 std::is_same<
typename Kokkos::View<T, P...>::array_layout,
3341 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3342 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3343 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3344 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3345 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3346 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3347 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3348 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
3352 "Can only realloc managed views");
3354 const std::string label = v.label();
3357 v = view_type(label, n0, n1, n2, n3, n4, n5, n6, n7);
3361 template <
class T,
class... P>
3364 const typename Kokkos::View<T, P...>::array_layout& layout) {
3368 "Can only realloc managed views");
3370 const std::string label = v.label();
3373 v = view_type(label, layout);
3384 template <
class Space,
class T,
class... P>
3385 struct MirrorViewType {
3389 typedef typename Space::memory_space memory_space;
3393 std::is_same<memory_space, typename src_view_type::memory_space>::value
3396 typedef typename src_view_type::array_layout array_layout;
3399 typedef typename src_view_type::non_const_data_type data_type;
3404 typedef typename std::conditional<is_same_memspace, src_view_type,
3405 dest_view_type>::type view_type;
3408 template <
class Space,
class T,
class... P>
3413 typedef typename Space::memory_space memory_space;
3417 std::is_same<memory_space, typename src_view_type::memory_space>::value
3420 typedef typename src_view_type::array_layout array_layout;
3423 typedef typename src_view_type::non_const_data_type data_type;
3430 template <
class T,
class... P>
3431 inline typename Kokkos::View<T, P...>::HostMirror create_mirror(
3433 typename std::enable_if<
3434 std::is_same<
typename ViewTraits<T, P...>::specialize,
void>::value &&
3435 !std::is_same<
typename Kokkos::ViewTraits<T, P...>::array_layout,
3437 typedef View<T, P...> src_type;
3438 typedef typename src_type::HostMirror dst_type;
3440 return dst_type(std::string(src.label()).append(
"_mirror")
3441 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
3447 src.rank_dynamic > 0 ? src.
extent(0)
3448 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3449 src.rank_dynamic > 1 ? src.
extent(1)
3450 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3451 src.rank_dynamic > 2 ? src.
extent(2)
3452 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3453 src.rank_dynamic > 3 ? src.
extent(3)
3454 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3455 src.rank_dynamic > 4 ? src.
extent(4)
3456 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3457 src.rank_dynamic > 5 ? src.
extent(5)
3458 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3459 src.rank_dynamic > 6 ? src.
extent(6)
3460 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
3461 src.rank_dynamic > 7 ? src.
extent(7)
3462 : KOKKOS_IMPL_CTOR_DEFAULT_ARG);
3466 template <
class T,
class... P>
3467 inline typename Kokkos::View<T, P...>::HostMirror create_mirror(
3469 typename std::enable_if<
3470 std::is_same<
typename ViewTraits<T, P...>::specialize,
void>::value &&
3471 std::is_same<
typename Kokkos::ViewTraits<T, P...>::array_layout,
3473 typedef View<T, P...> src_type;
3474 typedef typename src_type::HostMirror dst_type;
3478 layout.dimension[0] = src.
extent(0);
3479 layout.dimension[1] = src.
extent(1);
3480 layout.dimension[2] = src.
extent(2);
3481 layout.dimension[3] = src.
extent(3);
3482 layout.dimension[4] = src.
extent(4);
3483 layout.dimension[5] = src.
extent(5);
3484 layout.dimension[6] = src.
extent(6);
3485 layout.dimension[7] = src.
extent(7);
3487 layout.stride[0] = src.stride_0();
3488 layout.stride[1] = src.stride_1();
3489 layout.stride[2] = src.stride_2();
3490 layout.stride[3] = src.stride_3();
3491 layout.stride[4] = src.stride_4();
3492 layout.stride[5] = src.stride_5();
3493 layout.stride[6] = src.stride_6();
3494 layout.stride[7] = src.stride_7();
3496 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
3500 template <
class Space,
class T,
class... P>
3501 typename Impl::MirrorType<Space, T, P...>::view_type create_mirror(
3503 typename std::enable_if<std::is_same<
3504 typename ViewTraits<T, P...>::specialize,
void>::value>::type* =
3506 return typename Impl::MirrorType<Space, T, P...>::view_type(src.label(),
3510 template <
class T,
class... P>
3511 inline typename Kokkos::View<T, P...>::HostMirror create_mirror_view(
3513 typename std::enable_if<
3515 typename Kokkos::View<T, P...>::memory_space,
3516 typename Kokkos::View<T, P...>::HostMirror::memory_space>::value &&
3517 std::is_same<
typename Kokkos::View<T, P...>::data_type,
3518 typename Kokkos::View<T, P...>::HostMirror::data_type>::
3519 value)>::type* =
nullptr) {
3523 template <
class T,
class... P>
3524 inline typename Kokkos::View<T, P...>::HostMirror create_mirror_view(
3526 typename std::enable_if<!(
3528 typename Kokkos::View<T, P...>::memory_space,
3529 typename Kokkos::View<T, P...>::HostMirror::memory_space>::value &&
3530 std::is_same<
typename Kokkos::View<T, P...>::data_type,
3531 typename Kokkos::View<T, P...>::HostMirror::data_type>::
3532 value)>::type* = 0) {
3533 return Kokkos::create_mirror(src);
3537 template <
class Space,
class T,
class... P>
3538 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3540 typename std::enable_if<
3541 Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
3547 template <
class Space,
class T,
class... P>
3548 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3550 typename std::enable_if<
3551 !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* = 0) {
3552 return typename Impl::MirrorViewType<Space, T, P...>::view_type(src.label(),
3558 template <
class Space,
class T,
class... P>
3559 typename Impl::MirrorViewType<Space, T, P...>::view_type
3560 create_mirror_view_and_copy(
3562 std::string
const& name =
"",
3563 typename std::enable_if<
3564 Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
3573 template <
class Space,
class T,
class... P>
3574 typename Impl::MirrorViewType<Space, T, P...>::view_type
3575 create_mirror_view_and_copy(
3577 std::string
const& name =
"",
3578 typename std::enable_if<
3579 !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* = 0) {
3580 using Mirror =
typename Impl::MirrorViewType<Space, T, P...>::view_type;
3581 std::string label = name.empty() ? src.label() : name;
3582 auto mirror =
typename Mirror::non_const_type{
3583 ViewAllocateWithoutInitializing(label), src.layout()};
3590 template <
class Space,
class T,
class... P>
3591 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3593 Kokkos::Impl::WithoutInitializing_t,
3594 typename std::enable_if<
3595 Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
3602 template <
class Space,
class T,
class... P>
3603 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3605 Kokkos::Impl::WithoutInitializing_t,
3606 typename std::enable_if<
3607 !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* = 0) {
3608 using Mirror =
typename Impl::MirrorViewType<Space, T, P...>::view_type;
3609 return Mirror(Kokkos::ViewAllocateWithoutInitializing(src.label()),
void deep_copy(const View< DT, DP...> &dst, typename ViewTraits< DT, DP...>::const_value_type &value, typename std::enable_if< std::is_same< typename ViewTraits< DT, DP...>::specialize, void >::value >::type *=nullptr)
Deep copy a value from Host memory into a view.
KOKKOS_INLINE_FUNCTION_DELETED Impl::TeamThreadRangeBoundariesStruct< iType, TeamMemberType > TeamThreadRange(const TeamMemberType &, const iType &count)=delete
Execution policy for parallel work over a threads within a team.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< std::is_integral< iType >::value, size_t >::type extent(const iType &r) const noexcept
rank() to be implemented
Can AccessSpace access MemorySpace ?
Replacement for std::pair that works on CUDA devices.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
View to an array of data.
Memory management for host memory.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
static constexpr const char * name()
Return Name of the MemorySpace.
Impl::ViewCtorProp< typename Impl::ViewCtorProp< void, Args >::type...> view_alloc(Args const &...args)
Create View allocation parameter bundle from argument list.
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type resize(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with copying old data to new data at the corresponding indices.
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type realloc(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with discarding old data.
void parallel_for(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename std::enable_if< Kokkos::Impl::is_execution_policy< ExecPolicy >::value >::type *=nullptr)
Execute functor in parallel according to the execution policy.
Execution policy for work over a range of an integral type.
Traits class for accessing attributes of a View.