forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kokkos_DynRankView.hpp
2438 lines (2159 loc) · 98.9 KB
/
Kokkos_DynRankView.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
/// \file Kokkos_DynRankView.hpp
/// \brief Declaration and definition of Kokkos::DynRankView.
///
/// This header file declares and defines Kokkos::DynRankView and its
/// related nonmember functions.
#ifndef KOKKOS_DYNRANKVIEW_HPP
#define KOKKOS_DYNRANKVIEW_HPP
#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
#define KOKKOS_IMPL_PUBLIC_INCLUDE
#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_DYNRANKVIEW
#endif
#include <Kokkos_Core.hpp>
#include <impl/Kokkos_Error.hpp>
#include <type_traits>
namespace Kokkos {
template <typename DataType, class... Properties>
class DynRankView; // forward declare
namespace Impl {
template <typename Specialize>
struct DynRankDimTraits {
enum : size_t { unspecified = KOKKOS_INVALID_INDEX };
// Compute the rank of the view from the nonzero dimension arguments.
KOKKOS_INLINE_FUNCTION
static size_t computeRank(const size_t N0, const size_t N1, const size_t N2,
const size_t N3, const size_t N4, const size_t N5,
const size_t N6, const size_t /* N7 */) {
return (
(N6 == unspecified && N5 == unspecified && N4 == unspecified &&
N3 == unspecified && N2 == unspecified && N1 == unspecified &&
N0 == unspecified)
? 0
: ((N6 == unspecified && N5 == unspecified && N4 == unspecified &&
N3 == unspecified && N2 == unspecified && N1 == unspecified)
? 1
: ((N6 == unspecified && N5 == unspecified &&
N4 == unspecified && N3 == unspecified &&
N2 == unspecified)
? 2
: ((N6 == unspecified && N5 == unspecified &&
N4 == unspecified && N3 == unspecified)
? 3
: ((N6 == unspecified && N5 == unspecified &&
N4 == unspecified)
? 4
: ((N6 == unspecified &&
N5 == unspecified)
? 5
: ((N6 == unspecified)
? 6
: 7)))))));
}
// Compute the rank of the view from the nonzero layout arguments.
template <typename Layout>
KOKKOS_INLINE_FUNCTION static size_t computeRank(const Layout& layout) {
return computeRank(layout.dimension[0], layout.dimension[1],
layout.dimension[2], layout.dimension[3],
layout.dimension[4], layout.dimension[5],
layout.dimension[6], layout.dimension[7]);
}
// Extra overload to match that for specialize types v2
template <typename Layout, typename... P>
KOKKOS_INLINE_FUNCTION static size_t computeRank(
const Kokkos::Impl::ViewCtorProp<P...>& /* prop */,
const Layout& layout) {
return computeRank(layout);
}
// Create the layout for the rank-7 view.
// Non-strided Layout
template <typename Layout>
KOKKOS_INLINE_FUNCTION static std::enable_if_t<
(std::is_same<Layout, Kokkos::LayoutRight>::value ||
std::is_same<Layout, Kokkos::LayoutLeft>::value),
Layout>
createLayout(const Layout& layout) {
return Layout(layout.dimension[0] != unspecified ? layout.dimension[0] : 1,
layout.dimension[1] != unspecified ? layout.dimension[1] : 1,
layout.dimension[2] != unspecified ? layout.dimension[2] : 1,
layout.dimension[3] != unspecified ? layout.dimension[3] : 1,
layout.dimension[4] != unspecified ? layout.dimension[4] : 1,
layout.dimension[5] != unspecified ? layout.dimension[5] : 1,
layout.dimension[6] != unspecified ? layout.dimension[6] : 1,
layout.dimension[7] != unspecified ? layout.dimension[7] : 1);
}
// LayoutStride
template <typename Layout>
KOKKOS_INLINE_FUNCTION static std::enable_if_t<
(std::is_same<Layout, Kokkos::LayoutStride>::value), Layout>
createLayout(const Layout& layout) {
return Layout(layout.dimension[0] != unspecified ? layout.dimension[0] : 1,
layout.stride[0],
layout.dimension[1] != unspecified ? layout.dimension[1] : 1,
layout.stride[1],
layout.dimension[2] != unspecified ? layout.dimension[2] : 1,
layout.stride[2],
layout.dimension[3] != unspecified ? layout.dimension[3] : 1,
layout.stride[3],
layout.dimension[4] != unspecified ? layout.dimension[4] : 1,
layout.stride[4],
layout.dimension[5] != unspecified ? layout.dimension[5] : 1,
layout.stride[5],
layout.dimension[6] != unspecified ? layout.dimension[6] : 1,
layout.stride[6],
layout.dimension[7] != unspecified ? layout.dimension[7] : 1,
layout.stride[7]);
}
// Extra overload to match that for specialize types
template <typename Traits, typename... P>
KOKKOS_INLINE_FUNCTION static std::enable_if_t<
(std::is_same<typename Traits::array_layout,
Kokkos::LayoutRight>::value ||
std::is_same<typename Traits::array_layout, Kokkos::LayoutLeft>::value ||
std::is_same<typename Traits::array_layout,
Kokkos::LayoutStride>::value),
typename Traits::array_layout>
createLayout(const Kokkos::Impl::ViewCtorProp<P...>& /* prop */,
const typename Traits::array_layout& layout) {
return createLayout(layout);
}
// Create a view from the given dimension arguments.
// This is only necessary because the shmem constructor doesn't take a layout.
// NDE shmem View's are not compatible with the added view_alloc value_type
// / fad_dim deduction functionality
template <typename ViewType, typename ViewArg>
static ViewType createView(const ViewArg& arg, const size_t N0,
const size_t N1, const size_t N2, const size_t N3,
const size_t N4, const size_t N5, const size_t N6,
const size_t N7) {
return ViewType(arg, N0 != unspecified ? N0 : 1, N1 != unspecified ? N1 : 1,
N2 != unspecified ? N2 : 1, N3 != unspecified ? N3 : 1,
N4 != unspecified ? N4 : 1, N5 != unspecified ? N5 : 1,
N6 != unspecified ? N6 : 1, N7 != unspecified ? N7 : 1);
}
};
// Non-strided Layout
template <typename Layout, typename iType>
KOKKOS_INLINE_FUNCTION static std::enable_if_t<
(std::is_same<Layout, Kokkos::LayoutRight>::value ||
std::is_same<Layout, Kokkos::LayoutLeft>::value) &&
std::is_integral<iType>::value,
Layout>
reconstructLayout(const Layout& layout, iType dynrank) {
return Layout(dynrank > 0 ? layout.dimension[0] : KOKKOS_INVALID_INDEX,
dynrank > 1 ? layout.dimension[1] : KOKKOS_INVALID_INDEX,
dynrank > 2 ? layout.dimension[2] : KOKKOS_INVALID_INDEX,
dynrank > 3 ? layout.dimension[3] : KOKKOS_INVALID_INDEX,
dynrank > 4 ? layout.dimension[4] : KOKKOS_INVALID_INDEX,
dynrank > 5 ? layout.dimension[5] : KOKKOS_INVALID_INDEX,
dynrank > 6 ? layout.dimension[6] : KOKKOS_INVALID_INDEX,
dynrank > 7 ? layout.dimension[7] : KOKKOS_INVALID_INDEX);
}
// LayoutStride
template <typename Layout, typename iType>
KOKKOS_INLINE_FUNCTION static std::enable_if_t<
(std::is_same<Layout, Kokkos::LayoutStride>::value) &&
std::is_integral<iType>::value,
Layout>
reconstructLayout(const Layout& layout, iType dynrank) {
return Layout(dynrank > 0 ? layout.dimension[0] : KOKKOS_INVALID_INDEX,
dynrank > 0 ? layout.stride[0] : (0),
dynrank > 1 ? layout.dimension[1] : KOKKOS_INVALID_INDEX,
dynrank > 1 ? layout.stride[1] : (0),
dynrank > 2 ? layout.dimension[2] : KOKKOS_INVALID_INDEX,
dynrank > 2 ? layout.stride[2] : (0),
dynrank > 3 ? layout.dimension[3] : KOKKOS_INVALID_INDEX,
dynrank > 3 ? layout.stride[3] : (0),
dynrank > 4 ? layout.dimension[4] : KOKKOS_INVALID_INDEX,
dynrank > 4 ? layout.stride[4] : (0),
dynrank > 5 ? layout.dimension[5] : KOKKOS_INVALID_INDEX,
dynrank > 5 ? layout.stride[5] : (0),
dynrank > 6 ? layout.dimension[6] : KOKKOS_INVALID_INDEX,
dynrank > 6 ? layout.stride[6] : (0),
dynrank > 7 ? layout.dimension[7] : KOKKOS_INVALID_INDEX,
dynrank > 7 ? layout.stride[7] : (0));
}
/** \brief Debug bounds-checking routines */
// Enhanced debug checking - most infrastructure matches that of functions in
// Kokkos_ViewMapping; additional checks for extra arguments beyond rank are 0
template <unsigned, typename iType0, class MapType>
KOKKOS_INLINE_FUNCTION bool dyn_rank_view_verify_operator_bounds(
const iType0&, const MapType&) {
return true;
}
template <unsigned R, typename iType0, class MapType, typename iType1,
class... Args>
KOKKOS_INLINE_FUNCTION bool dyn_rank_view_verify_operator_bounds(
const iType0& rank, const MapType& map, const iType1& i, Args... args) {
if (static_cast<iType0>(R) < rank) {
return (size_t(i) < map.extent(R)) &&
dyn_rank_view_verify_operator_bounds<R + 1>(rank, map, args...);
} else if (i != 0) {
Kokkos::printf(
"DynRankView Debug Bounds Checking Error: at rank %u\n Extra "
"arguments beyond the rank must be zero \n",
R);
return (false) &&
dyn_rank_view_verify_operator_bounds<R + 1>(rank, map, args...);
} else {
return (true) &&
dyn_rank_view_verify_operator_bounds<R + 1>(rank, map, args...);
}
}
template <unsigned, class MapType>
inline void dyn_rank_view_error_operator_bounds(char*, int, const MapType&) {}
template <unsigned R, class MapType, class iType, class... Args>
inline void dyn_rank_view_error_operator_bounds(char* buf, int len,
const MapType& map,
const iType& i, Args... args) {
const int n = snprintf(
buf, len, " %ld < %ld %c", static_cast<unsigned long>(i),
static_cast<unsigned long>(map.extent(R)), (sizeof...(Args) ? ',' : ')'));
dyn_rank_view_error_operator_bounds<R + 1>(buf + n, len - n, map, args...);
}
// op_rank = rank of the operator version that was called
template <typename MemorySpace, typename iType0, typename iType1, class MapType,
class... Args>
KOKKOS_INLINE_FUNCTION void dyn_rank_view_verify_operator_bounds(
const iType0& op_rank, const iType1& rank,
const Kokkos::Impl::SharedAllocationTracker& tracker, const MapType& map,
Args... args) {
if (static_cast<iType0>(rank) > op_rank) {
Kokkos::abort(
"DynRankView Bounds Checking Error: Need at least rank arguments to "
"the operator()");
}
if (!dyn_rank_view_verify_operator_bounds<0>(rank, map, args...)) {
KOKKOS_IF_ON_HOST(
(enum {LEN = 1024}; char buffer[LEN];
const std::string label = tracker.template get_label<MemorySpace>();
int n = snprintf(buffer, LEN, "DynRankView bounds error of view %s (",
label.c_str());
dyn_rank_view_error_operator_bounds<0>(buffer + n, LEN - n, map,
args...);
Kokkos::Impl::throw_runtime_exception(std::string(buffer));))
KOKKOS_IF_ON_DEVICE(
((void)tracker; Kokkos::abort("DynRankView bounds error");))
}
}
/** \brief Assign compatible default mappings */
struct ViewToDynRankViewTag {};
} // namespace Impl
namespace Impl {
template <class DstTraits, class SrcTraits>
class ViewMapping<
DstTraits, SrcTraits,
std::enable_if_t<(std::is_same<typename DstTraits::memory_space,
typename SrcTraits::memory_space>::value &&
std::is_void<typename DstTraits::specialize>::value &&
std::is_void<typename SrcTraits::specialize>::value &&
(std::is_same<typename DstTraits::array_layout,
typename SrcTraits::array_layout>::value ||
((std::is_same<typename DstTraits::array_layout,
Kokkos::LayoutLeft>::value ||
std::is_same<typename DstTraits::array_layout,
Kokkos::LayoutRight>::value ||
std::is_same<typename DstTraits::array_layout,
Kokkos::LayoutStride>::value) &&
(std::is_same<typename SrcTraits::array_layout,
Kokkos::LayoutLeft>::value ||
std::is_same<typename SrcTraits::array_layout,
Kokkos::LayoutRight>::value ||
std::is_same<typename SrcTraits::array_layout,
Kokkos::LayoutStride>::value)))),
Kokkos::Impl::ViewToDynRankViewTag>> {
private:
enum {
is_assignable_value_type =
std::is_same<typename DstTraits::value_type,
typename SrcTraits::value_type>::value ||
std::is_same<typename DstTraits::value_type,
typename SrcTraits::const_value_type>::value
};
enum {
is_assignable_layout =
std::is_same<typename DstTraits::array_layout,
typename SrcTraits::array_layout>::value ||
std::is_same<typename DstTraits::array_layout,
Kokkos::LayoutStride>::value
};
public:
enum { is_assignable = is_assignable_value_type && is_assignable_layout };
using DstType = ViewMapping<DstTraits, typename DstTraits::specialize>;
using SrcType = ViewMapping<SrcTraits, typename SrcTraits::specialize>;
template <typename DT, typename... DP, typename ST, typename... SP>
KOKKOS_INLINE_FUNCTION static void assign(
Kokkos::DynRankView<DT, DP...>& dst, const Kokkos::View<ST, SP...>& src) {
static_assert(
is_assignable_value_type,
"View assignment must have same value type or const = non-const");
static_assert(
is_assignable_layout,
"View assignment must have compatible layout or have rank <= 1");
// Removed dimension checks...
using dst_offset_type = typename DstType::offset_type;
dst.m_map.m_impl_offset = dst_offset_type(
std::integral_constant<unsigned, 0>(),
src.layout()); // Check this for integer input1 for padding, etc
dst.m_map.m_impl_handle = Kokkos::Impl::ViewDataHandle<DstTraits>::assign(
src.m_map.m_impl_handle, src.m_track.m_tracker);
dst.m_track.assign(src.m_track.m_tracker, DstTraits::is_managed);
dst.m_rank = Kokkos::View<ST, SP...>::rank();
}
};
} // namespace Impl
/* \class DynRankView
* \brief Container that creates a Kokkos view with rank determined at runtime.
* Essentially this is a rank 7 view
*
* Changes from View
* 1. The rank of the DynRankView is returned by the method rank()
* 2. Max rank of a DynRankView is 7
* 3. subview called with 'subview(...)' or 'subdynrankview(...)' (backward
* compatibility)
* 4. Every subview is returned with LayoutStride
* 5. Copy and Copy-Assign View to DynRankView
* 6. deep_copy between Views and DynRankViews
* 7. rank( view ); returns the rank of View or DynRankView
*
*/
template <class>
struct is_dyn_rank_view : public std::false_type {};
template <class D, class... P>
struct is_dyn_rank_view<Kokkos::DynRankView<D, P...>> : public std::true_type {
};
template <class T>
inline constexpr bool is_dyn_rank_view_v = is_dyn_rank_view<T>::value;
template <typename DataType, class... Properties>
class DynRankView : public ViewTraits<DataType, Properties...> {
static_assert(!std::is_array<DataType>::value &&
!std::is_pointer<DataType>::value,
"Cannot template DynRankView with array or pointer datatype - "
"must be pod");
private:
template <class, class...>
friend class DynRankView;
template <class, class...>
friend class Kokkos::Impl::ViewMapping;
public:
using drvtraits = ViewTraits<DataType, Properties...>;
using view_type = View<DataType*******, Properties...>;
using traits = ViewTraits<DataType*******, Properties...>;
private:
using map_type =
Kokkos::Impl::ViewMapping<traits, typename traits::specialize>;
using track_type = Kokkos::Impl::SharedAllocationTracker;
track_type m_track;
map_type m_map;
unsigned m_rank;
public:
KOKKOS_INLINE_FUNCTION
view_type& DownCast() const { return (view_type&)(*this); }
KOKKOS_INLINE_FUNCTION
const view_type& ConstDownCast() const { return (const view_type&)(*this); }
// Types below - at least the HostMirror requires the value_type, NOT the rank
// 7 data_type of the traits
/** \brief Compatible view of array of scalar types */
using array_type = DynRankView<
typename drvtraits::scalar_array_type, typename drvtraits::array_layout,
typename drvtraits::device_type, typename drvtraits::memory_traits>;
/** \brief Compatible view of const data type */
using const_type = DynRankView<
typename drvtraits::const_data_type, typename drvtraits::array_layout,
typename drvtraits::device_type, typename drvtraits::memory_traits>;
/** \brief Compatible view of non-const data type */
using non_const_type = DynRankView<
typename drvtraits::non_const_data_type, typename drvtraits::array_layout,
typename drvtraits::device_type, typename drvtraits::memory_traits>;
/** \brief Compatible HostMirror view */
using HostMirror = DynRankView<typename drvtraits::non_const_data_type,
typename drvtraits::array_layout,
typename drvtraits::host_mirror_space>;
//----------------------------------------
// Domain rank and extents
// enum { Rank = map_type::Rank }; //Will be dyn rank of 7 always, keep the
// enum?
template <typename iType>
KOKKOS_INLINE_FUNCTION constexpr std::enable_if_t<
std::is_integral<iType>::value, size_t>
extent(const iType& r) const {
return m_map.extent(r);
}
template <typename iType>
KOKKOS_INLINE_FUNCTION constexpr std::enable_if_t<
std::is_integral<iType>::value, int>
extent_int(const iType& r) const {
return static_cast<int>(m_map.extent(r));
}
KOKKOS_INLINE_FUNCTION constexpr typename traits::array_layout layout() const;
//----------------------------------------
/* Deprecate all 'dimension' functions in favor of
* ISO/C++ vocabulary 'extent'.
*/
KOKKOS_INLINE_FUNCTION constexpr size_t size() const {
return m_map.extent(0) * m_map.extent(1) * m_map.extent(2) *
m_map.extent(3) * m_map.extent(4) * m_map.extent(5) *
m_map.extent(6) * m_map.extent(7);
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const {
return m_map.stride_0();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const {
return m_map.stride_1();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const {
return m_map.stride_2();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const {
return m_map.stride_3();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const {
return m_map.stride_4();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const {
return m_map.stride_5();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const {
return m_map.stride_6();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const {
return m_map.stride_7();
}
template <typename iType>
KOKKOS_INLINE_FUNCTION void stride(iType* const s) const {
m_map.stride(s);
}
//----------------------------------------
// Range span is the span which contains all members.
using reference_type = typename map_type::reference_type;
using pointer_type = typename map_type::pointer_type;
enum {
reference_type_is_lvalue_reference =
std::is_lvalue_reference<reference_type>::value
};
KOKKOS_INLINE_FUNCTION constexpr size_t span() const { return m_map.span(); }
KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const {
return m_map.span_is_contiguous();
}
KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const {
return m_map.data();
}
KOKKOS_INLINE_FUNCTION constexpr bool is_allocated() const {
return (m_map.data() != nullptr);
}
//----------------------------------------
// Allow specializations to query their specialized map
KOKKOS_INLINE_FUNCTION
const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
impl_map() const {
return m_map;
}
//----------------------------------------
private:
enum {
is_layout_left =
std::is_same<typename traits::array_layout, Kokkos::LayoutLeft>::value,
is_layout_right =
std::is_same<typename traits::array_layout, Kokkos::LayoutRight>::value,
is_layout_stride = std::is_same<typename traits::array_layout,
Kokkos::LayoutStride>::value,
is_default_map = std::is_void<typename traits::specialize>::value &&
(is_layout_left || is_layout_right || is_layout_stride)
};
// Bounds checking macros
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
// rank of the calling operator - included as first argument in ARG
#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
Kokkos::Impl::runtime_check_memory_access_violation< \
typename traits::memory_space>( \
"Kokkos::DynRankView ERROR: attempt to access inaccessible memory " \
"space"); \
Kokkos::Impl::dyn_rank_view_verify_operator_bounds< \
typename traits::memory_space> \
ARG;
#else
#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
Kokkos::Impl::runtime_check_memory_access_violation< \
typename traits::memory_space>( \
"Kokkos::DynRankView ERROR: attempt to access inaccessible memory " \
"space");
#endif
public:
KOKKOS_INLINE_FUNCTION
constexpr unsigned rank() const { return m_rank; }
// operators ()
// Rank 0
KOKKOS_INLINE_FUNCTION
reference_type operator()() const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((0, this->rank(), m_track, m_map))
return impl_map().reference();
// return m_map.reference(0,0,0,0,0,0,0);
}
// Rank 1
// This assumes a contiguous underlying memory (i.e. no padding, no
// striding...)
template <typename iType>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
std::is_same<typename drvtraits::value_type,
typename drvtraits::scalar_array_type>::value &&
std::is_integral<iType>::value,
reference_type>
operator[](const iType& i0) const {
// Phalanx is violating this, since they use the operator to access ALL
// elements in the allocation KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 ,
// this->rank(), m_track, m_map) )
return data()[i0];
}
// This assumes a contiguous underlying memory (i.e. no padding, no
// striding... AND a Trilinos/Sacado scalar type )
template <typename iType>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
!std::is_same<typename drvtraits::value_type,
typename drvtraits::scalar_array_type>::value &&
std::is_integral<iType>::value,
reference_type>
operator[](const iType& i0) const {
// auto map = impl_map();
const size_t dim_scalar = m_map.dimension_scalar();
const size_t bytes = this->span() / dim_scalar;
using tmp_view_type = Kokkos::View<
DataType*, typename traits::array_layout, typename traits::device_type,
Kokkos::MemoryTraits<traits::memory_traits::is_unmanaged |
traits::memory_traits::is_random_access |
traits::memory_traits::is_atomic>>;
tmp_view_type rankone_view(this->data(), bytes, dim_scalar);
return rankone_view(i0);
}
// Rank 1 parenthesis
template <typename iType>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType>::value),
reference_type>
operator()(const iType& i0) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
return m_map.reference(i0);
}
template <typename iType>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType>::value),
reference_type>
operator()(const iType& i0) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
return m_map.reference(i0, 0, 0, 0, 0, 0, 0);
}
// Rank 2
template <typename iType0, typename iType1>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
return m_map.reference(i0, i1);
}
template <typename iType0, typename iType1>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
return m_map.reference(i0, i1, 0, 0, 0, 0, 0);
}
// Rank 3
template <typename iType0, typename iType1, typename iType2>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(3, this->rank(), m_track, m_map, i0, i1, i2))
return m_map.reference(i0, i1, i2);
}
template <typename iType0, typename iType1, typename iType2>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(3, this->rank(), m_track, m_map, i0, i1, i2))
return m_map.reference(i0, i1, i2, 0, 0, 0, 0);
}
// Rank 4
template <typename iType0, typename iType1, typename iType2, typename iType3>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(4, this->rank(), m_track, m_map, i0, i1, i2, i3))
return m_map.reference(i0, i1, i2, i3);
}
template <typename iType0, typename iType1, typename iType2, typename iType3>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(4, this->rank(), m_track, m_map, i0, i1, i2, i3))
return m_map.reference(i0, i1, i2, i3, 0, 0, 0);
}
// Rank 5
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
std::is_integral<iType4>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3, const iType4& i4) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
return m_map.reference(i0, i1, i2, i3, i4);
}
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3, const iType4& i4) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
return m_map.reference(i0, i1, i2, i3, i4, 0, 0);
}
// Rank 6
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4, typename iType5>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
std::is_integral<iType4>::value && std::is_integral<iType5>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3, const iType4& i4, const iType5& i5) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
return m_map.reference(i0, i1, i2, i3, i4, i5);
}
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4, typename iType5>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3, const iType4& i4, const iType5& i5) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
return m_map.reference(i0, i1, i2, i3, i4, i5, 0);
}
// Rank 7
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4, typename iType5, typename iType6>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
std::is_integral<iType4>::value && std::is_integral<iType5>::value &&
std::is_integral<iType6>::value),
reference_type>
operator()(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3, const iType4& i4, const iType5& i5,
const iType6& i6) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(7, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
}
// Rank 0
KOKKOS_INLINE_FUNCTION
reference_type access() const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((0, this->rank(), m_track, m_map))
return impl_map().reference();
// return m_map.reference(0,0,0,0,0,0,0);
}
// Rank 1
// Rank 1 parenthesis
template <typename iType>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType>::value),
reference_type>
access(const iType& i0) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
return m_map.reference(i0);
}
template <typename iType>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType>::value),
reference_type>
access(const iType& i0) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
return m_map.reference(i0, 0, 0, 0, 0, 0, 0);
}
// Rank 2
template <typename iType0, typename iType1>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value),
reference_type>
access(const iType0& i0, const iType1& i1) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
return m_map.reference(i0, i1);
}
template <typename iType0, typename iType1>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
access(const iType0& i0, const iType1& i1) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
return m_map.reference(i0, i1, 0, 0, 0, 0, 0);
}
// Rank 3
template <typename iType0, typename iType1, typename iType2>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(3, this->rank(), m_track, m_map, i0, i1, i2))
return m_map.reference(i0, i1, i2);
}
template <typename iType0, typename iType1, typename iType2>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(3, this->rank(), m_track, m_map, i0, i1, i2))
return m_map.reference(i0, i1, i2, 0, 0, 0, 0);
}
// Rank 4
template <typename iType0, typename iType1, typename iType2, typename iType3>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(4, this->rank(), m_track, m_map, i0, i1, i2, i3))
return m_map.reference(i0, i1, i2, i3);
}
template <typename iType0, typename iType1, typename iType2, typename iType3>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(4, this->rank(), m_track, m_map, i0, i1, i2, i3))
return m_map.reference(i0, i1, i2, i3, 0, 0, 0);
}
// Rank 5
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
std::is_integral<iType4>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
const iType4& i4) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
return m_map.reference(i0, i1, i2, i3, i4);
}
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3, const iType4& i4) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
return m_map.reference(i0, i1, i2, i3, i4, 0, 0);
}
// Rank 6
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4, typename iType5>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_void<typename traits::specialize>::value &&
std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
std::is_integral<iType4>::value && std::is_integral<iType5>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
const iType4& i4, const iType5& i5) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
return m_map.reference(i0, i1, i2, i3, i4, i5);
}
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4, typename iType5>
KOKKOS_INLINE_FUNCTION
std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
std::is_integral<iType0>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2,
const iType3& i3, const iType4& i4, const iType5& i5) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
return m_map.reference(i0, i1, i2, i3, i4, i5, 0);
}
// Rank 7
template <typename iType0, typename iType1, typename iType2, typename iType3,
typename iType4, typename iType5, typename iType6>
KOKKOS_INLINE_FUNCTION std::enable_if_t<
(std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
std::is_integral<iType4>::value && std::is_integral<iType5>::value &&
std::is_integral<iType6>::value),
reference_type>
access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
const iType4& i4, const iType5& i5, const iType6& i6) const {
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
(7, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
}
#undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
//----------------------------------------
// Standard constructor, destructor, and assignment operators...
KOKKOS_DEFAULTED_FUNCTION
~DynRankView() = default;
KOKKOS_INLINE_FUNCTION
DynRankView() : m_track(), m_map(), m_rank() {} // Default ctor
KOKKOS_INLINE_FUNCTION
DynRankView(const DynRankView& rhs)
: m_track(rhs.m_track), m_map(rhs.m_map), m_rank(rhs.m_rank) {}
KOKKOS_INLINE_FUNCTION
DynRankView(DynRankView&& rhs)
: m_track(rhs.m_track), m_map(rhs.m_map), m_rank(rhs.m_rank) {}
KOKKOS_INLINE_FUNCTION
DynRankView& operator=(const DynRankView& rhs) {
m_track = rhs.m_track;
m_map = rhs.m_map;
m_rank = rhs.m_rank;
return *this;
}
KOKKOS_INLINE_FUNCTION
DynRankView& operator=(DynRankView&& rhs) {
m_track = rhs.m_track;
m_map = rhs.m_map;
m_rank = rhs.m_rank;
return *this;
}
//----------------------------------------