51 #ifndef KOKKOS_SCATTER_VIEW_HPP
52 #define KOKKOS_SCATTER_VIEW_HPP
54 #include <Kokkos_Core.hpp>
58 namespace Experimental {
66 ScatterNonDuplicated = 0,
79 namespace Experimental {
81 template <
typename ExecSpace>
82 struct DefaultDuplication;
84 template <
typename ExecSpace,
int duplication>
85 struct DefaultContribution;
87 #ifdef KOKKOS_ENABLE_SERIAL
89 struct DefaultDuplication<Kokkos::Serial> {
90 enum :
int { value = Kokkos::Experimental::ScatterNonDuplicated };
93 struct DefaultContribution<Kokkos::Serial, Kokkos::Experimental::ScatterNonDuplicated> {
94 enum :
int { value = Kokkos::Experimental::ScatterNonAtomic };
97 struct DefaultContribution<Kokkos::Serial, Kokkos::Experimental::ScatterDuplicated> {
98 enum :
int { value = Kokkos::Experimental::ScatterNonAtomic };
102 #ifdef KOKKOS_ENABLE_OPENMP
104 struct DefaultDuplication<Kokkos::OpenMP> {
105 enum :
int { value = Kokkos::Experimental::ScatterDuplicated };
108 struct DefaultContribution<Kokkos::OpenMP, Kokkos::Experimental::ScatterNonDuplicated> {
109 enum :
int { value = Kokkos::Experimental::ScatterAtomic };
112 struct DefaultContribution<Kokkos::OpenMP, Kokkos::Experimental::ScatterDuplicated> {
113 enum :
int { value = Kokkos::Experimental::ScatterNonAtomic };
117 #ifdef KOKKOS_ENABLE_THREADS
119 struct DefaultDuplication<Kokkos::Threads> {
120 enum :
int { value = Kokkos::Experimental::ScatterDuplicated };
123 struct DefaultContribution<Kokkos::Threads, Kokkos::Experimental::ScatterNonDuplicated> {
124 enum :
int { value = Kokkos::Experimental::ScatterAtomic };
127 struct DefaultContribution<Kokkos::Threads, Kokkos::Experimental::ScatterDuplicated> {
128 enum :
int { value = Kokkos::Experimental::ScatterNonAtomic };
132 #ifdef KOKKOS_ENABLE_CUDA
134 struct DefaultDuplication<Kokkos::Cuda> {
135 enum :
int { value = Kokkos::Experimental::ScatterNonDuplicated };
138 struct DefaultContribution<Kokkos::Cuda, Kokkos::Experimental::ScatterNonDuplicated> {
139 enum :
int { value = Kokkos::Experimental::ScatterAtomic };
142 struct DefaultContribution<Kokkos::Cuda, Kokkos::Experimental::ScatterDuplicated> {
143 enum :
int { value = Kokkos::Experimental::ScatterAtomic };
150 template <
typename ValueType,
int Op,
int contribution>
153 template <
typename ValueType>
154 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterNonAtomic> {
156 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in) : value( value_in ) {}
157 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other) : value( other.value ) {}
158 KOKKOS_FORCEINLINE_FUNCTION
void operator+=(ValueType
const& rhs) {
161 KOKKOS_FORCEINLINE_FUNCTION
void operator-=(ValueType
const& rhs) {
168 template <
typename ValueType>
169 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterSum, Kokkos::Experimental::ScatterAtomic> {
171 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in) : value( value_in ) {}
172 KOKKOS_FORCEINLINE_FUNCTION
void operator+=(ValueType
const& rhs) {
173 Kokkos::atomic_add(&value, rhs);
175 KOKKOS_FORCEINLINE_FUNCTION
void operator-=(ValueType
const& rhs) {
176 Kokkos::atomic_add(&value, -rhs);
186 template <
typename T,
typename Layout>
187 struct DuplicatedDataType;
189 template <
typename T>
190 struct DuplicatedDataType<T, Kokkos::LayoutRight> {
191 typedef T* value_type;
194 template <
typename T,
size_t N>
195 struct DuplicatedDataType<T[N], Kokkos::LayoutRight> {
196 typedef typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type value_type[N];
199 template <
typename T>
200 struct DuplicatedDataType<T[], Kokkos::LayoutRight> {
201 typedef typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type value_type[];
204 template <
typename T>
206 typedef typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type* value_type;
209 template <
typename T>
210 struct DuplicatedDataType<T, Kokkos::LayoutLeft> {
211 typedef T* value_type;
214 template <
typename T,
size_t N>
215 struct DuplicatedDataType<T[N], Kokkos::LayoutLeft> {
216 typedef typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type* value_type;
219 template <
typename T>
220 struct DuplicatedDataType<T[], Kokkos::LayoutLeft> {
221 typedef typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type* value_type;
224 template <
typename T>
226 typedef typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type* value_type;
232 template <
typename Layout,
int rank,
typename V,
typename ... Args>
234 typedef Slice<Layout,
rank - 1, V, Kokkos::Impl::ALL_t, Args...> next;
235 typedef typename next::value_type value_type;
238 value_type
get(V
const& src,
const size_t i, Args ... args) {
239 return next::get(src, i, Kokkos::ALL, args...);
243 template <
typename V,
typename ... Args>
244 struct Slice<Kokkos::LayoutRight, 1, V, Args...> {
245 typedef typename Kokkos::Impl::ViewMapping
252 value_type
get(V
const& src,
const size_t i, Args ... args) {
253 return Kokkos::subview(src, i, args...);
257 template <
typename V,
typename ... Args>
258 struct Slice<Kokkos::LayoutLeft, 1, V, Args...> {
259 typedef typename Kokkos::Impl::ViewMapping
266 value_type
get(V
const& src,
const size_t i, Args ... args) {
267 return Kokkos::subview(src, args..., i);
271 template <
typename ExecSpace,
typename ValueType,
int Op>
272 struct ReduceDuplicates;
274 template <
typename ExecSpace,
typename ValueType,
int Op>
275 struct ReduceDuplicatesBase {
276 typedef ReduceDuplicates<ExecSpace, ValueType, Op> Derived;
277 ValueType
const* src;
282 ReduceDuplicatesBase(ValueType
const* src_in, ValueType* dest_in,
size_t stride_in,
size_t start_in,
size_t n_in, std::string
const& name)
289 #if defined(KOKKOS_ENABLE_PROFILING)
291 if(Kokkos::Profiling::profileLibraryLoaded()) {
292 Kokkos::Profiling::beginParallelFor(std::string(
"reduce_") + name, 0, &kpID);
295 typedef RangePolicy<ExecSpace, size_t> policy_type;
297 const closure_type closure(*(static_cast<Derived*>(
this)), policy_type(0, stride));
299 #if defined(KOKKOS_ENABLE_PROFILING)
300 if(Kokkos::Profiling::profileLibraryLoaded()) {
301 Kokkos::Profiling::endParallelFor(kpID);
307 template <
typename ExecSpace,
typename ValueType>
308 struct ReduceDuplicates<ExecSpace, ValueType, Kokkos::Experimental::ScatterSum> :
309 public ReduceDuplicatesBase<ExecSpace, ValueType, Kokkos::Experimental::ScatterSum>
311 typedef ReduceDuplicatesBase<ExecSpace, ValueType, Kokkos::Experimental::ScatterSum> Base;
312 ReduceDuplicates(ValueType
const* src_in, ValueType* dst_in,
size_t stride_in,
size_t start_in,
size_t n_in, std::string
const& name):
313 Base(src_in, dst_in, stride_in, start_in, n_in, name)
315 KOKKOS_FORCEINLINE_FUNCTION
void operator()(
size_t i)
const {
316 for (
size_t j = Base::start; j < Base::n; ++j) {
317 Base::dst[i] += Base::src[i + Base::stride * j];
322 template <
typename ExecSpace,
typename ValueType,
int Op>
323 struct ResetDuplicates;
325 template <
typename ExecSpace,
typename ValueType,
int Op>
326 struct ResetDuplicatesBase {
327 typedef ResetDuplicates<ExecSpace, ValueType, Op> Derived;
329 ResetDuplicatesBase(ValueType* data_in,
size_t size_in, std::string
const& name)
332 #if defined(KOKKOS_ENABLE_PROFILING)
334 if(Kokkos::Profiling::profileLibraryLoaded()) {
335 Kokkos::Profiling::beginParallelFor(std::string(
"reduce_") + name, 0, &kpID);
338 typedef RangePolicy<ExecSpace, size_t> policy_type;
340 const closure_type closure(*(static_cast<Derived*>(
this)), policy_type(0, size_in));
342 #if defined(KOKKOS_ENABLE_PROFILING)
343 if(Kokkos::Profiling::profileLibraryLoaded()) {
344 Kokkos::Profiling::endParallelFor(kpID);
350 template <
typename ExecSpace,
typename ValueType>
351 struct ResetDuplicates<ExecSpace, ValueType, Kokkos::Experimental::ScatterSum> :
352 public ResetDuplicatesBase<ExecSpace, ValueType, Kokkos::Experimental::ScatterSum>
354 typedef ResetDuplicatesBase<ExecSpace, ValueType, Kokkos::Experimental::ScatterSum> Base;
355 ResetDuplicates(ValueType* data_in,
size_t size_in, std::string
const& name):
356 Base(data_in, size_in, name)
358 KOKKOS_FORCEINLINE_FUNCTION
void operator()(
size_t i)
const {
359 Base::data[i] = Kokkos::reduction_identity<ValueType>::sum();
366 namespace Experimental {
368 template <
typename DataType
369 ,
typename Layout = Kokkos::DefaultExecutionSpace::array_layout
370 ,
typename ExecSpace = Kokkos::DefaultExecutionSpace
372 ,
int duplication = Kokkos::Impl::Experimental::DefaultDuplication<ExecSpace>::value
373 ,
int contribution = Kokkos::Impl::Experimental::DefaultContribution<ExecSpace, duplication>::value
377 template <
typename DataType
383 ,
int override_contribution
388 template <
typename DataType
394 class ScatterView<DataType
398 ,ScatterNonDuplicated
403 typedef typename original_view_type::value_type original_value_type;
404 typedef typename original_view_type::reference_type original_reference_type;
405 friend class ScatterAccess<DataType, Op, ExecSpace, Layout, ScatterNonDuplicated, contribution, ScatterNonAtomic>;
406 friend class ScatterAccess<DataType, Op, ExecSpace, Layout, ScatterNonDuplicated, contribution, ScatterAtomic>;
412 template <
typename RT,
typename ... RP>
413 ScatterView(View<RT, RP...>
const& original_view)
414 : internal_view(original_view)
418 template <
typename ... Dims>
419 ScatterView(std::string
const& name, Dims ... dims)
420 : internal_view(name, dims ...)
424 template <
int overr
ide_contrib = contribution>
425 KOKKOS_FORCEINLINE_FUNCTION
426 ScatterAccess<DataType, Op, ExecSpace, Layout, ScatterNonDuplicated, contribution, override_contrib>
428 return ScatterAccess<DataType, Op, ExecSpace, Layout, ScatterNonDuplicated, contribution, override_contrib>{*
this};
431 original_view_type subview()
const {
432 return internal_view;
435 template <
typename DT,
typename ... RP>
436 void contribute_into(View<DT, RP...>
const& dest)
const
438 typedef View<DT, RP...> dest_type;
439 static_assert(std::is_same<
440 typename dest_type::array_layout,
442 "ScatterView contribute destination has different layout");
443 static_assert(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace<
444 typename ExecSpace::memory_space,
445 typename dest_type::memory_space>::value,
446 "ScatterView contribute destination memory space not accessible");
447 if (dest.data() == internal_view.data())
return;
448 Kokkos::Impl::Experimental::ReduceDuplicates<ExecSpace, original_value_type, Op>(
449 internal_view.data(),
454 internal_view.label());
458 Kokkos::Impl::Experimental::ResetDuplicates<ExecSpace, original_value_type, Op>(
459 internal_view.data(),
460 internal_view.size(),
461 internal_view.label());
463 template <
typename DT,
typename ... RP>
464 void reset_except(View<DT, RP...>
const& view) {
465 if (view.data() != internal_view.data()) reset();
468 void resize(
const size_t n0 = 0,
475 const size_t n7 = 0) {
479 void realloc(
const size_t n0 = 0,
486 const size_t n7 = 0) {
491 template <
typename ... Args>
492 KOKKOS_FORCEINLINE_FUNCTION
493 original_reference_type at(Args ... args)
const {
494 return internal_view(args...);
497 typedef original_view_type internal_view_type;
498 internal_view_type internal_view;
501 template <
typename DataType
506 ,
int override_contribution
508 class ScatterAccess<DataType
512 ,ScatterNonDuplicated
514 ,override_contribution>
517 typedef ScatterView<DataType, Layout, ExecSpace, Op, ScatterNonDuplicated, contribution> view_type;
518 typedef typename view_type::original_value_type original_value_type;
519 typedef Kokkos::Impl::Experimental::ScatterValue<
520 original_value_type, Op, override_contribution> value_type;
522 KOKKOS_INLINE_FUNCTION
523 ScatterAccess(view_type
const& view_in)
528 template <
typename ... Args>
529 KOKKOS_FORCEINLINE_FUNCTION
530 value_type operator()(Args ... args)
const {
531 return view.at(args...);
534 template <
typename Arg>
535 KOKKOS_FORCEINLINE_FUNCTION
536 typename std::enable_if<view_type::original_view_type::rank == 1 &&
537 std::is_integral<Arg>::value, value_type>::type
538 operator[](Arg arg)
const {
543 view_type
const& view;
549 template <
typename DataType
554 class ScatterView<DataType
563 typedef typename original_view_type::value_type original_value_type;
564 typedef typename original_view_type::reference_type original_reference_type;
565 friend class ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutRight, ScatterDuplicated, contribution, ScatterNonAtomic>;
566 friend class ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutRight, ScatterDuplicated, contribution, ScatterAtomic>;
567 typedef typename Kokkos::Impl::Experimental::DuplicatedDataType<DataType, Kokkos::LayoutRight> data_type_info;
568 typedef typename data_type_info::value_type internal_data_type;
569 typedef
Kokkos::View<internal_data_type, Kokkos::LayoutRight, ExecSpace> internal_view_type;
575 template <
typename RT,
typename ... RP >
576 ScatterView(View<RT, RP...>
const& original_view)
578 , internal_view(Kokkos::ViewAllocateWithoutInitializing(
579 std::string(
"duplicated_") + original_view.label()),
581 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
582 original_view.extent(0),
583 original_view.extent(1),
584 original_view.extent(2),
585 original_view.extent(3),
586 original_view.extent(4),
587 original_view.extent(5),
588 original_view.extent(6) )
590 original_view.rank_dynamic > 0 ? original_view.extent(0): KOKKOS_IMPL_CTOR_DEFAULT_ARG,
591 original_view.rank_dynamic > 1 ? original_view.extent(1): KOKKOS_IMPL_CTOR_DEFAULT_ARG,
592 original_view.rank_dynamic > 2 ? original_view.extent(2): KOKKOS_IMPL_CTOR_DEFAULT_ARG,
593 original_view.rank_dynamic > 3 ? original_view.extent(3): KOKKOS_IMPL_CTOR_DEFAULT_ARG,
594 original_view.rank_dynamic > 4 ? original_view.extent(4): KOKKOS_IMPL_CTOR_DEFAULT_ARG,
595 original_view.rank_dynamic > 5 ? original_view.extent(5): KOKKOS_IMPL_CTOR_DEFAULT_ARG,
596 original_view.rank_dynamic > 6 ? original_view.extent(6): KOKKOS_IMPL_CTOR_DEFAULT_ARG)
603 template <
typename ... Dims>
604 ScatterView(std::string
const& name, Dims ... dims)
605 : internal_view(Kokkos::ViewAllocateWithoutInitializing(name), unique_token.size(), dims ...)
610 template <
int overr
ide_contribution = contribution>
612 ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutRight, ScatterDuplicated, contribution, override_contribution>
614 return ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutRight, ScatterDuplicated, contribution, override_contribution>{*
this};
617 typename Kokkos::Impl::Experimental::Slice<
621 return Kokkos::Impl::Experimental::Slice<
625 template <
typename DT,
typename ... RP>
626 void contribute_into(View<DT, RP...>
const& dest)
const
628 typedef View<DT, RP...> dest_type;
629 static_assert(std::is_same<
630 typename dest_type::array_layout,
632 "ScatterView deep_copy destination has different layout");
633 static_assert(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace<
634 typename ExecSpace::memory_space,
635 typename dest_type::memory_space>::value,
636 "ScatterView deep_copy destination memory space not accessible");
637 bool is_equal = (dest.data() == internal_view.data());
638 size_t start = is_equal ? 1 : 0;
639 Kokkos::Impl::Experimental::ReduceDuplicates<ExecSpace, original_value_type, Op>(
640 internal_view.data(),
642 internal_view.stride(0),
644 internal_view.extent(0),
645 internal_view.label());
649 Kokkos::Impl::Experimental::ResetDuplicates<ExecSpace, original_value_type, Op>(
650 internal_view.data(),
651 internal_view.size(),
652 internal_view.label());
654 template <
typename DT,
typename ... RP>
655 void reset_except(View<DT, RP...>
const& view) {
656 if (view.data() != internal_view.data()) {
660 Kokkos::Impl::Experimental::ResetDuplicates<ExecSpace, original_value_type, Op>(
661 internal_view.data() + view.size(),
662 internal_view.size() - view.size(),
663 internal_view.label());
666 void resize(
const size_t n0 = 0,
672 const size_t n6 = 0) {
676 void realloc(
const size_t n0 = 0,
682 const size_t n6 = 0) {
687 template <
typename ... Args>
688 KOKKOS_FORCEINLINE_FUNCTION
689 original_reference_type at(
int rank, Args ... args)
const {
690 return internal_view(rank, args...);
695 ExecSpace, Kokkos::Experimental::UniqueTokenScope::Global> unique_token_type;
697 unique_token_type unique_token;
698 internal_view_type internal_view;
701 template <
typename DataType
706 class ScatterView<DataType
715 typedef typename original_view_type::value_type original_value_type;
716 typedef typename original_view_type::reference_type original_reference_type;
717 friend class ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutLeft, ScatterDuplicated, contribution, ScatterNonAtomic>;
718 friend class ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutLeft, ScatterDuplicated, contribution, ScatterAtomic>;
719 typedef typename Kokkos::Impl::Experimental::DuplicatedDataType<DataType, Kokkos::LayoutLeft> data_type_info;
720 typedef typename data_type_info::value_type internal_data_type;
721 typedef
Kokkos::View<internal_data_type, Kokkos::LayoutLeft, ExecSpace> internal_view_type;
727 template <
typename RT,
typename ... RP >
728 ScatterView(View<RT, RP...>
const& original_view)
732 original_view.extent(0),
733 original_view.extent(1),
734 original_view.extent(2),
735 original_view.extent(3),
736 original_view.extent(4),
737 original_view.extent(5),
738 original_view.extent(6),
741 arg_N[internal_view_type::rank - 1] = unique_token.size();
742 internal_view = internal_view_type(
743 Kokkos::ViewAllocateWithoutInitializing(
744 std::string(
"duplicated_") + original_view.label()),
745 arg_N[0], arg_N[1], arg_N[2], arg_N[3],
746 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
750 template <
typename ... Dims>
751 ScatterView(std::string
const& name, Dims ... dims)
752 : internal_view(Kokkos::ViewAllocateWithoutInitializing(name), dims ..., unique_token.size())
757 template <
int overr
ide_contribution = contribution>
759 ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutLeft, ScatterDuplicated, contribution, override_contribution>
761 return ScatterAccess<DataType, Op, ExecSpace, Kokkos::LayoutLeft, ScatterDuplicated, contribution, override_contribution>{*
this};
764 typename Kokkos::Impl::Experimental::Slice<
768 return Kokkos::Impl::Experimental::Slice<
769 Kokkos::LayoutLeft, internal_view_type::rank, internal_view_type>::get(internal_view, 0);
772 template <
typename ... RP>
773 void contribute_into(View<DataType, RP...>
const& dest)
const
775 typedef View<DataType, RP...> dest_type;
776 static_assert(std::is_same<
777 typename dest_type::array_layout,
779 "ScatterView deep_copy destination has different layout");
780 static_assert(Kokkos::Impl::VerifyExecutionCanAccessMemorySpace<
781 typename ExecSpace::memory_space,
782 typename dest_type::memory_space>::value,
783 "ScatterView deep_copy destination memory space not accessible");
784 auto extent = internal_view.extent(
785 internal_view_type::rank - 1);
786 bool is_equal = (dest.data() == internal_view.data());
787 size_t start = is_equal ? 1 : 0;
788 Kokkos::Impl::Experimental::ReduceDuplicates<ExecSpace, original_value_type, Op>(
789 internal_view.data(),
791 internal_view.stride(internal_view_type::rank - 1),
794 internal_view.label());
798 Kokkos::Impl::Experimental::ResetDuplicates<ExecSpace, original_value_type, Op>(
799 internal_view.data(),
800 internal_view.size(),
801 internal_view.label());
803 template <
typename DT,
typename ... RP>
804 void reset_except(View<DT, RP...>
const& view) {
805 if (view.data() != internal_view.data()) {
809 Kokkos::Impl::Experimental::ResetDuplicates<ExecSpace, original_value_type, Op>(
810 internal_view.data() + view.size(),
811 internal_view.size() - view.size(),
812 internal_view.label());
815 void resize(
const size_t n0 = 0,
821 const size_t n6 = 0) {
823 size_t arg_N[8] = {n0,n1,n2,n3,n4,n5,n6,0};
824 const int i = internal_view.rank-1;
825 arg_N[i] = unique_token.size();
828 arg_N[0], arg_N[1], arg_N[2], arg_N[3],
829 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
832 void realloc(
const size_t n0 = 0,
838 const size_t n6 = 0) {
840 size_t arg_N[8] = {n0,n1,n2,n3,n4,n5,n6,0};
841 const int i = internal_view.rank-1;
842 arg_N[i] = unique_token.size();
845 arg_N[0], arg_N[1], arg_N[2], arg_N[3],
846 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
850 template <
typename ... Args>
851 inline original_reference_type at(
int thread_id, Args ... args)
const {
852 return internal_view(args..., thread_id);
857 ExecSpace, Kokkos::Experimental::UniqueTokenScope::Global> unique_token_type;
859 unique_token_type unique_token;
860 internal_view_type internal_view;
873 template <
typename DataType
878 ,
int override_contribution
880 class ScatterAccess<DataType
886 ,override_contribution>
889 typedef ScatterView<DataType, Layout, ExecSpace, Op, ScatterDuplicated, contribution> view_type;
890 typedef typename view_type::original_value_type original_value_type;
891 typedef Kokkos::Impl::Experimental::ScatterValue<
892 original_value_type, Op, override_contribution> value_type;
894 inline ScatterAccess(view_type
const& view_in)
896 , thread_id(view_in.unique_token.acquire()) {
899 inline ~ScatterAccess() {
900 if (thread_id != ~thread_id_type(0)) view.unique_token.release(thread_id);
903 template <
typename ... Args>
904 KOKKOS_FORCEINLINE_FUNCTION
905 value_type operator()(Args ... args)
const {
906 return view.at(thread_id, args...);
909 template <
typename Arg>
910 KOKKOS_FORCEINLINE_FUNCTION
911 typename std::enable_if<view_type::original_view_type::rank == 1 &&
912 std::is_integral<Arg>::value, value_type>::type
913 operator[](Arg arg)
const {
914 return view.at(thread_id, arg);
919 view_type
const& view;
922 ScatterAccess(ScatterAccess
const& other) =
delete;
923 ScatterAccess& operator=(ScatterAccess
const& other) =
delete;
924 ScatterAccess& operator=(ScatterAccess&& other) =
delete;
930 inline ScatterAccess(ScatterAccess&& other)
932 , thread_id(other.thread_id)
934 other.thread_id = ~thread_id_type(0);
939 typedef typename view_type::unique_token_type unique_token_type;
940 typedef typename unique_token_type::size_type thread_id_type;
941 thread_id_type thread_id;
944 template <
int Op = Kokkos::Experimental::ScatterSum,
945 int duplication = -1,
946 int contribution = -1,
947 typename RT,
typename ... RP>
950 ,
typename ViewTraits<RT, RP...>::array_layout
951 ,
typename ViewTraits<RT, RP...>::execution_space
956 , duplication == -1 ? Kokkos::Impl::Experimental::DefaultDuplication<
typename ViewTraits<RT, RP...>::execution_space>::value : duplication
957 , contribution == -1 ?
958 Kokkos::Impl::Experimental::DefaultContribution<
959 typename ViewTraits<RT, RP...>::execution_space,
961 Kokkos::Impl::Experimental::DefaultDuplication<
962 typename ViewTraits<RT, RP...>::execution_space
969 create_scatter_view(View<RT, RP...>
const& original_view) {
970 return original_view;
976 namespace Experimental {
978 template <
typename DT1,
typename DT2,
typename LY,
typename ES,
int OP,
int CT,
int DP,
typename ... VP>
980 contribute(View<DT1, VP...>& dest, Kokkos::Experimental::ScatterView<DT2, LY, ES, OP, CT, DP>
const& src)
982 src.contribute_into(dest);
989 template <
typename DT,
typename LY,
typename ES,
int OP,
int CT,
int DP,
typename ... IS>
991 realloc(Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view, IS ... is)
993 scatter_view.realloc(is ...);
996 template <
typename DT,
typename LY,
typename ES,
int OP,
int CT,
int DP,
typename ... IS>
998 resize(Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view, IS ... is)
1000 scatter_view.resize(is ...);
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
class to generate unique ids base on the required amount of concurrency
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type resize(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with copying old data to new data at the corresponding indices.
View to an array of data.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
void resize(DynRankView< T, P...> &v, const size_t n0=KOKKOS_INVALID_INDEX, const size_t n1=KOKKOS_INVALID_INDEX, const size_t n2=KOKKOS_INVALID_INDEX, const size_t n3=KOKKOS_INVALID_INDEX, const size_t n4=KOKKOS_INVALID_INDEX, const size_t n5=KOKKOS_INVALID_INDEX, const size_t n6=KOKKOS_INVALID_INDEX, const size_t n7=KOKKOS_INVALID_INDEX)
Resize a view with copying old data to new data at the corresponding indices.
Implementation of the ParallelFor operator that has a partial specialization for the device...
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type realloc(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with discarding old data.
KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View< D, P...> &V)
Temporary free function rank() until rank() is implemented in the View.
void realloc(DynRankView< T, P...> &v, const size_t n0=KOKKOS_INVALID_INDEX, const size_t n1=KOKKOS_INVALID_INDEX, const size_t n2=KOKKOS_INVALID_INDEX, const size_t n3=KOKKOS_INVALID_INDEX, const size_t n4=KOKKOS_INVALID_INDEX, const size_t n5=KOKKOS_INVALID_INDEX, const size_t n6=KOKKOS_INVALID_INDEX, const size_t n7=KOKKOS_INVALID_INDEX)
Resize a view with copying old data to new data at the corresponding indices.