3
// ************************************************************************
5
// Kokkos: Manycore Performance-Portable Multidimensional Arrays
6
// Copyright (2012) Sandia Corporation
8
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9
// the U.S. Government retains certain rights in this software.
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
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.
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.
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.
38
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
40
// ************************************************************************
44
#ifndef KOKKOS_VIEW_HPP
45
#define KOKKOS_VIEW_HPP
48
#include <Kokkos_Core_fwd.hpp>
49
#include <Kokkos_HostSpace.hpp>
50
#include <Kokkos_MemoryTraits.hpp>
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>
60
//----------------------------------------------------------------------------
61
//----------------------------------------------------------------------------
66
/** \brief View specialization mapping of view traits to a specialization tag */
67
template< class ValueType ,
68
class ArraySpecialize ,
72
struct ViewSpecialize ;
74
/** \brief Defines the type of a subview given a source view type
75
* and subview argument types.
77
template< class SrcViewType
87
struct ViewSubview /* { typedef ... type ; } */ ;
89
template< class DstViewSpecialize ,
90
class SrcViewSpecialize = void ,
92
struct ViewAssignment ;
94
template< class DstMemorySpace , class SrcMemorySpace >
97
} /* namespace Impl */
100
//----------------------------------------------------------------------------
101
//----------------------------------------------------------------------------
105
/** \class ViewTraits
106
* \brief Traits class for accessing attributes of a View.
108
* This is an implementation detail of View. It is only of interest
109
* to developers implementing a new specialization of View.
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 >
123
template< class DataType ,
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
135
enum { Arg1IsLayout = Impl::is_array_layout<Arg1>::value };
137
enum { Arg1IsSpace = Impl::is_space<Arg1>::value };
138
enum { Arg2IsSpace = Impl::is_space<Arg2>::value };
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 };
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 };
148
// Arg1 is Layout, Space, MemoryTraits, or void
151
( 1 == Arg1IsLayout + Arg1IsSpace + Arg1IsMemoryTraits + Arg1IsVoid )
152
, Arg1 >::type Arg1Verified ;
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
160
( Arg1IsLayout && ( 1 == Arg2IsSpace + Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
161
( Arg1IsSpace && ( 0 == Arg2IsSpace ) && ( 1 == Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
162
( Arg1IsMemoryTraits && Arg2IsVoid ) ||
163
( Arg1IsVoid && Arg2IsVoid )
164
, Arg2 >::type Arg2Verified ;
166
// Arg3 is MemoryTraits or void and at most one argument is MemoryTraits
169
( 1 == Arg3IsMemoryTraits + Arg3IsVoid ) &&
170
( Arg1IsMemoryTraits + Arg2IsMemoryTraits + Arg3IsMemoryTraits <= 1 )
171
, Arg3 >::type Arg3Verified ;
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 ;
179
typedef typename Impl::if_c<( Arg1IsSpace ), Arg1Verified ,
180
typename Impl::if_c<( Arg2IsSpace ), Arg2Verified ,
181
Kokkos::DefaultExecutionSpace
182
>::type >::type::memory_space MemorySpace ;
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 ;
190
// Arg1 may be array layout
191
typedef typename Impl::if_c< Arg1IsLayout , Arg1Verified ,
192
typename ExecutionSpace::array_layout
193
>::type ArrayLayout ;
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 ,
200
>::type >::type >::type MemoryTraits ;
202
typedef Impl::AnalyzeShape<DataType> analysis ;
206
//------------------------------------
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 ;
213
//------------------------------------
214
// Array of intrinsic scalar type traits:
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 ;
220
//------------------------------------
221
// Value type traits:
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 ;
227
//------------------------------------
228
// Layout and shape traits:
230
typedef ArrayLayout array_layout ;
231
typedef typename analysis::shape shape_type ;
233
enum { rank = shape_type::rank };
234
enum { rank_dynamic = shape_type::rank_dynamic };
236
//------------------------------------
237
// Execution space, memory space, memory access traits, and host mirror space.
239
typedef ExecutionSpace execution_space ;
240
typedef MemorySpace memory_space ;
241
typedef MemoryTraits memory_traits ;
242
typedef HostMirrorSpace host_mirror_space ;
244
typedef typename memory_space::size_type size_type ;
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 };
250
//------------------------------------
252
typedef ExecutionSpace device_type ; // for backward compatibility, to be removed
254
//------------------------------------
255
// Specialization tag:
258
Impl::ViewSpecialize< value_type
259
, typename analysis::specialize
266
} /* namespace Kokkos */
268
//----------------------------------------------------------------------------
269
//----------------------------------------------------------------------------
274
class ViewDefault {};
276
/** \brief Default view specialization has LayoutLeft, LayoutRight, or LayoutStride.
278
template< class ValueType , class MemorySpace , class MemoryTraits >
279
struct ViewSpecialize< ValueType , void , LayoutLeft , MemorySpace , MemoryTraits >
280
{ typedef ViewDefault type ; };
282
template< class ValueType , class MemorySpace , class MemoryTraits >
283
struct ViewSpecialize< ValueType , void , LayoutRight , MemorySpace , MemoryTraits >
284
{ typedef ViewDefault type ; };
286
template< class ValueType , class MemorySpace , class MemoryTraits >
287
struct ViewSpecialize< ValueType , void , LayoutStride , MemorySpace , MemoryTraits >
288
{ typedef ViewDefault type ; };
290
} /* namespace Impl */
291
} /* namespace Kokkos */
293
//----------------------------------------------------------------------------
294
//----------------------------------------------------------------------------
299
/** \brief Types for compile-time detection of View usage errors */
300
namespace ViewError {
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 {};
307
struct scalar_operator_called_from_non_scalar_view {};
309
} /* namespace ViewError */
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.
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 ;
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 ,
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 )
341
typedef ReturnType type ;
344
} /* namespace Impl */
345
} /* namespace Kokkos */
347
//----------------------------------------------------------------------------
348
//----------------------------------------------------------------------------
353
* \brief View to an array of data.
355
* A View represents an array of one or more dimensions.
356
* For details, please refer to Kokkos' tutorial materials.
358
* \section Kokkos_View_TemplateParameters Template parameters
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
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 >
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.
387
* \tparam Space (required) The memory space.
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
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
401
* \section Kokkos_View_MT MemoryTraits discussion
403
* \subsection Kokkos_View_MT_Interp MemoryTraits interpretation depends on Space
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.
410
* \subsection Kokkos_View_MT_PrefUse Preferred use of MemoryTraits
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.
420
* // Pass in the simplest types of View possible.
422
* doSomething (View<double*, Cuda> out,
423
* View<const double*, Cuda> in)
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 ...
432
template< class DataType ,
433
class Arg1Type = void , /* ArrayLayout, SpaceType, or MemoryTraits */
434
class Arg2Type = void , /* SpaceType or MemoryTraits */
435
class Arg3Type = void , /* MemoryTraits */
437
typename ViewTraits<DataType,Arg1Type,Arg2Type,Arg3Type>::specialize >
443
struct is_view : public bool_< false > {};
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 > {};
450
//----------------------------------------------------------------------------
452
template< class DataType ,
456
class View< DataType , Arg1Type , Arg2Type , Arg3Type , Impl::ViewDefault >
457
: public ViewTraits< DataType , Arg1Type , Arg2Type, Arg3Type >
461
typedef ViewTraits< DataType , Arg1Type , Arg2Type, Arg3Type > traits ;
465
// Assignment of compatible views requirement:
466
template< class , class , class , class , class > friend class View ;
468
// Assignment of compatible subview requirement:
469
template< class , class , class > friend struct Impl::ViewAssignment ;
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
478
// Intermediary class for data management and access
479
typedef Impl::ViewDataManagement< traits > view_data_management ;
481
//----------------------------------------
484
typename view_data_management::handle_type m_ptr_on_device ;
485
offset_map_type m_offset_map ;
486
view_data_management m_management ;
488
//----------------------------------------
492
/** return type for all indexing operators */
493
typedef typename view_data_management::return_type reference_type ;
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 ;
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 ;
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 ;
510
typedef View< typename traits::non_const_data_type ,
511
typename traits::array_layout ,
512
typename traits::host_mirror_space ,
515
//------------------------------------
518
enum { Rank = traits::rank };
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(); }
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 ); }
536
//------------------------------------
537
// Destructor, constructors, assignment operators:
539
KOKKOS_INLINE_FUNCTION
541
{ m_management.decrement( m_ptr_on_device ); }
543
KOKKOS_INLINE_FUNCTION
545
: m_ptr_on_device((typename traits::value_type*) NULL)
548
{ m_offset_map.assign(0, 0,0,0,0,0,0,0,0); }
550
KOKKOS_INLINE_FUNCTION
551
View( const View & rhs )
552
: m_ptr_on_device((typename traits::value_type*) NULL)
556
(void) Impl::ViewAssignment<
557
typename traits::specialize ,
558
typename traits::specialize >( *this , rhs );
561
KOKKOS_INLINE_FUNCTION
562
View & operator = ( const View & rhs )
564
(void) Impl::ViewAssignment<
565
typename traits::specialize ,
566
typename traits::specialize >( *this , rhs );
570
//------------------------------------
571
// Construct or assign compatible view:
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)
580
(void) Impl::ViewAssignment<
581
typename traits::specialize , RS >( *this , rhs );
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 )
588
(void) Impl::ViewAssignment<
589
typename traits::specialize , RS >( *this , rhs );
593
//------------------------------------
594
/**\brief Allocation of a managed view with possible alignment padding.
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")
601
* Allocation properties for allocating and bypassing initialization:
602
* Kokkos::ViewAllocateWithoutInitializing()
603
* Kokkos::ViewAllocateWithoutInitializing("label")
606
template< class AllocationProperties >
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 )
624
typedef Impl::ViewAllocProp< traits , AllocationProperties > Alloc ;
626
m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7, n8 );
627
if(Alloc::AllowPadding)
628
m_offset_map.set_padding();
630
m_ptr_on_device = view_data_management::template allocate< Alloc::Initialize >( Alloc::label(prop) , m_offset_map );
633
template< class AllocationProperties >
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 )
644
typedef Impl::ViewAllocProp< traits , AllocationProperties > Alloc ;
646
m_offset_map.assign( layout );
647
if(Alloc::AllowPadding)
648
m_offset_map.set_padding();
650
m_ptr_on_device = view_data_management::template allocate< Alloc::Initialize >( Alloc::label(prop) , m_offset_map );
652
m_management.set_noncontiguous();
655
//------------------------------------
656
// Assign an unmanaged View from pointer, can be called in functors.
657
// No alignment padding is performed.
659
template< class Type >
660
explicit KOKKOS_INLINE_FUNCTION
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)
675
m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7, n8 );
676
m_management.set_unmanaged();
679
template< class Type >
680
explicit KOKKOS_INLINE_FUNCTION
682
typename traits::array_layout const & layout ,
683
typename Impl::ViewRawPointerProp< traits , Type >::size_type = 0 )
684
: m_ptr_on_device(ptr)
688
m_offset_map.assign( layout );
689
m_management.set_unmanaged();
690
m_management.set_noncontiguous();
693
//------------------------------------
694
/** \brief Constructors for subviews requires following
695
* type-compatibility condition, enforce via StaticAssert.
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
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
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
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
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
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
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
738
template< class D , class A1 , class A2 , class A3
739
, class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
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
749
template< class D , class A1 , class A2 , class A3
750
, class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
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
758
template< class D , class A1 , class A2 , class A3
759
, class SubArg0_type , class SubArg1_type , class SubArg2_type
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
767
template< class D , class A1 , class A2 , class A3
768
, class SubArg0_type , class SubArg1_type
770
KOKKOS_INLINE_FUNCTION
771
View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
772
, const SubArg0_type & arg0 , const SubArg1_type & arg1
775
template< class D , class A1 , class A2 , class A3
778
KOKKOS_INLINE_FUNCTION
779
View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
780
, const SubArg0_type & arg0
783
//------------------------------------
784
// Assign unmanaged View to portion of execution space's shared memory
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 ;
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 )
805
typedef typename traits::value_type value_type_ ;
808
enum { mask = align - 1 };
810
m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7 );
812
typedef Impl::if_c< ! traits::is_managed ,
814
Impl::ViewError::device_shmem_constructor_requires_unmanaged >
815
if_device_shmem_pointer ;
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) ) );
822
explicit KOKKOS_INLINE_FUNCTION
823
View( typename if_scratch_memory_constructor::type space ,
824
typename traits::array_layout const & layout)
829
typedef typename traits::value_type value_type_ ;
831
typedef Impl::if_c< ! traits::is_managed ,
833
Impl::ViewError::device_shmem_constructor_requires_unmanaged >
834
if_device_shmem_pointer ;
836
m_offset_map.assign( layout );
837
m_management.set_unmanaged();
838
m_management.set_noncontiguous();
841
enum { mask = align - 1 };
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) ) );
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 )
859
enum { mask = align - 1 };
861
typedef typename traits::value_type value_type_ ;
863
offset_map_type offset_map ;
865
offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7 );
867
return unsigned( sizeof(value_type_) * offset_map.capacity() + unsigned(mask) ) & ~unsigned(mask) ;
870
//------------------------------------
873
KOKKOS_FORCEINLINE_FUNCTION
874
bool is_null() const { return 0 == ptr_on_device() ; }
876
//------------------------------------
877
// Operators for scalar (rank zero) views.
879
typedef Impl::if_c< traits::rank == 0 ,
880
typename traits::value_type ,
881
Impl::ViewError::scalar_operator_called_from_non_scalar_view >
884
KOKKOS_INLINE_FUNCTION
885
const View & operator = ( const typename if_scalar_operator::type & rhs ) const
887
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
888
*m_ptr_on_device = if_scalar_operator::select( rhs );
892
KOKKOS_FORCEINLINE_FUNCTION
893
operator typename if_scalar_operator::type & () const
895
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
896
return if_scalar_operator::select( *m_ptr_on_device );
899
KOKKOS_FORCEINLINE_FUNCTION
900
typename if_scalar_operator::type & operator()() const
902
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
903
return if_scalar_operator::select( *m_ptr_on_device );
906
KOKKOS_FORCEINLINE_FUNCTION
907
typename if_scalar_operator::type & operator*() const
909
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
910
return if_scalar_operator::select( *m_ptr_on_device );
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
//------------------------------------
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
926
KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
927
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
929
return m_ptr_on_device[ i0 ];
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
937
KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
938
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
940
return m_ptr_on_device[ i0 ];
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
949
KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
950
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
952
return m_ptr_on_device[ i0 ];
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
963
KOKKOS_ASSERT_SHAPE_BOUNDS_2( m_offset_map, i0,i1 );
964
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
966
return m_ptr_on_device[ m_offset_map(i0,i1) ];
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
976
KOKKOS_ASSERT_SHAPE_BOUNDS_2( m_offset_map, i0,i1 );
977
KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
979
return m_ptr_on_device[ m_offset_map(i0,i1) ];
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
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() );
993
return m_ptr_on_device[ m_offset_map(i0,i1,i2) ];
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
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() );
1006
return m_ptr_on_device[ m_offset_map(i0,i1,i2) ];
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
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() );
1020
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3) ];
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
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() );
1033
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3) ];
1038
template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
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
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() );
1049
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4) ];
1052
template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
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
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() );
1063
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4) ];
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
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() );
1080
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5) ];
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
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() );
1095
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5) ];
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
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() );
1112
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6) ];
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
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() );
1127
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6) ];
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
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() );
1144
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6,i7) ];
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
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() );
1159
return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6,i7) ];
1162
//------------------------------------
1163
// Access to the underlying contiguous storage of this view specialization.
1164
// These methods are specific to specialization of a view.
1166
KOKKOS_FORCEINLINE_FUNCTION
1167
typename traits::value_type * ptr_on_device() const
1168
{ return (typename traits::value_type *) m_ptr_on_device ; }
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); }
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(); }
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(); }
1188
} /* namespace Kokkos */
1190
//----------------------------------------------------------------------------
1191
//----------------------------------------------------------------------------
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 )
1202
// Same data, layout, dimensions
1203
typedef ViewTraits<LT,LL,LD,LM> lhs_traits ;
1204
typedef ViewTraits<RT,RL,RD,RM> rhs_traits ;
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() ;
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 )
1225
return ! operator==( lhs , rhs );
1228
//----------------------------------------------------------------------------
1231
} // namespace Kokkos
1233
//----------------------------------------------------------------------------
1234
//----------------------------------------------------------------------------
1238
//----------------------------------------------------------------------------
1239
/** \brief Deep copy a value into a view.
1241
template< class DT , class DL , class DD , class DM , class DS >
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 )
1249
Impl::ViewFill< View<DT,DL,DD,DM,DS> >( dst , value );
1252
template< class ST , class SL , class SD , class SM , class SS >
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 )
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) );
1262
//----------------------------------------------------------------------------
1263
/** \brief A deep copy between views of compatible type, and rank zero.
1265
template< class DT , class DL , class DD , class DM , class DS ,
1266
class ST , class SL , class SD , class SM , class SS >
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
1276
( unsigned(View<DT,DL,DD,DM,DS>::rank) == unsigned(0) ) &&
1277
( unsigned(View<ST,SL,SD,SM,SS>::rank) == unsigned(0) )
1280
typedef View<DT,DL,DD,DM,DS> dst_type ;
1281
typedef View<ST,SL,SD,SM,SS> src_type ;
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 ;
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) );
1292
//----------------------------------------------------------------------------
1293
/** \brief A deep copy between views of the default specialization, compatible type,
1294
* same non-zero rank, same contiguous layout.
1296
template< class DT , class DL , class DD , class DM ,
1297
class ST , class SL , class SD , class SM >
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
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) )
1310
( 0 < unsigned(View<DT,DL,DD,DM,Impl::ViewDefault>::rank) )
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
1317
typedef View<DT,DL,DD,DM,Impl::ViewDefault> dst_type ;
1318
typedef View<ST,SL,SD,SM,Impl::ViewDefault> src_type ;
1320
typedef typename dst_type::memory_space dst_memory_space ;
1321
typedef typename src_type::memory_space src_memory_space ;
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 };
1327
if ( dst.ptr_on_device() != src.ptr_on_device() ) {
1329
// Same shape (dimensions)
1330
Impl::assert_shapes_are_equal( dst.shape() , src.shape() );
1332
if ( is_contiguous && dst.capacity() == src.capacity() ) {
1334
// Views span equal length contiguous range.
1335
// Assuming can perform a straight memory copy over this range.
1337
const size_t nbytes = sizeof(typename dst_type::value_type) * dst.capacity();
1339
Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.ptr_on_device() , src.ptr_on_device() , nbytes );
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 );
1350
/** \brief Deep copy equal dimension arrays in the same space which
1351
* have different layouts or specializations.
1353
template< class DT , class DL , class DD , class DM , class DS ,
1354
class ST , class SL , class SD , class SM , class SS >
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
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
1367
// Same non-zero rank
1368
( unsigned( View<DT,DL,DD,DM,DS>::rank ) ==
1369
unsigned( View<ST,SL,SD,SM,SS>::rank ) )
1371
( 0 < unsigned( View<DT,DL,DD,DM,DS>::rank ) )
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 )
1377
( ! Impl::is_same< DS , SS >::value )
1381
typedef View< DT, DL, DD, DM, DS > dst_type ;
1382
typedef View< ST, SL, SD, SM, SS > src_type ;
1384
assert_shapes_equal_dimension( dst.shape() , src.shape() );
1386
Impl::ViewRemap< dst_type , src_type >( dst , src );
1389
//----------------------------------------------------------------------------
1390
//----------------------------------------------------------------------------
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
1397
create_mirror( const View<T,L,D,M,S> & src )
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 ;
1403
// 'view' is managed therefore we can allocate a
1404
// compatible host_view through the ordinary constructor.
1406
std::string label = memory_space::query_label( src.ptr_on_device() );
1407
label.append("_mirror");
1409
return host_view_type( label ,
1417
src.dimension_7() );
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
1426
create_mirror_view( const View<T,L,D,M,S> & src )
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
1437
create_mirror_view( const View<T,L,D,M,S> & src )
1439
return create_mirror( src );
1442
//----------------------------------------------------------------------------
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 >
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 )
1457
typedef View<T,L,D,M,S> view_type ;
1458
typedef typename view_type::memory_space memory_space ;
1460
const std::string label = memory_space::query_label( v.ptr_on_device() );
1462
view_type v_resized( label, n0, n1, n2, n3, n4, n5, n6, n7 );
1464
Impl::ViewRemap< view_type , view_type >( v_resized , v );
1469
/** \brief Reallocate a view without copying old data to new data */
1470
template< class T , class L , class D , class M , class S >
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 )
1482
typedef View<T,L,D,M,S> view_type ;
1483
typedef typename view_type::memory_space memory_space ;
1485
// Query the current label and reuse it.
1486
const std::string label = memory_space::query_label( v.ptr_on_device() );
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 );
1492
} // namespace Kokkos
1494
//----------------------------------------------------------------------------
1495
//----------------------------------------------------------------------------
1499
struct ALL { KOKKOS_INLINE_FUNCTION ALL(){} };
1501
template< class DstViewType ,
1502
class T , class L , class D , class M , class S ,
1504
KOKKOS_INLINE_FUNCTION
1506
subview( const View<T,L,D,M,S> & src ,
1507
const ArgType0 & arg0 )
1511
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst , src , arg0 );
1516
template< class DstViewType ,
1517
class T , class L , class D , class M , class S ,
1518
class ArgType0 , class ArgType1 >
1519
KOKKOS_INLINE_FUNCTION
1521
subview( const View<T,L,D,M,S> & src ,
1522
const ArgType0 & arg0 ,
1523
const ArgType1 & arg1 )
1527
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1 );
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
1537
subview( const View<T,L,D,M,S> & src ,
1538
const ArgType0 & arg0 ,
1539
const ArgType1 & arg1 ,
1540
const ArgType2 & arg2 )
1544
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2 );
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
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 )
1562
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3 );
1567
template< class DstViewType ,
1568
class T , class L , class D , class M , class S ,
1569
class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
1571
KOKKOS_INLINE_FUNCTION
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 )
1582
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4 );
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
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 )
1603
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4, arg5 );
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
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 )
1625
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4, arg5, arg6 );
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
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 )
1648
Impl::ViewAssignment<typename DstViewType::specialize,S>( dst, src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
1653
} // namespace Kokkos
1655
//----------------------------------------------------------------------------
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
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 )
1678
Impl::ViewSubview< View<D,A1,A2,A3,S>
1679
, ArgType0 , ArgType1 , ArgType2 , ArgType3
1680
, ArgType4 , ArgType5 , ArgType6 , ArgType7
1684
return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
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
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 )
1705
Impl::ViewSubview< View<D,A1,A2,A3,S>
1706
, ArgType0 , ArgType1 , ArgType2 , ArgType3
1707
, ArgType4 , ArgType5 , ArgType6 , void
1711
return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5, arg6 );
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
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 )
1731
Impl::ViewSubview< View<D,A1,A2,A3,S>
1732
, ArgType0 , ArgType1 , ArgType2 , ArgType3
1733
, ArgType4 , ArgType5 , void , void
1737
return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5 );
1740
template< class D , class A1 , class A2 , class A3 , class S ,
1741
class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
1743
KOKKOS_INLINE_FUNCTION
1744
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
1745
, ArgType0 , ArgType1 , ArgType2 , ArgType3
1746
, ArgType4 , void , void , void
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 )
1756
Impl::ViewSubview< View<D,A1,A2,A3,S>
1757
, ArgType0 , ArgType1 , ArgType2 , ArgType3
1758
, ArgType4 , void , void , void
1762
return DstViewType( src, arg0, arg1, arg2, arg3, arg4 );
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
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 )
1779
Impl::ViewSubview< View<D,A1,A2,A3,S>
1780
, ArgType0 , ArgType1 , ArgType2 , ArgType3
1781
, void , void , void , void
1785
return DstViewType( src, arg0, arg1, arg2, arg3 );
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
1795
subview( const View<D,A1,A2,A3,S> & src ,
1796
const ArgType0 & arg0 ,
1797
const ArgType1 & arg1 ,
1798
const ArgType2 & arg2 )
1801
Impl::ViewSubview< View<D,A1,A2,A3,S>
1802
, ArgType0 , ArgType1 , ArgType2 , void
1803
, void , void , void , void
1807
return DstViewType( src, arg0, arg1, arg2 );
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
1817
subview( const View<D,A1,A2,A3,S> & src ,
1818
const ArgType0 & arg0 ,
1819
const ArgType1 & arg1 )
1822
Impl::ViewSubview< View<D,A1,A2,A3,S>
1823
, ArgType0 , ArgType1 , void , void
1824
, void , void , void , void
1828
return DstViewType( src, arg0, arg1 );
1831
template< class D , class A1 , class A2 , class A3 , class S ,
1833
KOKKOS_INLINE_FUNCTION
1834
typename Impl::ViewSubview< View<D,A1,A2,A3,S>
1835
, ArgType0 , void , void , void
1836
, void , void , void , void
1838
subview( const View<D,A1,A2,A3,S> & src ,
1839
const ArgType0 & arg0 )
1842
Impl::ViewSubview< View<D,A1,A2,A3,S>
1843
, ArgType0 , void , void , void
1844
, void , void , void , void
1848
return DstViewType( src, arg0 );
1851
} // namespace Kokkos
1853
//----------------------------------------------------------------------------
1854
//----------------------------------------------------------------------------
1856
#include <impl/Kokkos_ViewDefault.hpp>
1857
#include <impl/Kokkos_Atomic_View.hpp>
1859
//----------------------------------------------------------------------------
1860
//----------------------------------------------------------------------------