forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kokkos_ViewMapping.hpp
3685 lines (3256 loc) · 137 KB
/
Kokkos_ViewMapping.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
#ifndef KOKKOS_EXPERIMENTAL_VIEW_MAPPING_HPP
#define KOKKOS_EXPERIMENTAL_VIEW_MAPPING_HPP
#include <type_traits>
#include <initializer_list>
#include <Kokkos_Core_fwd.hpp>
#include <Kokkos_DetectionIdiom.hpp>
#include <Kokkos_Pair.hpp>
#include <Kokkos_Layout.hpp>
#include <Kokkos_Extents.hpp>
#include <impl/Kokkos_Error.hpp>
#include <impl/Kokkos_Traits.hpp>
#include <impl/Kokkos_ViewTracker.hpp>
#include <impl/Kokkos_ViewCtor.hpp>
#include <impl/Kokkos_Atomic_View.hpp>
#include <impl/Kokkos_Tools.hpp>
#include <impl/Kokkos_StringManipulation.hpp>
#include <impl/Kokkos_ZeroMemset_fwd.hpp>
#include <impl/Kokkos_ViewDataAnalysis.hpp>
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
namespace Kokkos {
struct ALL_t {
KOKKOS_INLINE_FUNCTION
constexpr const ALL_t& operator()() const { return *this; }
KOKKOS_INLINE_FUNCTION
constexpr bool operator==(const ALL_t&) const { return true; }
};
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
namespace Impl {
// TODO This alias declaration forces us to fully qualify ALL_t inside the
// Kokkos::Impl namespace to avoid deprecation warnings. Replace the
// fully-qualified name when we remove Kokkos::Impl::ALL_t.
using ALL_t KOKKOS_DEPRECATED_WITH_COMMENT("Use Kokkos::ALL_t instead!") =
Kokkos::ALL_t;
} // namespace Impl
#endif
} // namespace Kokkos
namespace Kokkos {
namespace Impl {
template <class T>
struct is_integral_extent_type {
enum : bool { value = std::is_same<T, Kokkos::ALL_t>::value ? 1 : 0 };
};
template <class iType>
struct is_integral_extent_type<std::pair<iType, iType>> {
enum : bool { value = std::is_integral<iType>::value ? 1 : 0 };
};
template <class iType>
struct is_integral_extent_type<Kokkos::pair<iType, iType>> {
enum : bool { value = std::is_integral<iType>::value ? 1 : 0 };
};
// Assuming '2 == initializer_list<iType>::size()'
template <class iType>
struct is_integral_extent_type<std::initializer_list<iType>> {
enum : bool { value = std::is_integral<iType>::value ? 1 : 0 };
};
template <unsigned I, class... Args>
struct is_integral_extent {
// get_type is void when sizeof...(Args) <= I
using type = std::remove_cv_t<std::remove_reference_t<
typename Kokkos::Impl::get_type<I, Args...>::type>>;
enum : bool { value = is_integral_extent_type<type>::value };
static_assert(value || std::is_integral<type>::value ||
std::is_void<type>::value,
"subview argument must be either integral or integral extent");
};
// Rules for subview arguments and layouts matching
template <class LayoutDest, class LayoutSrc, int RankDest, int RankSrc,
int CurrentArg, class... SubViewArgs>
struct SubviewLegalArgsCompileTime;
// Rules which allow LayoutLeft to LayoutLeft assignment
template <int RankDest, int RankSrc, int CurrentArg, class Arg,
class... SubViewArgs>
struct SubviewLegalArgsCompileTime<Kokkos::LayoutLeft, Kokkos::LayoutLeft,
RankDest, RankSrc, CurrentArg, Arg,
SubViewArgs...> {
enum {
value = (((CurrentArg == RankDest - 1) &&
(Kokkos::Impl::is_integral_extent_type<Arg>::value)) ||
((CurrentArg >= RankDest) && (std::is_integral<Arg>::value)) ||
((CurrentArg < RankDest) &&
(std::is_same<Arg, Kokkos::ALL_t>::value)) ||
((CurrentArg == 0) &&
(Kokkos::Impl::is_integral_extent_type<Arg>::value))) &&
(SubviewLegalArgsCompileTime<Kokkos::LayoutLeft, Kokkos::LayoutLeft,
RankDest, RankSrc, CurrentArg + 1,
SubViewArgs...>::value)
};
};
template <int RankDest, int RankSrc, int CurrentArg, class Arg>
struct SubviewLegalArgsCompileTime<Kokkos::LayoutLeft, Kokkos::LayoutLeft,
RankDest, RankSrc, CurrentArg, Arg> {
enum {
value = ((CurrentArg == RankDest - 1) || (std::is_integral<Arg>::value)) &&
(CurrentArg == RankSrc - 1)
};
};
// Rules which allow LayoutRight to LayoutRight assignment
template <int RankDest, int RankSrc, int CurrentArg, class Arg,
class... SubViewArgs>
struct SubviewLegalArgsCompileTime<Kokkos::LayoutRight, Kokkos::LayoutRight,
RankDest, RankSrc, CurrentArg, Arg,
SubViewArgs...> {
enum {
value = (((CurrentArg == RankSrc - RankDest) &&
(Kokkos::Impl::is_integral_extent_type<Arg>::value)) ||
((CurrentArg < RankSrc - RankDest) &&
(std::is_integral<Arg>::value)) ||
((CurrentArg >= RankSrc - RankDest) &&
(std::is_same<Arg, Kokkos::ALL_t>::value))) &&
(SubviewLegalArgsCompileTime<Kokkos::LayoutRight,
Kokkos::LayoutRight, RankDest, RankSrc,
CurrentArg + 1, SubViewArgs...>::value)
};
};
template <int RankDest, int RankSrc, int CurrentArg, class Arg>
struct SubviewLegalArgsCompileTime<Kokkos::LayoutRight, Kokkos::LayoutRight,
RankDest, RankSrc, CurrentArg, Arg> {
enum {
value = ((CurrentArg == RankSrc - 1) &&
(std::is_same<Arg, Kokkos::ALL_t>::value))
};
};
// Rules which allow assignment to LayoutStride
template <int RankDest, int RankSrc, int CurrentArg, class... SubViewArgs>
struct SubviewLegalArgsCompileTime<Kokkos::LayoutStride, Kokkos::LayoutLeft,
RankDest, RankSrc, CurrentArg,
SubViewArgs...> {
enum : bool { value = true };
};
template <int RankDest, int RankSrc, int CurrentArg, class... SubViewArgs>
struct SubviewLegalArgsCompileTime<Kokkos::LayoutStride, Kokkos::LayoutRight,
RankDest, RankSrc, CurrentArg,
SubViewArgs...> {
enum : bool { value = true };
};
template <int RankDest, int RankSrc, int CurrentArg, class... SubViewArgs>
struct SubviewLegalArgsCompileTime<Kokkos::LayoutStride, Kokkos::LayoutStride,
RankDest, RankSrc, CurrentArg,
SubViewArgs...> {
enum : bool { value = true };
};
template <unsigned DomainRank, unsigned RangeRank>
struct SubviewExtents {
private:
// Cannot declare zero-length arrays
// '+' is used to silence GCC 7.2.0 -Wduplicated-branches warning when
// RangeRank=1
enum { InternalRangeRank = RangeRank ? RangeRank : +1u };
size_t m_begin[DomainRank];
size_t m_length[InternalRangeRank];
unsigned m_index[InternalRangeRank];
template <size_t... DimArgs>
KOKKOS_FORCEINLINE_FUNCTION bool set(unsigned, unsigned,
const ViewDimension<DimArgs...>&) {
return true;
}
template <class T, size_t... DimArgs, class... Args>
KOKKOS_FORCEINLINE_FUNCTION bool set(unsigned domain_rank,
unsigned range_rank,
const ViewDimension<DimArgs...>& dim,
const T& val, Args... args) {
const size_t v = static_cast<size_t>(val);
m_begin[domain_rank] = v;
return set(domain_rank + 1, range_rank, dim, args...)
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
&& (v < dim.extent(domain_rank))
#endif
;
}
// ALL_t
template <size_t... DimArgs, class... Args>
KOKKOS_FORCEINLINE_FUNCTION bool set(unsigned domain_rank,
unsigned range_rank,
const ViewDimension<DimArgs...>& dim,
Kokkos::ALL_t, Args... args) {
m_begin[domain_rank] = 0;
m_length[range_rank] = dim.extent(domain_rank);
m_index[range_rank] = domain_rank;
return set(domain_rank + 1, range_rank + 1, dim, args...);
}
// std::pair range
template <class T, size_t... DimArgs, class... Args>
KOKKOS_FORCEINLINE_FUNCTION bool set(unsigned domain_rank,
unsigned range_rank,
const ViewDimension<DimArgs...>& dim,
const std::pair<T, T>& val,
Args... args) {
const size_t b = static_cast<size_t>(val.first);
const size_t e = static_cast<size_t>(val.second);
m_begin[domain_rank] = b;
m_length[range_rank] = e - b;
m_index[range_rank] = domain_rank;
return set(domain_rank + 1, range_rank + 1, dim, args...)
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
&& (e <= b + dim.extent(domain_rank))
#endif
;
}
// Kokkos::pair range
template <class T, size_t... DimArgs, class... Args>
KOKKOS_FORCEINLINE_FUNCTION bool set(unsigned domain_rank,
unsigned range_rank,
const ViewDimension<DimArgs...>& dim,
const Kokkos::pair<T, T>& val,
Args... args) {
const size_t b = static_cast<size_t>(val.first);
const size_t e = static_cast<size_t>(val.second);
m_begin[domain_rank] = b;
m_length[range_rank] = e - b;
m_index[range_rank] = domain_rank;
return set(domain_rank + 1, range_rank + 1, dim, args...)
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
&& (e <= b + dim.extent(domain_rank))
#endif
;
}
// { begin , end } range
template <class T, size_t... DimArgs, class... Args>
KOKKOS_FORCEINLINE_FUNCTION bool set(unsigned domain_rank,
unsigned range_rank,
const ViewDimension<DimArgs...>& dim,
const std::initializer_list<T>& val,
Args... args) {
const size_t b = static_cast<size_t>(val.begin()[0]);
const size_t e = static_cast<size_t>(val.begin()[1]);
m_begin[domain_rank] = b;
m_length[range_rank] = e - b;
m_index[range_rank] = domain_rank;
return set(domain_rank + 1, range_rank + 1, dim, args...)
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
&& (val.size() == 2) && (e <= b + dim.extent(domain_rank))
#endif
;
}
//------------------------------
#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
template <size_t... DimArgs>
void error(char*, int, unsigned, unsigned,
const ViewDimension<DimArgs...>&) const {}
template <class T, size_t... DimArgs, class... Args>
void error(char* buf, int buf_len, unsigned domain_rank, unsigned range_rank,
const ViewDimension<DimArgs...>& dim, const T& val,
Args... args) const {
const int n = std::min(
buf_len,
snprintf(buf, buf_len, " %lu < %lu %c", static_cast<unsigned long>(val),
static_cast<unsigned long>(dim.extent(domain_rank)),
int(sizeof...(Args) ? ',' : ')')));
error(buf + n, buf_len - n, domain_rank + 1, range_rank, dim, args...);
}
// std::pair range
template <size_t... DimArgs, class... Args>
void error(char* buf, int buf_len, unsigned domain_rank, unsigned range_rank,
const ViewDimension<DimArgs...>& dim, Kokkos::ALL_t,
Args... args) const {
const int n = std::min(buf_len, snprintf(buf, buf_len, " Kokkos::ALL %c",
int(sizeof...(Args) ? ',' : ')')));
error(buf + n, buf_len - n, domain_rank + 1, range_rank + 1, dim, args...);
}
// std::pair range
template <class T, size_t... DimArgs, class... Args>
void error(char* buf, int buf_len, unsigned domain_rank, unsigned range_rank,
const ViewDimension<DimArgs...>& dim, const std::pair<T, T>& val,
Args... args) const {
// d <= e - b
const int n = std::min(
buf_len, snprintf(buf, buf_len, " %lu <= %lu - %lu %c",
static_cast<unsigned long>(dim.extent(domain_rank)),
static_cast<unsigned long>(val.second),
static_cast<unsigned long>(val.first),
int(sizeof...(Args) ? ',' : ')')));
error(buf + n, buf_len - n, domain_rank + 1, range_rank + 1, dim, args...);
}
// Kokkos::pair range
template <class T, size_t... DimArgs, class... Args>
void error(char* buf, int buf_len, unsigned domain_rank, unsigned range_rank,
const ViewDimension<DimArgs...>& dim,
const Kokkos::pair<T, T>& val, Args... args) const {
// d <= e - b
const int n = std::min(
buf_len, snprintf(buf, buf_len, " %lu <= %lu - %lu %c",
static_cast<unsigned long>(dim.extent(domain_rank)),
static_cast<unsigned long>(val.second),
static_cast<unsigned long>(val.first),
int(sizeof...(Args) ? ',' : ')')));
error(buf + n, buf_len - n, domain_rank + 1, range_rank + 1, dim, args...);
}
// { begin , end } range
template <class T, size_t... DimArgs, class... Args>
void error(char* buf, int buf_len, unsigned domain_rank, unsigned range_rank,
const ViewDimension<DimArgs...>& dim,
const std::initializer_list<T>& val, Args... args) const {
// d <= e - b
int n = 0;
if (val.size() == 2) {
n = std::min(buf_len,
snprintf(buf, buf_len, " %lu <= %lu - %lu %c",
static_cast<unsigned long>(dim.extent(domain_rank)),
static_cast<unsigned long>(val.begin()[0]),
static_cast<unsigned long>(val.begin()[1]),
int(sizeof...(Args) ? ',' : ')')));
} else {
n = std::min(buf_len, snprintf(buf, buf_len, " { ... }.size() == %u %c",
unsigned(val.size()),
int(sizeof...(Args) ? ',' : ')')));
}
error(buf + n, buf_len - n, domain_rank + 1, range_rank + 1, dim, args...);
}
template <size_t... DimArgs, class... Args>
KOKKOS_FORCEINLINE_FUNCTION void error(const ViewDimension<DimArgs...>& dim,
Args... args) const {
KOKKOS_IF_ON_HOST(
(enum {LEN = 1024}; char buffer[LEN];
const int n = snprintf(buffer, LEN, "Kokkos::subview bounds error (");
error(buffer + n, LEN - n, 0, 0, dim, args...);
Kokkos::Impl::throw_runtime_exception(std::string(buffer));))
KOKKOS_IF_ON_DEVICE(((void)dim;
Kokkos::abort("Kokkos::subview bounds error");
[](Args...) {}(args...);))
}
#else
template <size_t... DimArgs, class... Args>
KOKKOS_FORCEINLINE_FUNCTION void error(const ViewDimension<DimArgs...>&,
Args...) const {}
#endif
public:
template <size_t... DimArgs, class... Args>
KOKKOS_INLINE_FUNCTION SubviewExtents(const ViewDimension<DimArgs...>& dim,
Args... args) {
static_assert(DomainRank == sizeof...(DimArgs));
static_assert(DomainRank == sizeof...(Args));
// Verifies that all arguments, up to 8, are integral types,
// integral extents, or don't exist.
static_assert(RangeRank ==
unsigned(is_integral_extent<0, Args...>::value) +
unsigned(is_integral_extent<1, Args...>::value) +
unsigned(is_integral_extent<2, Args...>::value) +
unsigned(is_integral_extent<3, Args...>::value) +
unsigned(is_integral_extent<4, Args...>::value) +
unsigned(is_integral_extent<5, Args...>::value) +
unsigned(is_integral_extent<6, Args...>::value) +
unsigned(is_integral_extent<7, Args...>::value));
if (RangeRank == 0) {
m_length[0] = 0;
m_index[0] = ~0u;
}
if (!set(0, 0, dim, args...)) error(dim, args...);
}
template <typename iType>
KOKKOS_FORCEINLINE_FUNCTION constexpr size_t domain_offset(
const iType i) const {
return unsigned(i) < DomainRank ? m_begin[i] : 0;
}
template <typename iType>
KOKKOS_FORCEINLINE_FUNCTION constexpr size_t range_extent(
const iType i) const {
return unsigned(i) < InternalRangeRank ? m_length[i] : 0;
}
template <typename iType>
KOKKOS_FORCEINLINE_FUNCTION constexpr unsigned range_index(
const iType i) const {
return unsigned(i) < InternalRangeRank ? m_index[i] : ~0u;
}
};
} // namespace Impl
} // namespace Kokkos
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
namespace Kokkos {
namespace Impl {
//----------------------------------------------------------------------------
// LayoutLeft AND ( 1 >= rank OR 0 == rank_dynamic ) : no padding / striding
template <class Dimension>
struct ViewOffset<
Dimension, Kokkos::LayoutLeft,
std::enable_if_t<(1 >= Dimension::rank || 0 == Dimension::rank_dynamic)>> {
using is_mapping_plugin = std::true_type;
using is_regular = std::true_type;
using size_type = size_t;
using dimension_type = Dimension;
using array_layout = Kokkos::LayoutLeft;
dimension_type m_dim;
//----------------------------------------
// rank 1
template <typename I0>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0) const {
return i0;
}
// rank 2
template <typename I0, typename I1>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1) const {
return i0 + m_dim.N0 * i1;
}
// rank 3
template <typename I0, typename I1, typename I2>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1,
I2 const& i2) const {
return i0 + m_dim.N0 * (i1 + m_dim.N1 * i2);
}
// rank 4
template <typename I0, typename I1, typename I2, typename I3>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1,
I2 const& i2,
I3 const& i3) const {
return i0 + m_dim.N0 * (i1 + m_dim.N1 * (i2 + m_dim.N2 * i3));
}
// rank 5
template <typename I0, typename I1, typename I2, typename I3, typename I4>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1,
I2 const& i2,
I3 const& i3,
I4 const& i4) const {
return i0 +
m_dim.N0 * (i1 + m_dim.N1 * (i2 + m_dim.N2 * (i3 + m_dim.N3 * i4)));
}
// rank 6
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(
I0 const& i0, I1 const& i1, I2 const& i2, I3 const& i3, I4 const& i4,
I5 const& i5) const {
return i0 +
m_dim.N0 *
(i1 +
m_dim.N1 *
(i2 + m_dim.N2 * (i3 + m_dim.N3 * (i4 + m_dim.N4 * i5))));
}
// rank 7
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(
I0 const& i0, I1 const& i1, I2 const& i2, I3 const& i3, I4 const& i4,
I5 const& i5, I6 const& i6) const {
return i0 +
m_dim.N0 *
(i1 + m_dim.N1 *
(i2 + m_dim.N2 *
(i3 + m_dim.N3 *
(i4 + m_dim.N4 *
(i5 + m_dim.N5 * i6)))));
}
// rank 8
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6, typename I7>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(
I0 const& i0, I1 const& i1, I2 const& i2, I3 const& i3, I4 const& i4,
I5 const& i5, I6 const& i6, I7 const& i7) const {
return i0 +
m_dim.N0 *
(i1 +
m_dim.N1 *
(i2 + m_dim.N2 *
(i3 + m_dim.N3 *
(i4 + m_dim.N4 *
(i5 + m_dim.N5 *
(i6 + m_dim.N6 *
i7))))));
}
//----------------------------------------
KOKKOS_INLINE_FUNCTION
constexpr array_layout layout() const {
constexpr auto r = dimension_type::rank;
return array_layout((r > 0 ? m_dim.N0 : KOKKOS_INVALID_INDEX),
(r > 1 ? m_dim.N1 : KOKKOS_INVALID_INDEX),
(r > 2 ? m_dim.N2 : KOKKOS_INVALID_INDEX),
(r > 3 ? m_dim.N3 : KOKKOS_INVALID_INDEX),
(r > 4 ? m_dim.N4 : KOKKOS_INVALID_INDEX),
(r > 5 ? m_dim.N5 : KOKKOS_INVALID_INDEX),
(r > 6 ? m_dim.N6 : KOKKOS_INVALID_INDEX),
(r > 7 ? m_dim.N7 : KOKKOS_INVALID_INDEX));
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_0() const {
return m_dim.N0;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_1() const {
return m_dim.N1;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_2() const {
return m_dim.N2;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_3() const {
return m_dim.N3;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_4() const {
return m_dim.N4;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_5() const {
return m_dim.N5;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_6() const {
return m_dim.N6;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_7() const {
return m_dim.N7;
}
/* Cardinality of the domain index space */
KOKKOS_INLINE_FUNCTION
constexpr size_type size() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4 *
m_dim.N5 * m_dim.N6 * m_dim.N7;
}
/* Span of the range space */
KOKKOS_INLINE_FUNCTION
constexpr size_type span() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4 *
m_dim.N5 * m_dim.N6 * m_dim.N7;
}
KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const {
return true;
}
/* Strides of dimensions */
KOKKOS_INLINE_FUNCTION constexpr size_type stride_0() const { return 1; }
KOKKOS_INLINE_FUNCTION constexpr size_type stride_1() const {
return m_dim.N0;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_2() const {
return size_type(m_dim.N0) * m_dim.N1;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_3() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_4() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2 * m_dim.N3;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_5() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_6() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4 *
m_dim.N5;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_7() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4 *
m_dim.N5 * m_dim.N6;
}
// Stride with [ rank ] value is the total length
template <typename iType>
KOKKOS_INLINE_FUNCTION void stride(iType* const s) const {
s[0] = 1;
if (0 < dimension_type::rank) {
s[1] = m_dim.N0;
}
if (1 < dimension_type::rank) {
s[2] = s[1] * m_dim.N1;
}
if (2 < dimension_type::rank) {
s[3] = s[2] * m_dim.N2;
}
if (3 < dimension_type::rank) {
s[4] = s[3] * m_dim.N3;
}
if (4 < dimension_type::rank) {
s[5] = s[4] * m_dim.N4;
}
if (5 < dimension_type::rank) {
s[6] = s[5] * m_dim.N5;
}
if (6 < dimension_type::rank) {
s[7] = s[6] * m_dim.N6;
}
if (7 < dimension_type::rank) {
s[8] = s[7] * m_dim.N7;
}
}
//----------------------------------------
// MSVC (16.5.5) + CUDA (10.2) did not generate the defaulted functions
// correct and errors out during compilation. Same for the other places where
// I changed this.
#ifdef KOKKOS_IMPL_WINDOWS_CUDA
KOKKOS_FUNCTION ViewOffset() : m_dim(dimension_type()) {}
KOKKOS_FUNCTION ViewOffset(const ViewOffset& src) { m_dim = src.m_dim; }
KOKKOS_FUNCTION ViewOffset& operator=(const ViewOffset& src) {
m_dim = src.m_dim;
return *this;
}
#else
ViewOffset() = default;
ViewOffset(const ViewOffset&) = default;
ViewOffset& operator=(const ViewOffset&) = default;
#endif
template <unsigned TrivialScalarSize>
KOKKOS_INLINE_FUNCTION constexpr ViewOffset(
std::integral_constant<unsigned, TrivialScalarSize> const&,
Kokkos::LayoutLeft const& arg_layout)
: m_dim(arg_layout.dimension[0], 0, 0, 0, 0, 0, 0, 0) {}
template <class DimRHS>
KOKKOS_INLINE_FUNCTION constexpr ViewOffset(
const ViewOffset<DimRHS, Kokkos::LayoutLeft, void>& rhs)
: m_dim(rhs.m_dim.N0, rhs.m_dim.N1, rhs.m_dim.N2, rhs.m_dim.N3,
rhs.m_dim.N4, rhs.m_dim.N5, rhs.m_dim.N6, rhs.m_dim.N7) {
static_assert(int(DimRHS::rank) == int(dimension_type::rank),
"ViewOffset assignment requires equal rank");
// Also requires equal static dimensions ...
}
template <class DimRHS>
KOKKOS_INLINE_FUNCTION constexpr ViewOffset(
const ViewOffset<DimRHS, Kokkos::LayoutRight, void>& rhs)
: m_dim(rhs.m_dim.N0, 0, 0, 0, 0, 0, 0, 0) {
static_assert(((DimRHS::rank == 0 && dimension_type::rank == 0) ||
(DimRHS::rank == 1 && dimension_type::rank == 1)),
"ViewOffset LayoutLeft and LayoutRight are only compatible "
"when rank <= 1");
}
template <class DimRHS>
KOKKOS_INLINE_FUNCTION ViewOffset(
const ViewOffset<DimRHS, Kokkos::LayoutStride, void>& rhs)
: m_dim(rhs.m_dim.N0, 0, 0, 0, 0, 0, 0, 0) {
if (rhs.m_stride.S0 != 1) {
Kokkos::abort(
"Kokkos::Impl::ViewOffset assignment of LayoutLeft from LayoutStride "
" requires stride == 1");
}
}
//----------------------------------------
// Subview construction
template <class DimRHS>
KOKKOS_INLINE_FUNCTION constexpr ViewOffset(
const ViewOffset<DimRHS, Kokkos::LayoutLeft, void>&,
const SubviewExtents<DimRHS::rank, dimension_type::rank>& sub)
: m_dim(sub.range_extent(0), 0, 0, 0, 0, 0, 0, 0) {
static_assert((0 == dimension_type::rank_dynamic) ||
(1 == dimension_type::rank &&
1 == dimension_type::rank_dynamic && 1 <= DimRHS::rank),
"ViewOffset subview construction requires compatible rank");
}
};
//----------------------------------------------------------------------------
// LayoutLeft AND ( 1 < rank AND 0 < rank_dynamic ) : has padding / striding
template <class Dimension>
struct ViewOffset<
Dimension, Kokkos::LayoutLeft,
std::enable_if_t<(1 < Dimension::rank && 0 < Dimension::rank_dynamic)>> {
using is_mapping_plugin = std::true_type;
using is_regular = std::true_type;
using size_type = size_t;
using dimension_type = Dimension;
using array_layout = Kokkos::LayoutLeft;
dimension_type m_dim;
size_type m_stride;
//----------------------------------------
// rank 1
template <typename I0>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0) const {
return i0;
}
// rank 2
template <typename I0, typename I1>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1) const {
return i0 + m_stride * i1;
}
// rank 3
template <typename I0, typename I1, typename I2>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1,
I2 const& i2) const {
return i0 + m_stride * (i1 + m_dim.N1 * i2);
}
// rank 4
template <typename I0, typename I1, typename I2, typename I3>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1,
I2 const& i2,
I3 const& i3) const {
return i0 + m_stride * (i1 + m_dim.N1 * (i2 + m_dim.N2 * i3));
}
// rank 5
template <typename I0, typename I1, typename I2, typename I3, typename I4>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(I0 const& i0,
I1 const& i1,
I2 const& i2,
I3 const& i3,
I4 const& i4) const {
return i0 +
m_stride * (i1 + m_dim.N1 * (i2 + m_dim.N2 * (i3 + m_dim.N3 * i4)));
}
// rank 6
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(
I0 const& i0, I1 const& i1, I2 const& i2, I3 const& i3, I4 const& i4,
I5 const& i5) const {
return i0 +
m_stride *
(i1 +
m_dim.N1 *
(i2 + m_dim.N2 * (i3 + m_dim.N3 * (i4 + m_dim.N4 * i5))));
}
// rank 7
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(
I0 const& i0, I1 const& i1, I2 const& i2, I3 const& i3, I4 const& i4,
I5 const& i5, I6 const& i6) const {
return i0 +
m_stride *
(i1 + m_dim.N1 *
(i2 + m_dim.N2 *
(i3 + m_dim.N3 *
(i4 + m_dim.N4 *
(i5 + m_dim.N5 * i6)))));
}
// rank 8
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6, typename I7>
KOKKOS_INLINE_FUNCTION constexpr size_type operator()(
I0 const& i0, I1 const& i1, I2 const& i2, I3 const& i3, I4 const& i4,
I5 const& i5, I6 const& i6, I7 const& i7) const {
return i0 +
m_stride *
(i1 +
m_dim.N1 *
(i2 + m_dim.N2 *
(i3 + m_dim.N3 *
(i4 + m_dim.N4 *
(i5 + m_dim.N5 *
(i6 + m_dim.N6 *
i7))))));
}
//----------------------------------------
KOKKOS_INLINE_FUNCTION
constexpr array_layout layout() const {
constexpr auto r = dimension_type::rank;
return array_layout((r > 0 ? m_dim.N0 : KOKKOS_INVALID_INDEX),
(r > 1 ? m_dim.N1 : KOKKOS_INVALID_INDEX),
(r > 2 ? m_dim.N2 : KOKKOS_INVALID_INDEX),
(r > 3 ? m_dim.N3 : KOKKOS_INVALID_INDEX),
(r > 4 ? m_dim.N4 : KOKKOS_INVALID_INDEX),
(r > 5 ? m_dim.N5 : KOKKOS_INVALID_INDEX),
(r > 6 ? m_dim.N6 : KOKKOS_INVALID_INDEX),
(r > 7 ? m_dim.N7 : KOKKOS_INVALID_INDEX));
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_0() const {
return m_dim.N0;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_1() const {
return m_dim.N1;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_2() const {
return m_dim.N2;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_3() const {
return m_dim.N3;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_4() const {
return m_dim.N4;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_5() const {
return m_dim.N5;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_6() const {
return m_dim.N6;
}
KOKKOS_INLINE_FUNCTION constexpr size_type dimension_7() const {
return m_dim.N7;
}
/* Cardinality of the domain index space */
KOKKOS_INLINE_FUNCTION
constexpr size_type size() const {
return size_type(m_dim.N0) * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4 *
m_dim.N5 * m_dim.N6 * m_dim.N7;
}
/* Span of the range space */
KOKKOS_INLINE_FUNCTION
constexpr size_type span() const {
return (m_dim.N0 > size_type(0) ? m_stride : size_type(0)) * m_dim.N1 *
m_dim.N2 * m_dim.N3 * m_dim.N4 * m_dim.N5 * m_dim.N6 * m_dim.N7;
}
KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const {
return m_stride == m_dim.N0;
}
/* Strides of dimensions */
KOKKOS_INLINE_FUNCTION constexpr size_type stride_0() const { return 1; }
KOKKOS_INLINE_FUNCTION constexpr size_type stride_1() const {
return m_stride;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_2() const {
return m_stride * m_dim.N1;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_3() const {
return m_stride * m_dim.N1 * m_dim.N2;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_4() const {
return m_stride * m_dim.N1 * m_dim.N2 * m_dim.N3;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_5() const {
return m_stride * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_6() const {
return m_stride * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4 * m_dim.N5;
}
KOKKOS_INLINE_FUNCTION constexpr size_type stride_7() const {
return m_stride * m_dim.N1 * m_dim.N2 * m_dim.N3 * m_dim.N4 * m_dim.N5 *
m_dim.N6;
}
// Stride with [ rank ] value is the total length
template <typename iType>
KOKKOS_INLINE_FUNCTION void stride(iType* const s) const {
s[0] = 1;
if (0 < dimension_type::rank) {
s[1] = m_stride;
}
if (1 < dimension_type::rank) {
s[2] = s[1] * m_dim.N1;
}
if (2 < dimension_type::rank) {
s[3] = s[2] * m_dim.N2;
}
if (3 < dimension_type::rank) {
s[4] = s[3] * m_dim.N3;
}
if (4 < dimension_type::rank) {
s[5] = s[4] * m_dim.N4;
}
if (5 < dimension_type::rank) {
s[6] = s[5] * m_dim.N5;
}
if (6 < dimension_type::rank) {
s[7] = s[6] * m_dim.N6;
}
if (7 < dimension_type::rank) {
s[8] = s[7] * m_dim.N7;
}
}
//----------------------------------------
private:
template <unsigned TrivialScalarSize>
struct Padding {
enum {
div = TrivialScalarSize == 0
? 0
: Kokkos::Impl::MEMORY_ALIGNMENT /
(TrivialScalarSize ? TrivialScalarSize : 1)
};
enum {
mod = TrivialScalarSize == 0
? 0
: Kokkos::Impl::MEMORY_ALIGNMENT %
(TrivialScalarSize ? TrivialScalarSize : 1)
};
// If memory alignment is a multiple of the trivial scalar size then attempt
// to align.
enum { align = 0 != TrivialScalarSize && 0 == mod ? div : 0 };
enum {
div_ok = (div != 0) ? div : 1
}; // To valid modulo zero in constexpr
KOKKOS_INLINE_FUNCTION
static constexpr size_t stride(size_t const N) {
return ((align != 0) &&
((static_cast<int>(Kokkos::Impl::MEMORY_ALIGNMENT_THRESHOLD) *
static_cast<int>(align)) < N) &&
((N % div_ok) != 0))
? N + align - (N % div_ok)
: N;