23 #ifndef KOKKOS_SCATTER_VIEW_HPP
24 #define KOKKOS_SCATTER_VIEW_HPP
25 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
26 #define KOKKOS_IMPL_PUBLIC_INCLUDE
27 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SCATTERVIEW
30 #include <Kokkos_Core.hpp>
34 namespace Experimental {
42 struct ScatterProd {};
46 struct ScatterNonDuplicated {};
47 struct ScatterDuplicated {};
49 struct ScatterNonAtomic {};
50 struct ScatterAtomic {};
57 namespace Experimental {
59 template <
typename ExecSpace>
60 struct DefaultDuplication;
62 template <
typename ExecSpace,
typename Duplication>
63 struct DefaultContribution;
65 #ifdef KOKKOS_ENABLE_SERIAL
67 struct DefaultDuplication<Kokkos::Serial> {
68 using type = Kokkos::Experimental::ScatterNonDuplicated;
72 struct DefaultContribution<Kokkos::Serial,
73 Kokkos::Experimental::ScatterNonDuplicated> {
74 using type = Kokkos::Experimental::ScatterNonAtomic;
77 struct DefaultContribution<Kokkos::Serial,
78 Kokkos::Experimental::ScatterDuplicated> {
79 using type = Kokkos::Experimental::ScatterNonAtomic;
83 #ifdef KOKKOS_ENABLE_OPENMP
85 struct DefaultDuplication<Kokkos::OpenMP> {
86 using type = Kokkos::Experimental::ScatterDuplicated;
89 struct DefaultContribution<Kokkos::OpenMP,
90 Kokkos::Experimental::ScatterNonDuplicated> {
91 using type = Kokkos::Experimental::ScatterAtomic;
94 struct DefaultContribution<Kokkos::OpenMP,
95 Kokkos::Experimental::ScatterDuplicated> {
96 using type = Kokkos::Experimental::ScatterNonAtomic;
100 #ifdef KOKKOS_ENABLE_OPENMPTARGET
102 struct DefaultDuplication<Kokkos::Experimental::OpenMPTarget> {
103 using type = Kokkos::Experimental::ScatterNonDuplicated;
106 struct DefaultContribution<Kokkos::Experimental::OpenMPTarget,
107 Kokkos::Experimental::ScatterNonDuplicated> {
108 using type = Kokkos::Experimental::ScatterAtomic;
111 struct DefaultContribution<Kokkos::Experimental::OpenMPTarget,
112 Kokkos::Experimental::ScatterDuplicated> {
113 using type = Kokkos::Experimental::ScatterNonAtomic;
117 #ifdef KOKKOS_ENABLE_HPX
119 struct DefaultDuplication<Kokkos::Experimental::HPX> {
120 using type = Kokkos::Experimental::ScatterDuplicated;
123 struct DefaultContribution<Kokkos::Experimental::HPX,
124 Kokkos::Experimental::ScatterNonDuplicated> {
125 using type = Kokkos::Experimental::ScatterAtomic;
128 struct DefaultContribution<Kokkos::Experimental::HPX,
129 Kokkos::Experimental::ScatterDuplicated> {
130 using type = Kokkos::Experimental::ScatterNonAtomic;
134 #ifdef KOKKOS_ENABLE_THREADS
136 struct DefaultDuplication<Kokkos::Threads> {
137 using type = Kokkos::Experimental::ScatterDuplicated;
140 struct DefaultContribution<Kokkos::Threads,
141 Kokkos::Experimental::ScatterNonDuplicated> {
142 using type = Kokkos::Experimental::ScatterAtomic;
145 struct DefaultContribution<Kokkos::Threads,
146 Kokkos::Experimental::ScatterDuplicated> {
147 using type = Kokkos::Experimental::ScatterNonAtomic;
151 #ifdef KOKKOS_ENABLE_CUDA
153 struct DefaultDuplication<Kokkos::Cuda> {
154 using type = Kokkos::Experimental::ScatterNonDuplicated;
157 struct DefaultContribution<Kokkos::Cuda,
158 Kokkos::Experimental::ScatterNonDuplicated> {
159 using type = Kokkos::Experimental::ScatterAtomic;
162 struct DefaultContribution<Kokkos::Cuda,
163 Kokkos::Experimental::ScatterDuplicated> {
164 using type = Kokkos::Experimental::ScatterAtomic;
168 #ifdef KOKKOS_ENABLE_HIP
170 struct DefaultDuplication<Kokkos::HIP> {
171 using type = Kokkos::Experimental::ScatterNonDuplicated;
174 struct DefaultContribution<Kokkos::HIP,
175 Kokkos::Experimental::ScatterNonDuplicated> {
176 using type = Kokkos::Experimental::ScatterAtomic;
179 struct DefaultContribution<Kokkos::HIP,
180 Kokkos::Experimental::ScatterDuplicated> {
181 using type = Kokkos::Experimental::ScatterAtomic;
185 #ifdef KOKKOS_ENABLE_SYCL
187 struct DefaultDuplication<Kokkos::Experimental::SYCL> {
188 using type = Kokkos::Experimental::ScatterNonDuplicated;
191 struct DefaultContribution<Kokkos::Experimental::SYCL,
192 Kokkos::Experimental::ScatterNonDuplicated> {
193 using type = Kokkos::Experimental::ScatterAtomic;
196 struct DefaultContribution<Kokkos::Experimental::SYCL,
197 Kokkos::Experimental::ScatterDuplicated> {
198 using type = Kokkos::Experimental::ScatterAtomic;
207 template <
typename ValueType,
typename Op,
typename DeviceType,
208 typename Contribution>
217 template <
typename ValueType,
typename DeviceType>
218 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterSum, DeviceType,
219 Kokkos::Experimental::ScatterNonAtomic> {
223 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
225 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other)
226 : value(other.value) {}
227 KOKKOS_FORCEINLINE_FUNCTION
void operator+=(ValueType
const& rhs) {
230 KOKKOS_FORCEINLINE_FUNCTION
void operator++() { update(1); }
231 KOKKOS_FORCEINLINE_FUNCTION
void operator++(
int) { update(1); }
232 KOKKOS_FORCEINLINE_FUNCTION
void operator-=(ValueType
const& rhs) {
233 update(ValueType(-rhs));
235 KOKKOS_FORCEINLINE_FUNCTION
void operator--() { update(ValueType(-1)); }
236 KOKKOS_FORCEINLINE_FUNCTION
void operator--(
int) { update(ValueType(-1)); }
237 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
240 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
241 value = reduction_identity<ValueType>::sum();
250 template <
typename ValueType,
typename DeviceType>
251 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterSum, DeviceType,
252 Kokkos::Experimental::ScatterAtomic> {
256 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
259 KOKKOS_FORCEINLINE_FUNCTION
void operator+=(ValueType
const& rhs) {
260 this->join(value, rhs);
262 KOKKOS_FORCEINLINE_FUNCTION
void operator++() { this->join(value, 1); }
263 KOKKOS_FORCEINLINE_FUNCTION
void operator++(
int) { this->join(value, 1); }
264 KOKKOS_FORCEINLINE_FUNCTION
void operator-=(ValueType
const& rhs) {
265 this->join(value, ValueType(-rhs));
267 KOKKOS_FORCEINLINE_FUNCTION
void operator--() {
268 this->join(value, ValueType(-1));
270 KOKKOS_FORCEINLINE_FUNCTION
void operator--(
int) {
271 this->join(value, ValueType(-1));
274 KOKKOS_INLINE_FUNCTION
275 void join(ValueType& dest,
const ValueType& src)
const {
276 Kokkos::atomic_add(&dest, src);
279 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
280 this->join(value, rhs);
283 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
284 value = reduction_identity<ValueType>::sum();
294 template <
typename ValueType,
typename DeviceType>
295 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterProd, DeviceType,
296 Kokkos::Experimental::ScatterNonAtomic> {
300 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
302 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other)
303 : value(other.value) {}
304 KOKKOS_FORCEINLINE_FUNCTION
void operator*=(ValueType
const& rhs) {
307 KOKKOS_FORCEINLINE_FUNCTION
void operator/=(ValueType
const& rhs) {
311 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
314 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
315 value = reduction_identity<ValueType>::prod();
325 template <
typename ValueType,
typename DeviceType>
326 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterProd, DeviceType,
327 Kokkos::Experimental::ScatterAtomic> {
331 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
333 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other)
334 : value(other.value) {}
336 KOKKOS_FORCEINLINE_FUNCTION
void operator*=(ValueType
const& rhs) {
337 Kokkos::atomic_mul(&value, rhs);
339 KOKKOS_FORCEINLINE_FUNCTION
void operator/=(ValueType
const& rhs) {
340 Kokkos::atomic_div(&value, rhs);
343 KOKKOS_INLINE_FUNCTION
344 void join(ValueType& dest,
const ValueType& src)
const {
345 atomic_prod(&dest, src);
348 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
349 atomic_prod(&value, rhs);
351 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
352 value = reduction_identity<ValueType>::prod();
362 template <
typename ValueType,
typename DeviceType>
363 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterMin, DeviceType,
364 Kokkos::Experimental::ScatterNonAtomic> {
366 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
368 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other)
369 : value(other.value) {}
372 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
373 value = rhs < value ? rhs : value;
375 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
376 value = reduction_identity<ValueType>::min();
386 template <
typename ValueType,
typename DeviceType>
387 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterMin, DeviceType,
388 Kokkos::Experimental::ScatterAtomic> {
392 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
394 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other)
395 : value(other.value) {}
397 KOKKOS_INLINE_FUNCTION
398 void join(ValueType& dest,
const ValueType& src)
const {
399 atomic_min(&dest, src);
402 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
403 this->join(value, rhs);
405 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
406 value = reduction_identity<ValueType>::min();
416 template <
typename ValueType,
typename DeviceType>
417 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterMax, DeviceType,
418 Kokkos::Experimental::ScatterNonAtomic> {
422 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
424 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other)
425 : value(other.value) {}
426 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
427 value = rhs > value ? rhs : value;
429 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
430 value = reduction_identity<ValueType>::max();
440 template <
typename ValueType,
typename DeviceType>
441 struct ScatterValue<ValueType, Kokkos::Experimental::ScatterMax, DeviceType,
442 Kokkos::Experimental::ScatterAtomic> {
446 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ValueType& value_in)
448 KOKKOS_FORCEINLINE_FUNCTION ScatterValue(ScatterValue&& other)
449 : value(other.value) {}
451 KOKKOS_INLINE_FUNCTION
452 void join(ValueType& dest,
const ValueType& src)
const {
453 atomic_max(&dest, src);
456 KOKKOS_FORCEINLINE_FUNCTION
void update(ValueType
const& rhs) {
457 this->join(value, rhs);
459 KOKKOS_FORCEINLINE_FUNCTION
void reset() {
460 value = reduction_identity<ValueType>::max();
469 template <
typename T,
typename Layout>
470 struct DuplicatedDataType;
472 template <
typename T>
473 struct DuplicatedDataType<T, Kokkos::LayoutRight> {
474 using value_type = T*;
477 template <
typename T,
size_t N>
478 struct DuplicatedDataType<T[N], Kokkos::LayoutRight> {
480 typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type[N];
483 template <
typename T>
484 struct DuplicatedDataType<T[], Kokkos::LayoutRight> {
486 typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type[];
489 template <
typename T>
492 typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type*;
495 template <
typename T>
496 struct DuplicatedDataType<T, Kokkos::LayoutLeft> {
497 using value_type = T*;
500 template <
typename T,
size_t N>
501 struct DuplicatedDataType<T[N], Kokkos::LayoutLeft> {
503 typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type*;
506 template <
typename T>
507 struct DuplicatedDataType<T[], Kokkos::LayoutLeft> {
509 typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type*;
512 template <
typename T>
515 typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type*;
521 void args_to_array(
size_t* array,
int pos, T dim0) {
524 template <
class T,
class... Dims>
525 void args_to_array(
size_t* array,
int pos, T dim0, Dims... dims) {
527 args_to_array(array, pos + 1, dims...);
533 template <
typename Layout,
int rank,
typename V,
typename... Args>
535 using next = Slice<Layout, rank - 1, V, Kokkos::ALL_t, Args...>;
536 using value_type =
typename next::value_type;
538 static value_type
get(V
const& src,
const size_t i, Args... args) {
539 return next::get(src, i, Kokkos::ALL, args...);
543 template <
typename V,
typename... Args>
544 struct Slice<Kokkos::LayoutRight, 1, V, Args...> {
546 typename Kokkos::Impl::ViewMapping<void, V,
const size_t, Args...>::type;
547 static value_type
get(V
const& src,
const size_t i, Args... args) {
548 return Kokkos::subview(src, i, args...);
552 template <
typename V,
typename... Args>
553 struct Slice<Kokkos::LayoutLeft, 1, V, Args...> {
555 typename Kokkos::Impl::ViewMapping<void, V, Args...,
const size_t>::type;
556 static value_type
get(V
const& src,
const size_t i, Args... args) {
557 return Kokkos::subview(src, args..., i);
561 template <
typename ExecSpace,
typename ValueType,
typename Op>
562 struct ReduceDuplicates;
564 template <
typename ExecSpace,
typename ValueType,
typename Op>
565 struct ReduceDuplicatesBase {
566 using Derived = ReduceDuplicates<ExecSpace, ValueType, Op>;
567 ValueType
const* src;
572 ReduceDuplicatesBase(ExecSpace
const& exec_space, ValueType
const* src_in,
573 ValueType* dest_in,
size_t stride_in,
size_t start_in,
574 size_t n_in, std::string
const& name)
575 : src(src_in), dst(dest_in), stride(stride_in), start(start_in), n(n_in) {
577 std::string(
"Kokkos::ScatterView::ReduceDuplicates [") + name +
"]",
578 RangePolicy<ExecSpace, size_t>(exec_space, 0, stride),
579 static_cast<Derived const&>(*
this));
586 template <
typename ExecSpace,
typename ValueType,
typename Op>
587 struct ReduceDuplicates
588 :
public ReduceDuplicatesBase<ExecSpace, ValueType, Op> {
589 using Base = ReduceDuplicatesBase<ExecSpace, ValueType, Op>;
590 ReduceDuplicates(ExecSpace
const& exec_space, ValueType
const* src_in,
591 ValueType* dst_in,
size_t stride_in,
size_t start_in,
592 size_t n_in, std::string
const& name)
593 : Base(exec_space, src_in, dst_in, stride_in, start_in, n_in, name) {}
594 KOKKOS_FORCEINLINE_FUNCTION
void operator()(
size_t i)
const {
595 for (
size_t j = Base::start; j < Base::n; ++j) {
596 ScatterValue<ValueType, Op, ExecSpace,
597 Kokkos::Experimental::ScatterNonAtomic>
599 sv.update(Base::src[i + Base::stride * j]);
604 template <
typename ExecSpace,
typename ValueType,
typename Op>
605 struct ResetDuplicates;
607 template <
typename ExecSpace,
typename ValueType,
typename Op>
608 struct ResetDuplicatesBase {
609 using Derived = ResetDuplicates<ExecSpace, ValueType, Op>;
611 ResetDuplicatesBase(ExecSpace
const& exec_space, ValueType* data_in,
612 size_t size_in, std::string
const& name)
615 std::string(
"Kokkos::ScatterView::ResetDuplicates [") + name +
"]",
616 RangePolicy<ExecSpace, size_t>(exec_space, 0, size_in),
617 static_cast<Derived const&>(*
this));
624 template <
typename ExecSpace,
typename ValueType,
typename Op>
625 struct ResetDuplicates :
public ResetDuplicatesBase<ExecSpace, ValueType, Op> {
626 using Base = ResetDuplicatesBase<ExecSpace, ValueType, Op>;
627 ResetDuplicates(ExecSpace
const& exec_space, ValueType* data_in,
628 size_t size_in, std::string
const& name)
629 : Base(exec_space, data_in, size_in, name) {}
630 KOKKOS_FORCEINLINE_FUNCTION
void operator()(
size_t i)
const {
631 ScatterValue<ValueType, Op, ExecSpace,
632 Kokkos::Experimental::ScatterNonAtomic>
638 template <
typename... P>
639 void check_scatter_view_allocation_properties_argument(
640 ViewCtorProp<P...>
const&) {
641 static_assert(ViewCtorProp<P...>::has_execution_space &&
642 ViewCtorProp<P...>::has_label &&
643 ViewCtorProp<P...>::initialize,
644 "Allocation property must have an execution name as well as a "
645 "label, and must perform the view initialization");
653 namespace Experimental {
655 template <
typename DataType,
656 typename Layout = Kokkos::DefaultExecutionSpace::array_layout,
657 typename DeviceType = Kokkos::DefaultExecutionSpace,
658 typename Op = Kokkos::Experimental::ScatterSum,
659 typename Duplication =
typename Kokkos::Impl::Experimental::
660 DefaultDuplication<typename DeviceType::execution_space>::type,
661 typename Contribution =
662 typename Kokkos::Impl::Experimental::DefaultContribution<
663 typename DeviceType::execution_space, Duplication>::type>
667 struct is_scatter_view :
public std::false_type {};
669 template <
class D,
class... P>
670 struct is_scatter_view<ScatterView<D, P...>> :
public std::true_type {};
672 template <
class D,
class... P>
673 struct is_scatter_view<const ScatterView<D, P...>> :
public std::true_type {};
676 inline constexpr
bool is_scatter_view_v = is_scatter_view<T>::value;
678 template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
679 typename Duplication,
typename Contribution,
680 typename OverrideContribution>
684 template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
685 typename Contribution>
686 class ScatterView<DataType, Layout, DeviceType, Op, ScatterNonDuplicated,
689 using execution_space =
typename DeviceType::execution_space;
690 using memory_space =
typename DeviceType::memory_space;
691 using device_type = Kokkos::Device<execution_space, memory_space>;
693 using original_value_type =
typename original_view_type::value_type;
694 using original_reference_type =
typename original_view_type::reference_type;
695 friend class ScatterAccess<DataType, Op, DeviceType, Layout,
696 ScatterNonDuplicated, Contribution,
698 friend class ScatterAccess<DataType, Op, DeviceType, Layout,
699 ScatterNonDuplicated, Contribution, ScatterAtomic>;
700 template <
class,
class,
class,
class,
class,
class>
701 friend class ScatterView;
703 ScatterView() =
default;
705 template <
typename RT,
typename... RP>
706 ScatterView(View<RT, RP...>
const& original_view)
707 : internal_view(original_view) {}
709 template <
typename RT,
typename... P,
typename... RP>
710 ScatterView(execution_space
const& ,
711 View<RT, RP...>
const& original_view)
712 : internal_view(original_view) {}
714 template <
typename... Dims>
715 ScatterView(std::string
const& name, Dims... dims)
716 : internal_view(name, dims...) {}
721 template <
typename... P,
typename... Dims>
722 ScatterView(::Kokkos::Impl::ViewCtorProp<P...>
const& arg_prop, Dims... dims)
723 : internal_view(arg_prop, dims...) {
724 using ::Kokkos::Impl::Experimental::
725 check_scatter_view_allocation_properties_argument;
726 check_scatter_view_allocation_properties_argument(arg_prop);
729 template <
typename OtherDataType,
typename OtherDeviceType>
730 KOKKOS_FUNCTION ScatterView(
731 const ScatterView<OtherDataType, Layout, OtherDeviceType, Op,
732 ScatterNonDuplicated, Contribution>& other_view)
733 : internal_view(other_view.internal_view) {}
735 template <
typename OtherDataType,
typename OtherDeviceType>
736 KOKKOS_FUNCTION ScatterView& operator=(
737 const ScatterView<OtherDataType, Layout, OtherDeviceType, Op,
738 ScatterNonDuplicated, Contribution>& other_view) {
739 internal_view = other_view.internal_view;
743 template <
typename Overr
ideContribution = Contribution>
744 KOKKOS_FORCEINLINE_FUNCTION
745 ScatterAccess<DataType, Op, DeviceType, Layout, ScatterNonDuplicated,
746 Contribution, OverrideContribution>
748 return ScatterAccess<DataType, Op, DeviceType, Layout, ScatterNonDuplicated,
749 Contribution, OverrideContribution>(*this);
752 original_view_type subview()
const {
return internal_view; }
754 KOKKOS_INLINE_FUNCTION constexpr
bool is_allocated()
const {
755 return internal_view.is_allocated();
758 template <
typename DT,
typename... RP>
759 void contribute_into(View<DT, RP...>
const& dest)
const {
760 contribute_into(execution_space(), dest);
763 template <
typename DT,
typename... RP>
764 void contribute_into(execution_space
const& exec_space,
765 View<DT, RP...>
const& dest)
const {
766 using dest_type =
View<DT, RP...>;
767 static_assert(std::is_same<typename dest_type::array_layout, Layout>::value,
768 "ScatterView contribute destination has different layout");
771 execution_space,
typename dest_type::memory_space>::accessible,
772 "ScatterView contribute destination memory space not accessible");
773 if (dest.data() == internal_view.data())
return;
774 Kokkos::Impl::Experimental::ReduceDuplicates<execution_space,
775 original_value_type, Op>(
776 exec_space, internal_view.data(), dest.data(), 0, 0, 1,
777 internal_view.label());
780 void reset(execution_space
const& exec_space = execution_space()) {
781 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
782 original_value_type, Op>(
783 exec_space, internal_view.data(), internal_view.size(),
784 internal_view.label());
786 template <
typename DT,
typename... RP>
787 void reset_except(View<DT, RP...>
const& view) {
788 reset_except(execution_space(), view);
791 template <
typename DT,
typename... RP>
792 void reset_except(
const execution_space& exec_space,
793 View<DT, RP...>
const& view) {
794 if (view.data() != internal_view.data()) reset(exec_space);
797 void resize(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
798 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
799 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
800 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
801 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
802 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
803 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
804 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
805 ::Kokkos::resize(internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
808 template <
class... ViewCtorArgs>
809 void resize(const ::Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
810 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
811 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
812 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
813 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
814 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
815 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
816 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
817 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
818 ::Kokkos::resize(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
822 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
823 const I& arg_prop,
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
824 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
825 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
826 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
827 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
828 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
829 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
830 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
831 ::Kokkos::resize(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
834 template <
class... ViewCtorArgs>
835 void realloc(
const Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
836 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
837 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
838 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
839 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
840 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
841 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
842 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
843 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
844 ::Kokkos::realloc(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
847 void realloc(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
848 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
849 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
850 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
851 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
852 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
853 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
854 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
855 ::Kokkos::realloc(internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
859 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
860 const I& arg_prop,
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
861 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
862 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
863 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
864 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
865 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
866 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
867 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
868 ::Kokkos::realloc(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
872 template <
typename... Args>
873 KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(Args... args)
const {
874 return internal_view(args...);
878 using internal_view_type = original_view_type;
879 internal_view_type internal_view;
882 template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
883 typename Contribution,
typename OverrideContribution>
884 class ScatterAccess<DataType, Op, DeviceType, Layout, ScatterNonDuplicated,
885 Contribution, OverrideContribution> {
887 using view_type = ScatterView<DataType, Layout, DeviceType, Op,
888 ScatterNonDuplicated, Contribution>;
889 using original_value_type =
typename view_type::original_value_type;
890 using value_type = Kokkos::Impl::Experimental::ScatterValue<
891 original_value_type, Op, DeviceType, OverrideContribution>;
893 KOKKOS_INLINE_FUNCTION
894 ScatterAccess() : view(view_type()) {}
896 KOKKOS_INLINE_FUNCTION
897 ScatterAccess(view_type
const& view_in) : view(view_in) {}
898 KOKKOS_DEFAULTED_FUNCTION
899 ~ScatterAccess() =
default;
901 template <
typename... Args>
902 KOKKOS_FORCEINLINE_FUNCTION value_type operator()(Args... args)
const {
903 return view.at(args...);
906 template <
typename Arg>
907 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
908 view_type::original_view_type::rank == 1 && std::is_integral<Arg>::value,
910 operator[](Arg arg)
const {
915 view_type
const& view;
922 template <
typename DataType,
typename Op,
typename DeviceType,
923 typename Contribution>
924 class ScatterView<DataType, Kokkos::LayoutRight, DeviceType, Op,
925 ScatterDuplicated, Contribution> {
927 using execution_space =
typename DeviceType::execution_space;
928 using memory_space =
typename DeviceType::memory_space;
929 using device_type = Kokkos::Device<execution_space, memory_space>;
930 using original_view_type =
932 using original_value_type =
typename original_view_type::value_type;
933 using original_reference_type =
typename original_view_type::reference_type;
934 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutRight,
935 ScatterDuplicated, Contribution, ScatterNonAtomic>;
936 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutRight,
937 ScatterDuplicated, Contribution, ScatterAtomic>;
938 template <class, class, class, class, class, class>
939 friend class ScatterView;
941 using data_type_info =
942 typename Kokkos::Impl::Experimental::DuplicatedDataType<
943 DataType, Kokkos::LayoutRight>;
944 using internal_data_type = typename data_type_info::value_type;
945 using internal_view_type =
946 Kokkos::View<internal_data_type, Kokkos::LayoutRight, device_type>;
948 ScatterView() = default;
950 template <typename OtherDataType, typename OtherDeviceType>
951 KOKKOS_FUNCTION ScatterView(
952 const ScatterView<OtherDataType, Kokkos::LayoutRight, OtherDeviceType, Op,
953 ScatterDuplicated, Contribution>& other_view)
954 : unique_token(other_view.unique_token),
955 internal_view(other_view.internal_view) {}
957 template <
typename OtherDataType,
typename OtherDeviceType>
958 KOKKOS_FUNCTION ScatterView& operator=(
960 ScatterDuplicated, Contribution>& other_view) {
961 unique_token = other_view.unique_token;
962 internal_view = other_view.internal_view;
966 template <
typename RT,
typename... RP>
967 ScatterView(View<RT, RP...>
const& original_view)
968 : ScatterView(execution_space(), original_view) {}
970 template <
typename RT,
typename... P,
typename... RP>
971 ScatterView(execution_space
const& exec_space,
972 View<RT, RP...>
const& original_view)
975 view_alloc(WithoutInitializing,
976 std::string(
"duplicated_") + original_view.label(),
979 original_view.rank_dynamic > 0 ? original_view.extent(0)
980 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
981 original_view.rank_dynamic > 1 ? original_view.extent(1)
982 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
983 original_view.rank_dynamic > 2 ? original_view.extent(2)
984 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
985 original_view.rank_dynamic > 3 ? original_view.extent(3)
986 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
987 original_view.rank_dynamic > 4 ? original_view.extent(4)
988 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
989 original_view.rank_dynamic > 5 ? original_view.extent(5)
990 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
991 original_view.rank_dynamic > 6 ? original_view.extent(6)
992 : KOKKOS_IMPL_CTOR_DEFAULT_ARG)
998 template <
typename... Dims>
999 ScatterView(std::string
const& name, Dims... dims)
1000 : ScatterView(view_alloc(execution_space(), name), dims...) {}
1005 template <
typename... P,
typename... Dims>
1006 ScatterView(::Kokkos::Impl::ViewCtorProp<P...>
const& arg_prop, Dims... dims)
1007 : internal_view(view_alloc(WithoutInitializing,
1008 static_cast<::Kokkos::Impl::ViewCtorProp<
1009 void, std::string> const&>(arg_prop)
1011 unique_token.size(), dims...) {
1012 using ::Kokkos::Impl::Experimental::
1013 check_scatter_view_allocation_properties_argument;
1014 check_scatter_view_allocation_properties_argument(arg_prop);
1016 auto const& exec_space =
1017 Kokkos::Impl::get_property<Kokkos::Impl::ExecutionSpaceTag>(arg_prop);
1021 template <
typename Overr
ideContribution = Contribution>
1022 KOKKOS_FORCEINLINE_FUNCTION
1024 ScatterDuplicated, Contribution, OverrideContribution>
1027 ScatterDuplicated, Contribution, OverrideContribution>(
1032 internal_view_type::rank,
1033 internal_view_type>::value_type
1035 return Kokkos::Impl::Experimental::Slice<
1037 internal_view_type>::get(internal_view, 0);
1040 KOKKOS_INLINE_FUNCTION constexpr
bool is_allocated()
const {
1041 return internal_view.is_allocated();
1044 template <
typename DT,
typename... RP>
1045 void contribute_into(View<DT, RP...>
const& dest)
const {
1046 contribute_into(execution_space(), dest);
1049 template <
typename DT,
typename... RP>
1050 void contribute_into(execution_space
const& exec_space,
1051 View<DT, RP...>
const& dest)
const {
1052 using dest_type =
View<DT, RP...>;
1053 static_assert(std::is_same<
typename dest_type::array_layout,
1055 "ScatterView deep_copy destination has different layout");
1058 execution_space,
typename dest_type::memory_space>::accessible,
1059 "ScatterView deep_copy destination memory space not accessible");
1060 bool is_equal = (dest.data() == internal_view.data());
1061 size_t start = is_equal ? 1 : 0;
1062 Kokkos::Impl::Experimental::ReduceDuplicates<execution_space,
1063 original_value_type, Op>(
1064 exec_space, internal_view.data(), dest.data(), internal_view.stride(0),
1065 start, internal_view.extent(0), internal_view.label());
1068 void reset(execution_space
const& exec_space = execution_space()) {
1069 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1070 original_value_type, Op>(
1071 exec_space, internal_view.data(), internal_view.size(),
1072 internal_view.label());
1075 template <
typename DT,
typename... RP>
1076 void reset_except(View<DT, RP...>
const& view) {
1077 reset_except(execution_space(), view);
1080 template <
typename DT,
typename... RP>
1081 void reset_except(execution_space
const& exec_space,
1082 View<DT, RP...>
const& view) {
1083 if (view.data() != internal_view.data()) {
1087 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1088 original_value_type, Op>(
1089 exec_space, internal_view.data() + view.size(),
1090 internal_view.size() - view.size(), internal_view.label());
1093 void resize(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1094 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1095 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1096 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1097 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1098 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1099 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1100 ::Kokkos::resize(internal_view, unique_token.size(), n0, n1, n2, n3, n4, n5,
1104 template <
class... ViewCtorArgs>
1105 void resize(const ::Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1106 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1107 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1108 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1109 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1110 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1111 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1112 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1113 ::Kokkos::resize(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1118 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
1119 const I& arg_prop,
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1120 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1121 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1122 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1123 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1124 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1125 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1126 ::Kokkos::resize(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1130 template <
class... ViewCtorArgs>
1131 void realloc(const ::Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1132 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1133 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1134 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1135 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1136 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1137 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1138 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1139 ::Kokkos::realloc(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1143 void realloc(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1144 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1145 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1146 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1147 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1148 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1149 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1150 ::Kokkos::realloc(internal_view, unique_token.size(), n0, n1, n2, n3, n4,
1155 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
1156 const I& arg_prop,
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1157 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1158 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1159 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1160 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1161 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1162 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1163 ::Kokkos::realloc(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1168 template <
typename... Args>
1169 KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(
int rank,
1170 Args... args)
const {
1171 return internal_view(rank, args...);
1176 execution_space, Kokkos::Experimental::UniqueTokenScope::Global>;
1178 unique_token_type unique_token;
1179 internal_view_type internal_view;
1182 template <
typename DataType,
typename Op,
typename DeviceType,
1183 typename Contribution>
1184 class ScatterView<DataType, Kokkos::LayoutLeft, DeviceType, Op,
1185 ScatterDuplicated, Contribution> {
1187 using execution_space =
typename DeviceType::execution_space;
1188 using memory_space =
typename DeviceType::memory_space;
1189 using device_type = Kokkos::Device<execution_space, memory_space>;
1190 using original_view_type =
1192 using original_value_type =
typename original_view_type::value_type;
1193 using original_reference_type =
typename original_view_type::reference_type;
1194 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutLeft,
1195 ScatterDuplicated, Contribution, ScatterNonAtomic>;
1196 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutLeft,
1197 ScatterDuplicated, Contribution, ScatterAtomic>;
1198 template <class, class, class, class, class, class>
1199 friend class ScatterView;
1201 using data_type_info =
1202 typename Kokkos::Impl::Experimental::DuplicatedDataType<
1203 DataType, Kokkos::LayoutLeft>;
1204 using internal_data_type = typename data_type_info::value_type;
1205 using internal_view_type =
1206 Kokkos::View<internal_data_type, Kokkos::LayoutLeft, device_type>;
1208 ScatterView() = default;
1210 template <typename RT, typename... RP>
1211 ScatterView(View<RT, RP...> const& original_view)
1212 : ScatterView(execution_space(), original_view) {}
1214 template <
typename RT,
typename... P,
typename... RP>
1215 ScatterView(execution_space
const& exec_space,
1216 View<RT, RP...>
const& original_view)
1218 size_t arg_N[8] = {original_view.rank > 0 ? original_view.extent(0)
1219 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1220 original_view.rank > 1 ? original_view.extent(1)
1221 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1222 original_view.rank > 2 ? original_view.extent(2)
1223 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1224 original_view.rank > 3 ? original_view.extent(3)
1225 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1226 original_view.rank > 4 ? original_view.extent(4)
1227 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1228 original_view.rank > 5 ? original_view.extent(5)
1229 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1230 original_view.rank > 6 ? original_view.extent(6)
1231 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1232 KOKKOS_IMPL_CTOR_DEFAULT_ARG};
1233 arg_N[internal_view_type::rank - 1] = unique_token.size();
1234 internal_view = internal_view_type(
1235 view_alloc(WithoutInitializing,
1236 std::string(
"duplicated_") + original_view.label(),
1238 arg_N[0], arg_N[1], arg_N[2], arg_N[3], arg_N[4], arg_N[5], arg_N[6],
1243 template <
typename... Dims>
1244 ScatterView(std::string
const& name, Dims... dims)
1245 : ScatterView(view_alloc(execution_space(), name), dims...) {}
1250 template <
typename... P,
typename... Dims>
1251 ScatterView(::Kokkos::Impl::ViewCtorProp<P...>
const& arg_prop,
1253 using ::Kokkos::Impl::Experimental::
1254 check_scatter_view_allocation_properties_argument;
1255 check_scatter_view_allocation_properties_argument(arg_prop);
1257 original_view_type original_view;
1258 size_t arg_N[8] = {original_view.rank > 0 ? original_view.static_extent(0)
1259 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1260 original_view.rank > 1 ? original_view.static_extent(1)
1261 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1262 original_view.rank > 2 ? original_view.static_extent(2)
1263 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1264 original_view.rank > 3 ? original_view.static_extent(3)
1265 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1266 original_view.rank > 4 ? original_view.static_extent(4)
1267 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1268 original_view.rank > 5 ? original_view.static_extent(5)
1269 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1270 original_view.rank > 6 ? original_view.static_extent(6)
1271 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1272 KOKKOS_IMPL_CTOR_DEFAULT_ARG};
1273 Kokkos::Impl::Experimental::args_to_array(arg_N, 0, dims...);
1274 arg_N[internal_view_type::rank - 1] = unique_token.size();
1277 Kokkos::Impl::get_property<Kokkos::Impl::LabelTag>(arg_prop);
1278 internal_view = internal_view_type(view_alloc(WithoutInitializing, name),
1279 arg_N[0], arg_N[1], arg_N[2], arg_N[3],
1280 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
1282 auto const& exec_space =
1283 Kokkos::Impl::get_property<Kokkos::Impl::ExecutionSpaceTag>(arg_prop);
1287 template <
typename OtherDataType,
typename OtherDeviceType>
1288 KOKKOS_FUNCTION ScatterView(
1290 ScatterDuplicated, Contribution>& other_view)
1291 : unique_token(other_view.unique_token),
1292 internal_view(other_view.internal_view) {}
1294 template <
typename OtherDataType,
typename OtherDeviceType>
1295 KOKKOS_FUNCTION ScatterView& operator=(
1297 ScatterDuplicated, Contribution>& other_view) {
1298 unique_token = other_view.unique_token;
1299 internal_view = other_view.internal_view;
1303 template <
typename Overr
ideContribution = Contribution>
1304 KOKKOS_FORCEINLINE_FUNCTION
1306 ScatterDuplicated, Contribution, OverrideContribution>
1309 ScatterDuplicated, Contribution, OverrideContribution>(
1314 internal_view_type::rank,
1315 internal_view_type>::value_type
1317 return Kokkos::Impl::Experimental::Slice<
1319 internal_view_type>::get(internal_view, 0);
1322 KOKKOS_INLINE_FUNCTION constexpr
bool is_allocated()
const {
1323 return internal_view.is_allocated();
1326 template <
typename... RP>
1327 void contribute_into(View<RP...>
const& dest)
const {
1328 contribute_into(execution_space(), dest);
1331 template <
typename... RP>
1332 void contribute_into(execution_space
const& exec_space,
1333 View<RP...>
const& dest)
const {
1334 using dest_type =
View<RP...>;
1336 std::is_same<
typename dest_type::value_type,
1337 typename original_view_type::non_const_value_type>::value,
1338 "ScatterView deep_copy destination has wrong value_type");
1339 static_assert(std::is_same<
typename dest_type::array_layout,
1341 "ScatterView deep_copy destination has different layout");
1344 execution_space,
typename dest_type::memory_space>::accessible,
1345 "ScatterView deep_copy destination memory space not accessible");
1346 auto extent = internal_view.extent(internal_view_type::rank - 1);
1347 bool is_equal = (dest.data() == internal_view.data());
1348 size_t start = is_equal ? 1 : 0;
1349 Kokkos::Impl::Experimental::ReduceDuplicates<execution_space,
1350 original_value_type, Op>(
1351 exec_space, internal_view.data(), dest.data(),
1352 internal_view.stride(internal_view_type::rank - 1), start, extent,
1353 internal_view.label());
1356 void reset(execution_space
const& exec_space = execution_space()) {
1357 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1358 original_value_type, Op>(
1359 exec_space, internal_view.data(), internal_view.size(),
1360 internal_view.label());
1363 template <
typename DT,
typename... RP>
1364 void reset_except(View<DT, RP...>
const& view) {
1365 reset_except(execution_space(), view);
1368 template <
typename DT,
typename... RP>
1369 void reset_except(execution_space
const& exec_space,
1370 View<DT, RP...>
const& view) {
1371 if (view.data() != internal_view.data()) {
1375 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1376 original_value_type, Op>(
1377 exec_space, internal_view.data() + view.size(),
1378 internal_view.size() - view.size(), internal_view.label());
1381 void resize(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1382 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1383 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1384 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1385 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1386 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1387 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1388 size_t arg_N[8] = {n0, n1, n2, n3, n4, n5, n6, 0};
1389 const int i = internal_view.rank - 1;
1390 arg_N[i] = unique_token.size();
1392 ::Kokkos::resize(internal_view, arg_N[0], arg_N[1], arg_N[2], arg_N[3],
1393 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
1396 void realloc(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1397 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1398 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1399 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1400 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1401 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1402 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1403 size_t arg_N[8] = {n0, n1, n2, n3, n4, n5, n6, 0};
1404 const int i = internal_view.rank - 1;
1405 arg_N[i] = unique_token.size();
1407 ::Kokkos::realloc(internal_view, arg_N[0], arg_N[1], arg_N[2], arg_N[3],
1408 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
1412 template <
typename... Args>
1413 KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(
int thread_id,
1414 Args... args)
const {
1415 return internal_view(args..., thread_id);
1420 execution_space, Kokkos::Experimental::UniqueTokenScope::Global>;
1422 unique_token_type unique_token;
1423 internal_view_type internal_view;
1436 template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
1437 typename Contribution,
typename OverrideContribution>
1438 class ScatterAccess<DataType, Op, DeviceType, Layout, ScatterDuplicated,
1439 Contribution, OverrideContribution> {
1441 using view_type = ScatterView<DataType, Layout, DeviceType, Op,
1442 ScatterDuplicated, Contribution>;
1443 using original_value_type =
typename view_type::original_value_type;
1444 using value_type = Kokkos::Impl::Experimental::ScatterValue<
1445 original_value_type, Op, DeviceType, OverrideContribution>;
1447 KOKKOS_FORCEINLINE_FUNCTION
1448 ScatterAccess(view_type
const& view_in)
1449 : view(view_in), thread_id(view_in.unique_token.acquire()) {}
1451 KOKKOS_FORCEINLINE_FUNCTION
1453 if (thread_id != ~thread_id_type(0)) view.unique_token.release(thread_id);
1456 template <
typename... Args>
1457 KOKKOS_FORCEINLINE_FUNCTION value_type operator()(Args... args)
const {
1458 return view.at(thread_id, args...);
1461 template <
typename Arg>
1462 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1463 view_type::original_view_type::rank == 1 && std::is_integral<Arg>::value,
1465 operator[](Arg arg)
const {
1466 return view.at(thread_id, arg);
1470 view_type
const& view;
1473 ScatterAccess(ScatterAccess
const& other) =
delete;
1474 ScatterAccess& operator=(ScatterAccess
const& other) =
delete;
1475 ScatterAccess& operator=(ScatterAccess&& other) =
delete;
1481 KOKKOS_FORCEINLINE_FUNCTION
1482 ScatterAccess(ScatterAccess&& other)
1483 : view(other.view), thread_id(other.thread_id) {
1484 other.thread_id = ~thread_id_type(0);
1488 using unique_token_type =
typename view_type::unique_token_type;
1489 using thread_id_type =
typename unique_token_type::size_type;
1490 thread_id_type thread_id;
1493 template <
typename Op = Kokkos::Experimental::ScatterSum,
1494 typename Duplication = void,
typename Contribution = void,
1495 typename RT,
typename... RP>
1497 RT,
typename ViewTraits<RT, RP...>::array_layout,
1498 typename ViewTraits<RT, RP...>::device_type, Op,
1500 std::is_void<Duplication>::value,
1501 typename Kokkos::Impl::Experimental::DefaultDuplication<
1502 typename ViewTraits<RT, RP...>::execution_space>::type,
1505 std::is_void<Contribution>::value,
1506 typename Kokkos::Impl::Experimental::DefaultContribution<
1507 typename ViewTraits<RT, RP...>::execution_space,
1508 typename std::conditional_t<
1509 std::is_void<Duplication>::value,
1510 typename Kokkos::Impl::Experimental::DefaultDuplication<
1511 typename ViewTraits<RT, RP...>::execution_space>::type,
1512 Duplication>>::type,
1514 create_scatter_view(View<RT, RP...>
const& original_view) {
1515 return original_view;
1518 template <
typename Op,
typename RT,
typename... RP>
1520 RT,
typename ViewTraits<RT, RP...>::array_layout,
1521 typename ViewTraits<RT, RP...>::device_type, Op,
1522 typename Kokkos::Impl::Experimental::DefaultDuplication<
1523 typename ViewTraits<RT, RP...>::execution_space>::type,
1524 typename Kokkos::Impl::Experimental::DefaultContribution<
1525 typename ViewTraits<RT, RP...>::execution_space,
1526 typename Kokkos::Impl::Experimental::DefaultDuplication<
1527 typename ViewTraits<RT, RP...>::execution_space>::type>::type>
1528 create_scatter_view(Op, View<RT, RP...>
const& original_view) {
1529 return original_view;
1532 template <
typename Op,
typename Duplication,
typename Contribution,
typename RT,
1534 ScatterView<RT,
typename ViewTraits<RT, RP...>::array_layout,
1535 typename ViewTraits<RT, RP...>::device_type, Op, Duplication,
1537 create_scatter_view(Op, Duplication, Contribution,
1538 View<RT, RP...>
const& original_view) {
1539 return original_view;
1546 namespace Experimental {
1548 template <
typename DT1,
typename DT2,
typename LY,
typename ES,
typename OP,
1549 typename CT,
typename DP,
typename... VP>
1551 typename ES::execution_space
const& exec_space, View<DT1, VP...>& dest,
1552 Kokkos::Experimental::ScatterView<DT2, LY, ES, OP, CT, DP>
const& src) {
1553 src.contribute_into(exec_space, dest);
1556 template <
typename DT1,
typename DT2,
typename LY,
typename ES,
typename OP,
1557 typename CT,
typename DP,
typename... VP>
1559 View<DT1, VP...>& dest,
1560 Kokkos::Experimental::ScatterView<DT2, LY, ES, OP, CT, DP>
const& src) {
1561 using execution_space =
typename ES::execution_space;
1562 contribute(execution_space{}, dest, src);
1570 template <
typename DT,
typename LY,
typename ES,
typename OP,
typename CT,
1571 typename DP,
typename... IS,
class... ViewCtorArgs>
1573 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1574 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1576 scatter_view.realloc(arg_prop, is...);
1579 template <
typename DT,
typename LY,
typename ES,
typename OP,
typename CT,
1580 typename DP,
typename... IS>
1582 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1584 scatter_view.realloc(is...);
1587 template <
typename I,
typename DT,
typename LY,
typename ES,
typename OP,
1588 typename CT,
typename DP,
typename... IS>
1589 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
1591 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1593 scatter_view.realloc(arg_prop, is...);
1596 template <
typename DT,
typename LY,
typename ES,
typename OP,
typename CT,
1597 typename DP,
typename... IS>
1599 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1601 scatter_view.resize(is...);
1604 template <
class... ViewCtorArgs,
typename DT,
typename LY,
typename ES,
1605 typename OP,
typename CT,
typename DP,
typename... IS>
1607 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1608 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1610 scatter_view.resize(arg_prop, is...);
1613 template <
typename I,
typename DT,
typename LY,
typename ES,
typename OP,
1614 typename CT,
typename DP,
typename... IS>
1615 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
1617 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1619 scatter_view.resize(arg_prop, is...);
1624 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SCATTERVIEW
1625 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
1626 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SCATTERVIEW
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
Can AccessSpace access MemorySpace ?
class to generate unique ids base on the required amount of concurrency
View to an array of data.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...