44 #ifndef KOKKOS_EXECPOLICY_HPP 45 #define KOKKOS_EXECPOLICY_HPP 47 #include <Kokkos_Core_fwd.hpp> 48 #include <impl/Kokkos_Traits.hpp> 49 #include <impl/Kokkos_StaticAssert.hpp> 50 #include <impl/Kokkos_Tags.hpp> 77 template<
class Arg0 = void ,
class Arg1 = void ,
class Arg2 = void
81 typename std::conditional
82 < Impl::is_execution_space< Arg0 >::value , Arg0
83 , Kokkos::DefaultExecutionSpace >::type
89 typedef int DefaultIntType ;
90 enum { DefaultIntValue = 8 };
92 enum { Arg0_Void = Impl::is_same< Arg0 , void >::value };
93 enum { Arg1_Void = Impl::is_same< Arg1 , void >::value };
94 enum { Arg2_Void = Impl::is_same< Arg2 , void >::value };
96 enum { Arg0_ExecSpace = Impl::is_execution_space< Arg0 >::value };
98 enum { Arg0_IntConst = Impl::is_integral_constant< Arg0 >::value };
99 enum { Arg1_IntConst = Impl::is_integral_constant< Arg1 >::value };
100 enum { Arg2_IntConst = Impl::is_integral_constant< Arg2 >::value };
102 enum { Arg0_IntType = Impl::is_integral< Arg0 >::value };
103 enum { Arg1_IntType = Impl::is_integral< Arg1 >::value };
104 enum { Arg2_IntType = Impl::is_integral< Arg2 >::value };
106 enum { Arg0_WorkTag = ! Arg0_ExecSpace && ! Arg0_IntConst && ! Arg0_IntType && ! Arg0_Void };
107 enum { Arg1_WorkTag = Arg0_ExecSpace && ! Arg1_IntConst && ! Arg1_IntType && ! Arg1_Void };
109 enum { ArgOption_OK = Impl::StaticAssert< (
110 ( Arg0_ExecSpace && Arg1_WorkTag && ( Arg2_IntConst || Arg2_IntType ) ) ||
111 ( Arg0_ExecSpace && Arg1_WorkTag && Arg2_Void ) ||
112 ( Arg0_ExecSpace && ( Arg1_IntConst || Arg1_IntType ) && Arg2_Void ) ||
113 ( Arg0_ExecSpace && Arg1_Void && Arg2_Void ) ||
114 ( Arg0_WorkTag && ( Arg1_IntConst || Arg1_IntType ) && Arg2_Void ) ||
115 ( Arg0_WorkTag && Arg1_Void && Arg2_Void ) ||
116 ( ( Arg0_IntConst || Arg0_IntType ) && Arg1_Void && Arg2_Void ) ||
117 ( Arg0_Void && Arg1_Void && Arg2_Void )
121 typedef typename std::conditional< Arg0_WorkTag , Arg0 ,
122 typename std::conditional< Arg1_WorkTag , Arg1 ,
void 126 enum { Granularity = Arg0_IntConst ? unsigned(Impl::is_integral_constant<Arg0>::integral_value) : (
127 Arg1_IntConst ? unsigned(Impl::is_integral_constant<Arg1>::integral_value) : (
128 Arg2_IntConst ? unsigned(Impl::is_integral_constant<Arg2>::integral_value) : (
129 unsigned(DefaultIntValue) ))) };
132 static_assert( Impl::is_integral_power_of_two( Granularity )
133 ,
"RangePolicy blocking granularity must be power of two" );
135 typedef typename std::conditional< Arg0_IntType , Arg0 ,
136 typename std::conditional< Arg1_IntType , Arg1 ,
137 typename std::conditional< Arg2_IntType , Arg2 ,
138 typename std::conditional< Arg0_IntConst , typename Impl::is_integral_constant<Arg0>::integral_type ,
139 typename std::conditional< Arg1_IntConst , typename Impl::is_integral_constant<Arg1>::integral_type ,
140 typename std::conditional< Arg2_IntConst , typename Impl::is_integral_constant<Arg2>::integral_type ,
142 >::type >::type >::type
143 >::type >::type >::type
146 enum { GranularityMask = IntType(Granularity) - 1 };
157 typedef WorkTag work_tag ;
158 typedef IntType member_type ;
160 KOKKOS_INLINE_FUNCTION
const execution_space & space()
const {
return m_space ; }
161 KOKKOS_INLINE_FUNCTION member_type begin()
const {
return m_begin ; }
162 KOKKOS_INLINE_FUNCTION member_type end()
const {
return m_end ; }
164 inline RangePolicy() : m_space(), m_begin(0), m_end(0) {}
169 ,
const member_type work_end
172 , m_begin( work_begin < work_end ? work_begin : 0 )
173 , m_end( work_begin < work_end ? work_end : 0 )
179 ,
const member_type work_begin
180 ,
const member_type work_end
182 : m_space( work_space )
183 , m_begin( work_begin < work_end ? work_begin : 0 )
184 , m_end( work_begin < work_end ? work_end : 0 )
192 typedef RangePolicy::work_tag work_tag ;
193 typedef RangePolicy::member_type member_type ;
195 KOKKOS_INLINE_FUNCTION member_type begin()
const {
return m_begin ; }
196 KOKKOS_INLINE_FUNCTION member_type end()
const {
return m_end ; }
202 KOKKOS_INLINE_FUNCTION
204 ,
const int part_rank
205 ,
const int part_size
207 : m_begin(0), m_end(0)
212 const member_type work_part =
213 ( ( ( ( range.end() - range.begin() ) + ( part_size - 1 ) ) / part_size )
214 + GranularityMask ) & ~member_type(GranularityMask);
216 m_begin = range.begin() + work_part * part_rank ;
217 m_end = m_begin + work_part ;
219 if ( range.end() < m_begin ) m_begin = range.end() ;
220 if ( range.end() < m_end ) m_end = range.end() ;
224 member_type m_begin ;
258 template<
class Arg0 = void
263 typename std::conditional
264 < Impl::is_execution_space< Arg0 >::value , Arg0
265 , Kokkos::DefaultExecutionSpace >::type
270 enum { Arg0_ExecSpace = Impl::is_execution_space< Arg0 >::value };
271 enum { Arg1_Void = Impl::is_same< Arg1 , void >::value };
272 enum { ArgOption_OK = Impl::StaticAssert< ( Arg0_ExecSpace || Arg1_Void ) >::value };
274 typedef typename std::conditional< Arg0_ExecSpace , Arg1 , Arg0 >::type WorkTag ;
281 typedef WorkTag work_tag ;
290 template<
class FunctorType >
291 static int team_size_max(
const FunctorType & );
299 template<
class FunctorType >
300 static int team_size_recommended(
const FunctorType & );
302 template<
class FunctorType >
303 static int team_size_recommended(
const FunctorType & ,
const int&);
306 TeamPolicy(
const execution_space & ,
int league_size_request ,
int team_size_request );
308 TeamPolicy(
const execution_space & ,
int league_size_request ,
const Kokkos::AUTO_t & );
311 TeamPolicy(
int league_size_request ,
int team_size_request );
313 TeamPolicy(
int league_size_request ,
const Kokkos::AUTO_t & );
320 KOKKOS_INLINE_FUNCTION
int league_size()
const ;
327 KOKKOS_INLINE_FUNCTION
int team_size()
const ;
335 KOKKOS_INLINE_FUNCTION
336 typename execution_space::scratch_memory_space team_shmem()
const ;
339 KOKKOS_INLINE_FUNCTION
int league_rank()
const ;
342 KOKKOS_INLINE_FUNCTION
int league_size()
const ;
345 KOKKOS_INLINE_FUNCTION
int team_rank()
const ;
348 KOKKOS_INLINE_FUNCTION
int team_size()
const ;
351 KOKKOS_INLINE_FUNCTION
void team_barrier()
const ;
354 template<
class JoinOp >
355 KOKKOS_INLINE_FUNCTION
356 typename JoinOp::value_type team_reduce(
const typename JoinOp::value_type
357 ,
const JoinOp & )
const ;
364 template<
typename Type >
365 KOKKOS_INLINE_FUNCTION Type team_scan(
const Type & value )
const ;
376 template<
typename Type >
377 KOKKOS_INLINE_FUNCTION Type team_scan(
const Type & value , Type *
const global_accum )
const ;
387 template<
typename iType,
class TeamMemberType>
388 struct TeamThreadRangeBoundariesStruct {
391 KOKKOS_INLINE_FUNCTION
static 392 iType ibegin(
const iType & arg_begin
393 ,
const iType & arg_end
394 ,
const iType & arg_rank
395 ,
const iType & arg_size
398 return arg_begin + ( ( arg_end - arg_begin + arg_size - 1 ) / arg_size ) * arg_rank ;
401 KOKKOS_INLINE_FUNCTION
static 402 iType iend(
const iType & arg_begin
403 ,
const iType & arg_end
404 ,
const iType & arg_rank
405 ,
const iType & arg_size
408 const iType end_ = arg_begin + ( ( arg_end - arg_begin + arg_size - 1 ) / arg_size ) * ( arg_rank + 1 );
409 return end_ < arg_end ? end_ : arg_end ;
414 typedef iType index_type;
417 enum {increment = 1};
418 const TeamMemberType& thread;
420 KOKKOS_INLINE_FUNCTION
421 TeamThreadRangeBoundariesStruct(
const TeamMemberType& arg_thread
422 ,
const iType& arg_end
424 : start( ibegin( 0 , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
425 , end( iend( 0 , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
426 , thread( arg_thread )
429 KOKKOS_INLINE_FUNCTION
430 TeamThreadRangeBoundariesStruct(
const TeamMemberType& arg_thread
431 ,
const iType& arg_begin
432 ,
const iType& arg_end
434 : start( ibegin( arg_begin , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
435 , end( iend( arg_begin , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
436 , thread( arg_thread )
440 template<
typename iType,
class TeamMemberType>
441 struct ThreadVectorRangeBoundariesStruct {
442 typedef iType index_type;
445 enum {increment = 1};
447 KOKKOS_INLINE_FUNCTION
448 ThreadVectorRangeBoundariesStruct (
const TeamMemberType& thread,
const iType& count):
453 template<
class TeamMemberType>
454 struct ThreadSingleStruct {
455 const TeamMemberType& team_member;
456 KOKKOS_INLINE_FUNCTION
457 ThreadSingleStruct(
const TeamMemberType& team_member_):team_member(team_member_){}
460 template<
class TeamMemberType>
461 struct VectorSingleStruct {
462 const TeamMemberType& team_member;
463 KOKKOS_INLINE_FUNCTION
464 VectorSingleStruct(
const TeamMemberType& team_member_):team_member(team_member_){}
474 template<
typename iType,
class TeamMemberType>
475 KOKKOS_INLINE_FUNCTION
476 Impl::TeamThreadRangeBoundariesStruct<iType,TeamMemberType>
TeamThreadRange(
const TeamMemberType&,
const iType& count);
484 template<
typename iType,
class TeamMemberType>
485 KOKKOS_INLINE_FUNCTION
486 Impl::TeamThreadRangeBoundariesStruct<iType,TeamMemberType>
TeamThreadRange(
const TeamMemberType&,
const iType& begin,
const iType& end);
494 template<
typename iType,
class TeamMemberType>
495 KOKKOS_INLINE_FUNCTION
496 Impl::ThreadVectorRangeBoundariesStruct<iType,TeamMemberType>
ThreadVectorRange(
const TeamMemberType&,
const iType& count);
TeamPolicy execution_policy
Tag this class as an execution policy.
KOKKOS_INLINE_FUNCTION Impl::TeamThreadRangeBoundariesStruct< iType, TeamMemberType > TeamThreadRange(const TeamMemberType &, const iType &count)
Execution policy for parallel work over a threads within a team.
RangePolicy(const execution_space &work_space, const member_type work_begin, const member_type work_end)
Total range.
Parallel execution of a functor calls the functor once with each member of the execution policy...
RangePolicy(const member_type work_begin, const member_type work_end)
Total range.
KOKKOS_INLINE_FUNCTION Impl::ThreadVectorRangeBoundariesStruct< iType, TeamMemberType > ThreadVectorRange(const TeamMemberType &, const iType &count)
Execution policy for a vector parallel loop.
Execution policy for work over a range of an integral type.
Subrange for a partition's rank and size.
Execution policy for parallel work over a league of teams of threads.
KOKKOS_INLINE_FUNCTION WorkRange(const RangePolicy &range, const int part_rank, const int part_size)
Subrange for a partition's rank and size.
ExecSpace execution_space
Tag this class as an execution policy.