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. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_COPYVIEWS_HPP_
45 #define KOKKOS_COPYVIEWS_HPP_
46 #include <string>
47 
48 //----------------------------------------------------------------------------
49 //----------------------------------------------------------------------------
50 
51 #ifndef KOKKOS_IMPL_COMPILING_LIBRARY
52 #define KOKKOS_IMPL_COMPILING_LIBRARY false
53 #endif
54 
55 namespace Kokkos {
56 
57 namespace Impl {
58 
59 template<class Layout>
60 struct ViewFillLayoutSelector {
61 };
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,bool ETIAvail>
82 struct ViewFill<ViewType,Layout,ExecSpace,0,iType,ETIAvail> {
83  ViewType a;
84  typename ViewType::const_value_type val;
85  typedef typename ViewType::non_const_value_type ST;
86  ViewFill(const ViewType&, const ST&);
87 };
88 
89 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
90 struct ViewFill<ViewType,Layout,ExecSpace,1,iType,ETIAvail> {
91  ViewType a;
92  typename ViewType::const_value_type val;
93  typedef typename ViewType::non_const_value_type ST;
94  ViewFill(const ViewType&, const ST&);
95  KOKKOS_INLINE_FUNCTION
96  void operator() (const iType&) const;
97 };
98 
99 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
100 struct ViewFill<ViewType,Layout,ExecSpace,2,iType,ETIAvail> {
101  ViewType a;
102  typename ViewType::const_value_type val;
103  typedef typename ViewType::non_const_value_type ST;
104  ViewFill(const ViewType&, const ST&);
105  KOKKOS_INLINE_FUNCTION
106  void operator() (const iType&, const iType&) const;
107 };
108 
109 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
110 struct ViewFill<ViewType,Layout,ExecSpace,3,iType,ETIAvail> {
111  ViewType a;
112  typename ViewType::const_value_type val;
113  typedef typename ViewType::non_const_value_type ST;
114  ViewFill(const ViewType&, const ST&);
115  KOKKOS_INLINE_FUNCTION
116  void operator() (const iType&, const iType&, const iType&) const;
117 };
118 
119 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
120 struct ViewFill<ViewType,Layout,ExecSpace,4,iType,ETIAvail> {
121  ViewType a;
122  typename ViewType::const_value_type val;
123  typedef typename ViewType::non_const_value_type ST;
124  ViewFill(const ViewType&, const ST&);
125  KOKKOS_INLINE_FUNCTION
126  void operator() (const iType&, const iType&, const iType&, const iType&) const;
127 };
128 
129 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
130 struct ViewFill<ViewType,Layout,ExecSpace,5,iType,ETIAvail> {
131  ViewType a;
132  typename ViewType::const_value_type val;
133  typedef typename ViewType::non_const_value_type ST;
134  ViewFill(const ViewType&, const ST&);
135  KOKKOS_INLINE_FUNCTION
136  void operator() (const iType&, const iType&, const iType&, const iType&,
137  const iType&) const;
138 };
139 
140 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
141 struct ViewFill<ViewType,Layout,ExecSpace,6,iType,ETIAvail> {
142  ViewType a;
143  typename ViewType::const_value_type val;
144  typedef typename ViewType::non_const_value_type ST;
145  ViewFill(const ViewType&, const ST&);
146  KOKKOS_INLINE_FUNCTION
147  void operator() (const iType&, const iType&, const iType&, const iType&,
148  const iType&, const iType&) const;
149 };
150 
151 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
152 struct ViewFill<ViewType,Layout,ExecSpace,7,iType,ETIAvail> {
153  ViewType a;
154  typename ViewType::const_value_type val;
155  typedef typename ViewType::non_const_value_type ST;
156  ViewFill(const ViewType&, const ST&);
157  KOKKOS_INLINE_FUNCTION
158  void operator() (const iType&, const iType&, const iType&, const iType&,
159  const iType&, const iType&, const iType&) const;
160 };
161 
162 template<class ViewType,class Layout, class ExecSpace,typename iType,bool ETIAvail>
163 struct ViewFill<ViewType,Layout,ExecSpace,8,iType,ETIAvail> {
164  ViewType a;
165  typename ViewType::const_value_type val;
166  typedef typename ViewType::non_const_value_type ST;
167  ViewFill(const ViewType&, const ST&);
168  KOKKOS_INLINE_FUNCTION
169  void operator() (const iType&, const iType&, const iType&, const iType&,
170  const iType&, const iType&, const iType&, const iType&) const;
171 };
172 
173 template<class ViewType,class Layout, class ExecSpace,typename iType>
174 struct ViewFill<ViewType,Layout,ExecSpace,0,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
175  typedef typename ViewType::non_const_value_type ST;
176  ViewFill(const ViewType& a, const ST& val) {
177  Kokkos::Impl::DeepCopy< typename ViewType::memory_space, Kokkos::HostSpace >( a.data() , &val, sizeof(ST) );
178  }
179 };
180 
181 
182 template<class ViewType,class Layout, class ExecSpace,typename iType>
183 struct ViewFill<ViewType,Layout,ExecSpace,1,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
184  ViewType a;
185  typename ViewType::const_value_type val;
187 
188  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
189  ExecSpace().fence();
190  Kokkos::parallel_for("Kokkos::ViewFill-1D",policy_type(0,a.extent(0)),*this);
191  ExecSpace().fence();
192  }
193 
194  KOKKOS_INLINE_FUNCTION
195  void operator() (const iType& i) const {
196  a(i) = val;
197  };
198 };
199 
200 template<class ViewType,class Layout, class ExecSpace,typename iType>
201 struct ViewFill<ViewType,Layout,ExecSpace,2,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
202  ViewType a;
203  typename ViewType::const_value_type val;
204 
205  typedef Kokkos::Rank<2,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
206  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
207 
208  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
209  ExecSpace().fence();
210  Kokkos::parallel_for("Kokkos::ViewFill-2D",
211  policy_type({0,0},{a.extent(0),a.extent(1)}),*this);
212  ExecSpace().fence();
213  }
214 
215  KOKKOS_INLINE_FUNCTION
216  void operator() (const iType& i0, const iType& i1) const {
217  a(i0,i1) = val;
218  };
219 };
220 
221 template<class ViewType,class Layout, class ExecSpace,typename iType>
222 struct ViewFill<ViewType,Layout,ExecSpace,3,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
223  ViewType a;
224  typename ViewType::const_value_type val;
225 
226  typedef Kokkos::Rank<3,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
227  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
228 
229  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
230  ExecSpace().fence();
231  Kokkos::parallel_for("Kokkos::ViewFill-3D",
232  policy_type({0,0,0},{a.extent(0),a.extent(1),a.extent(2)}),*this);
233  ExecSpace().fence();
234  }
235 
236  KOKKOS_INLINE_FUNCTION
237  void operator() (const iType& i0, const iType& i1, const iType& i2) const {
238  a(i0,i1,i2) = val;
239  };
240 };
241 
242 template<class ViewType,class Layout, class ExecSpace,typename iType>
243 struct ViewFill<ViewType,Layout,ExecSpace,4,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
244  ViewType a;
245  typename ViewType::const_value_type val;
246 
247  typedef Kokkos::Rank<4,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
248  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
249 
250  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
251  ExecSpace().fence();
252  Kokkos::parallel_for("Kokkos::ViewFill-4D",
253  policy_type({0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3)}),*this);
254  ExecSpace().fence();
255  }
256 
257  KOKKOS_INLINE_FUNCTION
258  void operator() (const iType& i0, const iType& i1, const iType& i2, const iType& i3) const {
259  a(i0,i1,i2,i3) = val;
260  };
261 };
262 
263 template<class ViewType,class Layout, class ExecSpace,typename iType>
264 struct ViewFill<ViewType,Layout,ExecSpace,5,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
265  ViewType a;
266  typename ViewType::const_value_type val;
267 
268  typedef Kokkos::Rank<5,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
269  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
270 
271  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
272  ExecSpace().fence();
273  Kokkos::parallel_for("Kokkos::ViewFill-5D",
274  policy_type({0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3),a.extent(4)}),*this);
275  ExecSpace().fence();
276  }
277 
278  KOKKOS_INLINE_FUNCTION
279  void operator() (const iType& i0, const iType& i1, const iType& i2, const iType& i3, const iType& i4) const {
280  a(i0,i1,i2,i3,i4) = val;
281  };
282 };
283 
284 template<class ViewType,class Layout, class ExecSpace,typename iType>
285 struct ViewFill<ViewType,Layout,ExecSpace,6,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
286  ViewType a;
287  typename ViewType::const_value_type val;
288 
289  typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
290  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
291 
292  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
293  ExecSpace().fence();
294  Kokkos::parallel_for("Kokkos::ViewFill-6D",
295  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3),a.extent(4),a.extent(5)}),*this);
296  ExecSpace().fence();
297  }
298 
299  KOKKOS_INLINE_FUNCTION
300  void operator() (const iType& i0, const iType& i1, const iType& i2, const iType& i3, const iType& i4, const iType& i5) const {
301  a(i0,i1,i2,i3,i4,i5) = val;
302  };
303 };
304 
305 template<class ViewType,class Layout, class ExecSpace,typename iType>
306 struct ViewFill<ViewType,Layout,ExecSpace,7,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
307  ViewType a;
308  typename ViewType::const_value_type val;
309 
310  typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
311  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
312 
313  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
314  ExecSpace().fence();
315  Kokkos::parallel_for("Kokkos::ViewFill-7D",
316  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),a.extent(3),
317  a.extent(5),a.extent(6)}),*this);
318  ExecSpace().fence();
319  }
320 
321  KOKKOS_INLINE_FUNCTION
322  void operator() (const iType& i0, const iType& i1, const iType& i3,
323  const iType& i4, const iType& i5, const iType& i6) const {
324  for(iType i2=0; i2<iType(a.extent(2));i2++)
325  a(i0,i1,i2,i3,i4,i5,i6) = val;
326  };
327 };
328 
329 template<class ViewType,class Layout, class ExecSpace,typename iType>
330 struct ViewFill<ViewType,Layout,ExecSpace,8,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
331  ViewType a;
332  typename ViewType::const_value_type val;
333 
334  typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
335  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
336 
337  ViewFill(const ViewType& a_, typename ViewType::const_value_type& val_):a(a_),val(val_) {
338  ExecSpace().fence();
339  Kokkos::parallel_for("Kokkos::ViewFill-8D",
340  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
341  a.extent(5),a.extent(6),a.extent(7)}),*this);
342  ExecSpace().fence();
343  }
344 
345  KOKKOS_INLINE_FUNCTION
346  void operator() (const iType& i0, const iType& i1, const iType& i3,
347  const iType& i5, const iType& i6, const iType& i7) const {
348  for(iType i2=0; i2<iType(a.extent(2));i2++)
349  for(iType i4=0; i4<iType(a.extent(4));i4++)
350  a(i0,i1,i2,i3,i4,i5,i6,i7) = val;
351  };
352 };
353 
354 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
355 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,1,iType,ETIAvail> {
356  ViewTypeA a;
357  ViewTypeB b;
358  ViewCopy(const ViewTypeA&, const ViewTypeB&);
359  KOKKOS_INLINE_FUNCTION
360  void operator() (const iType& i0) const;
361 };
362 
363 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
364 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,2,iType,ETIAvail> {
365  ViewTypeA a;
366  ViewTypeB b;
367  ViewCopy(const ViewTypeA&, const ViewTypeB&);
368  KOKKOS_INLINE_FUNCTION
369  void operator() (const iType& i0,const iType& i1) const;
370 };
371 
372 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
373 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,3,iType,ETIAvail> {
374  ViewTypeA a;
375  ViewTypeB b;
376  ViewCopy(const ViewTypeA&, const ViewTypeB&);
377  KOKKOS_INLINE_FUNCTION
378  void operator() (const iType& i0,const iType& i1,const iType& i2) const;
379 };
380 
381 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
382 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,4,iType,ETIAvail> {
383  ViewTypeA a;
384  ViewTypeB b;
385  ViewCopy(const ViewTypeA&, const ViewTypeB&);
386  KOKKOS_INLINE_FUNCTION
387  void operator() (const iType& i0,const iType& i1,const iType& i2,const iType& i3) const;
388 };
389 
390 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
391 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,5,iType,ETIAvail> {
392  ViewTypeA a;
393  ViewTypeB b;
394  ViewCopy(const ViewTypeA&, const ViewTypeB&);
395  KOKKOS_INLINE_FUNCTION
396  void operator() (const iType& i0,const iType& i1,const iType& i2,const iType& i3,
397  const iType& i4) const;
398 };
399 
400 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
401 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,6,iType,ETIAvail> {
402  ViewTypeA a;
403  ViewTypeB b;
404  ViewCopy(const ViewTypeA&, const ViewTypeB&);
405  KOKKOS_INLINE_FUNCTION
406  void operator() (const iType& i0,const iType& i1,const iType& i2,const iType& i3,
407  const iType& i4,const iType& i5) const;
408 };
409 
410 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
411 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,7,iType,ETIAvail> {
412  ViewTypeA a;
413  ViewTypeB b;
414  ViewCopy(const ViewTypeA&, const ViewTypeB&);
415  KOKKOS_INLINE_FUNCTION
416  void operator() (const iType& i0,const iType& i1,const iType& i2,const iType& i3,
417  const iType& i4,const iType& i5,const iType& i6) const;
418 };
419 
420 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType, bool ETIAvail>
421 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,8,iType,ETIAvail> {
422  ViewTypeA a;
423  ViewTypeB b;
424  ViewCopy(const ViewTypeA&, const ViewTypeB&);
425  KOKKOS_INLINE_FUNCTION
426  void operator() (const iType& i0,const iType& i1,const iType& i2,const iType& i3,
427  const iType& i4,const iType& i5,const iType& i6,const iType& i7) const;
428 };
429 
430 
431 
432 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
433 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,1,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
434  ViewTypeA a;
435  ViewTypeB b;
436 
438 
439  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
440  ExecSpace().fence();
441  Kokkos::parallel_for("Kokkos::ViewCopy-1D",
442  policy_type(0,a.extent(0)),*this);
443  ExecSpace().fence();
444  }
445 
446  KOKKOS_INLINE_FUNCTION
447  void operator() (const iType& i0) const {
448  a(i0) = b(i0);
449  };
450 };
451 
452 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
453 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,2,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
454  ViewTypeA a;
455  ViewTypeB b;
456  static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
457  static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
458  typedef Kokkos::Rank<2,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
459  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
460 
461  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
462  ExecSpace().fence();
463  Kokkos::parallel_for("Kokkos::ViewCopy-2D",
464  policy_type({0,0},{a.extent(0),a.extent(1)}),*this);
465  ExecSpace().fence();
466  }
467 
468  KOKKOS_INLINE_FUNCTION
469  void operator() (const iType& i0, const iType& i1) const {
470  a(i0,i1) = b(i0,i1);
471  };
472 };
473 
474 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
475 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,3,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
476  ViewTypeA a;
477  ViewTypeB b;
478 
479  static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
480  static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
481  typedef Kokkos::Rank<3,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
482  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
483 
484  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
485  ExecSpace().fence();
486  Kokkos::parallel_for("Kokkos::ViewCopy-3D",
487  policy_type({0,0,0},{a.extent(0),a.extent(1),a.extent(2)}),*this);
488  ExecSpace().fence();
489  }
490 
491  KOKKOS_INLINE_FUNCTION
492  void operator() (const iType& i0, const iType& i1, const iType& i2) const {
493  a(i0,i1,i2) = b(i0,i1,i2);
494  };
495 };
496 
497 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
498 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,4,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
499  ViewTypeA a;
500  ViewTypeB b;
501 
502  static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
503  static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
504  typedef Kokkos::Rank<4,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
505  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
506 
507  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
508  ExecSpace().fence();
509  Kokkos::parallel_for("Kokkos::ViewCopy-4D",
510  policy_type({0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
511  a.extent(3)}),*this);
512  ExecSpace().fence();
513  }
514 
515  KOKKOS_INLINE_FUNCTION
516  void operator() (const iType& i0, const iType& i1, const iType& i2,
517  const iType& i3) const {
518  a(i0,i1,i2,i3) = b(i0,i1,i2,i3);
519  };
520 };
521 
522 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
523 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,5,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
524  ViewTypeA a;
525  ViewTypeB b;
526 
527  static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
528  static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
529  typedef Kokkos::Rank<5,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
530  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
531 
532  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
533  ExecSpace().fence();
534  Kokkos::parallel_for("Kokkos::ViewCopy-5D",
535  policy_type({0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
536  a.extent(3),a.extent(4)}),*this);
537  ExecSpace().fence();
538  }
539 
540  KOKKOS_INLINE_FUNCTION
541  void operator() (const iType& i0, const iType& i1, const iType& i2,
542  const iType& i3, const iType& i4) const {
543  a(i0,i1,i2,i3,i4) = b(i0,i1,i2,i3,i4);
544  };
545 };
546 
547 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
548 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,6,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
549  ViewTypeA a;
550  ViewTypeB b;
551 
552  static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
553  static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
554  typedef Kokkos::Rank<6,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
555  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
556 
557  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
558  ExecSpace().fence();
559  Kokkos::parallel_for("Kokkos::ViewCopy-6D",
560  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
561  a.extent(3),a.extent(4),a.extent(5)}),*this);
562  ExecSpace().fence();
563  }
564 
565  KOKKOS_INLINE_FUNCTION
566  void operator() (const iType& i0, const iType& i1, const iType& i2,
567  const iType& i3, const iType& i4, const iType& i5) const {
568  a(i0,i1,i2,i3,i4,i5) = b(i0,i1,i2,i3,i4,i5);
569  };
570 };
571 
572 
573 template<class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,typename iType>
574 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,7,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
575  ViewTypeA a;
576  ViewTypeB b;
577 
578  static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
579  static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
580  typedef Kokkos::Rank<6,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
581  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
582 
583  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
584  ExecSpace().fence();
585  Kokkos::parallel_for("Kokkos::ViewCopy-7D",
586  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
587  a.extent(4),a.extent(5),a.extent(6)}),*this);
588  ExecSpace().fence();
589  }
590 
591  KOKKOS_INLINE_FUNCTION
592  void operator() (const iType& i0, const iType& i1, const iType& i3,
593  const iType& i4, const iType& i5, const iType& i6) const {
594  for(iType i2=0; i2<iType(a.extent(2));i2++)
595  a(i0,i1,i2,i3,i4,i5,i6) = b(i0,i1,i2,i3,i4,i5,i6);
596  };
597 };
598 
599 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
600 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,8,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
601  ViewTypeA a;
602  ViewTypeB b;
603 
604  static const Kokkos::Iterate outer_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::outer_iteration_pattern;
605  static const Kokkos::Iterate inner_iteration_pattern = Kokkos::layout_iterate_type_selector<Layout>::inner_iteration_pattern;
606  typedef Kokkos::Rank<6,outer_iteration_pattern,inner_iteration_pattern> iterate_type;
607  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
608 
609  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
610  ExecSpace().fence();
611  Kokkos::parallel_for("Kokkos::ViewCopy-8D",
612  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
613  a.extent(5),a.extent(6),a.extent(7)}),*this);
614  ExecSpace().fence();
615  }
616 
617  KOKKOS_INLINE_FUNCTION
618  void operator() (const iType& i0, const iType& i1, const iType& i3,
619  const iType& i5, const iType& i6, const iType& i7) const {
620  for(iType i2=0; i2<iType(a.extent(2));i2++)
621  for(iType i4=0; i4<iType(a.extent(4));i4++)
622  a(i0,i1,i2,i3,i4,i5,i6,i7) = b(i0,i1,i2,i3,i4,i5,i6,i7);
623  };
624 };
625 
626 }
627 }
628 
629 #include<impl/Kokkos_ViewFillCopyETIDecl.hpp>
630 
631 namespace Kokkos {
632 namespace Impl {
633 
634 template<class DstType, class SrcType>
635 void view_copy(const DstType& dst, const SrcType& src) {
636  typedef typename DstType::execution_space dst_execution_space;
637  typedef typename SrcType::execution_space src_execution_space;
638  typedef typename DstType::memory_space dst_memory_space;
639  typedef typename SrcType::memory_space src_memory_space;
640 
641  enum { DstExecCanAccessSrc =
643 
644  enum { SrcExecCanAccessDst =
646 
647  if( ! DstExecCanAccessSrc && ! SrcExecCanAccessDst) {
648  std::string message("Error: Kokkos::deep_copy with no available copy mechanism: ");
649  message += src.label(); message += " to ";
650  message += dst.label();
651  Kokkos::Impl::throw_runtime_exception(message);
652  }
653 
654  // Figure out iteration order in case we need it
655  int64_t strides[DstType::Rank+1];
656  dst.stride(strides);
657  Kokkos::Iterate iterate;
658  if ( Kokkos::is_layouttiled<typename DstType::array_layout>::value ) {
659  iterate = Kokkos::layout_iterate_type_selector<typename DstType::array_layout>::outer_iteration_pattern;
660  } else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutRight>::value ) {
661  iterate = Kokkos::Iterate::Right;
662  } else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutLeft>::value ) {
663  iterate = Kokkos::Iterate::Left;
664  } else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutStride>::value ) {
665  if( strides[0] > strides[DstType::Rank-1] )
666  iterate = Kokkos::Iterate::Right;
667  else
668  iterate = Kokkos::Iterate::Left;
669  } else {
670  if( std::is_same<typename DstType::execution_space::array_layout, Kokkos::LayoutRight>::value )
671  iterate = Kokkos::Iterate::Right;
672  else
673  iterate = Kokkos::Iterate::Left;
674  }
675 
676  if( (dst.span() >= size_t(std::numeric_limits<int>::max())) ||
677  (src.span() >= size_t(std::numeric_limits<int>::max())) ){
678  if(DstExecCanAccessSrc) {
679  if(iterate == Kokkos::Iterate::Right)
680  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, dst_execution_space,
681  DstType::Rank, int64_t >( dst , src );
682  else
683  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, dst_execution_space,
684  DstType::Rank, int64_t >( dst , src );
685  } else {
686  if(iterate == Kokkos::Iterate::Right)
687  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, src_execution_space,
688  DstType::Rank, int64_t >( dst , src );
689  else
690  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, src_execution_space,
691  DstType::Rank, int64_t >( dst , src );
692  }
693  } else {
694  if(DstExecCanAccessSrc) {
695  if(iterate == Kokkos::Iterate::Right)
696  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, dst_execution_space,
697  DstType::Rank, int >( dst , src );
698  else
699  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, dst_execution_space,
700  DstType::Rank, int >( dst , src );
701  } else {
702  if(iterate == Kokkos::Iterate::Right)
703  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, src_execution_space,
704  DstType::Rank, int >( dst , src );
705  else
706  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, src_execution_space,
707  DstType::Rank, int >( dst , src );
708  }
709 
710  }
711 }
712 
713 template<class DstType, class SrcType, int Rank, class ... Args>
714 struct CommonSubview;
715 
716 template<class DstType, class SrcType, class Arg0, class ... Args>
717 struct CommonSubview<DstType,SrcType,1,Arg0,Args...> {
718  typedef typename Kokkos::Subview<DstType,Arg0> dst_subview_type;
719  typedef typename Kokkos::Subview<SrcType,Arg0> src_subview_type;
720  dst_subview_type dst_sub;
721  src_subview_type src_sub;
722  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, Args... ):
723  dst_sub(dst,arg0),src_sub(src,arg0) {}
724 };
725 
726 template<class DstType, class SrcType, class Arg0, class Arg1, class ... Args>
727 struct CommonSubview<DstType,SrcType,2,Arg0,Arg1,Args...> {
728  typedef typename Kokkos::Subview<DstType,Arg0,Arg1> dst_subview_type;
729  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1> src_subview_type;
730  dst_subview_type dst_sub;
731  src_subview_type src_sub;
732  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1, Args... ):
733  dst_sub(dst,arg0,arg1),src_sub(src,arg0,arg1) {}
734 };
735 
736 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class ... Args>
737 struct CommonSubview<DstType,SrcType,3,Arg0,Arg1,Arg2,Args...> {
738  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2> dst_subview_type;
739  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2> src_subview_type;
740  dst_subview_type dst_sub;
741  src_subview_type src_sub;
742  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
743  const Arg2& arg2, Args... ):
744  dst_sub(dst,arg0,arg1,arg2),src_sub(src,arg0,arg1,arg2) {}
745 };
746 
747 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
748  class ... Args>
749 struct CommonSubview<DstType,SrcType,4,Arg0,Arg1,Arg2,Arg3,Args...> {
750  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3> dst_subview_type;
751  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3> src_subview_type;
752  dst_subview_type dst_sub;
753  src_subview_type src_sub;
754  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
755  const Arg2& arg2, const Arg3& arg3,
756  const Args ...):
757  dst_sub(dst,arg0,arg1,arg2,arg3),src_sub(src,arg0,arg1,arg2,arg3) {}
758 };
759 
760 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
761  class Arg4, class ... Args>
762 struct CommonSubview<DstType,SrcType,5,Arg0,Arg1,Arg2,Arg3,Arg4,Args...> {
763  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4> dst_subview_type;
764  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4> src_subview_type;
765  dst_subview_type dst_sub;
766  src_subview_type src_sub;
767  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
768  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4,
769  const Args ...):
770  dst_sub(dst,arg0,arg1,arg2,arg3,arg4),src_sub(src,arg0,arg1,arg2,arg3,arg4) {}
771 };
772 
773 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
774  class Arg4, class Arg5, class ... Args>
775 struct CommonSubview<DstType,SrcType,6,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Args...> {
776  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5> dst_subview_type;
777  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5> src_subview_type;
778  dst_subview_type dst_sub;
779  src_subview_type src_sub;
780  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
781  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5,
782  const Args ...):
783  dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5) {}
784 };
785 
786 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
787  class Arg4, class Arg5, class Arg6, class ...Args>
788 struct CommonSubview<DstType,SrcType,7,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Args...> {
789  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6> dst_subview_type;
790  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6> src_subview_type;
791  dst_subview_type dst_sub;
792  src_subview_type src_sub;
793  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
794  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5,
795  const Arg6& arg6, Args...):
796  dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5,arg6),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5,arg6) {}
797 };
798 
799 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
800  class Arg4, class Arg5, class Arg6, class Arg7>
801 struct CommonSubview<DstType,SrcType,8,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> {
802  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> dst_subview_type;
803  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> src_subview_type;
804  dst_subview_type dst_sub;
805  src_subview_type src_sub;
806  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
807  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5,
808  const Arg6& arg6, const Arg7& arg7):
809  dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7) {}
810 };
811 
812 
813 template<class DstType, class SrcType, class ExecSpace = typename DstType::execution_space, int Rank = DstType::Rank>
814 struct ViewRemap;
815 
816 template<class DstType, class SrcType, class ExecSpace>
817 struct ViewRemap<DstType,SrcType,ExecSpace,1> {
818  typedef Kokkos::pair<int64_t,int64_t> p_type;
819 
820  ViewRemap(const DstType& dst, const SrcType& src) {
821  if(dst.extent(0) == src.extent(0)) {
822  view_copy(dst,src);
823  } else {
824  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
825  typedef CommonSubview<DstType,SrcType,1,p_type> sv_adapter_type;
826  sv_adapter_type common_subview(dst,src,ext0);
827  view_copy(common_subview.dst_sub,common_subview.src_sub);
828  }
829  }
830 };
831 
832 template<class DstType, class SrcType, class ExecSpace>
833 struct ViewRemap<DstType,SrcType,ExecSpace,2> {
834  typedef Kokkos::pair<int64_t,int64_t> p_type;
835 
836  ViewRemap(const DstType& dst, const SrcType& src) {
837  if(dst.extent(0) == src.extent(0)) {
838  if(dst.extent(1) == src.extent(1)) {
839  view_copy(dst,src);
840  } else {
841  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
842  typedef CommonSubview<DstType,SrcType,2,Kokkos::Impl::ALL_t,p_type> sv_adapter_type;
843  sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1);
844  view_copy(common_subview.dst_sub,common_subview.src_sub);
845  }
846  } else {
847  if(dst.extent(1) == src.extent(1)) {
848  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
849  typedef CommonSubview<DstType,SrcType,2,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
850  sv_adapter_type common_subview(dst,src,ext0,Kokkos::ALL);
851  view_copy(common_subview.dst_sub,common_subview.src_sub);
852  } else {
853  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
854  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
855  typedef CommonSubview<DstType,SrcType,2,p_type,p_type> sv_adapter_type;
856  sv_adapter_type common_subview(dst,src,ext0,ext1);
857  view_copy(common_subview.dst_sub,common_subview.src_sub);
858  }
859  }
860  }
861 };
862 
863 template<class DstType, class SrcType, class ExecSpace>
864 struct ViewRemap<DstType,SrcType,ExecSpace,3> {
865  typedef Kokkos::pair<int64_t,int64_t> p_type;
866 
867  ViewRemap(const DstType& dst, const SrcType& src) {
868  if(dst.extent(0) == src.extent(0)) {
869  if(dst.extent(2) == src.extent(2)) {
870  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
871  typedef CommonSubview<DstType,SrcType,3,Kokkos::Impl::ALL_t,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
872  sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1,Kokkos::ALL);
873  view_copy(common_subview.dst_sub,common_subview.src_sub);
874  } else {
875  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
876  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
877  typedef CommonSubview<DstType,SrcType,3,Kokkos::Impl::ALL_t,p_type,p_type> sv_adapter_type;
878  sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1,ext2);
879  view_copy(common_subview.dst_sub,common_subview.src_sub);
880  }
881  } else {
882  if(dst.extent(2) == src.extent(2)) {
883  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
884  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
885  typedef CommonSubview<DstType,SrcType,3,p_type,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
886  sv_adapter_type common_subview(dst,src,ext0,ext1,Kokkos::ALL);
887  view_copy(common_subview.dst_sub,common_subview.src_sub);
888  } else {
889  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
890  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
891  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
892  typedef CommonSubview<DstType,SrcType,3,p_type,p_type,p_type> sv_adapter_type;
893  sv_adapter_type common_subview(dst,src,ext0,ext1,ext2);
894  view_copy(common_subview.dst_sub,common_subview.src_sub);
895  }
896  }
897  }
898 };
899 
900 template<class DstType, class SrcType, class ExecSpace>
901 struct ViewRemap<DstType,SrcType,ExecSpace,4> {
902  typedef Kokkos::pair<int64_t,int64_t> p_type;
903 
904  ViewRemap(const DstType& dst, const SrcType& src) {
905  if(dst.extent(0) == src.extent(0)) {
906  if(dst.extent(3) == src.extent(3)) {
907  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
908  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
909  typedef CommonSubview<DstType,SrcType,4,Kokkos::Impl::ALL_t,
910  p_type,p_type,
911  Kokkos::Impl::ALL_t> sv_adapter_type;
912  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
913  ext1,ext2,
914  Kokkos::ALL);
915  view_copy(common_subview.dst_sub,common_subview.src_sub);
916  } else {
917  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
918  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
919  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
920  typedef CommonSubview<DstType,SrcType,4,Kokkos::Impl::ALL_t,
921  p_type,p_type,
922  p_type> sv_adapter_type;
923  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
924  ext1,ext2,
925  ext3);
926  view_copy(common_subview.dst_sub,common_subview.src_sub);
927  }
928  } else {
929  if(dst.extent(7) == src.extent(7)) {
930  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
931  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
932  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
933  typedef CommonSubview<DstType,SrcType,4,p_type,
934  p_type,p_type,
935  Kokkos::Impl::ALL_t> sv_adapter_type;
936  sv_adapter_type common_subview(dst,src,ext0,
937  ext1,ext2,
938  Kokkos::ALL);
939  view_copy(common_subview.dst_sub,common_subview.src_sub);
940  } else {
941  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
942  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
943  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
944  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
945  typedef CommonSubview<DstType,SrcType,4,p_type,
946  p_type,p_type,
947  p_type> sv_adapter_type;
948  sv_adapter_type common_subview(dst,src,ext0,
949  ext1,ext2,
950  ext3);
951  view_copy(common_subview.dst_sub,common_subview.src_sub);
952  }
953  }
954  }
955 };
956 
957 template<class DstType, class SrcType, class ExecSpace>
958 struct ViewRemap<DstType,SrcType,ExecSpace,5> {
959  typedef Kokkos::pair<int64_t,int64_t> p_type;
960 
961  ViewRemap(const DstType& dst, const SrcType& src) {
962  if(dst.extent(0) == src.extent(0)) {
963  if(dst.extent(4) == src.extent(4)) {
964  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
965  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
966  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
967  typedef CommonSubview<DstType,SrcType,5,Kokkos::Impl::ALL_t,
968  p_type,p_type,p_type,
969  Kokkos::Impl::ALL_t> sv_adapter_type;
970  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
971  ext1,ext2,ext3,
972  Kokkos::ALL);
973  view_copy(common_subview.dst_sub,common_subview.src_sub);
974  } else {
975  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
976  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
977  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
978  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
979  typedef CommonSubview<DstType,SrcType,5,Kokkos::Impl::ALL_t,
980  p_type,p_type,p_type,
981  p_type> sv_adapter_type;
982  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
983  ext1,ext2,ext3,
984  ext4);
985  view_copy(common_subview.dst_sub,common_subview.src_sub);
986  }
987  } else {
988  if(dst.extent(4) == src.extent(4)) {
989  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
990  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
991  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
992  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
993  typedef CommonSubview<DstType,SrcType,5,p_type,
994  p_type,p_type,p_type,
995  Kokkos::Impl::ALL_t> sv_adapter_type;
996  sv_adapter_type common_subview(dst,src,ext0,
997  ext1,ext2,ext3,
998  Kokkos::ALL);
999  view_copy(common_subview.dst_sub,common_subview.src_sub);
1000  } else {
1001  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1002  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1003  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1004  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1005  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1006  typedef CommonSubview<DstType,SrcType,5,p_type,
1007  p_type,p_type,p_type,
1008  p_type> sv_adapter_type;
1009  sv_adapter_type common_subview(dst,src,ext0,
1010  ext1,ext2,ext3,
1011  ext4);
1012  view_copy(common_subview.dst_sub,common_subview.src_sub);
1013  }
1014  }
1015  }
1016 };
1017 template<class DstType, class SrcType, class ExecSpace>
1018 struct ViewRemap<DstType,SrcType,ExecSpace,6> {
1019  typedef Kokkos::pair<int64_t,int64_t> p_type;
1020 
1021  ViewRemap(const DstType& dst, const SrcType& src) {
1022  if(dst.extent(0) == src.extent(0)) {
1023  if(dst.extent(5) == src.extent(5)) {
1024  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1025  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1026  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1027  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1028  typedef CommonSubview<DstType,SrcType,6,Kokkos::Impl::ALL_t,
1029  p_type,p_type,p_type,p_type,
1030  Kokkos::Impl::ALL_t> sv_adapter_type;
1031  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1032  ext1,ext2,ext3,ext4,
1033  Kokkos::ALL);
1034  view_copy(common_subview.dst_sub,common_subview.src_sub);
1035  } else {
1036  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1037  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1038  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1039  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1040  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1041  typedef CommonSubview<DstType,SrcType,6,Kokkos::Impl::ALL_t,
1042  p_type,p_type,p_type,p_type,
1043  p_type> sv_adapter_type;
1044  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1045  ext1,ext2,ext3,ext4,
1046  ext5);
1047  view_copy(common_subview.dst_sub,common_subview.src_sub);
1048  }
1049  } else {
1050  if(dst.extent(5) == src.extent(5)) {
1051  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1052  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1053  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1054  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1055  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1056 
1057  typedef CommonSubview<DstType,SrcType,6,p_type,
1058  p_type,p_type,p_type,p_type,
1059  Kokkos::Impl::ALL_t> sv_adapter_type;
1060  sv_adapter_type common_subview(dst,src,ext0,
1061  ext1,ext2,ext3,ext4,
1062  Kokkos::ALL);
1063  view_copy(common_subview.dst_sub,common_subview.src_sub);
1064  } else {
1065  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1066  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1067  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1068  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1069  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1070  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1071 
1072  typedef CommonSubview<DstType,SrcType,6,p_type,
1073  p_type,p_type,p_type,p_type,
1074  p_type> sv_adapter_type;
1075  sv_adapter_type common_subview(dst,src,ext0,
1076  ext1,ext2,ext3,ext4,
1077  ext5);
1078  view_copy(common_subview.dst_sub,common_subview.src_sub);
1079  }
1080  }
1081  }
1082 };
1083 
1084 template<class DstType, class SrcType, class ExecSpace>
1085 struct ViewRemap<DstType,SrcType,ExecSpace,7> {
1086  typedef Kokkos::pair<int64_t,int64_t> p_type;
1087 
1088  ViewRemap(const DstType& dst, const SrcType& src) {
1089  if(dst.extent(0) == src.extent(0)) {
1090  if(dst.extent(6) == src.extent(6)) {
1091  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1092  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1093  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1094  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1095  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1096  typedef CommonSubview<DstType,SrcType,7,Kokkos::Impl::ALL_t,
1097  p_type,p_type,p_type,p_type,p_type,
1098  Kokkos::Impl::ALL_t> sv_adapter_type;
1099  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1100  ext1,ext2,ext3,ext4,ext5,
1101  Kokkos::ALL);
1102  view_copy(common_subview.dst_sub,common_subview.src_sub);
1103  } else {
1104  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1105  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1106  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1107  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1108  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1109  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1110  typedef CommonSubview<DstType,SrcType,7,Kokkos::Impl::ALL_t,
1111  p_type,p_type,p_type,p_type,p_type,
1112  p_type> sv_adapter_type;
1113  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1114  ext1,ext2,ext3,ext4,ext5,
1115  ext6);
1116  view_copy(common_subview.dst_sub,common_subview.src_sub);
1117  }
1118  } else {
1119  if(dst.extent(6) == src.extent(6)) {
1120  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1121  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1122  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1123  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1124  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1125  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1126  typedef CommonSubview<DstType,SrcType,7,p_type,
1127  p_type,p_type,p_type,p_type,p_type,
1128  Kokkos::Impl::ALL_t> sv_adapter_type;
1129  sv_adapter_type common_subview(dst,src,ext0,
1130  ext1,ext2,ext3,ext4,ext5,
1131  Kokkos::ALL);
1132  view_copy(common_subview.dst_sub,common_subview.src_sub);
1133  } else {
1134  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1135  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1136  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1137  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1138  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1139  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1140  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1141  typedef CommonSubview<DstType,SrcType,7,p_type,
1142  p_type,p_type,p_type,p_type,p_type,
1143  p_type> sv_adapter_type;
1144  sv_adapter_type common_subview(dst,src,ext0,
1145  ext1,ext2,ext3,ext4,ext5,
1146  ext6);
1147  view_copy(common_subview.dst_sub,common_subview.src_sub);
1148  }
1149  }
1150  }
1151 };
1152 
1153 template<class DstType, class SrcType, class ExecSpace>
1154 struct ViewRemap<DstType,SrcType,ExecSpace,8> {
1155  typedef Kokkos::pair<int64_t,int64_t> p_type;
1156 
1157  ViewRemap(const DstType& dst, const SrcType& src) {
1158  if(dst.extent(0) == src.extent(0)) {
1159  if(dst.extent(7) == src.extent(7)) {
1160  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1161  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1162  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1163  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1164  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1165  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1166  typedef CommonSubview<DstType,SrcType,8,Kokkos::Impl::ALL_t,
1167  p_type,p_type,p_type,p_type,p_type,p_type,
1168  Kokkos::Impl::ALL_t> sv_adapter_type;
1169  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1170  ext1,ext2,ext3,ext4,ext5,ext6,
1171  Kokkos::ALL);
1172  view_copy(common_subview.dst_sub,common_subview.src_sub);
1173  } else {
1174  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1175  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1176  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1177  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1178  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1179  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1180  p_type ext7(0,std::min(dst.extent(7),src.extent(7)));
1181  typedef CommonSubview<DstType,SrcType,8,Kokkos::Impl::ALL_t,
1182  p_type,p_type,p_type,p_type,p_type,p_type,
1183  p_type> sv_adapter_type;
1184  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1185  ext1,ext2,ext3,ext4,ext5,ext6,
1186  ext7);
1187  view_copy(common_subview.dst_sub,common_subview.src_sub);
1188  }
1189  } else {
1190  if(dst.extent(7) == src.extent(7)) {
1191  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1192  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1193  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1194  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1195  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1196  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1197  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1198  typedef CommonSubview<DstType,SrcType,8,p_type,
1199  p_type,p_type,p_type,p_type,p_type,p_type,
1200  Kokkos::Impl::ALL_t> sv_adapter_type;
1201  sv_adapter_type common_subview(dst,src,ext0,
1202  ext1,ext2,ext3,ext4,ext5,ext6,
1203  Kokkos::ALL);
1204  view_copy(common_subview.dst_sub,common_subview.src_sub);
1205  } else {
1206  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1207  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1208  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1209  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1210  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1211  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1212  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1213  p_type ext7(0,std::min(dst.extent(7),src.extent(7)));
1214  typedef CommonSubview<DstType,SrcType,8,p_type,
1215  p_type,p_type,p_type,p_type,p_type,p_type,
1216  p_type> sv_adapter_type;
1217  sv_adapter_type common_subview(dst,src,ext0,
1218  ext1,ext2,ext3,ext4,ext5,ext6,
1219  ext7);
1220  view_copy(common_subview.dst_sub,common_subview.src_sub);
1221  }
1222  }
1223  }
1224 };
1225 
1226 }
1227 
1229 template< class DT , class ... DP >
1230 inline
1231 void deep_copy
1232  ( const View<DT,DP...> & dst
1233  , typename ViewTraits<DT,DP...>::const_value_type & value
1234  , typename std::enable_if<
1235  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1236  >::type * = 0 )
1237 {
1238  typedef View<DT,DP...> ViewType;
1239  if(dst.data() == NULL ) {
1240  Kokkos::fence();
1241  return;
1242  }
1243 
1244  Kokkos::fence();
1245  static_assert(
1246  std::is_same< typename ViewType::non_const_value_type ,
1247  typename ViewType::value_type >::value
1248  , "deep_copy requires non-const type" );
1249 
1250  // If contigous we can simply do a 1D flat loop
1251  if(dst.span_is_contiguous()) {
1252  typedef Kokkos::View<typename ViewType::value_type*,Kokkos::LayoutRight,
1253  Kokkos::Device<typename ViewType::execution_space,
1254  typename std::conditional<ViewType::Rank==0,
1255  typename ViewType::memory_space,Kokkos::AnonymousSpace
1256  >::type>,
1257  Kokkos::MemoryTraits<0> >
1258  ViewTypeFlat;
1259 
1260  ViewTypeFlat dst_flat(dst.data(),dst.size());
1261  if(dst.span() < std::numeric_limits<int>::max()) {
1262  Kokkos::Impl::ViewFill< ViewTypeFlat , Kokkos::LayoutRight, typename ViewType::execution_space, ViewTypeFlat::Rank, int >( dst_flat , value );
1263  } else
1264  Kokkos::Impl::ViewFill< ViewTypeFlat , Kokkos::LayoutRight, typename ViewType::execution_space, ViewTypeFlat::Rank, int64_t >( dst_flat , value );
1265  Kokkos::fence();
1266  return;
1267  }
1268 
1269  // Figure out iteration order to do the ViewFill
1270  int64_t strides[ViewType::Rank+1];
1271  dst.stride(strides);
1272  Kokkos::Iterate iterate;
1273  if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutRight>::value ) {
1274  iterate = Kokkos::Iterate::Right;
1275  } else if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutLeft>::value ) {
1276  iterate = Kokkos::Iterate::Left;
1277  } else if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutStride>::value ) {
1278  if( strides[0] > strides[ViewType::Rank>0?ViewType::Rank-1:0] )
1279  iterate = Kokkos::Iterate::Right;
1280  else
1281  iterate = Kokkos::Iterate::Left;
1282  } else {
1283  if( std::is_same<typename ViewType::execution_space::array_layout, Kokkos::LayoutRight>::value )
1284  iterate = Kokkos::Iterate::Right;
1285  else
1286  iterate = Kokkos::Iterate::Left;
1287  }
1288 
1289  // Lets call the right ViewFill functor based on integer space needed and iteration type
1290  typedef typename std::conditional<ViewType::Rank==0,
1291  typename ViewType::uniform_runtime_type,
1292  typename ViewType::uniform_runtime_nomemspace_type>::type ViewTypeUniform;
1293  if(dst.span() > std::numeric_limits<int>::max()) {
1294  if(iterate == Kokkos::Iterate::Right)
1295  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutRight, typename ViewType::execution_space, ViewType::Rank, int64_t >( dst , value );
1296  else
1297  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutLeft, typename ViewType::execution_space, ViewType::Rank, int64_t >( dst , value );
1298  } else {
1299  if(iterate == Kokkos::Iterate::Right)
1300  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutRight, typename ViewType::execution_space, ViewType::Rank, int >( dst , value );
1301  else
1302  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutLeft, typename ViewType::execution_space, ViewType::Rank, int >( dst , value );
1303  }
1304  Kokkos::fence();
1305 }
1306 
1308 template< class ST , class ... SP >
1309 inline
1310 void deep_copy
1311  ( typename ViewTraits<ST,SP...>::non_const_value_type & dst
1312  , const View<ST,SP...> & src
1313  , typename std::enable_if<
1314  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1315  >::type * = 0 )
1316 {
1317  static_assert( ViewTraits<ST,SP...>::rank == 0
1318  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1319 
1320  if(src.data() == NULL) {
1321  Kokkos::fence();
1322  return;
1323  }
1324 
1325  typedef ViewTraits<ST,SP...> src_traits ;
1326  typedef typename src_traits::memory_space src_memory_space ;
1327  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() , sizeof(ST) );
1328 }
1329 
1330 //----------------------------------------------------------------------------
1332 template< class DT , class ... DP , class ST , class ... SP >
1333 inline
1334 void deep_copy
1335  ( const View<DT,DP...> & dst
1336  , const View<ST,SP...> & src
1337  , typename std::enable_if<(
1338  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1339  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1340  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
1341  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
1342  )>::type * = 0 )
1343 {
1344  static_assert(
1345  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1346  typename ViewTraits<ST,SP...>::non_const_value_type >::value
1347  , "deep_copy requires matching non-const destination type" );
1348 
1349  if(dst.data() == NULL && src.data() == NULL) {
1350  Kokkos::fence();
1351  return;
1352  }
1353 
1354  typedef View<DT,DP...> dst_type ;
1355  typedef View<ST,SP...> src_type ;
1356 
1357  typedef typename dst_type::value_type value_type ;
1358  typedef typename dst_type::memory_space dst_memory_space ;
1359  typedef typename src_type::memory_space src_memory_space ;
1360 
1361  Kokkos::fence();
1362  if ( dst.data() != src.data() ) {
1363  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , sizeof(value_type) );
1364  Kokkos::fence();
1365  }
1366 }
1367 
1368 //----------------------------------------------------------------------------
1372 template< class DT , class ... DP , class ST , class ... SP >
1373 inline
1374 void deep_copy
1375  ( const View<DT,DP...> & dst
1376  , const View<ST,SP...> & src
1377  , typename std::enable_if<(
1378  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1379  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1380  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
1381  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
1382  )>::type * = 0 )
1383 {
1384  typedef View<DT,DP...> dst_type ;
1385  typedef View<ST,SP...> src_type ;
1386 
1387  static_assert(
1388  std::is_same< typename dst_type::value_type ,
1389  typename dst_type::non_const_value_type >::value
1390  , "deep_copy requires non-const destination type" );
1391 
1392  static_assert(
1393  ( unsigned(dst_type::rank) ==
1394  unsigned(src_type::rank) )
1395  , "deep_copy requires Views of equal rank" );
1396 
1397 
1398  typedef typename dst_type::execution_space dst_execution_space ;
1399  typedef typename src_type::execution_space src_execution_space ;
1400  typedef typename dst_type::memory_space dst_memory_space ;
1401  typedef typename src_type::memory_space src_memory_space ;
1402  typedef typename dst_type::value_type dst_value_type ;
1403  typedef typename src_type::value_type src_value_type ;
1404  if(dst.data() == NULL || src.data() == NULL) {
1405 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1406  // do nothing
1407 #else
1408  // throw if dimension mismatch
1409  if ( (src.extent(0) != dst.extent(0)) ||
1410  (src.extent(1) != dst.extent(1)) ||
1411  (src.extent(2) != dst.extent(2)) ||
1412  (src.extent(3) != dst.extent(3)) ||
1413  (src.extent(4) != dst.extent(4)) ||
1414  (src.extent(5) != dst.extent(5)) ||
1415  (src.extent(6) != dst.extent(6)) ||
1416  (src.extent(7) != dst.extent(7))
1417  ) {
1418  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1419  message += dst.label(); message += "(";
1420  for(int r = 0; r<dst_type::Rank-1; r++)
1421  { message+= std::to_string(dst.extent(r)); message += ","; }
1422  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
1423  message += src.label(); message += "(";
1424  for(int r = 0; r<src_type::Rank-1; r++)
1425  { message+= std::to_string(src.extent(r)); message += ","; }
1426  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
1427 
1428  Kokkos::Impl::throw_runtime_exception(message);
1429  }
1430 #endif
1431  Kokkos::fence();
1432  return;
1433  }
1434 
1435  enum { DstExecCanAccessSrc =
1437 
1438  enum { SrcExecCanAccessDst =
1440 
1441  // Checking for Overlapping Views.
1442  dst_value_type* dst_start = dst.data();
1443  dst_value_type* dst_end = dst.data() + dst.span();
1444  src_value_type* src_start = src.data();
1445  src_value_type* src_end = src.data() + src.span();
1446  if( ((std::ptrdiff_t)dst_start == (std::ptrdiff_t)src_start) &&
1447  ((std::ptrdiff_t)dst_end == (std::ptrdiff_t)src_end) &&
1448  (dst.span_is_contiguous() && src.span_is_contiguous()) ) {
1449  Kokkos::fence();
1450  return;
1451  }
1452 
1453  if( ( ( (std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end ) && ( (std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start ) ) &&
1454  ( ( dst.span_is_contiguous() && src.span_is_contiguous() ))) {
1455  std::string message("Error: Kokkos::deep_copy of overlapping views: ");
1456  message += dst.label(); message += "(";
1457  message += std::to_string((std::ptrdiff_t)dst_start); message += ",";
1458  message += std::to_string((std::ptrdiff_t)dst_end); message += ") ";
1459  message += src.label(); message += "(";
1460  message += std::to_string((std::ptrdiff_t)src_start); message += ",";
1461  message += std::to_string((std::ptrdiff_t)src_end); message += ") ";
1462  Kokkos::Impl::throw_runtime_exception(message);
1463  }
1464 
1465  // Check for same extents
1466  if ( (src.extent(0) != dst.extent(0)) ||
1467  (src.extent(1) != dst.extent(1)) ||
1468  (src.extent(2) != dst.extent(2)) ||
1469  (src.extent(3) != dst.extent(3)) ||
1470  (src.extent(4) != dst.extent(4)) ||
1471  (src.extent(5) != dst.extent(5)) ||
1472  (src.extent(6) != dst.extent(6)) ||
1473  (src.extent(7) != dst.extent(7))
1474  ) {
1475 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1476  Kokkos::fence();
1477  if ( DstExecCanAccessSrc ) {
1478  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1479  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1480  }
1481  else if ( SrcExecCanAccessDst ) {
1482  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1483  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1484  }
1485  else {
1486  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1487  }
1488  Kokkos::fence();
1489  return;
1490 #else
1491  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1492  message += dst.label(); message += "(";
1493  for(int r = 0; r<dst_type::Rank-1; r++)
1494  { message+= std::to_string(dst.extent(r)); message += ","; }
1495  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
1496  message += src.label(); message += "(";
1497  for(int r = 0; r<src_type::Rank-1; r++)
1498  { message+= std::to_string(src.extent(r)); message += ","; }
1499  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
1500 
1501  Kokkos::Impl::throw_runtime_exception(message);
1502 #endif
1503  }
1504 
1505  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1506 
1507  if ( std::is_same< typename dst_type::value_type ,
1508  typename src_type::non_const_value_type >::value &&
1509  (
1510  std::is_same< typename dst_type::array_layout ,
1511  typename src_type::array_layout >::value
1512  ||
1513  ( dst_type::rank == 1 &&
1514  src_type::rank == 1 )
1515  ) &&
1516  dst.span_is_contiguous() &&
1517  src.span_is_contiguous() &&
1518  ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1519  ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1520  ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1521  ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1522  ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1523  ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1524  ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1525  ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))
1526  ) {
1527  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1528  Kokkos::fence();
1529  if((void*)dst.data()!=(void*)src.data()) {
1530  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >
1531  ( dst.data() , src.data() , nbytes );
1532  }
1533  Kokkos::fence();
1534  } else {
1535  Kokkos::fence();
1536  Impl::view_copy(dst, src);
1537  Kokkos::fence();
1538  }
1539 }
1540 
1541 //----------------------------------------------------------------------------
1542 //----------------------------------------------------------------------------
1543 namespace Experimental {
1547 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1548 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(const TeamType& team, const View<DT,DP...> & dst, const View<ST,SP...> & src) {
1549  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, src.span()), [&] (const int& i) {
1550  dst.data()[i] = src.data()[i];
1551  });
1552 }
1553 //----------------------------------------------------------------------------
1554 template< class DT , class ... DP , class ST , class ... SP >
1555 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(const View<DT,DP...> & dst, const View<ST,SP...> & src) {
1556 
1557  for(size_t i=0;i<src.span();++i) {
1558  dst.data()[i] = src.data()[i];
1559  }
1560 }
1561 //----------------------------------------------------------------------------
1562 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1563 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1564  const View<ST,SP...> & src,
1565  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 1 &&
1566  unsigned(ViewTraits<ST,SP...>::rank) == 1
1567  )>::type * = 0 )
1568 {
1569  if( dst.data() == nullptr ) {
1570  return;
1571  }
1572 
1573  const size_t N = dst.extent(0);
1574 
1575  team.team_barrier();
1576  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1577  dst(i) = src(i);
1578  });
1579  team.team_barrier();
1580 }
1581 //----------------------------------------------------------------------------
1582 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1583 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1584  const View<ST,SP...> & src,
1585  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 2 &&
1586  unsigned(ViewTraits<ST,SP...>::rank) == 2
1587  )>::type * = 0 )
1588 {
1589  if( dst.data() == nullptr ) {
1590  return;
1591  }
1592 
1593  const size_t N = dst.extent(0)*dst.extent(1);
1594 
1595  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1596  team.team_barrier();
1597  local_deep_copy_contiguous(team,dst,src);
1598  team.team_barrier();
1599  } else {
1600  team.team_barrier();
1601  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1602  int i0 = i%dst.extent(0);
1603  int i1 = i/dst.extent(0);
1604  dst(i0,i1) = src(i0,i1);
1605  });
1606  team.team_barrier();
1607  }
1608 }
1609 //----------------------------------------------------------------------------
1610 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1611 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1612  const View<ST,SP...> & src,
1613  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 3 &&
1614  unsigned(ViewTraits<ST,SP...>::rank) == 3
1615  )>::type * = 0 )
1616 {
1617  if( dst.data() == nullptr ) {
1618  return;
1619  }
1620 
1621  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2);
1622 
1623  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1624  team.team_barrier();
1625  local_deep_copy_contiguous(team,dst,src);
1626  team.team_barrier();
1627  } else {
1628  team.team_barrier();
1629  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1630  int i0 = i%dst.extent(0);
1631  int itmp = i/dst.extent(0);
1632  int i1 = itmp%dst.extent(1);
1633  int i2 = itmp/dst.extent(1);
1634  dst(i0,i1,i2) = src(i0,i1,i2);
1635  });
1636  team.team_barrier();
1637  }
1638 }
1639 //----------------------------------------------------------------------------
1640 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1641 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1642  const View<ST,SP...> & src,
1643  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 4 &&
1644  unsigned(ViewTraits<ST,SP...>::rank) == 4
1645  )>::type * = 0 )
1646 {
1647  if( dst.data() == nullptr ) {
1648  return;
1649  }
1650 
1651  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3);
1652 
1653  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1654  team.team_barrier();
1655  local_deep_copy_contiguous(team,dst,src);
1656  team.team_barrier();
1657  } else {
1658  team.team_barrier();
1659  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1660  int i0 = i%dst.extent(0);
1661  int itmp = i/dst.extent(0);
1662  int i1 = itmp%dst.extent(1);
1663  itmp = itmp/dst.extent(1);
1664  int i2 = itmp%dst.extent(2);
1665  int i3 = itmp/dst.extent(2);
1666  dst(i0,i1,i2,i3) = src(i0,i1,i2,i3);
1667  });
1668  team.team_barrier();
1669  }
1670 }
1671 //----------------------------------------------------------------------------
1672 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1673 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1674  const View<ST,SP...> & src,
1675  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 5 &&
1676  unsigned(ViewTraits<ST,SP...>::rank) == 5
1677  )>::type * = 0 )
1678 {
1679  if( dst.data() == nullptr ) {
1680  return;
1681  }
1682 
1683  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3)*dst.extent(4);
1684 
1685  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1686  team.team_barrier();
1687  local_deep_copy_contiguous(team,dst,src);
1688  team.team_barrier();
1689  } else {
1690  team.team_barrier();
1691  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1692  int i0 = i%dst.extent(0);
1693  int itmp = i/dst.extent(0);
1694  int i1 = itmp%dst.extent(1);
1695  itmp = itmp/dst.extent(1);
1696  int i2 = itmp%dst.extent(2);
1697  itmp = itmp/dst.extent(2);
1698  int i3 = itmp%dst.extent(3);
1699  int i4 = itmp/dst.extent(3);
1700  dst(i0,i1,i2,i3,i4) = src(i0,i1,i2,i3,i4);
1701  });
1702  team.team_barrier();
1703  }
1704 }
1705 //----------------------------------------------------------------------------
1706 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1707 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1708  const View<ST,SP...> & src,
1709  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 6 &&
1710  unsigned(ViewTraits<ST,SP...>::rank) == 6
1711  )>::type * = 0 )
1712 {
1713  if( dst.data() == nullptr ) {
1714  return;
1715  }
1716 
1717  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3)*dst.extent(4)*dst.extent(5);
1718 
1719  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1720  team.team_barrier();
1721  local_deep_copy_contiguous(team,dst,src);
1722  team.team_barrier();
1723  } else {
1724  team.team_barrier();
1725  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1726  int i0 = i%dst.extent(0);
1727  int itmp = i/dst.extent(0);
1728  int i1 = itmp%dst.extent(1);
1729  itmp = itmp/dst.extent(1);
1730  int i2 = itmp%dst.extent(2);
1731  itmp = itmp/dst.extent(2);
1732  int i3 = itmp%dst.extent(3);
1733  itmp = itmp/dst.extent(3);
1734  int i4 = itmp%dst.extent(4);
1735  int i5 = itmp/dst.extent(4);
1736  dst(i0,i1,i2,i3,i4,i5) = src(i0,i1,i2,i3,i4,i5);
1737  });
1738  team.team_barrier();
1739  }
1740 }
1741 //----------------------------------------------------------------------------
1742 template< class TeamType, class DT , class ... DP , class ST , class ... SP >
1743 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1744  const View<ST,SP...> & src,
1745  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 7 &&
1746  unsigned(ViewTraits<ST,SP...>::rank) == 7
1747  )>::type * = 0 )
1748 {
1749  if( dst.data() == nullptr ) {
1750  return;
1751  }
1752 
1753  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3)*dst.extent(4)*dst.extent(5)*dst.extent(6);
1754 
1755  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1756  team.team_barrier();
1757  local_deep_copy_contiguous(team,dst,src);
1758  team.team_barrier();
1759  } else {
1760  team.team_barrier();
1761  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1762  int i0 = i%dst.extent(0);
1763  int itmp = i/dst.extent(0);
1764  int i1 = itmp%dst.extent(1);
1765  itmp = itmp/dst.extent(1);
1766  int i2 = itmp%dst.extent(2);
1767  itmp = itmp/dst.extent(2);
1768  int i3 = itmp%dst.extent(3);
1769  itmp = itmp/dst.extent(3);
1770  int i4 = itmp%dst.extent(4);
1771  itmp = itmp/dst.extent(4);
1772  int i5 = itmp%dst.extent(5);
1773  int i6 = itmp/dst.extent(5);
1774  dst(i0,i1,i2,i3,i4,i5,i6) = src(i0,i1,i2,i3,i4,i5,i6);
1775  });
1776  team.team_barrier();
1777  }
1778 }
1779 //----------------------------------------------------------------------------
1780 template< class DT , class ... DP , class ST , class ... SP >
1781 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
1782  const View<ST,SP...> & src,
1783  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 1 &&
1784  unsigned(ViewTraits<ST,SP...>::rank) == 1
1785  )>::type * = 0 )
1786 {
1787  if( dst.data() == nullptr ) {
1788  return;
1789  }
1790 
1791  const size_t N = dst.extent(0);
1792 
1793 
1794  for(size_t i=0;i<N;++i){
1795  dst(i) = src(i);
1796  }
1797 }
1798 //----------------------------------------------------------------------------
1799 template< class DT , class ... DP , class ST , class ... SP >
1800 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
1801  const View<ST,SP...> & src,
1802  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 2 &&
1803  unsigned(ViewTraits<ST,SP...>::rank) == 2
1804  )>::type * = 0 )
1805 {
1806  if( dst.data() == nullptr ) {
1807  return;
1808  }
1809 
1810  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1811  local_deep_copy_contiguous(dst,src);
1812  } else {
1813 
1814  for(size_t i0=0;i0<dst.extent(0);++i0)
1815  for(size_t i1=0;i1<dst.extent(1);++i1)
1816  dst(i0,i1) = src(i0,i1);
1817  }
1818 }
1819 //----------------------------------------------------------------------------
1820 template< class DT , class ... DP , class ST , class ... SP >
1821 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
1822  const View<ST,SP...> & src,
1823  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 3 &&
1824  unsigned(ViewTraits<ST,SP...>::rank) == 3
1825  )>::type * = 0 )
1826 {
1827  if( dst.data() == nullptr ) {
1828  return;
1829  }
1830 
1831  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1832  local_deep_copy_contiguous(dst,src);
1833  } else {
1834 
1835  for(size_t i0=0;i0<dst.extent(0);++i0)
1836  for(size_t i1=0;i1<dst.extent(1);++i1)
1837  for(size_t i2=0;i2<dst.extent(2);++i2)
1838  dst(i0,i1,i2) = src(i0,i1,i2);
1839  }
1840 }
1841 //----------------------------------------------------------------------------
1842 template< class DT , class ... DP , class ST , class ... SP >
1843 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
1844  const View<ST,SP...> & src,
1845  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 4 &&
1846  unsigned(ViewTraits<ST,SP...>::rank) == 4
1847  )>::type * = 0 )
1848 {
1849  if( dst.data() == nullptr ) {
1850  return;
1851  }
1852 
1853  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1854  local_deep_copy_contiguous(dst,src);
1855  } else {
1856 
1857  for(size_t i0=0;i0<dst.extent(0);++i0)
1858  for(size_t i1=0;i1<dst.extent(1);++i1)
1859  for(size_t i2=0;i2<dst.extent(2);++i2)
1860  for(size_t i3=0;i3<dst.extent(3);++i3)
1861  dst(i0,i1,i2,i3) = src(i0,i1,i2,i3);
1862  }
1863 }
1864 //----------------------------------------------------------------------------
1865 template< class DT , class ... DP , class ST , class ... SP >
1866 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
1867  const View<ST,SP...> & src,
1868  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 5 &&
1869  unsigned(ViewTraits<ST,SP...>::rank) == 5
1870  )>::type * = 0 )
1871 {
1872  if( dst.data() == nullptr ) {
1873  return;
1874  }
1875 
1876  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1877  local_deep_copy_contiguous(dst,src);
1878  } else {
1879 
1880  for(size_t i0=0;i0<dst.extent(0);++i0)
1881  for(size_t i1=0;i1<dst.extent(1);++i1)
1882  for(size_t i2=0;i2<dst.extent(2);++i2)
1883  for(size_t i3=0;i3<dst.extent(3);++i3)
1884  for(size_t i4=0;i4<dst.extent(4);++i4)
1885  dst(i0,i1,i2,i3,i4) = src(i0,i1,i2,i3,i4);
1886  }
1887 }
1888 //----------------------------------------------------------------------------
1889 template< class DT , class ... DP , class ST , class ... SP >
1890 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
1891  const View<ST,SP...> & src,
1892  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 6 &&
1893  unsigned(ViewTraits<ST,SP...>::rank) == 6
1894  )>::type * = 0 )
1895 {
1896  if( dst.data() == nullptr ) {
1897  return;
1898  }
1899 
1900  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1901  local_deep_copy_contiguous(dst,src);
1902  } else {
1903 
1904  for(size_t i0=0;i0<dst.extent(0);++i0)
1905  for(size_t i1=0;i1<dst.extent(1);++i1)
1906  for(size_t i2=0;i2<dst.extent(2);++i2)
1907  for(size_t i3=0;i3<dst.extent(3);++i3)
1908  for(size_t i4=0;i4<dst.extent(4);++i4)
1909  for(size_t i5=0;i5<dst.extent(5);++i5)
1910  dst(i0,i1,i2,i3,i4,i5) = src(i0,i1,i2,i3,i4,i5);
1911  }
1912 }
1913 //----------------------------------------------------------------------------
1914 template< class DT , class ... DP , class ST , class ... SP >
1915 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
1916  const View<ST,SP...> & src,
1917  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 7 &&
1918  unsigned(ViewTraits<ST,SP...>::rank) == 7
1919  )>::type * = 0 )
1920 {
1921  if( dst.data() == nullptr ) {
1922  return;
1923  }
1924 
1925  if ( dst.span_is_contiguous() && src.span_is_contiguous() ) {
1926  local_deep_copy_contiguous(dst,src);
1927  } else {
1928 
1929  for(size_t i0=0;i0<dst.extent(0);++i0)
1930  for(size_t i1=0;i1<dst.extent(1);++i1)
1931  for(size_t i2=0;i2<dst.extent(2);++i2)
1932  for(size_t i3=0;i3<dst.extent(3);++i3)
1933  for(size_t i4=0;i4<dst.extent(4);++i4)
1934  for(size_t i5=0;i5<dst.extent(5);++i5)
1935  for(size_t i6=0;i6<dst.extent(6);++i6)
1936  dst(i0,i1,i2,i3,i4,i5,i6) = src(i0,i1,i2,i3,i4,i5,i6);
1937  }
1938 }
1939 //----------------------------------------------------------------------------
1940 //----------------------------------------------------------------------------
1942 template< class TeamType, class DT , class ... DP >
1943 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(const TeamType& team, const View<DT,DP...> & dst, typename ViewTraits<DT,DP...>::const_value_type & value) {
1944  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, dst.span()), [&] (const int& i) {
1945  dst.data()[i] = value;
1946  });
1947 }
1948 //----------------------------------------------------------------------------
1949 template< class DT , class ... DP >
1950 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(const View<DT,DP...> & dst, typename ViewTraits<DT,DP...>::const_value_type & value) {
1951 
1952  for(size_t i=0;i<dst.span();++i) {
1953  dst.data()[i] = value;
1954  }
1955 }
1956 //----------------------------------------------------------------------------
1957 template< class TeamType, class DT , class ... DP >
1958 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1959  typename ViewTraits<DT,DP...>::const_value_type & value,
1960  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 1 )>::type * = 0 )
1961 {
1962  if( dst.data() == nullptr ) {
1963  return;
1964  }
1965 
1966  const size_t N = dst.extent(0);
1967 
1968  team.team_barrier();
1969  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1970  dst(i) = value;
1971  });
1972  team.team_barrier();
1973 }
1974 //----------------------------------------------------------------------------
1975 template< class TeamType, class DT , class ... DP >
1976 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
1977  typename ViewTraits<DT,DP...>::const_value_type & value,
1978  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 2 )>::type * = 0 )
1979 {
1980  if( dst.data() == nullptr ) {
1981  return;
1982  }
1983 
1984  const size_t N = dst.extent(0)*dst.extent(1);
1985 
1986  if ( dst.span_is_contiguous() ) {
1987  team.team_barrier();
1988  local_deep_copy_contiguous(team,dst,value);
1989  team.team_barrier();
1990  } else {
1991  team.team_barrier();
1992  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
1993  int i0 = i%dst.extent(0);
1994  int i1 = i/dst.extent(0);
1995  dst(i0,i1) = value;
1996  });
1997  team.team_barrier();
1998  }
1999 }
2000 //----------------------------------------------------------------------------
2001 template< class TeamType, class DT , class ... DP >
2002 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
2003  typename ViewTraits<DT,DP...>::const_value_type & value,
2004  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 3 )>::type * = 0 )
2005 {
2006  if( dst.data() == nullptr ) {
2007  return;
2008  }
2009 
2010  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2);
2011 
2012  if ( dst.span_is_contiguous() ) {
2013  team.team_barrier();
2014  local_deep_copy_contiguous(team,dst,value);
2015  team.team_barrier();
2016  } else {
2017  team.team_barrier();
2018  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
2019  int i0 = i%dst.extent(0);
2020  int itmp = i/dst.extent(0);
2021  int i1 = itmp%dst.extent(1);
2022  int i2 = itmp/dst.extent(1);
2023  dst(i0,i1,i2) = value;
2024  });
2025  team.team_barrier();
2026  }
2027 }
2028 //----------------------------------------------------------------------------
2029 template< class TeamType, class DT , class ... DP >
2030 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
2031  typename ViewTraits<DT,DP...>::const_value_type & value,
2032  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 4 )>::type * = 0 )
2033 {
2034  if( dst.data() == nullptr ) {
2035  return;
2036  }
2037 
2038  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3);
2039 
2040  if ( dst.span_is_contiguous() ) {
2041  team.team_barrier();
2042  local_deep_copy_contiguous(team,dst,value);
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) = value;
2054  });
2055  team.team_barrier();
2056  }
2057 }
2058 //----------------------------------------------------------------------------
2059 template< class TeamType, class DT , class ... DP >
2060 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
2061  typename ViewTraits<DT,DP...>::const_value_type & value,
2062  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 5 )>::type * = 0 )
2063 {
2064  if( dst.data() == nullptr ) {
2065  return;
2066  }
2067 
2068  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3)*dst.extent(4);
2069 
2070  if ( dst.span_is_contiguous() ) {
2071  team.team_barrier();
2072  local_deep_copy_contiguous(team,dst,value);
2073  team.team_barrier();
2074  } else {
2075  team.team_barrier();
2076  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
2077  int i0 = i%dst.extent(0);
2078  int itmp = i/dst.extent(0);
2079  int i1 = itmp%dst.extent(1);
2080  itmp = itmp/dst.extent(1);
2081  int i2 = itmp%dst.extent(2);
2082  itmp = itmp/dst.extent(2);
2083  int i3 = itmp%dst.extent(3);
2084  int i4 = itmp/dst.extent(3);
2085  dst(i0,i1,i2,i3,i4) = value;
2086  });
2087  team.team_barrier();
2088  }
2089 }
2090 //----------------------------------------------------------------------------
2091 template< class TeamType, class DT , class ... DP >
2092 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
2093  typename ViewTraits<DT,DP...>::const_value_type & value,
2094  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 6 )>::type * = 0 )
2095 {
2096  if( dst.data() == nullptr ) {
2097  return;
2098  }
2099 
2100  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3)*dst.extent(4)*dst.extent(5);
2101 
2102  if ( dst.span_is_contiguous() ) {
2103  team.team_barrier();
2104  local_deep_copy_contiguous(team,dst,value);
2105  team.team_barrier();
2106  } else {
2107  team.team_barrier();
2108  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
2109  int i0 = i%dst.extent(0);
2110  int itmp = i/dst.extent(0);
2111  int i1 = itmp%dst.extent(1);
2112  itmp = itmp/dst.extent(1);
2113  int i2 = itmp%dst.extent(2);
2114  itmp = itmp/dst.extent(2);
2115  int i3 = itmp%dst.extent(3);
2116  itmp = itmp/dst.extent(3);
2117  int i4 = itmp%dst.extent(4);
2118  int i5 = itmp/dst.extent(4);
2119  dst(i0,i1,i2,i3,i4,i5) = value;
2120  });
2121  team.team_barrier();
2122  }
2123 }
2124 //----------------------------------------------------------------------------
2125 template< class TeamType, class DT , class ... DP >
2126 void KOKKOS_INLINE_FUNCTION local_deep_copy (const TeamType& team, const View<DT,DP...> & dst,
2127  typename ViewTraits<DT,DP...>::const_value_type & value,
2128  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 7 )>::type * = 0 )
2129 {
2130  if( dst.data() == nullptr ) {
2131  return;
2132  }
2133 
2134  const size_t N = dst.extent(0)*dst.extent(1)*dst.extent(2)*dst.extent(3)*dst.extent(4)*dst.extent(5)*dst.extent(6);
2135 
2136  if ( dst.span_is_contiguous() ) {
2137  team.team_barrier();
2138  local_deep_copy_contiguous(team,dst,value);
2139  team.team_barrier();
2140  } else {
2141  team.team_barrier();
2142  Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&] (const int& i) {
2143  int i0 = i%dst.extent(0);
2144  int itmp = i/dst.extent(0);
2145  int i1 = itmp%dst.extent(1);
2146  itmp = itmp/dst.extent(1);
2147  int i2 = itmp%dst.extent(2);
2148  itmp = itmp/dst.extent(2);
2149  int i3 = itmp%dst.extent(3);
2150  itmp = itmp/dst.extent(3);
2151  int i4 = itmp%dst.extent(4);
2152  itmp = itmp/dst.extent(4);
2153  int i5 = itmp%dst.extent(5);
2154  int i6 = itmp/dst.extent(5);
2155  dst(i0,i1,i2,i3,i4,i5,i6) = value;
2156  });
2157  team.team_barrier();
2158  }
2159 }
2160 //----------------------------------------------------------------------------
2161 template< class DT , class ... DP >
2162 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
2163  typename ViewTraits<DT,DP...>::const_value_type & value,
2164  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 1
2165  )>::type * = 0 )
2166 {
2167  if( dst.data() == nullptr ) {
2168  return;
2169  }
2170 
2171  const size_t N = dst.extent(0);
2172 
2173 
2174  for(size_t i=0;i<N;++i){
2175  dst(i) = value;
2176  }
2177 }
2178 //----------------------------------------------------------------------------
2179 template< class DT , class ... DP >
2180 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
2181  typename ViewTraits<DT,DP...>::const_value_type & value,
2182  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 2
2183  )>::type * = 0 )
2184 {
2185  if( dst.data() == nullptr ) {
2186  return;
2187  }
2188 
2189  if ( dst.span_is_contiguous() ) {
2190  local_deep_copy_contiguous(dst,value);
2191  } else {
2192 
2193  for(size_t i0=0;i0<dst.extent(0);++i0)
2194  for(size_t i1=0;i1<dst.extent(1);++i1)
2195  dst(i0,i1) = value;
2196  }
2197 }
2198 //----------------------------------------------------------------------------
2199 template< class DT , class ... DP >
2200 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
2201  typename ViewTraits<DT,DP...>::const_value_type & value,
2202  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 3
2203  )>::type * = 0 )
2204 {
2205  if( dst.data() == nullptr ) {
2206  return;
2207  }
2208 
2209  if ( dst.span_is_contiguous() ) {
2210  local_deep_copy_contiguous(dst,value);
2211  } else {
2212 
2213  for(size_t i0=0;i0<dst.extent(0);++i0)
2214  for(size_t i1=0;i1<dst.extent(1);++i1)
2215  for(size_t i2=0;i2<dst.extent(2);++i2)
2216  dst(i0,i1,i2) = value;
2217  }
2218 }
2219 //----------------------------------------------------------------------------
2220 template< class DT , class ... DP >
2221 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
2222  typename ViewTraits<DT,DP...>::const_value_type & value,
2223  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 4
2224  )>::type * = 0 )
2225 {
2226  if( dst.data() == nullptr ) {
2227  return;
2228  }
2229 
2230  if ( dst.span_is_contiguous() ) {
2231  local_deep_copy_contiguous(dst,value);
2232  } else {
2233 
2234  for(size_t i0=0;i0<dst.extent(0);++i0)
2235  for(size_t i1=0;i1<dst.extent(1);++i1)
2236  for(size_t i2=0;i2<dst.extent(2);++i2)
2237  for(size_t i3=0;i3<dst.extent(3);++i3)
2238  dst(i0,i1,i2,i3) = value;
2239  }
2240 }
2241 //----------------------------------------------------------------------------
2242 template< class DT , class ... DP >
2243 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
2244  typename ViewTraits<DT,DP...>::const_value_type & value,
2245  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 5
2246  )>::type * = 0 )
2247 {
2248  if( dst.data() == nullptr ) {
2249  return;
2250  }
2251 
2252  if ( dst.span_is_contiguous() ) {
2253  local_deep_copy_contiguous(dst,value);
2254  } else {
2255 
2256  for(size_t i0=0;i0<dst.extent(0);++i0)
2257  for(size_t i1=0;i1<dst.extent(1);++i1)
2258  for(size_t i2=0;i2<dst.extent(2);++i2)
2259  for(size_t i3=0;i3<dst.extent(3);++i3)
2260  for(size_t i4=0;i4<dst.extent(4);++i4)
2261  dst(i0,i1,i2,i3,i4) = value;
2262  }
2263 }
2264 //----------------------------------------------------------------------------
2265 template< class DT , class ... DP >
2266 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
2267  typename ViewTraits<DT,DP...>::const_value_type & value,
2268  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 6
2269  )>::type * = 0 )
2270 {
2271  if( dst.data() == nullptr ) {
2272  return;
2273  }
2274 
2275  if ( dst.span_is_contiguous() ) {
2276  local_deep_copy_contiguous(dst,value);
2277  } else {
2278 
2279  for(size_t i0=0;i0<dst.extent(0);++i0)
2280  for(size_t i1=0;i1<dst.extent(1);++i1)
2281  for(size_t i2=0;i2<dst.extent(2);++i2)
2282  for(size_t i3=0;i3<dst.extent(3);++i3)
2283  for(size_t i4=0;i4<dst.extent(4);++i4)
2284  for(size_t i5=0;i5<dst.extent(5);++i5)
2285  dst(i0,i1,i2,i3,i4,i5) = value;
2286  }
2287 }
2288 //----------------------------------------------------------------------------
2289 template< class DT , class ... DP >
2290 void KOKKOS_INLINE_FUNCTION local_deep_copy (const View<DT,DP...> & dst,
2291  typename ViewTraits<DT,DP...>::const_value_type & value,
2292  typename std::enable_if<( unsigned(ViewTraits<DT,DP...>::rank) == 7
2293  )>::type * = 0 )
2294 {
2295  if( dst.data() == nullptr ) {
2296  return;
2297  }
2298 
2299  if ( dst.span_is_contiguous() ) {
2300  local_deep_copy_contiguous(dst,value);
2301  } else {
2302 
2303  for(size_t i0=0;i0<dst.extent(0);++i0)
2304  for(size_t i1=0;i1<dst.extent(1);++i1)
2305  for(size_t i2=0;i2<dst.extent(2);++i2)
2306  for(size_t i3=0;i3<dst.extent(3);++i3)
2307  for(size_t i4=0;i4<dst.extent(4);++i4)
2308  for(size_t i5=0;i5<dst.extent(5);++i5)
2309  for(size_t i6=0;i6<dst.extent(6);++i6)
2310  dst(i0,i1,i2,i3,i4,i5,i6) = value;
2311  }
2312 }
2313 } /* namespace Experimental */
2314 } /* namespace Kokkos */
2315 
2316 //----------------------------------------------------------------------------
2317 //----------------------------------------------------------------------------
2318 
2319 namespace Kokkos {
2320 
2322 template< class ExecSpace ,class DT , class ... DP >
2323 inline
2324 void deep_copy
2325  ( const ExecSpace &
2326  , const View<DT,DP...> & dst
2327  , typename ViewTraits<DT,DP...>::const_value_type & value
2328  , typename std::enable_if<
2329  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2330  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
2331  >::type * = 0 )
2332 {
2333  static_assert(
2334  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
2335  typename ViewTraits<DT,DP...>::value_type >::value
2336  , "deep_copy requires non-const type" );
2337 
2338  ExecSpace().fence();
2339  typedef typename View<DT,DP...>::uniform_runtime_nomemspace_type ViewTypeUniform;
2340  Kokkos::Impl::ViewFill< ViewTypeUniform >( dst , value );
2341  ExecSpace().fence();
2342 }
2343 
2345 template< class ExecSpace , class ST , class ... SP >
2346 inline
2347 void deep_copy
2348  ( const ExecSpace & exec_space
2349  , typename ViewTraits<ST,SP...>::non_const_value_type & dst
2350  , const View<ST,SP...> & src
2351  , typename std::enable_if<
2352  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2353  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
2354  >::type * = 0 )
2355 {
2356  static_assert( ViewTraits<ST,SP...>::rank == 0
2357  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
2358 
2359  if(src.data() == NULL) {
2360  exec_space.fence();
2361  return;
2362  }
2363 
2364  typedef ViewTraits<ST,SP...> src_traits ;
2365  typedef typename src_traits::memory_space src_memory_space ;
2366  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >
2367  ( exec_space , & dst , src.data() , sizeof(ST) );
2368 }
2369 
2370 //----------------------------------------------------------------------------
2372 template< class ExecSpace , class DT , class ... DP , class ST , class ... SP >
2373 inline
2374 void deep_copy
2375  ( const ExecSpace & exec_space
2376  , const View<DT,DP...> & dst
2377  , const View<ST,SP...> & src
2378  , typename std::enable_if<(
2379  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2380  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
2381  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
2382  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
2383  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
2384  )>::type * = 0 )
2385 {
2386  static_assert(
2387  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
2388  typename ViewTraits<ST,SP...>::non_const_value_type >::value
2389  , "deep_copy requires matching non-const destination type" );
2390 
2391  typedef View<DT,DP...> dst_type ;
2392  typedef View<ST,SP...> src_type ;
2393 
2394  typedef typename dst_type::value_type value_type ;
2395  typedef typename dst_type::memory_space dst_memory_space ;
2396  typedef typename src_type::memory_space src_memory_space ;
2397  if(dst.data() == NULL && src.data() == NULL) {
2398  exec_space.fence();
2399  return;
2400  }
2401 
2402  exec_space.fence();
2403  if ( dst.data() != src.data() ) {
2404  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
2405  ( exec_space , dst.data() , src.data() , sizeof(value_type) );
2406  }
2407  exec_space.fence();
2408 }
2409 
2410 //----------------------------------------------------------------------------
2414 template< class ExecSpace , class DT, class ... DP, class ST, class ... SP >
2415 inline
2416 void deep_copy
2417  ( const ExecSpace & exec_space
2418  , const View<DT,DP...> & dst
2419  , const View<ST,SP...> & src
2420  , typename std::enable_if<(
2421  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2422  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
2423  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
2424  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
2425  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
2426  )>::type * = 0 )
2427 {
2428  typedef View<DT,DP...> dst_type ;
2429  typedef View<ST,SP...> src_type ;
2430 
2431  static_assert(
2432  std::is_same< typename dst_type::value_type ,
2433  typename dst_type::non_const_value_type >::value
2434  , "deep_copy requires non-const destination type" );
2435 
2436  static_assert(
2437  ( unsigned(dst_type::rank) ==
2438  unsigned(src_type::rank) )
2439  , "deep_copy requires Views of equal rank" );
2440 
2441  typedef typename dst_type::execution_space dst_execution_space ;
2442  typedef typename src_type::execution_space src_execution_space ;
2443  typedef typename dst_type::memory_space dst_memory_space ;
2444  typedef typename src_type::memory_space src_memory_space ;
2445  typedef typename dst_type::value_type dst_value_type ;
2446  typedef typename src_type::value_type src_value_type ;
2447 
2448  if(dst.data() == NULL || src.data() == NULL) {
2449 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
2450  // do nothing
2451 #else
2452  // throw if dimension mismatch
2453  if ( (src.extent(0) != dst.extent(0)) ||
2454  (src.extent(1) != dst.extent(1)) ||
2455  (src.extent(2) != dst.extent(2)) ||
2456  (src.extent(3) != dst.extent(3)) ||
2457  (src.extent(4) != dst.extent(4)) ||
2458  (src.extent(5) != dst.extent(5)) ||
2459  (src.extent(6) != dst.extent(6)) ||
2460  (src.extent(7) != dst.extent(7))
2461  ) {
2462  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
2463  message += dst.label(); message += "(";
2464  for(int r = 0; r<dst_type::Rank-1; r++)
2465  { message+= std::to_string(dst.extent(r)); message += ","; }
2466  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
2467  message += src.label(); message += "(";
2468  for(int r = 0; r<src_type::Rank-1; r++)
2469  { message+= std::to_string(src.extent(r)); message += ","; }
2470  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
2471 
2472  Kokkos::Impl::throw_runtime_exception(message);
2473  }
2474 #endif
2475  exec_space.fence();
2476  return;
2477  }
2478 
2479  enum { ExecCanAccessSrcDst =
2482  };
2483  enum { DstExecCanAccessSrc =
2485 
2486  enum { SrcExecCanAccessDst =
2488 
2489  // Checking for Overlapping Views.
2490  dst_value_type* dst_start = dst.data();
2491  dst_value_type* dst_end = dst.data() + dst.span();
2492  src_value_type* src_start = src.data();
2493  src_value_type* src_end = src.data() + src.span();
2494  if( ( ( (std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end ) && ( (std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start ) ) &&
2495  ( ( dst.span_is_contiguous() && src.span_is_contiguous() ))) {
2496  std::string message("Error: Kokkos::deep_copy of overlapping views: ");
2497  message += dst.label(); message += "(";
2498  message += std::to_string((std::ptrdiff_t)dst_start); message += ",";
2499  message += std::to_string((std::ptrdiff_t)dst_end); message += ") ";
2500  message += src.label(); message += "(";
2501  message += std::to_string((std::ptrdiff_t)src_start); message += ",";
2502  message += std::to_string((std::ptrdiff_t)src_end); message += ") ";
2503  Kokkos::Impl::throw_runtime_exception(message);
2504  }
2505 
2506  // Check for same extents
2507  if ( (src.extent(0) != dst.extent(0)) ||
2508  (src.extent(1) != dst.extent(1)) ||
2509  (src.extent(2) != dst.extent(2)) ||
2510  (src.extent(3) != dst.extent(3)) ||
2511  (src.extent(4) != dst.extent(4)) ||
2512  (src.extent(5) != dst.extent(5)) ||
2513  (src.extent(6) != dst.extent(6)) ||
2514  (src.extent(7) != dst.extent(7))
2515  ) {
2516 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
2517  exec_space.fence();
2518  if ( ExecCanAccessSrcDst ) {
2519  Kokkos::Impl::ViewRemap< dst_type , src_type , ExecSpace >( dst , src );
2520  }
2521  else if ( DstExecCanAccessSrc ) {
2522  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
2523  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
2524  }
2525  else if ( SrcExecCanAccessDst ) {
2526  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
2527  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
2528  }
2529  else {
2530  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
2531  }
2532  exec_space.fence();
2533  return;
2534 #else
2535  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
2536  message += dst.label(); message += "(";
2537  for(int r = 0; r<dst_type::Rank-1; r++)
2538  { message+= std::to_string(dst.extent(r)); message += ","; }
2539  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
2540  message += src.label(); message += "(";
2541  for(int r = 0; r<src_type::Rank-1; r++)
2542  { message+= std::to_string(src.extent(r)); message += ","; }
2543  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
2544 
2545  Kokkos::Impl::throw_runtime_exception(message);
2546 #endif
2547  }
2548 
2549  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
2550 
2551  if ( std::is_same< typename dst_type::value_type ,
2552  typename src_type::non_const_value_type >::value &&
2553  (
2554  std::is_same< typename dst_type::array_layout ,
2555  typename src_type::array_layout >::value
2556  ||
2557  ( dst_type::rank == 1 &&
2558  src_type::rank == 1 )
2559  ) &&
2560  dst.span_is_contiguous() &&
2561  src.span_is_contiguous() &&
2562  ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
2563  ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
2564  ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
2565  ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
2566  ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
2567  ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
2568  ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
2569  ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))
2570  ) {
2571 
2572  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
2573  exec_space.fence();
2574  if((void*)dst.data() != (void*)src.data()) {
2575  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
2576  ( exec_space , dst.data() , src.data() , nbytes );
2577  }
2578  exec_space.fence();
2579  } else {
2580  exec_space.fence();
2581  Impl::view_copy(dst, src);
2582  exec_space.fence();
2583  }
2584 }
2585 
2586 } /* namespace Kokkos */
2587 
2588 //----------------------------------------------------------------------------
2589 //----------------------------------------------------------------------------
2590 
2591 namespace Kokkos {
2592 
2594 template< class T , class ... P >
2595 inline
2596 typename std::enable_if<
2597  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
2598  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
2599 >::type
2601  const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2602  const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2603  const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2604  const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2605  const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2606  const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2607  const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2608  const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
2609 {
2610  typedef Kokkos::View<T,P...> view_type ;
2611 
2612  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2613 
2614  // Fix #904 by checking dimensions before actually resizing.
2615  //
2616  // Rank is known at compile time, so hopefully the compiler will
2617  // remove branches that are compile-time false. The upcoming "if
2618  // constexpr" language feature would make this certain.
2619  if (view_type::Rank == 1 &&
2620  n0 == static_cast<size_t> (v.extent(0))) {
2621  return;
2622  }
2623  if (view_type::Rank == 2 &&
2624  n0 == static_cast<size_t> (v.extent(0)) &&
2625  n1 == static_cast<size_t> (v.extent(1))) {
2626  return;
2627  }
2628  if (view_type::Rank == 3 &&
2629  n0 == static_cast<size_t> (v.extent(0)) &&
2630  n1 == static_cast<size_t> (v.extent(1)) &&
2631  n2 == static_cast<size_t> (v.extent(2))) {
2632  return;
2633  }
2634  if (view_type::Rank == 4 &&
2635  n0 == static_cast<size_t> (v.extent(0)) &&
2636  n1 == static_cast<size_t> (v.extent(1)) &&
2637  n2 == static_cast<size_t> (v.extent(2)) &&
2638  n3 == static_cast<size_t> (v.extent(3))) {
2639  return;
2640  }
2641  if (view_type::Rank == 5 &&
2642  n0 == static_cast<size_t> (v.extent(0)) &&
2643  n1 == static_cast<size_t> (v.extent(1)) &&
2644  n2 == static_cast<size_t> (v.extent(2)) &&
2645  n3 == static_cast<size_t> (v.extent(3)) &&
2646  n4 == static_cast<size_t> (v.extent(4))) {
2647  return;
2648  }
2649  if (view_type::Rank == 6 &&
2650  n0 == static_cast<size_t> (v.extent(0)) &&
2651  n1 == static_cast<size_t> (v.extent(1)) &&
2652  n2 == static_cast<size_t> (v.extent(2)) &&
2653  n3 == static_cast<size_t> (v.extent(3)) &&
2654  n4 == static_cast<size_t> (v.extent(4)) &&
2655  n5 == static_cast<size_t> (v.extent(5))) {
2656  return;
2657  }
2658  if (view_type::Rank == 7 &&
2659  n0 == static_cast<size_t> (v.extent(0)) &&
2660  n1 == static_cast<size_t> (v.extent(1)) &&
2661  n2 == static_cast<size_t> (v.extent(2)) &&
2662  n3 == static_cast<size_t> (v.extent(3)) &&
2663  n4 == static_cast<size_t> (v.extent(4)) &&
2664  n5 == static_cast<size_t> (v.extent(5)) &&
2665  n6 == static_cast<size_t> (v.extent(6))) {
2666  return;
2667  }
2668  if (view_type::Rank == 8 &&
2669  n0 == static_cast<size_t> (v.extent(0)) &&
2670  n1 == static_cast<size_t> (v.extent(1)) &&
2671  n2 == static_cast<size_t> (v.extent(2)) &&
2672  n3 == static_cast<size_t> (v.extent(3)) &&
2673  n4 == static_cast<size_t> (v.extent(4)) &&
2674  n5 == static_cast<size_t> (v.extent(5)) &&
2675  n6 == static_cast<size_t> (v.extent(6)) &&
2676  n7 == static_cast<size_t> (v.extent(7))) {
2677  return;
2678  }
2679  // If Kokkos ever supports Views of rank > 8, the above code won't
2680  // be incorrect, because avoiding reallocation in resize() is just
2681  // an optimization.
2682 
2683  // TODO (mfh 27 Jun 2017) If the old View has enough space but just
2684  // different dimensions (e.g., if the product of the dimensions,
2685  // including extra space for alignment, will not change), then
2686  // consider just reusing storage. For now, Kokkos always
2687  // reallocates if any of the dimensions change, even if the old View
2688  // has enough space.
2689 
2690  view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
2691 
2692  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2693 
2694  v = v_resized ;
2695 }
2696 
2698 template< class T , class ... P >
2699 inline
2701  const typename Kokkos::View<T,P...>::array_layout & layout)
2702 {
2703  typedef Kokkos::View<T,P...> view_type ;
2704 
2705  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2706 
2707  view_type v_resized( v.label(), layout );
2708 
2709  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2710 
2711  v = v_resized ;
2712 }
2713 
2715 template< class T , class ... P >
2716 inline
2717 typename std::enable_if<
2718  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
2719  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
2720 >::type
2722  const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2723  const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2724  const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2725  const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2726  const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2727  const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2728  const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
2729  const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
2730 {
2731  typedef Kokkos::View<T,P...> view_type ;
2732 
2733  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2734 
2735  const std::string label = v.label();
2736 
2737  v = view_type(); // Deallocate first, if the only view to allocation
2738  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
2739 }
2740 
2742 template< class T , class ... P >
2743 inline
2745  const typename Kokkos::View<T,P...>::array_layout & layout)
2746 {
2747  typedef Kokkos::View<T,P...> view_type ;
2748 
2749  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2750 
2751  const std::string label = v.label();
2752 
2753  v = view_type(); // Deallocate first, if the only view to allocation
2754  v = view_type( label, layout );
2755 }
2756 } /* namespace Kokkos */
2757 
2758 //----------------------------------------------------------------------------
2759 //----------------------------------------------------------------------------
2760 
2761 namespace Kokkos {
2762 namespace Impl {
2763 
2764 // Deduce Mirror Types
2765 template<class Space, class T, class ... P>
2766 struct MirrorViewType {
2767  // The incoming view_type
2768  typedef typename Kokkos::View<T,P...> src_view_type;
2769  // The memory space for the mirror view
2770  typedef typename Space::memory_space memory_space;
2771  // Check whether it is the same memory space
2772  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2773  // The array_layout
2774  typedef typename src_view_type::array_layout array_layout;
2775  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2776  typedef typename src_view_type::non_const_data_type data_type;
2777  // The destination view type if it is not the same memory space
2778  typedef Kokkos::View<data_type,array_layout,Space> dest_view_type;
2779  // If it is the same memory_space return the existsing view_type
2780  // This will also keep the unmanaged trait if necessary
2781  typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
2782 };
2783 
2784 template<class Space, class T, class ... P>
2785 struct MirrorType {
2786  // The incoming view_type
2787  typedef typename Kokkos::View<T,P...> src_view_type;
2788  // The memory space for the mirror view
2789  typedef typename Space::memory_space memory_space;
2790  // Check whether it is the same memory space
2791  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2792  // The array_layout
2793  typedef typename src_view_type::array_layout array_layout;
2794  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2795  typedef typename src_view_type::non_const_data_type data_type;
2796  // The destination view type if it is not the same memory space
2798 };
2799 
2800 }
2801 
2802 template< class T , class ... P >
2803 inline
2804 typename Kokkos::View<T,P...>::HostMirror
2805 create_mirror( const Kokkos::View<T,P...> & src
2806  , typename std::enable_if<
2807  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
2808  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2809  , Kokkos::LayoutStride >::value
2810  >::type * = 0
2811  )
2812 {
2813  typedef View<T,P...> src_type ;
2814  typedef typename src_type::HostMirror dst_type ;
2815 
2816  return dst_type( std::string( src.label() ).append("_mirror")
2817 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
2818  , src.extent(0)
2819  , src.extent(1)
2820  , src.extent(2)
2821  , src.extent(3)
2822  , src.extent(4)
2823  , src.extent(5)
2824  , src.extent(6)
2825  , src.extent(7) );
2826 #else
2827  , src.rank_dynamic > 0 ? src.extent(0): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2828  , src.rank_dynamic > 1 ? src.extent(1): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2829  , src.rank_dynamic > 2 ? src.extent(2): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2830  , src.rank_dynamic > 3 ? src.extent(3): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2831  , src.rank_dynamic > 4 ? src.extent(4): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2832  , src.rank_dynamic > 5 ? src.extent(5): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2833  , src.rank_dynamic > 6 ? src.extent(6): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2834  , src.rank_dynamic > 7 ? src.extent(7): KOKKOS_IMPL_CTOR_DEFAULT_ARG );
2835 #endif
2836 }
2837 
2838 template< class T , class ... P >
2839 inline
2840 typename Kokkos::View<T,P...>::HostMirror
2841 create_mirror( const Kokkos::View<T,P...> & src
2842  , typename std::enable_if<
2843  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
2844  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2845  , Kokkos::LayoutStride >::value
2846  >::type * = 0
2847  )
2848 {
2849  typedef View<T,P...> src_type ;
2850  typedef typename src_type::HostMirror dst_type ;
2851 
2852  Kokkos::LayoutStride layout ;
2853 
2854  layout.dimension[0] = src.extent(0);
2855  layout.dimension[1] = src.extent(1);
2856  layout.dimension[2] = src.extent(2);
2857  layout.dimension[3] = src.extent(3);
2858  layout.dimension[4] = src.extent(4);
2859  layout.dimension[5] = src.extent(5);
2860  layout.dimension[6] = src.extent(6);
2861  layout.dimension[7] = src.extent(7);
2862 
2863  layout.stride[0] = src.stride_0();
2864  layout.stride[1] = src.stride_1();
2865  layout.stride[2] = src.stride_2();
2866  layout.stride[3] = src.stride_3();
2867  layout.stride[4] = src.stride_4();
2868  layout.stride[5] = src.stride_5();
2869  layout.stride[6] = src.stride_6();
2870  layout.stride[7] = src.stride_7();
2871 
2872  return dst_type( std::string( src.label() ).append("_mirror") , layout );
2873 }
2874 
2875 
2876 // Create a mirror in a new space (specialization for different space)
2877 template<class Space, class T, class ... P>
2878 typename Impl::MirrorType<Space,T,P ...>::view_type
2879 create_mirror(const Space& , const Kokkos::View<T,P...> & src
2880  , typename std::enable_if<
2881  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value
2882  >::type * = 0) {
2883  return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),src.layout());
2884 }
2885 
2886 template< class T , class ... P >
2887 inline
2888 typename Kokkos::View<T,P...>::HostMirror
2889 create_mirror_view( const Kokkos::View<T,P...> & src
2890  , typename std::enable_if<(
2891  std::is_same< typename Kokkos::View<T,P...>::memory_space
2892  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2893  >::value
2894  &&
2895  std::is_same< typename Kokkos::View<T,P...>::data_type
2896  , typename Kokkos::View<T,P...>::HostMirror::data_type
2897  >::value
2898  )>::type * = 0
2899  )
2900 {
2901  return src ;
2902 }
2903 
2904 template< class T , class ... P >
2905 inline
2906 typename Kokkos::View<T,P...>::HostMirror
2907 create_mirror_view( const Kokkos::View<T,P...> & src
2908  , typename std::enable_if< ! (
2909  std::is_same< typename Kokkos::View<T,P...>::memory_space
2910  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2911  >::value
2912  &&
2913  std::is_same< typename Kokkos::View<T,P...>::data_type
2914  , typename Kokkos::View<T,P...>::HostMirror::data_type
2915  >::value
2916  )>::type * = 0
2917  )
2918 {
2919  return Kokkos::create_mirror( src );
2920 }
2921 
2922 // Create a mirror view in a new space (specialization for same space)
2923 template<class Space, class T, class ... P>
2924 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2925 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2926  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2927  return src;
2928 }
2929 
2930 // Create a mirror view in a new space (specialization for different space)
2931 template<class Space, class T, class ... P>
2932 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2933 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2934  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2935  return typename Impl::MirrorViewType<Space,T,P ...>::view_type(src.label(),src.layout());
2936 }
2937 
2938 // Create a mirror view and deep_copy in a new space (specialization for same space)
2939 template<class Space, class T, class ... P>
2940 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2941 create_mirror_view_and_copy(const Space& , const Kokkos::View<T,P...> & src
2942  , std::string const& name = ""
2943  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2944  (void)name;
2945  return src;
2946 }
2947 
2948 // Create a mirror view and deep_copy in a new space (specialization for different space)
2949 template<class Space, class T, class ... P>
2950 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2951 create_mirror_view_and_copy(const Space& , const Kokkos::View<T,P...> & src
2952  , std::string const& name = ""
2953  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2954  using Mirror = typename Impl::MirrorViewType<Space,T,P ...>::view_type;
2955  std::string label = name.empty() ? src.label() : name;
2956  auto mirror = Mirror(ViewAllocateWithoutInitializing(label), src.layout());
2957  deep_copy(mirror, src);
2958  return mirror;
2959 }
2960 
2961 // Create a mirror view in a new space without initializing (specialization for same space)
2962 template<class Space, class T, class ... P>
2963 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2964 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2965  , Kokkos::Impl::WithoutInitializing_t
2966  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2967  return src;
2968 }
2969 
2970 // Create a mirror view in a new space without initializing (specialization for different space)
2971 template<class Space, class T, class ... P>
2972 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2973 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2974  , Kokkos::Impl::WithoutInitializing_t
2975  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2976  using Mirror = typename Impl::MirrorViewType<Space,T,P ...>::view_type;
2977  return Mirror(Kokkos::ViewAllocateWithoutInitializing(src.label()), src.layout());
2978 }
2979 
2980 } /* namespace Kokkos */
2981 
2982 
2983 //----------------------------------------------------------------------------
2984 //----------------------------------------------------------------------------
2985 
2986 #endif
void parallel_for(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename Impl::enable_if< Kokkos::Impl::is_execution_policy< ExecPolicy >::value >::type *=0)
Execute functor in parallel according to the execution policy.
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.
Can AccessSpace access MemorySpace ?
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type resize(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with copying old data to new data at the corresponding indices.
Replacement for std::pair that works on CUDA devices.
Definition: Kokkos_Pair.hpp:64
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
void deep_copy(const View< DT, DP...> &dst, typename ViewTraits< DT, DP...>::const_value_type &value, typename std::enable_if< std::is_same< typename ViewTraits< DT, DP...>::specialize, void >::value >::type *=0)
Deep copy a value from Host memory into a view.
View to an array of data.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type realloc(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with discarding old data.
Execution policy for work over a range of an integral type.
Traits class for accessing attributes of a View.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< std::is_integral< iType >::value, size_t >::type extent(const iType &r) const noexcept
rank() to be implemented