47 #ifndef KOKKOS_SERIAL_HPP
48 #define KOKKOS_SERIAL_HPP
50 #include <Kokkos_Macros.hpp>
51 #if defined( KOKKOS_ENABLE_SERIAL )
56 #include <Kokkos_TaskScheduler.hpp>
58 #include <Kokkos_HostSpace.hpp>
59 #include <Kokkos_ScratchSpace.hpp>
60 #include <Kokkos_MemoryTraits.hpp>
61 #include <impl/Kokkos_Tags.hpp>
62 #include <impl/Kokkos_HostThreadTeam.hpp>
63 #include <impl/Kokkos_FunctorAnalysis.hpp>
64 #include <impl/Kokkos_FunctorAdapter.hpp>
65 #include <impl/Kokkos_Profiling_Interface.hpp>
67 #include <KokkosExp_MDRangePolicy.hpp>
69 #include <Kokkos_UniqueToken.hpp>
91 typedef Serial execution_space ;
93 typedef HostSpace::size_type size_type ;
95 typedef HostSpace memory_space ;
97 typedef Kokkos::Device<execution_space,memory_space> device_type;
100 typedef LayoutRight array_layout ;
103 typedef ScratchMemorySpace< Kokkos::Serial > scratch_memory_space ;
113 inline static int in_parallel() {
return false ; }
121 static void impl_static_fence() {}
123 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
124 static void fence() {}
126 void fence()
const {}
130 static int concurrency() {
return 1;}
135 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
139 static void initialize(
unsigned threads_count = 1 ,
140 unsigned use_numa_count = 0 ,
141 unsigned use_cores_per_numa = 0 ,
142 bool allow_asynchronous_threadpool =
false);
144 static bool is_initialized();
151 inline static int thread_pool_size(
int = 0 ) {
return 1 ; }
152 KOKKOS_INLINE_FUNCTION
static int thread_pool_rank() {
return 0 ; }
156 KOKKOS_INLINE_FUNCTION
static unsigned hardware_thread_id() {
return thread_pool_rank(); }
157 inline static unsigned max_hardware_threads() {
return thread_pool_size(0); }
159 static void impl_initialize();
161 static bool impl_is_initialized();
164 static void impl_finalize();
168 inline static int impl_thread_pool_size(
int = 0 ) {
return 1 ; }
169 KOKKOS_INLINE_FUNCTION
static int impl_thread_pool_rank() {
return 0 ; }
173 KOKKOS_INLINE_FUNCTION
static unsigned impl_hardware_thread_id() {
return impl_thread_pool_rank(); }
174 inline static unsigned impl_max_hardware_threads() {
return impl_thread_pool_size(0); }
177 static const char* name();
190 struct MemorySpaceAccess
191 < Kokkos::Serial::memory_space
192 , Kokkos::Serial::scratch_memory_space
195 enum { assignable =
false };
196 enum { accessible =
true };
197 enum { deepcopy =
false };
201 struct VerifyExecutionCanAccessMemorySpace
202 < Kokkos::Serial::memory_space
203 , Kokkos::Serial::scratch_memory_space
206 enum { value =
true };
207 inline static void verify(
void ) { }
208 inline static void verify(
const void * ) { }
221 void serial_resize_thread_team_data(
size_t pool_reduce_bytes
222 ,
size_t team_reduce_bytes
223 ,
size_t team_shared_bytes
224 ,
size_t thread_local_bytes );
226 HostThreadTeamData * serial_get_thread_team_data();
240 template<
class ... Properties >
241 class TeamPolicyInternal< Kokkos::Serial , Properties ... >:
public PolicyTraits<Properties...>
245 size_t m_team_scratch_size[2] ;
246 size_t m_thread_scratch_size[2] ;
253 typedef TeamPolicyInternal execution_policy ;
255 typedef PolicyTraits<Properties ... > traits;
258 typedef Kokkos::Serial execution_space ;
260 TeamPolicyInternal& operator = (
const TeamPolicyInternal& p) {
261 m_league_size = p.m_league_size;
262 m_team_scratch_size[0] = p.m_team_scratch_size[0];
263 m_thread_scratch_size[0] = p.m_thread_scratch_size[0];
264 m_team_scratch_size[1] = p.m_team_scratch_size[1];
265 m_thread_scratch_size[1] = p.m_thread_scratch_size[1];
266 m_chunk_size = p.m_chunk_size;
270 template<
class ExecSpace,
class ... OtherProperties >
271 friend class TeamPolicyInternal;
273 template<
class ... OtherProperties >
274 TeamPolicyInternal(
const TeamPolicyInternal<Kokkos::Serial,OtherProperties...>& p) {
275 m_league_size = p.m_league_size;
276 m_team_scratch_size[0] = p.m_team_scratch_size[0];
277 m_thread_scratch_size[0] = p.m_thread_scratch_size[0];
278 m_team_scratch_size[1] = p.m_team_scratch_size[1];
279 m_thread_scratch_size[1] = p.m_thread_scratch_size[1];
280 m_chunk_size = p.m_chunk_size;
285 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
286 template<
class FunctorType >
288 int team_size_max(
const FunctorType & ) {
return 1 ; }
290 template<
class FunctorType >
292 int team_size_recommended(
const FunctorType & ) {
return 1 ; }
294 template<
class FunctorType >
296 int team_size_recommended(
const FunctorType & ,
const int& ) {
return 1 ; }
299 template<
class FunctorType>
300 int team_size_max(
const FunctorType&,
const ParallelForTag& )
const {
return 1 ; }
301 template<
class FunctorType>
302 int team_size_max(
const FunctorType&,
const ParallelReduceTag& )
const {
return 1 ; }
303 template<
class FunctorType>
304 int team_size_recommended(
const FunctorType&,
const ParallelForTag& )
const {
return 1 ; }
305 template<
class FunctorType>
306 int team_size_recommended(
const FunctorType&,
const ParallelReduceTag& )
const {
return 1 ; }
310 inline int team_size()
const {
return 1 ; }
311 inline int league_size()
const {
return m_league_size ; }
312 inline size_t scratch_size(
const int& level,
int = 0)
const {
return m_team_scratch_size[level] + m_thread_scratch_size[level]; }
315 int vector_length_max()
319 int scratch_size_max(
int level)
325 TeamPolicyInternal(
const execution_space &
326 ,
int league_size_request
327 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
328 ,
int team_size_request
333 : m_team_scratch_size { 0 , 0 }
334 , m_thread_scratch_size { 0 , 0 }
335 , m_league_size( league_size_request )
336 , m_chunk_size ( 32 )
338 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
339 if(team_size_request > 1) Kokkos::abort(
"Kokkos::abort: Requested Team Size is too large!");
343 TeamPolicyInternal(
const execution_space &
344 ,
int league_size_request
345 ,
const Kokkos::AUTO_t &
347 : m_team_scratch_size { 0 , 0 }
348 , m_thread_scratch_size { 0 , 0 }
349 , m_league_size( league_size_request )
350 , m_chunk_size ( 32 )
353 TeamPolicyInternal(
int league_size_request
354 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
355 ,
int team_size_request
360 : m_team_scratch_size { 0 , 0 }
361 , m_thread_scratch_size { 0 , 0 }
362 , m_league_size( league_size_request )
363 , m_chunk_size ( 32 )
365 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
366 if(team_size_request > 1) Kokkos::abort(
"Kokkos::abort: Requested Team Size is too large!");
370 TeamPolicyInternal(
int league_size_request
371 ,
const Kokkos::AUTO_t &
373 : m_team_scratch_size { 0 , 0 }
374 , m_thread_scratch_size { 0 , 0 }
375 , m_league_size( league_size_request )
376 , m_chunk_size ( 32 )
379 inline int chunk_size()
const {
return m_chunk_size ; }
381 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
383 inline TeamPolicyInternal set_chunk_size(
typename traits::index_type chunk_size_)
const {
384 TeamPolicyInternal p = *
this;
385 p.m_chunk_size = chunk_size_;
390 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerTeamValue& per_team)
const {
391 TeamPolicyInternal p = *
this;
392 p.m_team_scratch_size[level] = per_team.value;
397 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerThreadValue& per_thread)
const {
398 TeamPolicyInternal p = *
this;
399 p.m_thread_scratch_size[level] = per_thread.value;
404 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerTeamValue& per_team,
const PerThreadValue& per_thread)
const {
405 TeamPolicyInternal p = *
this;
406 p.m_team_scratch_size[level] = per_team.value;
407 p.m_thread_scratch_size[level] = per_thread.value;
412 inline TeamPolicyInternal& set_chunk_size(
typename traits::index_type chunk_size_) {
413 m_chunk_size = chunk_size_;
418 inline TeamPolicyInternal& set_scratch_size(
const int& level,
const PerTeamValue& per_team) {
419 m_team_scratch_size[level] = per_team.value;
424 inline TeamPolicyInternal& set_scratch_size(
const int& level,
const PerThreadValue& per_thread) {
425 m_thread_scratch_size[level] = per_thread.value;
430 inline TeamPolicyInternal& set_scratch_size(
const int& level,
const PerTeamValue& per_team,
const PerThreadValue& per_thread) {
431 m_team_scratch_size[level] = per_team.value;
432 m_thread_scratch_size[level] = per_thread.value;
437 typedef Impl::HostThreadTeamMember< Kokkos::Serial > member_type ;
440 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
442 inline TeamPolicyInternal internal_set_chunk_size(
typename traits::index_type chunk_size_) {
443 m_chunk_size = chunk_size_;
448 inline TeamPolicyInternal internal_set_scratch_size(
const int& level,
const PerTeamValue& per_team) {
449 m_team_scratch_size[level] = per_team.value;
454 inline TeamPolicyInternal internal_set_scratch_size(
const int& level,
const PerThreadValue& per_thread) {
455 m_thread_scratch_size[level] = per_thread.value;
460 inline TeamPolicyInternal internal_set_scratch_size(
const int& level,
const PerTeamValue& per_team,
const PerThreadValue& per_thread) {
461 m_team_scratch_size[level] = per_team.value;
462 m_thread_scratch_size[level] = per_thread.value;
477 template<
class FunctorType ,
class ... Traits >
478 class ParallelFor< FunctorType ,
479 Kokkos::RangePolicy< Traits ... > ,
487 const FunctorType m_functor ;
488 const Policy m_policy ;
490 template<
class TagType >
491 typename std::enable_if< std::is_same< TagType , void >::value >::type
494 const typename Policy::member_type e = m_policy.end();
495 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
500 template<
class TagType >
501 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
505 const typename Policy::member_type e = m_policy.end();
506 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
515 { this->
template exec< typename Policy::work_tag >(); }
518 ParallelFor(
const FunctorType & arg_functor
519 ,
const Policy & arg_policy )
520 : m_functor( arg_functor )
521 , m_policy( arg_policy )
527 template<
class FunctorType ,
class ReducerType ,
class ... Traits >
528 class ParallelReduce< FunctorType
529 , Kokkos::RangePolicy< Traits ... >
537 typedef typename Policy::work_tag WorkTag ;
539 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
541 typedef typename ReducerConditional::type ReducerTypeFwd;
542 typedef typename Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, WorkTag,
void>::type WorkTagFwd;
544 typedef FunctorAnalysis< FunctorPatternInterface::REDUCE , Policy , FunctorType > Analysis ;
546 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTagFwd > ValueInit ;
548 typedef typename Analysis::pointer_type pointer_type ;
549 typedef typename Analysis::reference_type reference_type ;
551 const FunctorType m_functor ;
552 const Policy m_policy ;
553 const ReducerType m_reducer ;
554 const pointer_type m_result_ptr ;
556 template<
class TagType >
558 typename std::enable_if< std::is_same< TagType , void >::value >::type
559 exec( reference_type update )
const
561 const typename Policy::member_type e = m_policy.end();
562 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
563 m_functor( i , update );
567 template<
class TagType >
569 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
570 exec( reference_type update )
const
574 const typename Policy::member_type e = m_policy.end();
575 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
576 m_functor( t , i , update );
585 const size_t pool_reduce_size =
586 Analysis::value_size( ReducerConditional::select(m_functor , m_reducer) );
587 const size_t team_reduce_size = 0 ;
588 const size_t team_shared_size = 0 ;
589 const size_t thread_local_size = 0 ;
591 serial_resize_thread_team_data( pool_reduce_size
594 , thread_local_size );
596 HostThreadTeamData & data = *serial_get_thread_team_data();
599 m_result_ptr ? m_result_ptr : pointer_type(data.pool_reduce_local());
601 reference_type update =
602 ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
604 this->
template exec< WorkTag >( update );
606 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , WorkTagFwd >::
607 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
610 template<
class HostViewType >
611 ParallelReduce(
const FunctorType & arg_functor ,
612 const Policy & arg_policy ,
613 const HostViewType & arg_result_view ,
614 typename std::enable_if<
615 Kokkos::is_view< HostViewType >::value &&
616 !Kokkos::is_reducer_type<ReducerType>::value
617 ,
void*>::type = NULL)
618 : m_functor( arg_functor )
619 , m_policy( arg_policy )
620 , m_reducer( InvalidType() )
621 , m_result_ptr( arg_result_view.data() )
623 static_assert( Kokkos::is_view< HostViewType >::value
624 ,
"Kokkos::Serial reduce result must be a View" );
626 static_assert( std::is_same< typename HostViewType::memory_space , HostSpace >::value
627 ,
"Kokkos::Serial reduce result must be a View in HostSpace" );
631 ParallelReduce(
const FunctorType & arg_functor
633 ,
const ReducerType& reducer )
634 : m_functor( arg_functor )
635 , m_policy( arg_policy )
636 , m_reducer( reducer )
637 , m_result_ptr( reducer.view().data() )
648 template<
class FunctorType ,
class ... Traits >
649 class ParallelScan< FunctorType
650 , Kokkos::RangePolicy< Traits ... >
657 typedef typename Policy::work_tag WorkTag ;
659 typedef FunctorAnalysis< FunctorPatternInterface::SCAN , Policy , FunctorType > Analysis ;
661 typedef Kokkos::Impl::FunctorValueInit< FunctorType , WorkTag > ValueInit ;
663 typedef typename Analysis::pointer_type pointer_type ;
664 typedef typename Analysis::reference_type reference_type ;
666 const FunctorType m_functor ;
667 const Policy m_policy ;
669 template<
class TagType >
671 typename std::enable_if< std::is_same< TagType , void >::value >::type
672 exec( reference_type update )
const
674 const typename Policy::member_type e = m_policy.end();
675 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
676 m_functor( i , update ,
true );
680 template<
class TagType >
682 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
683 exec( reference_type update )
const
686 const typename Policy::member_type e = m_policy.end();
687 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
688 m_functor( t , i , update ,
true );
697 const size_t pool_reduce_size = Analysis::value_size( m_functor );
698 const size_t team_reduce_size = 0 ;
699 const size_t team_shared_size = 0 ;
700 const size_t thread_local_size = 0 ;
702 serial_resize_thread_team_data( pool_reduce_size
705 , thread_local_size );
707 HostThreadTeamData & data = *serial_get_thread_team_data();
709 reference_type update =
710 ValueInit::init( m_functor , pointer_type(data.pool_reduce_local()) );
712 this->
template exec< WorkTag >( update );
716 ParallelScan(
const FunctorType & arg_functor
717 ,
const Policy & arg_policy
719 : m_functor( arg_functor )
720 , m_policy( arg_policy )
725 template<
class FunctorType ,
class ReturnType,
class ... Traits >
726 class ParallelScanWithTotal< FunctorType
727 , Kokkos::RangePolicy< Traits ... >
735 typedef typename Policy::work_tag WorkTag ;
737 typedef FunctorAnalysis< FunctorPatternInterface::SCAN , Policy , FunctorType > Analysis ;
739 typedef Kokkos::Impl::FunctorValueInit< FunctorType , WorkTag > ValueInit ;
741 typedef typename Analysis::pointer_type pointer_type ;
742 typedef typename Analysis::reference_type reference_type ;
744 const FunctorType m_functor ;
745 const Policy m_policy ;
748 template<
class TagType >
750 typename std::enable_if< std::is_same< TagType , void >::value >::type
751 exec( reference_type update )
const
753 const typename Policy::member_type e = m_policy.end();
754 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
755 m_functor( i , update ,
true );
759 template<
class TagType >
761 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
762 exec( reference_type update )
const
765 const typename Policy::member_type e = m_policy.end();
766 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
767 m_functor( t , i , update ,
true );
776 const size_t pool_reduce_size = Analysis::value_size( m_functor );
777 const size_t team_reduce_size = 0 ;
778 const size_t team_shared_size = 0 ;
779 const size_t thread_local_size = 0 ;
781 serial_resize_thread_team_data( pool_reduce_size
784 , thread_local_size );
786 HostThreadTeamData & data = *serial_get_thread_team_data();
788 reference_type update =
789 ValueInit::init( m_functor , pointer_type(data.pool_reduce_local()) );
791 this->
template exec< WorkTag >( update );
793 m_returnvalue = update;
797 ParallelScanWithTotal(
const FunctorType & arg_functor
798 ,
const Policy & arg_policy
801 : m_functor( arg_functor )
802 , m_policy( arg_policy )
803 , m_returnvalue( arg_returnvalue )
818 template<
class FunctorType ,
class ... Traits >
819 class ParallelFor< FunctorType ,
820 Kokkos::MDRangePolicy< Traits ... > ,
826 typedef Kokkos::MDRangePolicy< Traits ... > MDRangePolicy ;
827 typedef typename MDRangePolicy::impl_range_policy Policy ;
829 typedef typename Kokkos::Impl::HostIterateTile< MDRangePolicy, FunctorType, typename MDRangePolicy::work_tag, void > iterate_type;
831 const FunctorType m_functor ;
832 const MDRangePolicy m_mdr_policy ;
833 const Policy m_policy ;
838 const typename Policy::member_type e = m_policy.end();
839 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
840 iterate_type( m_mdr_policy, m_functor )( i );
851 ParallelFor(
const FunctorType & arg_functor
852 ,
const MDRangePolicy & arg_policy )
853 : m_functor( arg_functor )
854 , m_mdr_policy( arg_policy )
855 , m_policy( Policy(0, m_mdr_policy.m_num_tiles).set_chunk_size(1) )
860 template<
class FunctorType ,
class ReducerType ,
class ... Traits >
861 class ParallelReduce< FunctorType
862 , Kokkos::MDRangePolicy< Traits ... >
869 typedef Kokkos::MDRangePolicy< Traits ... > MDRangePolicy ;
870 typedef typename MDRangePolicy::impl_range_policy Policy ;
872 typedef typename MDRangePolicy::work_tag WorkTag ;
874 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
875 typedef typename ReducerConditional::type ReducerTypeFwd;
876 typedef typename Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, WorkTag,
void>::type WorkTagFwd;
878 typedef FunctorAnalysis< FunctorPatternInterface::REDUCE , MDRangePolicy , FunctorType > Analysis ;
880 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTagFwd > ValueInit ;
882 typedef typename Analysis::pointer_type pointer_type ;
883 typedef typename Analysis::value_type value_type ;
884 typedef typename Analysis::reference_type reference_type ;
887 using iterate_type =
typename Kokkos::Impl::HostIterateTile< MDRangePolicy
894 const FunctorType m_functor ;
895 const MDRangePolicy m_mdr_policy ;
896 const Policy m_policy ;
897 const ReducerType m_reducer ;
898 const pointer_type m_result_ptr ;
902 exec( reference_type update )
const
904 const typename Policy::member_type e = m_policy.end();
905 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
906 iterate_type( m_mdr_policy, m_functor, update )( i );
915 const size_t pool_reduce_size =
916 Analysis::value_size( ReducerConditional::select(m_functor , m_reducer) );
917 const size_t team_reduce_size = 0 ;
918 const size_t team_shared_size = 0 ;
919 const size_t thread_local_size = 0 ;
921 serial_resize_thread_team_data( pool_reduce_size
924 , thread_local_size );
926 HostThreadTeamData & data = *serial_get_thread_team_data();
929 m_result_ptr ? m_result_ptr : pointer_type(data.pool_reduce_local());
931 reference_type update =
932 ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
934 this-> exec( update );
936 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , WorkTagFwd >::
937 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
940 template<
class HostViewType >
941 ParallelReduce(
const FunctorType & arg_functor ,
942 const MDRangePolicy & arg_policy ,
943 const HostViewType & arg_result_view ,
944 typename std::enable_if<
945 Kokkos::is_view< HostViewType >::value &&
946 !Kokkos::is_reducer_type<ReducerType>::value
947 ,
void*>::type = NULL)
948 : m_functor( arg_functor )
949 , m_mdr_policy( arg_policy )
950 , m_policy( Policy(0, m_mdr_policy.m_num_tiles).set_chunk_size(1) )
951 , m_reducer( InvalidType() )
952 , m_result_ptr( arg_result_view.data() )
954 static_assert( Kokkos::is_view< HostViewType >::value
955 ,
"Kokkos::Serial reduce result must be a View" );
957 static_assert( std::is_same< typename HostViewType::memory_space , HostSpace >::value
958 ,
"Kokkos::Serial reduce result must be a View in HostSpace" );
962 ParallelReduce(
const FunctorType & arg_functor
963 , MDRangePolicy arg_policy
964 ,
const ReducerType& reducer )
965 : m_functor( arg_functor )
966 , m_mdr_policy( arg_policy )
967 , m_policy( Policy(0, m_mdr_policy.m_num_tiles).set_chunk_size(1) )
968 , m_reducer( reducer )
969 , m_result_ptr( reducer.view().data() )
989 template<
class FunctorType ,
class ... Properties >
990 class ParallelFor< FunctorType
991 , Kokkos::TeamPolicy< Properties ... >
997 enum { TEAM_REDUCE_SIZE = 512 };
999 typedef TeamPolicyInternal< Kokkos::Serial , Properties ...> Policy ;
1000 typedef typename Policy::member_type Member ;
1002 const FunctorType m_functor ;
1003 const int m_league ;
1004 const int m_shared ;
1006 template<
class TagType >
1008 typename std::enable_if< std::is_same< TagType , void >::value >::type
1009 exec( HostThreadTeamData & data )
const
1011 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
1012 m_functor( Member(data,ileague,m_league) );
1016 template<
class TagType >
1018 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
1019 exec( HostThreadTeamData & data )
const
1022 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
1023 m_functor( t , Member(data,ileague,m_league) );
1030 void execute()
const
1032 const size_t pool_reduce_size = 0 ;
1033 const size_t team_reduce_size = TEAM_REDUCE_SIZE ;
1034 const size_t team_shared_size = m_shared ;
1035 const size_t thread_local_size = 0 ;
1037 serial_resize_thread_team_data( pool_reduce_size
1040 , thread_local_size );
1042 HostThreadTeamData & data = *serial_get_thread_team_data();
1044 this->
template exec< typename Policy::work_tag >( data );
1047 ParallelFor(
const FunctorType & arg_functor
1048 ,
const Policy & arg_policy )
1049 : m_functor( arg_functor )
1050 , m_league( arg_policy.league_size() )
1051 , m_shared( arg_policy.scratch_size(0) +
1052 arg_policy.scratch_size(1) +
1053 FunctorTeamShmemSize< FunctorType >::value( arg_functor , 1 ) )
1059 template<
class FunctorType ,
class ReducerType ,
class ... Properties >
1060 class ParallelReduce< FunctorType
1061 , Kokkos::TeamPolicy< Properties ... >
1068 enum { TEAM_REDUCE_SIZE = 512 };
1070 typedef TeamPolicyInternal< Kokkos::Serial, Properties ... > Policy ;
1072 typedef FunctorAnalysis< FunctorPatternInterface::REDUCE , Policy , FunctorType > Analysis ;
1074 typedef typename Policy::member_type Member ;
1075 typedef typename Policy::work_tag WorkTag ;
1077 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
1078 typedef typename ReducerConditional::type ReducerTypeFwd;
1079 typedef typename Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, WorkTag,
void>::type WorkTagFwd;
1081 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTagFwd > ValueInit ;
1083 typedef typename Analysis::pointer_type pointer_type ;
1084 typedef typename Analysis::reference_type reference_type ;
1086 const FunctorType m_functor ;
1087 const int m_league ;
1088 const ReducerType m_reducer ;
1089 pointer_type m_result_ptr ;
1090 const int m_shared ;
1092 template<
class TagType >
1094 typename std::enable_if< std::is_same< TagType , void >::value >::type
1095 exec( HostThreadTeamData & data , reference_type update )
const
1097 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
1098 m_functor( Member(data,ileague,m_league) , update );
1102 template<
class TagType >
1104 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
1105 exec( HostThreadTeamData & data , reference_type update )
const
1109 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
1110 m_functor( t , Member(data,ileague,m_league) , update );
1117 void execute()
const
1119 const size_t pool_reduce_size =
1120 Analysis::value_size( ReducerConditional::select(m_functor, m_reducer));
1122 const size_t team_reduce_size = TEAM_REDUCE_SIZE ;
1123 const size_t team_shared_size = m_shared ;
1124 const size_t thread_local_size = 0 ;
1126 serial_resize_thread_team_data( pool_reduce_size
1129 , thread_local_size );
1132 HostThreadTeamData & data = *serial_get_thread_team_data();
1135 m_result_ptr ? m_result_ptr : pointer_type(data.pool_reduce_local());
1137 reference_type update =
1138 ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
1140 this->
template exec< WorkTag >( data , update );
1142 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , WorkTagFwd >::
1143 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
1146 template<
class ViewType >
1147 ParallelReduce(
const FunctorType & arg_functor
1148 ,
const Policy & arg_policy
1149 ,
const ViewType & arg_result ,
1150 typename std::enable_if<
1151 Kokkos::is_view< ViewType >::value &&
1152 !Kokkos::is_reducer_type<ReducerType>::value
1153 ,
void*>::type = NULL)
1154 : m_functor( arg_functor )
1155 , m_league( arg_policy.league_size() )
1156 , m_reducer( InvalidType() )
1157 , m_result_ptr( arg_result.data() )
1158 , m_shared( arg_policy.scratch_size(0) +
1159 arg_policy.scratch_size(1) +
1160 FunctorTeamShmemSize< FunctorType >::value( m_functor , 1 ) )
1162 static_assert( Kokkos::is_view< ViewType >::value
1163 ,
"Reduction result on Kokkos::Serial must be a Kokkos::View" );
1165 static_assert( std::is_same<
typename ViewType::memory_space
1167 ,
"Reduction result on Kokkos::Serial must be a Kokkos::View in HostSpace" );
1171 ParallelReduce(
const FunctorType & arg_functor
1173 ,
const ReducerType& reducer )
1174 : m_functor( arg_functor )
1175 , m_league( arg_policy.league_size() )
1176 , m_reducer( reducer )
1177 , m_result_ptr( reducer.view().data() )
1178 , m_shared( arg_policy.scratch_size(0) +
1179 arg_policy.scratch_size(1) +
1180 FunctorTeamShmemSize< FunctorType >::value( arg_functor , 1 ) )
1195 namespace Kokkos {
namespace Experimental {
1198 class UniqueToken< Serial, UniqueTokenScope::Instance>
1201 using execution_space = Serial;
1202 using size_type = int;
1207 UniqueToken( execution_space
const& = execution_space() ) noexcept {}
1210 KOKKOS_INLINE_FUNCTION
1211 int size() const noexcept {
return 1; }
1214 KOKKOS_INLINE_FUNCTION
1215 int acquire() const noexcept {
return 0; }
1218 KOKKOS_INLINE_FUNCTION
1219 void release(
int ) const noexcept {}
1223 class UniqueToken< Serial, UniqueTokenScope::Global>
1226 using execution_space = Serial;
1227 using size_type = int;
1232 UniqueToken( execution_space
const& = execution_space() ) noexcept {}
1235 KOKKOS_INLINE_FUNCTION
1236 int size() const noexcept {
return 1; }
1239 KOKKOS_INLINE_FUNCTION
1240 int acquire() const noexcept {
return 0; }
1243 KOKKOS_INLINE_FUNCTION
1244 void release(
int ) const noexcept {}
1249 #include <impl/Kokkos_Serial_Task.hpp>
1251 #endif // defined( KOKKOS_ENABLE_SERIAL )
void print_configuration(std::ostream &, const bool detail=false)
Print "Bill of Materials".
Memory management for host memory.
Declaration of various MemoryLayout options.
Declaration of parallel operators.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.
Execution policy for work over a range of an integral type.