17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22#ifndef KOKKOS_EXECPOLICY_HPP
23#define KOKKOS_EXECPOLICY_HPP
25#include <Kokkos_Core_fwd.hpp>
26#include <impl/Kokkos_Traits.hpp>
27#include <impl/Kokkos_Error.hpp>
28#include <impl/Kokkos_AnalyzePolicy.hpp>
29#include <Kokkos_BitManipulation.hpp>
30#include <Kokkos_Concepts.hpp>
31#include <Kokkos_TypeInfo.hpp>
32#ifndef KOKKOS_ENABLE_IMPL_TYPEINFO
41struct ParallelForTag {};
42struct ParallelScanTag {};
43struct ParallelReduceTag {};
47 explicit ChunkSize(
int value_) : value(value_) {}
48#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
49 template <
typename T =
void>
50 KOKKOS_DEPRECATED_WITH_COMMENT(
"ChunkSize should be constructed explicitly.")
51 ChunkSize(
int value_) : value(value_) {}
76template <
class... Properties>
79 using traits = Impl::PolicyTraits<
Properties...>;
82 typename traits::execution_space m_space;
83 typename traits::index_type m_begin;
84 typename traits::index_type m_end;
85 typename traits::index_type m_granularity;
86 typename traits::index_type m_granularity_mask;
94 using member_type =
typename traits::index_type;
95 using index_type =
typename traits::index_type;
97 KOKKOS_INLINE_FUNCTION
const typename traits::execution_space& space()
const {
100 KOKKOS_INLINE_FUNCTION member_type begin()
const {
return m_begin; }
101 KOKKOS_INLINE_FUNCTION member_type end()
const {
return m_end; }
108 void operator()(
const int&)
const {}
110 template <
class... OtherProperties>
111 RangePolicy(
const RangePolicy<OtherProperties...>& p)
116 m_granularity(p.m_granularity),
117 m_granularity_mask(p.m_granularity_mask) {}
124 m_granularity_mask(0) {}
127 template <
typename IndexType1,
typename IndexType2,
128 std::enable_if_t<(std::is_convertible_v<IndexType1, member_type> &&
129 std::is_convertible_v<IndexType2, member_type>),
136 std::enable_if_t<(std::is_convertible_v<IndexType1, member_type> &&
137 std::is_convertible_v<IndexType2, member_type>),
145 m_granularity_mask(0) {
148 check_bounds_validity();
149 set_auto_chunk_size();
153 std::enable_if_t<(std::is_convertible_v<IndexType1, member_type> &&
154 std::is_convertible_v<IndexType2, member_type>),
163 m_granularity_mask(0) {
166 check_bounds_validity();
171 template <
typename IndexType1,
typename IndexType2,
typename... Args,
172 std::enable_if_t<(std::is_convertible_v<IndexType1, member_type> &&
173 std::is_convertible_v<IndexType2, member_type>),
176 const ChunkSize chunk_size)
181#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
182 KOKKOS_DEPRECATED_WITH_COMMENT(
"Use set_chunk_size instead")
185 m_granularity_mask = m_granularity - 1;
191 inline member_type
chunk_size()
const {
return m_granularity; }
195 m_granularity = chunk_size;
196 m_granularity_mask = m_granularity - 1;
202 inline void set_auto_chunk_size() {
203#ifdef KOKKOS_ENABLE_SYCL
204 if (std::is_same_v<typename traits::execution_space, Kokkos::SYCL>) {
208 m_granularity_mask = 0;
212 auto concurrency =
static_cast<int64_t
>(m_space.concurrency());
213 if (concurrency == 0) concurrency = 1;
215 if (m_granularity > 0 &&
216 !Kokkos::has_single_bit(
static_cast<unsigned>(m_granularity))) {
217 Kokkos::abort(
"RangePolicy blocking granularity must be power of two");
220 int64_t new_chunk_size = 1;
221 while (new_chunk_size * 100 * concurrency <
222 static_cast<int64_t
>(m_end - m_begin))
224 if (new_chunk_size < 128) {
226 while ((new_chunk_size * 40 * concurrency <
227 static_cast<int64_t
>(m_end - m_begin)) &&
228 (new_chunk_size < 128))
231 m_granularity = new_chunk_size;
232 m_granularity_mask = m_granularity - 1;
235 void check_bounds_validity() {
236 if (m_end < m_begin) {
237 std::string msg =
"Kokkos::RangePolicy bounds error: The lower bound (" +
238 std::to_string(m_begin) +
239 ") is greater than the upper bound (" +
240 std::to_string(m_end) +
").\n";
241#ifndef KOKKOS_ENABLE_DEPRECATED_CODE_4
242 Kokkos::abort(msg.c_str());
246#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
247 Kokkos::Impl::log_warning(msg);
253 template <
typename IndexType>
254 static void check_conversion_safety([[maybe_unused]]
const IndexType bound) {
256 if constexpr (std::is_convertible_v<member_type, IndexType>) {
257#if !defined(KOKKOS_ENABLE_DEPRECATED_CODE_4) || \
258 defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS)
261 if constexpr (std::is_arithmetic_v<member_type> &&
262 (std::is_signed_v<IndexType> !=
263 std::is_signed_v<member_type>)) {
265 if constexpr (std::is_signed_v<IndexType>)
266 warn |= (bound <
static_cast<IndexType
>(
267 std::numeric_limits<member_type>::min()));
270 if constexpr (std::is_signed_v<member_type>)
271 warn |= (bound >
static_cast<IndexType
>(
272 std::numeric_limits<member_type>::max()));
277 (
static_cast<IndexType
>(
static_cast<member_type
>(bound)) != bound);
281 "Kokkos::RangePolicy bound type error: an unsafe implicit "
282 "conversion is performed on a bound (" +
283 std::to_string(bound) +
284 "), which may not preserve its original value.\n";
286#ifndef KOKKOS_ENABLE_DEPRECATED_CODE_4
287 Kokkos::abort(msg.c_str());
290#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
291 Kokkos::Impl::log_warning(msg);
307 KOKKOS_INLINE_FUNCTION member_type begin()
const {
return m_begin; }
308 KOKKOS_INLINE_FUNCTION member_type end()
const {
return m_end; }
314 KOKKOS_INLINE_FUNCTION
317 : m_begin(0), m_end(0) {
322 range.m_granularity_mask) &
323 ~member_type(
range.m_granularity_mask);
328 if (
range.end() < m_begin) m_begin =
range.end();
341RangePolicy() -> RangePolicy<>;
343RangePolicy(int64_t, int64_t) -> RangePolicy<>;
344RangePolicy(int64_t, int64_t, ChunkSize
const&) -> RangePolicy<>;
346RangePolicy(DefaultExecutionSpace
const&, int64_t, int64_t) -> RangePolicy<>;
347RangePolicy(DefaultExecutionSpace
const&, int64_t, int64_t, ChunkSize
const&)
350template <
typename ES,
typename = std::enable_if_t<is_execution_space_v<ES>>>
351RangePolicy(ES
const&, int64_t, int64_t) -> RangePolicy<ES>;
353template <
typename ES,
typename = std::enable_if_t<is_execution_space_v<ES>>>
354RangePolicy(ES
const&, int64_t, int64_t, ChunkSize
const&) -> RangePolicy<ES>;
365template <
class ExecSpace,
class... Properties>
366class TeamPolicyInternal :
public Impl::PolicyTraits<Properties...> {
368 using traits = Impl::PolicyTraits<Properties...>;
371 using index_type =
typename traits::index_type;
384 template <
class FunctorType>
385 static int team_size_max(
const FunctorType&);
397 template <
class FunctorType>
398 static int team_size_recommended(
const FunctorType&);
400 template <
class FunctorType>
401 static int team_size_recommended(
const FunctorType&,
const int&);
403 template <
class FunctorType>
404 int team_size_recommended(
const FunctorType& functor,
405 const int vector_length);
409 TeamPolicyInternal(
const typename traits::execution_space&,
410 int league_size_request,
int team_size_request,
411 int vector_length_request = 1);
413 TeamPolicyInternal(
const typename traits::execution_space&,
414 int league_size_request,
const Kokkos::AUTO_t&,
415 int vector_length_request = 1);
419 TeamPolicyInternal(
int league_size_request,
int team_size_request,
420 int vector_length_request = 1);
422 TeamPolicyInternal(
int league_size_request,
const Kokkos::AUTO_t&,
423 int vector_length_request = 1);
434 KOKKOS_INLINE_FUNCTION
int league_size()
const;
441 KOKKOS_INLINE_FUNCTION
int team_size()
const;
445 inline bool impl_auto_team_size()
const;
448 inline bool impl_auto_vector_length()
const;
450 static int vector_length_max();
452 KOKKOS_INLINE_FUNCTION
int impl_vector_length()
const;
454 inline typename traits::index_type chunk_size()
const;
456 inline TeamPolicyInternal& set_chunk_size(
int chunk_size);
463 KOKKOS_INLINE_FUNCTION
464 typename traits::execution_space::scratch_memory_space
team_shmem()
const;
483 template <
class JoinOp>
485 const typename JoinOp::value_type,
const JoinOp&)
const;
492 template <
typename Type>
504 template <
typename Type>
512 PerTeamValue(
size_t arg);
515struct PerThreadValue {
517 PerThreadValue(
size_t arg);
520template <
class iType,
class... Args>
521struct ExtractVectorLength {
522 static inline iType value(
523 std::enable_if_t<std::is_integral_v<iType>, iType> val, Args...) {
526 static inline std::enable_if_t<!std::is_integral_v<iType>,
int> value(
527 std::enable_if_t<!std::is_integral_v<iType>, iType>, Args...) {
532template <
class iType,
class... Args>
533inline std::enable_if_t<std::is_integral_v<iType>, iType> extract_vector_length(
534 iType val, Args...) {
538template <
class iType,
class... Args>
539inline std::enable_if_t<!std::is_integral_v<iType>,
int> extract_vector_length(
546Impl::PerTeamValue PerTeam(
const size_t& arg);
547Impl::PerThreadValue PerThread(
const size_t& arg);
549struct ScratchRequest {
555 inline ScratchRequest(
const int& level_,
556 const Impl::PerTeamValue& team_value) {
558 per_team = team_value.value;
562 inline ScratchRequest(
const int& level_,
563 const Impl::PerThreadValue& thread_value) {
566 per_thread = thread_value.value;
569 inline ScratchRequest(
const int& level_,
const Impl::PerTeamValue& team_value,
570 const Impl::PerThreadValue& thread_value) {
572 per_team = team_value.value;
573 per_thread = thread_value.value;
576 inline ScratchRequest(
const int& level_,
577 const Impl::PerThreadValue& thread_value,
578 const Impl::PerTeamValue& team_value) {
580 per_team = team_value.value;
581 per_thread = thread_value.value;
586void team_policy_check_valid_storage_level_argument(
int level);
614template <
class... Properties>
616 :
public Impl::TeamPolicyInternal<
617 typename Impl::PolicyTraits<Properties...>::execution_space,
619 using internal_policy = Impl::TeamPolicyInternal<
620 typename Impl::PolicyTraits<Properties...>::execution_space,
623 template <
class... OtherProperties>
624 friend class TeamPolicy;
627 using traits = Impl::PolicyTraits<Properties...>;
629 using execution_policy = TeamPolicy<Properties...>;
631 TeamPolicy() : internal_policy(0, AUTO) {}
634 TeamPolicy(
const typename traits::execution_space& space_,
635 int league_size_request,
int team_size_request,
636 int vector_length_request = 1)
637 : internal_policy(space_, league_size_request, team_size_request,
638 vector_length_request) {}
640 TeamPolicy(
const typename traits::execution_space& space_,
641 int league_size_request,
const Kokkos::AUTO_t&,
642 int vector_length_request = 1)
643 : internal_policy(space_, league_size_request, Kokkos::AUTO(),
644 vector_length_request) {}
646 TeamPolicy(
const typename traits::execution_space& space_,
647 int league_size_request,
const Kokkos::AUTO_t&,
648 const Kokkos::AUTO_t&)
649 : internal_policy(space_, league_size_request, Kokkos::AUTO(),
651 TeamPolicy(
const typename traits::execution_space& space_,
652 int league_size_request,
const int team_size_request,
653 const Kokkos::AUTO_t&)
654 : internal_policy(space_, league_size_request, team_size_request,
658 TeamPolicy(
int league_size_request,
int team_size_request,
659 int vector_length_request = 1)
660 : internal_policy(league_size_request, team_size_request,
661 vector_length_request) {}
663 TeamPolicy(
int league_size_request,
const Kokkos::AUTO_t&,
664 int vector_length_request = 1)
665 : internal_policy(league_size_request, Kokkos::AUTO(),
666 vector_length_request) {}
668 TeamPolicy(
int league_size_request,
const Kokkos::AUTO_t&,
669 const Kokkos::AUTO_t&)
670 : internal_policy(league_size_request, Kokkos::AUTO(), Kokkos::AUTO()) {}
671 TeamPolicy(
int league_size_request,
const int team_size_request,
672 const Kokkos::AUTO_t&)
673 : internal_policy(league_size_request, team_size_request,
676 template <
class... OtherProperties>
677 TeamPolicy(
const TeamPolicy<OtherProperties...> p) : internal_policy(p) {
680 internal_policy::traits::operator=(p);
684 TeamPolicy(
const internal_policy& p) : internal_policy(p) {}
687 inline TeamPolicy& set_chunk_size(
int chunk) {
689 std::is_same_v<
decltype(internal_policy::set_chunk_size(chunk)),
691 "internal set_chunk_size should return a reference");
692 return static_cast<TeamPolicy&
>(internal_policy::set_chunk_size(chunk));
695 inline TeamPolicy& set_scratch_size(
const int& level,
696 const Impl::PerTeamValue& per_team) {
697 static_assert(std::is_same_v<
decltype(internal_policy::set_scratch_size(
700 "internal set_chunk_size should return a reference");
702 team_policy_check_valid_storage_level_argument(level);
703 return static_cast<TeamPolicy&
>(
704 internal_policy::set_scratch_size(level, per_team));
706 inline TeamPolicy& set_scratch_size(
const int& level,
707 const Impl::PerThreadValue& per_thread) {
708 team_policy_check_valid_storage_level_argument(level);
709 return static_cast<TeamPolicy&
>(
710 internal_policy::set_scratch_size(level, per_thread));
712 inline TeamPolicy& set_scratch_size(
const int& level,
713 const Impl::PerTeamValue& per_team,
714 const Impl::PerThreadValue& per_thread) {
715 team_policy_check_valid_storage_level_argument(level);
716 return static_cast<TeamPolicy&
>(
717 internal_policy::set_scratch_size(level, per_team, per_thread));
719 inline TeamPolicy& set_scratch_size(
const int& level,
720 const Impl::PerThreadValue& per_thread,
721 const Impl::PerTeamValue& per_team) {
722 team_policy_check_valid_storage_level_argument(level);
723 return static_cast<TeamPolicy&
>(
724 internal_policy::set_scratch_size(level, per_team, per_thread));
730TeamPolicy() -> TeamPolicy<>;
732TeamPolicy(
int,
int) -> TeamPolicy<>;
733TeamPolicy(
int,
int,
int) -> TeamPolicy<>;
734TeamPolicy(
int, Kokkos::AUTO_t
const&) -> TeamPolicy<>;
735TeamPolicy(
int, Kokkos::AUTO_t
const&,
int) -> TeamPolicy<>;
736TeamPolicy(
int, Kokkos::AUTO_t
const&, Kokkos::AUTO_t
const&) -> TeamPolicy<>;
737TeamPolicy(
int,
int, Kokkos::AUTO_t
const&) -> TeamPolicy<>;
741TeamPolicy(DefaultExecutionSpace
const&,
int,
int) -> TeamPolicy<>;
742TeamPolicy(DefaultExecutionSpace
const&,
int,
int,
int) -> TeamPolicy<>;
743TeamPolicy(DefaultExecutionSpace
const&,
int, Kokkos::AUTO_t
const&)
745TeamPolicy(DefaultExecutionSpace
const&,
int, Kokkos::AUTO_t
const&,
int)
747TeamPolicy(DefaultExecutionSpace
const&,
int, Kokkos::AUTO_t
const&,
748 Kokkos::AUTO_t
const&) -> TeamPolicy<>;
749TeamPolicy(DefaultExecutionSpace
const&,
int,
int, Kokkos::AUTO_t
const&)
754template <
typename ES,
755 typename = std::enable_if_t<Kokkos::is_execution_space_v<ES>>>
756TeamPolicy(ES
const&,
int,
int) -> TeamPolicy<ES>;
758template <
typename ES,
759 typename = std::enable_if_t<Kokkos::is_execution_space_v<ES>>>
760TeamPolicy(ES
const&,
int,
int,
int) -> TeamPolicy<ES>;
762template <
typename ES,
763 typename = std::enable_if_t<Kokkos::is_execution_space_v<ES>>>
764TeamPolicy(ES
const&,
int, Kokkos::AUTO_t
const&) -> TeamPolicy<ES>;
766template <
typename ES,
767 typename = std::enable_if_t<Kokkos::is_execution_space_v<ES>>>
768TeamPolicy(ES
const&,
int, Kokkos::AUTO_t
const&,
int) -> TeamPolicy<ES>;
770template <
typename ES,
771 typename = std::enable_if_t<Kokkos::is_execution_space_v<ES>>>
772TeamPolicy(ES
const&,
int, Kokkos::AUTO_t
const&, Kokkos::AUTO_t
const&)
775template <
typename ES,
776 typename = std::enable_if_t<Kokkos::is_execution_space_v<ES>>>
777TeamPolicy(ES
const&,
int,
int, Kokkos::AUTO_t
const&) -> TeamPolicy<ES>;
781template <
typename iType,
class TeamMemberType>
782struct TeamThreadRangeBoundariesStruct {
784 KOKKOS_INLINE_FUNCTION
static iType ibegin(
const iType& arg_begin,
785 const iType& arg_end,
786 const iType& arg_rank,
787 const iType& arg_size) {
789 ((arg_end - arg_begin + arg_size - 1) / arg_size) * arg_rank;
792 KOKKOS_INLINE_FUNCTION
static iType iend(
const iType& arg_begin,
793 const iType& arg_end,
794 const iType& arg_rank,
795 const iType& arg_size) {
798 ((arg_end - arg_begin + arg_size - 1) / arg_size) * (arg_rank + 1);
799 return end_ < arg_end ? end_ : arg_end;
803 using index_type = iType;
806 enum { increment = 1 };
807 const TeamMemberType& member;
809 KOKKOS_INLINE_FUNCTION
810 TeamThreadRangeBoundariesStruct(
const TeamMemberType& arg_thread,
811 const iType& arg_count)
812 : start(ibegin(0, arg_count, arg_thread.team_rank(),
813 arg_thread.team_size())),
814 end(iend(0, arg_count, arg_thread.team_rank(), arg_thread.team_size())),
815 member(arg_thread) {}
817 KOKKOS_INLINE_FUNCTION
818 TeamThreadRangeBoundariesStruct(
const TeamMemberType& arg_thread,
819 const iType& arg_begin,
const iType& arg_end)
820 : start(ibegin(arg_begin, arg_end, arg_thread.team_rank(),
821 arg_thread.team_size())),
822 end(iend(arg_begin, arg_end, arg_thread.team_rank(),
823 arg_thread.team_size())),
824 member(arg_thread) {}
827template <
typename iType,
class TeamMemberType>
828struct TeamVectorRangeBoundariesStruct {
830 KOKKOS_INLINE_FUNCTION
static iType ibegin(
const iType& arg_begin,
831 const iType& arg_end,
832 const iType& arg_rank,
833 const iType& arg_size) {
835 ((arg_end - arg_begin + arg_size - 1) / arg_size) * arg_rank;
838 KOKKOS_INLINE_FUNCTION
static iType iend(
const iType& arg_begin,
839 const iType& arg_end,
840 const iType& arg_rank,
841 const iType& arg_size) {
844 ((arg_end - arg_begin + arg_size - 1) / arg_size) * (arg_rank + 1);
845 return end_ < arg_end ? end_ : arg_end;
849 using index_type = iType;
852 enum { increment = 1 };
853 const TeamMemberType& member;
855 KOKKOS_INLINE_FUNCTION
856 TeamVectorRangeBoundariesStruct(
const TeamMemberType& arg_thread,
857 const iType& arg_count)
858 : start(ibegin(0, arg_count, arg_thread.team_rank(),
859 arg_thread.team_size())),
860 end(iend(0, arg_count, arg_thread.team_rank(), arg_thread.team_size())),
861 member(arg_thread) {}
863 KOKKOS_INLINE_FUNCTION
864 TeamVectorRangeBoundariesStruct(
const TeamMemberType& arg_thread,
865 const iType& arg_begin,
const iType& arg_end)
866 : start(ibegin(arg_begin, arg_end, arg_thread.team_rank(),
867 arg_thread.team_size())),
868 end(iend(arg_begin, arg_end, arg_thread.team_rank(),
869 arg_thread.team_size())),
870 member(arg_thread) {}
873template <
typename iType,
class TeamMemberType>
874struct ThreadVectorRangeBoundariesStruct {
875 using index_type = iType;
876 const index_type start;
877 const index_type end;
878 enum { increment = 1 };
880 KOKKOS_INLINE_FUNCTION
881 constexpr ThreadVectorRangeBoundariesStruct(
882 const TeamMemberType,
const index_type& arg_count) noexcept
883 : start(
static_cast<index_type
>(0)), end(arg_count) {}
885 KOKKOS_INLINE_FUNCTION
886 constexpr ThreadVectorRangeBoundariesStruct(
887 const TeamMemberType,
const index_type& arg_begin,
888 const index_type& arg_end) noexcept
889 : start(
static_cast<index_type
>(arg_begin)), end(arg_end) {}
892template <
class TeamMemberType>
893struct ThreadSingleStruct {
894 const TeamMemberType& team_member;
895 KOKKOS_INLINE_FUNCTION
896 ThreadSingleStruct(
const TeamMemberType& team_member_)
897 : team_member(team_member_) {}
900template <
class TeamMemberType>
901struct VectorSingleStruct {
902 const TeamMemberType& team_member;
903 KOKKOS_INLINE_FUNCTION
904 VectorSingleStruct(
const TeamMemberType& team_member_)
905 : team_member(team_member_) {}
917template <
typename iType,
class TeamMemberType,
class _never_use_this_overload>
918KOKKOS_INLINE_FUNCTION_DELETED
919 Impl::TeamThreadRangeBoundariesStruct<iType, TeamMemberType>
920 TeamThreadRange(
const TeamMemberType&,
const iType& count) =
delete;
929template <
typename iType1,
typename iType2,
class TeamMemberType,
930 class _never_use_this_overload>
931KOKKOS_INLINE_FUNCTION_DELETED Impl::TeamThreadRangeBoundariesStruct<
932 std::common_type_t<iType1, iType2>, TeamMemberType>
933TeamThreadRange(
const TeamMemberType&,
const iType1& begin,
934 const iType2& end) =
delete;
943template <
typename iType,
class TeamMemberType,
class _never_use_this_overload>
944KOKKOS_INLINE_FUNCTION_DELETED
945 Impl::TeamThreadRangeBoundariesStruct<iType, TeamMemberType>
946 TeamVectorRange(
const TeamMemberType&,
const iType& count) =
delete;
955template <
typename iType1,
typename iType2,
class TeamMemberType,
956 class _never_use_this_overload>
957KOKKOS_INLINE_FUNCTION_DELETED Impl::TeamThreadRangeBoundariesStruct<
958 std::common_type_t<iType1, iType2>, TeamMemberType>
959TeamVectorRange(
const TeamMemberType&,
const iType1& begin,
960 const iType2& end) =
delete;
969template <
typename iType,
class TeamMemberType,
class _never_use_this_overload>
970KOKKOS_INLINE_FUNCTION_DELETED
971 Impl::ThreadVectorRangeBoundariesStruct<iType, TeamMemberType>
972 ThreadVectorRange(
const TeamMemberType&,
const iType& count) =
delete;
974template <
typename iType1,
typename iType2,
class TeamMemberType,
975 class _never_use_this_overload>
976KOKKOS_INLINE_FUNCTION_DELETED Impl::ThreadVectorRangeBoundariesStruct<
977 std::common_type_t<iType1, iType2>, TeamMemberType>
978ThreadVectorRange(
const TeamMemberType&,
const iType1& arg_begin,
979 const iType2& arg_end) =
delete;
983enum class TeamMDRangeLastNestLevel :
bool { NotLastNestLevel, LastNestLevel };
984enum class TeamMDRangeParThread :
bool { NotParThread, ParThread };
985enum class TeamMDRangeParVector :
bool { NotParVector, ParVector };
986enum class TeamMDRangeThreadAndVector :
bool { NotBoth, Both };
988template <
typename Rank, TeamMDRangeThreadAndVector ThreadAndVector>
989struct HostBasedNestLevel;
991template <
typename Rank, TeamMDRangeThreadAndVector ThreadAndVector>
992struct AcceleratorBasedNestLevel;
1002template <
typename Rank,
typename ExecSpace,
1003 TeamMDRangeThreadAndVector ThreadAndVector>
1004struct ThreadAndVectorNestLevel;
1006struct NoReductionTag {};
1008template <
typename Rank,
typename TeamMDPolicy,
typename Lambda,
1009 typename ReductionValueType>
1010KOKKOS_INLINE_FUNCTION
void md_parallel_impl(TeamMDPolicy
const& policy,
1011 Lambda
const& lambda,
1012 ReductionValueType&& val);
1015template <
typename Rank,
typename TeamHandle>
1016struct TeamThreadMDRange;
1018template <
unsigned N, Iterate OuterDir, Iterate InnerDir,
typename TeamHandle>
1019struct TeamThreadMDRange<Rank<N, OuterDir, InnerDir>, TeamHandle> {
1020 using NestLevelType = int;
1021 using BoundaryType = int;
1022 using TeamHandleType = TeamHandle;
1023 using ExecutionSpace =
typename TeamHandleType::execution_space;
1024 using ArrayLayout =
typename ExecutionSpace::array_layout;
1026 static constexpr NestLevelType total_nest_level =
1027 Rank<N, OuterDir, InnerDir>::rank;
1028 static constexpr Iterate iter = OuterDir;
1029 static constexpr auto par_thread = Impl::TeamMDRangeParThread::ParThread;
1030 static constexpr auto par_vector = Impl::TeamMDRangeParVector::NotParVector;
1032 static constexpr Iterate direction =
1033 OuterDir == Iterate::Default ? Impl::layout_iterate_type_selector<
1034 ArrayLayout>::outer_iteration_pattern
1037 template <
class... Args>
1038 KOKKOS_FUNCTION TeamThreadMDRange(TeamHandleType
const& team_, Args&&... args)
1039 : team(team_), boundaries{static_cast<BoundaryType>(args)...} {
1040 static_assert(
sizeof...(Args) == total_nest_level);
1043 TeamHandleType
const& team;
1044 BoundaryType boundaries[total_nest_level];
1047template <
typename TeamHandle,
typename... Args>
1048KOKKOS_DEDUCTION_GUIDE TeamThreadMDRange(TeamHandle
const&, Args&&...)
1049 -> TeamThreadMDRange<Rank<
sizeof...(Args), Iterate::Default>, TeamHandle>;
1051template <
typename Rank,
typename TeamHandle>
1052struct ThreadVectorMDRange;
1054template <
unsigned N, Iterate OuterDir, Iterate InnerDir,
typename TeamHandle>
1055struct ThreadVectorMDRange<Rank<N, OuterDir, InnerDir>, TeamHandle> {
1056 using NestLevelType = int;
1057 using BoundaryType = int;
1058 using TeamHandleType = TeamHandle;
1059 using ExecutionSpace =
typename TeamHandleType::execution_space;
1060 using ArrayLayout =
typename ExecutionSpace::array_layout;
1062 static constexpr NestLevelType total_nest_level =
1063 Rank<N, OuterDir, InnerDir>::rank;
1064 static constexpr Iterate iter = OuterDir;
1065 static constexpr auto par_thread = Impl::TeamMDRangeParThread::NotParThread;
1066 static constexpr auto par_vector = Impl::TeamMDRangeParVector::ParVector;
1068 static constexpr Iterate direction =
1069 OuterDir == Iterate::Default ? Impl::layout_iterate_type_selector<
1070 ArrayLayout>::outer_iteration_pattern
1073 template <
class... Args>
1074 KOKKOS_INLINE_FUNCTION ThreadVectorMDRange(TeamHandleType
const& team_,
1076 : team(team_), boundaries{static_cast<BoundaryType>(args)...} {
1077 static_assert(
sizeof...(Args) == total_nest_level);
1080 TeamHandleType
const& team;
1081 BoundaryType boundaries[total_nest_level];
1084template <
typename TeamHandle,
typename... Args>
1085KOKKOS_DEDUCTION_GUIDE ThreadVectorMDRange(TeamHandle
const&, Args&&...)
1086 -> ThreadVectorMDRange<Rank<
sizeof...(Args), Iterate::Default>, TeamHandle>;
1088template <
typename Rank,
typename TeamHandle>
1089struct TeamVectorMDRange;
1091template <
unsigned N, Iterate OuterDir, Iterate InnerDir,
typename TeamHandle>
1092struct TeamVectorMDRange<Rank<N, OuterDir, InnerDir>, TeamHandle> {
1093 using NestLevelType = int;
1094 using BoundaryType = int;
1095 using TeamHandleType = TeamHandle;
1096 using ExecutionSpace =
typename TeamHandleType::execution_space;
1097 using ArrayLayout =
typename ExecutionSpace::array_layout;
1099 static constexpr NestLevelType total_nest_level =
1100 Rank<N, OuterDir, InnerDir>::rank;
1101 static constexpr Iterate iter = OuterDir;
1102 static constexpr auto par_thread = Impl::TeamMDRangeParThread::ParThread;
1103 static constexpr auto par_vector = Impl::TeamMDRangeParVector::ParVector;
1105 static constexpr Iterate direction =
1106 iter == Iterate::Default ? Impl::layout_iterate_type_selector<
1107 ArrayLayout>::outer_iteration_pattern
1110 template <
class... Args>
1111 KOKKOS_INLINE_FUNCTION TeamVectorMDRange(TeamHandleType
const& team_,
1113 : team(team_), boundaries{static_cast<BoundaryType>(args)...} {
1114 static_assert(
sizeof...(Args) == total_nest_level);
1117 TeamHandleType
const& team;
1118 BoundaryType boundaries[total_nest_level];
1121template <
typename TeamHandle,
typename... Args>
1122KOKKOS_DEDUCTION_GUIDE TeamVectorMDRange(TeamHandle
const&, Args&&...)
1123 -> TeamVectorMDRange<Rank<
sizeof...(Args), Iterate::Default>, TeamHandle>;
1125template <
typename Rank,
typename TeamHandle,
typename Lambda,
1126 typename ReducerValueType>
1127KOKKOS_INLINE_FUNCTION
void parallel_reduce(
1128 TeamThreadMDRange<Rank, TeamHandle>
const& policy, Lambda
const& lambda,
1129 ReducerValueType& val) {
1131 !std::is_array_v<ReducerValueType> &&
1132 !std::is_pointer_v<ReducerValueType> &&
1134 "Only scalar return types are allowed!");
1136 val = ReducerValueType{};
1137 Impl::md_parallel_impl<Rank>(policy, lambda, val);
1138 policy.team.team_reduce(
1142template <
typename Rank,
typename TeamHandle,
typename Lambda>
1143KOKKOS_INLINE_FUNCTION
void parallel_for(
1144 TeamThreadMDRange<Rank, TeamHandle>
const& policy, Lambda
const& lambda) {
1145 Impl::md_parallel_impl<Rank>(policy, lambda, Impl::NoReductionTag());
1148template <
typename Rank,
typename TeamHandle,
typename Lambda,
1149 typename ReducerValueType>
1150KOKKOS_INLINE_FUNCTION
void parallel_reduce(
1151 ThreadVectorMDRange<Rank, TeamHandle>
const& policy, Lambda
const& lambda,
1152 ReducerValueType& val) {
1154 !std::is_array_v<ReducerValueType> &&
1155 !std::is_pointer_v<ReducerValueType> &&
1157 "Only a scalar return types are allowed!");
1159 val = ReducerValueType{};
1160 Impl::md_parallel_impl<Rank>(policy, lambda, val);
1162#ifdef KOKKOS_ENABLE_CUDA
1163 || std::is_same_v<
typename TeamHandle::execution_space,
1165#elif defined(KOKKOS_ENABLE_HIP)
1166 || std::is_same_v<
typename TeamHandle::execution_space,
1168#elif defined(KOKKOS_ENABLE_SYCL)
1169 || std::is_same_v<
typename TeamHandle::execution_space,
1173 policy.team.vector_reduce(
1178template <
typename Rank,
typename TeamHandle,
typename Lambda>
1179KOKKOS_INLINE_FUNCTION
void parallel_for(
1180 ThreadVectorMDRange<Rank, TeamHandle>
const& policy, Lambda
const& lambda) {
1181 Impl::md_parallel_impl<Rank>(policy, lambda, Impl::NoReductionTag());
1184template <
typename Rank,
typename TeamHandle,
typename Lambda,
1185 typename ReducerValueType>
1186KOKKOS_INLINE_FUNCTION
void parallel_reduce(
1187 TeamVectorMDRange<Rank, TeamHandle>
const& policy, Lambda
const& lambda,
1188 ReducerValueType& val) {
1190 !std::is_array_v<ReducerValueType> &&
1191 !std::is_pointer_v<ReducerValueType> &&
1193 "Only a scalar return types are allowed!");
1195 val = ReducerValueType{};
1196 Impl::md_parallel_impl<Rank>(policy, lambda, val);
1198#ifdef KOKKOS_ENABLE_CUDA
1199 || std::is_same_v<
typename TeamHandle::execution_space,
1201#elif defined(KOKKOS_ENABLE_HIP)
1202 || std::is_same_v<
typename TeamHandle::execution_space,
1204#elif defined(KOKKOS_ENABLE_SYCL)
1205 || std::is_same_v<
typename TeamHandle::execution_space,
1209 policy.team.vector_reduce(
1212 policy.team.team_reduce(
1216template <
typename Rank,
typename TeamHandle,
typename Lambda>
1217KOKKOS_INLINE_FUNCTION
void parallel_for(
1218 TeamVectorMDRange<Rank, TeamHandle>
const& policy, Lambda
const& lambda) {
1219 Impl::md_parallel_impl<Rank>(policy, lambda, Impl::NoReductionTag());
1224template <
typename FunctorType,
typename TagType,
1225 bool HasTag = !std::is_void_v<TagType>>
1226struct ParallelConstructName;
1228template <
typename FunctorType,
typename TagType>
1229struct ParallelConstructName<FunctorType, TagType, true> {
1230 ParallelConstructName(std::string
const& label) : label_ref(label) {
1231 if (label.empty()) {
1232#ifdef KOKKOS_ENABLE_IMPL_TYPEINFO
1234 std::string(TypeInfo<std::remove_const_t<FunctorType>>::name()) +
1235 "/" + std::string(TypeInfo<TagType>::name());
1237 default_name = std::string(
typeid(FunctorType).name()) +
"/" +
1238 typeid(TagType).name();
1242 std::string
const& get() {
1243 return (label_ref.empty()) ? default_name : label_ref;
1245 std::string
const& label_ref;
1246 std::string default_name;
1249template <
typename FunctorType,
typename TagType>
1250struct ParallelConstructName<FunctorType, TagType, false> {
1251 ParallelConstructName(std::string
const& label) : label_ref(label) {
1252 if (label.empty()) {
1253#ifdef KOKKOS_ENABLE_IMPL_TYPEINFO
1254 default_name = TypeInfo<std::remove_const_t<FunctorType>>::name();
1256 default_name =
typeid(FunctorType).name();
1260 std::string
const& get() {
1261 return (label_ref.empty()) ? default_name : label_ref;
1263 std::string
const& label_ref;
1264 std::string default_name;
1275template <
class PatternTag,
class... Args>
1276struct PatternImplSpecializationFromTag;
1278template <
class... Args>
1279struct PatternImplSpecializationFromTag<Kokkos::ParallelForTag, Args...>
1280 : type_identity<ParallelFor<Args...>> {};
1282template <
class... Args>
1283struct PatternImplSpecializationFromTag<Kokkos::ParallelReduceTag, Args...>
1284 : type_identity<ParallelReduce<Args...>> {};
1286template <
class... Args>
1287struct PatternImplSpecializationFromTag<Kokkos::ParallelScanTag, Args...>
1288 : type_identity<ParallelScan<Args...>> {};
1290template <
class PatternImpl>
1291struct PatternTagFromImplSpecialization;
1293template <
class... Args>
1294struct PatternTagFromImplSpecialization<ParallelFor<Args...>>
1295 : type_identity<ParallelForTag> {};
1297template <
class... Args>
1298struct PatternTagFromImplSpecialization<ParallelReduce<Args...>>
1299 : type_identity<ParallelReduceTag> {};
1301template <
class... Args>
1302struct PatternTagFromImplSpecialization<ParallelScan<Args...>>
1303 : type_identity<ParallelScanTag> {};
A thread safe view to a bitset.
Execution policy for work over a range of an integral type.
RangePolicy(const typename traits::execution_space &work_space, const IndexType1 work_begin, const IndexType2 work_end)
Total range.
RangePolicy(const IndexType1 work_begin, const IndexType2 work_end)
Total range.
RangePolicy(const IndexType1 work_begin, const IndexType2 work_end, const ChunkSize chunk_size)
Total range.
RangePolicy & set_chunk_size(int chunk_size)
set chunk_size to a discrete value
member_type chunk_size() const
return chunk_size
Parallel execution of a functor calls the functor once with each member of the execution policy.
KOKKOS_INLINE_FUNCTION JoinOp::value_type team_reduce(const typename JoinOp::value_type, const JoinOp &) const
Intra-team reduction. Returns join of all values of the team members.
KOKKOS_INLINE_FUNCTION Type team_scan(const Type &value, Type *const global_accum) const
Intra-team exclusive prefix sum with team_rank() ordering with intra-team non-deterministic ordering ...
KOKKOS_INLINE_FUNCTION int team_size() const
Number of threads in this team.
KOKKOS_INLINE_FUNCTION traits::execution_space::scratch_memory_space team_shmem() const
Handle to the currently executing team shared scratch memory.
KOKKOS_INLINE_FUNCTION int team_rank() const
Rank of this thread within this team.
KOKKOS_INLINE_FUNCTION int league_size() const
Number of teams in the league.
KOKKOS_INLINE_FUNCTION int league_rank() const
Rank of this team within the league of teams.
KOKKOS_INLINE_FUNCTION void team_barrier() const
Barrier among the threads of this team.
KOKKOS_INLINE_FUNCTION Type team_scan(const Type &value) const
Intra-team exclusive prefix sum with team_rank() ordering.
Subrange for a partition's rank and size.
KOKKOS_INLINE_FUNCTION WorkRange(const RangePolicy &range, const int part_rank, const int part_size)
Subrange for a partition's rank and size.