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>
46struct ScatterNonDuplicated {};
47struct ScatterDuplicated {};
49struct ScatterNonAtomic {};
50struct ScatterAtomic {};
59template <
typename ExecSpace>
60struct DefaultDuplication;
62template <
typename ExecSpace,
typename Duplication>
63struct DefaultContribution;
65#ifdef KOKKOS_ENABLE_SERIAL
67struct DefaultDuplication<Kokkos::Serial> {
68 using type = Kokkos::Experimental::ScatterNonDuplicated;
72struct DefaultContribution<Kokkos::Serial,
73 Kokkos::Experimental::ScatterNonDuplicated> {
74 using type = Kokkos::Experimental::ScatterNonAtomic;
77struct DefaultContribution<Kokkos::Serial,
78 Kokkos::Experimental::ScatterDuplicated> {
79 using type = Kokkos::Experimental::ScatterNonAtomic;
83#ifdef KOKKOS_ENABLE_OPENMP
85struct DefaultDuplication<Kokkos::OpenMP> {
86 using type = Kokkos::Experimental::ScatterDuplicated;
89struct DefaultContribution<Kokkos::OpenMP,
90 Kokkos::Experimental::ScatterNonDuplicated> {
91 using type = Kokkos::Experimental::ScatterAtomic;
94struct DefaultContribution<Kokkos::OpenMP,
95 Kokkos::Experimental::ScatterDuplicated> {
96 using type = Kokkos::Experimental::ScatterNonAtomic;
100#ifdef KOKKOS_ENABLE_OPENMPTARGET
102struct DefaultDuplication<Kokkos::Experimental::OpenMPTarget> {
103 using type = Kokkos::Experimental::ScatterNonDuplicated;
106struct DefaultContribution<Kokkos::Experimental::OpenMPTarget,
107 Kokkos::Experimental::ScatterNonDuplicated> {
108 using type = Kokkos::Experimental::ScatterAtomic;
111struct DefaultContribution<Kokkos::Experimental::OpenMPTarget,
112 Kokkos::Experimental::ScatterDuplicated> {
113 using type = Kokkos::Experimental::ScatterNonAtomic;
117#ifdef KOKKOS_ENABLE_HPX
119struct DefaultDuplication<Kokkos::Experimental::HPX> {
120 using type = Kokkos::Experimental::ScatterDuplicated;
123struct DefaultContribution<Kokkos::Experimental::HPX,
124 Kokkos::Experimental::ScatterNonDuplicated> {
125 using type = Kokkos::Experimental::ScatterAtomic;
128struct DefaultContribution<Kokkos::Experimental::HPX,
129 Kokkos::Experimental::ScatterDuplicated> {
130 using type = Kokkos::Experimental::ScatterNonAtomic;
134#ifdef KOKKOS_ENABLE_THREADS
136struct DefaultDuplication<Kokkos::Threads> {
137 using type = Kokkos::Experimental::ScatterDuplicated;
140struct DefaultContribution<Kokkos::Threads,
141 Kokkos::Experimental::ScatterNonDuplicated> {
142 using type = Kokkos::Experimental::ScatterAtomic;
145struct DefaultContribution<Kokkos::Threads,
146 Kokkos::Experimental::ScatterDuplicated> {
147 using type = Kokkos::Experimental::ScatterNonAtomic;
151#ifdef KOKKOS_ENABLE_CUDA
153struct DefaultDuplication<Kokkos::Cuda> {
154 using type = Kokkos::Experimental::ScatterNonDuplicated;
157struct DefaultContribution<Kokkos::Cuda,
158 Kokkos::Experimental::ScatterNonDuplicated> {
159 using type = Kokkos::Experimental::ScatterAtomic;
162struct DefaultContribution<Kokkos::Cuda,
163 Kokkos::Experimental::ScatterDuplicated> {
164 using type = Kokkos::Experimental::ScatterAtomic;
168#ifdef KOKKOS_ENABLE_HIP
170struct DefaultDuplication<Kokkos::HIP> {
171 using type = Kokkos::Experimental::ScatterNonDuplicated;
174struct DefaultContribution<Kokkos::HIP,
175 Kokkos::Experimental::ScatterNonDuplicated> {
176 using type = Kokkos::Experimental::ScatterAtomic;
179struct DefaultContribution<Kokkos::HIP,
180 Kokkos::Experimental::ScatterDuplicated> {
181 using type = Kokkos::Experimental::ScatterAtomic;
185#ifdef KOKKOS_ENABLE_SYCL
187struct DefaultDuplication<Kokkos::Experimental::SYCL> {
188 using type = Kokkos::Experimental::ScatterNonDuplicated;
191struct DefaultContribution<Kokkos::Experimental::SYCL,
192 Kokkos::Experimental::ScatterNonDuplicated> {
193 using type = Kokkos::Experimental::ScatterAtomic;
196struct DefaultContribution<Kokkos::Experimental::SYCL,
197 Kokkos::Experimental::ScatterDuplicated> {
198 using type = Kokkos::Experimental::ScatterAtomic;
207template <
typename ValueType,
typename Op,
typename DeviceType,
208 typename Contribution>
217template <
typename ValueType,
typename DeviceType>
218struct 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();
250template <
typename ValueType,
typename DeviceType>
251struct 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();
294template <
typename ValueType,
typename DeviceType>
295struct 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();
325template <
typename ValueType,
typename DeviceType>
326struct 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) {
339 KOKKOS_FORCEINLINE_FUNCTION
void operator/=(ValueType
const& 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();
362template <
typename ValueType,
typename DeviceType>
363struct 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();
386template <
typename ValueType,
typename DeviceType>
387struct 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();
416template <
typename ValueType,
typename DeviceType>
417struct 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();
440template <
typename ValueType,
typename DeviceType>
441struct 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();
469template <
typename T,
typename Layout>
470struct DuplicatedDataType;
473struct DuplicatedDataType<T, Kokkos::LayoutRight> {
474 using value_type = T*;
477template <
typename T,
size_t N>
478struct DuplicatedDataType<T[N], Kokkos::LayoutRight> {
480 typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type[N];
484struct DuplicatedDataType<T[], Kokkos::LayoutRight> {
486 typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type[];
492 typename DuplicatedDataType<T, Kokkos::LayoutRight>::value_type*;
496struct DuplicatedDataType<T, Kokkos::LayoutLeft> {
497 using value_type = T*;
500template <
typename T,
size_t N>
501struct DuplicatedDataType<T[N], Kokkos::LayoutLeft> {
503 typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type*;
507struct DuplicatedDataType<T[], Kokkos::LayoutLeft> {
509 typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type*;
515 typename DuplicatedDataType<T, Kokkos::LayoutLeft>::value_type*;
521void args_to_array(
size_t* array,
int pos, T dim0) {
524template <
class T,
class... Dims>
525void args_to_array(
size_t* array,
int pos, T dim0, Dims... dims) {
527 args_to_array(array, pos + 1, dims...);
533template <
typename Layout,
int rank,
typename V,
typename... Args>
535 using next = Slice<Layout, rank - 1, V, Kokkos::Impl::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) {
543template <
typename V,
typename... Args>
544struct 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...);
552template <
typename V,
typename... Args>
553struct 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);
561template <
typename ExecSpace,
typename ValueType,
typename Op>
562struct ReduceDuplicates;
564template <
typename ExecSpace,
typename ValueType,
typename Op>
565struct 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));
586template <
typename ExecSpace,
typename ValueType,
typename Op>
587struct 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]);
604template <
typename ExecSpace,
typename ValueType,
typename Op>
605struct ResetDuplicates;
607template <
typename ExecSpace,
typename ValueType,
typename Op>
608struct 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));
624template <
typename ExecSpace,
typename ValueType,
typename Op>
625struct 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>
638template <
typename... P>
639void 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");
655template <
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>
666template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
667 typename Duplication,
typename Contribution,
668 typename OverrideContribution>
672template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
673 typename Contribution>
674class ScatterView<DataType, Layout, DeviceType, Op, ScatterNonDuplicated,
677 using execution_space =
typename DeviceType::execution_space;
678 using memory_space =
typename DeviceType::memory_space;
681 using original_value_type =
typename original_view_type::value_type;
682 using original_reference_type =
typename original_view_type::reference_type;
683 friend class ScatterAccess<DataType, Op, DeviceType, Layout,
684 ScatterNonDuplicated, Contribution,
686 friend class ScatterAccess<DataType, Op, DeviceType, Layout,
687 ScatterNonDuplicated, Contribution, ScatterAtomic>;
688 template <
class,
class,
class,
class,
class,
class>
689 friend class ScatterView;
691 ScatterView() =
default;
693 template <
typename RT,
typename... RP>
694 ScatterView(View<RT, RP...>
const& original_view)
695 : internal_view(original_view) {}
697 template <
typename RT,
typename... P,
typename... RP>
698 ScatterView(execution_space
const& ,
699 View<RT, RP...>
const& original_view)
700 : internal_view(original_view) {}
702 template <
typename... Dims>
703 ScatterView(std::string
const& name, Dims... dims)
704 : internal_view(name, dims...) {}
709 template <
typename... P,
typename... Dims>
710 ScatterView(::Kokkos::Impl::ViewCtorProp<P...>
const& arg_prop, Dims... dims)
711 : internal_view(arg_prop, dims...) {
712 using ::Kokkos::Impl::Experimental::
713 check_scatter_view_allocation_properties_argument;
714 check_scatter_view_allocation_properties_argument(arg_prop);
717 template <
typename OtherDataType,
typename OtherDeviceType>
718 KOKKOS_FUNCTION ScatterView(
719 const ScatterView<OtherDataType, Layout, OtherDeviceType, Op,
720 ScatterNonDuplicated, Contribution>& other_view)
721 : internal_view(other_view.internal_view) {}
723 template <
typename OtherDataType,
typename OtherDeviceType>
724 KOKKOS_FUNCTION
void operator=(
725 const ScatterView<OtherDataType, Layout, OtherDeviceType, Op,
726 ScatterNonDuplicated, Contribution>& other_view) {
727 internal_view = other_view.internal_view;
730 template <
typename Overr
ideContribution = Contribution>
731 KOKKOS_FORCEINLINE_FUNCTION
732 ScatterAccess<DataType, Op, DeviceType, Layout, ScatterNonDuplicated,
733 Contribution, OverrideContribution>
735 return ScatterAccess<DataType, Op, DeviceType, Layout, ScatterNonDuplicated,
736 Contribution, OverrideContribution>(*this);
739 original_view_type subview()
const {
return internal_view; }
741 KOKKOS_INLINE_FUNCTION
constexpr bool is_allocated()
const {
742 return internal_view.is_allocated();
745 template <
typename DT,
typename... RP>
746 void contribute_into(View<DT, RP...>
const& dest)
const {
747 contribute_into(execution_space(), dest);
750 template <
typename DT,
typename... RP>
751 void contribute_into(execution_space
const& exec_space,
752 View<DT, RP...>
const& dest)
const {
753 using dest_type =
View<DT, RP...>;
754 static_assert(std::is_same<typename dest_type::array_layout, Layout>::value,
755 "ScatterView contribute destination has different layout");
758 execution_space,
typename dest_type::memory_space>::accessible,
759 "ScatterView contribute destination memory space not accessible");
760 if (dest.data() == internal_view.data())
return;
761 Kokkos::Impl::Experimental::ReduceDuplicates<execution_space,
762 original_value_type, Op>(
763 exec_space, internal_view.data(), dest.data(), 0, 0, 1,
764 internal_view.label());
767 void reset(execution_space
const& exec_space = execution_space()) {
768 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
769 original_value_type, Op>(
770 exec_space, internal_view.data(), internal_view.size(),
771 internal_view.label());
773 template <
typename DT,
typename... RP>
774 void reset_except(View<DT, RP...>
const& view) {
775 reset_except(execution_space(), view);
778 template <
typename DT,
typename... RP>
779 void reset_except(
const execution_space& exec_space,
780 View<DT, RP...>
const& view) {
781 if (view.data() != internal_view.data()) reset(exec_space);
784 void resize(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
785 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
786 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
787 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
788 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
789 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
790 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
791 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
792 ::Kokkos::resize(internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
795 template <
class... ViewCtorArgs>
796 void resize(const ::Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
797 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(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
809 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
810 const I& arg_prop,
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);
821 template <
class... ViewCtorArgs>
822 void realloc(
const Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
823 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::realloc(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
834 void realloc(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
835 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
836 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
837 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
838 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
839 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
840 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
841 const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
842 ::Kokkos::realloc(internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
846 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
847 const I& arg_prop,
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(arg_prop, internal_view, n0, n1, n2, n3, n4, n5, n6, n7);
859 template <
typename... Args>
860 KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(Args... args)
const {
861 return internal_view(args...);
865 using internal_view_type = original_view_type;
866 internal_view_type internal_view;
869template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
870 typename Contribution,
typename OverrideContribution>
871class ScatterAccess<DataType, Op, DeviceType, Layout, ScatterNonDuplicated,
872 Contribution, OverrideContribution> {
874 using view_type = ScatterView<DataType, Layout, DeviceType, Op,
875 ScatterNonDuplicated, Contribution>;
876 using original_value_type =
typename view_type::original_value_type;
877 using value_type = Kokkos::Impl::Experimental::ScatterValue<
878 original_value_type, Op, DeviceType, OverrideContribution>;
880 KOKKOS_INLINE_FUNCTION
881 ScatterAccess() : view(view_type()) {}
883 KOKKOS_INLINE_FUNCTION
884 ScatterAccess(view_type
const& view_in) : view(view_in) {}
885 KOKKOS_DEFAULTED_FUNCTION
886 ~ScatterAccess() =
default;
888 template <
typename... Args>
889 KOKKOS_FORCEINLINE_FUNCTION value_type operator()(Args... args)
const {
890 return view.at(args...);
893 template <
typename Arg>
894 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
895 view_type::original_view_type::rank == 1 && std::is_integral<Arg>::value,
897 operator[](Arg arg)
const {
902 view_type
const& view;
909template <
typename DataType,
typename Op,
typename DeviceType,
910 typename Contribution>
911class ScatterView<DataType, Kokkos::LayoutRight, DeviceType, Op,
912 ScatterDuplicated, Contribution> {
914 using execution_space =
typename DeviceType::execution_space;
915 using memory_space =
typename DeviceType::memory_space;
917 using original_view_type =
919 using original_value_type =
typename original_view_type::value_type;
920 using original_reference_type =
typename original_view_type::reference_type;
921 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutRight,
922 ScatterDuplicated, Contribution, ScatterNonAtomic>;
923 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutRight,
924 ScatterDuplicated, Contribution, ScatterAtomic>;
925 template <class, class, class, class, class, class>
926 friend class ScatterView;
928 using data_type_info =
929 typename Kokkos::Impl::Experimental::DuplicatedDataType<
930 DataType, Kokkos::LayoutRight>;
931 using internal_data_type = typename data_type_info::value_type;
932 using internal_view_type =
933 Kokkos::View<internal_data_type, Kokkos::LayoutRight, device_type>;
935 ScatterView() = default;
937 template <typename OtherDataType, typename OtherDeviceType>
938 KOKKOS_FUNCTION ScatterView(
939 const ScatterView<OtherDataType, Kokkos::LayoutRight, OtherDeviceType, Op,
940 ScatterDuplicated, Contribution>& other_view)
941 : unique_token(other_view.unique_token),
942 internal_view(other_view.internal_view) {}
944 template <
typename OtherDataType,
typename OtherDeviceType>
945 KOKKOS_FUNCTION
void operator=(
947 ScatterDuplicated, Contribution>& other_view) {
948 unique_token = other_view.unique_token;
949 internal_view = other_view.internal_view;
952 template <
typename RT,
typename... RP>
953 ScatterView(View<RT, RP...>
const& original_view)
954 : ScatterView(execution_space(), original_view) {}
956 template <
typename RT,
typename... P,
typename... RP>
957 ScatterView(execution_space
const& exec_space,
958 View<RT, RP...>
const& original_view)
961 view_alloc(WithoutInitializing,
962 std::string(
"duplicated_") + original_view.label(),
965 original_view.rank_dynamic > 0 ? original_view.extent(0)
966 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
967 original_view.rank_dynamic > 1 ? original_view.extent(1)
968 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
969 original_view.rank_dynamic > 2 ? original_view.extent(2)
970 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
971 original_view.rank_dynamic > 3 ? original_view.extent(3)
972 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
973 original_view.rank_dynamic > 4 ? original_view.extent(4)
974 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
975 original_view.rank_dynamic > 5 ? original_view.extent(5)
976 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
977 original_view.rank_dynamic > 6 ? original_view.extent(6)
978 : KOKKOS_IMPL_CTOR_DEFAULT_ARG)
984 template <
typename... Dims>
985 ScatterView(std::string
const& name, Dims... dims)
986 : ScatterView(view_alloc(execution_space(), name), dims...) {}
991 template <
typename... P,
typename... Dims>
992 ScatterView(::Kokkos::Impl::ViewCtorProp<P...>
const& arg_prop, Dims... dims)
993 : internal_view(view_alloc(WithoutInitializing,
994 static_cast<::Kokkos::Impl::ViewCtorProp<
995 void, std::string> const&>(arg_prop)
997 unique_token.size(), dims...) {
998 using ::Kokkos::Impl::Experimental::
999 check_scatter_view_allocation_properties_argument;
1000 check_scatter_view_allocation_properties_argument(arg_prop);
1002 auto const& exec_space =
1003 Kokkos::Impl::get_property<Kokkos::Impl::ExecutionSpaceTag>(arg_prop);
1007 template <
typename Overr
ideContribution = Contribution>
1008 KOKKOS_FORCEINLINE_FUNCTION
1010 ScatterDuplicated, Contribution, OverrideContribution>
1013 ScatterDuplicated, Contribution, OverrideContribution>(
1018 internal_view_type::rank,
1019 internal_view_type>::value_type
1021 return Kokkos::Impl::Experimental::Slice<
1023 internal_view_type>::get(internal_view, 0);
1026 KOKKOS_INLINE_FUNCTION
constexpr bool is_allocated()
const {
1027 return internal_view.is_allocated();
1030 template <
typename DT,
typename... RP>
1031 void contribute_into(View<DT, RP...>
const& dest)
const {
1032 contribute_into(execution_space(), dest);
1035 template <
typename DT,
typename... RP>
1036 void contribute_into(execution_space
const& exec_space,
1037 View<DT, RP...>
const& dest)
const {
1038 using dest_type =
View<DT, RP...>;
1039 static_assert(std::is_same<
typename dest_type::array_layout,
1041 "ScatterView deep_copy destination has different layout");
1044 execution_space,
typename dest_type::memory_space>::accessible,
1045 "ScatterView deep_copy destination memory space not accessible");
1046 bool is_equal = (dest.data() == internal_view.data());
1047 size_t start = is_equal ? 1 : 0;
1048 Kokkos::Impl::Experimental::ReduceDuplicates<execution_space,
1049 original_value_type, Op>(
1050 exec_space, internal_view.data(), dest.data(), internal_view.stride(0),
1051 start, internal_view.extent(0), internal_view.label());
1054 void reset(execution_space
const& exec_space = execution_space()) {
1055 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1056 original_value_type, Op>(
1057 exec_space, internal_view.data(), internal_view.size(),
1058 internal_view.label());
1061 template <
typename DT,
typename... RP>
1062 void reset_except(View<DT, RP...>
const& view) {
1063 reset_except(execution_space(), view);
1066 template <
typename DT,
typename... RP>
1067 void reset_except(execution_space
const& exec_space,
1068 View<DT, RP...>
const& view) {
1069 if (view.data() != internal_view.data()) {
1073 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1074 original_value_type, Op>(
1075 exec_space, internal_view.data() + view.size(),
1076 internal_view.size() - view.size(), internal_view.label());
1079 void resize(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1080 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1081 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1082 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1083 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1084 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1085 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1086 ::Kokkos::resize(internal_view, unique_token.size(), n0, n1, n2, n3, n4, n5,
1090 template <
class... ViewCtorArgs>
1091 void resize(const ::Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1092 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1093 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1094 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1095 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1096 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1097 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1098 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1099 ::Kokkos::resize(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1104 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
1105 const I& arg_prop,
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1106 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1107 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1108 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1109 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1110 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1111 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1112 ::Kokkos::resize(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1116 template <
class... ViewCtorArgs>
1117 void realloc(const ::Kokkos::Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1118 const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1119 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1120 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1121 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1122 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1123 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1124 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1125 ::Kokkos::realloc(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1129 void realloc(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1130 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1131 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1132 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1133 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1134 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1135 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1136 ::Kokkos::realloc(internal_view, unique_token.size(), n0, n1, n2, n3, n4,
1141 std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
1142 const I& arg_prop,
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1143 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1144 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1145 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1146 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1147 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1148 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1149 ::Kokkos::realloc(arg_prop, internal_view, unique_token.size(), n0, n1, n2,
1154 template <
typename... Args>
1155 KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(
int rank,
1156 Args... args)
const {
1157 return internal_view(rank, args...);
1162 execution_space, Kokkos::Experimental::UniqueTokenScope::Global>;
1164 unique_token_type unique_token;
1165 internal_view_type internal_view;
1168template <
typename DataType,
typename Op,
typename DeviceType,
1169 typename Contribution>
1170class ScatterView<DataType, Kokkos::LayoutLeft, DeviceType, Op,
1171 ScatterDuplicated, Contribution> {
1173 using execution_space =
typename DeviceType::execution_space;
1174 using memory_space =
typename DeviceType::memory_space;
1176 using original_view_type =
1178 using original_value_type =
typename original_view_type::value_type;
1179 using original_reference_type =
typename original_view_type::reference_type;
1180 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutLeft,
1181 ScatterDuplicated, Contribution, ScatterNonAtomic>;
1182 friend class ScatterAccess<DataType, Op, DeviceType, Kokkos::LayoutLeft,
1183 ScatterDuplicated, Contribution, ScatterAtomic>;
1184 template <class, class, class, class, class, class>
1185 friend class ScatterView;
1187 using data_type_info =
1188 typename Kokkos::Impl::Experimental::DuplicatedDataType<
1189 DataType, Kokkos::LayoutLeft>;
1190 using internal_data_type = typename data_type_info::value_type;
1191 using internal_view_type =
1192 Kokkos::View<internal_data_type, Kokkos::LayoutLeft, device_type>;
1194 ScatterView() = default;
1196 template <typename RT, typename... RP>
1197 ScatterView(View<RT, RP...> const& original_view)
1198 : ScatterView(execution_space(), original_view) {}
1200 template <
typename RT,
typename... P,
typename... RP>
1201 ScatterView(execution_space
const& exec_space,
1202 View<RT, RP...>
const& original_view)
1204 size_t arg_N[8] = {original_view.rank > 0 ? original_view.extent(0)
1205 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1206 original_view.rank > 1 ? original_view.extent(1)
1207 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1208 original_view.rank > 2 ? original_view.extent(2)
1209 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1210 original_view.rank > 3 ? original_view.extent(3)
1211 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1212 original_view.rank > 4 ? original_view.extent(4)
1213 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1214 original_view.rank > 5 ? original_view.extent(5)
1215 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1216 original_view.rank > 6 ? original_view.extent(6)
1217 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1218 KOKKOS_IMPL_CTOR_DEFAULT_ARG};
1219 arg_N[internal_view_type::rank - 1] = unique_token.size();
1220 internal_view = internal_view_type(
1221 view_alloc(WithoutInitializing,
1222 std::string(
"duplicated_") + original_view.label(),
1224 arg_N[0], arg_N[1], arg_N[2], arg_N[3], arg_N[4], arg_N[5], arg_N[6],
1229 template <
typename... Dims>
1230 ScatterView(std::string
const& name, Dims... dims)
1231 : ScatterView(view_alloc(execution_space(), name), dims...) {}
1236 template <
typename... P,
typename... Dims>
1237 ScatterView(::Kokkos::Impl::ViewCtorProp<P...>
const& arg_prop,
1239 using ::Kokkos::Impl::Experimental::
1240 check_scatter_view_allocation_properties_argument;
1241 check_scatter_view_allocation_properties_argument(arg_prop);
1243 original_view_type original_view;
1244 size_t arg_N[8] = {original_view.rank > 0 ? original_view.static_extent(0)
1245 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1246 original_view.rank > 1 ? original_view.static_extent(1)
1247 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1248 original_view.rank > 2 ? original_view.static_extent(2)
1249 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1250 original_view.rank > 3 ? original_view.static_extent(3)
1251 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1252 original_view.rank > 4 ? original_view.static_extent(4)
1253 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1254 original_view.rank > 5 ? original_view.static_extent(5)
1255 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1256 original_view.rank > 6 ? original_view.static_extent(6)
1257 : KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1258 KOKKOS_IMPL_CTOR_DEFAULT_ARG};
1259 Kokkos::Impl::Experimental::args_to_array(arg_N, 0, dims...);
1260 arg_N[internal_view_type::rank - 1] = unique_token.size();
1263 Kokkos::Impl::get_property<Kokkos::Impl::LabelTag>(arg_prop);
1264 internal_view = internal_view_type(view_alloc(WithoutInitializing, name),
1265 arg_N[0], arg_N[1], arg_N[2], arg_N[3],
1266 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
1268 auto const& exec_space =
1269 Kokkos::Impl::get_property<Kokkos::Impl::ExecutionSpaceTag>(arg_prop);
1273 template <
typename OtherDataType,
typename OtherDeviceType>
1274 KOKKOS_FUNCTION ScatterView(
1276 ScatterDuplicated, Contribution>& other_view)
1277 : unique_token(other_view.unique_token),
1278 internal_view(other_view.internal_view) {}
1280 template <
typename OtherDataType,
typename OtherDeviceType>
1281 KOKKOS_FUNCTION
void operator=(
1283 ScatterDuplicated, Contribution>& other_view) {
1284 unique_token = other_view.unique_token;
1285 internal_view = other_view.internal_view;
1288 template <
typename Overr
ideContribution = Contribution>
1289 KOKKOS_FORCEINLINE_FUNCTION
1291 ScatterDuplicated, Contribution, OverrideContribution>
1294 ScatterDuplicated, Contribution, OverrideContribution>(
1299 internal_view_type::rank,
1300 internal_view_type>::value_type
1302 return Kokkos::Impl::Experimental::Slice<
1304 internal_view_type>::get(internal_view, 0);
1307 KOKKOS_INLINE_FUNCTION
constexpr bool is_allocated()
const {
1308 return internal_view.is_allocated();
1311 template <
typename... RP>
1312 void contribute_into(View<RP...>
const& dest)
const {
1313 contribute_into(execution_space(), dest);
1316 template <
typename... RP>
1317 void contribute_into(execution_space
const& exec_space,
1318 View<RP...>
const& dest)
const {
1319 using dest_type =
View<RP...>;
1321 std::is_same<
typename dest_type::value_type,
1322 typename original_view_type::non_const_value_type>::value,
1323 "ScatterView deep_copy destination has wrong value_type");
1324 static_assert(std::is_same<
typename dest_type::array_layout,
1326 "ScatterView deep_copy destination has different layout");
1329 execution_space,
typename dest_type::memory_space>::accessible,
1330 "ScatterView deep_copy destination memory space not accessible");
1331 auto extent = internal_view.extent(internal_view_type::rank - 1);
1332 bool is_equal = (dest.data() == internal_view.data());
1333 size_t start = is_equal ? 1 : 0;
1334 Kokkos::Impl::Experimental::ReduceDuplicates<execution_space,
1335 original_value_type, Op>(
1336 exec_space, internal_view.data(), dest.data(),
1337 internal_view.stride(internal_view_type::rank - 1), start, extent,
1338 internal_view.label());
1341 void reset(execution_space
const& exec_space = execution_space()) {
1342 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1343 original_value_type, Op>(
1344 exec_space, internal_view.data(), internal_view.size(),
1345 internal_view.label());
1348 template <
typename DT,
typename... RP>
1349 void reset_except(View<DT, RP...>
const& view) {
1350 reset_except(execution_space(), view);
1353 template <
typename DT,
typename... RP>
1354 void reset_except(execution_space
const& exec_space,
1355 View<DT, RP...>
const& view) {
1356 if (view.data() != internal_view.data()) {
1360 Kokkos::Impl::Experimental::ResetDuplicates<execution_space,
1361 original_value_type, Op>(
1362 exec_space, internal_view.data() + view.size(),
1363 internal_view.size() - view.size(), internal_view.label());
1366 void resize(
const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1367 const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1368 const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1369 const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1370 const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1371 const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1372 const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
1373 size_t arg_N[8] = {n0, n1, n2, n3, n4, n5, n6, 0};
1374 const int i = internal_view.rank - 1;
1375 arg_N[i] = unique_token.size();
1377 ::Kokkos::resize(internal_view, arg_N[0], arg_N[1], arg_N[2], arg_N[3],
1378 arg_N[4], arg_N[5], arg_N[6], arg_N[7]);
1381 void realloc(
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::realloc(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]);
1397 template <
typename... Args>
1398 KOKKOS_FORCEINLINE_FUNCTION original_reference_type at(
int thread_id,
1399 Args... args)
const {
1400 return internal_view(args..., thread_id);
1405 execution_space, Kokkos::Experimental::UniqueTokenScope::Global>;
1407 unique_token_type unique_token;
1408 internal_view_type internal_view;
1421template <
typename DataType,
typename Op,
typename DeviceType,
typename Layout,
1422 typename Contribution,
typename OverrideContribution>
1423class ScatterAccess<DataType, Op, DeviceType, Layout, ScatterDuplicated,
1424 Contribution, OverrideContribution> {
1426 using view_type = ScatterView<DataType, Layout, DeviceType, Op,
1427 ScatterDuplicated, Contribution>;
1428 using original_value_type =
typename view_type::original_value_type;
1429 using value_type = Kokkos::Impl::Experimental::ScatterValue<
1430 original_value_type, Op, DeviceType, OverrideContribution>;
1432 KOKKOS_FORCEINLINE_FUNCTION
1433 ScatterAccess(view_type
const& view_in)
1434 : view(view_in), thread_id(view_in.unique_token.acquire()) {}
1436 KOKKOS_FORCEINLINE_FUNCTION
1438 if (thread_id != ~thread_id_type(0)) view.unique_token.release(thread_id);
1441 template <
typename... Args>
1442 KOKKOS_FORCEINLINE_FUNCTION value_type operator()(Args... args)
const {
1443 return view.at(thread_id, args...);
1446 template <
typename Arg>
1447 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1448 view_type::original_view_type::rank == 1 && std::is_integral<Arg>::value,
1450 operator[](Arg arg)
const {
1451 return view.at(thread_id, arg);
1455 view_type
const& view;
1458 ScatterAccess(ScatterAccess
const& other) =
delete;
1459 ScatterAccess& operator=(ScatterAccess
const& other) =
delete;
1460 ScatterAccess& operator=(ScatterAccess&& other) =
delete;
1466 KOKKOS_FORCEINLINE_FUNCTION
1467 ScatterAccess(ScatterAccess&& other)
1468 : view(other.view), thread_id(other.thread_id) {
1469 other.thread_id = ~thread_id_type(0);
1473 using unique_token_type =
typename view_type::unique_token_type;
1474 using thread_id_type =
typename unique_token_type::size_type;
1475 thread_id_type thread_id;
1478template <
typename Op = Kokkos::Experimental::ScatterSum,
1479 typename Duplication = void,
typename Contribution = void,
1480 typename RT,
typename... RP>
1482 RT,
typename ViewTraits<RT, RP...>::array_layout,
1483 typename ViewTraits<RT, RP...>::device_type, Op,
1485 std::is_void<Duplication>::value,
1486 typename Kokkos::Impl::Experimental::DefaultDuplication<
1487 typename ViewTraits<RT, RP...>::execution_space>::type,
1490 std::is_void<Contribution>::value,
1491 typename Kokkos::Impl::Experimental::DefaultContribution<
1492 typename ViewTraits<RT, RP...>::execution_space,
1493 typename std::conditional_t<
1494 std::is_void<Duplication>::value,
1495 typename Kokkos::Impl::Experimental::DefaultDuplication<
1496 typename ViewTraits<RT, RP...>::execution_space>::type,
1497 Duplication>>::type,
1499create_scatter_view(View<RT, RP...>
const& original_view) {
1500 return original_view;
1503template <
typename Op,
typename RT,
typename... RP>
1505 RT,
typename ViewTraits<RT, RP...>::array_layout,
1506 typename ViewTraits<RT, RP...>::device_type, Op,
1507 typename Kokkos::Impl::Experimental::DefaultDuplication<
1508 typename ViewTraits<RT, RP...>::execution_space>::type,
1509 typename Kokkos::Impl::Experimental::DefaultContribution<
1510 typename ViewTraits<RT, RP...>::execution_space,
1511 typename Kokkos::Impl::Experimental::DefaultDuplication<
1512 typename ViewTraits<RT, RP...>::execution_space>::type>::type>
1513create_scatter_view(Op, View<RT, RP...>
const& original_view) {
1514 return original_view;
1517template <
typename Op,
typename Duplication,
typename Contribution,
typename RT,
1519ScatterView<RT,
typename ViewTraits<RT, RP...>::array_layout,
1520 typename ViewTraits<RT, RP...>::device_type, Op, Duplication,
1522create_scatter_view(Op, Duplication, Contribution,
1523 View<RT, RP...>
const& original_view) {
1524 return original_view;
1533template <
typename DT1,
typename DT2,
typename LY,
typename ES,
typename OP,
1534 typename CT,
typename DP,
typename... VP>
1536 typename ES::execution_space
const& exec_space, View<DT1, VP...>& dest,
1537 Kokkos::Experimental::ScatterView<DT2, LY, ES, OP, CT, DP>
const& src) {
1538 src.contribute_into(exec_space, dest);
1541template <
typename DT1,
typename DT2,
typename LY,
typename ES,
typename OP,
1542 typename CT,
typename DP,
typename... VP>
1544 View<DT1, VP...>& dest,
1545 Kokkos::Experimental::ScatterView<DT2, LY, ES, OP, CT, DP>
const& src) {
1546 using execution_space =
typename ES::execution_space;
1547 contribute(execution_space{}, dest, src);
1555template <
typename DT,
typename LY,
typename ES,
typename OP,
typename CT,
1556 typename DP,
typename... IS,
class... ViewCtorArgs>
1558 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1559 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1561 scatter_view.realloc(arg_prop, is...);
1564template <
typename DT,
typename LY,
typename ES,
typename OP,
typename CT,
1565 typename DP,
typename... IS>
1567 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1569 scatter_view.realloc(is...);
1572template <
typename I,
typename DT,
typename LY,
typename ES,
typename OP,
1573 typename CT,
typename DP,
typename... IS>
1574std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> realloc(
1576 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1578 scatter_view.realloc(arg_prop, is...);
1581template <
typename DT,
typename LY,
typename ES,
typename OP,
typename CT,
1582 typename DP,
typename... IS>
1584 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1586 scatter_view.resize(is...);
1589template <
class... ViewCtorArgs,
typename DT,
typename LY,
typename ES,
1590 typename OP,
typename CT,
typename DP,
typename... IS>
1592 const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1593 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1595 scatter_view.resize(arg_prop, is...);
1598template <
typename I,
typename DT,
typename LY,
typename ES,
typename OP,
1599 typename CT,
typename DP,
typename... IS>
1600std::enable_if_t<Kokkos::Impl::is_view_ctor_property<I>::value> resize(
1602 Kokkos::Experimental::ScatterView<DT, LY, ES, OP, CT, DP>& scatter_view,
1604 scatter_view.resize(arg_prop, is...);
1609#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SCATTERVIEW
1610#undef KOKKOS_IMPL_PUBLIC_INCLUDE
1611#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_SCATTERVIEW
A thread safe view to a bitset.
class to generate unique ids base on the required amount of concurrency
View to an array of data.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices.
Can AccessSpace access MemorySpace ?