44 #ifndef KOKKOS_COPYVIEWS_HPP_
45 #define KOKKOS_COPYVIEWS_HPP_
51 #ifndef KOKKOS_IMPL_COMPILING_LIBRARY
52 #define KOKKOS_IMPL_COMPILING_LIBRARY false
59 template<
class Layout>
60 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,
bool ETIAvail>
82 struct ViewFill<ViewType,Layout,ExecSpace,0,iType,ETIAvail> {
84 typename ViewType::const_value_type val;
85 typedef typename ViewType::non_const_value_type ST;
86 ViewFill(
const ViewType&,
const ST&);
89 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
90 struct ViewFill<ViewType,Layout,ExecSpace,1,iType,ETIAvail> {
92 typename ViewType::const_value_type val;
93 typedef typename ViewType::non_const_value_type ST;
94 ViewFill(
const ViewType&,
const ST&);
95 KOKKOS_INLINE_FUNCTION
96 void operator() (
const iType&)
const;
99 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
100 struct ViewFill<ViewType,Layout,ExecSpace,2,iType,ETIAvail> {
102 typename ViewType::const_value_type val;
103 typedef typename ViewType::non_const_value_type ST;
104 ViewFill(
const ViewType&,
const ST&);
105 KOKKOS_INLINE_FUNCTION
106 void operator() (
const iType&,
const iType&)
const;
109 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
110 struct ViewFill<ViewType,Layout,ExecSpace,3,iType,ETIAvail> {
112 typename ViewType::const_value_type val;
113 typedef typename ViewType::non_const_value_type ST;
114 ViewFill(
const ViewType&,
const ST&);
115 KOKKOS_INLINE_FUNCTION
116 void operator() (
const iType&,
const iType&,
const iType&)
const;
119 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
120 struct ViewFill<ViewType,Layout,ExecSpace,4,iType,ETIAvail> {
122 typename ViewType::const_value_type val;
123 typedef typename ViewType::non_const_value_type ST;
124 ViewFill(
const ViewType&,
const ST&);
125 KOKKOS_INLINE_FUNCTION
126 void operator() (
const iType&,
const iType&,
const iType&,
const iType&)
const;
129 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
130 struct ViewFill<ViewType,Layout,ExecSpace,5,iType,ETIAvail> {
132 typename ViewType::const_value_type val;
133 typedef typename ViewType::non_const_value_type ST;
134 ViewFill(
const ViewType&,
const ST&);
135 KOKKOS_INLINE_FUNCTION
136 void operator() (
const iType&,
const iType&,
const iType&,
const iType&,
140 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
141 struct ViewFill<ViewType,Layout,ExecSpace,6,iType,ETIAvail> {
143 typename ViewType::const_value_type val;
144 typedef typename ViewType::non_const_value_type ST;
145 ViewFill(
const ViewType&,
const ST&);
146 KOKKOS_INLINE_FUNCTION
147 void operator() (
const iType&,
const iType&,
const iType&,
const iType&,
148 const iType&,
const iType&)
const;
151 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
152 struct ViewFill<ViewType,Layout,ExecSpace,7,iType,ETIAvail> {
154 typename ViewType::const_value_type val;
155 typedef typename ViewType::non_const_value_type ST;
156 ViewFill(
const ViewType&,
const ST&);
157 KOKKOS_INLINE_FUNCTION
158 void operator() (
const iType&,
const iType&,
const iType&,
const iType&,
159 const iType&,
const iType&,
const iType&)
const;
162 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
163 struct ViewFill<ViewType,Layout,ExecSpace,8,iType,ETIAvail> {
165 typename ViewType::const_value_type val;
166 typedef typename ViewType::non_const_value_type ST;
167 ViewFill(
const ViewType&,
const ST&);
168 KOKKOS_INLINE_FUNCTION
169 void operator() (
const iType&,
const iType&,
const iType&,
const iType&,
170 const iType&,
const iType&,
const iType&,
const iType&)
const;
173 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
174 struct ViewFill<ViewType,Layout,ExecSpace,0,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
175 typedef typename ViewType::non_const_value_type ST;
176 ViewFill(
const ViewType& a,
const ST& val) {
177 Kokkos::Impl::DeepCopy< typename ViewType::memory_space, Kokkos::HostSpace >( a.data() , &val,
sizeof(ST) );
182 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
183 struct ViewFill<ViewType,Layout,ExecSpace,1,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
185 typename ViewType::const_value_type val;
188 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
194 KOKKOS_INLINE_FUNCTION
195 void operator() (
const iType& i)
const {
200 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
201 struct ViewFill<ViewType,Layout,ExecSpace,2,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
203 typename ViewType::const_value_type val;
205 typedef Kokkos::Rank<2,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
206 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
208 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
211 policy_type({0,0},{a.extent(0),a.extent(1)}),*
this);
215 KOKKOS_INLINE_FUNCTION
216 void operator() (
const iType& i0,
const iType& i1)
const {
221 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
222 struct ViewFill<ViewType,Layout,ExecSpace,3,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
224 typename ViewType::const_value_type val;
226 typedef Kokkos::Rank<3,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
227 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
229 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
232 policy_type({0,0,0},{a.extent(0),a.extent(1),a.extent(2)}),*
this);
236 KOKKOS_INLINE_FUNCTION
237 void operator() (
const iType& i0,
const iType& i1,
const iType& i2)
const {
242 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
243 struct ViewFill<ViewType,Layout,ExecSpace,4,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
245 typename ViewType::const_value_type val;
247 typedef Kokkos::Rank<4,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
248 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
250 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
253 policy_type({0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3)}),*
this);
257 KOKKOS_INLINE_FUNCTION
258 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3)
const {
259 a(i0,i1,i2,i3) = val;
263 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
264 struct ViewFill<ViewType,Layout,ExecSpace,5,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
266 typename ViewType::const_value_type val;
268 typedef Kokkos::Rank<5,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
269 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
271 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
274 policy_type({0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3),a.extent(4)}),*
this);
278 KOKKOS_INLINE_FUNCTION
279 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3,
const iType& i4)
const {
280 a(i0,i1,i2,i3,i4) = val;
284 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
285 struct ViewFill<ViewType,Layout,ExecSpace,6,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
287 typename ViewType::const_value_type val;
289 typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
290 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
292 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
295 policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3),a.extent(4),a.extent(5)}),*
this);
299 KOKKOS_INLINE_FUNCTION
300 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3,
const iType& i4,
const iType& i5)
const {
301 a(i0,i1,i2,i3,i4,i5) = val;
305 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
306 struct ViewFill<ViewType,Layout,ExecSpace,7,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
308 typename ViewType::const_value_type val;
310 typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
311 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
313 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
316 policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3),
317 a.extent(5),a.extent(6)}),*
this);
321 KOKKOS_INLINE_FUNCTION
322 void operator() (
const iType& i0,
const iType& i1,
const iType& i3,
323 const iType& i4,
const iType& i5,
const iType& i6)
const {
324 for(iType i2=0; i2<iType(a.extent(2));i2++)
325 a(i0,i1,i2,i3,i4,i5,i6) = val;
329 template<
class ViewType,
class Layout,
class ExecSpace,
typename iType>
330 struct ViewFill<ViewType,Layout,ExecSpace,8,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
332 typename ViewType::const_value_type val;
334 typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
335 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
337 ViewFill(
const ViewType& a_,
typename ViewType::const_value_type& val_):a(a_),val(val_) {
340 policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
341 a.extent(5),a.extent(6),a.extent(7)}),*
this);
345 KOKKOS_INLINE_FUNCTION
346 void operator() (
const iType& i0,
const iType& i1,
const iType& i3,
347 const iType& i5,
const iType& i6,
const iType& i7)
const {
348 for(iType i2=0; i2<iType(a.extent(2));i2++)
349 for(iType i4=0; i4<iType(a.extent(4));i4++)
350 a(i0,i1,i2,i3,i4,i5,i6,i7) = val;
354 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
355 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,1,iType,ETIAvail> {
358 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
359 KOKKOS_INLINE_FUNCTION
360 void operator() (
const iType& i0)
const;
363 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
364 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,2,iType,ETIAvail> {
367 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
368 KOKKOS_INLINE_FUNCTION
369 void operator() (
const iType& i0,
const iType& i1)
const;
372 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
373 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,3,iType,ETIAvail> {
376 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
377 KOKKOS_INLINE_FUNCTION
378 void operator() (
const iType& i0,
const iType& i1,
const iType& i2)
const;
381 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
382 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,4,iType,ETIAvail> {
385 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
386 KOKKOS_INLINE_FUNCTION
387 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3)
const;
390 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
391 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,5,iType,ETIAvail> {
394 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
395 KOKKOS_INLINE_FUNCTION
396 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3,
397 const iType& i4)
const;
400 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
401 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,6,iType,ETIAvail> {
404 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
405 KOKKOS_INLINE_FUNCTION
406 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3,
407 const iType& i4,
const iType& i5)
const;
410 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
411 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,7,iType,ETIAvail> {
414 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
415 KOKKOS_INLINE_FUNCTION
416 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3,
417 const iType& i4,
const iType& i5,
const iType& i6)
const;
420 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType,
bool ETIAvail>
421 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,8,iType,ETIAvail> {
424 ViewCopy(
const ViewTypeA&,
const ViewTypeB&);
425 KOKKOS_INLINE_FUNCTION
426 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
const iType& i3,
427 const iType& i4,
const iType& i5,
const iType& i6,
const iType& i7)
const;
432 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
433 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,1,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
439 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
442 policy_type(0,a.extent(0)),*
this);
446 KOKKOS_INLINE_FUNCTION
447 void operator() (
const iType& i0)
const {
452 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
453 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,2,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
456 static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
457 static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
458 typedef Kokkos::Rank<2,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
459 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
461 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
464 policy_type({0,0},{a.extent(0),a.extent(1)}),*
this);
468 KOKKOS_INLINE_FUNCTION
469 void operator() (
const iType& i0,
const iType& i1)
const {
474 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
475 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,3,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
479 static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
480 static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
481 typedef Kokkos::Rank<3,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
482 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
484 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
487 policy_type({0,0,0},{a.extent(0),a.extent(1),a.extent(2)}),*
this);
491 KOKKOS_INLINE_FUNCTION
492 void operator() (
const iType& i0,
const iType& i1,
const iType& i2)
const {
493 a(i0,i1,i2) = b(i0,i1,i2);
497 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
498 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,4,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
502 static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
503 static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
504 typedef Kokkos::Rank<4,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
505 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
507 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
510 policy_type({0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
511 a.extent(3)}),*
this);
515 KOKKOS_INLINE_FUNCTION
516 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
517 const iType& i3)
const {
518 a(i0,i1,i2,i3) = b(i0,i1,i2,i3);
522 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
523 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,5,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
527 static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
528 static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
529 typedef Kokkos::Rank<5,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
530 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
532 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
535 policy_type({0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
536 a.extent(3),a.extent(4)}),*
this);
540 KOKKOS_INLINE_FUNCTION
541 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
542 const iType& i3,
const iType& i4)
const {
543 a(i0,i1,i2,i3,i4) = b(i0,i1,i2,i3,i4);
547 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
548 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,6,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
552 static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
553 static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
554 typedef Kokkos::Rank<6,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
555 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
557 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
560 policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
561 a.extent(3),a.extent(4),a.extent(5)}),*
this);
565 KOKKOS_INLINE_FUNCTION
566 void operator() (
const iType& i0,
const iType& i1,
const iType& i2,
567 const iType& i3,
const iType& i4,
const iType& i5)
const {
568 a(i0,i1,i2,i3,i4,i5) = b(i0,i1,i2,i3,i4,i5);
573 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
574 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,7,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
578 static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
579 static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
580 typedef Kokkos::Rank<6,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
581 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
583 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
586 policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
587 a.extent(4),a.extent(5),a.extent(6)}),*
this);
591 KOKKOS_INLINE_FUNCTION
592 void operator() (
const iType& i0,
const iType& i1,
const iType& i3,
593 const iType& i4,
const iType& i5,
const iType& i6)
const {
594 for(iType i2=0; i2<iType(a.extent(2));i2++)
595 a(i0,i1,i2,i3,i4,i5,i6) = b(i0,i1,i2,i3,i4,i5,i6);
599 template<
class ViewTypeA,
class ViewTypeB,
class Layout,
class ExecSpace,
typename iType>
600 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,8,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
604 static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
605 static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
606 typedef Kokkos::Rank<6,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
607 typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
609 ViewCopy(
const ViewTypeA& a_,
const ViewTypeB& b_):a(a_),b(b_) {
612 policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
613 a.extent(5),a.extent(6),a.extent(7)}),*
this);
617 KOKKOS_INLINE_FUNCTION
618 void operator() (
const iType& i0,
const iType& i1,
const iType& i3,
619 const iType& i5,
const iType& i6,
const iType& i7)
const {
620 for(iType i2=0; i2<iType(a.extent(2));i2++)
621 for(iType i4=0; i4<iType(a.extent(4));i4++)
622 a(i0,i1,i2,i3,i4,i5,i6,i7) = b(i0,i1,i2,i3,i4,i5,i6,i7);
629 #include<impl/Kokkos_ViewFillCopyETIDecl.hpp>
634 template<
class DstType,
class SrcType>
635 void view_copy(
const DstType& dst,
const SrcType& src) {
636 typedef typename DstType::execution_space dst_execution_space;
637 typedef typename SrcType::execution_space src_execution_space;
638 typedef typename DstType::memory_space dst_memory_space;
639 typedef typename SrcType::memory_space src_memory_space;
641 enum { DstExecCanAccessSrc =
644 enum { SrcExecCanAccessDst =
647 if( ! DstExecCanAccessSrc && ! SrcExecCanAccessDst) {
648 std::string message(
"Error: Kokkos::deep_copy with no available copy mechanism: ");
649 message += src.label(); message +=
" to ";
650 message += dst.label();
651 Kokkos::Impl::throw_runtime_exception(message);
655 int64_t strides[DstType::Rank+1];
657 Kokkos::Iterate iterate;
658 if ( Kokkos::is_layouttiled<typename DstType::array_layout>::value ) {
659 iterate = Kokkos::layout_iterate_type_selector<typename DstType::array_layout>::outer_iteration_pattern;
660 }
else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutRight>::value ) {
661 iterate = Kokkos::Iterate::Right;
662 }
else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutLeft>::value ) {
663 iterate = Kokkos::Iterate::Left;
664 }
else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutStride>::value ) {
665 if( strides[0] > strides[DstType::Rank-1] )
666 iterate = Kokkos::Iterate::Right;
668 iterate = Kokkos::Iterate::Left;
670 if( std::is_same<typename DstType::execution_space::array_layout, Kokkos::LayoutRight>::value )
671 iterate = Kokkos::Iterate::Right;
673 iterate = Kokkos::Iterate::Left;
676 if( (dst.span() >= size_t(std::numeric_limits<int>::max())) ||
677 (src.span() >= size_t(std::numeric_limits<int>::max())) ){
678 if(DstExecCanAccessSrc) {
679 if(iterate == Kokkos::Iterate::Right)
680 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutRight, dst_execution_space,
681 DstType::Rank, int64_t >( dst , src );
683 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutLeft, dst_execution_space,
684 DstType::Rank, int64_t >( dst , src );
686 if(iterate == Kokkos::Iterate::Right)
687 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutRight, src_execution_space,
688 DstType::Rank, int64_t >( dst , src );
690 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutLeft, src_execution_space,
691 DstType::Rank, int64_t >( dst , src );
694 if(DstExecCanAccessSrc) {
695 if(iterate == Kokkos::Iterate::Right)
696 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutRight, dst_execution_space,
697 DstType::Rank,
int >( dst , src );
699 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutLeft, dst_execution_space,
700 DstType::Rank,
int >( dst , src );
702 if(iterate == Kokkos::Iterate::Right)
703 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutRight, src_execution_space,
704 DstType::Rank,
int >( dst , src );
706 Kokkos::Impl::ViewCopy<
typename DstType::uniform_runtime_nomemspace_type,
typename SrcType::uniform_runtime_const_nomemspace_type,
Kokkos::LayoutLeft, src_execution_space,
707 DstType::Rank,
int >( dst , src );
713 template<
class DstType,
class SrcType,
int Rank,
class ... Args>
714 struct CommonSubview;
716 template<
class DstType,
class SrcType,
class Arg0,
class ... Args>
717 struct CommonSubview<DstType,SrcType,1,Arg0,Args...> {
718 typedef typename Kokkos::Subview<DstType,Arg0> dst_subview_type;
719 typedef typename Kokkos::Subview<SrcType,Arg0> src_subview_type;
720 dst_subview_type dst_sub;
721 src_subview_type src_sub;
722 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0, Args... ):
723 dst_sub(dst,arg0),src_sub(src,arg0) {}
726 template<
class DstType,
class SrcType,
class Arg0,
class Arg1,
class ... Args>
727 struct CommonSubview<DstType,SrcType,2,Arg0,Arg1,Args...> {
728 typedef typename Kokkos::Subview<DstType,Arg0,Arg1> dst_subview_type;
729 typedef typename Kokkos::Subview<SrcType,Arg0,Arg1> src_subview_type;
730 dst_subview_type dst_sub;
731 src_subview_type src_sub;
732 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
const Arg1& arg1, Args... ):
733 dst_sub(dst,arg0,arg1),src_sub(src,arg0,arg1) {}
736 template<
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
class ... Args>
737 struct CommonSubview<DstType,SrcType,3,Arg0,Arg1,Arg2,Args...> {
738 typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2> dst_subview_type;
739 typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2> src_subview_type;
740 dst_subview_type dst_sub;
741 src_subview_type src_sub;
742 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
const Arg1& arg1,
743 const Arg2& arg2, Args... ):
744 dst_sub(dst,arg0,arg1,arg2),src_sub(src,arg0,arg1,arg2) {}
747 template<
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
class Arg3,
749 struct CommonSubview<DstType,SrcType,4,Arg0,Arg1,Arg2,Arg3,Args...> {
750 typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3> dst_subview_type;
751 typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3> src_subview_type;
752 dst_subview_type dst_sub;
753 src_subview_type src_sub;
754 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
const Arg1& arg1,
755 const Arg2& arg2,
const Arg3& arg3,
757 dst_sub(dst,arg0,arg1,arg2,arg3),src_sub(src,arg0,arg1,arg2,arg3) {}
760 template<
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
class Arg3,
761 class Arg4,
class ... Args>
762 struct CommonSubview<DstType,SrcType,5,Arg0,Arg1,Arg2,Arg3,Arg4,Args...> {
763 typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4> dst_subview_type;
764 typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4> src_subview_type;
765 dst_subview_type dst_sub;
766 src_subview_type src_sub;
767 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
const Arg1& arg1,
768 const Arg2& arg2,
const Arg3& arg3,
const Arg4& arg4,
770 dst_sub(dst,arg0,arg1,arg2,arg3,arg4),src_sub(src,arg0,arg1,arg2,arg3,arg4) {}
773 template<
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
class Arg3,
774 class Arg4,
class Arg5,
class ... Args>
775 struct CommonSubview<DstType,SrcType,6,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Args...> {
776 typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5> dst_subview_type;
777 typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5> src_subview_type;
778 dst_subview_type dst_sub;
779 src_subview_type src_sub;
780 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
const Arg1& arg1,
781 const Arg2& arg2,
const Arg3& arg3,
const Arg4& arg4,
const Arg5& arg5,
783 dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5) {}
786 template<
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
class Arg3,
787 class Arg4,
class Arg5,
class Arg6,
class ...Args>
788 struct CommonSubview<DstType,SrcType,7,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Args...> {
789 typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6> dst_subview_type;
790 typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6> src_subview_type;
791 dst_subview_type dst_sub;
792 src_subview_type src_sub;
793 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
const Arg1& arg1,
794 const Arg2& arg2,
const Arg3& arg3,
const Arg4& arg4,
const Arg5& arg5,
795 const Arg6& arg6, Args...):
796 dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5,arg6),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5,arg6) {}
799 template<
class DstType,
class SrcType,
class Arg0,
class Arg1,
class Arg2,
class Arg3,
800 class Arg4,
class Arg5,
class Arg6,
class Arg7>
801 struct CommonSubview<DstType,SrcType,8,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> {
802 typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> dst_subview_type;
803 typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> src_subview_type;
804 dst_subview_type dst_sub;
805 src_subview_type src_sub;
806 CommonSubview(
const DstType& dst,
const SrcType& src,
const Arg0& arg0,
const Arg1& arg1,
807 const Arg2& arg2,
const Arg3& arg3,
const Arg4& arg4,
const Arg5& arg5,
808 const Arg6& arg6,
const Arg7& arg7):
809 dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7) {}
813 template<
class DstType,
class SrcType,
class ExecSpace =
typename DstType::execution_space,
int Rank = DstType::Rank>
816 template<
class DstType,
class SrcType,
class ExecSpace>
817 struct ViewRemap<DstType,SrcType,ExecSpace,1> {
820 ViewRemap(
const DstType& dst,
const SrcType& src) {
821 if(dst.extent(0) == src.extent(0)) {
824 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
825 typedef CommonSubview<DstType,SrcType,1,p_type> sv_adapter_type;
826 sv_adapter_type common_subview(dst,src,ext0);
827 view_copy(common_subview.dst_sub,common_subview.src_sub);
832 template<
class DstType,
class SrcType,
class ExecSpace>
833 struct ViewRemap<DstType,SrcType,ExecSpace,2> {
836 ViewRemap(
const DstType& dst,
const SrcType& src) {
837 if(dst.extent(0) == src.extent(0)) {
838 if(dst.extent(1) == src.extent(1)) {
841 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
842 typedef CommonSubview<DstType,SrcType,2,Kokkos::Impl::ALL_t,p_type> sv_adapter_type;
843 sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1);
844 view_copy(common_subview.dst_sub,common_subview.src_sub);
847 if(dst.extent(1) == src.extent(1)) {
848 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
849 typedef CommonSubview<DstType,SrcType,2,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
850 sv_adapter_type common_subview(dst,src,ext0,Kokkos::ALL);
851 view_copy(common_subview.dst_sub,common_subview.src_sub);
853 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
854 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
855 typedef CommonSubview<DstType,SrcType,2,p_type,p_type> sv_adapter_type;
856 sv_adapter_type common_subview(dst,src,ext0,ext1);
857 view_copy(common_subview.dst_sub,common_subview.src_sub);
863 template<
class DstType,
class SrcType,
class ExecSpace>
864 struct ViewRemap<DstType,SrcType,ExecSpace,3> {
867 ViewRemap(
const DstType& dst,
const SrcType& src) {
868 if(dst.extent(0) == src.extent(0)) {
869 if(dst.extent(2) == src.extent(2)) {
870 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
871 typedef CommonSubview<DstType,SrcType,3,Kokkos::Impl::ALL_t,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
872 sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1,Kokkos::ALL);
873 view_copy(common_subview.dst_sub,common_subview.src_sub);
875 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
876 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
877 typedef CommonSubview<DstType,SrcType,3,Kokkos::Impl::ALL_t,p_type,p_type> sv_adapter_type;
878 sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1,ext2);
879 view_copy(common_subview.dst_sub,common_subview.src_sub);
882 if(dst.extent(2) == src.extent(2)) {
883 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
884 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
885 typedef CommonSubview<DstType,SrcType,3,p_type,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
886 sv_adapter_type common_subview(dst,src,ext0,ext1,Kokkos::ALL);
887 view_copy(common_subview.dst_sub,common_subview.src_sub);
889 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
890 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
891 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
892 typedef CommonSubview<DstType,SrcType,3,p_type,p_type,p_type> sv_adapter_type;
893 sv_adapter_type common_subview(dst,src,ext0,ext1,ext2);
894 view_copy(common_subview.dst_sub,common_subview.src_sub);
900 template<
class DstType,
class SrcType,
class ExecSpace>
901 struct ViewRemap<DstType,SrcType,ExecSpace,4> {
904 ViewRemap(
const DstType& dst,
const SrcType& src) {
905 if(dst.extent(0) == src.extent(0)) {
906 if(dst.extent(3) == src.extent(3)) {
907 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
908 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
909 typedef CommonSubview<DstType,SrcType,4,Kokkos::Impl::ALL_t,
911 Kokkos::Impl::ALL_t> sv_adapter_type;
912 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
915 view_copy(common_subview.dst_sub,common_subview.src_sub);
917 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
918 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
919 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
920 typedef CommonSubview<DstType,SrcType,4,Kokkos::Impl::ALL_t,
922 p_type> sv_adapter_type;
923 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
926 view_copy(common_subview.dst_sub,common_subview.src_sub);
929 if(dst.extent(7) == src.extent(7)) {
930 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
931 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
932 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
933 typedef CommonSubview<DstType,SrcType,4,p_type,
935 Kokkos::Impl::ALL_t> sv_adapter_type;
936 sv_adapter_type common_subview(dst,src,ext0,
939 view_copy(common_subview.dst_sub,common_subview.src_sub);
941 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
942 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
943 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
944 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
945 typedef CommonSubview<DstType,SrcType,4,p_type,
947 p_type> sv_adapter_type;
948 sv_adapter_type common_subview(dst,src,ext0,
951 view_copy(common_subview.dst_sub,common_subview.src_sub);
957 template<
class DstType,
class SrcType,
class ExecSpace>
958 struct ViewRemap<DstType,SrcType,ExecSpace,5> {
961 ViewRemap(
const DstType& dst,
const SrcType& src) {
962 if(dst.extent(0) == src.extent(0)) {
963 if(dst.extent(4) == src.extent(4)) {
964 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
965 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
966 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
967 typedef CommonSubview<DstType,SrcType,5,Kokkos::Impl::ALL_t,
968 p_type,p_type,p_type,
969 Kokkos::Impl::ALL_t> sv_adapter_type;
970 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
973 view_copy(common_subview.dst_sub,common_subview.src_sub);
975 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
976 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
977 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
978 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
979 typedef CommonSubview<DstType,SrcType,5,Kokkos::Impl::ALL_t,
980 p_type,p_type,p_type,
981 p_type> sv_adapter_type;
982 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
985 view_copy(common_subview.dst_sub,common_subview.src_sub);
988 if(dst.extent(4) == src.extent(4)) {
989 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
990 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
991 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
992 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
993 typedef CommonSubview<DstType,SrcType,5,p_type,
994 p_type,p_type,p_type,
995 Kokkos::Impl::ALL_t> sv_adapter_type;
996 sv_adapter_type common_subview(dst,src,ext0,
999 view_copy(common_subview.dst_sub,common_subview.src_sub);
1001 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1002 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1003 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1004 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1005 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1006 typedef CommonSubview<DstType,SrcType,5,p_type,
1007 p_type,p_type,p_type,
1008 p_type> sv_adapter_type;
1009 sv_adapter_type common_subview(dst,src,ext0,
1012 view_copy(common_subview.dst_sub,common_subview.src_sub);
1017 template<
class DstType,
class SrcType,
class ExecSpace>
1018 struct ViewRemap<DstType,SrcType,ExecSpace,6> {
1021 ViewRemap(
const DstType& dst,
const SrcType& src) {
1022 if(dst.extent(0) == src.extent(0)) {
1023 if(dst.extent(5) == src.extent(5)) {
1024 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1025 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1026 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1027 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1028 typedef CommonSubview<DstType,SrcType,6,Kokkos::Impl::ALL_t,
1029 p_type,p_type,p_type,p_type,
1030 Kokkos::Impl::ALL_t> sv_adapter_type;
1031 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1032 ext1,ext2,ext3,ext4,
1034 view_copy(common_subview.dst_sub,common_subview.src_sub);
1036 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1037 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1038 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1039 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1040 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1041 typedef CommonSubview<DstType,SrcType,6,Kokkos::Impl::ALL_t,
1042 p_type,p_type,p_type,p_type,
1043 p_type> sv_adapter_type;
1044 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1045 ext1,ext2,ext3,ext4,
1047 view_copy(common_subview.dst_sub,common_subview.src_sub);
1050 if(dst.extent(5) == src.extent(5)) {
1051 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1052 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1053 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1054 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1055 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1057 typedef CommonSubview<DstType,SrcType,6,p_type,
1058 p_type,p_type,p_type,p_type,
1059 Kokkos::Impl::ALL_t> sv_adapter_type;
1060 sv_adapter_type common_subview(dst,src,ext0,
1061 ext1,ext2,ext3,ext4,
1063 view_copy(common_subview.dst_sub,common_subview.src_sub);
1065 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1066 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1067 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1068 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1069 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1070 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1072 typedef CommonSubview<DstType,SrcType,6,p_type,
1073 p_type,p_type,p_type,p_type,
1074 p_type> sv_adapter_type;
1075 sv_adapter_type common_subview(dst,src,ext0,
1076 ext1,ext2,ext3,ext4,
1078 view_copy(common_subview.dst_sub,common_subview.src_sub);
1084 template<
class DstType,
class SrcType,
class ExecSpace>
1085 struct ViewRemap<DstType,SrcType,ExecSpace,7> {
1088 ViewRemap(
const DstType& dst,
const SrcType& src) {
1089 if(dst.extent(0) == src.extent(0)) {
1090 if(dst.extent(6) == src.extent(6)) {
1091 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1092 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1093 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1094 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1095 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1096 typedef CommonSubview<DstType,SrcType,7,Kokkos::Impl::ALL_t,
1097 p_type,p_type,p_type,p_type,p_type,
1098 Kokkos::Impl::ALL_t> sv_adapter_type;
1099 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1100 ext1,ext2,ext3,ext4,ext5,
1102 view_copy(common_subview.dst_sub,common_subview.src_sub);
1104 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1105 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1106 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1107 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1108 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1109 p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1110 typedef CommonSubview<DstType,SrcType,7,Kokkos::Impl::ALL_t,
1111 p_type,p_type,p_type,p_type,p_type,
1112 p_type> sv_adapter_type;
1113 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1114 ext1,ext2,ext3,ext4,ext5,
1116 view_copy(common_subview.dst_sub,common_subview.src_sub);
1119 if(dst.extent(6) == src.extent(6)) {
1120 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1121 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1122 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1123 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1124 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1125 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1126 typedef CommonSubview<DstType,SrcType,7,p_type,
1127 p_type,p_type,p_type,p_type,p_type,
1128 Kokkos::Impl::ALL_t> sv_adapter_type;
1129 sv_adapter_type common_subview(dst,src,ext0,
1130 ext1,ext2,ext3,ext4,ext5,
1132 view_copy(common_subview.dst_sub,common_subview.src_sub);
1134 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1135 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1136 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1137 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1138 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1139 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1140 p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1141 typedef CommonSubview<DstType,SrcType,7,p_type,
1142 p_type,p_type,p_type,p_type,p_type,
1143 p_type> sv_adapter_type;
1144 sv_adapter_type common_subview(dst,src,ext0,
1145 ext1,ext2,ext3,ext4,ext5,
1147 view_copy(common_subview.dst_sub,common_subview.src_sub);
1153 template<
class DstType,
class SrcType,
class ExecSpace>
1154 struct ViewRemap<DstType,SrcType,ExecSpace,8> {
1157 ViewRemap(
const DstType& dst,
const SrcType& src) {
1158 if(dst.extent(0) == src.extent(0)) {
1159 if(dst.extent(7) == src.extent(7)) {
1160 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1161 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1162 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1163 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1164 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1165 p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1166 typedef CommonSubview<DstType,SrcType,8,Kokkos::Impl::ALL_t,
1167 p_type,p_type,p_type,p_type,p_type,p_type,
1168 Kokkos::Impl::ALL_t> sv_adapter_type;
1169 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1170 ext1,ext2,ext3,ext4,ext5,ext6,
1172 view_copy(common_subview.dst_sub,common_subview.src_sub);
1174 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1175 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1176 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1177 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1178 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1179 p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1180 p_type ext7(0,std::min(dst.extent(7),src.extent(7)));
1181 typedef CommonSubview<DstType,SrcType,8,Kokkos::Impl::ALL_t,
1182 p_type,p_type,p_type,p_type,p_type,p_type,
1183 p_type> sv_adapter_type;
1184 sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1185 ext1,ext2,ext3,ext4,ext5,ext6,
1187 view_copy(common_subview.dst_sub,common_subview.src_sub);
1190 if(dst.extent(7) == src.extent(7)) {
1191 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1192 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1193 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1194 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1195 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1196 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1197 p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1198 typedef CommonSubview<DstType,SrcType,8,p_type,
1199 p_type,p_type,p_type,p_type,p_type,p_type,
1200 Kokkos::Impl::ALL_t> sv_adapter_type;
1201 sv_adapter_type common_subview(dst,src,ext0,
1202 ext1,ext2,ext3,ext4,ext5,ext6,
1204 view_copy(common_subview.dst_sub,common_subview.src_sub);
1206 p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1207 p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1208 p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1209 p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1210 p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1211 p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1212 p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1213 p_type ext7(0,std::min(dst.extent(7),src.extent(7)));
1214 typedef CommonSubview<DstType,SrcType,8,p_type,
1215 p_type,p_type,p_type,p_type,p_type,p_type,
1216 p_type> sv_adapter_type;
1217 sv_adapter_type common_subview(dst,src,ext0,
1218 ext1,ext2,ext3,ext4,ext5,ext6,
1220 view_copy(common_subview.dst_sub,common_subview.src_sub);
1229 template<
class DT ,
class ... DP >
1233 ,
typename ViewTraits<DT,DP...>::const_value_type & value
1234 ,
typename std::enable_if<
1235 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value
1238 typedef View<DT,DP...> ViewType;
1239 if(dst.data() == NULL ) {
1246 std::is_same<
typename ViewType::non_const_value_type ,
1247 typename ViewType::value_type >::value
1248 ,
"deep_copy requires non-const type" );
1251 if(dst.span_is_contiguous()) {
1253 Kokkos::Device<
typename ViewType::execution_space,
1254 typename std::conditional<ViewType::Rank==0,
1255 typename ViewType::memory_space,Kokkos::AnonymousSpace
1257 Kokkos::MemoryTraits<0> >
1260 ViewTypeFlat dst_flat(dst.data(),dst.size());
1261 if(dst.span() < std::numeric_limits<int>::max()) {
1262 Kokkos::Impl::ViewFill< ViewTypeFlat , Kokkos::LayoutRight, typename ViewType::execution_space, ViewTypeFlat::Rank, int >( dst_flat , value );
1264 Kokkos::Impl::ViewFill< ViewTypeFlat , Kokkos::LayoutRight, typename ViewType::execution_space, ViewTypeFlat::Rank, int64_t >( dst_flat , value );
1270 int64_t strides[ViewType::Rank+1];
1271 dst.stride(strides);
1272 Kokkos::Iterate iterate;
1273 if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutRight>::value ) {
1274 iterate = Kokkos::Iterate::Right;
1275 }
else if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutLeft>::value ) {
1276 iterate = Kokkos::Iterate::Left;
1277 }
else if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutStride>::value ) {
1278 if( strides[0] > strides[ViewType::Rank>0?ViewType::Rank-1:0] )
1279 iterate = Kokkos::Iterate::Right;
1281 iterate = Kokkos::Iterate::Left;
1283 if( std::is_same<typename ViewType::execution_space::array_layout, Kokkos::LayoutRight>::value )
1284 iterate = Kokkos::Iterate::Right;
1286 iterate = Kokkos::Iterate::Left;
1290 typedef typename std::conditional<ViewType::Rank==0,
1291 typename ViewType::uniform_runtime_type,
1292 typename ViewType::uniform_runtime_nomemspace_type>::type ViewTypeUniform;
1293 if(dst.span() > std::numeric_limits<int>::max()) {
1294 if(iterate == Kokkos::Iterate::Right)
1295 Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutRight, typename ViewType::execution_space, ViewType::Rank, int64_t >( dst , value );
1297 Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutLeft, typename ViewType::execution_space, ViewType::Rank, int64_t >( dst , value );
1299 if(iterate == Kokkos::Iterate::Right)
1300 Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutRight, typename ViewType::execution_space, ViewType::Rank, int >( dst , value );
1302 Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutLeft, typename ViewType::execution_space, ViewType::Rank, int >( dst , value );
1308 template<
class ST ,
class ... SP >
1311 (
typename ViewTraits<ST,SP...>::non_const_value_type & dst
1313 ,
typename std::enable_if<
1314 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value
1318 ,
"ERROR: Non-rank-zero view in deep_copy( value , View )" );
1320 if(src.data() == NULL) {
1326 typedef typename src_traits::memory_space src_memory_space ;
1327 Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() ,
sizeof(ST) );
1332 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
1337 ,
typename std::enable_if<(
1338 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1339 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1345 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1346 typename ViewTraits<ST,SP...>::non_const_value_type >::value
1347 ,
"deep_copy requires matching non-const destination type" );
1349 if(dst.data() == NULL && src.data() == NULL) {
1354 typedef View<DT,DP...> dst_type ;
1355 typedef View<ST,SP...> src_type ;
1357 typedef typename dst_type::value_type value_type ;
1358 typedef typename dst_type::memory_space dst_memory_space ;
1359 typedef typename src_type::memory_space src_memory_space ;
1362 if ( dst.data() != src.data() ) {
1363 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() ,
sizeof(value_type) );
1372 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
1377 ,
typename std::enable_if<(
1378 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1379 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1384 typedef View<DT,DP...> dst_type ;
1385 typedef View<ST,SP...> src_type ;
1388 std::is_same<
typename dst_type::value_type ,
1389 typename dst_type::non_const_value_type >::value
1390 ,
"deep_copy requires non-const destination type" );
1393 (
unsigned(dst_type::rank) ==
1394 unsigned(src_type::rank) )
1395 ,
"deep_copy requires Views of equal rank" );
1398 typedef typename dst_type::execution_space dst_execution_space ;
1399 typedef typename src_type::execution_space src_execution_space ;
1400 typedef typename dst_type::memory_space dst_memory_space ;
1401 typedef typename src_type::memory_space src_memory_space ;
1402 typedef typename dst_type::value_type dst_value_type ;
1403 typedef typename src_type::value_type src_value_type ;
1404 if(dst.data() == NULL || src.data() == NULL) {
1405 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1418 std::string message(
"Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1419 message += dst.label(); message +=
"(";
1420 for(
int r = 0; r<dst_type::Rank-1; r++)
1421 { message+= std::to_string(dst.
extent(r)); message +=
","; }
1422 message+= std::to_string(dst.
extent(dst_type::Rank-1)); message +=
") ";
1423 message += src.label(); message +=
"(";
1424 for(
int r = 0; r<src_type::Rank-1; r++)
1425 { message+= std::to_string(src.
extent(r)); message +=
","; }
1426 message+= std::to_string(src.
extent(src_type::Rank-1)); message +=
") ";
1428 Kokkos::Impl::throw_runtime_exception(message);
1435 enum { DstExecCanAccessSrc =
1438 enum { SrcExecCanAccessDst =
1442 dst_value_type* dst_start = dst.data();
1443 dst_value_type* dst_end = dst.data() + dst.span();
1444 src_value_type* src_start = src.data();
1445 src_value_type* src_end = src.data() + src.span();
1446 if( ((std::ptrdiff_t)dst_start == (std::ptrdiff_t)src_start) &&
1447 ((std::ptrdiff_t)dst_end == (std::ptrdiff_t)src_end) &&
1448 (dst.span_is_contiguous() && src.span_is_contiguous()) ) {
1453 if( ( ( (std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end ) && ( (std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start ) ) &&
1454 ( ( dst.span_is_contiguous() && src.span_is_contiguous() ))) {
1455 std::string message(
"Error: Kokkos::deep_copy of overlapping views: ");
1456 message += dst.label(); message +=
"(";
1457 message += std::to_string((std::ptrdiff_t)dst_start); message +=
",";
1458 message += std::to_string((std::ptrdiff_t)dst_end); message +=
") ";
1459 message += src.label(); message +=
"(";
1460 message += std::to_string((std::ptrdiff_t)src_start); message +=
",";
1461 message += std::to_string((std::ptrdiff_t)src_end); message +=
") ";
1462 Kokkos::Impl::throw_runtime_exception(message);
1475 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1477 if ( DstExecCanAccessSrc ) {
1479 Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1481 else if ( SrcExecCanAccessDst ) {
1483 Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1486 Kokkos::Impl::throw_runtime_exception(
"deep_copy given views that would require a temporary allocation");
1491 std::string message(
"Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1492 message += dst.label(); message +=
"(";
1493 for(
int r = 0; r<dst_type::Rank-1; r++)
1494 { message+= std::to_string(dst.
extent(r)); message +=
","; }
1495 message+= std::to_string(dst.
extent(dst_type::Rank-1)); message +=
") ";
1496 message += src.label(); message +=
"(";
1497 for(
int r = 0; r<src_type::Rank-1; r++)
1498 { message+= std::to_string(src.
extent(r)); message +=
","; }
1499 message+= std::to_string(src.
extent(src_type::Rank-1)); message +=
") ";
1501 Kokkos::Impl::throw_runtime_exception(message);
1507 if ( std::is_same<
typename dst_type::value_type ,
1508 typename src_type::non_const_value_type >::value &&
1510 std::is_same<
typename dst_type::array_layout ,
1511 typename src_type::array_layout >::value
1513 ( dst_type::rank == 1 &&
1514 src_type::rank == 1 )
1516 dst.span_is_contiguous() &&
1517 src.span_is_contiguous() &&
1518 ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1519 ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1520 ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1521 ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1522 ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1523 ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1524 ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1525 ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))
1527 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1529 if((
void*)dst.data()!=(
void*)src.data()) {
1530 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >
1531 ( dst.data() , src.data() , nbytes );
1536 Impl::view_copy(dst, src);
1549 template<
class ExecSpace ,
class DT ,
class ... DP >
1554 ,
typename ViewTraits<DT,DP...>::const_value_type & value
1555 ,
typename std::enable_if<
1556 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1557 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value
1561 std::is_same<
typename ViewTraits<DT,DP...>::non_const_value_type ,
1562 typename ViewTraits<DT,DP...>::value_type >::value
1563 ,
"deep_copy requires non-const type" );
1566 typedef typename View<DT,DP...>::uniform_runtime_nomemspace_type ViewTypeUniform;
1567 Kokkos::Impl::ViewFill< ViewTypeUniform >( dst , value );
1572 template<
class ExecSpace ,
class ST ,
class ... SP >
1575 (
const ExecSpace & exec_space
1576 ,
typename ViewTraits<ST,SP...>::non_const_value_type & dst
1578 ,
typename std::enable_if<
1579 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1580 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value
1584 ,
"ERROR: Non-rank-zero view in deep_copy( value , View )" );
1586 if(src.data() == NULL) {
1592 typedef typename src_traits::memory_space src_memory_space ;
1593 Kokkos::Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >
1594 ( exec_space , & dst , src.data() ,
sizeof(ST) );
1599 template<
class ExecSpace ,
class DT ,
class ... DP ,
class ST ,
class ... SP >
1602 (
const ExecSpace & exec_space
1605 ,
typename std::enable_if<(
1606 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1607 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1608 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1614 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1615 typename ViewTraits<ST,SP...>::non_const_value_type >::value
1616 ,
"deep_copy requires matching non-const destination type" );
1618 typedef View<DT,DP...> dst_type ;
1619 typedef View<ST,SP...> src_type ;
1621 typedef typename dst_type::value_type value_type ;
1622 typedef typename dst_type::memory_space dst_memory_space ;
1623 typedef typename src_type::memory_space src_memory_space ;
1624 if(dst.data() == NULL && src.data() == NULL) {
1630 if ( dst.data() != src.data() ) {
1631 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1632 ( exec_space , dst.data() , src.data() ,
sizeof(value_type) );
1641 template<
class ExecSpace ,
class DT,
class ... DP,
class ST,
class ... SP >
1644 (
const ExecSpace & exec_space
1647 ,
typename std::enable_if<(
1648 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1649 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1650 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1655 typedef View<DT,DP...> dst_type ;
1656 typedef View<ST,SP...> src_type ;
1659 std::is_same<
typename dst_type::value_type ,
1660 typename dst_type::non_const_value_type >::value
1661 ,
"deep_copy requires non-const destination type" );
1664 (
unsigned(dst_type::rank) ==
1665 unsigned(src_type::rank) )
1666 ,
"deep_copy requires Views of equal rank" );
1668 typedef typename dst_type::execution_space dst_execution_space ;
1669 typedef typename src_type::execution_space src_execution_space ;
1670 typedef typename dst_type::memory_space dst_memory_space ;
1671 typedef typename src_type::memory_space src_memory_space ;
1672 typedef typename dst_type::value_type dst_value_type ;
1673 typedef typename src_type::value_type src_value_type ;
1675 if(dst.data() == NULL || src.data() == NULL) {
1676 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1689 std::string message(
"Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1690 message += dst.label(); message +=
"(";
1691 for(
int r = 0; r<dst_type::Rank-1; r++)
1692 { message+= std::to_string(dst.
extent(r)); message +=
","; }
1693 message+= std::to_string(dst.
extent(dst_type::Rank-1)); message +=
") ";
1694 message += src.label(); message +=
"(";
1695 for(
int r = 0; r<src_type::Rank-1; r++)
1696 { message+= std::to_string(src.
extent(r)); message +=
","; }
1697 message+= std::to_string(src.
extent(src_type::Rank-1)); message +=
") ";
1699 Kokkos::Impl::throw_runtime_exception(message);
1706 enum { ExecCanAccessSrcDst =
1710 enum { DstExecCanAccessSrc =
1713 enum { SrcExecCanAccessDst =
1717 dst_value_type* dst_start = dst.data();
1718 dst_value_type* dst_end = dst.data() + dst.span();
1719 src_value_type* src_start = src.data();
1720 src_value_type* src_end = src.data() + src.span();
1721 if( ( ( (std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end ) && ( (std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start ) ) &&
1722 ( ( dst.span_is_contiguous() && src.span_is_contiguous() ))) {
1723 std::string message(
"Error: Kokkos::deep_copy of overlapping views: ");
1724 message += dst.label(); message +=
"(";
1725 message += std::to_string((std::ptrdiff_t)dst_start); message +=
",";
1726 message += std::to_string((std::ptrdiff_t)dst_end); message +=
") ";
1727 message += src.label(); message +=
"(";
1728 message += std::to_string((std::ptrdiff_t)src_start); message +=
",";
1729 message += std::to_string((std::ptrdiff_t)src_end); message +=
") ";
1730 Kokkos::Impl::throw_runtime_exception(message);
1743 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1745 if ( ExecCanAccessSrcDst ) {
1746 Kokkos::Impl::ViewRemap< dst_type , src_type , ExecSpace >( dst , src );
1748 else if ( DstExecCanAccessSrc ) {
1750 Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1752 else if ( SrcExecCanAccessDst ) {
1754 Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1757 Kokkos::Impl::throw_runtime_exception(
"deep_copy given views that would require a temporary allocation");
1762 std::string message(
"Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1763 message += dst.label(); message +=
"(";
1764 for(
int r = 0; r<dst_type::Rank-1; r++)
1765 { message+= std::to_string(dst.
extent(r)); message +=
","; }
1766 message+= std::to_string(dst.
extent(dst_type::Rank-1)); message +=
") ";
1767 message += src.label(); message +=
"(";
1768 for(
int r = 0; r<src_type::Rank-1; r++)
1769 { message+= std::to_string(src.
extent(r)); message +=
","; }
1770 message+= std::to_string(src.
extent(src_type::Rank-1)); message +=
") ";
1772 Kokkos::Impl::throw_runtime_exception(message);
1778 if ( std::is_same<
typename dst_type::value_type ,
1779 typename src_type::non_const_value_type >::value &&
1781 std::is_same<
typename dst_type::array_layout ,
1782 typename src_type::array_layout >::value
1784 ( dst_type::rank == 1 &&
1785 src_type::rank == 1 )
1787 dst.span_is_contiguous() &&
1788 src.span_is_contiguous() &&
1789 ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1790 ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1791 ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1792 ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1793 ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1794 ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1795 ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1796 ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))
1799 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1801 if((
void*)dst.data() != (
void*)src.data()) {
1802 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1803 ( exec_space , dst.data() , src.data() , nbytes );
1808 Impl::view_copy(dst, src);
1821 template<
class T ,
class ... P >
1823 typename std::enable_if<
1828 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1829 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1830 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1831 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1832 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1833 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1834 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1835 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
1846 if (view_type::Rank == 1 &&
1847 n0 == static_cast<size_t> (v.
extent(0))) {
1850 if (view_type::Rank == 2 &&
1851 n0 == static_cast<size_t> (v.
extent(0)) &&
1852 n1 == static_cast<size_t> (v.
extent(1))) {
1855 if (view_type::Rank == 3 &&
1856 n0 == static_cast<size_t> (v.
extent(0)) &&
1857 n1 == static_cast<size_t> (v.
extent(1)) &&
1858 n2 == static_cast<size_t> (v.
extent(2))) {
1861 if (view_type::Rank == 4 &&
1862 n0 == static_cast<size_t> (v.
extent(0)) &&
1863 n1 == static_cast<size_t> (v.
extent(1)) &&
1864 n2 == static_cast<size_t> (v.
extent(2)) &&
1865 n3 == static_cast<size_t> (v.
extent(3))) {
1868 if (view_type::Rank == 5 &&
1869 n0 == static_cast<size_t> (v.
extent(0)) &&
1870 n1 == static_cast<size_t> (v.
extent(1)) &&
1871 n2 == static_cast<size_t> (v.
extent(2)) &&
1872 n3 == static_cast<size_t> (v.
extent(3)) &&
1873 n4 == static_cast<size_t> (v.
extent(4))) {
1876 if (view_type::Rank == 6 &&
1877 n0 == static_cast<size_t> (v.
extent(0)) &&
1878 n1 == static_cast<size_t> (v.
extent(1)) &&
1879 n2 == static_cast<size_t> (v.
extent(2)) &&
1880 n3 == static_cast<size_t> (v.
extent(3)) &&
1881 n4 == static_cast<size_t> (v.
extent(4)) &&
1882 n5 == static_cast<size_t> (v.
extent(5))) {
1885 if (view_type::Rank == 7 &&
1886 n0 == static_cast<size_t> (v.
extent(0)) &&
1887 n1 == static_cast<size_t> (v.
extent(1)) &&
1888 n2 == static_cast<size_t> (v.
extent(2)) &&
1889 n3 == static_cast<size_t> (v.
extent(3)) &&
1890 n4 == static_cast<size_t> (v.
extent(4)) &&
1891 n5 == static_cast<size_t> (v.
extent(5)) &&
1892 n6 == static_cast<size_t> (v.
extent(6))) {
1895 if (view_type::Rank == 8 &&
1896 n0 == static_cast<size_t> (v.
extent(0)) &&
1897 n1 == static_cast<size_t> (v.
extent(1)) &&
1898 n2 == static_cast<size_t> (v.
extent(2)) &&
1899 n3 == static_cast<size_t> (v.
extent(3)) &&
1900 n4 == static_cast<size_t> (v.
extent(4)) &&
1901 n5 == static_cast<size_t> (v.
extent(5)) &&
1902 n6 == static_cast<size_t> (v.
extent(6)) &&
1903 n7 == static_cast<size_t> (v.
extent(7))) {
1917 view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
1919 Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
1925 template<
class T ,
class ... P >
1928 const typename Kokkos::View<T,P...>::array_layout & layout)
1934 view_type v_resized( v.label(), layout );
1936 Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
1942 template<
class T ,
class ... P >
1944 typename std::enable_if<
1949 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1950 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1951 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1952 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1953 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1954 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1955 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1956 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
1962 const std::string label = v.label();
1965 v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
1969 template<
class T ,
class ... P >
1972 const typename Kokkos::View<T,P...>::array_layout & layout)
1978 const std::string label = v.label();
1981 v = view_type( label, layout );
1992 template<
class Space,
class T,
class ... P>
1993 struct MirrorViewType {
1997 typedef typename Space::memory_space memory_space;
1999 enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2001 typedef typename src_view_type::array_layout array_layout;
2003 typedef typename src_view_type::non_const_data_type data_type;
2008 typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
2011 template<
class Space,
class T,
class ... P>
2016 typedef typename Space::memory_space memory_space;
2018 enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2020 typedef typename src_view_type::array_layout array_layout;
2022 typedef typename src_view_type::non_const_data_type data_type;
2029 template<
class T ,
class ... P >
2033 ,
typename std::enable_if<
2034 std::is_same<
typename ViewTraits<T,P...>::specialize ,
void >::value &&
2035 ! std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
2040 typedef View<T,P...> src_type ;
2041 typedef typename src_type::HostMirror dst_type ;
2043 return dst_type( std::string( src.label() ).append(
"_mirror")
2044 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
2054 , src.rank_dynamic > 0 ? src.
extent(0): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2055 , src.rank_dynamic > 1 ? src.
extent(1): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2056 , src.rank_dynamic > 2 ? src.
extent(2): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2057 , src.rank_dynamic > 3 ? src.
extent(3): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2058 , src.rank_dynamic > 4 ? src.
extent(4): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2059 , src.rank_dynamic > 5 ? src.
extent(5): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2060 , src.rank_dynamic > 6 ? src.
extent(6): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2061 , src.rank_dynamic > 7 ? src.
extent(7): KOKKOS_IMPL_CTOR_DEFAULT_ARG );
2065 template<
class T ,
class ... P >
2069 ,
typename std::enable_if<
2070 std::is_same<
typename ViewTraits<T,P...>::specialize ,
void >::value &&
2071 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
2076 typedef View<T,P...> src_type ;
2077 typedef typename src_type::HostMirror dst_type ;
2081 layout.dimension[0] = src.
extent(0);
2082 layout.dimension[1] = src.
extent(1);
2083 layout.dimension[2] = src.
extent(2);
2084 layout.dimension[3] = src.
extent(3);
2085 layout.dimension[4] = src.
extent(4);
2086 layout.dimension[5] = src.
extent(5);
2087 layout.dimension[6] = src.
extent(6);
2088 layout.dimension[7] = src.
extent(7);
2090 layout.stride[0] = src.stride_0();
2091 layout.stride[1] = src.stride_1();
2092 layout.stride[2] = src.stride_2();
2093 layout.stride[3] = src.stride_3();
2094 layout.stride[4] = src.stride_4();
2095 layout.stride[5] = src.stride_5();
2096 layout.stride[6] = src.stride_6();
2097 layout.stride[7] = src.stride_7();
2099 return dst_type( std::string( src.label() ).append(
"_mirror") , layout );
2104 template<
class Space,
class T,
class ... P>
2105 typename Impl::MirrorType<Space,T,P ...>::view_type
2107 ,
typename std::enable_if<
2108 std::is_same<
typename ViewTraits<T,P...>::specialize ,
void >::value
2110 return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),src.layout());
2113 template<
class T ,
class ... P >
2117 ,
typename std::enable_if<(
2118 std::is_same<
typename Kokkos::View<T,P...>::memory_space
2119 ,
typename Kokkos::View<T,P...>::HostMirror::memory_space
2122 std::is_same<
typename Kokkos::View<T,P...>::data_type
2123 ,
typename Kokkos::View<T,P...>::HostMirror::data_type
2131 template<
class T ,
class ... P >
2135 ,
typename std::enable_if< ! (
2136 std::is_same<
typename Kokkos::View<T,P...>::memory_space
2137 ,
typename Kokkos::View<T,P...>::HostMirror::memory_space
2140 std::is_same<
typename Kokkos::View<T,P...>::data_type
2141 ,
typename Kokkos::View<T,P...>::HostMirror::data_type
2146 return Kokkos::create_mirror( src );
2150 template<
class Space,
class T,
class ... P>
2151 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2153 ,
typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2158 template<
class Space,
class T,
class ... P>
2159 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2161 ,
typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2162 return typename Impl::MirrorViewType<Space,T,P ...>::view_type(src.label(),src.layout());
2166 template<
class Space,
class T,
class ... P>
2167 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2169 , std::string
const& name =
""
2170 ,
typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2176 template<
class Space,
class T,
class ... P>
2177 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2179 , std::string
const& name =
""
2180 ,
typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2181 using Mirror =
typename Impl::MirrorViewType<Space,T,P ...>::view_type;
2182 std::string label = name.empty() ? src.label() : name;
2183 auto mirror = Mirror(ViewAllocateWithoutInitializing(label), src.layout());
void parallel_for(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename Impl::enable_if< Kokkos::Impl::is_execution_policy< ExecPolicy >::value >::type *=0)
Execute functor in parallel according to the execution policy.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
Can AccessSpace access MemorySpace ?
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.
Replacement for std::pair that works on CUDA devices.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
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 *=0)
Deep copy a value from Host memory into a view.
View to an array of data.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-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.
Execution policy for work over a range of an integral type.
Traits class for accessing attributes of a View.
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