Kokkos Core Kernels Package  Version of the Day
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 
457  typedef Kokkos::Rank<2,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
458  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
459 
460  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
461  ExecSpace::fence();
462  Kokkos::parallel_for("Kokkos::ViewCopy-2D",
463  policy_type({0,0},{a.extent(0),a.extent(1)}),*this);
464  ExecSpace::fence();
465  }
466 
467  KOKKOS_INLINE_FUNCTION
468  void operator() (const iType& i0, const iType& i1) const {
469  a(i0,i1) = b(i0,i1);
470  };
471 };
472 
473 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
474 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,3,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
475  ViewTypeA a;
476  ViewTypeB b;
477 
478  typedef Kokkos::Rank<3,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
479  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
480 
481  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
482  ExecSpace::fence();
483  Kokkos::parallel_for("Kokkos::ViewCopy-3D",
484  policy_type({0,0,0},{a.extent(0),a.extent(1),a.extent(2)}),*this);
485  ExecSpace::fence();
486  }
487 
488  KOKKOS_INLINE_FUNCTION
489  void operator() (const iType& i0, const iType& i1, const iType& i2) const {
490  a(i0,i1,i2) = b(i0,i1,i2);
491  };
492 };
493 
494 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
495 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,4,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
496  ViewTypeA a;
497  ViewTypeB b;
498 
499  typedef Kokkos::Rank<4,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
500  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
501 
502  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
503  ExecSpace::fence();
504  Kokkos::parallel_for("Kokkos::ViewCopy-4D",
505  policy_type({0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
506  a.extent(3)}),*this);
507  ExecSpace::fence();
508  }
509 
510  KOKKOS_INLINE_FUNCTION
511  void operator() (const iType& i0, const iType& i1, const iType& i2,
512  const iType& i3) const {
513  a(i0,i1,i2,i3) = b(i0,i1,i2,i3);
514  };
515 };
516 
517 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
518 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,5,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
519  ViewTypeA a;
520  ViewTypeB b;
521 
522  typedef Kokkos::Rank<5,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
523  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
524 
525  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
526  ExecSpace::fence();
527  Kokkos::parallel_for("Kokkos::ViewCopy-5D",
528  policy_type({0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
529  a.extent(3),a.extent(4)}),*this);
530  ExecSpace::fence();
531  }
532 
533  KOKKOS_INLINE_FUNCTION
534  void operator() (const iType& i0, const iType& i1, const iType& i2,
535  const iType& i3, const iType& i4) const {
536  a(i0,i1,i2,i3,i4) = b(i0,i1,i2,i3,i4);
537  };
538 };
539 
540 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
541 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,6,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
542  ViewTypeA a;
543  ViewTypeB b;
544 
545  typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
546  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
547 
548  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
549  ExecSpace::fence();
550  Kokkos::parallel_for("Kokkos::ViewCopy-6D",
551  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(2),
552  a.extent(3),a.extent(4),a.extent(5)}),*this);
553  ExecSpace::fence();
554  }
555 
556  KOKKOS_INLINE_FUNCTION
557  void operator() (const iType& i0, const iType& i1, const iType& i2,
558  const iType& i3, const iType& i4, const iType& i5) const {
559  a(i0,i1,i2,i3,i4,i5) = b(i0,i1,i2,i3,i4,i5);
560  };
561 };
562 
563 
564 template<class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,typename iType>
565 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,7,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
566  ViewTypeA a;
567  ViewTypeB b;
568 
569  typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
570  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
571 
572  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
573  ExecSpace::fence();
574  Kokkos::parallel_for("Kokkos::ViewCopy-7D",
575  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
576  a.extent(4),a.extent(5),a.extent(6)}),*this);
577  ExecSpace::fence();
578  }
579 
580  KOKKOS_INLINE_FUNCTION
581  void operator() (const iType& i0, const iType& i1, const iType& i3,
582  const iType& i4, const iType& i5, const iType& i6) const {
583  for(iType i2=0; i2<iType(a.extent(2));i2++)
584  a(i0,i1,i2,i3,i4,i5,i6) = b(i0,i1,i2,i3,i4,i5,i6);
585  };
586 };
587 
588 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace,typename iType>
589 struct ViewCopy<ViewTypeA,ViewTypeB,Layout,ExecSpace,8,iType,KOKKOS_IMPL_COMPILING_LIBRARY> {
590  ViewTypeA a;
591  ViewTypeB b;
592 
593  typedef Kokkos::Rank<6,ViewFillLayoutSelector<Layout>::iterate,ViewFillLayoutSelector<Layout>::iterate> iterate_type;
594  typedef Kokkos::MDRangePolicy<ExecSpace,iterate_type,Kokkos::IndexType<iType>> policy_type;
595 
596  ViewCopy(const ViewTypeA& a_, const ViewTypeB& b_):a(a_),b(b_) {
597  ExecSpace::fence();
598  Kokkos::parallel_for("Kokkos::ViewCopy-8D",
599  policy_type({0,0,0,0,0,0},{a.extent(0),a.extent(1),a.extent(3),
600  a.extent(5),a.extent(6),a.extent(7)}),*this);
601  ExecSpace::fence();
602  }
603 
604  KOKKOS_INLINE_FUNCTION
605  void operator() (const iType& i0, const iType& i1, const iType& i3,
606  const iType& i5, const iType& i6, const iType& i7) const {
607  for(iType i2=0; i2<iType(a.extent(2));i2++)
608  for(iType i4=0; i4<iType(a.extent(4));i4++)
609  a(i0,i1,i2,i3,i4,i5,i6,i7) = b(i0,i1,i2,i3,i4,i5,i6,i7);
610  };
611 };
612 
613 }
614 }
615 
616 #include<impl/Kokkos_ViewFillCopyETIDecl.hpp>
617 
618 namespace Kokkos {
619 namespace Impl {
620 
621 template<class DstType, class SrcType>
622 void view_copy(const DstType& dst, const SrcType& src) {
623  typedef typename DstType::execution_space dst_execution_space;
624  typedef typename SrcType::execution_space src_execution_space;
625  typedef typename DstType::memory_space dst_memory_space;
626  typedef typename SrcType::memory_space src_memory_space;
627 
628  enum { DstExecCanAccessSrc =
630 
631  enum { SrcExecCanAccessDst =
633 
634  if( ! DstExecCanAccessSrc && ! SrcExecCanAccessDst) {
635  std::string message("Error: Kokkos::deep_copy with no available copy mechanism: ");
636  message += src.label(); message += " to ";
637  message += dst.label();
638  Kokkos::Impl::throw_runtime_exception(message);
639  }
640 
641  // Figure out iteration order in case we need it
642  int64_t strides[DstType::Rank+1];
643  dst.stride(strides);
644  Kokkos::Iterate iterate;
645  if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutRight>::value ) {
646  iterate = Kokkos::Iterate::Right;
647  } else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutLeft>::value ) {
648  iterate = Kokkos::Iterate::Left;
649  } else if ( std::is_same<typename DstType::array_layout,Kokkos::LayoutStride>::value ) {
650  if( strides[0] > strides[DstType::Rank-1] )
651  iterate = Kokkos::Iterate::Right;
652  else
653  iterate = Kokkos::Iterate::Left;
654  } else {
655  if( std::is_same<typename DstType::execution_space::array_layout, Kokkos::LayoutRight>::value )
656  iterate = Kokkos::Iterate::Right;
657  else
658  iterate = Kokkos::Iterate::Left;
659  }
660 
661  if( (dst.span() >= size_t(std::numeric_limits<int>::max())) ||
662  (src.span() >= size_t(std::numeric_limits<int>::max())) ){
663  if(DstExecCanAccessSrc) {
664  if(iterate == Kokkos::Iterate::Right)
665  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, dst_execution_space,
666  DstType::Rank, int64_t >( dst , src );
667  else
668  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, dst_execution_space,
669  DstType::Rank, int64_t >( dst , src );
670  } else {
671  if(iterate == Kokkos::Iterate::Right)
672  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, src_execution_space,
673  DstType::Rank, int64_t >( dst , src );
674  else
675  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, src_execution_space,
676  DstType::Rank, int64_t >( dst , src );
677  }
678  } else {
679  if(DstExecCanAccessSrc) {
680  if(iterate == Kokkos::Iterate::Right)
681  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, dst_execution_space,
682  DstType::Rank, int >( dst , src );
683  else
684  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, dst_execution_space,
685  DstType::Rank, int >( dst , src );
686  } else {
687  if(iterate == Kokkos::Iterate::Right)
688  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutRight, src_execution_space,
689  DstType::Rank, int >( dst , src );
690  else
691  Kokkos::Impl::ViewCopy< typename DstType::uniform_runtime_nomemspace_type, typename SrcType::uniform_runtime_const_nomemspace_type, Kokkos::LayoutLeft, src_execution_space,
692  DstType::Rank, int >( dst , src );
693  }
694 
695  }
696 }
697 
698 template<class DstType, class SrcType, int Rank, class ... Args>
699 struct CommonSubview;
700 
701 template<class DstType, class SrcType, class Arg0, class ... Args>
702 struct CommonSubview<DstType,SrcType,1,Arg0,Args...> {
703  typedef typename Kokkos::Subview<DstType,Arg0> dst_subview_type;
704  typedef typename Kokkos::Subview<SrcType,Arg0> src_subview_type;
705  dst_subview_type dst_sub;
706  src_subview_type src_sub;
707  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, Args... ):
708  dst_sub(dst,arg0),src_sub(src,arg0) {}
709 };
710 
711 template<class DstType, class SrcType, class Arg0, class Arg1, class ... Args>
712 struct CommonSubview<DstType,SrcType,2,Arg0,Arg1,Args...> {
713  typedef typename Kokkos::Subview<DstType,Arg0,Arg1> dst_subview_type;
714  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1> src_subview_type;
715  dst_subview_type dst_sub;
716  src_subview_type src_sub;
717  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1, Args... ):
718  dst_sub(dst,arg0,arg1),src_sub(src,arg0,arg1) {}
719 };
720 
721 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class ... Args>
722 struct CommonSubview<DstType,SrcType,3,Arg0,Arg1,Arg2,Args...> {
723  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2> dst_subview_type;
724  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2> src_subview_type;
725  dst_subview_type dst_sub;
726  src_subview_type src_sub;
727  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
728  const Arg2& arg2, Args... ):
729  dst_sub(dst,arg0,arg1,arg2),src_sub(src,arg0,arg1,arg2) {}
730 };
731 
732 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
733  class ... Args>
734 struct CommonSubview<DstType,SrcType,4,Arg0,Arg1,Arg2,Arg3,Args...> {
735  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3> dst_subview_type;
736  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3> src_subview_type;
737  dst_subview_type dst_sub;
738  src_subview_type src_sub;
739  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
740  const Arg2& arg2, const Arg3& arg3,
741  const Args ...):
742  dst_sub(dst,arg0,arg1,arg2,arg3),src_sub(src,arg0,arg1,arg2,arg3) {}
743 };
744 
745 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
746  class Arg4, class ... Args>
747 struct CommonSubview<DstType,SrcType,5,Arg0,Arg1,Arg2,Arg3,Arg4,Args...> {
748  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4> dst_subview_type;
749  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4> src_subview_type;
750  dst_subview_type dst_sub;
751  src_subview_type src_sub;
752  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
753  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4,
754  const Args ...):
755  dst_sub(dst,arg0,arg1,arg2,arg3,arg4),src_sub(src,arg0,arg1,arg2,arg3,arg4) {}
756 };
757 
758 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
759  class Arg4, class Arg5, class ... Args>
760 struct CommonSubview<DstType,SrcType,6,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Args...> {
761  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5> dst_subview_type;
762  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5> src_subview_type;
763  dst_subview_type dst_sub;
764  src_subview_type src_sub;
765  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
766  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5,
767  const Args ...):
768  dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5) {}
769 };
770 
771 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
772  class Arg4, class Arg5, class Arg6, class ...Args>
773 struct CommonSubview<DstType,SrcType,7,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Args...> {
774  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6> dst_subview_type;
775  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6> src_subview_type;
776  dst_subview_type dst_sub;
777  src_subview_type src_sub;
778  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
779  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5,
780  const Arg6& arg6, Args...):
781  dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5,arg6),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5,arg6) {}
782 };
783 
784 template<class DstType, class SrcType, class Arg0, class Arg1, class Arg2, class Arg3,
785  class Arg4, class Arg5, class Arg6, class Arg7>
786 struct CommonSubview<DstType,SrcType,8,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> {
787  typedef typename Kokkos::Subview<DstType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> dst_subview_type;
788  typedef typename Kokkos::Subview<SrcType,Arg0,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7> src_subview_type;
789  dst_subview_type dst_sub;
790  src_subview_type src_sub;
791  CommonSubview(const DstType& dst, const SrcType& src, const Arg0& arg0, const Arg1& arg1,
792  const Arg2& arg2, const Arg3& arg3, const Arg4& arg4, const Arg5& arg5,
793  const Arg6& arg6, const Arg7& arg7):
794  dst_sub(dst,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7),src_sub(src,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7) {}
795 };
796 
797 
798 template<class DstType, class SrcType, class ExecSpace = typename DstType::execution_space, int Rank = DstType::Rank>
799 struct ViewRemap;
800 
801 template<class DstType, class SrcType, class ExecSpace>
802 struct ViewRemap<DstType,SrcType,ExecSpace,1> {
803  typedef Kokkos::pair<int64_t,int64_t> p_type;
804 
805  ViewRemap(const DstType& dst, const SrcType& src) {
806  if(dst.extent(0) == src.extent(0)) {
807  view_copy(dst,src);
808  } else {
809  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
810  typedef CommonSubview<DstType,SrcType,1,p_type> sv_adapter_type;
811  sv_adapter_type common_subview(dst,src,ext0);
812  view_copy(common_subview.dst_sub,common_subview.src_sub);
813  }
814  }
815 };
816 
817 template<class DstType, class SrcType, class ExecSpace>
818 struct ViewRemap<DstType,SrcType,ExecSpace,2> {
819  typedef Kokkos::pair<int64_t,int64_t> p_type;
820 
821  ViewRemap(const DstType& dst, const SrcType& src) {
822  if(dst.extent(0) == src.extent(0)) {
823  if(dst.extent(1) == src.extent(1)) {
824  view_copy(dst,src);
825  } else {
826  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
827  typedef CommonSubview<DstType,SrcType,2,Kokkos::Impl::ALL_t,p_type> sv_adapter_type;
828  sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1);
829  view_copy(common_subview.dst_sub,common_subview.src_sub);
830  }
831  } else {
832  if(dst.extent(1) == src.extent(1)) {
833  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
834  typedef CommonSubview<DstType,SrcType,2,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
835  sv_adapter_type common_subview(dst,src,ext0,Kokkos::ALL);
836  view_copy(common_subview.dst_sub,common_subview.src_sub);
837  } else {
838  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
839  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
840  typedef CommonSubview<DstType,SrcType,2,p_type,p_type> sv_adapter_type;
841  sv_adapter_type common_subview(dst,src,ext0,ext1);
842  view_copy(common_subview.dst_sub,common_subview.src_sub);
843  }
844  }
845  }
846 };
847 
848 template<class DstType, class SrcType, class ExecSpace>
849 struct ViewRemap<DstType,SrcType,ExecSpace,3> {
850  typedef Kokkos::pair<int64_t,int64_t> p_type;
851 
852  ViewRemap(const DstType& dst, const SrcType& src) {
853  if(dst.extent(0) == src.extent(0)) {
854  if(dst.extent(2) == src.extent(2)) {
855  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
856  typedef CommonSubview<DstType,SrcType,3,Kokkos::Impl::ALL_t,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
857  sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1,Kokkos::ALL);
858  view_copy(common_subview.dst_sub,common_subview.src_sub);
859  } else {
860  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
861  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
862  typedef CommonSubview<DstType,SrcType,3,Kokkos::Impl::ALL_t,p_type,p_type> sv_adapter_type;
863  sv_adapter_type common_subview(dst,src,Kokkos::ALL,ext1,ext2);
864  view_copy(common_subview.dst_sub,common_subview.src_sub);
865  }
866  } else {
867  if(dst.extent(2) == src.extent(2)) {
868  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
869  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
870  typedef CommonSubview<DstType,SrcType,3,p_type,p_type,Kokkos::Impl::ALL_t> sv_adapter_type;
871  sv_adapter_type common_subview(dst,src,ext0,ext1,Kokkos::ALL);
872  view_copy(common_subview.dst_sub,common_subview.src_sub);
873  } else {
874  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
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,p_type,p_type,p_type> sv_adapter_type;
878  sv_adapter_type common_subview(dst,src,ext0,ext1,ext2);
879  view_copy(common_subview.dst_sub,common_subview.src_sub);
880  }
881  }
882  }
883 };
884 
885 template<class DstType, class SrcType, class ExecSpace>
886 struct ViewRemap<DstType,SrcType,ExecSpace,4> {
887  typedef Kokkos::pair<int64_t,int64_t> p_type;
888 
889  ViewRemap(const DstType& dst, const SrcType& src) {
890  if(dst.extent(0) == src.extent(0)) {
891  if(dst.extent(3) == src.extent(3)) {
892  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
893  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
894  typedef CommonSubview<DstType,SrcType,4,Kokkos::Impl::ALL_t,
895  p_type,p_type,
896  Kokkos::Impl::ALL_t> sv_adapter_type;
897  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
898  ext1,ext2,
899  Kokkos::ALL);
900  view_copy(common_subview.dst_sub,common_subview.src_sub);
901  } else {
902  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
903  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
904  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
905  typedef CommonSubview<DstType,SrcType,4,Kokkos::Impl::ALL_t,
906  p_type,p_type,
907  p_type> sv_adapter_type;
908  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
909  ext1,ext2,
910  ext3);
911  view_copy(common_subview.dst_sub,common_subview.src_sub);
912  }
913  } else {
914  if(dst.extent(7) == src.extent(7)) {
915  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
916  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
917  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
918  typedef CommonSubview<DstType,SrcType,4,p_type,
919  p_type,p_type,
920  Kokkos::Impl::ALL_t> sv_adapter_type;
921  sv_adapter_type common_subview(dst,src,ext0,
922  ext1,ext2,
923  Kokkos::ALL);
924  view_copy(common_subview.dst_sub,common_subview.src_sub);
925  } else {
926  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
927  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
928  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
929  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
930  typedef CommonSubview<DstType,SrcType,4,p_type,
931  p_type,p_type,
932  p_type> sv_adapter_type;
933  sv_adapter_type common_subview(dst,src,ext0,
934  ext1,ext2,
935  ext3);
936  view_copy(common_subview.dst_sub,common_subview.src_sub);
937  }
938  }
939  }
940 };
941 
942 template<class DstType, class SrcType, class ExecSpace>
943 struct ViewRemap<DstType,SrcType,ExecSpace,5> {
944  typedef Kokkos::pair<int64_t,int64_t> p_type;
945 
946  ViewRemap(const DstType& dst, const SrcType& src) {
947  if(dst.extent(0) == src.extent(0)) {
948  if(dst.extent(4) == src.extent(4)) {
949  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
950  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
951  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
952  typedef CommonSubview<DstType,SrcType,5,Kokkos::Impl::ALL_t,
953  p_type,p_type,p_type,
954  Kokkos::Impl::ALL_t> sv_adapter_type;
955  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
956  ext1,ext2,ext3,
957  Kokkos::ALL);
958  view_copy(common_subview.dst_sub,common_subview.src_sub);
959  } else {
960  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
961  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
962  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
963  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
964  typedef CommonSubview<DstType,SrcType,5,Kokkos::Impl::ALL_t,
965  p_type,p_type,p_type,
966  p_type> sv_adapter_type;
967  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
968  ext1,ext2,ext3,
969  ext4);
970  view_copy(common_subview.dst_sub,common_subview.src_sub);
971  }
972  } else {
973  if(dst.extent(4) == src.extent(4)) {
974  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
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  typedef CommonSubview<DstType,SrcType,5,p_type,
979  p_type,p_type,p_type,
980  Kokkos::Impl::ALL_t> sv_adapter_type;
981  sv_adapter_type common_subview(dst,src,ext0,
982  ext1,ext2,ext3,
983  Kokkos::ALL);
984  view_copy(common_subview.dst_sub,common_subview.src_sub);
985  } else {
986  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
987  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
988  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
989  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
990  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
991  typedef CommonSubview<DstType,SrcType,5,p_type,
992  p_type,p_type,p_type,
993  p_type> sv_adapter_type;
994  sv_adapter_type common_subview(dst,src,ext0,
995  ext1,ext2,ext3,
996  ext4);
997  view_copy(common_subview.dst_sub,common_subview.src_sub);
998  }
999  }
1000  }
1001 };
1002 template<class DstType, class SrcType, class ExecSpace>
1003 struct ViewRemap<DstType,SrcType,ExecSpace,6> {
1004  typedef Kokkos::pair<int64_t,int64_t> p_type;
1005 
1006  ViewRemap(const DstType& dst, const SrcType& src) {
1007  if(dst.extent(0) == src.extent(0)) {
1008  if(dst.extent(5) == src.extent(5)) {
1009  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1010  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1011  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1012  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1013  typedef CommonSubview<DstType,SrcType,6,Kokkos::Impl::ALL_t,
1014  p_type,p_type,p_type,p_type,
1015  Kokkos::Impl::ALL_t> sv_adapter_type;
1016  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1017  ext1,ext2,ext3,ext4,
1018  Kokkos::ALL);
1019  view_copy(common_subview.dst_sub,common_subview.src_sub);
1020  } else {
1021  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1022  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1023  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1024  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1025  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1026  typedef CommonSubview<DstType,SrcType,6,Kokkos::Impl::ALL_t,
1027  p_type,p_type,p_type,p_type,
1028  p_type> sv_adapter_type;
1029  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1030  ext1,ext2,ext3,ext4,
1031  ext5);
1032  view_copy(common_subview.dst_sub,common_subview.src_sub);
1033  }
1034  } else {
1035  if(dst.extent(5) == src.extent(5)) {
1036  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1037  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1038  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1039  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1040  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1041 
1042  typedef CommonSubview<DstType,SrcType,6,p_type,
1043  p_type,p_type,p_type,p_type,
1044  Kokkos::Impl::ALL_t> sv_adapter_type;
1045  sv_adapter_type common_subview(dst,src,ext0,
1046  ext1,ext2,ext3,ext4,
1047  Kokkos::ALL);
1048  view_copy(common_subview.dst_sub,common_subview.src_sub);
1049  } else {
1050  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1051  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1052  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1053  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1054  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1055  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1056 
1057  typedef CommonSubview<DstType,SrcType,6,p_type,
1058  p_type,p_type,p_type,p_type,
1059  p_type> sv_adapter_type;
1060  sv_adapter_type common_subview(dst,src,ext0,
1061  ext1,ext2,ext3,ext4,
1062  ext5);
1063  view_copy(common_subview.dst_sub,common_subview.src_sub);
1064  }
1065  }
1066  }
1067 };
1068 
1069 template<class DstType, class SrcType, class ExecSpace>
1070 struct ViewRemap<DstType,SrcType,ExecSpace,7> {
1071  typedef Kokkos::pair<int64_t,int64_t> p_type;
1072 
1073  ViewRemap(const DstType& dst, const SrcType& src) {
1074  if(dst.extent(0) == src.extent(0)) {
1075  if(dst.extent(6) == src.extent(6)) {
1076  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1077  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1078  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1079  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1080  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1081  typedef CommonSubview<DstType,SrcType,7,Kokkos::Impl::ALL_t,
1082  p_type,p_type,p_type,p_type,p_type,
1083  Kokkos::Impl::ALL_t> sv_adapter_type;
1084  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1085  ext1,ext2,ext3,ext4,ext5,
1086  Kokkos::ALL);
1087  view_copy(common_subview.dst_sub,common_subview.src_sub);
1088  } else {
1089  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1090  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1091  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1092  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1093  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1094  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1095  typedef CommonSubview<DstType,SrcType,7,Kokkos::Impl::ALL_t,
1096  p_type,p_type,p_type,p_type,p_type,
1097  p_type> sv_adapter_type;
1098  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1099  ext1,ext2,ext3,ext4,ext5,
1100  ext6);
1101  view_copy(common_subview.dst_sub,common_subview.src_sub);
1102  }
1103  } else {
1104  if(dst.extent(6) == src.extent(6)) {
1105  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1106  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1107  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1108  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1109  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1110  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1111  typedef CommonSubview<DstType,SrcType,7,p_type,
1112  p_type,p_type,p_type,p_type,p_type,
1113  Kokkos::Impl::ALL_t> sv_adapter_type;
1114  sv_adapter_type common_subview(dst,src,ext0,
1115  ext1,ext2,ext3,ext4,ext5,
1116  Kokkos::ALL);
1117  view_copy(common_subview.dst_sub,common_subview.src_sub);
1118  } else {
1119  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1120  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1121  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1122  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1123  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1124  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1125  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1126  typedef CommonSubview<DstType,SrcType,7,p_type,
1127  p_type,p_type,p_type,p_type,p_type,
1128  p_type> sv_adapter_type;
1129  sv_adapter_type common_subview(dst,src,ext0,
1130  ext1,ext2,ext3,ext4,ext5,
1131  ext6);
1132  view_copy(common_subview.dst_sub,common_subview.src_sub);
1133  }
1134  }
1135  }
1136 };
1137 
1138 template<class DstType, class SrcType, class ExecSpace>
1139 struct ViewRemap<DstType,SrcType,ExecSpace,8> {
1140  typedef Kokkos::pair<int64_t,int64_t> p_type;
1141 
1142  ViewRemap(const DstType& dst, const SrcType& src) {
1143  if(dst.extent(0) == src.extent(0)) {
1144  if(dst.extent(7) == src.extent(7)) {
1145  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1146  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1147  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1148  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1149  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1150  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1151  typedef CommonSubview<DstType,SrcType,8,Kokkos::Impl::ALL_t,
1152  p_type,p_type,p_type,p_type,p_type,p_type,
1153  Kokkos::Impl::ALL_t> sv_adapter_type;
1154  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1155  ext1,ext2,ext3,ext4,ext5,ext6,
1156  Kokkos::ALL);
1157  view_copy(common_subview.dst_sub,common_subview.src_sub);
1158  } else {
1159  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1160  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1161  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1162  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1163  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1164  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1165  p_type ext7(0,std::min(dst.extent(7),src.extent(7)));
1166  typedef CommonSubview<DstType,SrcType,8,Kokkos::Impl::ALL_t,
1167  p_type,p_type,p_type,p_type,p_type,p_type,
1168  p_type> sv_adapter_type;
1169  sv_adapter_type common_subview(dst,src,Kokkos::ALL,
1170  ext1,ext2,ext3,ext4,ext5,ext6,
1171  ext7);
1172  view_copy(common_subview.dst_sub,common_subview.src_sub);
1173  }
1174  } else {
1175  if(dst.extent(7) == src.extent(7)) {
1176  p_type ext0(0,std::min(dst.extent(0),src.extent(0)));
1177  p_type ext1(0,std::min(dst.extent(1),src.extent(1)));
1178  p_type ext2(0,std::min(dst.extent(2),src.extent(2)));
1179  p_type ext3(0,std::min(dst.extent(3),src.extent(3)));
1180  p_type ext4(0,std::min(dst.extent(4),src.extent(4)));
1181  p_type ext5(0,std::min(dst.extent(5),src.extent(5)));
1182  p_type ext6(0,std::min(dst.extent(6),src.extent(6)));
1183  typedef CommonSubview<DstType,SrcType,8,p_type,
1184  p_type,p_type,p_type,p_type,p_type,p_type,
1185  Kokkos::Impl::ALL_t> sv_adapter_type;
1186  sv_adapter_type common_subview(dst,src,ext0,
1187  ext1,ext2,ext3,ext4,ext5,ext6,
1188  Kokkos::ALL);
1189  view_copy(common_subview.dst_sub,common_subview.src_sub);
1190  } else {
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  p_type ext7(0,std::min(dst.extent(7),src.extent(7)));
1199  typedef CommonSubview<DstType,SrcType,8,p_type,
1200  p_type,p_type,p_type,p_type,p_type,p_type,
1201  p_type> sv_adapter_type;
1202  sv_adapter_type common_subview(dst,src,ext0,
1203  ext1,ext2,ext3,ext4,ext5,ext6,
1204  ext7);
1205  view_copy(common_subview.dst_sub,common_subview.src_sub);
1206  }
1207  }
1208  }
1209 };
1210 
1211 }
1212 
1214 template< class DT , class ... DP >
1215 inline
1216 void deep_copy
1217  ( const View<DT,DP...> & dst
1218  , typename ViewTraits<DT,DP...>::const_value_type & value
1219  , typename std::enable_if<
1220  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1221  >::type * = 0 )
1222 {
1223  typedef View<DT,DP...> ViewType;
1224  if(dst.data() == NULL ) {
1225  Kokkos::fence();
1226  return;
1227  }
1228 
1229  Kokkos::fence();
1230  static_assert(
1231  std::is_same< typename ViewType::non_const_value_type ,
1232  typename ViewType::value_type >::value
1233  , "deep_copy requires non-const type" );
1234 
1235  // If contigous we can simply do a 1D flat loop
1236  if(dst.span_is_contiguous()) {
1237  typedef Kokkos::View<typename ViewType::value_type*,Kokkos::LayoutRight,
1238  Kokkos::Device<typename ViewType::execution_space,
1239  typename std::conditional<ViewType::Rank==0,
1240  typename ViewType::memory_space,Kokkos::AnonymousSpace
1241  >::type>,
1242  Kokkos::MemoryTraits<0> >
1243  ViewTypeFlat;
1244 
1245  ViewTypeFlat dst_flat(dst.data(),dst.size());
1246  if(dst.span() < std::numeric_limits<int>::max())
1247  Kokkos::Impl::ViewFill< ViewTypeFlat , Kokkos::LayoutRight, typename ViewType::execution_space, ViewTypeFlat::Rank, int >( dst_flat , value );
1248  else
1249  Kokkos::Impl::ViewFill< ViewTypeFlat , Kokkos::LayoutRight, typename ViewType::execution_space, ViewTypeFlat::Rank, int64_t >( dst_flat , value );
1250  Kokkos::fence();
1251  return;
1252  }
1253 
1254  // Figure out iteration order to do the ViewFill
1255  int64_t strides[ViewType::Rank+1];
1256  dst.stride(strides);
1257  Kokkos::Iterate iterate;
1258  if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutRight>::value ) {
1259  iterate = Kokkos::Iterate::Right;
1260  } else if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutLeft>::value ) {
1261  iterate = Kokkos::Iterate::Left;
1262  } else if ( std::is_same<typename ViewType::array_layout,Kokkos::LayoutStride>::value ) {
1263  if( strides[0] > strides[ViewType::Rank>0?ViewType::Rank-1:0] )
1264  iterate = Kokkos::Iterate::Right;
1265  else
1266  iterate = Kokkos::Iterate::Left;
1267  } else {
1268  if( std::is_same<typename ViewType::execution_space::array_layout, Kokkos::LayoutRight>::value )
1269  iterate = Kokkos::Iterate::Right;
1270  else
1271  iterate = Kokkos::Iterate::Left;
1272  }
1273 
1274  // Lets call the right ViewFill functor based on integer space needed and iteration type
1275  typedef typename std::conditional<ViewType::Rank==0,
1276  typename ViewType::uniform_runtime_type,
1277  typename ViewType::uniform_runtime_nomemspace_type>::type ViewTypeUniform;
1278  if(dst.span() > std::numeric_limits<int>::max()) {
1279  if(iterate == Kokkos::Iterate::Right)
1280  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutRight, typename ViewType::execution_space, ViewType::Rank, int64_t >( dst , value );
1281  else
1282  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutLeft, typename ViewType::execution_space, ViewType::Rank, int64_t >( dst , value );
1283  } else {
1284  if(iterate == Kokkos::Iterate::Right)
1285  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutRight, typename ViewType::execution_space, ViewType::Rank, int >( dst , value );
1286  else
1287  Kokkos::Impl::ViewFill< ViewTypeUniform, Kokkos::LayoutLeft, typename ViewType::execution_space, ViewType::Rank, int >( dst , value );
1288  }
1289  Kokkos::fence();
1290 }
1291 
1293 template< class ST , class ... SP >
1294 inline
1295 void deep_copy
1296  ( typename ViewTraits<ST,SP...>::non_const_value_type & dst
1297  , const View<ST,SP...> & src
1298  , typename std::enable_if<
1299  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1300  >::type * = 0 )
1301 {
1302  static_assert( ViewTraits<ST,SP...>::rank == 0
1303  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1304 
1305  if(src.data() == NULL) {
1306  Kokkos::fence();
1307  return;
1308  }
1309 
1310  typedef ViewTraits<ST,SP...> src_traits ;
1311  typedef typename src_traits::memory_space src_memory_space ;
1312  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() , sizeof(ST) );
1313 }
1314 
1315 //----------------------------------------------------------------------------
1317 template< class DT , class ... DP , class ST , class ... SP >
1318 inline
1319 void deep_copy
1320  ( const View<DT,DP...> & dst
1321  , const View<ST,SP...> & src
1322  , typename std::enable_if<(
1323  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1324  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1325  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
1326  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
1327  )>::type * = 0 )
1328 {
1329  static_assert(
1330  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1331  typename ViewTraits<ST,SP...>::non_const_value_type >::value
1332  , "deep_copy requires matching non-const destination type" );
1333 
1334  if(dst.data() == NULL && src.data() == NULL) {
1335  Kokkos::fence();
1336  return;
1337  }
1338 
1339  typedef View<DT,DP...> dst_type ;
1340  typedef View<ST,SP...> src_type ;
1341 
1342  typedef typename dst_type::value_type value_type ;
1343  typedef typename dst_type::memory_space dst_memory_space ;
1344  typedef typename src_type::memory_space src_memory_space ;
1345 
1346  Kokkos::fence();
1347  if ( dst.data() != src.data() ) {
1348  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , sizeof(value_type) );
1349  Kokkos::fence();
1350  }
1351 }
1352 
1353 //----------------------------------------------------------------------------
1357 template< class DT , class ... DP , class ST , class ... SP >
1358 inline
1359 void deep_copy
1360  ( const View<DT,DP...> & dst
1361  , const View<ST,SP...> & src
1362  , typename std::enable_if<(
1363  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1364  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1365  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
1366  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
1367  )>::type * = 0 )
1368 {
1369  typedef View<DT,DP...> dst_type ;
1370  typedef View<ST,SP...> src_type ;
1371 
1372  static_assert(
1373  std::is_same< typename dst_type::value_type ,
1374  typename dst_type::non_const_value_type >::value
1375  , "deep_copy requires non-const destination type" );
1376 
1377  static_assert(
1378  ( unsigned(dst_type::rank) ==
1379  unsigned(src_type::rank) )
1380  , "deep_copy requires Views of equal rank" );
1381 
1382 
1383  typedef typename dst_type::execution_space dst_execution_space ;
1384  typedef typename src_type::execution_space src_execution_space ;
1385  typedef typename dst_type::memory_space dst_memory_space ;
1386  typedef typename src_type::memory_space src_memory_space ;
1387  typedef typename dst_type::value_type dst_value_type ;
1388  typedef typename src_type::value_type src_value_type ;
1389  if(dst.data() == NULL && src.data() == NULL) {
1390  Kokkos::fence();
1391  return;
1392  }
1393 
1394  enum { DstExecCanAccessSrc =
1396 
1397  enum { SrcExecCanAccessDst =
1399 
1400 
1401  // Checking for Overlapping Views.
1402  dst_value_type* dst_start = dst.data();
1403  dst_value_type* dst_end = dst.data() + dst.span();
1404  src_value_type* src_start = src.data();
1405  src_value_type* src_end = src.data() + src.span();
1406  if( ((std::ptrdiff_t)dst_start == (std::ptrdiff_t)src_start) &&
1407  ((std::ptrdiff_t)dst_end == (std::ptrdiff_t)src_end) &&
1408  (dst.span_is_contiguous() && src.span_is_contiguous()) ) {
1409  Kokkos::fence();
1410  return;
1411  }
1412 
1413  if( ( ( (std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end ) && ( (std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start ) ) &&
1414  ( ( dst.span_is_contiguous() && src.span_is_contiguous() ))) {
1415  std::string message("Error: Kokkos::deep_copy of overlapping views: ");
1416  message += dst.label(); message += "(";
1417  message += std::to_string((std::ptrdiff_t)dst_start); message += ",";
1418  message += std::to_string((std::ptrdiff_t)dst_end); message += ") ";
1419  message += src.label(); message += "(";
1420  message += std::to_string((std::ptrdiff_t)src_start); message += ",";
1421  message += std::to_string((std::ptrdiff_t)src_end); message += ") ";
1422  Kokkos::Impl::throw_runtime_exception(message);
1423  }
1424 
1425  // Check for same extents
1426  if ( (src.extent(0) != dst.extent(0)) ||
1427  (src.extent(1) != dst.extent(1)) ||
1428  (src.extent(2) != dst.extent(2)) ||
1429  (src.extent(3) != dst.extent(3)) ||
1430  (src.extent(4) != dst.extent(4)) ||
1431  (src.extent(5) != dst.extent(5)) ||
1432  (src.extent(6) != dst.extent(6)) ||
1433  (src.extent(7) != dst.extent(7))
1434  ) {
1435 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1436  Kokkos::fence();
1437  if ( DstExecCanAccessSrc ) {
1438  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1439  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1440  }
1441  else if ( SrcExecCanAccessDst ) {
1442  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1443  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1444  }
1445  else {
1446  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1447  }
1448  Kokkos::fence();
1449  return;
1450 #else
1451  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1452  message += dst.label(); message += "(";
1453  for(int r = 0; r<dst_type::Rank-1; r++)
1454  { message+= std::to_string(dst.extent(r)); message += ","; }
1455  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
1456  message += src.label(); message += "(";
1457  for(int r = 0; r<src_type::Rank-1; r++)
1458  { message+= std::to_string(src.extent(r)); message += ","; }
1459  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
1460 
1461  Kokkos::Impl::throw_runtime_exception(message);
1462 #endif
1463  }
1464 
1465  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1466 
1467  if ( std::is_same< typename dst_type::value_type ,
1468  typename src_type::non_const_value_type >::value &&
1469  (
1470  std::is_same< typename dst_type::array_layout ,
1471  typename src_type::array_layout >::value
1472  ||
1473  ( dst_type::rank == 1 &&
1474  src_type::rank == 1 )
1475  ) &&
1476  dst.span_is_contiguous() &&
1477  src.span_is_contiguous() &&
1478  ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1479  ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1480  ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1481  ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1482  ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1483  ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1484  ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1485  ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))
1486  ) {
1487  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1488  Kokkos::fence();
1489  if((void*)dst.data()!=(void*)src.data()) {
1490  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >
1491  ( dst.data() , src.data() , nbytes );
1492  }
1493  Kokkos::fence();
1494  } else {
1495  Kokkos::fence();
1496  Impl::view_copy(dst, src);
1497  Kokkos::fence();
1498  }
1499 }
1500 
1501 } /* namespace Kokkos */
1502 
1503 //----------------------------------------------------------------------------
1504 //----------------------------------------------------------------------------
1505 
1506 namespace Kokkos {
1507 
1509 template< class ExecSpace ,class DT , class ... DP >
1510 inline
1511 void deep_copy
1512  ( const ExecSpace &
1513  , const View<DT,DP...> & dst
1514  , typename ViewTraits<DT,DP...>::const_value_type & value
1515  , typename std::enable_if<
1516  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1517  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1518  >::type * = 0 )
1519 {
1520  static_assert(
1521  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
1522  typename ViewTraits<DT,DP...>::value_type >::value
1523  , "deep_copy requires non-const type" );
1524 
1525  ExecSpace::fence();
1526  typedef typename View<DT,DP...>::uniform_runtime_nomemspace_type ViewTypeUniform;
1527  Kokkos::Impl::ViewFill< ViewTypeUniform >( dst , value );
1528  ExecSpace::fence();
1529 }
1530 
1532 template< class ExecSpace , class ST , class ... SP >
1533 inline
1534 void deep_copy
1535  ( const ExecSpace & exec_space
1536  , typename ViewTraits<ST,SP...>::non_const_value_type & dst
1537  , const View<ST,SP...> & src
1538  , typename std::enable_if<
1539  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1540  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1541  >::type * = 0 )
1542 {
1543  static_assert( ViewTraits<ST,SP...>::rank == 0
1544  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1545 
1546  if(src.data() == NULL) {
1547  exec_space.fence();
1548  return;
1549  }
1550 
1551  typedef ViewTraits<ST,SP...> src_traits ;
1552  typedef typename src_traits::memory_space src_memory_space ;
1553  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >
1554  ( exec_space , & dst , src.data() , sizeof(ST) );
1555 }
1556 
1557 //----------------------------------------------------------------------------
1559 template< class ExecSpace , class DT , class ... DP , class ST , class ... SP >
1560 inline
1561 void deep_copy
1562  ( const ExecSpace & exec_space
1563  , const View<DT,DP...> & dst
1564  , const View<ST,SP...> & src
1565  , typename std::enable_if<(
1566  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1567  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1568  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1569  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
1570  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
1571  )>::type * = 0 )
1572 {
1573  static_assert(
1574  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1575  typename ViewTraits<ST,SP...>::non_const_value_type >::value
1576  , "deep_copy requires matching non-const destination type" );
1577 
1578  typedef View<DT,DP...> dst_type ;
1579  typedef View<ST,SP...> src_type ;
1580 
1581  typedef typename dst_type::value_type value_type ;
1582  typedef typename dst_type::memory_space dst_memory_space ;
1583  typedef typename src_type::memory_space src_memory_space ;
1584  if(dst.data() == NULL && src.data() == NULL) {
1585  exec_space.fence();
1586  return;
1587  }
1588 
1589  exec_space.fence();
1590  if ( dst.data() != src.data() ) {
1591  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1592  ( exec_space , dst.data() , src.data() , sizeof(value_type) );
1593  }
1594  exec_space.fence();
1595 }
1596 
1597 //----------------------------------------------------------------------------
1601 template< class ExecSpace , class DT, class ... DP, class ST, class ... SP >
1602 inline
1603 void deep_copy
1604  ( const ExecSpace & exec_space
1605  , const View<DT,DP...> & dst
1606  , const View<ST,SP...> & src
1607  , typename std::enable_if<(
1608  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1609  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1610  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1611  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
1612  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
1613  )>::type * = 0 )
1614 {
1615  typedef View<DT,DP...> dst_type ;
1616  typedef View<ST,SP...> src_type ;
1617 
1618  static_assert(
1619  std::is_same< typename dst_type::value_type ,
1620  typename dst_type::non_const_value_type >::value
1621  , "deep_copy requires non-const destination type" );
1622 
1623  static_assert(
1624  ( unsigned(dst_type::rank) ==
1625  unsigned(src_type::rank) )
1626  , "deep_copy requires Views of equal rank" );
1627 
1628  typedef typename dst_type::execution_space dst_execution_space ;
1629  typedef typename src_type::execution_space src_execution_space ;
1630  typedef typename dst_type::memory_space dst_memory_space ;
1631  typedef typename src_type::memory_space src_memory_space ;
1632  typedef typename dst_type::value_type dst_value_type ;
1633  typedef typename src_type::value_type src_value_type ;
1634 
1635  if(dst.data() == NULL && src.data() == NULL) {
1636  exec_space.fence();
1637  return;
1638  }
1639 
1640  enum { ExecCanAccessSrcDst =
1643  };
1644  enum { DstExecCanAccessSrc =
1646 
1647  enum { SrcExecCanAccessDst =
1649 
1650  // Checking for Overlapping Views.
1651  dst_value_type* dst_start = dst.data();
1652  dst_value_type* dst_end = dst.data() + dst.span();
1653  src_value_type* src_start = src.data();
1654  src_value_type* src_end = src.data() + src.span();
1655  if( ( ( (std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end ) && ( (std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start ) ) &&
1656  ( ( dst.span_is_contiguous() && src.span_is_contiguous() ))) {
1657  std::string message("Error: Kokkos::deep_copy of overlapping views: ");
1658  message += dst.label(); message += "(";
1659  message += std::to_string((std::ptrdiff_t)dst_start); message += ",";
1660  message += std::to_string((std::ptrdiff_t)dst_end); message += ") ";
1661  message += src.label(); message += "(";
1662  message += std::to_string((std::ptrdiff_t)src_start); message += ",";
1663  message += std::to_string((std::ptrdiff_t)src_end); message += ") ";
1664  Kokkos::Impl::throw_runtime_exception(message);
1665  }
1666 
1667  // Check for same extents
1668  if ( (src.extent(0) != dst.extent(0)) ||
1669  (src.extent(1) != dst.extent(1)) ||
1670  (src.extent(2) != dst.extent(2)) ||
1671  (src.extent(3) != dst.extent(3)) ||
1672  (src.extent(4) != dst.extent(4)) ||
1673  (src.extent(5) != dst.extent(5)) ||
1674  (src.extent(6) != dst.extent(6)) ||
1675  (src.extent(7) != dst.extent(7))
1676  ) {
1677 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1678  exec_space.fence();
1679  if ( ExecCanAccessSrcDst ) {
1680  Kokkos::Impl::ViewRemap< dst_type , src_type , ExecSpace >( dst , src );
1681  }
1682  else if ( DstExecCanAccessSrc ) {
1683  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1684  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1685  }
1686  else if ( SrcExecCanAccessDst ) {
1687  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1688  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1689  }
1690  else {
1691  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1692  }
1693  exec_space.fence();
1694  return;
1695 #else
1696  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1697  message += dst.label(); message += "(";
1698  for(int r = 0; r<dst_type::Rank-1; r++)
1699  { message+= std::to_string(dst.extent(r)); message += ","; }
1700  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
1701  message += src.label(); message += "(";
1702  for(int r = 0; r<src_type::Rank-1; r++)
1703  { message+= std::to_string(src.extent(r)); message += ","; }
1704  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
1705 
1706  Kokkos::Impl::throw_runtime_exception(message);
1707 #endif
1708  }
1709 
1710  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1711 
1712  if ( std::is_same< typename dst_type::value_type ,
1713  typename src_type::non_const_value_type >::value &&
1714  (
1715  std::is_same< typename dst_type::array_layout ,
1716  typename src_type::array_layout >::value
1717  ||
1718  ( dst_type::rank == 1 &&
1719  src_type::rank == 1 )
1720  ) &&
1721  dst.span_is_contiguous() &&
1722  src.span_is_contiguous() &&
1723  ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1724  ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1725  ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1726  ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1727  ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1728  ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1729  ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1730  ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))
1731  ) {
1732 
1733  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1734  exec_space.fence();
1735  if((void*)dst.data() != (void*)src.data()) {
1736  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1737  ( exec_space , dst.data() , src.data() , nbytes );
1738  }
1739  exec_space.fence();
1740  } else {
1741  exec_space.fence();
1742  Impl::view_copy(dst, src);
1743  exec_space.fence();
1744  }
1745 }
1746 
1747 } /* namespace Kokkos */
1748 
1749 //----------------------------------------------------------------------------
1750 //----------------------------------------------------------------------------
1751 
1752 namespace Kokkos {
1753 
1755 template< class T , class ... P >
1756 inline
1757 typename std::enable_if<
1758  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
1759  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
1760 >::type
1762  const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1763  const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1764  const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1765  const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1766  const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1767  const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1768  const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1769  const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
1770 {
1771  typedef Kokkos::View<T,P...> view_type ;
1772 
1773  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
1774 
1775  // Fix #904 by checking dimensions before actually resizing.
1776  //
1777  // Rank is known at compile time, so hopefully the compiler will
1778  // remove branches that are compile-time false. The upcoming "if
1779  // constexpr" language feature would make this certain.
1780  if (view_type::Rank == 1 &&
1781  n0 == static_cast<size_t> (v.extent(0))) {
1782  return;
1783  }
1784  if (view_type::Rank == 2 &&
1785  n0 == static_cast<size_t> (v.extent(0)) &&
1786  n1 == static_cast<size_t> (v.extent(1))) {
1787  return;
1788  }
1789  if (view_type::Rank == 3 &&
1790  n0 == static_cast<size_t> (v.extent(0)) &&
1791  n1 == static_cast<size_t> (v.extent(1)) &&
1792  n2 == static_cast<size_t> (v.extent(2))) {
1793  return;
1794  }
1795  if (view_type::Rank == 4 &&
1796  n0 == static_cast<size_t> (v.extent(0)) &&
1797  n1 == static_cast<size_t> (v.extent(1)) &&
1798  n2 == static_cast<size_t> (v.extent(2)) &&
1799  n3 == static_cast<size_t> (v.extent(3))) {
1800  return;
1801  }
1802  if (view_type::Rank == 5 &&
1803  n0 == static_cast<size_t> (v.extent(0)) &&
1804  n1 == static_cast<size_t> (v.extent(1)) &&
1805  n2 == static_cast<size_t> (v.extent(2)) &&
1806  n3 == static_cast<size_t> (v.extent(3)) &&
1807  n4 == static_cast<size_t> (v.extent(4))) {
1808  return;
1809  }
1810  if (view_type::Rank == 6 &&
1811  n0 == static_cast<size_t> (v.extent(0)) &&
1812  n1 == static_cast<size_t> (v.extent(1)) &&
1813  n2 == static_cast<size_t> (v.extent(2)) &&
1814  n3 == static_cast<size_t> (v.extent(3)) &&
1815  n4 == static_cast<size_t> (v.extent(4)) &&
1816  n5 == static_cast<size_t> (v.extent(5))) {
1817  return;
1818  }
1819  if (view_type::Rank == 7 &&
1820  n0 == static_cast<size_t> (v.extent(0)) &&
1821  n1 == static_cast<size_t> (v.extent(1)) &&
1822  n2 == static_cast<size_t> (v.extent(2)) &&
1823  n3 == static_cast<size_t> (v.extent(3)) &&
1824  n4 == static_cast<size_t> (v.extent(4)) &&
1825  n5 == static_cast<size_t> (v.extent(5)) &&
1826  n6 == static_cast<size_t> (v.extent(6))) {
1827  return;
1828  }
1829  if (view_type::Rank == 8 &&
1830  n0 == static_cast<size_t> (v.extent(0)) &&
1831  n1 == static_cast<size_t> (v.extent(1)) &&
1832  n2 == static_cast<size_t> (v.extent(2)) &&
1833  n3 == static_cast<size_t> (v.extent(3)) &&
1834  n4 == static_cast<size_t> (v.extent(4)) &&
1835  n5 == static_cast<size_t> (v.extent(5)) &&
1836  n6 == static_cast<size_t> (v.extent(6)) &&
1837  n7 == static_cast<size_t> (v.extent(7))) {
1838  return;
1839  }
1840  // If Kokkos ever supports Views of rank > 8, the above code won't
1841  // be incorrect, because avoiding reallocation in resize() is just
1842  // an optimization.
1843 
1844  // TODO (mfh 27 Jun 2017) If the old View has enough space but just
1845  // different dimensions (e.g., if the product of the dimensions,
1846  // including extra space for alignment, will not change), then
1847  // consider just reusing storage. For now, Kokkos always
1848  // reallocates if any of the dimensions change, even if the old View
1849  // has enough space.
1850 
1851  view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
1852 
1853  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
1854 
1855  v = v_resized ;
1856 }
1857 
1859 template< class T , class ... P >
1860 inline
1862  const typename Kokkos::View<T,P...>::array_layout & layout)
1863 {
1864  typedef Kokkos::View<T,P...> view_type ;
1865 
1866  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
1867 
1868  view_type v_resized( v.label(), layout );
1869 
1870  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
1871 
1872  v = v_resized ;
1873 }
1874 
1876 template< class T , class ... P >
1877 inline
1878 typename std::enable_if<
1879  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
1880  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
1881 >::type
1883  const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1884  const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1885  const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1886  const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1887  const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1888  const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1889  const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1890  const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
1891 {
1892  typedef Kokkos::View<T,P...> view_type ;
1893 
1894  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
1895 
1896  const std::string label = v.label();
1897 
1898  v = view_type(); // Deallocate first, if the only view to allocation
1899  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
1900 }
1901 
1903 template< class T , class ... P >
1904 inline
1906  const typename Kokkos::View<T,P...>::array_layout & layout)
1907 {
1908  typedef Kokkos::View<T,P...> view_type ;
1909 
1910  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
1911 
1912  const std::string label = v.label();
1913 
1914  v = view_type(); // Deallocate first, if the only view to allocation
1915  v = view_type( label, layout );
1916 }
1917 } /* namespace Kokkos */
1918 
1919 //----------------------------------------------------------------------------
1920 //----------------------------------------------------------------------------
1921 
1922 namespace Kokkos {
1923 namespace Impl {
1924 
1925 // Deduce Mirror Types
1926 template<class Space, class T, class ... P>
1927 struct MirrorViewType {
1928  // The incoming view_type
1929  typedef typename Kokkos::View<T,P...> src_view_type;
1930  // The memory space for the mirror view
1931  typedef typename Space::memory_space memory_space;
1932  // Check whether it is the same memory space
1933  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
1934  // The array_layout
1935  typedef typename src_view_type::array_layout array_layout;
1936  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
1937  typedef typename src_view_type::non_const_data_type data_type;
1938  // The destination view type if it is not the same memory space
1939  typedef Kokkos::View<data_type,array_layout,Space> dest_view_type;
1940  // If it is the same memory_space return the existsing view_type
1941  // This will also keep the unmanaged trait if necessary
1942  typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
1943 };
1944 
1945 template<class Space, class T, class ... P>
1946 struct MirrorType {
1947  // The incoming view_type
1948  typedef typename Kokkos::View<T,P...> src_view_type;
1949  // The memory space for the mirror view
1950  typedef typename Space::memory_space memory_space;
1951  // Check whether it is the same memory space
1952  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
1953  // The array_layout
1954  typedef typename src_view_type::array_layout array_layout;
1955  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
1956  typedef typename src_view_type::non_const_data_type data_type;
1957  // The destination view type if it is not the same memory space
1959 };
1960 
1961 }
1962 
1963 template< class T , class ... P >
1964 inline
1965 typename Kokkos::View<T,P...>::HostMirror
1966 create_mirror( const Kokkos::View<T,P...> & src
1967  , typename std::enable_if<
1968  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
1969  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1970  , Kokkos::LayoutStride >::value
1971  >::type * = 0
1972  )
1973 {
1974  typedef View<T,P...> src_type ;
1975  typedef typename src_type::HostMirror dst_type ;
1976 
1977  return dst_type( std::string( src.label() ).append("_mirror")
1978 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1979  , src.extent(0)
1980  , src.extent(1)
1981  , src.extent(2)
1982  , src.extent(3)
1983  , src.extent(4)
1984  , src.extent(5)
1985  , src.extent(6)
1986  , src.extent(7) );
1987 #else
1988  , src.rank_dynamic > 0 ? src.extent(0): KOKKOS_IMPL_CTOR_DEFAULT_ARG
1989  , src.rank_dynamic > 1 ? src.extent(1): KOKKOS_IMPL_CTOR_DEFAULT_ARG
1990  , src.rank_dynamic > 2 ? src.extent(2): KOKKOS_IMPL_CTOR_DEFAULT_ARG
1991  , src.rank_dynamic > 3 ? src.extent(3): KOKKOS_IMPL_CTOR_DEFAULT_ARG
1992  , src.rank_dynamic > 4 ? src.extent(4): KOKKOS_IMPL_CTOR_DEFAULT_ARG
1993  , src.rank_dynamic > 5 ? src.extent(5): KOKKOS_IMPL_CTOR_DEFAULT_ARG
1994  , src.rank_dynamic > 6 ? src.extent(6): KOKKOS_IMPL_CTOR_DEFAULT_ARG
1995  , src.rank_dynamic > 7 ? src.extent(7): KOKKOS_IMPL_CTOR_DEFAULT_ARG );
1996 #endif
1997 }
1998 
1999 template< class T , class ... P >
2000 inline
2001 typename Kokkos::View<T,P...>::HostMirror
2002 create_mirror( const Kokkos::View<T,P...> & src
2003  , typename std::enable_if<
2004  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
2005  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2006  , Kokkos::LayoutStride >::value
2007  >::type * = 0
2008  )
2009 {
2010  typedef View<T,P...> src_type ;
2011  typedef typename src_type::HostMirror dst_type ;
2012 
2013  Kokkos::LayoutStride layout ;
2014 
2015  layout.dimension[0] = src.extent(0);
2016  layout.dimension[1] = src.extent(1);
2017  layout.dimension[2] = src.extent(2);
2018  layout.dimension[3] = src.extent(3);
2019  layout.dimension[4] = src.extent(4);
2020  layout.dimension[5] = src.extent(5);
2021  layout.dimension[6] = src.extent(6);
2022  layout.dimension[7] = src.extent(7);
2023 
2024  layout.stride[0] = src.stride_0();
2025  layout.stride[1] = src.stride_1();
2026  layout.stride[2] = src.stride_2();
2027  layout.stride[3] = src.stride_3();
2028  layout.stride[4] = src.stride_4();
2029  layout.stride[5] = src.stride_5();
2030  layout.stride[6] = src.stride_6();
2031  layout.stride[7] = src.stride_7();
2032 
2033  return dst_type( std::string( src.label() ).append("_mirror") , layout );
2034 }
2035 
2036 
2037 // Create a mirror in a new space (specialization for different space)
2038 template<class Space, class T, class ... P>
2039 typename Impl::MirrorType<Space,T,P ...>::view_type
2040 create_mirror(const Space& , const Kokkos::View<T,P...> & src
2041  , typename std::enable_if<
2042  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value
2043  >::type * = 0) {
2044  return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),src.layout());
2045 }
2046 
2047 template< class T , class ... P >
2048 inline
2049 typename Kokkos::View<T,P...>::HostMirror
2050 create_mirror_view( const Kokkos::View<T,P...> & src
2051  , typename std::enable_if<(
2052  std::is_same< typename Kokkos::View<T,P...>::memory_space
2053  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2054  >::value
2055  &&
2056  std::is_same< typename Kokkos::View<T,P...>::data_type
2057  , typename Kokkos::View<T,P...>::HostMirror::data_type
2058  >::value
2059  )>::type * = 0
2060  )
2061 {
2062  return src ;
2063 }
2064 
2065 template< class T , class ... P >
2066 inline
2067 typename Kokkos::View<T,P...>::HostMirror
2068 create_mirror_view( const Kokkos::View<T,P...> & src
2069  , typename std::enable_if< ! (
2070  std::is_same< typename Kokkos::View<T,P...>::memory_space
2071  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2072  >::value
2073  &&
2074  std::is_same< typename Kokkos::View<T,P...>::data_type
2075  , typename Kokkos::View<T,P...>::HostMirror::data_type
2076  >::value
2077  )>::type * = 0
2078  )
2079 {
2080  return Kokkos::create_mirror( src );
2081 }
2082 
2083 // Create a mirror view in a new space (specialization for same space)
2084 template<class Space, class T, class ... P>
2085 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2086 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2087  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2088  return src;
2089 }
2090 
2091 // Create a mirror view in a new space (specialization for different space)
2092 template<class Space, class T, class ... P>
2093 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2094 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2095  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2096  return typename Impl::MirrorViewType<Space,T,P ...>::view_type(src.label(),src.layout());
2097 }
2098 
2099 // Create a mirror view and deep_copy in a new space (specialization for same space)
2100 template<class Space, class T, class ... P>
2101 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2102 create_mirror_view_and_copy(const Space& , const Kokkos::View<T,P...> & src
2103  , std::string const& name = ""
2104  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2105  (void)name;
2106  return src;
2107 }
2108 
2109 // Create a mirror view and deep_copy in a new space (specialization for different space)
2110 template<class Space, class T, class ... P>
2111 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2112 create_mirror_view_and_copy(const Space& , const Kokkos::View<T,P...> & src
2113  , std::string const& name = ""
2114  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2115  using Mirror = typename Impl::MirrorViewType<Space,T,P ...>::view_type;
2116  std::string label = name.empty() ? src.label() : name;
2117  auto mirror = Mirror(ViewAllocateWithoutInitializing(label), src.layout());
2118  deep_copy(mirror, src);
2119  return mirror;
2120 }
2121 
2122 } /* namespace Kokkos */
2123 
2124 
2125 //----------------------------------------------------------------------------
2126 //----------------------------------------------------------------------------
2127 
2128 #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.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
Can AccessSpace access MemorySpace ?
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...
View to an array of data.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
View
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.
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.
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
rank() to be implemented
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.