forked from kokkos/kokkos-remote-spaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kokkos_RemoteSpaces_ViewMapping.hpp
1248 lines (1098 loc) · 46.7 KB
/
Kokkos_RemoteSpaces_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
//
// Contact: Jan Ciesko (jciesko@sandia.gov)
//
//@HEADER
#ifndef KOKKOS_REMOTESPACES_VIEWMAPPING_HPP
#define KOKKOS_REMOTESPACES_VIEWMAPPING_HPP
#include <type_traits>
#define ENABLE_IF_GLOBAL_LAYOUT \
std::enable_if_t<!Is_Partitioned_Layout<T>::value> * = nullptr
#define ENABLE_IF_PARTITIONED_LAYOUT \
std::enable_if_t<Is_Partitioned_Layout<T>::value> * = nullptr
#define USING_GLOBAL_INDEXING !remote_view_props.using_local_indexing
#define USING_LOCAL_INDEXING remote_view_props.using_local_indexing
//----------------------------------------------------------------------------
/** \brief View mapping for specialized data type */
namespace Kokkos {
namespace Impl {
using namespace Kokkos::Experimental::Impl;
/*
* Type used for subview creation with non-standard Layouts and default (void)
* view specialization.
*/
template <class SrcTraits, class... Args>
class ViewMapping<
std::enable_if_t<(std::is_void<typename SrcTraits::specialize>::value &&
(std::is_same<typename SrcTraits::array_layout,
Kokkos::PartitionedLayoutLeft>::value ||
std::is_same<typename SrcTraits::array_layout,
Kokkos::PartitionedLayoutRight>::value ||
std::is_same<typename SrcTraits::array_layout,
Kokkos::PartitionedLayoutStride>::value))>,
SrcTraits, Args...> {
private:
static_assert(SrcTraits::rank == sizeof...(Args),
"Subview mapping requires one argument for each dimension of "
"source View");
enum {
RZ = false,
R0 = bool(is_integral_extent<0, Args...>::value),
R1 = bool(is_integral_extent<1, Args...>::value),
R2 = bool(is_integral_extent<2, Args...>::value),
R3 = bool(is_integral_extent<3, Args...>::value),
R4 = bool(is_integral_extent<4, Args...>::value),
R5 = bool(is_integral_extent<5, Args...>::value),
R6 = bool(is_integral_extent<6, Args...>::value),
R7 = bool(is_integral_extent<7, Args...>::value)
};
enum {
rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3) +
unsigned(R4) + unsigned(R5) + unsigned(R6) + unsigned(R7)
};
// Whether right-most rank is a range.
enum {
R0_rev =
(0 == SrcTraits::rank
? RZ
: (1 == SrcTraits::rank
? R0
: (2 == SrcTraits::rank
? R1
: (3 == SrcTraits::rank
? R2
: (4 == SrcTraits::rank
? R3
: (5 == SrcTraits::rank
? R4
: (6 == SrcTraits::rank
? R5
: (7 == SrcTraits::rank
? R6
: R7))))))))
};
// Subview's layout
using array_layout = std::conditional_t<
( /* Same array layout IF */
(rank == 0) /* output rank zero */
|| SubviewLegalArgsCompileTime<typename SrcTraits::array_layout,
typename SrcTraits::array_layout, rank,
SrcTraits::rank, 0, Args...>::value ||
// OutputRank 1 or 2, InputLayout Left, Interval 0
// because single stride one or second index has a stride.
(rank <= 2 && R0 &&
std::is_same<typename SrcTraits::array_layout,
Kokkos::LayoutLeft>::value) // replace with input rank
||
// OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
// because single stride one or second index has a stride.
(rank <= 2 && R0_rev &&
std::is_same<typename SrcTraits::array_layout,
Kokkos::LayoutRight>::value) // replace input rank
),
typename SrcTraits::array_layout, Kokkos::LayoutStride>;
using value_type = typename SrcTraits::value_type;
using data_type =
typename SubViewDataType<value_type,
typename Kokkos::Impl::ParseViewExtents<
typename SrcTraits::data_type>::type,
Args...>::type;
public:
using traits_type = Kokkos::ViewTraits<data_type, array_layout,
typename SrcTraits::device_type,
typename SrcTraits::memory_traits>;
using type =
Kokkos::View<data_type, array_layout, typename SrcTraits::device_type,
typename SrcTraits::memory_traits>;
template <class MemoryTraits>
struct apply {
static_assert(Kokkos::is_memory_traits<MemoryTraits>::value, "");
using traits_type =
Kokkos::ViewTraits<data_type, array_layout,
typename SrcTraits::device_type, MemoryTraits>;
using type = Kokkos::View<data_type, array_layout,
typename SrcTraits::device_type, MemoryTraits>;
};
// The presumed type is 'ViewMapping< traits_type , void >'
// However, a compatible ViewMapping is acceptable.
template <class DstTraits>
KOKKOS_INLINE_FUNCTION static void assign(
ViewMapping<DstTraits, void> &dst,
ViewMapping<SrcTraits, void> const &src, Args... args) {
static_assert(ViewMapping<DstTraits, traits_type, void>::is_assignable,
"Subview destination type must be compatible with subview "
"derived type");
using DstType = ViewMapping<DstTraits, void>;
using dst_offset_type = typename DstType::offset_type;
const SubviewExtents<SrcTraits::rank, rank> extents(src.m_impl_offset.m_dim,
args...);
dst.m_impl_offset = dst_offset_type(src.m_impl_offset, extents);
dst.m_impl_handle = ViewDataHandle<DstTraits>::assign(
src.m_impl_handle,
src.m_impl_offset(extents.domain_offset(0), extents.domain_offset(1),
extents.domain_offset(2), extents.domain_offset(3),
extents.domain_offset(4), extents.domain_offset(5),
extents.domain_offset(6), extents.domain_offset(7)));
}
};
/*
* ViewMapping type used by View copy-ctr and subview() to specialize new
* (sub-) view type
*/
template <class SrcTraits, class... Args>
class ViewMapping<
typename std::enable_if<(
std::is_same<typename SrcTraits::specialize,
Kokkos::Experimental::RemoteSpaceSpecializeTag>::value)>::
type,
SrcTraits, Args...> {
private:
static_assert(SrcTraits::rank == sizeof...(Args),
"Subview mapping requires one argument for each dimension of "
"source View");
enum {
RZ = false,
R0 = bool(is_integral_extent<0, Args...>::value),
R1 = bool(is_integral_extent<1, Args...>::value),
R2 = bool(is_integral_extent<2, Args...>::value),
R3 = bool(is_integral_extent<3, Args...>::value),
R4 = bool(is_integral_extent<4, Args...>::value),
R5 = bool(is_integral_extent<5, Args...>::value),
R6 = bool(is_integral_extent<6, Args...>::value),
R7 = bool(is_integral_extent<7, Args...>::value)
};
enum {
rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3) +
unsigned(R4) + unsigned(R5) + unsigned(R6) + unsigned(R7)
};
// Whether right-most rank is a range.
enum {
R0_rev =
(0 == SrcTraits::rank
? RZ
: (1 == SrcTraits::rank
? R0
: (2 == SrcTraits::rank
? R1
: (3 == SrcTraits::rank
? R2
: (4 == SrcTraits::rank
? R3
: (5 == SrcTraits::rank
? R4
: (6 == SrcTraits::rank
? R5
: (7 == SrcTraits::rank
? R6
: R7))))))))
};
// Subview's layout
using array_layout_candidate =
typename std::conditional<
( /* Same array layout IF */
(rank == 0) /* output rank zero */
|| SubviewLegalArgsCompileTime<
typename SrcTraits::array_layout,
typename SrcTraits::array_layout, rank, SrcTraits::rank, 0,
Args...>::value || // OutputRank 1 or 2, InputLayout Left,
// Interval 0 because single stride one or
// second index has a stride.
(rank <= 2 && R0 &&
(std::is_same<typename SrcTraits::array_layout,
Kokkos::LayoutLeft>::value ||
std::is_same<typename SrcTraits::array_layout,
Kokkos::PartitionedLayoutLeft>::value)) // replace
// with input
// rank
||
// OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
// because single stride one or second index has a stride.
(rank <= 2 && R0_rev &&
(std::is_same<typename SrcTraits::array_layout,
Kokkos::LayoutRight>::value ||
std::is_same<typename SrcTraits::array_layout,
Kokkos::PartitionedLayoutRight>::value) // replace
// input rank
)),
typename SrcTraits::array_layout, Kokkos::LayoutStride>::type;
// Check if Kokkos::LayoutStride should become PartitionedLayoutStride
using array_layout = typename std::conditional<
std::is_same<array_layout_candidate, Kokkos::LayoutStride>::value &&
Is_Partitioned_Layout<SrcTraits>::value,
Kokkos::PartitionedLayoutStride, array_layout_candidate>::type;
using value_type = typename SrcTraits::value_type;
using data_type =
typename SubViewDataType<value_type,
typename Kokkos::Impl::ParseViewExtents<
typename SrcTraits::data_type>::type,
Args...>::type;
// If dim0 is range and PartitionedLayout, dim0 is PE
// We compute the offset to that subview during assign
enum { require_R0 = R0 };
public:
using memory_traits = typename std::conditional<
require_R0,
Kokkos::MemoryTraits<
RemoteSpaces_MemoryTraits<typename SrcTraits::memory_traits>::state |
RemoteSpaces_MemoryTraitFlags::Dim0IsPE> /*Remove as obsolete*/,
typename SrcTraits::memory_traits>::type;
using traits_type =
Kokkos::ViewTraits<data_type, array_layout,
typename SrcTraits::memory_space, memory_traits>;
using view_type =
typename Kokkos::View<data_type, array_layout,
typename SrcTraits::memory_space, memory_traits>;
using type = view_type;
static_assert(
std::is_same<typename SrcTraits::specialize,
Kokkos::Experimental::RemoteSpaceSpecializeTag>::value,
"Remote memory space copy-construction with incorrect specialization.");
template <class MemoryTraits>
struct apply {
static_assert(Kokkos::is_memory_traits<MemoryTraits>::value, "");
using traits_type =
Kokkos::ViewTraits<data_type, array_layout,
typename SrcTraits::memory_space, MemoryTraits>;
using type = Kokkos::View<data_type, array_layout,
typename SrcTraits::memory_space, MemoryTraits>;
};
template <class DstTraits>
KOKKOS_INLINE_FUNCTION static void assign(
ViewMapping<DstTraits, Kokkos::Experimental::RemoteSpaceSpecializeTag>
&dst,
ViewMapping<SrcTraits,
Kokkos::Experimental::RemoteSpaceSpecializeTag> const &src,
Args... args) {
static_assert(
ViewMapping<
DstTraits, traits_type,
Kokkos::Experimental::RemoteSpaceSpecializeTag>::is_assignable,
"Subview destination type must be compatible with subview "
"derived type");
using SrcType =
ViewMapping<SrcTraits, Kokkos::Experimental::RemoteSpaceSpecializeTag>;
using DstType =
ViewMapping<DstTraits, Kokkos::Experimental::RemoteSpaceSpecializeTag>;
using dst_offset_type = typename DstType::offset_type;
const SubviewExtents<SrcTraits::rank, rank> extents(src.m_offset.m_dim,
args...);
dst.m_offset = dst_offset_type(src.m_offset, extents);
dst.remote_view_props = src.remote_view_props;
bool switch_to_local_indexing = false;
/* Currently we only have a restricted support of subviews of subviews.
*/
if (!src.remote_view_props.using_local_indexing) {
dst.remote_view_props.using_local_indexing = !R0 ? true : false;
dst.remote_view_props.R0_offset = extents.domain_offset(0);
} else
switch_to_local_indexing = true;
typename view_type::size_type offset;
offset =
switch_to_local_indexing
? src.m_offset(extents.domain_offset(0), extents.domain_offset(1),
extents.domain_offset(2), extents.domain_offset(3),
extents.domain_offset(4), extents.domain_offset(5),
extents.domain_offset(6), extents.domain_offset(7))
: src.m_offset(
0 /*Global indexing uses R0_offset for this dim offset*/,
extents.domain_offset(1), extents.domain_offset(2),
extents.domain_offset(3), extents.domain_offset(4),
extents.domain_offset(5), extents.domain_offset(6),
extents.domain_offset(7));
#ifdef KRS_ENABLE_MPISPACE
// Subviews propagate MPI_Window of the original view
dst.m_handle = ViewDataHandle<DstTraits>::assign(
src.m_handle, src.m_handle.loc.win, offset);
#else
dst.m_handle = ViewDataHandle<DstTraits>::assign(src.m_handle, offset);
#endif
}
};
/*
* ViewMapping class used by View specialization
*/
template <class Traits>
class ViewMapping<Traits, Kokkos::Experimental::RemoteSpaceSpecializeTag> {
private:
template <class, class...>
friend class ViewMapping;
template <class, class...>
friend class Kokkos::View;
using layout = typename Traits::array_layout;
typedef typename ViewDataHandle<Traits>::handle_type handle_type;
typedef typename ViewDataHandle<Traits>::return_type reference_type;
typedef typename Traits::value_type *pointer_type;
// Add here a std::conditional to differentiate between a subview remote
// offset. A subview ViewOffset can handle dim0 accesses correctly (offsets)
typedef ViewOffset<typename Traits::dimension, typename Traits::array_layout,
void>
offset_type;
RemoteSpaces_View_Properties<typename Traits::size_type> remote_view_props;
public:
offset_type m_offset;
handle_type m_handle;
typedef void printable_label_typedef;
enum { is_managed = Traits::is_managed };
//----------------------------------------
// Domain dimensions
enum { Rank = Traits::dimension::rank };
KOKKOS_INLINE_FUNCTION
int get_PE() const { return remote_view_props.my_PE; }
template <typename T = Traits>
KOKKOS_INLINE_FUNCTION int get_logical_PE(ENABLE_IF_GLOBAL_LAYOUT) const {
// If View is subview, compute owning PE of index R0_offset
if (USING_GLOBAL_INDEXING && remote_view_props.R0_offset != 0)
return compute_dim0_offsets(remote_view_props.R0_offset).PE;
// Else, return my_PE
return remote_view_props.my_PE;
}
template <typename T = Traits>
KOKKOS_INLINE_FUNCTION int get_logical_PE(
ENABLE_IF_PARTITIONED_LAYOUT) const {
if (USING_GLOBAL_INDEXING && remote_view_props.R0_offset != 0)
return remote_view_props.R0_offset;
return remote_view_props.my_PE;
}
template <typename iType, typename T = Traits>
KOKKOS_INLINE_FUNCTION constexpr size_t extent(const iType &r) const {
if (r == 0) return dimension_0();
return m_offset.m_dim.extent(r);
}
KOKKOS_INLINE_FUNCTION constexpr typename Traits::array_layout get_layout()
const {
return m_offset.layout();
}
template <typename T = Traits>
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0(
ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_GLOBAL_INDEXING)
return remote_view_props.R0_size;
else
return m_offset.dimension_0();
}
template <typename T = Traits>
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0(
ENABLE_IF_PARTITIONED_LAYOUT) const {
return m_offset.dimension_0();
}
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const {
return m_offset.dimension_1();
}
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const {
return m_offset.dimension_2();
}
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const {
return m_offset.dimension_3();
}
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const {
return m_offset.dimension_4();
}
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const {
return m_offset.dimension_5();
}
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const {
return m_offset.dimension_6();
}
KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const {
return m_offset.dimension_7();
}
// Is a regular layout with uniform striding for each index.
using is_regular = typename offset_type::is_regular;
KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const {
return m_offset.stride_0();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const {
return m_offset.stride_1();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const {
return m_offset.stride_2();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const {
return m_offset.stride_3();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const {
return m_offset.stride_4();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const {
return m_offset.stride_5();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const {
return m_offset.stride_6();
}
KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const {
return m_offset.stride_7();
}
template <typename iType>
KOKKOS_INLINE_FUNCTION void stride(iType *const s) const {
m_offset.stride(s);
}
//----------------------------------------
// Range span
/** \brief Span of the mapped range */
KOKKOS_INLINE_FUNCTION constexpr size_t span() const {
return m_offset.span();
}
/** \brief Is the mapped range span contiguous */
KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const {
return m_offset.span_is_contiguous();
}
/** \brief Query raw pointer to memory */
KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const {
return m_handle.ptr;
}
/** \brief Query raw pointer to memory */
KOKKOS_INLINE_FUNCTION handle_type handle() const { return m_handle; }
//----------------------------------------
// The View class performs all rank and bounds checking before
// calling these element reference methods.
KOKKOS_INLINE_FUNCTION
reference_type reference() const { return m_handle[0]; }
// PartitionedLayout{Left,Right,Strided} access operators
template <typename I0, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, ENABLE_IF_PARTITIONED_LAYOUT) const {
// We need this dynamic check as we do not derive the
// type specialization at view construction through the
// view ctr (only through Kokkos::subview(...)). This adds support
// for auto sub_v = View_t(old_sub_v,...).
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element = m_handle(dim0_offset, m_offset(_i0));
return element;
}
template <typename I0, typename I1, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, ENABLE_IF_PARTITIONED_LAYOUT) const {
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element = m_handle(dim0_offset, m_offset(_i0, i1));
return element;
}
template <typename I0, typename I1, typename I2, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2,
ENABLE_IF_PARTITIONED_LAYOUT) const {
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element = m_handle(dim0_offset, m_offset(_i0, i1, i2));
return element;
}
template <typename I0, typename I1, typename I2, typename I3,
typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3,
ENABLE_IF_PARTITIONED_LAYOUT) const {
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element =
m_handle(dim0_offset, m_offset(_i0, i1, i2, i3));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3,
const I4 &i4, ENABLE_IF_PARTITIONED_LAYOUT) const {
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element =
m_handle(dim0_offset, m_offset(_i0, i1, i2, i3, i4));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3,
const I4 &i4, const I5 &i5, ENABLE_IF_PARTITIONED_LAYOUT) const {
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element =
m_handle(dim0_offset, m_offset(_i0, i1, i2, i3, i4, i5));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type reference(
const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4,
const I5 &i5, const I6 &i6, ENABLE_IF_PARTITIONED_LAYOUT) const {
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element =
m_handle(dim0_offset, m_offset(_i0, i1, i2, i3, i4, i5, i6));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6, typename I7, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3,
const I4 &i4, const I5 &i5, const I6 &i6, const I7 &i7,
ENABLE_IF_PARTITIONED_LAYOUT) const {
auto dim0_offset = remote_view_props.R0_offset;
auto _i0 = i0;
if (USING_GLOBAL_INDEXING) {
dim0_offset += i0;
_i0 = 0;
}
const reference_type element =
m_handle(dim0_offset, m_offset(_i0, i1, i2, i3, i4, i5, i6, i7));
return element;
}
//----------------------------------------
// Layout{Left,Right,Stride} access operators
// Implements global views
template <class T>
struct Dim0_IndexOffset {
int PE;
T offset;
};
template <typename I0>
KOKKOS_INLINE_FUNCTION Dim0_IndexOffset<I0> compute_dim0_offsets(
const I0 &_i0) const {
assert(remote_view_props.R0_size);
auto local_size = static_cast<I0>(remote_view_props.R0_size);
auto target_pe = static_cast<int>(_i0 / local_size);
auto dim0_mod = static_cast<I0>(_i0 % local_size);
return {target_pe, dim0_mod};
}
template <typename I0, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element = m_handle(new_offset.PE, m_offset(i0));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(new_offset.offset));
return element;
}
template <typename I0, typename I1, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0, i1));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element = m_handle(new_offset.PE, m_offset(i0, i1));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0, i1));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(new_offset.offset, i1));
return element;
}
template <typename I0, typename I1, typename I2, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type reference(
const I0 &i0, const I1 &i1, const I2 &i2, ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0, i1, i2));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(i0, i1, i2));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0, i1, i2));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(new_offset.offset, i1, i2));
return element;
}
template <typename I0, typename I1, typename I2, typename I3,
typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3,
ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0, i1, i2, i3));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(i0, i1, i2, i3));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0, i1, i2, i3));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(new_offset.offset, i1, i2, i3));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3,
const I4 &i4, ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element =
m_handle(0, m_offset(i0, i1, i2, i3, i4));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(i0, i1, i2, i3, i4));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element = m_handle(0, m_offset(i0, i1, i2, i3, i4));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(new_offset.offset, i1, i2, i3, i4));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type
reference(const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3,
const I4 &i4, const I5 &i5, ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element =
m_handle(0, m_offset(i0, i1, i2, i3, i4, i5));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(i0, i1, i2, i3, i4, i5));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element =
m_handle(0, m_offset(i0, i1, i2, i3, i4, i5));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element = m_handle(
new_offset.PE, m_offset(new_offset.offset, i1, i2, i3, i4, i5));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type reference(
const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4,
const I5 &i5, const I6 &i6, ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element =
m_handle(0, m_offset(i0, i1, i2, i3, i4, i5, i6));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(i0, i1, i2, i3, i4, i5, i6));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element =
m_handle(0, m_offset(i0, i1, i2, i3, i4, i5, i6));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element = m_handle(
new_offset.PE, m_offset(new_offset.offset, i1, i2, i3, i4, i5, i6));
return element;
}
template <typename I0, typename I1, typename I2, typename I3, typename I4,
typename I5, typename I6, typename I7, typename T = Traits>
KOKKOS_INLINE_FUNCTION const reference_type reference(
const I0 &i0, const I1 &i1, const I2 &i2, const I3 &i3, const I4 &i4,
const I5 &i5, const I6 &i6, const I7 &i7, ENABLE_IF_GLOBAL_LAYOUT) const {
if (USING_LOCAL_INDEXING) {
if (remote_view_props.num_PEs <= 1) {
const reference_type element =
m_handle(0, m_offset(i0, i1, i2, i3, i4, i5, i6, i7));
return element;
}
auto dim0_offset = remote_view_props.R0_offset;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element =
m_handle(new_offset.PE, m_offset(i0, i1, i2, i3, i4, i5, i6, i7));
return element;
}
if (remote_view_props.num_PEs <= 1) {
const reference_type element =
m_handle(0, m_offset(i0, i1, i2, i3, i4, i5, i6, i7));
return element;
}
auto dim0_offset = remote_view_props.R0_offset + i0;
Dim0_IndexOffset<I0> new_offset = compute_dim0_offsets<I0>(dim0_offset);
const reference_type element = m_handle(
new_offset.PE, m_offset(new_offset.offset, i1, i2, i3, i4, i5, i6, i7));
return element;
}
private:
enum { MemorySpanMask = 8 - 1 /* Force alignment on 8 byte boundary */ };
enum { MemorySpanSize = sizeof(typename Traits::value_type) };
public:
/** \brief Span, in bytes, of the referenced memory */
KOKKOS_INLINE_FUNCTION constexpr size_t memory_span() const {
return (m_offset.span() * sizeof(typename Traits::value_type) +
MemorySpanMask) &
~size_t(MemorySpanMask);
}
/**\brief Span, in bytes, of the required memory */
KOKKOS_INLINE_FUNCTION
static constexpr size_t memory_span(
typename Traits::array_layout const &arg_layout) {
typedef std::integral_constant<unsigned, 0> padding;
return (offset_type(padding(), arg_layout).span() * MemorySpanSize +
MemorySpanMask) &
~size_t(MemorySpanMask);
}
KOKKOS_INLINE_FUNCTION ~ViewMapping() {}
KOKKOS_INLINE_FUNCTION ViewMapping()
: m_handle(), m_offset(), remote_view_props() {}
KOKKOS_INLINE_FUNCTION ViewMapping(const ViewMapping &rhs)
: m_handle(rhs.m_handle),
m_offset(rhs.m_offset),
remote_view_props(rhs.remote_view_props) {}
KOKKOS_INLINE_FUNCTION ViewMapping &operator=(const ViewMapping &rhs) {
m_handle = rhs.m_handle;
m_offset = rhs.m_offset;
remote_view_props = rhs.remote_view_props;
return *this;
}
KOKKOS_INLINE_FUNCTION ViewMapping(ViewMapping &&rhs)
: m_handle(rhs.m_handle),
m_offset(rhs.m_offset),
remote_view_props(rhs.remote_view_props) {}
KOKKOS_INLINE_FUNCTION ViewMapping &operator=(ViewMapping &&rhs) {
m_handle = rhs.m_handle;
m_offset = rhs.m_offset;
remote_view_props = rhs.remote_view_props;
return *this;
}
/**\brief Wrap a span of memory */
template <class... P>
KOKKOS_INLINE_FUNCTION ViewMapping(
Kokkos::Impl::ViewCtorProp<P...> const &arg_prop,
typename Traits::array_layout const &arg_layout)
: remote_view_props(),
m_handle(
((Kokkos::Impl::ViewCtorProp<void, pointer_type> const &)arg_prop)
.value)
{
typedef typename Traits::value_type value_type;
typedef std::integral_constant<
unsigned, Kokkos::Impl::ViewCtorProp<P...>::allow_padding
? sizeof(value_type)
: 0>
padding;
typename Traits::array_layout layout;
// Copy layout properties
set_layout(arg_layout, layout, remote_view_props);
m_offset = offset_type(padding(), layout);
}
/**\brief Assign data */
KOKKOS_FUNCTION
void assign_data(pointer_type arg_ptr) { m_handle = handle_type(arg_ptr); }
private:
template <typename T = Traits>
KOKKOS_FUNCTION typename std::enable_if_t<!Is_Partitioned_Layout<T>::value>
set_layout(typename T::array_layout const &arg_layout,
typename T::array_layout &layout,
RemoteSpaces_View_Properties<typename T::size_type> &view_props) {
for (int i = 0; i < T::rank; i++)