Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_CopyViews.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 3.0
6 // Copyright (2020) National Technology & Engineering
7 // Solutions of Sandia, LLC (NTESS).
8 //
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40 //
41 // ************************************************************************
42 //@HEADER
43 */
44 
45 #ifndef KOKKOS_COPYVIEWS_HPP_
46 #define KOKKOS_COPYVIEWS_HPP_
47 #include <string>
48 
49 //----------------------------------------------------------------------------
50 //----------------------------------------------------------------------------
51 
52 #ifndef KOKKOS_IMPL_COMPILING_LIBRARY
53 #define KOKKOS_IMPL_COMPILING_LIBRARY false
54 #endif
55 
56 namespace Kokkos {
57 
58 namespace Impl {
59 
60 template <class Layout>
61 struct ViewFillLayoutSelector {};
62 
63 template <>
64 struct ViewFillLayoutSelector<Kokkos::LayoutLeft> {
65  static const Kokkos::Iterate iterate = Kokkos::Iterate::Left;
66 };
67 
68 template <>
69 struct ViewFillLayoutSelector<Kokkos::LayoutRight> {
70  static const Kokkos::Iterate iterate = Kokkos::Iterate::Right;
71 };
72 
73 } // namespace Impl
74 } // namespace Kokkos
75 
76 #include <impl/Kokkos_ViewFillCopyETIAvail.hpp>
77 
78 namespace Kokkos {
79 namespace Impl {
80 
81 template <class ViewType, class Layout, class ExecSpace, typename iType,
82  bool ETIAvail>
83 struct ViewFill<ViewType, Layout, ExecSpace, 0, iType, ETIAvail> {
84  ViewType a;
85  typename ViewType::const_value_type val;
86  typedef typename ViewType::non_const_value_type ST;
87  ViewFill(const ViewType&, const ST&, const ExecSpace&);
88 };
89 
90 template <class ViewType, class Layout, class ExecSpace, typename iType,
91  bool ETIAvail>
92 struct ViewFill<ViewType, Layout, ExecSpace, 1, iType, ETIAvail> {
93  ViewType a;
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;
99 };
100 
101 template <class ViewType, class Layout, class ExecSpace, typename iType,
102  bool ETIAvail>
103 struct ViewFill<ViewType, Layout, ExecSpace, 2, iType, ETIAvail> {
104  ViewType a;
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;
110 };
111 
112 template <class ViewType, class Layout, class ExecSpace, typename iType,
113  bool ETIAvail>
114 struct ViewFill<ViewType, Layout, ExecSpace, 3, iType, ETIAvail> {
115  ViewType a;
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;
121 };
122 
123 template <class ViewType, class Layout, class ExecSpace, typename iType,
124  bool ETIAvail>
125 struct ViewFill<ViewType, Layout, ExecSpace, 4, iType, ETIAvail> {
126  ViewType a;
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;
132 };
133 
134 template <class ViewType, class Layout, class ExecSpace, typename iType,
135  bool ETIAvail>
136 struct ViewFill<ViewType, Layout, ExecSpace, 5, iType, ETIAvail> {
137  ViewType a;
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&,
143  const iType&) const;
144 };
145 
146 template <class ViewType, class Layout, class ExecSpace, typename iType,
147  bool ETIAvail>
148 struct ViewFill<ViewType, Layout, ExecSpace, 6, iType, ETIAvail> {
149  ViewType a;
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;
156 };
157 
158 template <class ViewType, class Layout, class ExecSpace, typename iType,
159  bool ETIAvail>
160 struct ViewFill<ViewType, Layout, ExecSpace, 7, iType, ETIAvail> {
161  ViewType a;
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;
168 };
169 
170 template <class ViewType, class Layout, class ExecSpace, typename iType,
171  bool ETIAvail>
172 struct ViewFill<ViewType, Layout, ExecSpace, 8, iType, ETIAvail> {
173  ViewType a;
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;
180 };
181 
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) {
187  Kokkos::Impl::DeepCopy<typename ViewType::memory_space, Kokkos::HostSpace,
188  ExecSpace>(space, a.data(), &val, sizeof(ST));
189  }
190 };
191 
192 template <class ViewType, class Layout, class ExecSpace, typename iType>
193 struct ViewFill<ViewType, Layout, ExecSpace, 1, iType,
194  KOKKOS_IMPL_COMPILING_LIBRARY> {
195  ViewType a;
196  typename ViewType::const_value_type val;
198 
199  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
200  const ExecSpace& space)
201  : a(a_), val(val_) {
202  Kokkos::parallel_for("Kokkos::ViewFill-1D",
203  policy_type(space, 0, a.extent(0)), *this);
204  }
205 
206  KOKKOS_INLINE_FUNCTION
207  void operator()(const iType& i) const { a(i) = val; };
208 };
209 
210 template <class ViewType, class Layout, class ExecSpace, typename iType>
211 struct ViewFill<ViewType, Layout, ExecSpace, 2, iType,
212  KOKKOS_IMPL_COMPILING_LIBRARY> {
213  ViewType a;
214  typename ViewType::const_value_type val;
215 
216  typedef Kokkos::Rank<2, ViewFillLayoutSelector<Layout>::iterate,
217  ViewFillLayoutSelector<Layout>::iterate>
218  iterate_type;
219  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
220  Kokkos::IndexType<iType>>
221  policy_type;
222 
223  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
224  const ExecSpace& space)
225  : a(a_), val(val_) {
226  Kokkos::parallel_for("Kokkos::ViewFill-2D",
227  policy_type(space, {0, 0}, {a.extent(0), a.extent(1)}),
228  *this);
229  }
230 
231  KOKKOS_INLINE_FUNCTION
232  void operator()(const iType& i0, const iType& i1) const { a(i0, i1) = val; };
233 };
234 
235 template <class ViewType, class Layout, class ExecSpace, typename iType>
236 struct ViewFill<ViewType, Layout, ExecSpace, 3, iType,
237  KOKKOS_IMPL_COMPILING_LIBRARY> {
238  ViewType a;
239  typename ViewType::const_value_type val;
240 
241  typedef Kokkos::Rank<3, ViewFillLayoutSelector<Layout>::iterate,
242  ViewFillLayoutSelector<Layout>::iterate>
243  iterate_type;
244  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
245  Kokkos::IndexType<iType>>
246  policy_type;
247 
248  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
249  const ExecSpace& space)
250  : a(a_), val(val_) {
252  "Kokkos::ViewFill-3D",
253  policy_type(space, {0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2)}),
254  *this);
255  }
256 
257  KOKKOS_INLINE_FUNCTION
258  void operator()(const iType& i0, const iType& i1, const iType& i2) const {
259  a(i0, i1, i2) = val;
260  };
261 };
262 
263 template <class ViewType, class Layout, class ExecSpace, typename iType>
264 struct ViewFill<ViewType, Layout, ExecSpace, 4, iType,
265  KOKKOS_IMPL_COMPILING_LIBRARY> {
266  ViewType a;
267  typename ViewType::const_value_type val;
268 
269  typedef Kokkos::Rank<4, ViewFillLayoutSelector<Layout>::iterate,
270  ViewFillLayoutSelector<Layout>::iterate>
271  iterate_type;
272  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
273  Kokkos::IndexType<iType>>
274  policy_type;
275 
276  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
277  const ExecSpace& space)
278  : a(a_), val(val_) {
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)}),
283  *this);
284  }
285 
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;
290  };
291 };
292 
293 template <class ViewType, class Layout, class ExecSpace, typename iType>
294 struct ViewFill<ViewType, Layout, ExecSpace, 5, iType,
295  KOKKOS_IMPL_COMPILING_LIBRARY> {
296  ViewType a;
297  typename ViewType::const_value_type val;
298 
299  typedef Kokkos::Rank<5, ViewFillLayoutSelector<Layout>::iterate,
300  ViewFillLayoutSelector<Layout>::iterate>
301  iterate_type;
302  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
303  Kokkos::IndexType<iType>>
304  policy_type;
305 
306  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
307  const ExecSpace& space)
308  : a(a_), val(val_) {
309  Kokkos::parallel_for("Kokkos::ViewFill-5D",
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)}),
313  *this);
314  }
315 
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;
320  };
321 };
322 
323 template <class ViewType, class Layout, class ExecSpace, typename iType>
324 struct ViewFill<ViewType, Layout, ExecSpace, 6, iType,
325  KOKKOS_IMPL_COMPILING_LIBRARY> {
326  ViewType a;
327  typename ViewType::const_value_type val;
328 
329  typedef Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
330  ViewFillLayoutSelector<Layout>::iterate>
331  iterate_type;
332  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
333  Kokkos::IndexType<iType>>
334  policy_type;
335 
336  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
337  const ExecSpace& space)
338  : a(a_), val(val_) {
339  Kokkos::parallel_for("Kokkos::ViewFill-6D",
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)}),
343  *this);
344  }
345 
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;
350  };
351 };
352 
353 template <class ViewType, class Layout, class ExecSpace, typename iType>
354 struct ViewFill<ViewType, Layout, ExecSpace, 7, iType,
355  KOKKOS_IMPL_COMPILING_LIBRARY> {
356  ViewType a;
357  typename ViewType::const_value_type val;
358 
359  typedef Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
360  ViewFillLayoutSelector<Layout>::iterate>
361  iterate_type;
362  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
363  Kokkos::IndexType<iType>>
364  policy_type;
365 
366  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
367  const ExecSpace& space)
368  : a(a_), val(val_) {
369  Kokkos::parallel_for("Kokkos::ViewFill-7D",
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)}),
373  *this);
374  }
375 
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;
381  };
382 };
383 
384 template <class ViewType, class Layout, class ExecSpace, typename iType>
385 struct ViewFill<ViewType, Layout, ExecSpace, 8, iType,
386  KOKKOS_IMPL_COMPILING_LIBRARY> {
387  ViewType a;
388  typename ViewType::const_value_type val;
389 
390  typedef Kokkos::Rank<6, ViewFillLayoutSelector<Layout>::iterate,
391  ViewFillLayoutSelector<Layout>::iterate>
392  iterate_type;
393  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
394  Kokkos::IndexType<iType>>
395  policy_type;
396 
397  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_,
398  const ExecSpace& space)
399  : a(a_), val(val_) {
400  Kokkos::parallel_for("Kokkos::ViewFill-8D",
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)}),
404  *this);
405  }
406 
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;
413  };
414 };
415 
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> {
419  ViewTypeA a;
420  ViewTypeB b;
421  ViewCopy(const ViewTypeA&, const ViewTypeB&, const ExecSpace&);
422  KOKKOS_INLINE_FUNCTION
423  void operator()(const iType& i0) const;
424 };
425 
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> {
429  ViewTypeA a;
430  ViewTypeB b;
431  ViewCopy(const ViewTypeA&, const ViewTypeB&, const ExecSpace&);
432  KOKKOS_INLINE_FUNCTION
433  void operator()(const iType& i0, const iType& i1) const;
434 };
435 
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> {
439  ViewTypeA a;
440  ViewTypeB b;
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;
444 };
445 
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> {
449  ViewTypeA a;
450  ViewTypeB b;
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;
455 };
456 
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> {
460  ViewTypeA a;
461  ViewTypeB b;
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;
466 };
467 
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> {
471  ViewTypeA a;
472  ViewTypeB b;
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;
477 };
478 
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> {
482  ViewTypeA a;
483  ViewTypeB b;
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;
489 };
490 
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> {
494  ViewTypeA a;
495  ViewTypeB b;
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;
501 };
502 
503 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
504  typename iType>
505 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 1, iType,
506  KOKKOS_IMPL_COMPILING_LIBRARY> {
507  ViewTypeA a;
508  ViewTypeB b;
509 
511 
512  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
513  const ExecSpace space = ExecSpace())
514  : a(a_), b(b_) {
515  Kokkos::parallel_for("Kokkos::ViewCopy-1D",
516  policy_type(space, 0, a.extent(0)), *this);
517  }
518 
519  KOKKOS_INLINE_FUNCTION
520  void operator()(const iType& i0) const { a(i0) = b(i0); };
521 };
522 
523 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
524  typename iType>
525 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 2, iType,
526  KOKKOS_IMPL_COMPILING_LIBRARY> {
527  ViewTypeA a;
528  ViewTypeB b;
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>
534  iterate_type;
535  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
536  Kokkos::IndexType<iType>>
537  policy_type;
538 
539  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
540  const ExecSpace space = ExecSpace())
541  : a(a_), b(b_) {
542  Kokkos::parallel_for("Kokkos::ViewCopy-2D",
543  policy_type(space, {0, 0}, {a.extent(0), a.extent(1)}),
544  *this);
545  }
546 
547  KOKKOS_INLINE_FUNCTION
548  void operator()(const iType& i0, const iType& i1) const {
549  a(i0, i1) = b(i0, i1);
550  };
551 };
552 
553 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
554  typename iType>
555 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 3, iType,
556  KOKKOS_IMPL_COMPILING_LIBRARY> {
557  ViewTypeA a;
558  ViewTypeB b;
559 
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>
565  iterate_type;
566  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
567  Kokkos::IndexType<iType>>
568  policy_type;
569 
570  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
571  const ExecSpace space = ExecSpace())
572  : a(a_), b(b_) {
574  "Kokkos::ViewCopy-3D",
575  policy_type(space, {0, 0, 0}, {a.extent(0), a.extent(1), a.extent(2)}),
576  *this);
577  }
578 
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);
582  };
583 };
584 
585 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
586  typename iType>
587 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 4, iType,
588  KOKKOS_IMPL_COMPILING_LIBRARY> {
589  ViewTypeA a;
590  ViewTypeB b;
591 
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>
597  iterate_type;
598  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
599  Kokkos::IndexType<iType>>
600  policy_type;
601 
602  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
603  const ExecSpace space = ExecSpace())
604  : a(a_), b(b_) {
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)}),
609  *this);
610  }
611 
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);
616  };
617 };
618 
619 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
620  typename iType>
621 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 5, iType,
622  KOKKOS_IMPL_COMPILING_LIBRARY> {
623  ViewTypeA a;
624  ViewTypeB b;
625 
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>
631  iterate_type;
632  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
633  Kokkos::IndexType<iType>>
634  policy_type;
635 
636  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
637  const ExecSpace space = ExecSpace())
638  : a(a_), b(b_) {
639  Kokkos::parallel_for("Kokkos::ViewCopy-5D",
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)}),
643  *this);
644  }
645 
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);
650  };
651 };
652 
653 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
654  typename iType>
655 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 6, iType,
656  KOKKOS_IMPL_COMPILING_LIBRARY> {
657  ViewTypeA a;
658  ViewTypeB b;
659 
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>
665  iterate_type;
666  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
667  Kokkos::IndexType<iType>>
668  policy_type;
669 
670  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
671  const ExecSpace space = ExecSpace())
672  : a(a_), b(b_) {
673  Kokkos::parallel_for("Kokkos::ViewCopy-6D",
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)}),
677  *this);
678  }
679 
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);
684  };
685 };
686 
687 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
688  typename iType>
689 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 7, iType,
690  KOKKOS_IMPL_COMPILING_LIBRARY> {
691  ViewTypeA a;
692  ViewTypeB b;
693 
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>
699  iterate_type;
700  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
701  Kokkos::IndexType<iType>>
702  policy_type;
703 
704  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
705  const ExecSpace space = ExecSpace())
706  : a(a_), b(b_) {
707  Kokkos::parallel_for("Kokkos::ViewCopy-7D",
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)}),
711  *this);
712  }
713 
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);
719  };
720 };
721 
722 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
723  typename iType>
724 struct ViewCopy<ViewTypeA, ViewTypeB, Layout, ExecSpace, 8, iType,
725  KOKKOS_IMPL_COMPILING_LIBRARY> {
726  ViewTypeA a;
727  ViewTypeB b;
728 
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>
734  iterate_type;
735  typedef Kokkos::MDRangePolicy<ExecSpace, iterate_type,
736  Kokkos::IndexType<iType>>
737  policy_type;
738 
739  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_,
740  const ExecSpace space = ExecSpace())
741  : a(a_), b(b_) {
742  Kokkos::parallel_for("Kokkos::ViewCopy-8D",
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)}),
746  *this);
747  }
748 
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);
755  };
756 };
757 
758 } // namespace Impl
759 } // namespace Kokkos
760 
761 #include <impl/Kokkos_ViewFillCopyETIDecl.hpp>
762 
763 namespace Kokkos {
764 namespace Impl {
765 
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;
771 
772  enum {
773  ExecCanAccessSrc =
774  Kokkos::Impl::SpaceAccessibility<ExecutionSpace,
775  src_memory_space>::accessible
776  };
777  enum {
778  ExecCanAccessDst =
779  Kokkos::Impl::SpaceAccessibility<ExecutionSpace,
780  dst_memory_space>::accessible
781  };
782 
783  if (!(ExecCanAccessSrc && ExecCanAccessDst)) {
784  Kokkos::Impl::throw_runtime_exception(
785  "Kokkos::Impl::view_copy called with invalid execution space");
786  } else {
787  // Figure out iteration order in case we need it
788  int64_t strides[DstType::Rank + 1];
789  dst.stride(strides);
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,
795  Kokkos::LayoutRight>::value) {
796  iterate = Kokkos::Iterate::Right;
797  } else if (std::is_same<typename DstType::array_layout,
798  Kokkos::LayoutLeft>::value) {
799  iterate = Kokkos::Iterate::Left;
800  } else if (std::is_same<typename DstType::array_layout,
801  Kokkos::LayoutStride>::value) {
802  if (strides[0] > strides[DstType::Rank - 1])
803  iterate = Kokkos::Iterate::Right;
804  else
805  iterate = Kokkos::Iterate::Left;
806  } else {
807  if (std::is_same<typename DstType::execution_space::array_layout,
808  Kokkos::LayoutRight>::value)
809  iterate = Kokkos::Iterate::Right;
810  else
811  iterate = Kokkos::Iterate::Left;
812  }
813 
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,
820  Kokkos::LayoutRight, ExecutionSpace, DstType::Rank, int64_t>(
821  dst, src, space);
822  else
823  Kokkos::Impl::ViewCopy<
824  typename DstType::uniform_runtime_nomemspace_type,
825  typename SrcType::uniform_runtime_const_nomemspace_type,
826  Kokkos::LayoutLeft, ExecutionSpace, DstType::Rank, int64_t>(
827  dst, src, space);
828  } else {
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,
833  Kokkos::LayoutRight, ExecutionSpace, DstType::Rank, int>(dst, src,
834  space);
835  else
836  Kokkos::Impl::ViewCopy<
837  typename DstType::uniform_runtime_nomemspace_type,
838  typename SrcType::uniform_runtime_const_nomemspace_type,
839  Kokkos::LayoutLeft, ExecutionSpace, DstType::Rank, int>(dst, src,
840  space);
841  }
842  }
843 }
844 
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;
851 
852  enum {
853  DstExecCanAccessSrc =
854  Kokkos::Impl::SpaceAccessibility<dst_execution_space,
855  src_memory_space>::accessible
856  };
857 
858  enum {
859  SrcExecCanAccessDst =
860  Kokkos::Impl::SpaceAccessibility<src_execution_space,
861  dst_memory_space>::accessible
862  };
863 
864  if (!DstExecCanAccessSrc && !SrcExecCanAccessDst) {
865  std::string message(
866  "Error: Kokkos::deep_copy with no available copy mechanism: ");
867  message += src.label();
868  message += " to ";
869  message += dst.label();
870  Kokkos::Impl::throw_runtime_exception(message);
871  }
872 
873  // Figure out iteration order in case we need it
874  int64_t strides[DstType::Rank + 1];
875  dst.stride(strides);
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,
881  Kokkos::LayoutRight>::value) {
882  iterate = Kokkos::Iterate::Right;
883  } else if (std::is_same<typename DstType::array_layout,
884  Kokkos::LayoutLeft>::value) {
885  iterate = Kokkos::Iterate::Left;
886  } else if (std::is_same<typename DstType::array_layout,
887  Kokkos::LayoutStride>::value) {
888  if (strides[0] > strides[DstType::Rank - 1])
889  iterate = Kokkos::Iterate::Right;
890  else
891  iterate = Kokkos::Iterate::Left;
892  } else {
893  if (std::is_same<typename DstType::execution_space::array_layout,
894  Kokkos::LayoutRight>::value)
895  iterate = Kokkos::Iterate::Right;
896  else
897  iterate = Kokkos::Iterate::Left;
898  }
899 
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,
907  Kokkos::LayoutRight, dst_execution_space, DstType::Rank, int64_t>(
908  dst, src);
909  else
910  Kokkos::Impl::ViewCopy<
911  typename DstType::uniform_runtime_nomemspace_type,
912  typename SrcType::uniform_runtime_const_nomemspace_type,
913  Kokkos::LayoutLeft, dst_execution_space, DstType::Rank, int64_t>(
914  dst, src);
915  } else {
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,
920  Kokkos::LayoutRight, src_execution_space, DstType::Rank, int64_t>(
921  dst, src);
922  else
923  Kokkos::Impl::ViewCopy<
924  typename DstType::uniform_runtime_nomemspace_type,
925  typename SrcType::uniform_runtime_const_nomemspace_type,
926  Kokkos::LayoutLeft, src_execution_space, DstType::Rank, int64_t>(
927  dst, src);
928  }
929  } else {
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,
935  Kokkos::LayoutRight, dst_execution_space, DstType::Rank, int>(dst,
936  src);
937  else
938  Kokkos::Impl::ViewCopy<
939  typename DstType::uniform_runtime_nomemspace_type,
940  typename SrcType::uniform_runtime_const_nomemspace_type,
941  Kokkos::LayoutLeft, dst_execution_space, DstType::Rank, int>(dst,
942  src);
943  } else {
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,
948  Kokkos::LayoutRight, src_execution_space, DstType::Rank, int>(dst,
949  src);
950  else
951  Kokkos::Impl::ViewCopy<
952  typename DstType::uniform_runtime_nomemspace_type,
953  typename SrcType::uniform_runtime_const_nomemspace_type,
954  Kokkos::LayoutLeft, src_execution_space, DstType::Rank, int>(dst,
955  src);
956  }
957  }
958 }
959 
960 template <class DstType, class SrcType, int Rank, class... Args>
961 struct CommonSubview;
962 
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,
970  Args...)
971  : dst_sub(dst, arg0), src_sub(src, arg0) {}
972 };
973 
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) {}
983 };
984 
985 template <class DstType, class SrcType, class Arg0, class Arg1, class Arg2,
986  class... Args>
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) {}
995 };
996 
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>
1001  dst_subview_type;
1002  typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3>
1003  src_subview_type;
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,
1008  const Args...)
1009  : dst_sub(dst, arg0, arg1, arg2, arg3),
1010  src_sub(src, arg0, arg1, arg2, arg3) {}
1011 };
1012 
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,
1016  Args...> {
1017  typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4>
1018  dst_subview_type;
1019  typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4>
1020  src_subview_type;
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) {}
1028 };
1029 
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,
1033  Args...> {
1034  typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5>
1035  dst_subview_type;
1036  typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5>
1037  src_subview_type;
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) {}
1045 };
1046 
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,
1050  Arg6, Args...> {
1051  typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1052  Arg6>
1053  dst_subview_type;
1054  typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1055  Arg6>
1056  src_subview_type;
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) {}
1064 };
1065 
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,
1069  Arg6, Arg7> {
1070  typedef typename Kokkos::Subview<DstType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1071  Arg6, Arg7>
1072  dst_subview_type;
1073  typedef typename Kokkos::Subview<SrcType, Arg0, Arg1, Arg2, Arg3, Arg4, Arg5,
1074  Arg6, Arg7>
1075  src_subview_type;
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,
1081  const Arg7& arg7)
1082  : dst_sub(dst, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7),
1083  src_sub(src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {}
1084 };
1085 
1086 template <class DstType, class SrcType,
1087  class ExecSpace = typename DstType::execution_space,
1088  int Rank = DstType::Rank>
1089 struct ViewRemap;
1090 
1091 template <class DstType, class SrcType, class ExecSpace>
1092 struct ViewRemap<DstType, SrcType, ExecSpace, 1> {
1093  typedef Kokkos::pair<int64_t, int64_t> p_type;
1094 
1095  ViewRemap(const DstType& dst, const SrcType& src) {
1096  if (dst.extent(0) == src.extent(0)) {
1097  view_copy(dst, src);
1098  } else {
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);
1103  }
1104  }
1105 };
1106 
1107 template <class DstType, class SrcType, class ExecSpace>
1108 struct ViewRemap<DstType, SrcType, ExecSpace, 2> {
1109  typedef Kokkos::pair<int64_t, int64_t> p_type;
1110 
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);
1115  } else {
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>
1118  sv_adapter_type;
1119  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1);
1120  view_copy(common_subview.dst_sub, common_subview.src_sub);
1121  }
1122  } else {
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>
1126  sv_adapter_type;
1127  sv_adapter_type common_subview(dst, src, ext0, Kokkos::ALL);
1128  view_copy(common_subview.dst_sub, common_subview.src_sub);
1129  } else {
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>
1133  sv_adapter_type;
1134  sv_adapter_type common_subview(dst, src, ext0, ext1);
1135  view_copy(common_subview.dst_sub, common_subview.src_sub);
1136  }
1137  }
1138  }
1139 };
1140 
1141 template <class DstType, class SrcType, class ExecSpace>
1142 struct ViewRemap<DstType, SrcType, ExecSpace, 3> {
1143  typedef Kokkos::pair<int64_t, int64_t> p_type;
1144 
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>
1151  sv_adapter_type;
1152  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1,
1153  Kokkos::ALL);
1154  view_copy(common_subview.dst_sub, common_subview.src_sub);
1155  } else {
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,
1159  p_type>
1160  sv_adapter_type;
1161  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2);
1162  view_copy(common_subview.dst_sub, common_subview.src_sub);
1163  }
1164  } else {
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>
1170  sv_adapter_type;
1171  sv_adapter_type common_subview(dst, src, ext0, ext1, Kokkos::ALL);
1172  view_copy(common_subview.dst_sub, common_subview.src_sub);
1173  } else {
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>
1178  sv_adapter_type;
1179  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2);
1180  view_copy(common_subview.dst_sub, common_subview.src_sub);
1181  }
1182  }
1183  }
1184 };
1185 
1186 template <class DstType, class SrcType, class ExecSpace>
1187 struct ViewRemap<DstType, SrcType, ExecSpace, 4> {
1188  typedef Kokkos::pair<int64_t, int64_t> p_type;
1189 
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>
1197  sv_adapter_type;
1198  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2,
1199  Kokkos::ALL);
1200  view_copy(common_subview.dst_sub, common_subview.src_sub);
1201  } else {
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,
1206  p_type, p_type>
1207  sv_adapter_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);
1210  }
1211  } else {
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>
1218  sv_adapter_type;
1219  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, Kokkos::ALL);
1220  view_copy(common_subview.dst_sub, common_subview.src_sub);
1221  } else {
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,
1227  p_type>
1228  sv_adapter_type;
1229  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3);
1230  view_copy(common_subview.dst_sub, common_subview.src_sub);
1231  }
1232  }
1233  }
1234 };
1235 
1236 template <class DstType, class SrcType, class ExecSpace>
1237 struct ViewRemap<DstType, SrcType, ExecSpace, 5> {
1238  typedef Kokkos::pair<int64_t, int64_t> p_type;
1239 
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>
1248  sv_adapter_type;
1249  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1250  Kokkos::ALL);
1251  view_copy(common_subview.dst_sub, common_subview.src_sub);
1252  } else {
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>
1259  sv_adapter_type;
1260  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1261  ext4);
1262  view_copy(common_subview.dst_sub, common_subview.src_sub);
1263  }
1264  } else {
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>
1272  sv_adapter_type;
1273  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3,
1274  Kokkos::ALL);
1275  view_copy(common_subview.dst_sub, common_subview.src_sub);
1276  } else {
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,
1283  p_type, p_type>
1284  sv_adapter_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);
1287  }
1288  }
1289  }
1290 };
1291 template <class DstType, class SrcType, class ExecSpace>
1292 struct ViewRemap<DstType, SrcType, ExecSpace, 6> {
1293  typedef Kokkos::pair<int64_t, int64_t> p_type;
1294 
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>
1304  sv_adapter_type;
1305  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1306  ext4, Kokkos::ALL);
1307  view_copy(common_subview.dst_sub, common_subview.src_sub);
1308  } else {
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>
1316  sv_adapter_type;
1317  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1318  ext4, ext5);
1319  view_copy(common_subview.dst_sub, common_subview.src_sub);
1320  }
1321  } else {
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)));
1328 
1329  typedef CommonSubview<DstType, SrcType, 6, p_type, p_type, p_type,
1330  p_type, p_type, Kokkos::Impl::ALL_t>
1331  sv_adapter_type;
1332  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1333  Kokkos::ALL);
1334  view_copy(common_subview.dst_sub, common_subview.src_sub);
1335  } else {
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)));
1342 
1343  typedef CommonSubview<DstType, SrcType, 6, p_type, p_type, p_type,
1344  p_type, p_type, p_type>
1345  sv_adapter_type;
1346  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1347  ext5);
1348  view_copy(common_subview.dst_sub, common_subview.src_sub);
1349  }
1350  }
1351  }
1352 };
1353 
1354 template <class DstType, class SrcType, class ExecSpace>
1355 struct ViewRemap<DstType, SrcType, ExecSpace, 7> {
1356  typedef Kokkos::pair<int64_t, int64_t> p_type;
1357 
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>
1369  sv_adapter_type;
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);
1373  } else {
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>
1382  sv_adapter_type;
1383  sv_adapter_type common_subview(dst, src, Kokkos::ALL, ext1, ext2, ext3,
1384  ext4, ext5, ext6);
1385  view_copy(common_subview.dst_sub, common_subview.src_sub);
1386  }
1387  } else {
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>
1397  sv_adapter_type;
1398  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1399  ext5, Kokkos::ALL);
1400  view_copy(common_subview.dst_sub, common_subview.src_sub);
1401  } else {
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>
1411  sv_adapter_type;
1412  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1413  ext5, ext6);
1414  view_copy(common_subview.dst_sub, common_subview.src_sub);
1415  }
1416  }
1417  }
1418 };
1419 
1420 template <class DstType, class SrcType, class ExecSpace>
1421 struct ViewRemap<DstType, SrcType, ExecSpace, 8> {
1422  typedef Kokkos::pair<int64_t, int64_t> p_type;
1423 
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>
1436  sv_adapter_type;
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);
1440  } else {
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>
1450  sv_adapter_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);
1454  }
1455  } else {
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>
1467  sv_adapter_type;
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);
1471  } else {
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>
1482  sv_adapter_type;
1483  sv_adapter_type common_subview(dst, src, ext0, ext1, ext2, ext3, ext4,
1484  ext5, ext6, ext7);
1485  view_copy(common_subview.dst_sub, common_subview.src_sub);
1486  }
1487  }
1488  }
1489 };
1490 
1491 } // namespace Impl
1492 
1494 template <class DT, class... DP>
1495 inline void deep_copy(
1496  const View<DT, DP...>& dst,
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* =
1500  nullptr) {
1501  typedef View<DT, DP...> ViewType;
1502  using exec_space_type = typename ViewType::execution_space;
1503 
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(),
1509  Kokkos::Profiling::SpaceHandle(Kokkos::HostSpace::name()), "Scalar",
1510  &value, dst.span() * sizeof(typename ViewType::value_type));
1511  }
1512 #endif
1513 
1514  if (dst.data() == nullptr) {
1515  Kokkos::fence();
1516 #if defined(KOKKOS_ENABLE_PROFILING)
1517  if (Kokkos::Profiling::profileLibraryLoaded()) {
1518  Kokkos::Profiling::endDeepCopy();
1519  }
1520 #endif
1521  return;
1522  }
1523 
1524  Kokkos::fence();
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");
1528 
1529  // If contiguous we can simply do a 1D flat loop
1530  if (dst.span_is_contiguous()) {
1531  typedef Kokkos::View<
1532  typename ViewType::value_type*, Kokkos::LayoutRight,
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>>
1538  ViewTypeFlat;
1539 
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,
1544  exec_space_type());
1545  } else
1546  Kokkos::Impl::ViewFill<ViewTypeFlat, Kokkos::LayoutRight, exec_space_type,
1547  ViewTypeFlat::Rank, int64_t>(dst_flat, value,
1548  exec_space_type());
1549  Kokkos::fence();
1550 #if defined(KOKKOS_ENABLE_PROFILING)
1551  if (Kokkos::Profiling::profileLibraryLoaded()) {
1552  Kokkos::Profiling::endDeepCopy();
1553  }
1554 #endif
1555  return;
1556  }
1557 
1558  // Figure out iteration order to do the ViewFill
1559  int64_t strides[ViewType::Rank + 1];
1560  dst.stride(strides);
1561  Kokkos::Iterate iterate;
1562  if (std::is_same<typename ViewType::array_layout,
1563  Kokkos::LayoutRight>::value) {
1564  iterate = Kokkos::Iterate::Right;
1565  } else if (std::is_same<typename ViewType::array_layout,
1566  Kokkos::LayoutLeft>::value) {
1567  iterate = Kokkos::Iterate::Left;
1568  } else if (std::is_same<typename ViewType::array_layout,
1569  Kokkos::LayoutStride>::value) {
1570  if (strides[0] > strides[ViewType::Rank > 0 ? ViewType::Rank - 1 : 0])
1571  iterate = Kokkos::Iterate::Right;
1572  else
1573  iterate = Kokkos::Iterate::Left;
1574  } else {
1575  if (std::is_same<typename ViewType::execution_space::array_layout,
1576  Kokkos::LayoutRight>::value)
1577  iterate = Kokkos::Iterate::Right;
1578  else
1579  iterate = Kokkos::Iterate::Left;
1580  }
1581 
1582  // Lets call the right ViewFill functor based on integer space needed and
1583  // iteration type
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)
1589  Kokkos::Impl::ViewFill<ViewTypeUniform, Kokkos::LayoutRight,
1590  exec_space_type, ViewType::Rank, int64_t>(
1591  dst, value, exec_space_type());
1592  else
1593  Kokkos::Impl::ViewFill<ViewTypeUniform, Kokkos::LayoutLeft,
1594  exec_space_type, ViewType::Rank, int64_t>(
1595  dst, value, exec_space_type());
1596  } else {
1597  if (iterate == Kokkos::Iterate::Right)
1598  Kokkos::Impl::ViewFill<ViewTypeUniform, Kokkos::LayoutRight,
1599  exec_space_type, ViewType::Rank, int>(
1600  dst, value, exec_space_type());
1601  else
1602  Kokkos::Impl::ViewFill<ViewTypeUniform, Kokkos::LayoutLeft,
1603  exec_space_type, ViewType::Rank, int>(
1604  dst, value, exec_space_type());
1605  }
1606  Kokkos::fence();
1607 
1608 #if defined(KOKKOS_ENABLE_PROFILING)
1609  if (Kokkos::Profiling::profileLibraryLoaded()) {
1610  Kokkos::Profiling::endDeepCopy();
1611  }
1612 #endif
1613 }
1614 
1616 template <class ST, class... SP>
1617 inline void deep_copy(
1618  typename ViewTraits<ST, SP...>::non_const_value_type& dst,
1619  const View<ST, SP...>& src,
1620  typename std::enable_if<std::is_same<
1621  typename ViewTraits<ST, SP...>::specialize, void>::value>::type* =
1622  nullptr) {
1623  typedef ViewTraits<ST, SP...> src_traits;
1624  typedef typename src_traits::memory_space src_memory_space;
1625 
1626  static_assert(src_traits::rank == 0,
1627  "ERROR: Non-rank-zero view in deep_copy( value , View )");
1628 
1629 #if defined(KOKKOS_ENABLE_PROFILING)
1630  if (Kokkos::Profiling::profileLibraryLoaded()) {
1631  Kokkos::Profiling::beginDeepCopy(
1632  Kokkos::Profiling::SpaceHandle(Kokkos::HostSpace::name()), "Scalar",
1633  &dst, Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
1634  src.label(), src.data(),
1635  src.span() * sizeof(typename src_traits::value_type));
1636  }
1637 #endif
1638 
1639  if (src.data() == nullptr) {
1640  Kokkos::fence();
1641 #if defined(KOKKOS_ENABLE_PROFILING)
1642  if (Kokkos::Profiling::profileLibraryLoaded()) {
1643  Kokkos::Profiling::endDeepCopy();
1644  }
1645 #endif
1646  return;
1647  }
1648 
1649  Kokkos::Impl::DeepCopy<HostSpace, src_memory_space>(&dst, src.data(),
1650  sizeof(ST));
1651 #if defined(KOKKOS_ENABLE_PROFILING)
1652  if (Kokkos::Profiling::profileLibraryLoaded()) {
1653  Kokkos::Profiling::endDeepCopy();
1654  }
1655 #endif
1656 }
1657 
1658 //----------------------------------------------------------------------------
1660 template <class DT, class... DP, class ST, class... SP>
1661 inline void deep_copy(
1662  const View<DT, DP...>& dst, const View<ST, SP...>& src,
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 &&
1666  (unsigned(ViewTraits<DT, DP...>::rank) == unsigned(0) &&
1667  unsigned(ViewTraits<ST, SP...>::rank) == unsigned(0)))>::type* =
1668  nullptr) {
1669  typedef View<DT, DP...> dst_type;
1670  typedef View<ST, SP...> src_type;
1671 
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;
1675 
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");
1679 
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));
1687  }
1688 #endif
1689 
1690  if (dst.data() == nullptr && src.data() == nullptr) {
1691  Kokkos::fence();
1692 #if defined(KOKKOS_ENABLE_PROFILING)
1693  if (Kokkos::Profiling::profileLibraryLoaded()) {
1694  Kokkos::Profiling::endDeepCopy();
1695  }
1696 #endif
1697  return;
1698  }
1699 
1700  Kokkos::fence();
1701  if (dst.data() != src.data()) {
1702  Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1703  dst.data(), src.data(), sizeof(value_type));
1704  Kokkos::fence();
1705  }
1706 #if defined(KOKKOS_ENABLE_PROFILING)
1707  if (Kokkos::Profiling::profileLibraryLoaded()) {
1708  Kokkos::Profiling::endDeepCopy();
1709  }
1710 #endif
1711 }
1712 
1713 //----------------------------------------------------------------------------
1717 template <class DT, class... DP, class ST, class... SP>
1718 inline void deep_copy(
1719  const View<DT, DP...>& dst, const View<ST, SP...>& src,
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 &&
1723  (unsigned(ViewTraits<DT, DP...>::rank) != 0 ||
1724  unsigned(ViewTraits<ST, SP...>::rank) != 0))>::type* = nullptr) {
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;
1733 
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");
1737 
1738  static_assert((unsigned(dst_type::rank) == unsigned(src_type::rank)),
1739  "deep_copy requires Views of equal rank");
1740 
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));
1748  }
1749 #endif
1750 
1751  if (dst.data() == nullptr || src.data() == nullptr) {
1752 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1753  // do nothing
1754 #else
1755  // throw if dimension mismatch
1756  if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
1757  (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
1758  (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
1759  (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
1760  std::string message(
1761  "Deprecation Error: Kokkos::deep_copy extents of views don't "
1762  "match: ");
1763  message += dst.label();
1764  message += "(";
1765  for (int r = 0; r < dst_type::Rank - 1; r++) {
1766  message += std::to_string(dst.extent(r));
1767  message += ",";
1768  }
1769  message += std::to_string(dst.extent(dst_type::Rank - 1));
1770  message += ") ";
1771  message += src.label();
1772  message += "(";
1773  for (int r = 0; r < src_type::Rank - 1; r++) {
1774  message += std::to_string(src.extent(r));
1775  message += ",";
1776  }
1777  message += std::to_string(src.extent(src_type::Rank - 1));
1778  message += ") ";
1779 
1780  Kokkos::Impl::throw_runtime_exception(message);
1781  }
1782 #endif
1783  Kokkos::fence();
1784 #if defined(KOKKOS_ENABLE_PROFILING)
1785  if (Kokkos::Profiling::profileLibraryLoaded()) {
1786  Kokkos::Profiling::endDeepCopy();
1787  }
1788 #endif
1789  return;
1790  }
1791 
1792  enum {
1793  DstExecCanAccessSrc =
1794  Kokkos::Impl::SpaceAccessibility<dst_execution_space,
1795  src_memory_space>::accessible
1796  };
1797 
1798  enum {
1799  SrcExecCanAccessDst =
1800  Kokkos::Impl::SpaceAccessibility<src_execution_space,
1801  dst_memory_space>::accessible
1802  };
1803 
1804  // Checking for Overlapping Views.
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())) {
1812  Kokkos::fence();
1813 #if defined(KOKKOS_ENABLE_PROFILING)
1814  if (Kokkos::Profiling::profileLibraryLoaded()) {
1815  Kokkos::Profiling::endDeepCopy();
1816  }
1817 #endif
1818  return;
1819  }
1820 
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();
1826  message += "(";
1827  message += std::to_string((std::ptrdiff_t)dst_start);
1828  message += ",";
1829  message += std::to_string((std::ptrdiff_t)dst_end);
1830  message += ") ";
1831  message += src.label();
1832  message += "(";
1833  message += std::to_string((std::ptrdiff_t)src_start);
1834  message += ",";
1835  message += std::to_string((std::ptrdiff_t)src_end);
1836  message += ") ";
1837  Kokkos::Impl::throw_runtime_exception(message);
1838  }
1839 
1840  // Check for same extents
1841  if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
1842  (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
1843  (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
1844  (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
1845 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1846  Kokkos::fence();
1847  if (DstExecCanAccessSrc) {
1848  // Copying data between views in accessible memory spaces and either
1849  // non-contiguous or incompatible shape.
1850  Kokkos::Impl::ViewRemap<dst_type, src_type>(dst, src);
1851  } else if (SrcExecCanAccessDst) {
1852  // Copying data between views in accessible memory spaces and either
1853  // non-contiguous or incompatible shape.
1854  Kokkos::Impl::ViewRemap<dst_type, src_type, src_execution_space>(dst,
1855  src);
1856  } else {
1857  Kokkos::Impl::throw_runtime_exception(
1858  "deep_copy given views that would require a temporary allocation");
1859  }
1860  Kokkos::fence();
1861 #if defined(KOKKOS_ENABLE_PROFILING)
1862  if (Kokkos::Profiling::profileLibraryLoaded()) {
1863  Kokkos::Profiling::endDeepCopy();
1864  }
1865 #endif
1866  return;
1867 #else
1868  std::string message(
1869  "Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1870  message += dst.label();
1871  message += "(";
1872  for (int r = 0; r < dst_type::Rank - 1; r++) {
1873  message += std::to_string(dst.extent(r));
1874  message += ",";
1875  }
1876  message += std::to_string(dst.extent(dst_type::Rank - 1));
1877  message += ") ";
1878  message += src.label();
1879  message += "(";
1880  for (int r = 0; r < src_type::Rank - 1; r++) {
1881  message += std::to_string(src.extent(r));
1882  message += ",";
1883  }
1884  message += std::to_string(src.extent(src_type::Rank - 1));
1885  message += ") ";
1886 
1887  Kokkos::Impl::throw_runtime_exception(message);
1888 #endif
1889  }
1890 
1891  // If same type, equal layout, equal dimensions, equal span, and contiguous
1892  // memory then can byte-wise copy
1893 
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();
1909  Kokkos::fence();
1910  if ((void*)dst.data() != (void*)src.data()) {
1911  Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1912  dst.data(), src.data(), nbytes);
1913  }
1914  Kokkos::fence();
1915  } else {
1916  Kokkos::fence();
1917  Impl::view_copy(dst, src);
1918  Kokkos::fence();
1919  }
1920 #if defined(KOKKOS_ENABLE_PROFILING)
1921  if (Kokkos::Profiling::profileLibraryLoaded()) {
1922  Kokkos::Profiling::endDeepCopy();
1923  }
1924 #endif
1925 }
1926 
1927 //----------------------------------------------------------------------------
1928 //----------------------------------------------------------------------------
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]; });
1939 }
1940 //----------------------------------------------------------------------------
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];
1946  }
1947 }
1948 //----------------------------------------------------------------------------
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) {
1957  return;
1958  }
1959 
1960  const size_t N = dst.extent(0);
1961 
1962  team.team_barrier();
1964  [&](const int& i) { dst(i) = src(i); });
1965  team.team_barrier();
1966 }
1967 //----------------------------------------------------------------------------
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) {
1976  return;
1977  }
1978 
1979  const size_t N = dst.extent(0) * dst.extent(1);
1980 
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();
1985  } else {
1986  team.team_barrier();
1987  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
1988  int i0 = i % dst.extent(0);
1989  int i1 = i / dst.extent(0);
1990  dst(i0, i1) = src(i0, i1);
1991  });
1992  team.team_barrier();
1993  }
1994 }
1995 //----------------------------------------------------------------------------
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) {
2004  return;
2005  }
2006 
2007  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
2008 
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();
2013  } else {
2014  team.team_barrier();
2015  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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);
2021  });
2022  team.team_barrier();
2023  }
2024 }
2025 //----------------------------------------------------------------------------
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) {
2034  return;
2035  }
2036 
2037  const size_t N =
2038  dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
2039 
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();
2044  } else {
2045  team.team_barrier();
2046  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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);
2054  });
2055  team.team_barrier();
2056  }
2057 }
2058 //----------------------------------------------------------------------------
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) {
2067  return;
2068  }
2069 
2070  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2071  dst.extent(3) * dst.extent(4);
2072 
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();
2077  } else {
2078  team.team_barrier();
2079  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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);
2089  });
2090  team.team_barrier();
2091  }
2092 }
2093 //----------------------------------------------------------------------------
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) {
2102  return;
2103  }
2104 
2105  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2106  dst.extent(3) * dst.extent(4) * dst.extent(5);
2107 
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();
2112  } else {
2113  team.team_barrier();
2114  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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);
2126  });
2127  team.team_barrier();
2128  }
2129 }
2130 //----------------------------------------------------------------------------
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) {
2139  return;
2140  }
2141 
2142  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2143  dst.extent(3) * dst.extent(4) * dst.extent(5) *
2144  dst.extent(6);
2145 
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();
2150  } else {
2151  team.team_barrier();
2152  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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);
2166  });
2167  team.team_barrier();
2168  }
2169 }
2170 //----------------------------------------------------------------------------
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) {
2178  return;
2179  }
2180 
2181  const size_t N = dst.extent(0);
2182 
2183  for (size_t i = 0; i < N; ++i) {
2184  dst(i) = src(i);
2185  }
2186 }
2187 //----------------------------------------------------------------------------
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) {
2195  return;
2196  }
2197 
2198  if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2199  local_deep_copy_contiguous(dst, src);
2200  } else {
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);
2203  }
2204 }
2205 //----------------------------------------------------------------------------
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) {
2213  return;
2214  }
2215 
2216  if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2217  local_deep_copy_contiguous(dst, src);
2218  } else {
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);
2223  }
2224 }
2225 //----------------------------------------------------------------------------
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) {
2233  return;
2234  }
2235 
2236  if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2237  local_deep_copy_contiguous(dst, src);
2238  } else {
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);
2244  }
2245 }
2246 //----------------------------------------------------------------------------
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) {
2254  return;
2255  }
2256 
2257  if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2258  local_deep_copy_contiguous(dst, src);
2259  } else {
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);
2266  }
2267 }
2268 //----------------------------------------------------------------------------
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) {
2276  return;
2277  }
2278 
2279  if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2280  local_deep_copy_contiguous(dst, src);
2281  } else {
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);
2289  }
2290 }
2291 //----------------------------------------------------------------------------
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) {
2299  return;
2300  }
2301 
2302  if (dst.span_is_contiguous() && src.span_is_contiguous()) {
2303  local_deep_copy_contiguous(dst, src);
2304  } else {
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);
2314  }
2315 }
2316 //----------------------------------------------------------------------------
2317 //----------------------------------------------------------------------------
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; });
2325 }
2326 //----------------------------------------------------------------------------
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;
2333  }
2334 }
2335 //----------------------------------------------------------------------------
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) {
2343  return;
2344  }
2345 
2346  const size_t N = dst.extent(0);
2347 
2348  team.team_barrier();
2350  [&](const int& i) { dst(i) = value; });
2351  team.team_barrier();
2352 }
2353 //----------------------------------------------------------------------------
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) {
2361  return;
2362  }
2363 
2364  const size_t N = dst.extent(0) * dst.extent(1);
2365 
2366  if (dst.span_is_contiguous()) {
2367  team.team_barrier();
2368  local_deep_copy_contiguous(team, dst, value);
2369  team.team_barrier();
2370  } else {
2371  team.team_barrier();
2372  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
2373  int i0 = i % dst.extent(0);
2374  int i1 = i / dst.extent(0);
2375  dst(i0, i1) = value;
2376  });
2377  team.team_barrier();
2378  }
2379 }
2380 //----------------------------------------------------------------------------
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) {
2388  return;
2389  }
2390 
2391  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
2392 
2393  if (dst.span_is_contiguous()) {
2394  team.team_barrier();
2395  local_deep_copy_contiguous(team, dst, value);
2396  team.team_barrier();
2397  } else {
2398  team.team_barrier();
2399  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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;
2405  });
2406  team.team_barrier();
2407  }
2408 }
2409 //----------------------------------------------------------------------------
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) {
2417  return;
2418  }
2419 
2420  const size_t N =
2421  dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
2422 
2423  if (dst.span_is_contiguous()) {
2424  team.team_barrier();
2425  local_deep_copy_contiguous(team, dst, value);
2426  team.team_barrier();
2427  } else {
2428  team.team_barrier();
2429  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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;
2437  });
2438  team.team_barrier();
2439  }
2440 }
2441 //----------------------------------------------------------------------------
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) {
2449  return;
2450  }
2451 
2452  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2453  dst.extent(3) * dst.extent(4);
2454 
2455  if (dst.span_is_contiguous()) {
2456  team.team_barrier();
2457  local_deep_copy_contiguous(team, dst, value);
2458  team.team_barrier();
2459  } else {
2460  team.team_barrier();
2461  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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;
2471  });
2472  team.team_barrier();
2473  }
2474 }
2475 //----------------------------------------------------------------------------
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) {
2483  return;
2484  }
2485 
2486  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2487  dst.extent(3) * dst.extent(4) * dst.extent(5);
2488 
2489  if (dst.span_is_contiguous()) {
2490  team.team_barrier();
2491  local_deep_copy_contiguous(team, dst, value);
2492  team.team_barrier();
2493  } else {
2494  team.team_barrier();
2495  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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;
2507  });
2508  team.team_barrier();
2509  }
2510 }
2511 //----------------------------------------------------------------------------
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) {
2519  return;
2520  }
2521 
2522  const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
2523  dst.extent(3) * dst.extent(4) * dst.extent(5) *
2524  dst.extent(6);
2525 
2526  if (dst.span_is_contiguous()) {
2527  team.team_barrier();
2528  local_deep_copy_contiguous(team, dst, value);
2529  team.team_barrier();
2530  } else {
2531  team.team_barrier();
2532  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) {
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;
2546  });
2547  team.team_barrier();
2548  }
2549 }
2550 //----------------------------------------------------------------------------
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) {
2558  return;
2559  }
2560 
2561  const size_t N = dst.extent(0);
2562 
2563  for (size_t i = 0; i < N; ++i) {
2564  dst(i) = value;
2565  }
2566 }
2567 //----------------------------------------------------------------------------
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) {
2575  return;
2576  }
2577 
2578  if (dst.span_is_contiguous()) {
2579  local_deep_copy_contiguous(dst, value);
2580  } else {
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;
2583  }
2584 }
2585 //----------------------------------------------------------------------------
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) {
2593  return;
2594  }
2595 
2596  if (dst.span_is_contiguous()) {
2597  local_deep_copy_contiguous(dst, value);
2598  } else {
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;
2602  }
2603 }
2604 //----------------------------------------------------------------------------
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) {
2612  return;
2613  }
2614 
2615  if (dst.span_is_contiguous()) {
2616  local_deep_copy_contiguous(dst, value);
2617  } else {
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;
2623  }
2624 }
2625 //----------------------------------------------------------------------------
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) {
2633  return;
2634  }
2635 
2636  if (dst.span_is_contiguous()) {
2637  local_deep_copy_contiguous(dst, value);
2638  } else {
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;
2645  }
2646 }
2647 //----------------------------------------------------------------------------
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) {
2655  return;
2656  }
2657 
2658  if (dst.span_is_contiguous()) {
2659  local_deep_copy_contiguous(dst, value);
2660  } else {
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;
2668  }
2669 }
2670 //----------------------------------------------------------------------------
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) {
2678  return;
2679  }
2680 
2681  if (dst.span_is_contiguous()) {
2682  local_deep_copy_contiguous(dst, value);
2683  } else {
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;
2692  }
2693 }
2694 } /* namespace Experimental */
2695 } /* namespace Kokkos */
2696 
2697 //----------------------------------------------------------------------------
2698 //----------------------------------------------------------------------------
2699 
2700 namespace Kokkos {
2701 
2704 template <class ExecSpace, class DT, class... DP>
2705 inline void deep_copy(
2706  const ExecSpace& space, const View<DT, DP...>& dst,
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 &&
2712  ExecSpace,
2713  typename ViewTraits<DT, DP...>::memory_space>::accessible>::type* =
2714  nullptr) {
2715  typedef ViewTraits<DT, DP...> dst_traits;
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(),
2724  dst.data(), Kokkos::Profiling::SpaceHandle(Kokkos::HostSpace::name()),
2725  "(none)", &value, dst.span() * sizeof(typename dst_traits::value_type));
2726  }
2727 #endif
2728  if (dst.data() == nullptr) {
2729  space.fence();
2730  } else {
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);
2737  }
2738 #if defined(KOKKOS_ENABLE_PROFILING)
2739  if (Kokkos::Profiling::profileLibraryLoaded()) {
2740  Kokkos::Profiling::endDeepCopy();
2741  }
2742 #endif
2743 }
2744 
2747 template <class ExecSpace, class DT, class... DP>
2748 inline void deep_copy(
2749  const ExecSpace& space, const View<DT, DP...>& dst,
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 &&
2755  ExecSpace,
2756  typename ViewTraits<DT, DP...>::memory_space>::accessible>::type* =
2757  nullptr) {
2758  typedef ViewTraits<DT, DP...> dst_traits;
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(),
2767  dst.data(), Kokkos::Profiling::SpaceHandle(Kokkos::HostSpace::name()),
2768  "(none)", &value, dst.span() * sizeof(typename dst_traits::value_type));
2769  }
2770 #endif
2771  if (dst.data() == nullptr) {
2772  space.fence();
2773  } else {
2774  space.fence();
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();
2783  }
2784 #if defined(KOKKOS_ENABLE_PROFILING)
2785  if (Kokkos::Profiling::profileLibraryLoaded()) {
2786  Kokkos::Profiling::endDeepCopy();
2787  }
2788 #endif
2789 }
2790 
2792 template <class ExecSpace, class ST, class... SP>
2793 inline void deep_copy(
2794  const ExecSpace& exec_space,
2795  typename ViewTraits<ST, SP...>::non_const_value_type& dst,
2796  const View<ST, SP...>& src,
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) {
2801  typedef ViewTraits<ST, SP...> src_traits;
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(
2808  Kokkos::Profiling::SpaceHandle(Kokkos::HostSpace::name()), "(none)",
2809  &dst, Kokkos::Profiling::SpaceHandle(src_memory_space::name()),
2810  src.label(), src.data(), sizeof(ST));
2811  }
2812 #endif
2813 
2814  if (src.data() == nullptr) {
2815  exec_space.fence();
2816 #if defined(KOKKOS_ENABLE_PROFILING)
2817  if (Kokkos::Profiling::profileLibraryLoaded()) {
2818  Kokkos::Profiling::endDeepCopy();
2819  }
2820 #endif
2821  return;
2822  }
2823 
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();
2829  }
2830 #endif
2831 }
2832 
2833 //----------------------------------------------------------------------------
2835 template <class ExecSpace, class DT, class... DP, class ST, class... SP>
2836 inline void deep_copy(
2837  const ExecSpace& exec_space, const View<DT, DP...>& dst,
2838  const View<ST, SP...>& src,
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 &&
2843  (unsigned(ViewTraits<DT, DP...>::rank) == unsigned(0) &&
2844  unsigned(ViewTraits<ST, SP...>::rank) == unsigned(0)))>::type* = 0) {
2845  typedef ViewTraits<ST, SP...> src_traits;
2846  typedef ViewTraits<DT, DP...> dst_traits;
2847 
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");
2853 
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));
2860  }
2861 #endif
2862 
2863  if (dst.data() == nullptr && src.data() == nullptr) {
2864  exec_space.fence();
2865 #if defined(KOKKOS_ENABLE_PROFILING)
2866  if (Kokkos::Profiling::profileLibraryLoaded()) {
2867  Kokkos::Profiling::endDeepCopy();
2868  }
2869 #endif
2870  return;
2871  }
2872 
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));
2877  }
2878 #if defined(KOKKOS_ENABLE_PROFILING)
2879  if (Kokkos::Profiling::profileLibraryLoaded()) {
2880  Kokkos::Profiling::endDeepCopy();
2881  }
2882 #endif
2883 }
2884 
2885 //----------------------------------------------------------------------------
2889 template <class ExecSpace, class DT, class... DP, class ST, class... SP>
2890 inline void deep_copy(
2891  const ExecSpace& exec_space, const View<DT, DP...>& dst,
2892  const View<ST, SP...>& src,
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 &&
2897  (unsigned(ViewTraits<DT, DP...>::rank) != 0 ||
2898  unsigned(ViewTraits<ST, SP...>::rank) != 0))>::type* = nullptr) {
2899  typedef View<DT, DP...> dst_type;
2900  typedef View<ST, SP...> src_type;
2901 
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");
2905 
2906  static_assert((unsigned(dst_type::rank) == unsigned(src_type::rank)),
2907  "deep_copy requires Views of equal rank");
2908 
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;
2915 
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));
2922  }
2923 #endif
2924 
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();
2929 
2930  // Early dropout if identical range
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
2935  // do nothing
2936 #else
2937  // throw if dimension mismatch
2938  if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
2939  (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
2940  (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
2941  (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
2942  std::string message(
2943  "Deprecation Error: Kokkos::deep_copy extents of views don't "
2944  "match: ");
2945  message += dst.label();
2946  message += "(";
2947  for (int r = 0; r < dst_type::Rank - 1; r++) {
2948  message += std::to_string(dst.extent(r));
2949  message += ",";
2950  }
2951  message += std::to_string(dst.extent(dst_type::Rank - 1));
2952  message += ") ";
2953  message += src.label();
2954  message += "(";
2955  for (int r = 0; r < src_type::Rank - 1; r++) {
2956  message += std::to_string(src.extent(r));
2957  message += ",";
2958  }
2959  message += std::to_string(src.extent(src_type::Rank - 1));
2960  message += ") ";
2961 
2962  Kokkos::Impl::throw_runtime_exception(message);
2963  }
2964 #endif
2965 #if defined(KOKKOS_ENABLE_PROFILING)
2966  if (Kokkos::Profiling::profileLibraryLoaded()) {
2967  Kokkos::Profiling::endDeepCopy();
2968  }
2969 #endif
2970  return;
2971  }
2972 
2973  enum {
2974  ExecCanAccessSrcDst =
2976  dst_memory_space>::accessible &&
2978  src_memory_space>::accessible
2979  };
2980  enum {
2981  DstExecCanAccessSrc =
2982  Kokkos::Impl::SpaceAccessibility<dst_execution_space,
2983  src_memory_space>::accessible
2984  };
2985 
2986  enum {
2987  SrcExecCanAccessDst =
2988  Kokkos::Impl::SpaceAccessibility<src_execution_space,
2989  dst_memory_space>::accessible
2990  };
2991 
2992  // Error out for non-identical overlapping views.
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();
2998  message += "(";
2999  message += std::to_string((std::ptrdiff_t)dst_start);
3000  message += ",";
3001  message += std::to_string((std::ptrdiff_t)dst_end);
3002  message += ") ";
3003  message += src.label();
3004  message += "(";
3005  message += std::to_string((std::ptrdiff_t)src_start);
3006  message += ",";
3007  message += std::to_string((std::ptrdiff_t)src_end);
3008  message += ") ";
3009  Kokkos::Impl::throw_runtime_exception(message);
3010  }
3011 
3012  // Check for same extents
3013  if ((src.extent(0) != dst.extent(0)) || (src.extent(1) != dst.extent(1)) ||
3014  (src.extent(2) != dst.extent(2)) || (src.extent(3) != dst.extent(3)) ||
3015  (src.extent(4) != dst.extent(4)) || (src.extent(5) != dst.extent(5)) ||
3016  (src.extent(6) != dst.extent(6)) || (src.extent(7) != dst.extent(7))) {
3017 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
3018  if (ExecCanAccessSrcDst) {
3019  Kokkos::Impl::ViewRemap<dst_type, src_type, ExecSpace>(dst, src);
3020  exec_space.fence();
3021  } else if (DstExecCanAccessSrc) {
3022  // Copying data between views in accessible memory spaces and either
3023  // non-contiguous or incompatible shape.
3024  exec_space.fence();
3025  Kokkos::Impl::ViewRemap<dst_type, src_type, dst_execution_space>(dst,
3026  src);
3027  dst_execution_space().fence();
3028  } else if (SrcExecCanAccessDst) {
3029  // Copying data between views in accessible memory spaces and either
3030  // non-contiguous or incompatible shape.
3031  exec_space.fence();
3032  Kokkos::Impl::ViewRemap<dst_type, src_type, src_execution_space>(dst,
3033  src);
3034  src_execution_space().fence();
3035  } else {
3036  Kokkos::Impl::throw_runtime_exception(
3037  "deep_copy given views that would require a temporary allocation");
3038  }
3039 #if defined(KOKKOS_ENABLE_PROFILING)
3040  if (Kokkos::Profiling::profileLibraryLoaded()) {
3041  Kokkos::Profiling::endDeepCopy();
3042  }
3043 #endif
3044  return;
3045 #else
3046  std::string message(
3047  "Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
3048  message += dst.label();
3049  message += "(";
3050  for (int r = 0; r < dst_type::Rank - 1; r++) {
3051  message += std::to_string(dst.extent(r));
3052  message += ",";
3053  }
3054  message += std::to_string(dst.extent(dst_type::Rank - 1));
3055  message += ") ";
3056  message += src.label();
3057  message += "(";
3058  for (int r = 0; r < src_type::Rank - 1; r++) {
3059  message += std::to_string(src.extent(r));
3060  message += ",";
3061  }
3062  message += std::to_string(src.extent(src_type::Rank - 1));
3063  message += ") ";
3064 
3065  Kokkos::Impl::throw_runtime_exception(message);
3066 #endif
3067  }
3068 
3069  // If same type, equal layout, equal dimensions, equal span, and contiguous
3070  // memory then can byte-wise copy
3071 
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);
3090  }
3091  } else {
3092  // Copying data between views in accessible memory spaces and either
3093  // non-contiguous or incompatible shape.
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;
3100  exec_space.fence();
3101  Impl::view_copy(cpy_exec_space(), dst, src);
3102  cpy_exec_space().fence();
3103  } else {
3104  Kokkos::Impl::throw_runtime_exception(
3105  "deep_copy given views that would require a temporary allocation");
3106  }
3107  }
3108 #if defined(KOKKOS_ENABLE_PROFILING)
3109  if (Kokkos::Profiling::profileLibraryLoaded()) {
3110  Kokkos::Profiling::endDeepCopy();
3111  }
3112 #endif
3113 }
3114 
3115 } /* namespace Kokkos */
3116 
3117 //----------------------------------------------------------------------------
3118 //----------------------------------------------------------------------------
3119 
3120 namespace Kokkos {
3121 
3124 template <class T, class... P>
3125 inline typename std::enable_if<
3126  std::is_same<typename Kokkos::View<T, P...>::array_layout,
3127  Kokkos::LayoutLeft>::value ||
3128  std::is_same<typename Kokkos::View<T, P...>::array_layout,
3129  Kokkos::LayoutRight>::value>::type
3130 resize(Kokkos::View<T, P...>& v, const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
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) {
3138  typedef Kokkos::View<T, P...> view_type;
3139 
3141  "Can only resize managed views");
3142 
3143  // Fix #904 by checking dimensions before actually resizing.
3144  //
3145  // Rank is known at compile time, so hopefully the compiler will
3146  // remove branches that are compile-time false. The upcoming "if
3147  // constexpr" language feature would make this certain.
3148  if (view_type::Rank == 1 && n0 == static_cast<size_t>(v.extent(0))) {
3149  return;
3150  }
3151  if (view_type::Rank == 2 && n0 == static_cast<size_t>(v.extent(0)) &&
3152  n1 == static_cast<size_t>(v.extent(1))) {
3153  return;
3154  }
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))) {
3158  return;
3159  }
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))) {
3164  return;
3165  }
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))) {
3171  return;
3172  }
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))) {
3179  return;
3180  }
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))) {
3188  return;
3189  }
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))) {
3198  return;
3199  }
3200  // If Kokkos ever supports Views of rank > 8, the above code won't
3201  // be incorrect, because avoiding reallocation in resize() is just
3202  // an optimization.
3203 
3204  // TODO (mfh 27 Jun 2017) If the old View has enough space but just
3205  // different dimensions (e.g., if the product of the dimensions,
3206  // including extra space for alignment, will not change), then
3207  // consider just reusing storage. For now, Kokkos always
3208  // reallocates if any of the dimensions change, even if the old View
3209  // has enough space.
3210 
3211  view_type v_resized(v.label(), n0, n1, n2, n3, n4, n5, n6, n7);
3212 
3213  Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3214 
3215  v = v_resized;
3216 }
3217 
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,
3223  Kokkos::LayoutLeft>::value ||
3224  std::is_same<typename Kokkos::View<T, P...>::array_layout,
3225  Kokkos::LayoutRight>::value>::type
3226 resize(const I& arg_prop, Kokkos::View<T, P...>& v,
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) {
3235  typedef Kokkos::View<T, P...> view_type;
3236 
3238  "Can only resize managed views");
3239 
3240  // Fix #904 by checking dimensions before actually resizing.
3241  //
3242  // Rank is known at compile time, so hopefully the compiler will
3243  // remove branches that are compile-time false. The upcoming "if
3244  // constexpr" language feature would make this certain.
3245  if (view_type::Rank == 1 && n0 == static_cast<size_t>(v.extent(0))) {
3246  return;
3247  }
3248  if (view_type::Rank == 2 && n0 == static_cast<size_t>(v.extent(0)) &&
3249  n1 == static_cast<size_t>(v.extent(1))) {
3250  return;
3251  }
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))) {
3255  return;
3256  }
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))) {
3261  return;
3262  }
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))) {
3268  return;
3269  }
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))) {
3276  return;
3277  }
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))) {
3285  return;
3286  }
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))) {
3295  return;
3296  }
3297  // If Kokkos ever supports Views of rank > 8, the above code won't
3298  // be incorrect, because avoiding reallocation in resize() is just
3299  // an optimization.
3300 
3301  // TODO (mfh 27 Jun 2017) If the old View has enough space but just
3302  // different dimensions (e.g., if the product of the dimensions,
3303  // including extra space for alignment, will not change), then
3304  // consider just reusing storage. For now, Kokkos always
3305  // reallocates if any of the dimensions change, even if the old View
3306  // has enough space.
3307 
3308  view_type v_resized(view_alloc(v.label(), std::forward<const I>(arg_prop)),
3309  n0, n1, n2, n3, n4, n5, n6, n7);
3310 
3311  Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3312 
3313  v = v_resized;
3314 }
3315 
3318 template <class T, class... P>
3320  const typename Kokkos::View<T, P...>::array_layout& layout) {
3321  typedef Kokkos::View<T, P...> view_type;
3322 
3324  "Can only resize managed views");
3325 
3326  view_type v_resized(v.label(), layout);
3327 
3328  Kokkos::Impl::ViewRemap<view_type, view_type>(v_resized, v);
3329 
3330  v = v_resized;
3331 }
3332 
3334 template <class T, class... P>
3335 inline typename std::enable_if<
3336  std::is_same<typename Kokkos::View<T, P...>::array_layout,
3337  Kokkos::LayoutLeft>::value ||
3338  std::is_same<typename Kokkos::View<T, P...>::array_layout,
3339  Kokkos::LayoutRight>::value>::type
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) {
3349  typedef Kokkos::View<T, P...> view_type;
3350 
3352  "Can only realloc managed views");
3353 
3354  const std::string label = v.label();
3355 
3356  v = view_type(); // Deallocate first, if the only view to allocation
3357  v = view_type(label, n0, n1, n2, n3, n4, n5, n6, n7);
3358 }
3359 
3361 template <class T, class... P>
3362 inline void realloc(
3364  const typename Kokkos::View<T, P...>::array_layout& layout) {
3365  typedef Kokkos::View<T, P...> view_type;
3366 
3368  "Can only realloc managed views");
3369 
3370  const std::string label = v.label();
3371 
3372  v = view_type(); // Deallocate first, if the only view to allocation
3373  v = view_type(label, layout);
3374 }
3375 } /* namespace Kokkos */
3376 
3377 //----------------------------------------------------------------------------
3378 //----------------------------------------------------------------------------
3379 
3380 namespace Kokkos {
3381 namespace Impl {
3382 
3383 // Deduce Mirror Types
3384 template <class Space, class T, class... P>
3385 struct MirrorViewType {
3386  // The incoming view_type
3387  typedef typename Kokkos::View<T, P...> src_view_type;
3388  // The memory space for the mirror view
3389  typedef typename Space::memory_space memory_space;
3390  // Check whether it is the same memory space
3391  enum {
3392  is_same_memspace =
3393  std::is_same<memory_space, typename src_view_type::memory_space>::value
3394  };
3395  // The array_layout
3396  typedef typename src_view_type::array_layout array_layout;
3397  // The data type (we probably want it non-const since otherwise we can't even
3398  // deep_copy to it.
3399  typedef typename src_view_type::non_const_data_type data_type;
3400  // The destination view type if it is not the same memory space
3401  typedef Kokkos::View<data_type, array_layout, Space> dest_view_type;
3402  // If it is the same memory_space return the existsing view_type
3403  // This will also keep the unmanaged trait if necessary
3404  typedef typename std::conditional<is_same_memspace, src_view_type,
3405  dest_view_type>::type view_type;
3406 };
3407 
3408 template <class Space, class T, class... P>
3409 struct MirrorType {
3410  // The incoming view_type
3411  typedef typename Kokkos::View<T, P...> src_view_type;
3412  // The memory space for the mirror view
3413  typedef typename Space::memory_space memory_space;
3414  // Check whether it is the same memory space
3415  enum {
3416  is_same_memspace =
3417  std::is_same<memory_space, typename src_view_type::memory_space>::value
3418  };
3419  // The array_layout
3420  typedef typename src_view_type::array_layout array_layout;
3421  // The data type (we probably want it non-const since otherwise we can't even
3422  // deep_copy to it.
3423  typedef typename src_view_type::non_const_data_type data_type;
3424  // The destination view type if it is not the same memory space
3426 };
3427 
3428 } // namespace Impl
3429 
3430 template <class T, class... P>
3431 inline typename Kokkos::View<T, P...>::HostMirror create_mirror(
3432  const Kokkos::View<T, P...>& src,
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,
3436  Kokkos::LayoutStride>::value>::type* = nullptr) {
3437  typedef View<T, P...> src_type;
3438  typedef typename src_type::HostMirror dst_type;
3439 
3440  return dst_type(std::string(src.label()).append("_mirror")
3441 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
3442  ,
3443  src.extent(0), src.extent(1), src.extent(2), src.extent(3),
3444  src.extent(4), src.extent(5), src.extent(6), src.extent(7));
3445 #else
3446  ,
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);
3463 #endif
3464 }
3465 
3466 template <class T, class... P>
3467 inline typename Kokkos::View<T, P...>::HostMirror create_mirror(
3468  const Kokkos::View<T, P...>& src,
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,
3472  Kokkos::LayoutStride>::value>::type* = nullptr) {
3473  typedef View<T, P...> src_type;
3474  typedef typename src_type::HostMirror dst_type;
3475 
3476  Kokkos::LayoutStride layout;
3477 
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);
3486 
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();
3495 
3496  return dst_type(std::string(src.label()).append("_mirror"), layout);
3497 }
3498 
3499 // Create a mirror in a new space (specialization for different space)
3500 template <class Space, class T, class... P>
3501 typename Impl::MirrorType<Space, T, P...>::view_type create_mirror(
3502  const Space&, const Kokkos::View<T, P...>& src,
3503  typename std::enable_if<std::is_same<
3504  typename ViewTraits<T, P...>::specialize, void>::value>::type* =
3505  nullptr) {
3506  return typename Impl::MirrorType<Space, T, P...>::view_type(src.label(),
3507  src.layout());
3508 }
3509 
3510 template <class T, class... P>
3511 inline typename Kokkos::View<T, P...>::HostMirror create_mirror_view(
3512  const Kokkos::View<T, P...>& src,
3513  typename std::enable_if<
3514  (std::is_same<
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) {
3520  return src;
3521 }
3522 
3523 template <class T, class... P>
3524 inline typename Kokkos::View<T, P...>::HostMirror create_mirror_view(
3525  const Kokkos::View<T, P...>& src,
3526  typename std::enable_if<!(
3527  std::is_same<
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);
3534 }
3535 
3536 // Create a mirror view in a new space (specialization for same space)
3537 template <class Space, class T, class... P>
3538 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3539  const Space&, const Kokkos::View<T, P...>& src,
3540  typename std::enable_if<
3541  Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
3542  nullptr) {
3543  return src;
3544 }
3545 
3546 // Create a mirror view in a new space (specialization for different space)
3547 template <class Space, class T, class... P>
3548 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3549  const Space&, const Kokkos::View<T, P...>& src,
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(),
3553  src.layout());
3554 }
3555 
3556 // Create a mirror view and deep_copy in a new space (specialization for same
3557 // space)
3558 template <class Space, class T, class... P>
3559 typename Impl::MirrorViewType<Space, T, P...>::view_type
3560 create_mirror_view_and_copy(
3561  const Space&, const Kokkos::View<T, P...>& src,
3562  std::string const& name = "",
3563  typename std::enable_if<
3564  Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
3565  nullptr) {
3566  (void)name;
3567  fence(); // same behavior as deep_copy(src, src)
3568  return src;
3569 }
3570 
3571 // Create a mirror view and deep_copy in a new space (specialization for
3572 // different space)
3573 template <class Space, class T, class... P>
3574 typename Impl::MirrorViewType<Space, T, P...>::view_type
3575 create_mirror_view_and_copy(
3576  const Space&, const Kokkos::View<T, P...>& src,
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()};
3584  deep_copy(mirror, src);
3585  return mirror;
3586 }
3587 
3588 // Create a mirror view in a new space without initializing (specialization for
3589 // same space)
3590 template <class Space, class T, class... P>
3591 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3592  const Space&, const Kokkos::View<T, P...>& src,
3593  Kokkos::Impl::WithoutInitializing_t,
3594  typename std::enable_if<
3595  Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type* =
3596  nullptr) {
3597  return src;
3598 }
3599 
3600 // Create a mirror view in a new space without initializing (specialization for
3601 // different space)
3602 template <class Space, class T, class... P>
3603 typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
3604  const Space&, const Kokkos::View<T, P...>& src,
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()),
3610  src.layout());
3611 }
3612 
3613 } /* namespace Kokkos */
3614 
3615 //----------------------------------------------------------------------------
3616 //----------------------------------------------------------------------------
3617 
3618 #endif
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.
Definition: Kokkos_Pair.hpp:65
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.