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

« back to all changes in this revision

Viewing changes to lib/kokkos/core/src/Kokkos_View.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_VIEW_HPP
 
45
#define KOKKOS_VIEW_HPP
 
46
 
 
47
#include <string>
 
48
#include <Kokkos_Core_fwd.hpp>
 
49
#include <Kokkos_HostSpace.hpp>
 
50
#include <Kokkos_MemoryTraits.hpp>
 
51
 
 
52
#include <impl/Kokkos_StaticAssert.hpp>
 
53
#include <impl/Kokkos_Traits.hpp>
 
54
#include <impl/Kokkos_Shape.hpp>
 
55
#include <impl/Kokkos_AnalyzeShape.hpp>
 
56
#include <impl/Kokkos_ViewOffset.hpp>
 
57
#include <impl/Kokkos_ViewSupport.hpp>
 
58
#include <impl/Kokkos_Tags.hpp>
 
59
 
 
60
//----------------------------------------------------------------------------
 
61
//----------------------------------------------------------------------------
 
62
 
 
63
namespace Kokkos {
 
64
namespace Impl {
 
65
 
 
66
/** \brief  View specialization mapping of view traits to a specialization tag */
 
67
template< class ValueType ,
 
68
          class ArraySpecialize ,
 
69
          class ArrayLayout ,
 
70
          class MemorySpace ,
 
71
          class MemoryTraits >
 
72
struct ViewSpecialize ;
 
73
 
 
74
/** \brief  Defines the type of a subview given a source view type
 
75
 *          and subview argument types.
 
76
 */
 
77
template< class SrcViewType
 
78
        , class Arg0Type
 
79
        , class Arg1Type
 
80
        , class Arg2Type
 
81
        , class Arg3Type
 
82
        , class Arg4Type
 
83
        , class Arg5Type
 
84
        , class Arg6Type
 
85
        , class Arg7Type
 
86
        >
 
87
struct ViewSubview /* { typedef ... type ; } */ ;
 
88
 
 
89
template< class DstViewSpecialize ,
 
90
          class SrcViewSpecialize = void ,
 
91
          class Enable = void >
 
92
struct ViewAssignment ;
 
93
 
 
94
template< class DstMemorySpace , class SrcMemorySpace >
 
95
struct DeepCopy ;
 
96
 
 
97
} /* namespace Impl */
 
98
} // namespace Kokkos
 
99
 
 
100
//----------------------------------------------------------------------------
 
101
//----------------------------------------------------------------------------
 
102
 
 
103
namespace Kokkos {
 
104
 
 
105
/** \class ViewTraits
 
106
 *  \brief Traits class for accessing attributes of a View.
 
107
 *
 
108
 * This is an implementation detail of View.  It is only of interest
 
109
 * to developers implementing a new specialization of View.
 
110
 *
 
111
 * Template argument permutations:
 
112
 *   - View< DataType , void         , void         , void >
 
113
 *   - View< DataType , Space        , void         , void >
 
114
 *   - View< DataType , Space        , MemoryTraits , void >
 
115
 *   - View< DataType , Space        , void         , MemoryTraits >
 
116
 *   - View< DataType , ArrayLayout  , void         , void >
 
117
 *   - View< DataType , ArrayLayout  , Space        , void >
 
118
 *   - View< DataType , ArrayLayout  , MemoryTraits , void   >
 
119
 *   - View< DataType , ArrayLayout  , Space        , MemoryTraits >
 
120
 *   - View< DataType , MemoryTraits , void         , void  >
 
121
 */
 
122
 
 
123
template< class DataType ,
 
124
          class Arg1 = void ,
 
125
          class Arg2 = void ,
 
126
          class Arg3 = void >
 
127
class ViewTraits {
 
128
private:
 
129
 
 
130
  // Layout, Space, and MemoryTraits are optional
 
131
  // but need to appear in that order. That means Layout
 
132
  // can only be Arg1, Space can be Arg1 or Arg2, and
 
133
  // MemoryTraits can be Arg1, Arg2 or Arg3
 
134
 
 
135
  enum { Arg1IsLayout = Impl::is_array_layout<Arg1>::value };
 
136
 
 
137
  enum { Arg1IsSpace = Impl::is_space<Arg1>::value };
 
138
  enum { Arg2IsSpace = Impl::is_space<Arg2>::value };
 
139
 
 
140
  enum { Arg1IsMemoryTraits = Impl::is_memory_traits<Arg1>::value };
 
141
  enum { Arg2IsMemoryTraits = Impl::is_memory_traits<Arg2>::value };
 
142
  enum { Arg3IsMemoryTraits = Impl::is_memory_traits<Arg3>::value };
 
143
 
 
144
  enum { Arg1IsVoid = Impl::is_same< Arg1 , void >::value };
 
145
  enum { Arg2IsVoid = Impl::is_same< Arg2 , void >::value };
 
146
  enum { Arg3IsVoid = Impl::is_same< Arg3 , void >::value };
 
147
 
 
148
  // Arg1 is Layout, Space, MemoryTraits, or void
 
149
  typedef typename
 
150
    Impl::StaticAssert<
 
151
      ( 1 == Arg1IsLayout + Arg1IsSpace + Arg1IsMemoryTraits + Arg1IsVoid )
 
152
      , Arg1 >::type Arg1Verified ;
 
153
 
 
154
  // If Arg1 is Layout       then Arg2 is Space, MemoryTraits, or void
 
155
  // If Arg1 is Space        then Arg2 is MemoryTraits or void
 
156
  // If Arg1 is MemoryTraits then Arg2 is void
 
157
  // If Arg1 is Void         then Arg2 is void
 
158
  typedef typename
 
159
    Impl::StaticAssert<
 
160
      ( Arg1IsLayout       && ( 1 == Arg2IsSpace + Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
 
161
      ( Arg1IsSpace        && ( 0 == Arg2IsSpace ) && ( 1 == Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
 
162
      ( Arg1IsMemoryTraits && Arg2IsVoid ) ||
 
163
      ( Arg1IsVoid         && Arg2IsVoid )
 
164
      , Arg2 >::type Arg2Verified ;
 
165
 
 
166
  // Arg3 is MemoryTraits or void and at most one argument is MemoryTraits
 
167
  typedef typename
 
168
    Impl::StaticAssert<
 
169
      ( 1 == Arg3IsMemoryTraits + Arg3IsVoid ) &&
 
170
      ( Arg1IsMemoryTraits + Arg2IsMemoryTraits + Arg3IsMemoryTraits <= 1 )
 
171
      , Arg3 >::type Arg3Verified ;
 
172
 
 
173
  // Arg1 or Arg2 may have execution and memory spaces
 
174
  typedef typename Impl::if_c<( Arg1IsSpace ), Arg1Verified ,
 
175
          typename Impl::if_c<( Arg2IsSpace ), Arg2Verified ,
 
176
          Kokkos::DefaultExecutionSpace
 
177
          >::type >::type::execution_space  ExecutionSpace ;
 
178
 
 
179
  typedef typename Impl::if_c<( Arg1IsSpace ), Arg1Verified ,
 
180
          typename Impl::if_c<( Arg2IsSpace ), Arg2Verified ,
 
181
          Kokkos::DefaultExecutionSpace
 
182
          >::type >::type::memory_space  MemorySpace ;
 
183
 
 
184
  typedef typename Impl::is_space<
 
185
    typename Impl::if_c<( Arg1IsSpace ), Arg1Verified ,
 
186
    typename Impl::if_c<( Arg2IsSpace ), Arg2Verified ,
 
187
    Kokkos::DefaultExecutionSpace
 
188
    >::type >::type >::host_mirror_space  HostMirrorSpace ;
 
189
 
 
190
  // Arg1 may be array layout
 
191
  typedef typename Impl::if_c< Arg1IsLayout , Arg1Verified ,
 
192
          typename ExecutionSpace::array_layout
 
193
          >::type ArrayLayout ;
 
194
 
 
195
  // Arg1, Arg2, or Arg3 may be memory traits
 
196
  typedef typename Impl::if_c< Arg1IsMemoryTraits , Arg1Verified ,
 
197
          typename Impl::if_c< Arg2IsMemoryTraits , Arg2Verified ,
 
198
          typename Impl::if_c< Arg3IsMemoryTraits , Arg3Verified ,
 
199
          MemoryManaged
 
200
          >::type >::type >::type  MemoryTraits ;
 
201
 
 
202
  typedef Impl::AnalyzeShape<DataType> analysis ;
 
203
 
 
204
public:
 
205
 
 
206
  //------------------------------------
 
207
  // Data type traits:
 
208
 
 
209
  typedef DataType                            data_type ;
 
210
  typedef typename analysis::const_type       const_data_type ;
 
211
  typedef typename analysis::non_const_type   non_const_data_type ;
 
212
 
 
213
  //------------------------------------
 
214
  // Array of intrinsic scalar type traits:
 
215
 
 
216
  typedef typename analysis::array_intrinsic_type            array_intrinsic_type ;
 
217
  typedef typename analysis::const_array_intrinsic_type      const_array_intrinsic_type ;
 
218
  typedef typename analysis::non_const_array_intrinsic_type  non_const_array_intrinsic_type ;
 
219
 
 
220
  //------------------------------------
 
221
  // Value type traits:
 
222
 
 
223
  typedef typename analysis::value_type            value_type ;
 
224
  typedef typename analysis::const_value_type      const_value_type ;
 
225
  typedef typename analysis::non_const_value_type  non_const_value_type ;
 
226
 
 
227
  //------------------------------------
 
228
  // Layout and shape traits:
 
229
 
 
230
  typedef ArrayLayout                array_layout ;
 
231
  typedef typename analysis::shape   shape_type ;
 
232
 
 
233
  enum { rank         = shape_type::rank };
 
234
  enum { rank_dynamic = shape_type::rank_dynamic };
 
235
 
 
236
  //------------------------------------
 
237
  // Execution space, memory space, memory access traits, and host mirror space.
 
238
 
 
239
  typedef ExecutionSpace   execution_space ;
 
240
  typedef MemorySpace      memory_space ;
 
241
  typedef MemoryTraits     memory_traits ;
 
242
  typedef HostMirrorSpace  host_mirror_space ;
 
243
 
 
244
  typedef typename memory_space::size_type  size_type ;
 
245
 
 
246
  enum { is_hostspace      = Impl::is_same< memory_space , HostSpace >::value };
 
247
  enum { is_managed        = memory_traits::Unmanaged == 0 };
 
248
  enum { is_random_access  = memory_traits::RandomAccess == 1 };
 
249
 
 
250
  //------------------------------------
 
251
 
 
252
  typedef ExecutionSpace  device_type ; // for backward compatibility, to be removed
 
253
 
 
254
  //------------------------------------
 
255
  // Specialization tag:
 
256
 
 
257
  typedef typename
 
258
    Impl::ViewSpecialize< value_type
 
259
                        , typename analysis::specialize
 
260
                        , array_layout
 
261
                        , memory_space
 
262
                        , memory_traits
 
263
                        >::type specialize ;
 
264
};
 
265
 
 
266
} /* namespace Kokkos */
 
267
 
 
268
//----------------------------------------------------------------------------
 
269
//----------------------------------------------------------------------------
 
270
 
 
271
namespace Kokkos {
 
272
namespace Impl {
 
273
 
 
274
class ViewDefault {};
 
275
 
 
276
/** \brief  Default view specialization has LayoutLeft, LayoutRight, or LayoutStride.
 
277
 */
 
278
template< class ValueType , class MemorySpace , class MemoryTraits >
 
279
struct ViewSpecialize< ValueType , void , LayoutLeft , MemorySpace , MemoryTraits >
 
280
{ typedef ViewDefault type ; };
 
281
 
 
282
template< class ValueType , class MemorySpace , class MemoryTraits >
 
283
struct ViewSpecialize< ValueType , void , LayoutRight , MemorySpace , MemoryTraits >
 
284
{ typedef ViewDefault type ; };
 
285
 
 
286
template< class ValueType , class MemorySpace , class MemoryTraits >
 
287
struct ViewSpecialize< ValueType , void , LayoutStride , MemorySpace , MemoryTraits >
 
288
{ typedef ViewDefault type ; };
 
289
 
 
290
} /* namespace Impl */
 
291
} /* namespace Kokkos */
 
292
 
 
293
//----------------------------------------------------------------------------
 
294
//----------------------------------------------------------------------------
 
295
 
 
296
namespace Kokkos {
 
297
namespace Impl {
 
298
 
 
299
/** \brief Types for compile-time detection of View usage errors */
 
300
namespace ViewError {
 
301
 
 
302
struct allocation_constructor_requires_managed {};
 
303
struct allocation_constructor_requires_nonconst {};
 
304
struct user_pointer_constructor_requires_unmanaged {};
 
305
struct device_shmem_constructor_requires_unmanaged {};
 
306
 
 
307
struct scalar_operator_called_from_non_scalar_view {};
 
308
 
 
309
} /* namespace ViewError */
 
310
 
 
311
//----------------------------------------------------------------------------
 
312
/** \brief  Enable view parentheses operator for
 
313
 *          match of layout and integral arguments.
 
314
 *          If correct rank define type from traits,
 
315
 *          otherwise define type as an error message.
 
316
 */
 
317
template< class ReturnType , class Traits , class Layout , unsigned Rank ,
 
318
          typename iType0 = int , typename iType1 = int ,
 
319
          typename iType2 = int , typename iType3 = int ,
 
320
          typename iType4 = int , typename iType5 = int ,
 
321
          typename iType6 = int , typename iType7 = int ,
 
322
          class Enable = void >
 
323
struct ViewEnableArrayOper ;
 
324
 
 
325
template< class ReturnType , class Traits , class Layout , unsigned Rank ,
 
326
          typename iType0 , typename iType1 ,
 
327
          typename iType2 , typename iType3 ,
 
328
          typename iType4 , typename iType5 ,
 
329
          typename iType6 , typename iType7 >
 
330
struct ViewEnableArrayOper<
 
331
   ReturnType , Traits , Layout , Rank ,
 
332
   iType0 , iType1 , iType2 , iType3 ,
 
333
   iType4 , iType5 , iType6 , iType7 ,
 
334
   typename enable_if<
 
335
     iType0(0) == 0 && iType1(0) == 0 && iType2(0) == 0 && iType3(0) == 0 &&
 
336
     iType4(0) == 0 && iType5(0) == 0 && iType6(0) == 0 && iType7(0) == 0 &&
 
337
     is_same< typename Traits::array_layout , Layout >::value &&
 
338
     ( unsigned(Traits::rank) == Rank )
 
339
   >::type >
 
340
{
 
341
  typedef ReturnType type ;
 
342
};
 
343
 
 
344
} /* namespace Impl */
 
345
} /* namespace Kokkos */
 
346
 
 
347
//----------------------------------------------------------------------------
 
348
//----------------------------------------------------------------------------
 
349
 
 
350
namespace Kokkos {
 
351
 
 
352
/** \class View
 
353
 *  \brief View to an array of data.
 
354
 *
 
355
 * A View represents an array of one or more dimensions.
 
356
 * For details, please refer to Kokkos' tutorial materials.
 
357
 *
 
358
 * \section Kokkos_View_TemplateParameters Template parameters
 
359
 *
 
360
 * This class has both required and optional template parameters.  The
 
361
 * \c DataType parameter must always be provided, and must always be
 
362
 * first. The parameters \c Arg1Type, \c Arg2Type, and \c Arg3Type are
 
363
 * placeholders for different template parameters.  The default value
 
364
 * of the fifth template parameter \c Specialize suffices for most use
 
365
 * cases.  When explaining the template parameters, we won't refer to
 
366
 * \c Arg1Type, \c Arg2Type, and \c Arg3Type; instead, we will refer
 
367
 * to the valid categories of template parameters, in whatever order
 
368
 * they may occur.
 
369
 *
 
370
 * Valid ways in which template arguments may be specified:
 
371
 *   - View< DataType , Space >
 
372
 *   - View< DataType , Space  ,         MemoryTraits >
 
373
 *   - View< DataType , Space  , void  , MemoryTraits >
 
374
 *   - View< DataType , Layout , Space >
 
375
 *   - View< DataType , Layout , Space , MemoryTraits >
 
376
 *
 
377
 * \tparam DataType (required) This indicates both the type of each
 
378
 *   entry of the array, and the combination of compile-time and
 
379
 *   run-time array dimension(s).  For example, <tt>double*</tt>
 
380
 *   indicates a one-dimensional array of \c double with run-time
 
381
 *   dimension, and <tt>int*[3]</tt> a two-dimensional array of \c int
 
382
 *   with run-time first dimension and compile-time second dimension
 
383
 *   (of 3).  In general, the run-time dimensions (if any) must go
 
384
 *   first, followed by zero or more compile-time dimensions.  For
 
385
 *   more examples, please refer to the tutorial materials.
 
386
 *
 
387
 * \tparam Space (required) The memory space.
 
388
 *
 
389
 * \tparam Layout (optional) The array's layout in memory.  For
 
390
 *   example, LayoutLeft indicates a column-major (Fortran style)
 
391
 *   layout, and LayoutRight a row-major (C style) layout.  If not
 
392
 *   specified, this defaults to the preferred layout for the
 
393
 *   <tt>Space</tt>.
 
394
 *
 
395
 * \tparam MemoryTraits (optional) Assertion of the user's intended
 
396
 *   access behavior.  For example, RandomAccess indicates read-only
 
397
 *   access with limited spatial locality, and Unmanaged lets users
 
398
 *   wrap externally allocated memory in a View without automatic
 
399
 *   deallocation.
 
400
 *
 
401
 * \section Kokkos_View_MT MemoryTraits discussion
 
402
 *
 
403
 * \subsection Kokkos_View_MT_Interp MemoryTraits interpretation depends on Space
 
404
 *
 
405
 * Some \c MemoryTraits options may have different interpretations for
 
406
 * different \c Space types.  For example, with the Cuda device,
 
407
 * \c RandomAccess tells Kokkos to fetch the data through the texture
 
408
 * cache, whereas the non-GPU devices have no such hardware construct.
 
409
 *
 
410
 * \subsection Kokkos_View_MT_PrefUse Preferred use of MemoryTraits
 
411
 *
 
412
 * Users should defer applying the optional \c MemoryTraits parameter
 
413
 * until the point at which they actually plan to rely on it in a
 
414
 * computational kernel.  This minimizes the number of template
 
415
 * parameters exposed in their code, which reduces the cost of
 
416
 * compilation.  Users may always assign a View without specified
 
417
 * \c MemoryTraits to a compatible View with that specification.
 
418
 * For example:
 
419
 * \code
 
420
 * // Pass in the simplest types of View possible.
 
421
 * void
 
422
 * doSomething (View<double*, Cuda> out,
 
423
 *              View<const double*, Cuda> in)
 
424
 * {
 
425
 *   // Assign the "generic" View in to a RandomAccess View in_rr.
 
426
 *   // Note that RandomAccess View objects must have const data.
 
427
 *   View<const double*, Cuda, RandomAccess> in_rr = in;
 
428
 *   // ... do something with in_rr and out ...
 
429
 * }
 
430
 * \endcode
 
431
 */
 
432
template< class DataType ,
 
433
          class Arg1Type = void , /* ArrayLayout, SpaceType, or MemoryTraits */
 
434
          class Arg2Type = void , /* SpaceType or MemoryTraits */
 
435
          class Arg3Type = void , /* MemoryTraits */
 
436
          class Specialize =
 
437
            typename ViewTraits<DataType,Arg1Type,Arg2Type,Arg3Type>::specialize >
 
438
class View ;
 
439
 
 
440
namespace Impl {
 
441
 
 
442
template< class C >
 
443
struct is_view : public bool_< false > {};
 
444
 
 
445
template< class D , class A1 , class A2 , class A3 , class S >
 
446
struct is_view< View< D , A1 , A2 , A3 , S > > : public bool_< true > {};
 
447
 
 
448
}
 
449
 
 
450
//----------------------------------------------------------------------------
 
451
 
 
452
template< class DataType ,
 
453
          class Arg1Type ,
 
454
          class Arg2Type ,
 
455
          class Arg3Type >
 
456
class View< DataType , Arg1Type , Arg2Type , Arg3Type , Impl::ViewDefault >
 
457
  : public ViewTraits< DataType , Arg1Type , Arg2Type, Arg3Type >
 
458
{
 
459
public:
 
460
 
 
461
  typedef ViewTraits< DataType , Arg1Type , Arg2Type, Arg3Type > traits ;
 
462
 
 
463
private:
 
464
 
 
465
  // Assignment of compatible views requirement:
 
466
  template< class , class , class , class , class > friend class View ;
 
467
 
 
468
  // Assignment of compatible subview requirement:
 
469
  template< class , class , class > friend struct Impl::ViewAssignment ;
 
470
 
 
471
  // Dimensions, cardinality, capacity, and offset computation for
 
472
  // multidimensional array view of contiguous memory.
 
473
  // Inherits from Impl::Shape
 
474
  typedef Impl::ViewOffset< typename traits::shape_type
 
475
                          , typename traits::array_layout
 
476
                          > offset_map_type ;
 
477
 
 
478
  // Intermediary class for data management and access
 
479
  typedef Impl::ViewDataManagement< traits > view_data_management ;
 
480
 
 
481
  //----------------------------------------
 
482
  // Data members:
 
483
 
 
484
  typename view_data_management::handle_type  m_ptr_on_device ;
 
485
  offset_map_type                             m_offset_map ;
 
486
  view_data_management                        m_management ;
 
487
 
 
488
  //----------------------------------------
 
489
 
 
490
public:
 
491
 
 
492
  /** return type for all indexing operators */
 
493
  typedef typename view_data_management::return_type reference_type ;
 
494
 
 
495
  typedef View< typename traits::array_intrinsic_type ,
 
496
                typename traits::array_layout ,
 
497
                typename traits::execution_space ,
 
498
                typename traits::memory_traits > array_type ;
 
499
 
 
500
  typedef View< typename traits::const_data_type ,
 
501
                typename traits::array_layout ,
 
502
                typename traits::execution_space ,
 
503
                typename traits::memory_traits > const_type ;
 
504
 
 
505
  typedef View< typename traits::non_const_data_type ,
 
506
                typename traits::array_layout ,
 
507
                typename traits::execution_space ,
 
508
                typename traits::memory_traits > non_const_type ;
 
509
 
 
510
  typedef View< typename traits::non_const_data_type ,
 
511
                typename traits::array_layout ,
 
512
                typename traits::host_mirror_space ,
 
513
                void > HostMirror ;
 
514
 
 
515
  //------------------------------------
 
516
  // Shape
 
517
 
 
518
  enum { Rank = traits::rank };
 
519
 
 
520
  KOKKOS_INLINE_FUNCTION offset_map_type shape() const { return m_offset_map ; }
 
521
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_0() const { return m_offset_map.N0 ; }
 
522
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_1() const { return m_offset_map.N1 ; }
 
523
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_2() const { return m_offset_map.N2 ; }
 
524
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_3() const { return m_offset_map.N3 ; }
 
525
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_4() const { return m_offset_map.N4 ; }
 
526
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_5() const { return m_offset_map.N5 ; }
 
527
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_6() const { return m_offset_map.N6 ; }
 
528
  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_7() const { return m_offset_map.N7 ; }
 
529
  KOKKOS_INLINE_FUNCTION typename traits::size_type size() const { return m_offset_map.cardinality(); }
 
530
 
 
531
  template< typename iType >
 
532
  KOKKOS_INLINE_FUNCTION
 
533
  typename traits::size_type dimension( const iType & i ) const
 
534
    { return Impl::dimension( m_offset_map , i ); }
 
535
 
 
536
  //------------------------------------
 
537
  // Destructor, constructors, assignment operators:
 
538
 
 
539
  KOKKOS_INLINE_FUNCTION
 
540
  ~View()
 
541
    { m_management.decrement( m_ptr_on_device ); }
 
542
 
 
543
  KOKKOS_INLINE_FUNCTION
 
544
  View()
 
545
    : m_ptr_on_device((typename traits::value_type*) NULL)
 
546
    , m_offset_map()
 
547
    , m_management()
 
548
    { m_offset_map.assign(0, 0,0,0,0,0,0,0,0); }
 
549
 
 
550
  KOKKOS_INLINE_FUNCTION
 
551
  View( const View & rhs )
 
552
    : m_ptr_on_device((typename traits::value_type*) NULL)
 
553
    , m_offset_map()
 
554
    , m_management()
 
555
    {
 
556
      (void) Impl::ViewAssignment<
 
557
         typename traits::specialize ,
 
558
         typename traits::specialize >( *this , rhs );
 
559
    }
 
560
 
 
561
  KOKKOS_INLINE_FUNCTION
 
562
  View & operator = ( const View & rhs )
 
563
    {
 
564
      (void) Impl::ViewAssignment<
 
565
         typename traits::specialize ,
 
566
         typename traits::specialize >( *this , rhs );
 
567
      return *this ;
 
568
    }
 
569
 
 
570
  //------------------------------------
 
571
  // Construct or assign compatible view:
 
572
 
 
573
  template< class RT , class RL , class RD , class RM , class RS >
 
574
  KOKKOS_INLINE_FUNCTION
 
575
  View( const View<RT,RL,RD,RM,RS> & rhs )
 
576
    : m_ptr_on_device((typename traits::value_type*) NULL)
 
577
    , m_offset_map()
 
578
    , m_management()
 
579
    {
 
580
      (void) Impl::ViewAssignment<
 
581
         typename traits::specialize , RS >( *this , rhs );
 
582
    }
 
583
 
 
584
  template< class RT , class RL , class RD , class RM , class RS >
 
585
  KOKKOS_INLINE_FUNCTION
 
586
  View & operator = ( const View<RT,RL,RD,RM,RS> & rhs )
 
587
    {
 
588
      (void) Impl::ViewAssignment<
 
589
         typename traits::specialize , RS >( *this , rhs );
 
590
      return *this ;
 
591
    }
 
592
 
 
593
  //------------------------------------
 
594
  /**\brief Allocation of a managed view with possible alignment padding.
 
595
   *
 
596
   *  Allocation properties for allocating and initializing to the default value_type:
 
597
   *    Kokkos::ViewAllocate()
 
598
   *    Kokkos::ViewAllocate("label")  OR  "label"
 
599
   *    Kokkos::ViewAllocate(std::string("label"))  OR  std::string("label")
 
600
   *
 
601
   *  Allocation properties for allocating and bypassing initialization:
 
602
   *    Kokkos::ViewAllocateWithoutInitializing()
 
603
   *    Kokkos::ViewAllocateWithoutInitializing("label")
 
604
   */
 
605
 
 
606
  template< class AllocationProperties >
 
607
  explicit inline
 
608
  View( const AllocationProperties & prop ,
 
609
        // Impl::ViewAllocProp::size_type exists when the traits and allocation properties
 
610
        // are valid for allocating viewed memory.
 
611
        const typename Impl::ViewAllocProp< traits , AllocationProperties >::size_type n0 = 0 ,
 
612
        const size_t n1 = 0 ,
 
613
        const size_t n2 = 0 ,
 
614
        const size_t n3 = 0 ,
 
615
        const size_t n4 = 0 ,
 
616
        const size_t n5 = 0 ,
 
617
        const size_t n6 = 0 ,
 
618
        const size_t n7 = 0 ,
 
619
        const size_t n8 = 0 )
 
620
    : m_ptr_on_device(0)
 
621
    , m_offset_map()
 
622
    , m_management()
 
623
    {
 
624
      typedef Impl::ViewAllocProp< traits , AllocationProperties > Alloc ;
 
625
 
 
626
      m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7, n8 );
 
627
      if(Alloc::AllowPadding)
 
628
        m_offset_map.set_padding();
 
629
 
 
630
      m_ptr_on_device = view_data_management::template allocate< Alloc::Initialize >( Alloc::label(prop) , m_offset_map );
 
631
    }
 
632
 
 
633
  template< class AllocationProperties >
 
634
  explicit inline
 
635
  View( const AllocationProperties & prop ,
 
636
        const typename traits::array_layout & layout ,
 
637
        // Impl::ViewAllocProp::size_type exists when the traits and allocation properties
 
638
        // are valid for allocating viewed memory.
 
639
        const typename Impl::ViewAllocProp< traits , AllocationProperties >::size_type = 0 )
 
640
    : m_ptr_on_device(0)
 
641
    , m_offset_map()
 
642
    , m_management()
 
643
    {
 
644
      typedef Impl::ViewAllocProp< traits , AllocationProperties > Alloc ;
 
645
 
 
646
      m_offset_map.assign( layout );
 
647
      if(Alloc::AllowPadding)
 
648
        m_offset_map.set_padding();
 
649
 
 
650
      m_ptr_on_device = view_data_management::template allocate< Alloc::Initialize >( Alloc::label(prop) , m_offset_map );
 
651
 
 
652
      m_management.set_noncontiguous();
 
653
    }
 
654
 
 
655
  //------------------------------------
 
656
  // Assign an unmanaged View from pointer, can be called in functors.
 
657
  // No alignment padding is performed.
 
658
 
 
659
  template< class Type >
 
660
  explicit KOKKOS_INLINE_FUNCTION
 
661
  View( Type * ptr ,
 
662
        typename Impl::ViewRawPointerProp< traits , Type >::size_type n0 = 0 ,
 
663
        const size_t n1 = 0 ,
 
664
        const size_t n2 = 0 ,
 
665
        const size_t n3 = 0 ,
 
666
        const size_t n4 = 0 ,
 
667
        const size_t n5 = 0 ,
 
668
        const size_t n6 = 0 ,
 
669
        const size_t n7 = 0 ,
 
670
        const size_t n8 = 0 )
 
671
    : m_ptr_on_device(ptr)
 
672
    , m_offset_map()
 
673
    , m_management()
 
674
    {
 
675
      m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7, n8 );
 
676
      m_management.set_unmanaged();
 
677
    }
 
678
 
 
679
  template< class Type >
 
680
  explicit KOKKOS_INLINE_FUNCTION
 
681
  View( Type * ptr ,
 
682
        typename traits::array_layout const & layout ,
 
683
        typename Impl::ViewRawPointerProp< traits , Type >::size_type = 0 )
 
684
    : m_ptr_on_device(ptr)
 
685
    , m_offset_map()
 
686
    , m_management()
 
687
    {
 
688
      m_offset_map.assign( layout );
 
689
      m_management.set_unmanaged();
 
690
      m_management.set_noncontiguous();
 
691
    }
 
692
 
 
693
  //------------------------------------
 
694
  /** \brief  Constructors for subviews requires following
 
695
   *          type-compatibility condition, enforce via StaticAssert.
 
696
   *
 
697
   *  Impl::is_same< View ,
 
698
   *                 typename Impl::ViewSubview< View<D,A1,A2,A3,Impl::ViewDefault>
 
699
   *                                           , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
700
   *                                           , ArgType4 , ArgType5 , ArgType6 , ArgType7
 
701
   *                 >::type >::value
 
702
   */
 
703
  template< class D , class A1 , class A2 , class A3
 
704
          , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
705
          , class SubArg4_type , class SubArg5_type , class SubArg6_type , class SubArg7_type
 
706
          >
 
707
  KOKKOS_INLINE_FUNCTION
 
708
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
709
      , const SubArg0_type & arg0 , const SubArg1_type & arg1
 
710
      , const SubArg2_type & arg2 , const SubArg3_type & arg3
 
711
      , const SubArg4_type & arg4 , const SubArg5_type & arg5
 
712
      , const SubArg6_type & arg6 , const SubArg7_type & arg7
 
713
      );
 
714
 
 
715
  template< class D , class A1 , class A2 , class A3
 
716
          , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
717
          , class SubArg4_type , class SubArg5_type , class SubArg6_type
 
718
          >
 
719
  KOKKOS_INLINE_FUNCTION
 
720
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
721
      , const SubArg0_type & arg0 , const SubArg1_type & arg1
 
722
      , const SubArg2_type & arg2 , const SubArg3_type & arg3
 
723
      , const SubArg4_type & arg4 , const SubArg5_type & arg5
 
724
      , const SubArg6_type & arg6
 
725
      );
 
726
 
 
727
  template< class D , class A1 , class A2 , class A3
 
728
          , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
729
          , class SubArg4_type , class SubArg5_type
 
730
          >
 
731
  KOKKOS_INLINE_FUNCTION
 
732
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
733
      , const SubArg0_type & arg0 , const SubArg1_type & arg1
 
734
      , const SubArg2_type & arg2 , const SubArg3_type & arg3
 
735
      , const SubArg4_type & arg4 , const SubArg5_type & arg5
 
736
      );
 
737
 
 
738
  template< class D , class A1 , class A2 , class A3
 
739
          , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
740
          , class SubArg4_type
 
741
          >
 
742
  KOKKOS_INLINE_FUNCTION
 
743
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
744
      , const SubArg0_type & arg0 , const SubArg1_type & arg1
 
745
      , const SubArg2_type & arg2 , const SubArg3_type & arg3
 
746
      , const SubArg4_type & arg4
 
747
      );
 
748
 
 
749
  template< class D , class A1 , class A2 , class A3
 
750
          , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
 
751
          >
 
752
  KOKKOS_INLINE_FUNCTION
 
753
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
754
      , const SubArg0_type & arg0 , const SubArg1_type & arg1
 
755
      , const SubArg2_type & arg2 , const SubArg3_type & arg3
 
756
      );
 
757
 
 
758
  template< class D , class A1 , class A2 , class A3
 
759
          , class SubArg0_type , class SubArg1_type , class SubArg2_type
 
760
          >
 
761
  KOKKOS_INLINE_FUNCTION
 
762
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
763
      , const SubArg0_type & arg0 , const SubArg1_type & arg1
 
764
      , const SubArg2_type & arg2
 
765
      );
 
766
 
 
767
  template< class D , class A1 , class A2 , class A3
 
768
          , class SubArg0_type , class SubArg1_type
 
769
          >
 
770
  KOKKOS_INLINE_FUNCTION
 
771
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
772
      , const SubArg0_type & arg0 , const SubArg1_type & arg1
 
773
      );
 
774
 
 
775
  template< class D , class A1 , class A2 , class A3
 
776
          , class SubArg0_type
 
777
          >
 
778
  KOKKOS_INLINE_FUNCTION
 
779
  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
 
780
      , const SubArg0_type & arg0
 
781
      );
 
782
 
 
783
  //------------------------------------
 
784
  // Assign unmanaged View to portion of execution space's shared memory
 
785
 
 
786
  typedef Impl::if_c< ! traits::is_managed ,
 
787
                      const typename traits::execution_space::scratch_memory_space & ,
 
788
                      Impl::ViewError::device_shmem_constructor_requires_unmanaged >
 
789
      if_scratch_memory_constructor ;
 
790
 
 
791
  explicit KOKKOS_INLINE_FUNCTION
 
792
  View( typename if_scratch_memory_constructor::type space ,
 
793
        const unsigned n0 = 0 ,
 
794
        const unsigned n1 = 0 ,
 
795
        const unsigned n2 = 0 ,
 
796
        const unsigned n3 = 0 ,
 
797
        const unsigned n4 = 0 ,
 
798
        const unsigned n5 = 0 ,
 
799
        const unsigned n6 = 0 ,
 
800
        const unsigned n7 = 0 )
 
801
    : m_ptr_on_device(0)
 
802
    , m_offset_map()
 
803
    , m_management()
 
804
    {
 
805
      typedef typename traits::value_type  value_type_ ;
 
806
 
 
807
      enum { align = 8 };
 
808
      enum { mask  = align - 1 };
 
809
 
 
810
      m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7 );
 
811
 
 
812
      typedef Impl::if_c< ! traits::is_managed ,
 
813
                          value_type_ * ,
 
814
                          Impl::ViewError::device_shmem_constructor_requires_unmanaged >
 
815
        if_device_shmem_pointer ;
 
816
 
 
817
      // Select the first argument:
 
818
      m_ptr_on_device = if_device_shmem_pointer::select(
 
819
       (value_type_*) space.get_shmem( unsigned( sizeof(value_type_) * m_offset_map.capacity() + unsigned(mask) ) & ~unsigned(mask) ) );
 
820
    }
 
821
 
 
822
  explicit KOKKOS_INLINE_FUNCTION
 
823
  View( typename if_scratch_memory_constructor::type space ,
 
824
        typename traits::array_layout const & layout)
 
825
    : m_ptr_on_device(0)
 
826
    , m_offset_map()
 
827
    , m_management()
 
828
    {
 
829
      typedef typename traits::value_type  value_type_ ;
 
830
 
 
831
      typedef Impl::if_c< ! traits::is_managed ,
 
832
                          value_type_ * ,
 
833
                          Impl::ViewError::device_shmem_constructor_requires_unmanaged >
 
834
        if_device_shmem_pointer ;
 
835
 
 
836
      m_offset_map.assign( layout );
 
837
      m_management.set_unmanaged();
 
838
      m_management.set_noncontiguous();
 
839
 
 
840
      enum { align = 8 };
 
841
      enum { mask  = align - 1 };
 
842
 
 
843
      // Select the first argument:
 
844
      m_ptr_on_device = if_device_shmem_pointer::select(
 
845
       (value_type_*) space.get_shmem( unsigned( sizeof(value_type_) * m_offset_map.capacity() + unsigned(mask) ) & ~unsigned(mask) ) );
 
846
    }
 
847
 
 
848
  static inline
 
849
  unsigned shmem_size( const unsigned n0 = 0 ,
 
850
                       const unsigned n1 = 0 ,
 
851
                       const unsigned n2 = 0 ,
 
852
                       const unsigned n3 = 0 ,
 
853
                       const unsigned n4 = 0 ,
 
854
                       const unsigned n5 = 0 ,
 
855
                       const unsigned n6 = 0 ,
 
856
                       const unsigned n7 = 0 )
 
857
  {
 
858
    enum { align = 8 };
 
859
    enum { mask  = align - 1 };
 
860
 
 
861
    typedef typename traits::value_type  value_type_ ;
 
862
 
 
863
    offset_map_type offset_map ;
 
864
 
 
865
    offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7 );
 
866
 
 
867
    return unsigned( sizeof(value_type_) * offset_map.capacity() + unsigned(mask) ) & ~unsigned(mask) ;
 
868
  }
 
869
 
 
870
  //------------------------------------
 
871
  // Is not allocated
 
872
 
 
873
  KOKKOS_FORCEINLINE_FUNCTION
 
874
  bool is_null() const { return 0 == ptr_on_device() ; }
 
875
 
 
876
  //------------------------------------
 
877
  // Operators for scalar (rank zero) views.
 
878
 
 
879
  typedef Impl::if_c< traits::rank == 0 ,
 
880
                      typename traits::value_type ,
 
881
                      Impl::ViewError::scalar_operator_called_from_non_scalar_view >
 
882
    if_scalar_operator ;
 
883
 
 
884
  KOKKOS_INLINE_FUNCTION
 
885
  const View & operator = ( const typename if_scalar_operator::type & rhs ) const
 
886
    {
 
887
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
888
      *m_ptr_on_device = if_scalar_operator::select( rhs );
 
889
      return *this ;
 
890
    }
 
891
 
 
892
  KOKKOS_FORCEINLINE_FUNCTION
 
893
  operator typename if_scalar_operator::type & () const
 
894
    {
 
895
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
896
      return if_scalar_operator::select( *m_ptr_on_device );
 
897
    }
 
898
 
 
899
  KOKKOS_FORCEINLINE_FUNCTION
 
900
  typename if_scalar_operator::type & operator()() const
 
901
    {
 
902
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
903
      return if_scalar_operator::select( *m_ptr_on_device );
 
904
    }
 
905
 
 
906
  KOKKOS_FORCEINLINE_FUNCTION
 
907
  typename if_scalar_operator::type & operator*() const
 
908
    {
 
909
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
910
      return if_scalar_operator::select( *m_ptr_on_device );
 
911
    }
 
912
 
 
913
  //------------------------------------
 
914
  // Array member access operators enabled if
 
915
  // (1) a zero value of all argument types are compile-time comparable to zero
 
916
  // (2) the rank matches the number of arguments
 
917
  // (3) the memory space is valid for the access
 
918
  //------------------------------------
 
919
  // rank 1:
 
920
 
 
921
  template< typename iType0 >
 
922
  KOKKOS_FORCEINLINE_FUNCTION
 
923
  typename Impl::ViewEnableArrayOper< reference_type , traits, typename traits::array_layout, 1, iType0 >::type
 
924
    operator[] ( const iType0 & i0 ) const
 
925
    {
 
926
      KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
 
927
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
928
 
 
929
      return m_ptr_on_device[ i0 ];
 
930
    }
 
931
 
 
932
  template< typename iType0 >
 
933
  KOKKOS_FORCEINLINE_FUNCTION
 
934
  typename Impl::ViewEnableArrayOper< reference_type , traits, typename traits::array_layout, 1, iType0 >::type
 
935
    operator() ( const iType0 & i0 ) const
 
936
    {
 
937
      KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
 
938
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
939
 
 
940
      return m_ptr_on_device[ i0 ];
 
941
    }
 
942
 
 
943
  template< typename iType0 >
 
944
  KOKKOS_FORCEINLINE_FUNCTION
 
945
  typename Impl::ViewEnableArrayOper< reference_type , traits, typename traits::array_layout, 1, iType0 >::type
 
946
    at( const iType0 & i0 , const int , const int , const int ,
 
947
        const int , const int , const int , const int ) const
 
948
    {
 
949
      KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
 
950
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
951
 
 
952
      return m_ptr_on_device[ i0 ];
 
953
    }
 
954
 
 
955
  // rank 2:
 
956
 
 
957
  template< typename iType0 , typename iType1 >
 
958
  KOKKOS_FORCEINLINE_FUNCTION
 
959
  typename Impl::ViewEnableArrayOper< reference_type ,
 
960
                                      traits, typename traits::array_layout, 2, iType0, iType1 >::type
 
961
    operator() ( const iType0 & i0 , const iType1 & i1 ) const
 
962
    {
 
963
      KOKKOS_ASSERT_SHAPE_BOUNDS_2( m_offset_map, i0,i1 );
 
964
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
965
 
 
966
      return m_ptr_on_device[ m_offset_map(i0,i1) ];
 
967
    }
 
968
 
 
969
  template< typename iType0 , typename iType1 >
 
970
  KOKKOS_FORCEINLINE_FUNCTION
 
971
  typename Impl::ViewEnableArrayOper< reference_type ,
 
972
                                      traits, typename traits::array_layout, 2, iType0, iType1 >::type
 
973
    at( const iType0 & i0 , const iType1 & i1 , const int , const int ,
 
974
        const int , const int , const int , const int ) const
 
975
    {
 
976
      KOKKOS_ASSERT_SHAPE_BOUNDS_2( m_offset_map, i0,i1 );
 
977
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
978
 
 
979
      return m_ptr_on_device[ m_offset_map(i0,i1) ];
 
980
    }
 
981
 
 
982
  // rank 3:
 
983
 
 
984
  template< typename iType0 , typename iType1 , typename iType2 >
 
985
  KOKKOS_FORCEINLINE_FUNCTION
 
986
  typename Impl::ViewEnableArrayOper< reference_type ,
 
987
                                      traits, typename traits::array_layout, 3, iType0, iType1, iType2 >::type
 
988
    operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
 
989
    {
 
990
      KOKKOS_ASSERT_SHAPE_BOUNDS_3( m_offset_map, i0,i1,i2 );
 
991
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
992
 
 
993
      return m_ptr_on_device[ m_offset_map(i0,i1,i2) ];
 
994
    }
 
995
 
 
996
  template< typename iType0 , typename iType1 , typename iType2 >
 
997
  KOKKOS_FORCEINLINE_FUNCTION
 
998
  typename Impl::ViewEnableArrayOper< reference_type ,
 
999
                                      traits, typename traits::array_layout, 3, iType0, iType1, iType2 >::type
 
1000
    at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const int ,
 
1001
        const int , const int , const int , const int ) const
 
1002
    {
 
1003
      KOKKOS_ASSERT_SHAPE_BOUNDS_3( m_offset_map, i0,i1,i2 );
 
1004
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1005
 
 
1006
      return m_ptr_on_device[ m_offset_map(i0,i1,i2) ];
 
1007
    }
 
1008
 
 
1009
  // rank 4:
 
1010
 
 
1011
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
 
1012
  KOKKOS_FORCEINLINE_FUNCTION
 
1013
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1014
                                      traits, typename traits::array_layout, 4, iType0, iType1, iType2, iType3 >::type
 
1015
    operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
 
1016
    {
 
1017
      KOKKOS_ASSERT_SHAPE_BOUNDS_4( m_offset_map, i0,i1,i2,i3 );
 
1018
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1019
 
 
1020
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3) ];
 
1021
    }
 
1022
 
 
1023
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
 
1024
  KOKKOS_FORCEINLINE_FUNCTION
 
1025
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1026
                                      traits, typename traits::array_layout, 4, iType0, iType1, iType2, iType3 >::type
 
1027
    at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1028
        const int , const int , const int , const int ) const
 
1029
    {
 
1030
      KOKKOS_ASSERT_SHAPE_BOUNDS_4( m_offset_map, i0,i1,i2,i3 );
 
1031
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1032
 
 
1033
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3) ];
 
1034
    }
 
1035
 
 
1036
  // rank 5:
 
1037
 
 
1038
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1039
            typename iType4 >
 
1040
  KOKKOS_FORCEINLINE_FUNCTION
 
1041
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1042
                                      traits, typename traits::array_layout, 5, iType0, iType1, iType2, iType3 , iType4 >::type
 
1043
    operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1044
                 const iType4 & i4 ) const
 
1045
    {
 
1046
      KOKKOS_ASSERT_SHAPE_BOUNDS_5( m_offset_map, i0,i1,i2,i3,i4 );
 
1047
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1048
 
 
1049
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4) ];
 
1050
    }
 
1051
 
 
1052
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1053
            typename iType4 >
 
1054
  KOKKOS_FORCEINLINE_FUNCTION
 
1055
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1056
                                      traits, typename traits::array_layout, 5, iType0, iType1, iType2, iType3 , iType4 >::type
 
1057
    at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1058
        const iType4 & i4 , const int , const int , const int ) const
 
1059
    {
 
1060
      KOKKOS_ASSERT_SHAPE_BOUNDS_5( m_offset_map, i0,i1,i2,i3,i4 );
 
1061
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1062
 
 
1063
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4) ];
 
1064
    }
 
1065
 
 
1066
  // rank 6:
 
1067
 
 
1068
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1069
            typename iType4 , typename iType5 >
 
1070
  KOKKOS_FORCEINLINE_FUNCTION
 
1071
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1072
                                      traits, typename traits::array_layout, 6,
 
1073
                                      iType0, iType1, iType2, iType3 , iType4, iType5 >::type
 
1074
    operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1075
                 const iType4 & i4 , const iType5 & i5 ) const
 
1076
    {
 
1077
      KOKKOS_ASSERT_SHAPE_BOUNDS_6( m_offset_map, i0,i1,i2,i3,i4,i5 );
 
1078
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1079
 
 
1080
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5) ];
 
1081
    }
 
1082
 
 
1083
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1084
            typename iType4 , typename iType5 >
 
1085
  KOKKOS_FORCEINLINE_FUNCTION
 
1086
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1087
                                      traits, typename traits::array_layout, 6,
 
1088
                                      iType0, iType1, iType2, iType3 , iType4, iType5 >::type
 
1089
    at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1090
        const iType4 & i4 , const iType5 & i5 , const int , const int ) const
 
1091
    {
 
1092
      KOKKOS_ASSERT_SHAPE_BOUNDS_6( m_offset_map, i0,i1,i2,i3,i4,i5 );
 
1093
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1094
 
 
1095
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5) ];
 
1096
    }
 
1097
 
 
1098
  // rank 7:
 
1099
 
 
1100
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1101
            typename iType4 , typename iType5 , typename iType6 >
 
1102
  KOKKOS_FORCEINLINE_FUNCTION
 
1103
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1104
                                      traits, typename traits::array_layout, 7,
 
1105
                                      iType0, iType1, iType2, iType3 , iType4, iType5, iType6 >::type
 
1106
    operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1107
                 const iType4 & i4 , const iType5 & i5 , const iType6 & i6 ) const
 
1108
    {
 
1109
      KOKKOS_ASSERT_SHAPE_BOUNDS_7( m_offset_map, i0,i1,i2,i3,i4,i5,i6 );
 
1110
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1111
 
 
1112
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6) ];
 
1113
    }
 
1114
 
 
1115
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1116
            typename iType4 , typename iType5 , typename iType6 >
 
1117
  KOKKOS_FORCEINLINE_FUNCTION
 
1118
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1119
                                      traits, typename traits::array_layout, 7,
 
1120
                                      iType0, iType1, iType2, iType3 , iType4, iType5, iType6 >::type
 
1121
    at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1122
        const iType4 & i4 , const iType5 & i5 , const iType6 & i6 , const int ) const
 
1123
    {
 
1124
      KOKKOS_ASSERT_SHAPE_BOUNDS_7( m_offset_map, i0,i1,i2,i3,i4,i5,i6 );
 
1125
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1126
 
 
1127
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6) ];
 
1128
    }
 
1129
 
 
1130
  // rank 8:
 
1131
 
 
1132
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1133
            typename iType4 , typename iType5 , typename iType6 , typename iType7 >
 
1134
  KOKKOS_FORCEINLINE_FUNCTION
 
1135
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1136
                                      traits, typename traits::array_layout, 8,
 
1137
                                      iType0, iType1, iType2, iType3 , iType4, iType5, iType6, iType7 >::type
 
1138
    operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1139
                 const iType4 & i4 , const iType5 & i5 , const iType6 & i6 , const iType7 & i7 ) const
 
1140
    {
 
1141
      KOKKOS_ASSERT_SHAPE_BOUNDS_8( m_offset_map, i0,i1,i2,i3,i4,i5,i6,i7 );
 
1142
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1143
 
 
1144
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6,i7) ];
 
1145
    }
 
1146
 
 
1147
  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
 
1148
            typename iType4 , typename iType5 , typename iType6 , typename iType7 >
 
1149
  KOKKOS_FORCEINLINE_FUNCTION
 
1150
  typename Impl::ViewEnableArrayOper< reference_type ,
 
1151
                                      traits, typename traits::array_layout, 8,
 
1152
                                      iType0, iType1, iType2, iType3 , iType4, iType5, iType6, iType7 >::type
 
1153
    at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
 
1154
        const iType4 & i4 , const iType5 & i5 , const iType6 & i6 , const iType7 & i7 ) const
 
1155
    {
 
1156
      KOKKOS_ASSERT_SHAPE_BOUNDS_8( m_offset_map, i0,i1,i2,i3,i4,i5,i6,i7 );
 
1157
      KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
 
1158
 
 
1159
      return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6,i7) ];
 
1160
    }
 
1161
 
 
1162
  //------------------------------------
 
1163
  // Access to the underlying contiguous storage of this view specialization.
 
1164
  // These methods are specific to specialization of a view.
 
1165
 
 
1166
  KOKKOS_FORCEINLINE_FUNCTION
 
1167
  typename traits::value_type * ptr_on_device() const
 
1168
    { return (typename traits::value_type *) m_ptr_on_device ; }
 
1169
 
 
1170
  // Stride of physical storage, dimensioned to at least Rank
 
1171
  template< typename iType >
 
1172
  KOKKOS_INLINE_FUNCTION
 
1173
  void stride( iType * const s ) const
 
1174
  { m_offset_map.stride(s); }
 
1175
 
 
1176
  // Count of contiguously allocated data members including padding.
 
1177
  KOKKOS_INLINE_FUNCTION
 
1178
  typename traits::size_type capacity() const
 
1179
  { return m_offset_map.capacity(); }
 
1180
 
 
1181
  // If the view data can be treated (deep copied)
 
1182
  // as a contiguous block of memory.
 
1183
  KOKKOS_INLINE_FUNCTION
 
1184
  bool is_contiguous() const
 
1185
  { return m_management.is_contiguous(); }
 
1186
};
 
1187
 
 
1188
} /* namespace Kokkos */
 
1189
 
 
1190
//----------------------------------------------------------------------------
 
1191
//----------------------------------------------------------------------------
 
1192
 
 
1193
namespace Kokkos {
 
1194
 
 
1195
template< class LT , class LL , class LD , class LM , class LS ,
 
1196
          class RT , class RL , class RD , class RM , class RS >
 
1197
KOKKOS_INLINE_FUNCTION
 
1198
typename Impl::enable_if<( Impl::is_same< LS , RS >::value ), bool >::type
 
1199
operator == ( const View<LT,LL,LD,LM,LS> & lhs ,
 
1200
              const View<RT,RL,RD,RM,RS> & rhs )
 
1201
{
 
1202
  // Same data, layout, dimensions
 
1203
  typedef ViewTraits<LT,LL,LD,LM> lhs_traits ;
 
1204
  typedef ViewTraits<RT,RL,RD,RM> rhs_traits ;
 
1205
 
 
1206
  return
 
1207
    Impl::is_same< typename lhs_traits::const_data_type ,
 
1208
                   typename rhs_traits::const_data_type >::value &&
 
1209
    Impl::is_same< typename lhs_traits::array_layout ,
 
1210
                   typename rhs_traits::array_layout >::value &&
 
1211
    Impl::is_same< typename lhs_traits::memory_space ,
 
1212
                   typename rhs_traits::memory_space >::value &&
 
1213
    Impl::is_same< typename lhs_traits::specialize ,
 
1214
                   typename rhs_traits::specialize >::value &&
 
1215
    lhs.ptr_on_device() == rhs.ptr_on_device() &&
 
1216
    lhs.shape()         == rhs.shape() ;
 
1217
}
 
1218
 
 
1219
template< class LT , class LL , class LD , class LM , class LS ,
 
1220
          class RT , class RL , class RD , class RM , class RS >
 
1221
KOKKOS_INLINE_FUNCTION
 
1222
bool operator != ( const View<LT,LL,LD,LM,LS> & lhs ,
 
1223
                   const View<RT,RL,RD,RM,RS> & rhs )
 
1224
{
 
1225
  return ! operator==( lhs , rhs );
 
1226
}
 
1227
 
 
1228
//----------------------------------------------------------------------------
 
1229
 
 
1230
 
 
1231
} // namespace Kokkos
 
1232
 
 
1233
//----------------------------------------------------------------------------
 
1234
//----------------------------------------------------------------------------
 
1235
 
 
1236
namespace Kokkos {
 
1237
 
 
1238
//----------------------------------------------------------------------------
 
1239
/** \brief  Deep copy a value into a view.
 
1240
 */
 
1241
template< class DT , class DL , class DD , class DM , class DS >
 
1242
inline
 
1243
void deep_copy( const View<DT,DL,DD,DM,DS> & dst ,
 
1244
                typename Impl::enable_if<(
 
1245
                  Impl::is_same< typename ViewTraits<DT,DL,DD,DM>::non_const_value_type ,
 
1246
                                 typename ViewTraits<DT,DL,DD,DM>::value_type >::value
 
1247
                ), typename ViewTraits<DT,DL,DD,DM>::const_value_type >::type & value )
 
1248
{
 
1249
  Impl::ViewFill< View<DT,DL,DD,DM,DS> >( dst , value );
 
1250
}
 
1251
 
 
1252
template< class ST , class SL , class SD , class SM , class SS >
 
1253
inline
 
1254
typename Impl::enable_if<( ViewTraits<ST,SL,SD,SM>::rank == 0 )>::type
 
1255
deep_copy( ST & dst , const View<ST,SL,SD,SM,SS> & src )
 
1256
{
 
1257
  typedef  ViewTraits<ST,SL,SD,SM>  src_traits ;
 
1258
  typedef typename src_traits::memory_space  src_memory_space ;
 
1259
  Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.ptr_on_device() , sizeof(ST) );
 
1260
}
 
1261
 
 
1262
//----------------------------------------------------------------------------
 
1263
/** \brief  A deep copy between views of compatible type, and rank zero.
 
1264
 */
 
1265
template< class DT , class DL , class DD , class DM , class DS ,
 
1266
          class ST , class SL , class SD , class SM , class SS >
 
1267
inline
 
1268
void deep_copy( const View<DT,DL,DD,DM,DS> & dst ,
 
1269
                const View<ST,SL,SD,SM,SS> & src ,
 
1270
                typename Impl::enable_if<(
 
1271
                  // Same type and destination is not constant:
 
1272
                  Impl::is_same< typename View<DT,DL,DD,DM,DS>::value_type ,
 
1273
                                 typename View<ST,SL,SD,SM,SS>::non_const_value_type >::value
 
1274
                  &&
 
1275
                  // Rank zero:
 
1276
                  ( unsigned(View<DT,DL,DD,DM,DS>::rank) == unsigned(0) ) &&
 
1277
                  ( unsigned(View<ST,SL,SD,SM,SS>::rank) == unsigned(0) )
 
1278
                )>::type * = 0 )
 
1279
{
 
1280
  typedef  View<DT,DL,DD,DM,DS>  dst_type ;
 
1281
  typedef  View<ST,SL,SD,SM,SS>  src_type ;
 
1282
 
 
1283
  typedef typename dst_type::memory_space  dst_memory_space ;
 
1284
  typedef typename src_type::memory_space  src_memory_space ;
 
1285
  typedef typename src_type::value_type    value_type ;
 
1286
 
 
1287
  if ( dst.ptr_on_device() != src.ptr_on_device() ) {
 
1288
    Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.ptr_on_device() , src.ptr_on_device() , sizeof(value_type) );
 
1289
  }
 
1290
}
 
1291
 
 
1292
//----------------------------------------------------------------------------
 
1293
/** \brief  A deep copy between views of the default specialization, compatible type,
 
1294
 *          same non-zero rank, same contiguous layout.
 
1295
 */
 
1296
template< class DT , class DL , class DD , class DM ,
 
1297
          class ST , class SL , class SD , class SM >
 
1298
inline
 
1299
void deep_copy( const View<DT,DL,DD,DM,Impl::ViewDefault> & dst ,
 
1300
                const View<ST,SL,SD,SM,Impl::ViewDefault> & src ,
 
1301
                typename Impl::enable_if<(
 
1302
                  // Same type and destination is not constant:
 
1303
                  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::value_type ,
 
1304
                                 typename View<ST,SL,SD,SM,Impl::ViewDefault>::non_const_value_type >::value
 
1305
                  &&
 
1306
                  // Same non-zero rank:
 
1307
                  ( unsigned(View<DT,DL,DD,DM,Impl::ViewDefault>::rank) ==
 
1308
                    unsigned(View<ST,SL,SD,SM,Impl::ViewDefault>::rank) )
 
1309
                  &&
 
1310
                  ( 0 < unsigned(View<DT,DL,DD,DM,Impl::ViewDefault>::rank) )
 
1311
                  &&
 
1312
                  // Same layout:
 
1313
                  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout ,
 
1314
                                 typename View<ST,SL,SD,SM,Impl::ViewDefault>::array_layout >::value
 
1315
                )>::type * = 0 )
 
1316
{
 
1317
  typedef  View<DT,DL,DD,DM,Impl::ViewDefault>  dst_type ;
 
1318
  typedef  View<ST,SL,SD,SM,Impl::ViewDefault>  src_type ;
 
1319
 
 
1320
  typedef typename dst_type::memory_space  dst_memory_space ;
 
1321
  typedef typename src_type::memory_space  src_memory_space ;
 
1322
 
 
1323
  enum { is_contiguous = // Contiguous (e.g., non-strided, non-tiled) layout
 
1324
           Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout , LayoutLeft >::value ||
 
1325
           Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout , LayoutRight >::value };
 
1326
 
 
1327
  if ( dst.ptr_on_device() != src.ptr_on_device() ) {
 
1328
 
 
1329
    // Same shape (dimensions)
 
1330
    Impl::assert_shapes_are_equal( dst.shape() , src.shape() );
 
1331
 
 
1332
    if ( is_contiguous && dst.capacity() == src.capacity() ) {
 
1333
 
 
1334
      // Views span equal length contiguous range.
 
1335
      // Assuming can perform a straight memory copy over this range.
 
1336
 
 
1337
      const size_t nbytes = sizeof(typename dst_type::value_type) * dst.capacity();
 
1338
 
 
1339
      Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.ptr_on_device() , src.ptr_on_device() , nbytes );
 
1340
    }
 
1341
    else {
 
1342
      // Destination view's execution space must be able to directly access source memory space
 
1343
      // in order for the ViewRemap functor run in the destination memory space's execution space.
 
1344
      Impl::ViewRemap< dst_type , src_type >( dst , src );
 
1345
    }
 
1346
  }
 
1347
}
 
1348
 
 
1349
 
 
1350
/** \brief Deep copy equal dimension arrays in the same space which
 
1351
 *         have different layouts or specializations.
 
1352
 */
 
1353
template< class DT , class DL , class DD , class DM , class DS ,
 
1354
          class ST , class SL , class SD , class SM , class SS >
 
1355
inline
 
1356
void deep_copy( const View< DT, DL, DD, DM, DS > & dst ,
 
1357
                const View< ST, SL, SD, SM, SS > & src ,
 
1358
                const typename Impl::enable_if<(
 
1359
                  // Same type and destination is not constant:
 
1360
                  Impl::is_same< typename View<DT,DL,DD,DM,DS>::value_type ,
 
1361
                                 typename View<DT,DL,DD,DM,DS>::non_const_value_type >::value
 
1362
                  &&
 
1363
                  // Source memory space is accessible to destination memory space
 
1364
                  Impl::VerifyExecutionCanAccessMemorySpace< typename View<DT,DL,DD,DM,DS>::memory_space
 
1365
                                                           , typename View<ST,SL,SD,SM,SS>::memory_space >::value
 
1366
                  &&
 
1367
                  // Same non-zero rank
 
1368
                  ( unsigned( View<DT,DL,DD,DM,DS>::rank ) ==
 
1369
                    unsigned( View<ST,SL,SD,SM,SS>::rank ) )
 
1370
                  &&
 
1371
                  ( 0 < unsigned( View<DT,DL,DD,DM,DS>::rank ) )
 
1372
                  &&
 
1373
                  // Different layout or different specialization:
 
1374
                  ( ( ! Impl::is_same< typename View<DT,DL,DD,DM,DS>::array_layout ,
 
1375
                                       typename View<ST,SL,SD,SM,SS>::array_layout >::value )
 
1376
                    ||
 
1377
                    ( ! Impl::is_same< DS , SS >::value )
 
1378
                  )
 
1379
                )>::type * = 0 )
 
1380
{
 
1381
  typedef View< DT, DL, DD, DM, DS > dst_type ;
 
1382
  typedef View< ST, SL, SD, SM, SS > src_type ;
 
1383
 
 
1384
  assert_shapes_equal_dimension( dst.shape() , src.shape() );
 
1385
 
 
1386
  Impl::ViewRemap< dst_type , src_type >( dst , src );
 
1387
}
 
1388
 
 
1389
//----------------------------------------------------------------------------
 
1390
//----------------------------------------------------------------------------
 
1391
 
 
1392
template< class T , class L , class D , class M , class S >
 
1393
typename Impl::enable_if<(
 
1394
    View<T,L,D,M,S>::is_managed
 
1395
  ), typename View<T,L,D,M,S>::HostMirror >::type
 
1396
inline
 
1397
create_mirror( const View<T,L,D,M,S> & src )
 
1398
{
 
1399
  typedef View<T,L,D,M,S>                  view_type ;
 
1400
  typedef typename view_type::HostMirror    host_view_type ;
 
1401
  typedef typename view_type::memory_space  memory_space ;
 
1402
 
 
1403
  // 'view' is managed therefore we can allocate a
 
1404
  // compatible host_view through the ordinary constructor.
 
1405
 
 
1406
  std::string label = memory_space::query_label( src.ptr_on_device() );
 
1407
  label.append("_mirror");
 
1408
 
 
1409
  return host_view_type( label ,
 
1410
                         src.dimension_0() ,
 
1411
                         src.dimension_1() ,
 
1412
                         src.dimension_2() ,
 
1413
                         src.dimension_3() ,
 
1414
                         src.dimension_4() ,
 
1415
                         src.dimension_5() ,
 
1416
                         src.dimension_6() ,
 
1417
                         src.dimension_7() );
 
1418
}
 
1419
 
 
1420
template< class T , class L , class D , class M , class S >
 
1421
typename Impl::enable_if<(
 
1422
    View<T,L,D,M,S>::is_managed &&
 
1423
    Impl::ViewAssignable< typename View<T,L,D,M,S>::HostMirror , View<T,L,D,M,S> >::value
 
1424
  ), typename View<T,L,D,M,S>::HostMirror >::type
 
1425
inline
 
1426
create_mirror_view( const View<T,L,D,M,S> & src )
 
1427
{
 
1428
  return src ;
 
1429
}
 
1430
 
 
1431
template< class T , class L , class D , class M , class S >
 
1432
typename Impl::enable_if<(
 
1433
    View<T,L,D,M,S>::is_managed &&
 
1434
    ! Impl::ViewAssignable< typename View<T,L,D,M,S>::HostMirror , View<T,L,D,M,S> >::value
 
1435
  ), typename View<T,L,D,M,S>::HostMirror >::type
 
1436
inline
 
1437
create_mirror_view( const View<T,L,D,M,S> & src )
 
1438
{
 
1439
  return create_mirror( src );
 
1440
}
 
1441
 
 
1442
//----------------------------------------------------------------------------
 
1443
 
 
1444
/** \brief  Resize a view with copying old data to new data at the corresponding indices. */
 
1445
template< class T , class L , class D , class M , class S >
 
1446
inline
 
1447
void resize( View<T,L,D,M,S> & v ,
 
1448
             const typename Impl::enable_if< ViewTraits<T,L,D,M>::is_managed , size_t >::type n0 ,
 
1449
             const size_t n1 = 0 ,
 
1450
             const size_t n2 = 0 ,
 
1451
             const size_t n3 = 0 ,
 
1452
             const size_t n4 = 0 ,
 
1453
             const size_t n5 = 0 ,
 
1454
             const size_t n6 = 0 ,
 
1455
             const size_t n7 = 0 )
 
1456
{
 
1457
  typedef View<T,L,D,M,S> view_type ;
 
1458
  typedef typename view_type::memory_space memory_space ;
 
1459
 
 
1460
  const std::string label = memory_space::query_label( v.ptr_on_device() );
 
1461
 
 
1462
  view_type v_resized( label, n0, n1, n2, n3, n4, n5, n6, n7 );
 
1463
 
 
1464
  Impl::ViewRemap< view_type , view_type >( v_resized , v );
 
1465
 
 
1466
  v = v_resized ;
 
1467
}
 
1468
 
 
1469
/** \brief  Reallocate a view without copying old data to new data */
 
1470
template< class T , class L , class D , class M , class S >
 
1471
inline
 
1472
void realloc( View<T,L,D,M,S> & v ,
 
1473
              const typename Impl::enable_if< ViewTraits<T,L,D,M>::is_managed , size_t >::type n0 ,
 
1474
              const size_t n1 = 0 ,
 
1475
              const size_t n2 = 0 ,
 
1476
              const size_t n3 = 0 ,
 
1477
              const size_t n4 = 0 ,
 
1478
              const size_t n5 = 0 ,
 
1479
              const size_t n6 = 0 ,
 
1480
              const size_t n7 = 0 )
 
1481
{
 
1482
  typedef View<T,L,D,M,S> view_type ;
 
1483
  typedef typename view_type::memory_space memory_space ;
 
1484
 
 
1485
  // Query the current label and reuse it.
 
1486
  const std::string label = memory_space::query_label( v.ptr_on_device() );
 
1487
 
 
1488
  v = view_type(); // deallocate first, if the only view to memory.
 
1489
  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
 
1490
}
 
1491
 
 
1492
} // namespace Kokkos
 
1493
 
 
1494
//----------------------------------------------------------------------------
 
1495
//----------------------------------------------------------------------------
 
1496
 
 
1497
namespace Kokkos {
 
1498
 
 
1499
struct ALL { KOKKOS_INLINE_FUNCTION ALL(){} };
 
1500
 
 
1501
template< class DstViewType ,
 
1502
          class T , class L , class D , class M , class S ,
 
1503
          class ArgType0 >
 
1504
KOKKOS_INLINE_FUNCTION
 
1505
DstViewType
 
1506
subview( const View<T,L,D,M,S> & src ,
 
1507
         const ArgType0 & arg0 )
 
1508
{
 
1509
  DstViewType dst ;
 
1510
 
 
1511
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst , src , arg0 );
 
1512
 
 
1513
  return dst ;
 
1514
}
 
1515
 
 
1516
template< class DstViewType ,
 
1517
          class T , class L , class D , class M , class S ,
 
1518
          class ArgType0 , class ArgType1 >
 
1519
KOKKOS_INLINE_FUNCTION
 
1520
DstViewType
 
1521
subview( const View<T,L,D,M,S> & src ,
 
1522
         const ArgType0 & arg0 ,
 
1523
         const ArgType1 & arg1 )
 
1524
{
 
1525
  DstViewType dst ;
 
1526
 
 
1527
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1 );
 
1528
 
 
1529
  return dst ;
 
1530
}
 
1531
 
 
1532
template< class DstViewType ,
 
1533
          class T , class L , class D , class M , class S ,
 
1534
          class ArgType0 , class ArgType1 , class ArgType2 >
 
1535
KOKKOS_INLINE_FUNCTION
 
1536
DstViewType
 
1537
subview( const View<T,L,D,M,S> & src ,
 
1538
         const ArgType0 & arg0 ,
 
1539
         const ArgType1 & arg1 ,
 
1540
         const ArgType2 & arg2 )
 
1541
{
 
1542
  DstViewType dst ;
 
1543
 
 
1544
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2 );
 
1545
 
 
1546
  return dst ;
 
1547
}
 
1548
 
 
1549
template< class DstViewType ,
 
1550
          class T , class L , class D , class M , class S ,
 
1551
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 >
 
1552
KOKKOS_INLINE_FUNCTION
 
1553
DstViewType
 
1554
subview( const View<T,L,D,M,S> & src ,
 
1555
         const ArgType0 & arg0 ,
 
1556
         const ArgType1 & arg1 ,
 
1557
         const ArgType2 & arg2 ,
 
1558
         const ArgType3 & arg3 )
 
1559
{
 
1560
  DstViewType dst ;
 
1561
 
 
1562
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3 );
 
1563
 
 
1564
  return dst ;
 
1565
}
 
1566
 
 
1567
template< class DstViewType ,
 
1568
          class T , class L , class D , class M , class S ,
 
1569
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1570
          class ArgType4 >
 
1571
KOKKOS_INLINE_FUNCTION
 
1572
DstViewType
 
1573
subview( const View<T,L,D,M,S> & src ,
 
1574
         const ArgType0 & arg0 ,
 
1575
         const ArgType1 & arg1 ,
 
1576
         const ArgType2 & arg2 ,
 
1577
         const ArgType3 & arg3 ,
 
1578
         const ArgType4 & arg4 )
 
1579
{
 
1580
  DstViewType dst ;
 
1581
 
 
1582
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4 );
 
1583
 
 
1584
  return dst ;
 
1585
}
 
1586
 
 
1587
template< class DstViewType ,
 
1588
          class T , class L , class D , class M , class S ,
 
1589
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1590
          class ArgType4 , class ArgType5 >
 
1591
KOKKOS_INLINE_FUNCTION
 
1592
DstViewType
 
1593
subview( const View<T,L,D,M,S> & src ,
 
1594
         const ArgType0 & arg0 ,
 
1595
         const ArgType1 & arg1 ,
 
1596
         const ArgType2 & arg2 ,
 
1597
         const ArgType3 & arg3 ,
 
1598
         const ArgType4 & arg4 ,
 
1599
         const ArgType5 & arg5 )
 
1600
{
 
1601
  DstViewType dst ;
 
1602
 
 
1603
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4, arg5 );
 
1604
 
 
1605
  return dst ;
 
1606
}
 
1607
 
 
1608
template< class DstViewType ,
 
1609
          class T , class L , class D , class M , class S ,
 
1610
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1611
          class ArgType4 , class ArgType5 , class ArgType6 >
 
1612
KOKKOS_INLINE_FUNCTION
 
1613
DstViewType
 
1614
subview( const View<T,L,D,M,S> & src ,
 
1615
         const ArgType0 & arg0 ,
 
1616
         const ArgType1 & arg1 ,
 
1617
         const ArgType2 & arg2 ,
 
1618
         const ArgType3 & arg3 ,
 
1619
         const ArgType4 & arg4 ,
 
1620
         const ArgType5 & arg5 ,
 
1621
         const ArgType6 & arg6 )
 
1622
{
 
1623
  DstViewType dst ;
 
1624
 
 
1625
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4, arg5, arg6 );
 
1626
 
 
1627
  return dst ;
 
1628
}
 
1629
 
 
1630
template< class DstViewType ,
 
1631
          class T , class L , class D , class M , class S ,
 
1632
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1633
          class ArgType4 , class ArgType5 , class ArgType6 , class ArgType7 >
 
1634
KOKKOS_INLINE_FUNCTION
 
1635
DstViewType
 
1636
subview( const View<T,L,D,M,S> & src ,
 
1637
         const ArgType0 & arg0 ,
 
1638
         const ArgType1 & arg1 ,
 
1639
         const ArgType2 & arg2 ,
 
1640
         const ArgType3 & arg3 ,
 
1641
         const ArgType4 & arg4 ,
 
1642
         const ArgType5 & arg5 ,
 
1643
         const ArgType6 & arg6 ,
 
1644
         const ArgType7 & arg7 )
 
1645
{
 
1646
  DstViewType dst ;
 
1647
 
 
1648
  Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
 
1649
 
 
1650
  return dst ;
 
1651
}
 
1652
 
 
1653
} // namespace Kokkos
 
1654
 
 
1655
//----------------------------------------------------------------------------
 
1656
 
 
1657
namespace Kokkos {
 
1658
 
 
1659
template< class D , class A1 , class A2 , class A3 , class S ,
 
1660
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1661
          class ArgType4 , class ArgType5 , class ArgType6 , class ArgType7 >
 
1662
KOKKOS_INLINE_FUNCTION
 
1663
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1664
                          , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1665
                          , ArgType4 , ArgType5 , ArgType6 , ArgType7
 
1666
                          >::type
 
1667
subview( const View<D,A1,A2,A3,S> & src ,
 
1668
         const ArgType0 & arg0 ,
 
1669
         const ArgType1 & arg1 ,
 
1670
         const ArgType2 & arg2 ,
 
1671
         const ArgType3 & arg3 ,
 
1672
         const ArgType4 & arg4 ,
 
1673
         const ArgType5 & arg5 ,
 
1674
         const ArgType6 & arg6 ,
 
1675
         const ArgType7 & arg7 )
 
1676
{
 
1677
  typedef typename
 
1678
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1679
                 , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1680
                 , ArgType4 , ArgType5 , ArgType6 , ArgType7
 
1681
                 >::type
 
1682
      DstViewType ;
 
1683
 
 
1684
  return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
 
1685
}
 
1686
 
 
1687
template< class D , class A1 , class A2 , class A3 , class S ,
 
1688
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1689
          class ArgType4 , class ArgType5 , class ArgType6 >
 
1690
KOKKOS_INLINE_FUNCTION
 
1691
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1692
                          , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1693
                          , ArgType4 , ArgType5 , ArgType6 , void
 
1694
                          >::type
 
1695
subview( const View<D,A1,A2,A3,S> & src ,
 
1696
         const ArgType0 & arg0 ,
 
1697
         const ArgType1 & arg1 ,
 
1698
         const ArgType2 & arg2 ,
 
1699
         const ArgType3 & arg3 ,
 
1700
         const ArgType4 & arg4 ,
 
1701
         const ArgType5 & arg5 ,
 
1702
         const ArgType6 & arg6 )
 
1703
{
 
1704
  typedef typename
 
1705
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1706
                 , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1707
                 , ArgType4 , ArgType5 , ArgType6 , void
 
1708
                 >::type
 
1709
      DstViewType ;
 
1710
 
 
1711
  return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5, arg6 );
 
1712
}
 
1713
 
 
1714
template< class D , class A1 , class A2 , class A3 , class S ,
 
1715
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1716
          class ArgType4 , class ArgType5 >
 
1717
KOKKOS_INLINE_FUNCTION
 
1718
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1719
                          , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1720
                          , ArgType4 , ArgType5 , void , void
 
1721
                          >::type
 
1722
subview( const View<D,A1,A2,A3,S> & src ,
 
1723
         const ArgType0 & arg0 ,
 
1724
         const ArgType1 & arg1 ,
 
1725
         const ArgType2 & arg2 ,
 
1726
         const ArgType3 & arg3 ,
 
1727
         const ArgType4 & arg4 ,
 
1728
         const ArgType5 & arg5 )
 
1729
{
 
1730
  typedef typename
 
1731
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1732
                 , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1733
                 , ArgType4 , ArgType5 , void , void
 
1734
                 >::type
 
1735
      DstViewType ;
 
1736
 
 
1737
  return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5 );
 
1738
}
 
1739
 
 
1740
template< class D , class A1 , class A2 , class A3 , class S ,
 
1741
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
 
1742
          class ArgType4 >
 
1743
KOKKOS_INLINE_FUNCTION
 
1744
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1745
                          , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1746
                          , ArgType4 , void , void , void
 
1747
                          >::type
 
1748
subview( const View<D,A1,A2,A3,S> & src ,
 
1749
         const ArgType0 & arg0 ,
 
1750
         const ArgType1 & arg1 ,
 
1751
         const ArgType2 & arg2 ,
 
1752
         const ArgType3 & arg3 ,
 
1753
         const ArgType4 & arg4 )
 
1754
{
 
1755
  typedef typename
 
1756
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1757
                 , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1758
                 , ArgType4 , void , void , void
 
1759
                 >::type
 
1760
      DstViewType ;
 
1761
 
 
1762
  return DstViewType( src, arg0, arg1, arg2, arg3, arg4 );
 
1763
}
 
1764
 
 
1765
template< class D , class A1 , class A2 , class A3 , class S ,
 
1766
          class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 >
 
1767
KOKKOS_INLINE_FUNCTION
 
1768
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1769
                          , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1770
                          , void , void , void , void
 
1771
                          >::type
 
1772
subview( const View<D,A1,A2,A3,S> & src ,
 
1773
         const ArgType0 & arg0 ,
 
1774
         const ArgType1 & arg1 ,
 
1775
         const ArgType2 & arg2 ,
 
1776
         const ArgType3 & arg3 )
 
1777
{
 
1778
  typedef typename
 
1779
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1780
                 , ArgType0 , ArgType1 , ArgType2 , ArgType3
 
1781
                 , void , void , void , void
 
1782
                 >::type
 
1783
      DstViewType ;
 
1784
 
 
1785
  return DstViewType( src, arg0, arg1, arg2, arg3 );
 
1786
}
 
1787
 
 
1788
template< class D , class A1 , class A2 , class A3 , class S ,
 
1789
          class ArgType0 , class ArgType1 , class ArgType2 >
 
1790
KOKKOS_INLINE_FUNCTION
 
1791
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1792
                          , ArgType0 , ArgType1 , ArgType2 , void
 
1793
                          , void , void , void , void
 
1794
                          >::type
 
1795
subview( const View<D,A1,A2,A3,S> & src ,
 
1796
         const ArgType0 & arg0 ,
 
1797
         const ArgType1 & arg1 ,
 
1798
         const ArgType2 & arg2 )
 
1799
{
 
1800
  typedef typename
 
1801
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1802
                 , ArgType0 , ArgType1 , ArgType2 , void
 
1803
                 , void , void , void , void
 
1804
                 >::type
 
1805
      DstViewType ;
 
1806
 
 
1807
  return DstViewType( src, arg0, arg1, arg2 );
 
1808
}
 
1809
 
 
1810
template< class D , class A1 , class A2 , class A3 , class S ,
 
1811
          class ArgType0 , class ArgType1 >
 
1812
KOKKOS_INLINE_FUNCTION
 
1813
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1814
                          , ArgType0 , ArgType1 , void , void
 
1815
                          , void , void , void , void
 
1816
                          >::type
 
1817
subview( const View<D,A1,A2,A3,S> & src ,
 
1818
         const ArgType0 & arg0 ,
 
1819
         const ArgType1 & arg1 )
 
1820
{
 
1821
  typedef typename
 
1822
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1823
                 , ArgType0 , ArgType1 , void , void
 
1824
                 , void , void , void , void
 
1825
                 >::type
 
1826
      DstViewType ;
 
1827
 
 
1828
  return DstViewType( src, arg0, arg1 );
 
1829
}
 
1830
 
 
1831
template< class D , class A1 , class A2 , class A3 , class S ,
 
1832
          class ArgType0 >
 
1833
KOKKOS_INLINE_FUNCTION
 
1834
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1835
                          , ArgType0 , void , void , void
 
1836
                          , void , void , void , void
 
1837
                          >::type
 
1838
subview( const View<D,A1,A2,A3,S> & src ,
 
1839
         const ArgType0 & arg0 )
 
1840
{
 
1841
  typedef typename
 
1842
    Impl::ViewSubview< View<D,A1,A2,A3,S>
 
1843
                 , ArgType0 , void , void , void
 
1844
                 , void , void , void , void
 
1845
                 >::type
 
1846
      DstViewType ;
 
1847
 
 
1848
  return DstViewType( src, arg0 );
 
1849
}
 
1850
 
 
1851
} // namespace Kokkos
 
1852
 
 
1853
//----------------------------------------------------------------------------
 
1854
//----------------------------------------------------------------------------
 
1855
 
 
1856
#include <impl/Kokkos_ViewDefault.hpp>
 
1857
#include <impl/Kokkos_Atomic_View.hpp>
 
1858
 
 
1859
//----------------------------------------------------------------------------
 
1860
//----------------------------------------------------------------------------
 
1861
 
 
1862
#endif
 
1863