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 } /* namespace Kokkos */
1542 
1543 //----------------------------------------------------------------------------
1544 //----------------------------------------------------------------------------
1545 
1546 namespace Kokkos {
1547 
1549 template< class ExecSpace ,class DT , class ... DP >
1550 inline
1551 void deep_copy
1552  ( const ExecSpace &
1553  , const View<DT,DP...> & dst
1554  , typename ViewTraits<DT,DP...>::const_value_type & value
1555  , typename std::enable_if<
1556  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1557  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1558  >::type * = 0 )
1559 {
1560  static_assert(
1561  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
1562  typename ViewTraits<DT,DP...>::value_type >::value
1563  , "deep_copy requires non-const type" );
1564 
1565  ExecSpace::fence();
1566  typedef typename View<DT,DP...>::uniform_runtime_nomemspace_type ViewTypeUniform;
1567  Kokkos::Impl::ViewFill< ViewTypeUniform >( dst , value );
1568  ExecSpace::fence();
1569 }
1570 
1572 template< class ExecSpace , class ST , class ... SP >
1573 inline
1574 void deep_copy
1575  ( const ExecSpace & exec_space
1576  , typename ViewTraits<ST,SP...>::non_const_value_type & dst
1577  , const View<ST,SP...> & src
1578  , typename std::enable_if<
1579  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1580  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1581  >::type * = 0 )
1582 {
1583  static_assert( ViewTraits<ST,SP...>::rank == 0
1584  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1585 
1586  if(src.data() == NULL) {
1587  exec_space.fence();
1588  return;
1589  }
1590 
1591  typedef ViewTraits<ST,SP...> src_traits ;
1592  typedef typename src_traits::memory_space src_memory_space ;
1593  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >
1594  ( exec_space , & dst , src.data() , sizeof(ST) );
1595 }
1596 
1597 //----------------------------------------------------------------------------
1599 template< class ExecSpace , class DT , class ... DP , class ST , class ... SP >
1600 inline
1601 void deep_copy
1602  ( const ExecSpace & exec_space
1603  , const View<DT,DP...> & dst
1604  , const View<ST,SP...> & src
1605  , typename std::enable_if<(
1606  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1607  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1608  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1609  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
1610  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
1611  )>::type * = 0 )
1612 {
1613  static_assert(
1614  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1615  typename ViewTraits<ST,SP...>::non_const_value_type >::value
1616  , "deep_copy requires matching non-const destination type" );
1617 
1618  typedef View<DT,DP...> dst_type ;
1619  typedef View<ST,SP...> src_type ;
1620 
1621  typedef typename dst_type::value_type value_type ;
1622  typedef typename dst_type::memory_space dst_memory_space ;
1623  typedef typename src_type::memory_space src_memory_space ;
1624  if(dst.data() == NULL && src.data() == NULL) {
1625  exec_space.fence();
1626  return;
1627  }
1628 
1629  exec_space.fence();
1630  if ( dst.data() != src.data() ) {
1631  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1632  ( exec_space , dst.data() , src.data() , sizeof(value_type) );
1633  }
1634  exec_space.fence();
1635 }
1636 
1637 //----------------------------------------------------------------------------
1641 template< class ExecSpace , class DT, class ... DP, class ST, class ... SP >
1642 inline
1643 void deep_copy
1644  ( const ExecSpace & exec_space
1645  , const View<DT,DP...> & dst
1646  , const View<ST,SP...> & src
1647  , typename std::enable_if<(
1648  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1649  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1650  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1651  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
1652  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
1653  )>::type * = 0 )
1654 {
1655  typedef View<DT,DP...> dst_type ;
1656  typedef View<ST,SP...> src_type ;
1657 
1658  static_assert(
1659  std::is_same< typename dst_type::value_type ,
1660  typename dst_type::non_const_value_type >::value
1661  , "deep_copy requires non-const destination type" );
1662 
1663  static_assert(
1664  ( unsigned(dst_type::rank) ==
1665  unsigned(src_type::rank) )
1666  , "deep_copy requires Views of equal rank" );
1667 
1668  typedef typename dst_type::execution_space dst_execution_space ;
1669  typedef typename src_type::execution_space src_execution_space ;
1670  typedef typename dst_type::memory_space dst_memory_space ;
1671  typedef typename src_type::memory_space src_memory_space ;
1672  typedef typename dst_type::value_type dst_value_type ;
1673  typedef typename src_type::value_type src_value_type ;
1674 
1675  if(dst.data() == NULL || src.data() == NULL) {
1676 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1677  // do nothing
1678 #else
1679  // throw if dimension mismatch
1680  if ( (src.extent(0) != dst.extent(0)) ||
1681  (src.extent(1) != dst.extent(1)) ||
1682  (src.extent(2) != dst.extent(2)) ||
1683  (src.extent(3) != dst.extent(3)) ||
1684  (src.extent(4) != dst.extent(4)) ||
1685  (src.extent(5) != dst.extent(5)) ||
1686  (src.extent(6) != dst.extent(6)) ||
1687  (src.extent(7) != dst.extent(7))
1688  ) {
1689  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1690  message += dst.label(); message += "(";
1691  for(int r = 0; r<dst_type::Rank-1; r++)
1692  { message+= std::to_string(dst.extent(r)); message += ","; }
1693  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
1694  message += src.label(); message += "(";
1695  for(int r = 0; r<src_type::Rank-1; r++)
1696  { message+= std::to_string(src.extent(r)); message += ","; }
1697  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
1698 
1699  Kokkos::Impl::throw_runtime_exception(message);
1700  }
1701 #endif
1702  exec_space.fence();
1703  return;
1704  }
1705 
1706  enum { ExecCanAccessSrcDst =
1709  };
1710  enum { DstExecCanAccessSrc =
1712 
1713  enum { SrcExecCanAccessDst =
1715 
1716  // Checking for Overlapping Views.
1717  dst_value_type* dst_start = dst.data();
1718  dst_value_type* dst_end = dst.data() + dst.span();
1719  src_value_type* src_start = src.data();
1720  src_value_type* src_end = src.data() + src.span();
1721  if( ( ( (std::ptrdiff_t)dst_start < (std::ptrdiff_t)src_end ) && ( (std::ptrdiff_t)dst_end > (std::ptrdiff_t)src_start ) ) &&
1722  ( ( dst.span_is_contiguous() && src.span_is_contiguous() ))) {
1723  std::string message("Error: Kokkos::deep_copy of overlapping views: ");
1724  message += dst.label(); message += "(";
1725  message += std::to_string((std::ptrdiff_t)dst_start); message += ",";
1726  message += std::to_string((std::ptrdiff_t)dst_end); message += ") ";
1727  message += src.label(); message += "(";
1728  message += std::to_string((std::ptrdiff_t)src_start); message += ",";
1729  message += std::to_string((std::ptrdiff_t)src_end); message += ") ";
1730  Kokkos::Impl::throw_runtime_exception(message);
1731  }
1732 
1733  // Check for same extents
1734  if ( (src.extent(0) != dst.extent(0)) ||
1735  (src.extent(1) != dst.extent(1)) ||
1736  (src.extent(2) != dst.extent(2)) ||
1737  (src.extent(3) != dst.extent(3)) ||
1738  (src.extent(4) != dst.extent(4)) ||
1739  (src.extent(5) != dst.extent(5)) ||
1740  (src.extent(6) != dst.extent(6)) ||
1741  (src.extent(7) != dst.extent(7))
1742  ) {
1743 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1744  exec_space.fence();
1745  if ( ExecCanAccessSrcDst ) {
1746  Kokkos::Impl::ViewRemap< dst_type , src_type , ExecSpace >( dst , src );
1747  }
1748  else if ( DstExecCanAccessSrc ) {
1749  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1750  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1751  }
1752  else if ( SrcExecCanAccessDst ) {
1753  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1754  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1755  }
1756  else {
1757  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1758  }
1759  exec_space.fence();
1760  return;
1761 #else
1762  std::string message("Deprecation Error: Kokkos::deep_copy extents of views don't match: ");
1763  message += dst.label(); message += "(";
1764  for(int r = 0; r<dst_type::Rank-1; r++)
1765  { message+= std::to_string(dst.extent(r)); message += ","; }
1766  message+= std::to_string(dst.extent(dst_type::Rank-1)); message += ") ";
1767  message += src.label(); message += "(";
1768  for(int r = 0; r<src_type::Rank-1; r++)
1769  { message+= std::to_string(src.extent(r)); message += ","; }
1770  message+= std::to_string(src.extent(src_type::Rank-1)); message += ") ";
1771 
1772  Kokkos::Impl::throw_runtime_exception(message);
1773 #endif
1774  }
1775 
1776  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1777 
1778  if ( std::is_same< typename dst_type::value_type ,
1779  typename src_type::non_const_value_type >::value &&
1780  (
1781  std::is_same< typename dst_type::array_layout ,
1782  typename src_type::array_layout >::value
1783  ||
1784  ( dst_type::rank == 1 &&
1785  src_type::rank == 1 )
1786  ) &&
1787  dst.span_is_contiguous() &&
1788  src.span_is_contiguous() &&
1789  ((dst_type::rank < 1) || (dst.stride_0() == src.stride_0())) &&
1790  ((dst_type::rank < 2) || (dst.stride_1() == src.stride_1())) &&
1791  ((dst_type::rank < 3) || (dst.stride_2() == src.stride_2())) &&
1792  ((dst_type::rank < 4) || (dst.stride_3() == src.stride_3())) &&
1793  ((dst_type::rank < 5) || (dst.stride_4() == src.stride_4())) &&
1794  ((dst_type::rank < 6) || (dst.stride_5() == src.stride_5())) &&
1795  ((dst_type::rank < 7) || (dst.stride_6() == src.stride_6())) &&
1796  ((dst_type::rank < 8) || (dst.stride_7() == src.stride_7()))
1797  ) {
1798 
1799  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1800  exec_space.fence();
1801  if((void*)dst.data() != (void*)src.data()) {
1802  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1803  ( exec_space , dst.data() , src.data() , nbytes );
1804  }
1805  exec_space.fence();
1806  } else {
1807  exec_space.fence();
1808  Impl::view_copy(dst, src);
1809  exec_space.fence();
1810  }
1811 }
1812 
1813 } /* namespace Kokkos */
1814 
1815 //----------------------------------------------------------------------------
1816 //----------------------------------------------------------------------------
1817 
1818 namespace Kokkos {
1819 
1821 template< class T , class ... P >
1822 inline
1823 typename std::enable_if<
1824  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
1825  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
1826 >::type
1828  const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1829  const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1830  const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1831  const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1832  const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1833  const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1834  const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1835  const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
1836 {
1837  typedef Kokkos::View<T,P...> view_type ;
1838 
1839  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
1840 
1841  // Fix #904 by checking dimensions before actually resizing.
1842  //
1843  // Rank is known at compile time, so hopefully the compiler will
1844  // remove branches that are compile-time false. The upcoming "if
1845  // constexpr" language feature would make this certain.
1846  if (view_type::Rank == 1 &&
1847  n0 == static_cast<size_t> (v.extent(0))) {
1848  return;
1849  }
1850  if (view_type::Rank == 2 &&
1851  n0 == static_cast<size_t> (v.extent(0)) &&
1852  n1 == static_cast<size_t> (v.extent(1))) {
1853  return;
1854  }
1855  if (view_type::Rank == 3 &&
1856  n0 == static_cast<size_t> (v.extent(0)) &&
1857  n1 == static_cast<size_t> (v.extent(1)) &&
1858  n2 == static_cast<size_t> (v.extent(2))) {
1859  return;
1860  }
1861  if (view_type::Rank == 4 &&
1862  n0 == static_cast<size_t> (v.extent(0)) &&
1863  n1 == static_cast<size_t> (v.extent(1)) &&
1864  n2 == static_cast<size_t> (v.extent(2)) &&
1865  n3 == static_cast<size_t> (v.extent(3))) {
1866  return;
1867  }
1868  if (view_type::Rank == 5 &&
1869  n0 == static_cast<size_t> (v.extent(0)) &&
1870  n1 == static_cast<size_t> (v.extent(1)) &&
1871  n2 == static_cast<size_t> (v.extent(2)) &&
1872  n3 == static_cast<size_t> (v.extent(3)) &&
1873  n4 == static_cast<size_t> (v.extent(4))) {
1874  return;
1875  }
1876  if (view_type::Rank == 6 &&
1877  n0 == static_cast<size_t> (v.extent(0)) &&
1878  n1 == static_cast<size_t> (v.extent(1)) &&
1879  n2 == static_cast<size_t> (v.extent(2)) &&
1880  n3 == static_cast<size_t> (v.extent(3)) &&
1881  n4 == static_cast<size_t> (v.extent(4)) &&
1882  n5 == static_cast<size_t> (v.extent(5))) {
1883  return;
1884  }
1885  if (view_type::Rank == 7 &&
1886  n0 == static_cast<size_t> (v.extent(0)) &&
1887  n1 == static_cast<size_t> (v.extent(1)) &&
1888  n2 == static_cast<size_t> (v.extent(2)) &&
1889  n3 == static_cast<size_t> (v.extent(3)) &&
1890  n4 == static_cast<size_t> (v.extent(4)) &&
1891  n5 == static_cast<size_t> (v.extent(5)) &&
1892  n6 == static_cast<size_t> (v.extent(6))) {
1893  return;
1894  }
1895  if (view_type::Rank == 8 &&
1896  n0 == static_cast<size_t> (v.extent(0)) &&
1897  n1 == static_cast<size_t> (v.extent(1)) &&
1898  n2 == static_cast<size_t> (v.extent(2)) &&
1899  n3 == static_cast<size_t> (v.extent(3)) &&
1900  n4 == static_cast<size_t> (v.extent(4)) &&
1901  n5 == static_cast<size_t> (v.extent(5)) &&
1902  n6 == static_cast<size_t> (v.extent(6)) &&
1903  n7 == static_cast<size_t> (v.extent(7))) {
1904  return;
1905  }
1906  // If Kokkos ever supports Views of rank > 8, the above code won't
1907  // be incorrect, because avoiding reallocation in resize() is just
1908  // an optimization.
1909 
1910  // TODO (mfh 27 Jun 2017) If the old View has enough space but just
1911  // different dimensions (e.g., if the product of the dimensions,
1912  // including extra space for alignment, will not change), then
1913  // consider just reusing storage. For now, Kokkos always
1914  // reallocates if any of the dimensions change, even if the old View
1915  // has enough space.
1916 
1917  view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
1918 
1919  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
1920 
1921  v = v_resized ;
1922 }
1923 
1925 template< class T , class ... P >
1926 inline
1928  const typename Kokkos::View<T,P...>::array_layout & layout)
1929 {
1930  typedef Kokkos::View<T,P...> view_type ;
1931 
1932  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
1933 
1934  view_type v_resized( v.label(), layout );
1935 
1936  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
1937 
1938  v = v_resized ;
1939 }
1940 
1942 template< class T , class ... P >
1943 inline
1944 typename std::enable_if<
1945  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
1946  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
1947 >::type
1949  const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1950  const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1951  const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1952  const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1953  const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1954  const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1955  const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
1956  const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG )
1957 {
1958  typedef Kokkos::View<T,P...> view_type ;
1959 
1960  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
1961 
1962  const std::string label = v.label();
1963 
1964  v = view_type(); // Deallocate first, if the only view to allocation
1965  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
1966 }
1967 
1969 template< class T , class ... P >
1970 inline
1972  const typename Kokkos::View<T,P...>::array_layout & layout)
1973 {
1974  typedef Kokkos::View<T,P...> view_type ;
1975 
1976  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
1977 
1978  const std::string label = v.label();
1979 
1980  v = view_type(); // Deallocate first, if the only view to allocation
1981  v = view_type( label, layout );
1982 }
1983 } /* namespace Kokkos */
1984 
1985 //----------------------------------------------------------------------------
1986 //----------------------------------------------------------------------------
1987 
1988 namespace Kokkos {
1989 namespace Impl {
1990 
1991 // Deduce Mirror Types
1992 template<class Space, class T, class ... P>
1993 struct MirrorViewType {
1994  // The incoming view_type
1995  typedef typename Kokkos::View<T,P...> src_view_type;
1996  // The memory space for the mirror view
1997  typedef typename Space::memory_space memory_space;
1998  // Check whether it is the same memory space
1999  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2000  // The array_layout
2001  typedef typename src_view_type::array_layout array_layout;
2002  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2003  typedef typename src_view_type::non_const_data_type data_type;
2004  // The destination view type if it is not the same memory space
2005  typedef Kokkos::View<data_type,array_layout,Space> dest_view_type;
2006  // If it is the same memory_space return the existsing view_type
2007  // This will also keep the unmanaged trait if necessary
2008  typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
2009 };
2010 
2011 template<class Space, class T, class ... P>
2012 struct MirrorType {
2013  // The incoming view_type
2014  typedef typename Kokkos::View<T,P...> src_view_type;
2015  // The memory space for the mirror view
2016  typedef typename Space::memory_space memory_space;
2017  // Check whether it is the same memory space
2018  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2019  // The array_layout
2020  typedef typename src_view_type::array_layout array_layout;
2021  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2022  typedef typename src_view_type::non_const_data_type data_type;
2023  // The destination view type if it is not the same memory space
2025 };
2026 
2027 }
2028 
2029 template< class T , class ... P >
2030 inline
2031 typename Kokkos::View<T,P...>::HostMirror
2032 create_mirror( const Kokkos::View<T,P...> & src
2033  , typename std::enable_if<
2034  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
2035  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2036  , Kokkos::LayoutStride >::value
2037  >::type * = 0
2038  )
2039 {
2040  typedef View<T,P...> src_type ;
2041  typedef typename src_type::HostMirror dst_type ;
2042 
2043  return dst_type( std::string( src.label() ).append("_mirror")
2044 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
2045  , src.extent(0)
2046  , src.extent(1)
2047  , src.extent(2)
2048  , src.extent(3)
2049  , src.extent(4)
2050  , src.extent(5)
2051  , src.extent(6)
2052  , src.extent(7) );
2053 #else
2054  , src.rank_dynamic > 0 ? src.extent(0): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2055  , src.rank_dynamic > 1 ? src.extent(1): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2056  , src.rank_dynamic > 2 ? src.extent(2): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2057  , src.rank_dynamic > 3 ? src.extent(3): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2058  , src.rank_dynamic > 4 ? src.extent(4): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2059  , src.rank_dynamic > 5 ? src.extent(5): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2060  , src.rank_dynamic > 6 ? src.extent(6): KOKKOS_IMPL_CTOR_DEFAULT_ARG
2061  , src.rank_dynamic > 7 ? src.extent(7): KOKKOS_IMPL_CTOR_DEFAULT_ARG );
2062 #endif
2063 }
2064 
2065 template< class T , class ... P >
2066 inline
2067 typename Kokkos::View<T,P...>::HostMirror
2068 create_mirror( const Kokkos::View<T,P...> & src
2069  , typename std::enable_if<
2070  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
2071  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2072  , Kokkos::LayoutStride >::value
2073  >::type * = 0
2074  )
2075 {
2076  typedef View<T,P...> src_type ;
2077  typedef typename src_type::HostMirror dst_type ;
2078 
2079  Kokkos::LayoutStride layout ;
2080 
2081  layout.dimension[0] = src.extent(0);
2082  layout.dimension[1] = src.extent(1);
2083  layout.dimension[2] = src.extent(2);
2084  layout.dimension[3] = src.extent(3);
2085  layout.dimension[4] = src.extent(4);
2086  layout.dimension[5] = src.extent(5);
2087  layout.dimension[6] = src.extent(6);
2088  layout.dimension[7] = src.extent(7);
2089 
2090  layout.stride[0] = src.stride_0();
2091  layout.stride[1] = src.stride_1();
2092  layout.stride[2] = src.stride_2();
2093  layout.stride[3] = src.stride_3();
2094  layout.stride[4] = src.stride_4();
2095  layout.stride[5] = src.stride_5();
2096  layout.stride[6] = src.stride_6();
2097  layout.stride[7] = src.stride_7();
2098 
2099  return dst_type( std::string( src.label() ).append("_mirror") , layout );
2100 }
2101 
2102 
2103 // Create a mirror in a new space (specialization for different space)
2104 template<class Space, class T, class ... P>
2105 typename Impl::MirrorType<Space,T,P ...>::view_type
2106 create_mirror(const Space& , const Kokkos::View<T,P...> & src
2107  , typename std::enable_if<
2108  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value
2109  >::type * = 0) {
2110  return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),src.layout());
2111 }
2112 
2113 template< class T , class ... P >
2114 inline
2115 typename Kokkos::View<T,P...>::HostMirror
2116 create_mirror_view( const Kokkos::View<T,P...> & src
2117  , typename std::enable_if<(
2118  std::is_same< typename Kokkos::View<T,P...>::memory_space
2119  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2120  >::value
2121  &&
2122  std::is_same< typename Kokkos::View<T,P...>::data_type
2123  , typename Kokkos::View<T,P...>::HostMirror::data_type
2124  >::value
2125  )>::type * = 0
2126  )
2127 {
2128  return src ;
2129 }
2130 
2131 template< class T , class ... P >
2132 inline
2133 typename Kokkos::View<T,P...>::HostMirror
2134 create_mirror_view( const Kokkos::View<T,P...> & src
2135  , typename std::enable_if< ! (
2136  std::is_same< typename Kokkos::View<T,P...>::memory_space
2137  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2138  >::value
2139  &&
2140  std::is_same< typename Kokkos::View<T,P...>::data_type
2141  , typename Kokkos::View<T,P...>::HostMirror::data_type
2142  >::value
2143  )>::type * = 0
2144  )
2145 {
2146  return Kokkos::create_mirror( src );
2147 }
2148 
2149 // Create a mirror view in a new space (specialization for same space)
2150 template<class Space, class T, class ... P>
2151 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2152 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2153  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2154  return src;
2155 }
2156 
2157 // Create a mirror view in a new space (specialization for different space)
2158 template<class Space, class T, class ... P>
2159 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2160 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2161  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2162  return typename Impl::MirrorViewType<Space,T,P ...>::view_type(src.label(),src.layout());
2163 }
2164 
2165 // Create a mirror view and deep_copy in a new space (specialization for same space)
2166 template<class Space, class T, class ... P>
2167 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2168 create_mirror_view_and_copy(const Space& , const Kokkos::View<T,P...> & src
2169  , std::string const& name = ""
2170  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2171  (void)name;
2172  return src;
2173 }
2174 
2175 // Create a mirror view and deep_copy in a new space (specialization for different space)
2176 template<class Space, class T, class ... P>
2177 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2178 create_mirror_view_and_copy(const Space& , const Kokkos::View<T,P...> & src
2179  , std::string const& name = ""
2180  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2181  using Mirror = typename Impl::MirrorViewType<Space,T,P ...>::view_type;
2182  std::string label = name.empty() ? src.label() : name;
2183  auto mirror = Mirror(ViewAllocateWithoutInitializing(label), src.layout());
2184  deep_copy(mirror, src);
2185  return mirror;
2186 }
2187 
2188 } /* namespace Kokkos */
2189 
2190 
2191 //----------------------------------------------------------------------------
2192 //----------------------------------------------------------------------------
2193 
2194 #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 ?
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