~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to lib/kokkos/core/src/impl/Kokkos_ViewDefault.hpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
//@HEADER
 
3
// ************************************************************************
 
4
//
 
5
//   Kokkos: Manycore Performance-Portable Multidimensional Arrays
 
6
//              Copyright (2012) 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  H. Carter Edwards (hcedwar@sandia.gov)
 
39
//
 
40
// ************************************************************************
 
41
//@HEADER
 
42
*/
 
43
 
 
44
#ifndef KOKKOS_VIEWDEFAULT_HPP
 
45
#define KOKKOS_VIEWDEFAULT_HPP
 
46
 
 
47
//----------------------------------------------------------------------------
 
48
//----------------------------------------------------------------------------
 
49
 
 
50
namespace Kokkos {
 
51
namespace Impl {
 
52
 
 
53
template<>
 
54
struct ViewAssignment< ViewDefault , ViewDefault , void >
 
55
{
 
56
  typedef ViewDefault Specialize ;
 
57
 
 
58
  //------------------------------------
 
59
  /** \brief  Compatible value and shape */
 
60
 
 
61
  template< class DT , class DL , class DD , class DM ,
 
62
            class ST , class SL , class SD , class SM >
 
63
  KOKKOS_INLINE_FUNCTION
 
64
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
65
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
66
                  const typename enable_if<(
 
67
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
68
                                    ViewTraits<ST,SL,SD,SM> >::value
 
69
                    ||
 
70
                    ( ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
71
                                      ViewTraits<ST,SL,SD,SM> >::assignable_value
 
72
                      &&
 
73
                      ShapeCompatible< typename ViewTraits<DT,DL,DD,DM>::shape_type ,
 
74
                                       typename ViewTraits<ST,SL,SD,SM>::shape_type >::value
 
75
                      &&
 
76
                      is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout,LayoutStride>::value )
 
77
                  )>::type * = 0 )
 
78
  {
 
79
    dst.m_management.decrement( dst.m_ptr_on_device );
 
80
 
 
81
    dst.m_offset_map.assign( src.m_offset_map );
 
82
 
 
83
    dst.m_management = src.m_management ;
 
84
 
 
85
    dst.m_ptr_on_device = typename ViewDataManagement< ViewTraits<DT,DL,DD,DM> >::handle_type( src.m_ptr_on_device );
 
86
 
 
87
    dst.m_management.increment( dst.m_ptr_on_device );
 
88
  }
 
89
 
 
90
  //------------------------------------
 
91
  /** \brief  Extract Rank-0 from Rank-1 */
 
92
 
 
93
  template< class DT , class DL , class DD , class DM ,
 
94
            class ST , class SL , class SD , class SM >
 
95
  KOKKOS_INLINE_FUNCTION
 
96
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
97
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
98
                  const typename enable_if< (
 
99
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
100
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
101
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
102
                    ( ViewTraits<ST,SL,SD,SM>::rank == 1 )
 
103
                  ), unsigned >::type i0 )
 
104
  {
 
105
    assert_shape_bounds( src.m_offset_map , 1 , i0 );
 
106
 
 
107
    dst.m_management.decrement( dst.m_ptr_on_device );
 
108
 
 
109
    dst.m_management = src.m_management ;
 
110
 
 
111
    dst.m_ptr_on_device = src.ptr_on_device() + i0 ;
 
112
 
 
113
    dst.m_management.increment( dst.m_ptr_on_device );
 
114
  }
 
115
 
 
116
  //------------------------------------
 
117
  /** \brief  Extract Rank-0 from Rank-2 */
 
118
 
 
119
  template< class DT , class DL , class DD , class DM ,
 
120
            class ST , class SL , class SD , class SM >
 
121
  KOKKOS_INLINE_FUNCTION
 
122
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
123
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
124
                  const typename enable_if< (
 
125
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
126
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
127
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
128
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
129
                  ), unsigned >::type i0 ,
 
130
                  const unsigned i1 )
 
131
  {
 
132
    assert_shape_bounds( src.m_offset_map , 2 , i0 , i1 );
 
133
 
 
134
    dst.m_management.decrement( dst.m_ptr_on_device );
 
135
 
 
136
    dst.m_management = src.m_management ;
 
137
 
 
138
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,i1);
 
139
 
 
140
    dst.m_management.increment( dst.m_ptr_on_device );
 
141
  }
 
142
 
 
143
  //------------------------------------
 
144
  /** \brief  Extract Rank-0 from Rank-3 */
 
145
 
 
146
  template< class DT , class DL , class DD , class DM ,
 
147
            class ST , class SL , class SD , class SM >
 
148
  KOKKOS_INLINE_FUNCTION
 
149
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
150
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
151
                  const typename enable_if< (
 
152
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
153
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
154
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
155
                    ( ViewTraits<ST,SL,SD,SM>::rank == 3 )
 
156
                  ), unsigned >::type i0 ,
 
157
                  const unsigned i1 ,
 
158
                  const unsigned i2 )
 
159
  {
 
160
    assert_shape_bounds( src.m_offset_map, 3, i0, i1, i2 );
 
161
 
 
162
    dst.m_management.decrement( dst.m_ptr_on_device );
 
163
 
 
164
    dst.m_management = src.m_management ;
 
165
 
 
166
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,i1,i2);
 
167
 
 
168
    dst.m_management.increment( dst.m_ptr_on_device );
 
169
  }
 
170
 
 
171
  //------------------------------------
 
172
  /** \brief  Extract Rank-0 from Rank-4 */
 
173
 
 
174
  template< class DT , class DL , class DD , class DM ,
 
175
            class ST , class SL , class SD , class SM >
 
176
  KOKKOS_INLINE_FUNCTION
 
177
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
178
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
179
                  const typename enable_if< (
 
180
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
181
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
182
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
183
                    ( ViewTraits<ST,SL,SD,SM>::rank == 4 )
 
184
                  ), unsigned >::type i0 ,
 
185
                  const unsigned i1 ,
 
186
                  const unsigned i2 ,
 
187
                  const unsigned i3 )
 
188
  {
 
189
    assert_shape_bounds( src.m_offset_map, 4, i0, i1, i2, i3 );
 
190
 
 
191
    dst.m_management.decrement( dst.m_ptr_on_device );
 
192
 
 
193
    dst.m_management = src.m_management ;
 
194
 
 
195
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,i1,i2,i3);
 
196
 
 
197
    dst.m_management.increment( dst.m_ptr_on_device );
 
198
  }
 
199
 
 
200
  //------------------------------------
 
201
  /** \brief  Extract Rank-0 from Rank-5 */
 
202
 
 
203
  template< class DT , class DL , class DD , class DM ,
 
204
            class ST , class SL , class SD , class SM >
 
205
  KOKKOS_INLINE_FUNCTION
 
206
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
207
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
208
                  const typename enable_if< (
 
209
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
210
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
211
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
212
                    ( ViewTraits<ST,SL,SD,SM>::rank == 5 )
 
213
                  ), unsigned >::type i0 ,
 
214
                  const unsigned i1 ,
 
215
                  const unsigned i2 ,
 
216
                  const unsigned i3 ,
 
217
                  const unsigned i4 )
 
218
  {
 
219
    assert_shape_bounds( src.m_offset_map, 5, i0, i1, i2, i3, i4);
 
220
 
 
221
    dst.m_management.decrement( dst.m_ptr_on_device );
 
222
 
 
223
    dst.m_management = src.m_management ;
 
224
 
 
225
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,i1,i2,i3,i4);
 
226
 
 
227
    dst.m_management.increment( dst.m_ptr_on_device );
 
228
  }
 
229
 
 
230
  //------------------------------------
 
231
  /** \brief  Extract Rank-0 from Rank-6 */
 
232
 
 
233
  template< class DT , class DL , class DD , class DM ,
 
234
            class ST , class SL , class SD , class SM >
 
235
  KOKKOS_INLINE_FUNCTION
 
236
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
237
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
238
                  const typename enable_if< (
 
239
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
240
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
241
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
242
                    ( ViewTraits<ST,SL,SD,SM>::rank == 6 )
 
243
                  ), unsigned >::type i0 ,
 
244
                  const unsigned i1 ,
 
245
                  const unsigned i2 ,
 
246
                  const unsigned i3 ,
 
247
                  const unsigned i4 ,
 
248
                  const unsigned i5 )
 
249
  {
 
250
    assert_shape_bounds( src.m_offset_map, 6, i0, i1, i2, i3, i4, i5);
 
251
 
 
252
    dst.m_management.decrement( dst.m_ptr_on_device );
 
253
 
 
254
    dst.m_management = src.m_management ;
 
255
 
 
256
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,i1,i2,i3,i4,i5);
 
257
 
 
258
    dst.m_management.increment( dst.m_ptr_on_device );
 
259
  }
 
260
 
 
261
  //------------------------------------
 
262
  /** \brief  Extract Rank-0 from Rank-7 */
 
263
 
 
264
  template< class DT , class DL , class DD , class DM ,
 
265
            class ST , class SL , class SD , class SM >
 
266
  KOKKOS_INLINE_FUNCTION
 
267
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
268
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
269
                  const typename enable_if< (
 
270
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
271
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
272
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
273
                    ( ViewTraits<ST,SL,SD,SM>::rank == 7 )
 
274
                  ), unsigned >::type i0 ,
 
275
                  const unsigned i1 ,
 
276
                  const unsigned i2 ,
 
277
                  const unsigned i3 ,
 
278
                  const unsigned i4 ,
 
279
                  const unsigned i5 ,
 
280
                  const unsigned i6 )
 
281
  {
 
282
    assert_shape_bounds( src.m_offset_map, 7, i0, i1, i2, i3, i4, i5, i6 );
 
283
 
 
284
    dst.m_management.decrement( dst.m_ptr_on_device );
 
285
 
 
286
    dst.m_management = src.m_management ;
 
287
 
 
288
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,i1,i2,i3,i4,i5,i6);
 
289
 
 
290
    dst.m_management.increment( dst.m_ptr_on_device );
 
291
  }
 
292
 
 
293
  //------------------------------------
 
294
  /** \brief  Extract Rank-0 from Rank-8 */
 
295
 
 
296
  template< class DT , class DL , class DD , class DM ,
 
297
            class ST , class SL , class SD , class SM >
 
298
  KOKKOS_INLINE_FUNCTION
 
299
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
300
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
301
                  const typename enable_if< (
 
302
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> ,
 
303
                                    ViewTraits<ST,SL,SD,SM> >::assignable_value &&
 
304
                    ( ViewTraits<DT,DL,DD,DM>::rank == 0 ) &&
 
305
                    ( ViewTraits<ST,SL,SD,SM>::rank == 8 )
 
306
                  ), unsigned >::type i0 ,
 
307
                  const unsigned i1 ,
 
308
                  const unsigned i2 ,
 
309
                  const unsigned i3 ,
 
310
                  const unsigned i4 ,
 
311
                  const unsigned i5 ,
 
312
                  const unsigned i6 ,
 
313
                  const unsigned i7 )
 
314
  {
 
315
    assert_shape_bounds( src.m_offset_map, 8, i0, i1, i2, i3, i4, i5, i6, i7 );
 
316
 
 
317
    dst.m_management.decrement( dst.m_ptr_on_device );
 
318
 
 
319
    dst.m_management = src.m_management ;
 
320
 
 
321
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,i1,i2,i3,i4,i5,i6,i7);
 
322
 
 
323
    dst.m_management.increment( dst.m_ptr_on_device );
 
324
  }
 
325
 
 
326
  //------------------------------------
 
327
  /** \brief  Extract Rank-1 array from range of Rank-1 array, either layout */
 
328
  template< class DT , class DL , class DD , class DM ,
 
329
            class ST , class SL , class SD , class SM ,
 
330
            typename iType >
 
331
  KOKKOS_INLINE_FUNCTION
 
332
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
333
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
334
                  const std::pair<iType,iType> & range ,
 
335
                  typename enable_if< (
 
336
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
337
                    &&
 
338
                    ( ViewTraits<ST,SL,SD,SM>::rank == 1 )
 
339
                    &&
 
340
                    ( ViewTraits<DT,DL,DD,DM>::rank == 1 )
 
341
                    &&
 
342
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 1 )
 
343
                  ) >::type * = 0 )
 
344
  {
 
345
    dst.m_management.decrement( dst.m_ptr_on_device );
 
346
 
 
347
    dst.m_offset_map.N0 = 0 ;
 
348
    dst.m_ptr_on_device = 0 ;
 
349
 
 
350
    if ( range.first < range.second ) {
 
351
      assert_shape_bounds( src.m_offset_map , 1 , range.first );
 
352
      assert_shape_bounds( src.m_offset_map , 1 , range.second - 1 );
 
353
 
 
354
      dst.m_management      = src.m_management ;
 
355
      dst.m_offset_map.N0 = range.second - range.first ;
 
356
      dst.m_ptr_on_device = src.ptr_on_device() + range.first ;
 
357
 
 
358
      dst.m_management.increment( dst.m_ptr_on_device );
 
359
    }
 
360
  }
 
361
 
 
362
  //------------------------------------
 
363
  /** \brief  Extract Rank-1 array from LayoutLeft Rank-2 array, using ALL as first argument. */
 
364
  template< class DT , class DL , class DD , class DM ,
 
365
            class ST , class SL , class SD , class SM >
 
366
  KOKKOS_INLINE_FUNCTION
 
367
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
368
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
369
                  const ALL & ,
 
370
                  const typename enable_if< (
 
371
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
372
                    &&
 
373
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutLeft >::value
 
374
                    &&
 
375
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
376
                    &&
 
377
                    ( ViewTraits<DT,DL,DD,DM>::rank == 1 )
 
378
                    &&
 
379
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 1 )
 
380
                  ), unsigned >::type i1 )
 
381
  {
 
382
    dst.m_management.decrement( dst.m_ptr_on_device );
 
383
 
 
384
    dst.m_management      = src.m_management ;
 
385
    dst.m_offset_map.N0 = src.m_offset_map.N0 ;
 
386
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(0,i1);
 
387
 
 
388
    dst.m_management.increment( dst.m_ptr_on_device );
 
389
  }
 
390
 
 
391
 
 
392
  //------------------------------------
 
393
  /** \brief  Extract Rank-1 array from LayoutLeft Rank-2 array, using a row range as first argument. */
 
394
  template< class DT , class DL , class DD , class DM ,
 
395
            class ST , class SL , class SD , class SM ,
 
396
            typename IndexType >
 
397
  KOKKOS_INLINE_FUNCTION
 
398
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
399
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
400
                  const std::pair<IndexType, IndexType>& rowRange,
 
401
                  const typename enable_if< (
 
402
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
403
                    &&
 
404
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutLeft >::value
 
405
                    &&
 
406
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
407
                    &&
 
408
                    ( ViewTraits<DT,DL,DD,DM>::rank == 1 )
 
409
                    &&
 
410
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 1 )
 
411
                  ), IndexType >::type columnIndex )
 
412
  {
 
413
    dst.m_management.decrement( dst.m_ptr_on_device );
 
414
 
 
415
    if (rowRange.first < rowRange.second) { // valid row range
 
416
      dst.m_management = src.m_management;
 
417
      dst.m_offset_map.N0 = rowRange.second - rowRange.first;
 
418
      dst.m_ptr_on_device = src.ptr_on_device () +
 
419
        src.m_offset_map (rowRange.first, columnIndex);
 
420
 
 
421
      dst.m_management.increment( dst.m_ptr_on_device );
 
422
    }
 
423
    else { // not a valid row range
 
424
      dst.m_offset_map.N0 = 0;
 
425
      dst.m_ptr_on_device = 0;
 
426
    }
 
427
  }
 
428
 
 
429
 
 
430
  //------------------------------------
 
431
  /** \brief  Extract Rank-1 array from LayoutRight Rank-2 array. */
 
432
  template< class DT , class DL , class DD , class DM ,
 
433
            class ST , class SL , class SD , class SM >
 
434
  KOKKOS_INLINE_FUNCTION
 
435
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
436
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
437
                  const unsigned i0 ,
 
438
                  const typename enable_if< (
 
439
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
440
                    &&
 
441
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
442
                    &&
 
443
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
444
                    &&
 
445
                    ( ViewTraits<DT,DL,DD,DM>::rank == 1 )
 
446
                    &&
 
447
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 1 )
 
448
                  ), ALL >::type & )
 
449
  {
 
450
    dst.m_management.decrement( dst.m_ptr_on_device );
 
451
 
 
452
    dst.m_management      = src.m_management ;
 
453
    dst.m_offset_map.N0 = src.m_offset_map.N1 ;
 
454
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,0);
 
455
 
 
456
    dst.m_management.increment( dst.m_ptr_on_device );
 
457
  }
 
458
 
 
459
  //------------------------------------
 
460
  /** \brief  Extract Rank-2 array from LayoutLeft Rank-2 array. */
 
461
  template< class DT , class DL , class DD , class DM ,
 
462
            class ST , class SL , class SD , class SM ,
 
463
            typename iType >
 
464
  KOKKOS_INLINE_FUNCTION
 
465
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
466
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
467
                  const std::pair<iType,iType> & range ,
 
468
                  const typename enable_if< (
 
469
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
470
                    &&
 
471
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutLeft >::value
 
472
                    &&
 
473
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
474
                    &&
 
475
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
476
                    &&
 
477
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
478
                  ), unsigned >::type i1 )
 
479
  {
 
480
    assert_shape_bounds( src.m_offset_map , 2 , range.first , i1 );
 
481
    assert_shape_bounds( src.m_offset_map , 2 , range.second - 1 , i1 );
 
482
 
 
483
    dst.m_management.decrement( dst.m_ptr_on_device );
 
484
 
 
485
    if ( range.first < range.second ) {
 
486
      dst.m_management      = src.m_management ;
 
487
      dst.m_offset_map.N0 = range.second - range.first ;
 
488
      dst.m_offset_map.N1 = 1 ;
 
489
      dst.m_offset_map.S0 = range.second - range.first ;
 
490
      dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(range.first,i1);
 
491
 
 
492
      dst.m_management.increment( dst.m_ptr_on_device );
 
493
    }
 
494
  }
 
495
 
 
496
  //------------------------------------
 
497
  /** \brief  Extract Rank-2 array from LayoutLeft Rank-2 array. */
 
498
  template< class DT , class DL , class DD , class DM ,
 
499
            class ST , class SL , class SD , class SM >
 
500
  KOKKOS_INLINE_FUNCTION
 
501
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
502
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
503
                  const ALL & ,
 
504
                  const typename enable_if< (
 
505
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
506
                    &&
 
507
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutLeft >::value
 
508
                    &&
 
509
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
510
                    &&
 
511
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
512
                    &&
 
513
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
514
                  ), unsigned >::type i1 )
 
515
  {
 
516
    dst.m_management.decrement( dst.m_ptr_on_device );
 
517
 
 
518
    dst.m_management      = src.m_management ;
 
519
    dst.m_offset_map.N0 = src.m_offset_map.N0 ;
 
520
    dst.m_offset_map.N1 = 1 ;
 
521
 
 
522
    dst.m_offset_map.S0 = src.m_offset_map.N0 ;
 
523
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(0,i1);
 
524
 
 
525
    dst.m_management.increment( dst.m_ptr_on_device );
 
526
  }
 
527
 
 
528
  //------------------------------------
 
529
  /** \brief  Extract Rank-2 array from LayoutRight Rank-2 array. */
 
530
  template< class DT , class DL , class DD , class DM ,
 
531
            class ST , class SL , class SD , class SM >
 
532
  KOKKOS_INLINE_FUNCTION
 
533
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
534
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
535
                  const unsigned i0 ,
 
536
                  const typename enable_if< (
 
537
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
538
                    &&
 
539
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
540
                    &&
 
541
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
542
                    &&
 
543
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
544
                    &&
 
545
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
546
                  ), ALL >::type & )
 
547
  {
 
548
    dst.m_management.decrement( dst.m_ptr_on_device );
 
549
 
 
550
    dst.m_management      = src.m_management ;
 
551
    dst.m_offset_map.N0 = 1 ;
 
552
    dst.m_offset_map.N1 = src.m_offset_map.N1 ;
 
553
    dst.m_offset_map.SR = src.m_offset_map.SR ;
 
554
    dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(i0,0);
 
555
 
 
556
    dst.m_management.increment( dst.m_ptr_on_device );
 
557
  }
 
558
  //------------------------------------
 
559
  /** \brief  Extract LayoutRight Rank-N array from range of LayoutRight Rank-N array */
 
560
  template< class DT , class DL , class DD , class DM ,
 
561
            class ST , class SL , class SD , class SM ,
 
562
            typename iType >
 
563
  KOKKOS_INLINE_FUNCTION
 
564
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
565
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
566
                  const std::pair<iType,iType> & range ,
 
567
                  typename enable_if< (
 
568
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::value
 
569
                    &&
 
570
                    Impl::is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutRight >::value
 
571
                    &&
 
572
                    ( ViewTraits<ST,SL,SD,SM>::rank > 1 )
 
573
                    &&
 
574
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic > 0 )
 
575
                  )>::type * = 0 )
 
576
  {
 
577
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
578
    //typedef typename traits_type::shape_type shape_type ; // unused
 
579
    //typedef typename View<DT,DL,DD,DM,Specialize>::stride_type stride_type ; // unused
 
580
 
 
581
    dst.m_management.decrement( dst.m_ptr_on_device );
 
582
 
 
583
    dst.m_offset_map.assign( 0, 0, 0, 0, 0, 0, 0, 0 );
 
584
 
 
585
    dst.m_ptr_on_device = 0 ;
 
586
 
 
587
    if ( ( range.first == range.second ) ||
 
588
         ( (src.capacity()==0u) && (range.second<src.m_offset_map.N0) )) {
 
589
      dst.m_offset_map.assign( 0 , src.m_offset_map.N1 , src.m_offset_map.N2 , src.m_offset_map.N3 ,
 
590
                                   src.m_offset_map.N4 , src.m_offset_map.N5 , src.m_offset_map.N6 , src.m_offset_map.N7 );
 
591
      dst.m_offset_map.SR = src.m_offset_map.SR ;
 
592
    }
 
593
    else if ( (range.first < range.second) ) {
 
594
      assert_shape_bounds( src.m_offset_map , 8 , range.first ,      0,0,0,0,0,0,0);
 
595
      assert_shape_bounds( src.m_offset_map , 8 , range.second - 1 , 0,0,0,0,0,0,0);
 
596
 
 
597
      dst.m_offset_map.assign( range.second - range.first
 
598
                             , src.m_offset_map.N1 , src.m_offset_map.N2 , src.m_offset_map.N3
 
599
                             , src.m_offset_map.N4 , src.m_offset_map.N5 , src.m_offset_map.N6 , src.m_offset_map.N7 );
 
600
 
 
601
      dst.m_offset_map.SR = src.m_offset_map.SR ;
 
602
 
 
603
      dst.m_management      = src.m_management ;
 
604
 
 
605
      dst.m_ptr_on_device = src.ptr_on_device() + range.first * src.m_offset_map.SR ;
 
606
 
 
607
      dst.m_management.increment( dst.m_ptr_on_device );
 
608
    }
 
609
  }
 
610
 
 
611
  //------------------------------------
 
612
  /** \brief  Extract rank-2 from rank-2 array */
 
613
  template< class DT , class DL , class DD , class DM ,
 
614
            class ST , class SL , class SD , class SM ,
 
615
            typename iType0 , typename iType1 >
 
616
  KOKKOS_INLINE_FUNCTION
 
617
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
618
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
619
                  const std::pair<iType0,iType0> & range0 ,
 
620
                  const std::pair<iType1,iType1> & range1 ,
 
621
                  typename enable_if< (
 
622
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::value
 
623
                    &&
 
624
                    ViewTraits<DT,DL,DD,DM>::rank == 2
 
625
                    &&
 
626
                    ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2
 
627
                  ) >::type * = 0 )
 
628
  {
 
629
    dst.m_management.decrement( dst.m_ptr_on_device );
 
630
    dst.m_offset_map.assign(0,0,0,0, 0,0,0,0);
 
631
    dst.m_ptr_on_device = 0 ;
 
632
 
 
633
    if ( (range0.first == range0.second) ||
 
634
         (range1.first == range1.second) ||
 
635
         ( ( src.capacity() == 0u ) &&
 
636
           ( long(range0.second) < long(src.m_offset_map.N0) ) &&
 
637
           ( long(range1.second) < long(src.m_offset_map.N1) ) ) ) {
 
638
 
 
639
      dst.m_offset_map.assign( src.m_offset_map );
 
640
      dst.m_offset_map.N0 = range0.second - range0.first ;
 
641
      dst.m_offset_map.N1 = range1.second - range1.first ;
 
642
    }
 
643
    else if ( (range0.first < range0.second && range1.first < range1.second) ) {
 
644
 
 
645
      assert_shape_bounds( src.m_offset_map , 2 , range0.first , range1.first );
 
646
      assert_shape_bounds( src.m_offset_map , 2 , range0.second - 1 , range1.second - 1 );
 
647
 
 
648
      dst.m_offset_map.assign( src.m_offset_map );
 
649
      dst.m_offset_map.N0 = range0.second - range0.first ;
 
650
      dst.m_offset_map.N1 = range1.second - range1.first ;
 
651
 
 
652
      dst.m_management = src.m_management ;
 
653
 
 
654
      dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(range0.first,range1.first);
 
655
 
 
656
      dst.m_management.increment( dst.m_ptr_on_device );
 
657
    }
 
658
  }
 
659
 
 
660
  //------------------------------------
 
661
  /** \brief  Extract rank-2 from rank-2 array */
 
662
  template< class DT , class DL , class DD , class DM ,
 
663
            class ST , class SL , class SD , class SM ,
 
664
            typename iType >
 
665
  KOKKOS_INLINE_FUNCTION
 
666
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
667
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
668
                  ALL ,
 
669
                  const std::pair<iType,iType> & range1 ,
 
670
                  typename enable_if< (
 
671
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::value
 
672
                    &&
 
673
                    ViewTraits<DT,DL,DD,DM>::rank == 2
 
674
                    &&
 
675
                    ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2
 
676
                  ) >::type * = 0 )
 
677
  {
 
678
    dst.m_management.decrement( dst.m_ptr_on_device );
 
679
    dst.m_offset_map.assign(0,0,0,0, 0,0,0,0);
 
680
    dst.m_ptr_on_device = 0 ;
 
681
 
 
682
    if ( (range1.first == range1.second) || ( (src.capacity()==0) && (range1.second<src.m_offset_map.N1) )) {
 
683
      dst.m_offset_map.assign(src.m_offset_map);
 
684
      dst.m_offset_map.N1 = range1.second - range1.first ;
 
685
    }
 
686
    else if ( (range1.first < range1.second) ) {
 
687
      assert_shape_bounds( src.m_offset_map , 2 , 0 , range1.first );
 
688
      assert_shape_bounds( src.m_offset_map , 2 , src.m_offset_map.N0 - 1 , range1.second - 1 );
 
689
 
 
690
      dst.m_offset_map.assign(src.m_offset_map);
 
691
      dst.m_offset_map.N1 = range1.second - range1.first ;
 
692
      dst.m_management      = src.m_management ;
 
693
 
 
694
      dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(0,range1.first);
 
695
 
 
696
      dst.m_management.increment( dst.m_ptr_on_device );
 
697
    }
 
698
  }
 
699
 
 
700
  //------------------------------------
 
701
  /** \brief  Extract rank-2 from rank-2 array */
 
702
  template< class DT , class DL , class DD , class DM ,
 
703
            class ST , class SL , class SD , class SM ,
 
704
            typename iType >
 
705
  KOKKOS_INLINE_FUNCTION
 
706
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
707
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
708
                  const std::pair<iType,iType> & range0 ,
 
709
                  ALL ,
 
710
                  typename enable_if< (
 
711
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::value
 
712
                    &&
 
713
                    ViewTraits<DT,DL,DD,DM>::rank == 2
 
714
                    &&
 
715
                    ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2
 
716
                  ) >::type * = 0 )
 
717
  {
 
718
    dst.m_management.decrement( dst.m_ptr_on_device );
 
719
    dst.m_offset_map.assign(0,0,0,0, 0,0,0,0);
 
720
    dst.m_ptr_on_device = 0 ;
 
721
 
 
722
    if ( (range0.first == range0.second) || ( (src.capacity()==0) && (range0.second<src.m_offset_map.N0) )) {
 
723
      dst.m_offset_map.assign(src.m_offset_map);
 
724
      dst.m_offset_map.N0 = range0.second - range0.first ;
 
725
    }
 
726
    else if ( (range0.first < range0.second) ) {
 
727
      assert_shape_bounds( src.m_offset_map , 2 , range0.first , 0 );
 
728
      assert_shape_bounds( src.m_offset_map , 2 , range0.second - 1 , src.m_offset_map.N1 - 1 );
 
729
 
 
730
      dst.m_offset_map.assign(src.m_offset_map);
 
731
      dst.m_offset_map.N0 = range0.second - range0.first ;
 
732
      dst.m_management = src.m_management ;
 
733
 
 
734
      dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(range0.first,0);
 
735
 
 
736
      dst.m_management.increment( dst.m_ptr_on_device );
 
737
    }
 
738
  }
 
739
 
 
740
  //------------------------------------
 
741
  /** \brief  Extract rank-2 from rank-2 array */
 
742
  template< class DT , class DL , class DD , class DM ,
 
743
            class ST , class SL , class SD , class SM ,
 
744
            typename iType >
 
745
  KOKKOS_INLINE_FUNCTION
 
746
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
747
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
748
                  const std::pair<iType,iType> & range0 ,
 
749
                  ALL ,
 
750
                  typename enable_if< (
 
751
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::value
 
752
                    &&
 
753
                    ViewTraits<DT,DL,DD,DM>::rank == 2
 
754
                    &&
 
755
                    ViewTraits<DT,DL,DD,DM>::rank_dynamic == 1
 
756
                  ) >::type * = 0 )
 
757
  {
 
758
    dst.m_tracking.decrement( dst.ptr_on_device() );
 
759
    dst.m_offset_map.assign(0,0,0,0, 0,0,0,0);
 
760
    dst.m_ptr_on_device = 0 ;
 
761
 
 
762
    if ( (range0.first == range0.second) || ( (src.capacity()==0) && (range0.second<src.m_offset_map.N0) )) {
 
763
      dst.m_offset_map.assign(src.m_offset_map);
 
764
      dst.m_offset_map.N0 = range0.second - range0.first ;
 
765
    }
 
766
    else if ( (range0.first < range0.second) ) {
 
767
      assert_shape_bounds( src.m_offset_map , 2 , range0.first , 0 );
 
768
      assert_shape_bounds( src.m_offset_map , 2 , range0.second - 1 , src.m_offset_map.N1 - 1 );
 
769
 
 
770
      dst.m_offset_map.assign(src.m_offset_map);
 
771
      dst.m_offset_map.N0 = range0.second - range0.first ;
 
772
      dst.m_tracking = src.m_tracking ;
 
773
 
 
774
      dst.m_ptr_on_device = src.ptr_on_device() + src.m_offset_map(range0.first,0);
 
775
 
 
776
      dst.m_tracking.increment( dst.ptr_on_device() );
 
777
    }
 
778
  }
 
779
  //------------------------------------
 
780
  /** \brief  Extract Rank-2 array from LayoutRight Rank-3 array. */
 
781
  template< class DT , class DL , class DD , class DM ,
 
782
            class ST , class SL , class SD , class SM >
 
783
  KOKKOS_INLINE_FUNCTION
 
784
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
785
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
786
                  const unsigned i0 ,
 
787
                  const ALL & ,
 
788
                  const typename enable_if< (
 
789
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
790
                    &&
 
791
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
792
                    &&
 
793
                    ( ViewTraits<ST,SL,SD,SM>::rank == 3 )
 
794
                    &&
 
795
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
796
                    &&
 
797
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
798
                  ), ALL >::type & )
 
799
  {
 
800
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
801
 
 
802
    dst.m_management.decrement( dst.m_ptr_on_device );
 
803
 
 
804
    dst.m_management      = src.m_management ;
 
805
    dst.m_offset_map.N0 = src.m_offset_map.N1 ;
 
806
    dst.m_offset_map.N1 = src.m_offset_map.N2 ;
 
807
    dst.m_offset_map.SR = dst.m_offset_map.N1 ;
 
808
    dst.m_ptr_on_device = &src(i0,0,0);
 
809
 
 
810
    dst.m_management.increment( dst.m_ptr_on_device );
 
811
  }
 
812
 
 
813
  //------------------------------------
 
814
  /** \brief  Extract Rank-2 array from LayoutRight Rank-4 array. */
 
815
  template< class DT , class DL , class DD , class DM ,
 
816
            class ST , class SL , class SD , class SM >
 
817
  KOKKOS_INLINE_FUNCTION
 
818
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
819
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
820
                  const unsigned i0 ,
 
821
                  const unsigned i1 ,
 
822
                  const ALL & ,
 
823
                  const typename enable_if< (
 
824
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
825
                    &&
 
826
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
827
                    &&
 
828
                    ( ViewTraits<ST,SL,SD,SM>::rank == 4 )
 
829
                    &&
 
830
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
831
                    &&
 
832
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
833
                  ), ALL >::type & )
 
834
  {
 
835
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
836
 
 
837
    dst.m_management.decrement( dst.m_ptr_on_device );
 
838
 
 
839
    dst.m_management      = src.m_management ;
 
840
    dst.m_offset_map.N0 = src.m_offset_map.N2 ;
 
841
    dst.m_offset_map.N1 = src.m_offset_map.N3 ;
 
842
    dst.m_offset_map.SR = dst.m_offset_map.N1 ;
 
843
    dst.m_ptr_on_device = &src(i0,i1,0,0);
 
844
 
 
845
    dst.m_management.increment( dst.m_ptr_on_device );
 
846
  }
 
847
 
 
848
  //------------------------------------
 
849
  /** \brief  Extract Rank-2 array from LayoutRight Rank-5 array. */
 
850
  template< class DT , class DL , class DD , class DM ,
 
851
            class ST , class SL , class SD , class SM >
 
852
  KOKKOS_INLINE_FUNCTION
 
853
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
854
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
855
                  const unsigned i0 ,
 
856
                  const unsigned i1 ,
 
857
                  const unsigned i2 ,
 
858
                  const ALL & ,
 
859
                  const typename enable_if< (
 
860
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
861
                    &&
 
862
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
863
                    &&
 
864
                    ( ViewTraits<ST,SL,SD,SM>::rank == 5 )
 
865
                    &&
 
866
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
867
                    &&
 
868
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
869
                  ), ALL >::type & )
 
870
  {
 
871
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
872
 
 
873
    dst.m_management.decrement( dst.m_ptr_on_device );
 
874
 
 
875
    dst.m_management      = src.m_management ;
 
876
    dst.m_offset_map.N0 = src.m_offset_map.N3 ;
 
877
    dst.m_offset_map.N1 = src.m_offset_map.N4 ;
 
878
    dst.m_offset_map.SR = dst.m_offset_map.N1 ;
 
879
    dst.m_ptr_on_device = &src(i0,i1,i2,0,0);
 
880
 
 
881
    dst.m_management.increment( dst.m_ptr_on_device );
 
882
  }
 
883
 
 
884
 
 
885
  //------------------------------------
 
886
  /** \brief  Extract Rank-2 array from LayoutRight Rank-6 array. */
 
887
  template< class DT , class DL , class DD , class DM ,
 
888
            class ST , class SL , class SD , class SM >
 
889
  KOKKOS_INLINE_FUNCTION
 
890
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
891
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
892
                  const unsigned i0 ,
 
893
                  const unsigned i1 ,
 
894
                  const unsigned i2 ,
 
895
                  const unsigned i3 ,
 
896
                  const ALL & ,
 
897
                  const typename enable_if< (
 
898
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
899
                    &&
 
900
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
901
                    &&
 
902
                    ( ViewTraits<ST,SL,SD,SM>::rank == 6 )
 
903
                    &&
 
904
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
905
                    &&
 
906
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
907
                  ), ALL >::type & )
 
908
  {
 
909
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
910
 
 
911
    dst.m_management.decrement( dst.m_ptr_on_device );
 
912
 
 
913
    dst.m_management      = src.m_management ;
 
914
    dst.m_offset_map.N0 = src.m_offset_map.N4 ;
 
915
    dst.m_offset_map.N1 = src.m_offset_map.N5 ;
 
916
    dst.m_offset_map.SR = dst.m_offset_map.N1 ;
 
917
    dst.m_ptr_on_device = &src(i0,i1,i2,i3,0,0);
 
918
 
 
919
    dst.m_management.increment( dst.m_ptr_on_device );
 
920
  }
 
921
 
 
922
  //------------------------------------
 
923
  /** \brief  Extract Rank-2 array from LayoutRight Rank-7 array. */
 
924
  template< class DT , class DL , class DD , class DM ,
 
925
            class ST , class SL , class SD , class SM >
 
926
  KOKKOS_INLINE_FUNCTION
 
927
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
928
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
929
                  const unsigned i0 ,
 
930
                  const unsigned i1 ,
 
931
                  const unsigned i2 ,
 
932
                  const unsigned i3 ,
 
933
                  const unsigned i4 ,
 
934
                  const ALL & ,
 
935
                  const typename enable_if< (
 
936
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
937
                    &&
 
938
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
939
                    &&
 
940
                    ( ViewTraits<ST,SL,SD,SM>::rank == 7 )
 
941
                    &&
 
942
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
943
                    &&
 
944
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
945
                  ), ALL >::type & )
 
946
  {
 
947
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
948
 
 
949
    dst.m_management.decrement( dst.m_ptr_on_device );
 
950
 
 
951
    dst.m_management      = src.m_management ;
 
952
    dst.m_offset_map.N0 = src.m_offset_map.N5 ;
 
953
    dst.m_offset_map.N1 = src.m_offset_map.N6 ;
 
954
    dst.m_offset_map.SR = dst.m_offset_map.N1 ;
 
955
    dst.m_ptr_on_device = &src(i0,i1,i2,i3,i4,0,0);
 
956
 
 
957
    dst.m_management.increment( dst.m_ptr_on_device );
 
958
  }
 
959
 
 
960
 
 
961
  //------------------------------------
 
962
  /** \brief  Extract Rank-2 array from LayoutRight Rank-8 array. */
 
963
  template< class DT , class DL , class DD , class DM ,
 
964
            class ST , class SL , class SD , class SM >
 
965
  KOKKOS_INLINE_FUNCTION
 
966
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
967
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
968
                  const unsigned i0 ,
 
969
                  const unsigned i1 ,
 
970
                  const unsigned i2 ,
 
971
                  const unsigned i3 ,
 
972
                  const unsigned i4 ,
 
973
                  const unsigned i5 ,
 
974
                  const ALL & ,
 
975
                  const typename enable_if< (
 
976
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
977
                    &&
 
978
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
979
                    &&
 
980
                    ( ViewTraits<ST,SL,SD,SM>::rank == 8 )
 
981
                    &&
 
982
                    ( ViewTraits<DT,DL,DD,DM>::rank == 2 )
 
983
                    &&
 
984
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 2 )
 
985
                  ), ALL >::type & )
 
986
  {
 
987
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
988
 
 
989
    dst.m_management.decrement( dst.m_ptr_on_device );
 
990
 
 
991
    dst.m_management      = src.m_management ;
 
992
    dst.m_offset_map.N0 = src.m_offset_map.N6 ;
 
993
    dst.m_offset_map.N1 = src.m_offset_map.N7 ;
 
994
    dst.m_offset_map.SR = dst.m_offset_map.N1 ;
 
995
    dst.m_ptr_on_device = &src(i0,i1,i2,i3,i4,i5,0,0);
 
996
 
 
997
    dst.m_management.increment( dst.m_ptr_on_device );
 
998
  }
 
999
 
 
1000
  //------------------------------------
 
1001
  /** \brief  Extract Rank-3 array from LayoutRight Rank-4 array. */
 
1002
  template< class DT , class DL , class DD , class DM ,
 
1003
            class ST , class SL , class SD , class SM >
 
1004
  KOKKOS_INLINE_FUNCTION
 
1005
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1006
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1007
                  const unsigned i0 ,
 
1008
                  const ALL & ,
 
1009
                  const ALL & ,
 
1010
                  const typename enable_if< (
 
1011
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1012
                    &&
 
1013
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1014
                    &&
 
1015
                    ( ViewTraits<ST,SL,SD,SM>::rank == 4 )
 
1016
                    &&
 
1017
                    ( ViewTraits<DT,DL,DD,DM>::rank == 3 )
 
1018
                    &&
 
1019
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 3 )
 
1020
                  ), ALL >::type & )
 
1021
  {
 
1022
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1023
 
 
1024
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1025
 
 
1026
    dst.m_management      = src.m_management ;
 
1027
    dst.m_offset_map.N0 = src.m_offset_map.N1 ;
 
1028
    dst.m_offset_map.N1 = src.m_offset_map.N2 ;
 
1029
    dst.m_offset_map.N2 = src.m_offset_map.N3 ;
 
1030
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 ;
 
1031
    dst.m_ptr_on_device = &src(i0,0,0,0);
 
1032
 
 
1033
    dst.m_management.increment( dst.m_ptr_on_device );
 
1034
  }
 
1035
 
 
1036
  //------------------------------------
 
1037
  /** \brief  Extract Rank-3 array from LayoutRight Rank-5 array. */
 
1038
  template< class DT , class DL , class DD , class DM ,
 
1039
            class ST , class SL , class SD , class SM >
 
1040
  KOKKOS_INLINE_FUNCTION
 
1041
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1042
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1043
                  const unsigned i0 ,
 
1044
                  const unsigned i1 ,
 
1045
                  const ALL & ,
 
1046
                  const ALL & ,
 
1047
                  const typename enable_if< (
 
1048
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1049
                    &&
 
1050
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1051
                    &&
 
1052
                    ( ViewTraits<ST,SL,SD,SM>::rank == 5 )
 
1053
                    &&
 
1054
                    ( ViewTraits<DT,DL,DD,DM>::rank == 3 )
 
1055
                    &&
 
1056
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 3 )
 
1057
                  ), ALL >::type & )
 
1058
  {
 
1059
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1060
 
 
1061
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1062
 
 
1063
    dst.m_management      = src.m_management ;
 
1064
    dst.m_offset_map.N0 = src.m_offset_map.N2 ;
 
1065
    dst.m_offset_map.N1 = src.m_offset_map.N3 ;
 
1066
    dst.m_offset_map.N2 = src.m_offset_map.N4 ;
 
1067
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 ;
 
1068
    dst.m_ptr_on_device = &src(i0,i1,0,0,0);
 
1069
 
 
1070
    dst.m_management.increment( dst.m_ptr_on_device );
 
1071
  }
 
1072
 
 
1073
  //------------------------------------
 
1074
  /** \brief  Extract Rank-3 array from LayoutRight Rank-6 array. */
 
1075
  template< class DT , class DL , class DD , class DM ,
 
1076
            class ST , class SL , class SD , class SM >
 
1077
  KOKKOS_INLINE_FUNCTION
 
1078
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1079
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1080
                  const unsigned i0 ,
 
1081
                  const unsigned i1 ,
 
1082
                  const unsigned i2 ,
 
1083
                  const ALL & ,
 
1084
                  const ALL & ,
 
1085
                  const typename enable_if< (
 
1086
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1087
                    &&
 
1088
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1089
                    &&
 
1090
                    ( ViewTraits<ST,SL,SD,SM>::rank == 6 )
 
1091
                    &&
 
1092
                    ( ViewTraits<DT,DL,DD,DM>::rank == 3 )
 
1093
                    &&
 
1094
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 3 )
 
1095
                  ), ALL >::type & )
 
1096
  {
 
1097
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1098
 
 
1099
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1100
 
 
1101
    dst.m_management      = src.m_management ;
 
1102
    dst.m_offset_map.N0 = src.m_offset_map.N3 ;
 
1103
    dst.m_offset_map.N1 = src.m_offset_map.N4 ;
 
1104
    dst.m_offset_map.N2 = src.m_offset_map.N5 ;
 
1105
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 ;
 
1106
    dst.m_ptr_on_device = &src(i0,i1,i2,0,0,0);
 
1107
 
 
1108
    dst.m_management.increment( dst.m_ptr_on_device );
 
1109
  }
 
1110
 
 
1111
  //------------------------------------
 
1112
  /** \brief  Extract Rank-3 array from LayoutRight Rank-7 array. */
 
1113
  template< class DT , class DL , class DD , class DM ,
 
1114
            class ST , class SL , class SD , class SM >
 
1115
  KOKKOS_INLINE_FUNCTION
 
1116
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1117
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1118
                  const unsigned i0 ,
 
1119
                  const unsigned i1 ,
 
1120
                  const unsigned i2 ,
 
1121
                  const unsigned i3 ,
 
1122
                  const ALL & ,
 
1123
                  const ALL & ,
 
1124
                  const typename enable_if< (
 
1125
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1126
                    &&
 
1127
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1128
                    &&
 
1129
                    ( ViewTraits<ST,SL,SD,SM>::rank == 7 )
 
1130
                    &&
 
1131
                    ( ViewTraits<DT,DL,DD,DM>::rank == 3 )
 
1132
                    &&
 
1133
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 3 )
 
1134
                  ), ALL >::type & )
 
1135
  {
 
1136
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1137
 
 
1138
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1139
 
 
1140
    dst.m_management      = src.m_management ;
 
1141
    dst.m_offset_map.N0 = src.m_offset_map.N4 ;
 
1142
    dst.m_offset_map.N1 = src.m_offset_map.N5 ;
 
1143
    dst.m_offset_map.N2 = src.m_offset_map.N6 ;
 
1144
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 ;
 
1145
    dst.m_ptr_on_device = &src(i0,i1,i2,i3,0,0,0);
 
1146
 
 
1147
    dst.m_management.increment( dst.m_ptr_on_device );
 
1148
  }
 
1149
 
 
1150
  //------------------------------------
 
1151
  /** \brief  Extract Rank-3 array from LayoutRight Rank-8 array. */
 
1152
  template< class DT , class DL , class DD , class DM ,
 
1153
            class ST , class SL , class SD , class SM >
 
1154
  KOKKOS_INLINE_FUNCTION
 
1155
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1156
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1157
                  const unsigned i0 ,
 
1158
                  const unsigned i1 ,
 
1159
                  const unsigned i2 ,
 
1160
                  const unsigned i3 ,
 
1161
                  const unsigned i4 ,
 
1162
                  const ALL & ,
 
1163
                  const ALL & ,
 
1164
                  const typename enable_if< (
 
1165
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1166
                    &&
 
1167
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1168
                    &&
 
1169
                    ( ViewTraits<ST,SL,SD,SM>::rank == 8 )
 
1170
                    &&
 
1171
                    ( ViewTraits<DT,DL,DD,DM>::rank == 3 )
 
1172
                    &&
 
1173
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 3 )
 
1174
                  ), ALL >::type & )
 
1175
  {
 
1176
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1177
 
 
1178
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1179
 
 
1180
    dst.m_management      = src.m_management ;
 
1181
    dst.m_offset_map.N0 = src.m_offset_map.N5 ;
 
1182
    dst.m_offset_map.N1 = src.m_offset_map.N6 ;
 
1183
    dst.m_offset_map.N2 = src.m_offset_map.N7 ;
 
1184
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 ;
 
1185
    dst.m_ptr_on_device = &src(i0,i1,i2,i3,i4,0,0,0);
 
1186
 
 
1187
    dst.m_management.increment( dst.m_ptr_on_device );
 
1188
  }
 
1189
 
 
1190
  //------------------------------------
 
1191
  /** \brief  Extract Rank-4 array from LayoutRight Rank-5 array. */
 
1192
  template< class DT , class DL , class DD , class DM ,
 
1193
            class ST , class SL , class SD , class SM >
 
1194
  KOKKOS_INLINE_FUNCTION
 
1195
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1196
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1197
                  const unsigned i0 ,
 
1198
                  const ALL & ,
 
1199
                  const ALL & ,
 
1200
                  const ALL & ,
 
1201
                  const typename enable_if< (
 
1202
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1203
                    &&
 
1204
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1205
                    &&
 
1206
                    ( ViewTraits<ST,SL,SD,SM>::rank == 5 )
 
1207
                    &&
 
1208
                    ( ViewTraits<DT,DL,DD,DM>::rank == 4 )
 
1209
                    &&
 
1210
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 4 )
 
1211
                  ), ALL >::type & )
 
1212
  {
 
1213
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1214
 
 
1215
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1216
 
 
1217
    dst.m_management      = src.m_management ;
 
1218
    dst.m_offset_map.N0 = src.m_offset_map.N1 ;
 
1219
    dst.m_offset_map.N1 = src.m_offset_map.N2 ;
 
1220
    dst.m_offset_map.N2 = src.m_offset_map.N3 ;
 
1221
    dst.m_offset_map.N3 = src.m_offset_map.N4 ;
 
1222
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 *
 
1223
                          dst.m_offset_map.N3 ;
 
1224
    dst.m_ptr_on_device = &src(i0,0,0,0,0);
 
1225
 
 
1226
    dst.m_management.increment( dst.m_ptr_on_device );
 
1227
  }
 
1228
 
 
1229
  //------------------------------------
 
1230
  /** \brief  Extract Rank-4 array from LayoutRight Rank-6 array. */
 
1231
  template< class DT , class DL , class DD , class DM ,
 
1232
            class ST , class SL , class SD , class SM >
 
1233
  KOKKOS_INLINE_FUNCTION
 
1234
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1235
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1236
                  const unsigned i0 ,
 
1237
                  const unsigned i1 ,
 
1238
                  const ALL & ,
 
1239
                  const ALL & ,
 
1240
                  const ALL & ,
 
1241
                  const typename enable_if< (
 
1242
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1243
                    &&
 
1244
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1245
                    &&
 
1246
                    ( ViewTraits<ST,SL,SD,SM>::rank == 6 )
 
1247
                    &&
 
1248
                    ( ViewTraits<DT,DL,DD,DM>::rank == 4 )
 
1249
                    &&
 
1250
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 4 )
 
1251
                  ), ALL >::type & )
 
1252
  {
 
1253
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1254
 
 
1255
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1256
 
 
1257
    dst.m_management      = src.m_management ;
 
1258
    dst.m_offset_map.N0 = src.m_offset_map.N2 ;
 
1259
    dst.m_offset_map.N1 = src.m_offset_map.N3 ;
 
1260
    dst.m_offset_map.N2 = src.m_offset_map.N4 ;
 
1261
    dst.m_offset_map.N3 = src.m_offset_map.N5 ;
 
1262
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 *
 
1263
                          dst.m_offset_map.N3 ;
 
1264
    dst.m_ptr_on_device = &src(i0,i1,0,0,0,0);
 
1265
 
 
1266
    dst.m_management.increment( dst.m_ptr_on_device );
 
1267
  }
 
1268
 
 
1269
  //------------------------------------
 
1270
  /** \brief  Extract Rank-4 array from LayoutRight Rank-7 array. */
 
1271
  template< class DT , class DL , class DD , class DM ,
 
1272
            class ST , class SL , class SD , class SM >
 
1273
  KOKKOS_INLINE_FUNCTION
 
1274
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1275
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1276
                  const unsigned i0 ,
 
1277
                  const unsigned i1 ,
 
1278
                  const unsigned i2 ,
 
1279
                  const ALL & ,
 
1280
                  const ALL & ,
 
1281
                  const ALL & ,
 
1282
                  const typename enable_if< (
 
1283
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1284
                    &&
 
1285
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1286
                    &&
 
1287
                    ( ViewTraits<ST,SL,SD,SM>::rank == 7 )
 
1288
                    &&
 
1289
                    ( ViewTraits<DT,DL,DD,DM>::rank == 4 )
 
1290
                    &&
 
1291
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 4 )
 
1292
                  ), ALL >::type & )
 
1293
  {
 
1294
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1295
 
 
1296
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1297
 
 
1298
    dst.m_management      = src.m_management ;
 
1299
    dst.m_offset_map.N0 = src.m_offset_map.N3 ;
 
1300
    dst.m_offset_map.N1 = src.m_offset_map.N4 ;
 
1301
    dst.m_offset_map.N2 = src.m_offset_map.N5 ;
 
1302
    dst.m_offset_map.N3 = src.m_offset_map.N6 ;
 
1303
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 *
 
1304
                          dst.m_offset_map.N3 ;
 
1305
    dst.m_ptr_on_device = &src(i0,i1,i2,0,0,0,0);
 
1306
 
 
1307
    dst.m_management.increment( dst.m_ptr_on_device );
 
1308
  }
 
1309
 
 
1310
  //------------------------------------
 
1311
  /** \brief  Extract Rank-4 array from LayoutRight Rank-8 array. */
 
1312
  template< class DT , class DL , class DD , class DM ,
 
1313
            class ST , class SL , class SD , class SM >
 
1314
  KOKKOS_INLINE_FUNCTION
 
1315
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1316
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1317
                  const unsigned i0 ,
 
1318
                  const unsigned i1 ,
 
1319
                  const unsigned i2 ,
 
1320
                  const unsigned i3 ,
 
1321
                  const ALL & ,
 
1322
                  const ALL & ,
 
1323
                  const ALL & ,
 
1324
                  const typename enable_if< (
 
1325
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1326
                    &&
 
1327
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1328
                    &&
 
1329
                    ( ViewTraits<ST,SL,SD,SM>::rank == 8 )
 
1330
                    &&
 
1331
                    ( ViewTraits<DT,DL,DD,DM>::rank == 4 )
 
1332
                    &&
 
1333
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 4 )
 
1334
                  ), ALL >::type & )
 
1335
  {
 
1336
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1337
 
 
1338
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1339
 
 
1340
    dst.m_management      = src.m_management ;
 
1341
    dst.m_offset_map.N0 = src.m_offset_map.N4 ;
 
1342
    dst.m_offset_map.N1 = src.m_offset_map.N5 ;
 
1343
    dst.m_offset_map.N2 = src.m_offset_map.N6 ;
 
1344
    dst.m_offset_map.N3 = src.m_offset_map.N7 ;
 
1345
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 *
 
1346
                          dst.m_offset_map.N3 ;
 
1347
    dst.m_ptr_on_device = &src(i0,i1,i2,i3,0,0,0,0);
 
1348
 
 
1349
    dst.m_management.increment( dst.m_ptr_on_device );
 
1350
  }
 
1351
 
 
1352
  //------------------------------------
 
1353
  /** \brief  Extract Rank-5 array from LayoutRight Rank-6 array. */
 
1354
  template< class DT , class DL , class DD , class DM ,
 
1355
            class ST , class SL , class SD , class SM >
 
1356
  KOKKOS_INLINE_FUNCTION
 
1357
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1358
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1359
                  const unsigned i0 ,
 
1360
                  const ALL & ,
 
1361
                  const ALL & ,
 
1362
                  const ALL & ,
 
1363
                  const ALL & ,
 
1364
                  const typename enable_if< (
 
1365
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1366
                    &&
 
1367
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1368
                    &&
 
1369
                    ( ViewTraits<ST,SL,SD,SM>::rank == 6 )
 
1370
                    &&
 
1371
                    ( ViewTraits<DT,DL,DD,DM>::rank == 5 )
 
1372
                    &&
 
1373
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 5 )
 
1374
                  ), ALL >::type & )
 
1375
  {
 
1376
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1377
 
 
1378
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1379
 
 
1380
    dst.m_management      = src.m_management ;
 
1381
    dst.m_offset_map.N0 = src.m_offset_map.N1 ;
 
1382
    dst.m_offset_map.N1 = src.m_offset_map.N2 ;
 
1383
    dst.m_offset_map.N2 = src.m_offset_map.N3 ;
 
1384
    dst.m_offset_map.N3 = src.m_offset_map.N4 ;
 
1385
    dst.m_offset_map.N4 = src.m_offset_map.N5 ;
 
1386
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 *
 
1387
                          dst.m_offset_map.N3 * dst.m_offset_map.N4 ;
 
1388
    dst.m_ptr_on_device = &src(i0,0,0,0,0,0);
 
1389
 
 
1390
    dst.m_management.increment( dst.m_ptr_on_device );
 
1391
  }
 
1392
 
 
1393
  //------------------------------------
 
1394
  /** \brief  Extract Rank-5 array from LayoutRight Rank-7 array. */
 
1395
  template< class DT , class DL , class DD , class DM ,
 
1396
            class ST , class SL , class SD , class SM >
 
1397
  KOKKOS_INLINE_FUNCTION
 
1398
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1399
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1400
                  const unsigned i0 ,
 
1401
                  const unsigned i1 ,
 
1402
                  const ALL & ,
 
1403
                  const ALL & ,
 
1404
                  const ALL & ,
 
1405
                  const ALL & ,
 
1406
                  const typename enable_if< (
 
1407
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1408
                    &&
 
1409
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1410
                    &&
 
1411
                    ( ViewTraits<ST,SL,SD,SM>::rank == 7 )
 
1412
                    &&
 
1413
                    ( ViewTraits<DT,DL,DD,DM>::rank == 5 )
 
1414
                    &&
 
1415
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 5 )
 
1416
                  ), ALL >::type & )
 
1417
  {
 
1418
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1419
 
 
1420
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1421
 
 
1422
    dst.m_management      = src.m_management ;
 
1423
    dst.m_offset_map.N0 = src.m_offset_map.N2 ;
 
1424
    dst.m_offset_map.N1 = src.m_offset_map.N3 ;
 
1425
    dst.m_offset_map.N2 = src.m_offset_map.N4 ;
 
1426
    dst.m_offset_map.N3 = src.m_offset_map.N5 ;
 
1427
    dst.m_offset_map.N4 = src.m_offset_map.N6 ;
 
1428
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 *
 
1429
                          dst.m_offset_map.N3 * dst.m_offset_map.N4 ;
 
1430
    dst.m_ptr_on_device = &src(i0,i1,0,0,0,0,0);
 
1431
 
 
1432
    dst.m_management.increment( dst.m_ptr_on_device );
 
1433
  }
 
1434
 
 
1435
  //------------------------------------
 
1436
  /** \brief  Extract Rank-5 array from LayoutRight Rank-8 array. */
 
1437
  template< class DT , class DL , class DD , class DM ,
 
1438
            class ST , class SL , class SD , class SM >
 
1439
  KOKKOS_INLINE_FUNCTION
 
1440
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1441
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1442
                  const unsigned i0 ,
 
1443
                  const unsigned i1 ,
 
1444
                  const unsigned i2 ,
 
1445
                  const ALL & ,
 
1446
                  const ALL & ,
 
1447
                  const ALL & ,
 
1448
                  const ALL & ,
 
1449
                  const typename enable_if< (
 
1450
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1451
                    &&
 
1452
                    is_same< typename ViewTraits<ST,SL,SD,SM>::array_layout , LayoutRight >::value
 
1453
                    &&
 
1454
                    ( ViewTraits<ST,SL,SD,SM>::rank == 8 )
 
1455
                    &&
 
1456
                    ( ViewTraits<DT,DL,DD,DM>::rank == 5 )
 
1457
                    &&
 
1458
                    ( ViewTraits<DT,DL,DD,DM>::rank_dynamic == 5 )
 
1459
                  ), ALL >::type & )
 
1460
  {
 
1461
    //typedef ViewTraits<DT,DL,DD,DM> traits_type ; // unused
 
1462
 
 
1463
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1464
 
 
1465
    dst.m_management      = src.m_management ;
 
1466
    dst.m_offset_map.N0 = src.m_offset_map.N3 ;
 
1467
    dst.m_offset_map.N1 = src.m_offset_map.N4 ;
 
1468
    dst.m_offset_map.N2 = src.m_offset_map.N5 ;
 
1469
    dst.m_offset_map.N3 = src.m_offset_map.N6 ;
 
1470
    dst.m_offset_map.N4 = src.m_offset_map.N7 ;
 
1471
    dst.m_offset_map.SR = dst.m_offset_map.N1 * dst.m_offset_map.N2 *
 
1472
                          dst.m_offset_map.N3 * dst.m_offset_map.N4 ;
 
1473
    dst.m_ptr_on_device = &src(i0,i1,i2,0,0,0,0,0);
 
1474
 
 
1475
    dst.m_management.increment( dst.m_ptr_on_device );
 
1476
  }
 
1477
 
 
1478
  //------------------------------------
 
1479
 
 
1480
  template< class DT , class DL , class DD , class DM
 
1481
          , class ST , class SL , class SD , class SM
 
1482
          , class Type0
 
1483
          >
 
1484
  KOKKOS_INLINE_FUNCTION
 
1485
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1486
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1487
                  const Type0 & arg0 ,
 
1488
                  const typename enable_if< (
 
1489
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1490
                    &&
 
1491
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
1492
                    &&
 
1493
                    ( ViewTraits<ST,SL,SD,SM>::rank == 1 )
 
1494
                    &&
 
1495
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
1496
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) )
 
1497
                  )>::type * = 0 )
 
1498
  {
 
1499
    enum { src_rank = 1 };
 
1500
 
 
1501
    size_t str[2] = {0,0};
 
1502
 
 
1503
    src.m_offset_map.stride( str );
 
1504
 
 
1505
    const size_t offset = ViewOffsetRange< Type0 >::begin( arg0 ) * str[0] ;
 
1506
 
 
1507
    LayoutStride spec ;
 
1508
 
 
1509
    // Collapse dimension for non-ranges
 
1510
    if ( ViewOffsetRange< Type0 >::is_range ) {
 
1511
      spec.dimension[0] = ViewOffsetRange< Type0 >::dimension( src.m_offset_map.N0 , arg0 );
 
1512
      spec.stride[0]    = str[0] ;
 
1513
    }
 
1514
    else {
 
1515
      spec.dimension[0] = 1 ;
 
1516
      spec.stride[0]    = 1 ;
 
1517
    }
 
1518
 
 
1519
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1520
    dst.m_management = src.m_management ;
 
1521
    dst.m_offset_map.assign( spec );
 
1522
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
1523
    dst.m_management.increment( dst.m_ptr_on_device );
 
1524
  }
 
1525
 
 
1526
  template< class DT , class DL , class DD , class DM
 
1527
          , class ST , class SL , class SD , class SM
 
1528
          , class Type0
 
1529
          , class Type1
 
1530
          >
 
1531
  KOKKOS_INLINE_FUNCTION
 
1532
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1533
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1534
                  const Type0 & arg0 ,
 
1535
                  const Type1 & arg1 ,
 
1536
                  const typename enable_if< (
 
1537
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1538
                    &&
 
1539
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
1540
                    &&
 
1541
                    ( ViewTraits<ST,SL,SD,SM>::rank == 2 )
 
1542
                    &&
 
1543
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
1544
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) +
 
1545
                      ( ViewOffsetRange< Type1 >::is_range ? 1u : 0 ) )
 
1546
                  )>::type * = 0 )
 
1547
  {
 
1548
    enum { src_rank = 2 };
 
1549
 
 
1550
    const bool is_range[ src_rank ] =
 
1551
      { ViewOffsetRange< Type0 >::is_range
 
1552
      , ViewOffsetRange< Type1 >::is_range
 
1553
      };
 
1554
 
 
1555
    const unsigned begin[ src_rank ] =
 
1556
      { static_cast<unsigned>(ViewOffsetRange< Type0 >::begin( arg0 ))
 
1557
      , static_cast<unsigned>(ViewOffsetRange< Type1 >::begin( arg1 ))
 
1558
      };
 
1559
 
 
1560
    size_t stride[9] ;
 
1561
 
 
1562
    src.m_offset_map.stride( stride );
 
1563
 
 
1564
    LayoutStride spec ;
 
1565
 
 
1566
    spec.dimension[0] = ViewOffsetRange< Type0 >::dimension( src.m_offset_map.N0 , arg0 );
 
1567
    spec.dimension[1] = ViewOffsetRange< Type1 >::dimension( src.m_offset_map.N1 , arg1 );
 
1568
    spec.stride[0]    = stride[0] ;
 
1569
    spec.stride[1]    = stride[1] ;
 
1570
 
 
1571
    size_t offset = 0 ;
 
1572
 
 
1573
    // Collapse dimension for non-ranges
 
1574
    for ( int i = 0 , j = 0 ; i < int(src_rank) ; ++i ) {
 
1575
      spec.dimension[j] = spec.dimension[i] ;
 
1576
      spec.stride[j]    = spec.stride[i] ;
 
1577
      offset += begin[i] * spec.stride[i] ;
 
1578
      if ( is_range[i] ) { ++j ; }
 
1579
    }
 
1580
 
 
1581
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1582
    dst.m_management = src.m_management ;
 
1583
    dst.m_offset_map.assign( spec );
 
1584
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
1585
    dst.m_management.increment( dst.m_ptr_on_device );
 
1586
  }
 
1587
 
 
1588
  template< class DT , class DL , class DD , class DM
 
1589
          , class ST , class SL , class SD , class SM
 
1590
          , class Type0
 
1591
          , class Type1
 
1592
          , class Type2
 
1593
          >
 
1594
  KOKKOS_INLINE_FUNCTION
 
1595
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1596
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1597
                  const Type0 & arg0 ,
 
1598
                  const Type1 & arg1 ,
 
1599
                  const Type2 & arg2 ,
 
1600
                  const typename enable_if< (
 
1601
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1602
                    &&
 
1603
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
1604
                    &&
 
1605
                    ( ViewTraits<ST,SL,SD,SM>::rank == 3 )
 
1606
                    &&
 
1607
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
1608
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) +
 
1609
                      ( ViewOffsetRange< Type1 >::is_range ? 1u : 0 ) +
 
1610
                      ( ViewOffsetRange< Type2 >::is_range ? 1u : 0 ) )
 
1611
                  )>::type * = 0 )
 
1612
  {
 
1613
    enum { src_rank = 3 };
 
1614
 
 
1615
    const bool is_range[ src_rank ] =
 
1616
      { ViewOffsetRange< Type0 >::is_range
 
1617
      , ViewOffsetRange< Type1 >::is_range
 
1618
      , ViewOffsetRange< Type2 >::is_range
 
1619
      };
 
1620
 
 
1621
    // FIXME (mfh 26 Oct 2014) Should use size_type typedef here
 
1622
    // instead of unsigned.  If we did that, the static_casts would be
 
1623
    // unnecessary.
 
1624
    const unsigned begin[ src_rank ] = {
 
1625
      static_cast<unsigned> (ViewOffsetRange< Type0 >::begin (arg0))
 
1626
      , static_cast<unsigned> (ViewOffsetRange< Type1 >::begin (arg1))
 
1627
      , static_cast<unsigned> (ViewOffsetRange< Type2 >::begin (arg2))
 
1628
    };
 
1629
 
 
1630
    // FIXME (mfh 26 Oct 2014) Should use size_type typedef here
 
1631
    // instead of unsigned.  If we did that, the static_casts would be
 
1632
    // unnecessary.
 
1633
    unsigned dim[ src_rank ] = {
 
1634
      static_cast<unsigned> (ViewOffsetRange< Type0 >::dimension (src.m_offset_map.N0, arg0))
 
1635
      , static_cast<unsigned> (ViewOffsetRange< Type1 >::dimension (src.m_offset_map.N1, arg1))
 
1636
      , static_cast<unsigned> (ViewOffsetRange< Type2 >::dimension (src.m_offset_map.N2, arg2))
 
1637
    };
 
1638
 
 
1639
    size_t stride[9] = {0,0,0,0,0,0,0,0,0};
 
1640
 
 
1641
    src.m_offset_map.stride( stride );
 
1642
 
 
1643
    LayoutStride spec ;
 
1644
 
 
1645
    size_t offset = 0 ;
 
1646
 
 
1647
    // Collapse dimension for non-ranges
 
1648
    for ( int i = 0 , j = 0 ; i < int(src_rank) ; ++i ) {
 
1649
      spec.dimension[j] = dim[i] ;
 
1650
      spec.stride[j]    = stride[i] ;
 
1651
      offset += begin[i] * stride[i] ;
 
1652
      if ( is_range[i] ) { ++j ; }
 
1653
    }
 
1654
 
 
1655
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1656
    dst.m_management = src.m_management ;
 
1657
    dst.m_offset_map.assign( spec );
 
1658
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
1659
    dst.m_management.increment( dst.m_ptr_on_device );
 
1660
  }
 
1661
 
 
1662
  template< class DT , class DL , class DD , class DM
 
1663
          , class ST , class SL , class SD , class SM
 
1664
          , class Type0
 
1665
          , class Type1
 
1666
          , class Type2
 
1667
          , class Type3
 
1668
          >
 
1669
  KOKKOS_INLINE_FUNCTION
 
1670
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1671
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1672
                  const Type0 & arg0 ,
 
1673
                  const Type1 & arg1 ,
 
1674
                  const Type2 & arg2 ,
 
1675
                  const Type3 & arg3 ,
 
1676
                  const typename enable_if< (
 
1677
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1678
                    &&
 
1679
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
1680
                    &&
 
1681
                    ( ViewTraits<ST,SL,SD,SM>::rank == 4 )
 
1682
                    &&
 
1683
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
1684
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) +
 
1685
                      ( ViewOffsetRange< Type1 >::is_range ? 1u : 0 ) +
 
1686
                      ( ViewOffsetRange< Type2 >::is_range ? 1u : 0 ) +
 
1687
                      ( ViewOffsetRange< Type3 >::is_range ? 1u : 0 ) )
 
1688
                  )>::type * = 0 )
 
1689
  {
 
1690
    enum { src_rank = 4 };
 
1691
    const bool is_range[ src_rank ] =
 
1692
      { ViewOffsetRange< Type0 >::is_range
 
1693
      , ViewOffsetRange< Type1 >::is_range
 
1694
      , ViewOffsetRange< Type2 >::is_range
 
1695
      , ViewOffsetRange< Type3 >::is_range
 
1696
      };
 
1697
 
 
1698
    const unsigned begin[ src_rank ] =
 
1699
      { static_cast<unsigned>(ViewOffsetRange< Type0 >::begin( arg0 ))
 
1700
      , static_cast<unsigned>(ViewOffsetRange< Type1 >::begin( arg1 ))
 
1701
      , static_cast<unsigned>(ViewOffsetRange< Type2 >::begin( arg2 ))
 
1702
      , static_cast<unsigned>(ViewOffsetRange< Type3 >::begin( arg3 ))
 
1703
      };
 
1704
 
 
1705
    unsigned dim[ src_rank ] =
 
1706
      { static_cast<unsigned>(ViewOffsetRange< Type0 >::dimension( src.m_offset_map.N0 , arg0 ))
 
1707
      , static_cast<unsigned>(ViewOffsetRange< Type1 >::dimension( src.m_offset_map.N1 , arg1 ))
 
1708
      , static_cast<unsigned>(ViewOffsetRange< Type2 >::dimension( src.m_offset_map.N2 , arg2 ))
 
1709
      , static_cast<unsigned>(ViewOffsetRange< Type3 >::dimension( src.m_offset_map.N3 , arg3 ))
 
1710
      };
 
1711
 
 
1712
    size_t stride[9] = {0,0,0,0,0,0,0,0,0};
 
1713
 
 
1714
    src.m_offset_map.stride( stride );
 
1715
 
 
1716
    LayoutStride spec ;
 
1717
 
 
1718
    size_t offset = 0 ;
 
1719
 
 
1720
    // Collapse dimension for non-ranges
 
1721
    for ( int i = 0 , j = 0 ; i < int(src_rank) ; ++i ) {
 
1722
      spec.dimension[j] = dim[i] ;
 
1723
      spec.stride[j]    = stride[i] ;
 
1724
      offset += begin[i] * stride[i] ;
 
1725
      if ( is_range[i] ) { ++j ; }
 
1726
    }
 
1727
 
 
1728
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1729
    dst.m_management = src.m_management ;
 
1730
    dst.m_offset_map.assign( spec );
 
1731
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
1732
    dst.m_management.increment( dst.m_ptr_on_device );
 
1733
  }
 
1734
 
 
1735
  template< class DT , class DL , class DD , class DM
 
1736
          , class ST , class SL , class SD , class SM
 
1737
          , class Type0
 
1738
          , class Type1
 
1739
          , class Type2
 
1740
          , class Type3
 
1741
          , class Type4
 
1742
          >
 
1743
  KOKKOS_INLINE_FUNCTION
 
1744
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1745
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1746
                  const Type0 & arg0 ,
 
1747
                  const Type1 & arg1 ,
 
1748
                  const Type2 & arg2 ,
 
1749
                  const Type3 & arg3 ,
 
1750
                  const Type4 & arg4 ,
 
1751
                  const typename enable_if< (
 
1752
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1753
                    &&
 
1754
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
1755
                    &&
 
1756
                    ( ViewTraits<ST,SL,SD,SM>::rank == 5 )
 
1757
                    &&
 
1758
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
1759
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) +
 
1760
                      ( ViewOffsetRange< Type1 >::is_range ? 1u : 0 ) +
 
1761
                      ( ViewOffsetRange< Type2 >::is_range ? 1u : 0 ) +
 
1762
                      ( ViewOffsetRange< Type3 >::is_range ? 1u : 0 ) +
 
1763
                      ( ViewOffsetRange< Type4 >::is_range ? 1u : 0 ) )
 
1764
                  )>::type * = 0 )
 
1765
  {
 
1766
    enum { src_rank = 5 };
 
1767
    const bool is_range[ src_rank ] =
 
1768
      { ViewOffsetRange< Type0 >::is_range
 
1769
      , ViewOffsetRange< Type1 >::is_range
 
1770
      , ViewOffsetRange< Type2 >::is_range
 
1771
      , ViewOffsetRange< Type3 >::is_range
 
1772
      , ViewOffsetRange< Type4 >::is_range
 
1773
      };
 
1774
 
 
1775
    const unsigned begin[ src_rank ] =
 
1776
      { ViewOffsetRange< Type0 >::begin( arg0 )
 
1777
      , ViewOffsetRange< Type1 >::begin( arg1 )
 
1778
      , ViewOffsetRange< Type2 >::begin( arg2 )
 
1779
      , ViewOffsetRange< Type3 >::begin( arg3 )
 
1780
      , ViewOffsetRange< Type4 >::begin( arg4 )
 
1781
      };
 
1782
 
 
1783
    unsigned dim[ src_rank ] =
 
1784
      { ViewOffsetRange< Type0 >::dimension( src.m_offset_map.N0 , arg0 )
 
1785
      , ViewOffsetRange< Type1 >::dimension( src.m_offset_map.N1 , arg1 )
 
1786
      , ViewOffsetRange< Type2 >::dimension( src.m_offset_map.N2 , arg2 )
 
1787
      , ViewOffsetRange< Type3 >::dimension( src.m_offset_map.N3 , arg3 )
 
1788
      , ViewOffsetRange< Type4 >::dimension( src.m_offset_map.N4 , arg4 )
 
1789
      };
 
1790
 
 
1791
    size_t stride[9] = {0,0,0,0,0,0,0,0,0};
 
1792
 
 
1793
    src.m_offset_map.stride( stride );
 
1794
 
 
1795
    LayoutStride spec ;
 
1796
 
 
1797
    size_t offset = 0 ;
 
1798
 
 
1799
    // Collapse dimension for non-ranges
 
1800
    for ( int i = 0 , j = 0 ; i < int(src_rank) ; ++i ) {
 
1801
      spec.dimension[j] = dim[i] ;
 
1802
      spec.stride[j]    = stride[i] ;
 
1803
      offset += begin[i] * stride[i] ;
 
1804
      if ( is_range[i] ) { ++j ; }
 
1805
    }
 
1806
 
 
1807
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1808
    dst.m_management = src.m_management ;
 
1809
    dst.m_offset_map.assign( spec );
 
1810
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
1811
    dst.m_management.increment( dst.m_ptr_on_device );
 
1812
  }
 
1813
 
 
1814
  template< class DT , class DL , class DD , class DM
 
1815
          , class ST , class SL , class SD , class SM
 
1816
          , class Type0
 
1817
          , class Type1
 
1818
          , class Type2
 
1819
          , class Type3
 
1820
          , class Type4
 
1821
          , class Type5
 
1822
          >
 
1823
  KOKKOS_INLINE_FUNCTION
 
1824
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1825
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1826
                  const Type0 & arg0 ,
 
1827
                  const Type1 & arg1 ,
 
1828
                  const Type2 & arg2 ,
 
1829
                  const Type3 & arg3 ,
 
1830
                  const Type4 & arg4 ,
 
1831
                  const Type5 & arg5 ,
 
1832
                  const typename enable_if< (
 
1833
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1834
                    &&
 
1835
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
1836
                    &&
 
1837
                    ( ViewTraits<ST,SL,SD,SM>::rank == 6 )
 
1838
                    &&
 
1839
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
1840
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) +
 
1841
                      ( ViewOffsetRange< Type1 >::is_range ? 1u : 0 ) +
 
1842
                      ( ViewOffsetRange< Type2 >::is_range ? 1u : 0 ) +
 
1843
                      ( ViewOffsetRange< Type3 >::is_range ? 1u : 0 ) +
 
1844
                      ( ViewOffsetRange< Type4 >::is_range ? 1u : 0 ) +
 
1845
                      ( ViewOffsetRange< Type5 >::is_range ? 1u : 0 ) )
 
1846
                  )>::type * = 0 )
 
1847
  {
 
1848
    enum { src_rank = 6 };
 
1849
    const bool is_range[ src_rank ] =
 
1850
      { ViewOffsetRange< Type0 >::is_range
 
1851
      , ViewOffsetRange< Type1 >::is_range
 
1852
      , ViewOffsetRange< Type2 >::is_range
 
1853
      , ViewOffsetRange< Type3 >::is_range
 
1854
      , ViewOffsetRange< Type4 >::is_range
 
1855
      , ViewOffsetRange< Type5 >::is_range
 
1856
      };
 
1857
 
 
1858
    const unsigned begin[ src_rank ] =
 
1859
      { ViewOffsetRange< Type0 >::begin( arg0 )
 
1860
      , ViewOffsetRange< Type1 >::begin( arg1 )
 
1861
      , ViewOffsetRange< Type2 >::begin( arg2 )
 
1862
      , ViewOffsetRange< Type3 >::begin( arg3 )
 
1863
      , ViewOffsetRange< Type4 >::begin( arg4 )
 
1864
      , ViewOffsetRange< Type5 >::begin( arg5 )
 
1865
      };
 
1866
 
 
1867
    unsigned dim[ src_rank ] =
 
1868
      { ViewOffsetRange< Type0 >::dimension( src.m_offset_map.N0 , arg0 )
 
1869
      , ViewOffsetRange< Type1 >::dimension( src.m_offset_map.N1 , arg1 )
 
1870
      , ViewOffsetRange< Type2 >::dimension( src.m_offset_map.N2 , arg2 )
 
1871
      , ViewOffsetRange< Type3 >::dimension( src.m_offset_map.N3 , arg3 )
 
1872
      , ViewOffsetRange< Type4 >::dimension( src.m_offset_map.N4 , arg4 )
 
1873
      , ViewOffsetRange< Type5 >::dimension( src.m_offset_map.N5 , arg5 )
 
1874
      };
 
1875
 
 
1876
    size_t stride[9] = {0,0,0,0,0,0,0,0,0};
 
1877
 
 
1878
    src.m_offset_map.stride( stride );
 
1879
 
 
1880
    LayoutStride spec ;
 
1881
 
 
1882
    size_t offset = 0 ;
 
1883
 
 
1884
    // Collapse dimension for non-ranges
 
1885
    for ( int i = 0 , j = 0 ; i < int(src_rank) ; ++i ) {
 
1886
      spec.dimension[j] = dim[i] ;
 
1887
      spec.stride[j]    = stride[i] ;
 
1888
      offset += begin[i] * stride[i] ;
 
1889
      if ( is_range[i] ) { ++j ; }
 
1890
    }
 
1891
 
 
1892
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1893
    dst.m_management = src.m_management ;
 
1894
    dst.m_offset_map.assign( spec );
 
1895
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
1896
    dst.m_management.increment( dst.m_ptr_on_device );
 
1897
  }
 
1898
 
 
1899
  template< class DT , class DL , class DD , class DM
 
1900
          , class ST , class SL , class SD , class SM
 
1901
          , class Type0
 
1902
          , class Type1
 
1903
          , class Type2
 
1904
          , class Type3
 
1905
          , class Type4
 
1906
          , class Type5
 
1907
          , class Type6
 
1908
          >
 
1909
  KOKKOS_INLINE_FUNCTION
 
1910
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
1911
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
1912
                  const Type0 & arg0 ,
 
1913
                  const Type1 & arg1 ,
 
1914
                  const Type2 & arg2 ,
 
1915
                  const Type3 & arg3 ,
 
1916
                  const Type4 & arg4 ,
 
1917
                  const Type5 & arg5 ,
 
1918
                  const Type6 & arg6 ,
 
1919
                  const typename enable_if< (
 
1920
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
1921
                    &&
 
1922
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
1923
                    &&
 
1924
                    ( ViewTraits<ST,SL,SD,SM>::rank == 7 )
 
1925
                    &&
 
1926
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
1927
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) +
 
1928
                      ( ViewOffsetRange< Type1 >::is_range ? 1u : 0 ) +
 
1929
                      ( ViewOffsetRange< Type2 >::is_range ? 1u : 0 ) +
 
1930
                      ( ViewOffsetRange< Type3 >::is_range ? 1u : 0 ) +
 
1931
                      ( ViewOffsetRange< Type4 >::is_range ? 1u : 0 ) +
 
1932
                      ( ViewOffsetRange< Type5 >::is_range ? 1u : 0 ) +
 
1933
                      ( ViewOffsetRange< Type6 >::is_range ? 1u : 0 ) )
 
1934
                  )>::type * = 0 )
 
1935
  {
 
1936
    enum { src_rank = 7 };
 
1937
    const bool is_range[ src_rank ] =
 
1938
      { ViewOffsetRange< Type0 >::is_range
 
1939
      , ViewOffsetRange< Type1 >::is_range
 
1940
      , ViewOffsetRange< Type2 >::is_range
 
1941
      , ViewOffsetRange< Type3 >::is_range
 
1942
      , ViewOffsetRange< Type4 >::is_range
 
1943
      , ViewOffsetRange< Type5 >::is_range
 
1944
      , ViewOffsetRange< Type6 >::is_range
 
1945
      };
 
1946
 
 
1947
    const unsigned begin[ src_rank ] =
 
1948
      { ViewOffsetRange< Type0 >::begin( arg0 )
 
1949
      , ViewOffsetRange< Type1 >::begin( arg1 )
 
1950
      , ViewOffsetRange< Type2 >::begin( arg2 )
 
1951
      , ViewOffsetRange< Type3 >::begin( arg3 )
 
1952
      , ViewOffsetRange< Type4 >::begin( arg4 )
 
1953
      , ViewOffsetRange< Type5 >::begin( arg5 )
 
1954
      , ViewOffsetRange< Type6 >::begin( arg6 )
 
1955
      };
 
1956
 
 
1957
    unsigned dim[ src_rank ] =
 
1958
      { ViewOffsetRange< Type0 >::dimension( src.m_offset_map.N0 , arg0 )
 
1959
      , ViewOffsetRange< Type1 >::dimension( src.m_offset_map.N1 , arg1 )
 
1960
      , ViewOffsetRange< Type2 >::dimension( src.m_offset_map.N2 , arg2 )
 
1961
      , ViewOffsetRange< Type3 >::dimension( src.m_offset_map.N3 , arg3 )
 
1962
      , ViewOffsetRange< Type4 >::dimension( src.m_offset_map.N4 , arg4 )
 
1963
      , ViewOffsetRange< Type5 >::dimension( src.m_offset_map.N5 , arg5 )
 
1964
      , ViewOffsetRange< Type6 >::dimension( src.m_offset_map.N6 , arg6 )
 
1965
      };
 
1966
 
 
1967
    size_t stride[9] = {0,0,0,0,0,0,0,0,0};
 
1968
 
 
1969
    src.m_offset_map.stride( stride );
 
1970
 
 
1971
    LayoutStride spec ;
 
1972
 
 
1973
    size_t offset = 0 ;
 
1974
 
 
1975
    // Collapse dimension for non-ranges
 
1976
    for ( int i = 0 , j = 0 ; i < int(src_rank) ; ++i ) {
 
1977
      spec.dimension[j] = dim[i] ;
 
1978
      spec.stride[j]    = stride[i] ;
 
1979
      offset += begin[i] * stride[i] ;
 
1980
      if ( is_range[i] ) { ++j ; }
 
1981
    }
 
1982
 
 
1983
    dst.m_management.decrement( dst.m_ptr_on_device );
 
1984
    dst.m_management = src.m_management ;
 
1985
    dst.m_offset_map.assign( spec );
 
1986
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
1987
    dst.m_management.increment( dst.m_ptr_on_device );
 
1988
  }
 
1989
 
 
1990
  template< class DT , class DL , class DD , class DM
 
1991
          , class ST , class SL , class SD , class SM
 
1992
          , class Type0
 
1993
          , class Type1
 
1994
          , class Type2
 
1995
          , class Type3
 
1996
          , class Type4
 
1997
          , class Type5
 
1998
          , class Type6
 
1999
          , class Type7
 
2000
          >
 
2001
  KOKKOS_INLINE_FUNCTION
 
2002
  ViewAssignment(       View<DT,DL,DD,DM,Specialize> & dst ,
 
2003
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
2004
                  const Type0 & arg0 ,
 
2005
                  const Type1 & arg1 ,
 
2006
                  const Type2 & arg2 ,
 
2007
                  const Type3 & arg3 ,
 
2008
                  const Type4 & arg4 ,
 
2009
                  const Type5 & arg5 ,
 
2010
                  const Type6 & arg6 ,
 
2011
                  const Type7 & arg7 ,
 
2012
                  const typename enable_if< (
 
2013
                    ViewAssignable< ViewTraits<DT,DL,DD,DM> , ViewTraits<ST,SL,SD,SM> >::assignable_value
 
2014
                    &&
 
2015
                    is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout , LayoutStride >::value
 
2016
                    &&
 
2017
                    ( ViewTraits<ST,SL,SD,SM>::rank == 8 )
 
2018
                    &&
 
2019
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) ==
 
2020
                      ( ViewOffsetRange< Type0 >::is_range ? 1u : 0 ) +
 
2021
                      ( ViewOffsetRange< Type1 >::is_range ? 1u : 0 ) +
 
2022
                      ( ViewOffsetRange< Type2 >::is_range ? 1u : 0 ) +
 
2023
                      ( ViewOffsetRange< Type3 >::is_range ? 1u : 0 ) +
 
2024
                      ( ViewOffsetRange< Type4 >::is_range ? 1u : 0 ) +
 
2025
                      ( ViewOffsetRange< Type5 >::is_range ? 1u : 0 ) +
 
2026
                      ( ViewOffsetRange< Type6 >::is_range ? 1u : 0 ) +
 
2027
                      ( ViewOffsetRange< Type7 >::is_range ? 1u : 0 ) )
 
2028
                  )>::type * = 0 )
 
2029
  {
 
2030
    enum { src_rank = 8 };
 
2031
 
 
2032
    const bool is_range[ src_rank ] =
 
2033
      { ViewOffsetRange< Type0 >::is_range
 
2034
      , ViewOffsetRange< Type1 >::is_range
 
2035
      , ViewOffsetRange< Type2 >::is_range
 
2036
      , ViewOffsetRange< Type3 >::is_range
 
2037
      , ViewOffsetRange< Type4 >::is_range
 
2038
      , ViewOffsetRange< Type5 >::is_range
 
2039
      , ViewOffsetRange< Type6 >::is_range
 
2040
      , ViewOffsetRange< Type7 >::is_range
 
2041
      };
 
2042
 
 
2043
    const unsigned begin[ src_rank ] =
 
2044
      { ViewOffsetRange< Type0 >::begin( arg0 )
 
2045
      , ViewOffsetRange< Type1 >::begin( arg1 )
 
2046
      , ViewOffsetRange< Type2 >::begin( arg2 )
 
2047
      , ViewOffsetRange< Type3 >::begin( arg3 )
 
2048
      , ViewOffsetRange< Type4 >::begin( arg4 )
 
2049
      , ViewOffsetRange< Type5 >::begin( arg5 )
 
2050
      , ViewOffsetRange< Type6 >::begin( arg6 )
 
2051
      , ViewOffsetRange< Type7 >::begin( arg7 )
 
2052
      };
 
2053
 
 
2054
    unsigned dim[ src_rank ] =
 
2055
      { ViewOffsetRange< Type0 >::dimension( src.m_offset_map.N0 , arg0 )
 
2056
      , ViewOffsetRange< Type1 >::dimension( src.m_offset_map.N1 , arg1 )
 
2057
      , ViewOffsetRange< Type2 >::dimension( src.m_offset_map.N2 , arg2 )
 
2058
      , ViewOffsetRange< Type3 >::dimension( src.m_offset_map.N3 , arg3 )
 
2059
      , ViewOffsetRange< Type4 >::dimension( src.m_offset_map.N4 , arg4 )
 
2060
      , ViewOffsetRange< Type5 >::dimension( src.m_offset_map.N5 , arg5 )
 
2061
      , ViewOffsetRange< Type6 >::dimension( src.m_offset_map.N6 , arg6 )
 
2062
      , ViewOffsetRange< Type7 >::dimension( src.m_offset_map.N7 , arg7 )
 
2063
      };
 
2064
 
 
2065
    size_t stride[9] = {0,0,0,0,0,0,0,0,0};
 
2066
 
 
2067
    src.m_offset_map.stride( stride );
 
2068
 
 
2069
    LayoutStride spec ;
 
2070
 
 
2071
    size_t offset = 0 ;
 
2072
 
 
2073
    // Collapse dimension for non-ranges
 
2074
    for ( int i = 0 , j = 0 ; i < int(src_rank) ; ++i ) {
 
2075
      spec.dimension[j] = dim[i] ;
 
2076
      spec.stride[j]    = stride[i] ;
 
2077
      offset += begin[i] * stride[i] ;
 
2078
      if ( is_range[i] ) { ++j ; }
 
2079
    }
 
2080
 
 
2081
    dst.m_management.decrement( dst.m_ptr_on_device );
 
2082
 
 
2083
    dst.m_management = src.m_management ;
 
2084
 
 
2085
    dst.m_offset_map.assign( spec );
 
2086
 
 
2087
    dst.m_ptr_on_device = src.ptr_on_device() + offset ;
 
2088
 
 
2089
    dst.m_management.increment( dst.m_ptr_on_device );
 
2090
  }
 
2091
 
 
2092
  //------------------------------------
 
2093
  /** \brief  Deep copy data from compatible value type, layout, rank, and specialization.
 
2094
   *          Check the dimensions and allocation lengths at runtime.
 
2095
   */
 
2096
  template< class DT , class DL , class DD , class DM ,
 
2097
            class ST , class SL , class SD , class SM >
 
2098
  inline static
 
2099
  void deep_copy( const View<DT,DL,DD,DM,Specialize> & dst ,
 
2100
                  const View<ST,SL,SD,SM,Specialize> & src ,
 
2101
                  const typename Impl::enable_if<(
 
2102
                    Impl::is_same< typename ViewTraits<DT,DL,DD,DM>::value_type ,
 
2103
                                   typename ViewTraits<ST,SL,SD,SM>::non_const_value_type >::value
 
2104
                    &&
 
2105
                    Impl::is_same< typename ViewTraits<DT,DL,DD,DM>::array_layout ,
 
2106
                                   typename ViewTraits<ST,SL,SD,SM>::array_layout >::value
 
2107
                    &&
 
2108
                    ( unsigned(ViewTraits<DT,DL,DD,DM>::rank) == unsigned(ViewTraits<ST,SL,SD,SM>::rank) )
 
2109
                  )>::type * = 0 )
 
2110
  {
 
2111
    typedef typename ViewTraits<DT,DL,DD,DM>::memory_space dst_memory_space ;
 
2112
    typedef typename ViewTraits<ST,SL,SD,SM>::memory_space src_memory_space ;
 
2113
 
 
2114
    if ( dst.ptr_on_device() != src.ptr_on_device() ) {
 
2115
 
 
2116
      Impl::assert_shapes_are_equal( dst.m_offset_map , src.m_offset_map );
 
2117
 
 
2118
      const size_t nbytes = dst.m_offset_map.scalar_size * dst.m_offset_map.capacity();
 
2119
 
 
2120
      DeepCopy< dst_memory_space , src_memory_space >( dst.ptr_on_device() , src.ptr_on_device() , nbytes );
 
2121
    }
 
2122
  }
 
2123
};
 
2124
 
 
2125
} /* namespace Impl */
 
2126
} /* namespace Kokkos */
 
2127
 
 
2128
//----------------------------------------------------------------------------
 
2129
//----------------------------------------------------------------------------
 
2130
 
 
2131
namespace Kokkos {
 
2132
namespace Impl {
 
2133
 
 
2134
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2135
        , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
2136
        , class SubArg4_type , class SubArg5_type , class SubArg6_type , class SubArg7_type
 
2137
        >
 
2138
struct ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2139
                  , SubArg0_type , SubArg1_type , SubArg2_type , SubArg3_type
 
2140
                  , SubArg4_type , SubArg5_type , SubArg6_type , SubArg7_type >
 
2141
{
 
2142
private:
 
2143
 
 
2144
  typedef View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >  SrcViewType ;
 
2145
 
 
2146
  enum { V0 = Impl::is_same< SubArg0_type , void >::value ? 1 : 0 };
 
2147
  enum { V1 = Impl::is_same< SubArg1_type , void >::value ? 1 : 0 };
 
2148
  enum { V2 = Impl::is_same< SubArg2_type , void >::value ? 1 : 0 };
 
2149
  enum { V3 = Impl::is_same< SubArg3_type , void >::value ? 1 : 0 };
 
2150
  enum { V4 = Impl::is_same< SubArg4_type , void >::value ? 1 : 0 };
 
2151
  enum { V5 = Impl::is_same< SubArg5_type , void >::value ? 1 : 0 };
 
2152
  enum { V6 = Impl::is_same< SubArg6_type , void >::value ? 1 : 0 };
 
2153
  enum { V7 = Impl::is_same< SubArg7_type , void >::value ? 1 : 0 };
 
2154
 
 
2155
  // The source view rank must be equal to the input argument rank
 
2156
  // Once a void argument is encountered all subsequent arguments must be void.
 
2157
  enum { InputRank =
 
2158
    Impl::StaticAssert<( SrcViewType::rank ==
 
2159
                         ( V0 ? 0 : (
 
2160
                           V1 ? 1 : (
 
2161
                           V2 ? 2 : (
 
2162
                           V3 ? 3 : (
 
2163
                           V4 ? 4 : (
 
2164
                           V5 ? 5 : (
 
2165
                           V6 ? 6 : (
 
2166
                           V7 ? 7 : 8 ))))))) ))
 
2167
                       &&
 
2168
                       ( SrcViewType::rank ==
 
2169
                         ( 8 - ( V0 + V1 + V2 + V3 + V4 + V5 + V6 + V7 ) ) )
 
2170
    >::value ? SrcViewType::rank : 0 };
 
2171
 
 
2172
  enum { R0 = Impl::ViewOffsetRange< SubArg0_type >::is_range ? 1 : 0 };
 
2173
  enum { R1 = Impl::ViewOffsetRange< SubArg1_type >::is_range ? 1 : 0 };
 
2174
  enum { R2 = Impl::ViewOffsetRange< SubArg2_type >::is_range ? 1 : 0 };
 
2175
  enum { R3 = Impl::ViewOffsetRange< SubArg3_type >::is_range ? 1 : 0 };
 
2176
  enum { R4 = Impl::ViewOffsetRange< SubArg4_type >::is_range ? 1 : 0 };
 
2177
  enum { R5 = Impl::ViewOffsetRange< SubArg5_type >::is_range ? 1 : 0 };
 
2178
  enum { R6 = Impl::ViewOffsetRange< SubArg6_type >::is_range ? 1 : 0 };
 
2179
  enum { R7 = Impl::ViewOffsetRange< SubArg7_type >::is_range ? 1 : 0 };
 
2180
 
 
2181
  enum { OutputRank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
 
2182
                    + unsigned(R4) + unsigned(R5) + unsigned(R6) + unsigned(R7) };
 
2183
 
 
2184
  // Reverse
 
2185
  enum { R0_rev = 0 == InputRank ? 0u : (
 
2186
                  1 == InputRank ? unsigned(R0) : (
 
2187
                  2 == InputRank ? unsigned(R1) : (
 
2188
                  3 == InputRank ? unsigned(R2) : (
 
2189
                  4 == InputRank ? unsigned(R3) : (
 
2190
                  5 == InputRank ? unsigned(R4) : (
 
2191
                  6 == InputRank ? unsigned(R5) : (
 
2192
                  7 == InputRank ? unsigned(R6) : unsigned(R7) ))))))) };
 
2193
 
 
2194
  typedef typename SrcViewType::array_layout  SrcViewLayout ;
 
2195
 
 
2196
  // Choose array layout, attempting to preserve original layout if at all possible.
 
2197
  typedef typename Impl::if_c<
 
2198
     ( // Same Layout IF
 
2199
       // OutputRank 0
 
2200
       ( OutputRank == 0 )
 
2201
       ||
 
2202
       // OutputRank 1 or 2, InputLayout Left, Interval 0
 
2203
       // because single stride one or second index has a stride.
 
2204
       ( OutputRank <= 2 && R0 && Impl::is_same<SrcViewLayout,LayoutLeft>::value )
 
2205
       ||
 
2206
       // OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
 
2207
       // because single stride one or second index has a stride.
 
2208
       ( OutputRank <= 2 && R0_rev && Impl::is_same<SrcViewLayout,LayoutRight>::value )
 
2209
     ), SrcViewLayout , Kokkos::LayoutStride >::type OutputViewLayout ;
 
2210
 
 
2211
  // Choose data type as a purely dynamic rank array to accomodate a runtime range.
 
2212
  typedef typename Impl::if_c< OutputRank == 0 , typename SrcViewType::value_type ,
 
2213
          typename Impl::if_c< OutputRank == 1 , typename SrcViewType::value_type *,
 
2214
          typename Impl::if_c< OutputRank == 2 , typename SrcViewType::value_type **,
 
2215
          typename Impl::if_c< OutputRank == 3 , typename SrcViewType::value_type ***,
 
2216
          typename Impl::if_c< OutputRank == 4 , typename SrcViewType::value_type ****,
 
2217
          typename Impl::if_c< OutputRank == 5 , typename SrcViewType::value_type *****,
 
2218
          typename Impl::if_c< OutputRank == 6 , typename SrcViewType::value_type ******,
 
2219
          typename Impl::if_c< OutputRank == 7 , typename SrcViewType::value_type *******,
 
2220
                                                 typename SrcViewType::value_type ********
 
2221
  >::type >::type >::type >::type >::type >::type >::type >::type  OutputData ;
 
2222
 
 
2223
  // Choose space.
 
2224
  // If the source view's template arg1 or arg2 is a space then use it,
 
2225
  // otherwise use the source view's execution space.
 
2226
 
 
2227
  typedef typename Impl::if_c< Impl::is_space< SrcArg1Type >::value , SrcArg1Type ,
 
2228
          typename Impl::if_c< Impl::is_space< SrcArg2Type >::value , SrcArg2Type , typename SrcViewType::execution_space 
 
2229
  >::type >::type OutputSpace ;
 
2230
 
 
2231
public:
 
2232
 
 
2233
  // If keeping the layout then match non-data type arguments
 
2234
  // else keep execution space and memory traits.
 
2235
  typedef typename
 
2236
    Impl::if_c< Impl::is_same< SrcViewLayout , OutputViewLayout >::value
 
2237
              , Kokkos::View< OutputData , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2238
              , Kokkos::View< OutputData , OutputViewLayout , OutputSpace
 
2239
                            , typename SrcViewType::memory_traits
 
2240
                            , Impl::ViewDefault >
 
2241
              >::type  type ;
 
2242
};
 
2243
 
 
2244
} /* namespace Impl */
 
2245
} /* namespace Kokkos */
 
2246
 
 
2247
//----------------------------------------------------------------------------
 
2248
//----------------------------------------------------------------------------
 
2249
 
 
2250
namespace Kokkos {
 
2251
 
 
2252
// Construct subview of a Rank 8 view
 
2253
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2254
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2255
        , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
2256
        , class SubArg4_type , class SubArg5_type , class SubArg6_type , class SubArg7_type
 
2257
        >
 
2258
KOKKOS_INLINE_FUNCTION
 
2259
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2260
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2261
    , const SubArg0_type & arg0
 
2262
    , const SubArg1_type & arg1
 
2263
    , const SubArg2_type & arg2
 
2264
    , const SubArg3_type & arg3
 
2265
    , const SubArg4_type & arg4
 
2266
    , const SubArg5_type & arg5
 
2267
    , const SubArg6_type & arg6
 
2268
    , const SubArg7_type & arg7
 
2269
    )
 
2270
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2271
  , m_offset_map()
 
2272
  , m_management()
 
2273
{
 
2274
  // This constructor can only be used to construct a subview
 
2275
  // from the source view.  This type must match the subview type
 
2276
  // deduced from the source view and subview arguments.
 
2277
 
 
2278
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2279
                           , SubArg0_type , SubArg1_type , SubArg2_type , SubArg3_type
 
2280
                           , SubArg4_type , SubArg5_type , SubArg6_type , SubArg7_type >
 
2281
    ViewSubviewDeduction ;
 
2282
 
 
2283
  enum { is_a_valid_subview_constructor =
 
2284
    Impl::StaticAssert<
 
2285
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2286
    >::value
 
2287
  };
 
2288
 
 
2289
  if ( is_a_valid_subview_constructor ) {
 
2290
 
 
2291
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2292
    typedef Impl::ViewOffsetRange< SubArg1_type > R1 ;
 
2293
    typedef Impl::ViewOffsetRange< SubArg2_type > R2 ;
 
2294
    typedef Impl::ViewOffsetRange< SubArg3_type > R3 ;
 
2295
    typedef Impl::ViewOffsetRange< SubArg4_type > R4 ;
 
2296
    typedef Impl::ViewOffsetRange< SubArg5_type > R5 ;
 
2297
    typedef Impl::ViewOffsetRange< SubArg6_type > R6 ;
 
2298
    typedef Impl::ViewOffsetRange< SubArg7_type > R7 ;
 
2299
 
 
2300
    // 'assign_subview' returns whether the subview offset_map
 
2301
    // introduces noncontiguity in the view.
 
2302
    const bool introduce_noncontiguity =
 
2303
      m_offset_map.assign_subview( src.m_offset_map
 
2304
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2305
                                 , R1::dimension( src.m_offset_map.N1 , arg1 )
 
2306
                                 , R2::dimension( src.m_offset_map.N2 , arg2 )
 
2307
                                 , R3::dimension( src.m_offset_map.N3 , arg3 )
 
2308
                                 , R4::dimension( src.m_offset_map.N4 , arg4 )
 
2309
                                 , R5::dimension( src.m_offset_map.N5 , arg5 )
 
2310
                                 , R6::dimension( src.m_offset_map.N6 , arg6 )
 
2311
                                 , R7::dimension( src.m_offset_map.N7 , arg7 )
 
2312
                                 );
 
2313
 
 
2314
    if ( m_offset_map.capacity() ) {
 
2315
 
 
2316
      m_management = src.m_management ;
 
2317
 
 
2318
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2319
 
 
2320
      m_ptr_on_device = src.m_ptr_on_device +
 
2321
                        src.m_offset_map( R0::begin( arg0 )
 
2322
                                        , R1::begin( arg1 )
 
2323
                                        , R2::begin( arg2 )
 
2324
                                        , R3::begin( arg3 )
 
2325
                                        , R4::begin( arg4 )
 
2326
                                        , R5::begin( arg5 )
 
2327
                                        , R6::begin( arg6 )
 
2328
                                        , R7::begin( arg7 ) );
 
2329
      m_management.increment( m_ptr_on_device );
 
2330
    }
 
2331
  }
 
2332
}
 
2333
 
 
2334
// Construct subview of a Rank 7 view
 
2335
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2336
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2337
        , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
2338
        , class SubArg4_type , class SubArg5_type , class SubArg6_type
 
2339
        >
 
2340
KOKKOS_INLINE_FUNCTION
 
2341
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2342
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2343
    , const SubArg0_type & arg0
 
2344
    , const SubArg1_type & arg1
 
2345
    , const SubArg2_type & arg2
 
2346
    , const SubArg3_type & arg3
 
2347
    , const SubArg4_type & arg4
 
2348
    , const SubArg5_type & arg5
 
2349
    , const SubArg6_type & arg6
 
2350
    )
 
2351
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2352
  , m_offset_map()
 
2353
  , m_management()
 
2354
{
 
2355
  // This constructor can only be used to construct a subview
 
2356
  // from the source view.  This type must match the subview type
 
2357
  // deduced from the source view and subview arguments.
 
2358
 
 
2359
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2360
                           , SubArg0_type , SubArg1_type , SubArg2_type , SubArg3_type
 
2361
                           , SubArg4_type , SubArg5_type , SubArg6_type , void >
 
2362
    ViewSubviewDeduction ;
 
2363
 
 
2364
  enum { is_a_valid_subview_constructor =
 
2365
    Impl::StaticAssert<
 
2366
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2367
    >::value
 
2368
  };
 
2369
 
 
2370
  if ( is_a_valid_subview_constructor ) {
 
2371
 
 
2372
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2373
    typedef Impl::ViewOffsetRange< SubArg1_type > R1 ;
 
2374
    typedef Impl::ViewOffsetRange< SubArg2_type > R2 ;
 
2375
    typedef Impl::ViewOffsetRange< SubArg3_type > R3 ;
 
2376
    typedef Impl::ViewOffsetRange< SubArg4_type > R4 ;
 
2377
    typedef Impl::ViewOffsetRange< SubArg5_type > R5 ;
 
2378
    typedef Impl::ViewOffsetRange< SubArg6_type > R6 ;
 
2379
 
 
2380
    // 'assign_subview' returns whether the subview offset_map
 
2381
    // introduces noncontiguity in the view.
 
2382
    const bool introduce_noncontiguity =
 
2383
      m_offset_map.assign_subview( src.m_offset_map
 
2384
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2385
                                 , R1::dimension( src.m_offset_map.N1 , arg1 )
 
2386
                                 , R2::dimension( src.m_offset_map.N2 , arg2 )
 
2387
                                 , R3::dimension( src.m_offset_map.N3 , arg3 )
 
2388
                                 , R4::dimension( src.m_offset_map.N4 , arg4 )
 
2389
                                 , R5::dimension( src.m_offset_map.N5 , arg5 )
 
2390
                                 , R6::dimension( src.m_offset_map.N6 , arg6 )
 
2391
                                 , 0
 
2392
                                 );
 
2393
 
 
2394
    if ( m_offset_map.capacity() ) {
 
2395
 
 
2396
      m_management = src.m_management ;
 
2397
 
 
2398
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2399
 
 
2400
      m_ptr_on_device = src.m_ptr_on_device +
 
2401
                        src.m_offset_map( R0::begin( arg0 )
 
2402
                                        , R1::begin( arg1 )
 
2403
                                        , R2::begin( arg2 )
 
2404
                                        , R3::begin( arg3 )
 
2405
                                        , R4::begin( arg4 )
 
2406
                                        , R5::begin( arg5 )
 
2407
                                        , R6::begin( arg6 )
 
2408
                                        , 0 );
 
2409
      m_management.increment( m_ptr_on_device );
 
2410
    }
 
2411
  }
 
2412
}
 
2413
 
 
2414
// Construct subview of a Rank 6 view
 
2415
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2416
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2417
        , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
2418
        , class SubArg4_type , class SubArg5_type
 
2419
        >
 
2420
KOKKOS_INLINE_FUNCTION
 
2421
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2422
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2423
    , const SubArg0_type & arg0
 
2424
    , const SubArg1_type & arg1
 
2425
    , const SubArg2_type & arg2
 
2426
    , const SubArg3_type & arg3
 
2427
    , const SubArg4_type & arg4
 
2428
    , const SubArg5_type & arg5
 
2429
    )
 
2430
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2431
  , m_offset_map()
 
2432
  , m_management()
 
2433
{
 
2434
  // This constructor can only be used to construct a subview
 
2435
  // from the source view.  This type must match the subview type
 
2436
  // deduced from the source view and subview arguments.
 
2437
 
 
2438
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2439
                           , SubArg0_type , SubArg1_type , SubArg2_type , SubArg3_type
 
2440
                           , SubArg4_type , SubArg5_type , void , void >
 
2441
    ViewSubviewDeduction ;
 
2442
 
 
2443
  enum { is_a_valid_subview_constructor =
 
2444
    Impl::StaticAssert<
 
2445
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2446
    >::value
 
2447
  };
 
2448
 
 
2449
  if ( is_a_valid_subview_constructor ) {
 
2450
 
 
2451
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2452
    typedef Impl::ViewOffsetRange< SubArg1_type > R1 ;
 
2453
    typedef Impl::ViewOffsetRange< SubArg2_type > R2 ;
 
2454
    typedef Impl::ViewOffsetRange< SubArg3_type > R3 ;
 
2455
    typedef Impl::ViewOffsetRange< SubArg4_type > R4 ;
 
2456
    typedef Impl::ViewOffsetRange< SubArg5_type > R5 ;
 
2457
 
 
2458
    // 'assign_subview' returns whether the subview offset_map
 
2459
    // introduces noncontiguity in the view.
 
2460
    const bool introduce_noncontiguity =
 
2461
      m_offset_map.assign_subview( src.m_offset_map
 
2462
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2463
                                 , R1::dimension( src.m_offset_map.N1 , arg1 )
 
2464
                                 , R2::dimension( src.m_offset_map.N2 , arg2 )
 
2465
                                 , R3::dimension( src.m_offset_map.N3 , arg3 )
 
2466
                                 , R4::dimension( src.m_offset_map.N4 , arg4 )
 
2467
                                 , R5::dimension( src.m_offset_map.N5 , arg5 )
 
2468
                                 , 0
 
2469
                                 , 0
 
2470
                                 );
 
2471
 
 
2472
    if ( m_offset_map.capacity() ) {
 
2473
 
 
2474
      m_management = src.m_management ;
 
2475
 
 
2476
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2477
 
 
2478
      m_ptr_on_device = src.m_ptr_on_device +
 
2479
                        src.m_offset_map( R0::begin( arg0 )
 
2480
                                        , R1::begin( arg1 )
 
2481
                                        , R2::begin( arg2 )
 
2482
                                        , R3::begin( arg3 )
 
2483
                                        , R4::begin( arg4 )
 
2484
                                        , R5::begin( arg5 )
 
2485
                                        , 0
 
2486
                                        , 0 );
 
2487
      m_management.increment( m_ptr_on_device );
 
2488
    }
 
2489
  }
 
2490
}
 
2491
 
 
2492
// Construct subview of a Rank 5 view
 
2493
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2494
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2495
        , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
2496
        , class SubArg4_type
 
2497
        >
 
2498
KOKKOS_INLINE_FUNCTION
 
2499
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2500
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2501
    , const SubArg0_type & arg0
 
2502
    , const SubArg1_type & arg1
 
2503
    , const SubArg2_type & arg2
 
2504
    , const SubArg3_type & arg3
 
2505
    , const SubArg4_type & arg4
 
2506
    )
 
2507
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2508
  , m_offset_map()
 
2509
  , m_management()
 
2510
{
 
2511
  // This constructor can only be used to construct a subview
 
2512
  // from the source view.  This type must match the subview type
 
2513
  // deduced from the source view and subview arguments.
 
2514
 
 
2515
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2516
                           , SubArg0_type , SubArg1_type , SubArg2_type , SubArg3_type
 
2517
                           , SubArg4_type , void , void , void >
 
2518
    ViewSubviewDeduction ;
 
2519
 
 
2520
  enum { is_a_valid_subview_constructor =
 
2521
    Impl::StaticAssert<
 
2522
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2523
    >::value
 
2524
  };
 
2525
 
 
2526
  if ( is_a_valid_subview_constructor ) {
 
2527
 
 
2528
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2529
    typedef Impl::ViewOffsetRange< SubArg1_type > R1 ;
 
2530
    typedef Impl::ViewOffsetRange< SubArg2_type > R2 ;
 
2531
    typedef Impl::ViewOffsetRange< SubArg3_type > R3 ;
 
2532
    typedef Impl::ViewOffsetRange< SubArg4_type > R4 ;
 
2533
 
 
2534
    // 'assign_subview' returns whether the subview offset_map
 
2535
    // introduces noncontiguity in the view.
 
2536
    const bool introduce_noncontiguity =
 
2537
      m_offset_map.assign_subview( src.m_offset_map
 
2538
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2539
                                 , R1::dimension( src.m_offset_map.N1 , arg1 )
 
2540
                                 , R2::dimension( src.m_offset_map.N2 , arg2 )
 
2541
                                 , R3::dimension( src.m_offset_map.N3 , arg3 )
 
2542
                                 , R4::dimension( src.m_offset_map.N4 , arg4 )
 
2543
                                 , 0
 
2544
                                 , 0
 
2545
                                 , 0
 
2546
                                 );
 
2547
 
 
2548
    if ( m_offset_map.capacity() ) {
 
2549
 
 
2550
      m_management = src.m_management ;
 
2551
 
 
2552
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2553
 
 
2554
      m_ptr_on_device = src.m_ptr_on_device +
 
2555
                        src.m_offset_map( R0::begin( arg0 )
 
2556
                                        , R1::begin( arg1 )
 
2557
                                        , R2::begin( arg2 )
 
2558
                                        , R3::begin( arg3 )
 
2559
                                        , R4::begin( arg4 )
 
2560
                                        , 0
 
2561
                                        , 0
 
2562
                                        , 0 );
 
2563
      m_management.increment( m_ptr_on_device );
 
2564
    }
 
2565
  }
 
2566
}
 
2567
 
 
2568
// Construct subview of a Rank 4 view
 
2569
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2570
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2571
        , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
2572
        >
 
2573
KOKKOS_INLINE_FUNCTION
 
2574
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2575
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2576
    , const SubArg0_type & arg0
 
2577
    , const SubArg1_type & arg1
 
2578
    , const SubArg2_type & arg2
 
2579
    , const SubArg3_type & arg3
 
2580
    )
 
2581
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2582
  , m_offset_map()
 
2583
  , m_management()
 
2584
{
 
2585
  // This constructor can only be used to construct a subview
 
2586
  // from the source view.  This type must match the subview type
 
2587
  // deduced from the source view and subview arguments.
 
2588
 
 
2589
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2590
                           , SubArg0_type , SubArg1_type , SubArg2_type , SubArg3_type
 
2591
                           , void , void , void , void >
 
2592
    ViewSubviewDeduction ;
 
2593
 
 
2594
  enum { is_a_valid_subview_constructor =
 
2595
    Impl::StaticAssert<
 
2596
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2597
    >::value
 
2598
  };
 
2599
 
 
2600
  if ( is_a_valid_subview_constructor ) {
 
2601
 
 
2602
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2603
    typedef Impl::ViewOffsetRange< SubArg1_type > R1 ;
 
2604
    typedef Impl::ViewOffsetRange< SubArg2_type > R2 ;
 
2605
    typedef Impl::ViewOffsetRange< SubArg3_type > R3 ;
 
2606
 
 
2607
    // 'assign_subview' returns whether the subview offset_map
 
2608
    // introduces noncontiguity in the view.
 
2609
    const bool introduce_noncontiguity =
 
2610
      m_offset_map.assign_subview( src.m_offset_map
 
2611
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2612
                                 , R1::dimension( src.m_offset_map.N1 , arg1 )
 
2613
                                 , R2::dimension( src.m_offset_map.N2 , arg2 )
 
2614
                                 , R3::dimension( src.m_offset_map.N3 , arg3 )
 
2615
                                 , 0
 
2616
                                 , 0
 
2617
                                 , 0
 
2618
                                 , 0
 
2619
                                 );
 
2620
 
 
2621
    if ( m_offset_map.capacity() ) {
 
2622
 
 
2623
      m_management = src.m_management ;
 
2624
 
 
2625
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2626
 
 
2627
      m_ptr_on_device = src.m_ptr_on_device +
 
2628
                        src.m_offset_map( R0::begin( arg0 )
 
2629
                                        , R1::begin( arg1 )
 
2630
                                        , R2::begin( arg2 )
 
2631
                                        , R3::begin( arg3 )
 
2632
                                        , 0
 
2633
                                        , 0
 
2634
                                        , 0
 
2635
                                        , 0 );
 
2636
      m_management.increment( m_ptr_on_device );
 
2637
    }
 
2638
  }
 
2639
}
 
2640
 
 
2641
// Construct subview of a Rank 3 view
 
2642
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2643
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2644
        , class SubArg0_type , class SubArg1_type , class SubArg2_type
 
2645
        >
 
2646
KOKKOS_INLINE_FUNCTION
 
2647
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2648
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2649
    , const SubArg0_type & arg0
 
2650
    , const SubArg1_type & arg1
 
2651
    , const SubArg2_type & arg2
 
2652
    )
 
2653
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2654
  , m_offset_map()
 
2655
  , m_management()
 
2656
{
 
2657
  // This constructor can only be used to construct a subview
 
2658
  // from the source view.  This type must match the subview type
 
2659
  // deduced from the source view and subview arguments.
 
2660
 
 
2661
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2662
                           , SubArg0_type , SubArg1_type , SubArg2_type , void , void , void , void , void >
 
2663
    ViewSubviewDeduction ;
 
2664
 
 
2665
  enum { is_a_valid_subview_constructor =
 
2666
    Impl::StaticAssert<
 
2667
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2668
    >::value
 
2669
  };
 
2670
 
 
2671
  if ( is_a_valid_subview_constructor ) {
 
2672
 
 
2673
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2674
    typedef Impl::ViewOffsetRange< SubArg1_type > R1 ;
 
2675
    typedef Impl::ViewOffsetRange< SubArg2_type > R2 ;
 
2676
 
 
2677
    // 'assign_subview' returns whether the subview offset_map
 
2678
    // introduces noncontiguity in the view.
 
2679
    const bool introduce_noncontiguity =
 
2680
      m_offset_map.assign_subview( src.m_offset_map
 
2681
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2682
                                 , R1::dimension( src.m_offset_map.N1 , arg1 )
 
2683
                                 , R2::dimension( src.m_offset_map.N2 , arg2 )
 
2684
                                 , 0 , 0 , 0 , 0 , 0);
 
2685
 
 
2686
    if ( m_offset_map.capacity() ) {
 
2687
 
 
2688
      m_management = src.m_management ;
 
2689
 
 
2690
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2691
 
 
2692
      m_ptr_on_device = src.m_ptr_on_device +
 
2693
                        src.m_offset_map( R0::begin( arg0 )
 
2694
                                        , R1::begin( arg1 )
 
2695
                                        , R2::begin( arg2 )
 
2696
                                        , 0 , 0 , 0 , 0 , 0 );
 
2697
      m_management.increment( m_ptr_on_device );
 
2698
    }
 
2699
  }
 
2700
}
 
2701
 
 
2702
// Construct subview of a Rank 2 view
 
2703
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2704
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2705
        , class SubArg0_type , class SubArg1_type
 
2706
        >
 
2707
KOKKOS_INLINE_FUNCTION
 
2708
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2709
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2710
    , const SubArg0_type & arg0
 
2711
    , const SubArg1_type & arg1
 
2712
    )
 
2713
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2714
  , m_offset_map()
 
2715
  , m_management()
 
2716
{
 
2717
  // This constructor can only be used to construct a subview
 
2718
  // from the source view.  This type must match the subview type
 
2719
  // deduced from the source view and subview arguments.
 
2720
 
 
2721
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2722
                           , SubArg0_type , SubArg1_type , void , void , void , void , void , void >
 
2723
    ViewSubviewDeduction ;
 
2724
 
 
2725
  enum { is_a_valid_subview_constructor =
 
2726
    Impl::StaticAssert<
 
2727
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2728
    >::value
 
2729
  };
 
2730
 
 
2731
  if ( is_a_valid_subview_constructor ) {
 
2732
 
 
2733
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2734
    typedef Impl::ViewOffsetRange< SubArg1_type > R1 ;
 
2735
 
 
2736
    // 'assign_subview' returns whether the subview offset_map
 
2737
    // introduces noncontiguity in the view.
 
2738
    const bool introduce_noncontiguity =
 
2739
      m_offset_map.assign_subview( src.m_offset_map
 
2740
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2741
                                 , R1::dimension( src.m_offset_map.N1 , arg1 )
 
2742
                                 , 0 , 0 , 0 , 0 , 0 , 0 );
 
2743
 
 
2744
    if ( m_offset_map.capacity() ) {
 
2745
 
 
2746
      m_management = src.m_management ;
 
2747
 
 
2748
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2749
 
 
2750
      m_ptr_on_device = src.m_ptr_on_device +
 
2751
                        src.m_offset_map( R0::begin( arg0 )
 
2752
                                        , R1::begin( arg1 )
 
2753
                                        , 0 , 0 , 0 , 0 , 0 , 0 );
 
2754
      m_management.increment( m_ptr_on_device );
 
2755
    }
 
2756
  }
 
2757
}
 
2758
 
 
2759
// Construct subview of a Rank 1 view
 
2760
template< class DstDataType , class DstArg1Type , class DstArg2Type , class DstArg3Type >
 
2761
template< class SrcDataType , class SrcArg1Type , class SrcArg2Type , class SrcArg3Type
 
2762
        , class SubArg0_type
 
2763
        >
 
2764
KOKKOS_INLINE_FUNCTION
 
2765
View< DstDataType , DstArg1Type , DstArg2Type , DstArg3Type , Impl::ViewDefault >::
 
2766
View( const View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault > & src
 
2767
    , const SubArg0_type & arg0
 
2768
    )
 
2769
  : m_ptr_on_device( (typename traits::value_type*) NULL)
 
2770
  , m_offset_map()
 
2771
  , m_management()
 
2772
{
 
2773
  // This constructor can only be used to construct a subview
 
2774
  // from the source view.  This type must match the subview type
 
2775
  // deduced from the source view and subview arguments.
 
2776
 
 
2777
  typedef Impl::ViewSubview< View< SrcDataType , SrcArg1Type , SrcArg2Type , SrcArg3Type , Impl::ViewDefault >
 
2778
                           , SubArg0_type , void , void , void , void , void , void , void >
 
2779
    ViewSubviewDeduction ;
 
2780
 
 
2781
  enum { is_a_valid_subview_constructor =
 
2782
    Impl::StaticAssert<
 
2783
      Impl::is_same< View , typename ViewSubviewDeduction::type >::value
 
2784
    >::value
 
2785
  };
 
2786
 
 
2787
  if ( is_a_valid_subview_constructor ) {
 
2788
 
 
2789
    typedef Impl::ViewOffsetRange< SubArg0_type > R0 ;
 
2790
 
 
2791
    // 'assign_subview' returns whether the subview offset_map
 
2792
    // introduces noncontiguity in the view.
 
2793
    const bool introduce_noncontiguity =
 
2794
      m_offset_map.assign_subview( src.m_offset_map
 
2795
                                 , R0::dimension( src.m_offset_map.N0 , arg0 )
 
2796
                                 , 0 , 0 , 0 , 0 , 0 , 0 , 0 );
 
2797
 
 
2798
    if ( m_offset_map.capacity() ) {
 
2799
 
 
2800
      m_management = src.m_management ;
 
2801
 
 
2802
      if ( introduce_noncontiguity ) m_management.set_noncontiguous();
 
2803
 
 
2804
      m_ptr_on_device = src.m_ptr_on_device +
 
2805
                        src.m_offset_map( R0::begin( arg0 )
 
2806
                                        , 0 , 0 , 0 , 0 , 0 , 0 , 0 );
 
2807
      m_management.increment( m_ptr_on_device );
 
2808
    }
 
2809
  }
 
2810
}
 
2811
 
 
2812
} /* namespace Kokkos */
 
2813
 
 
2814
//----------------------------------------------------------------------------
 
2815
//----------------------------------------------------------------------------
 
2816
 
 
2817
#endif /* #ifndef KOKKOS_VIEWDEFAULT_HPP */
 
2818