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 fence() {}
124 static int concurrency() {
return 1;};
129 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
133 static void initialize(
unsigned threads_count = 1 ,
134 unsigned use_numa_count = 0 ,
135 unsigned use_cores_per_numa = 0 ,
136 bool allow_asynchronous_threadpool =
false);
138 static bool is_initialized();
145 inline static int thread_pool_size(
int = 0 ) {
return 1 ; }
146 KOKKOS_INLINE_FUNCTION
static int thread_pool_rank() {
return 0 ; }
150 KOKKOS_INLINE_FUNCTION
static unsigned hardware_thread_id() {
return thread_pool_rank(); }
151 inline static unsigned max_hardware_threads() {
return thread_pool_size(0); }
153 static void impl_initialize();
155 static bool impl_is_initialized();
158 static void impl_finalize();
162 inline static int impl_thread_pool_size(
int = 0 ) {
return 1 ; }
163 KOKKOS_INLINE_FUNCTION
static int impl_thread_pool_rank() {
return 0 ; }
167 KOKKOS_INLINE_FUNCTION
static unsigned impl_hardware_thread_id() {
return impl_thread_pool_rank(); }
168 inline static unsigned impl_max_hardware_threads() {
return impl_thread_pool_size(0); }
171 static const char* name();
184 struct MemorySpaceAccess
185 < Kokkos::Serial::memory_space
186 , Kokkos::Serial::scratch_memory_space
189 enum { assignable =
false };
190 enum { accessible =
true };
191 enum { deepcopy =
false };
195 struct VerifyExecutionCanAccessMemorySpace
196 < Kokkos::Serial::memory_space
197 , Kokkos::Serial::scratch_memory_space
200 enum { value =
true };
201 inline static void verify(
void ) { }
202 inline static void verify(
const void * ) { }
215 void serial_resize_thread_team_data(
size_t pool_reduce_bytes
216 ,
size_t team_reduce_bytes
217 ,
size_t team_shared_bytes
218 ,
size_t thread_local_bytes );
220 HostThreadTeamData * serial_get_thread_team_data();
234 template<
class ... Properties >
235 class TeamPolicyInternal< Kokkos::Serial , Properties ... >:
public PolicyTraits<Properties...>
239 size_t m_team_scratch_size[2] ;
240 size_t m_thread_scratch_size[2] ;
247 typedef TeamPolicyInternal execution_policy ;
249 typedef PolicyTraits<Properties ... > traits;
252 typedef Kokkos::Serial execution_space ;
254 TeamPolicyInternal& operator = (
const TeamPolicyInternal& p) {
255 m_league_size = p.m_league_size;
256 m_team_scratch_size[0] = p.m_team_scratch_size[0];
257 m_thread_scratch_size[0] = p.m_thread_scratch_size[0];
258 m_team_scratch_size[1] = p.m_team_scratch_size[1];
259 m_thread_scratch_size[1] = p.m_thread_scratch_size[1];
260 m_chunk_size = p.m_chunk_size;
265 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
266 template<
class FunctorType >
268 int team_size_max(
const FunctorType & ) {
return 1 ; }
270 template<
class FunctorType >
272 int team_size_recommended(
const FunctorType & ) {
return 1 ; }
274 template<
class FunctorType >
276 int team_size_recommended(
const FunctorType & ,
const int& ) {
return 1 ; }
279 template<
class FunctorType>
280 int team_size_max(
const FunctorType&,
const ParallelForTag& )
const {
return 1 ; }
281 template<
class FunctorType>
282 int team_size_max(
const FunctorType&,
const ParallelReduceTag& )
const {
return 1 ; }
283 template<
class FunctorType>
284 int team_size_recommended(
const FunctorType&,
const ParallelForTag& )
const {
return 1 ; }
285 template<
class FunctorType>
286 int team_size_recommended(
const FunctorType&,
const ParallelReduceTag& )
const {
return 1 ; }
290 inline int team_size()
const {
return 1 ; }
291 inline int league_size()
const {
return m_league_size ; }
292 inline size_t scratch_size(
const int& level,
int = 0)
const {
return m_team_scratch_size[level] + m_thread_scratch_size[level]; }
295 int vector_length_max()
299 int scratch_size_max(
int level)
305 TeamPolicyInternal( execution_space &
306 ,
int league_size_request
307 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
308 ,
int team_size_request
313 : m_team_scratch_size { 0 , 0 }
314 , m_thread_scratch_size { 0 , 0 }
315 , m_league_size( league_size_request )
316 , m_chunk_size ( 32 )
318 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
319 if(team_size_request > 1) Kokkos::abort(
"Kokkos::abort: Requested Team Size is too large!");
323 TeamPolicyInternal( execution_space &
324 ,
int league_size_request
325 ,
const Kokkos::AUTO_t &
327 : m_team_scratch_size { 0 , 0 }
328 , m_thread_scratch_size { 0 , 0 }
329 , m_league_size( league_size_request )
330 , m_chunk_size ( 32 )
333 TeamPolicyInternal(
int league_size_request
334 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
335 ,
int team_size_request
340 : m_team_scratch_size { 0 , 0 }
341 , m_thread_scratch_size { 0 , 0 }
342 , m_league_size( league_size_request )
343 , m_chunk_size ( 32 )
345 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
346 if(team_size_request > 1) Kokkos::abort(
"Kokkos::abort: Requested Team Size is too large!");
350 TeamPolicyInternal(
int league_size_request
351 ,
const Kokkos::AUTO_t &
353 : m_team_scratch_size { 0 , 0 }
354 , m_thread_scratch_size { 0 , 0 }
355 , m_league_size( league_size_request )
356 , m_chunk_size ( 32 )
359 inline int chunk_size()
const {
return m_chunk_size ; }
361 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
363 inline TeamPolicyInternal set_chunk_size(
typename traits::index_type chunk_size_)
const {
364 TeamPolicyInternal p = *
this;
365 p.m_chunk_size = chunk_size_;
370 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerTeamValue& per_team)
const {
371 TeamPolicyInternal p = *
this;
372 p.m_team_scratch_size[level] = per_team.value;
377 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerThreadValue& per_thread)
const {
378 TeamPolicyInternal p = *
this;
379 p.m_thread_scratch_size[level] = per_thread.value;
384 inline TeamPolicyInternal set_scratch_size(
const int& level,
const PerTeamValue& per_team,
const PerThreadValue& per_thread)
const {
385 TeamPolicyInternal p = *
this;
386 p.m_team_scratch_size[level] = per_team.value;
387 p.m_thread_scratch_size[level] = per_thread.value;
392 inline TeamPolicyInternal& set_chunk_size(
typename traits::index_type chunk_size_) {
393 m_chunk_size = chunk_size_;
398 inline TeamPolicyInternal& set_scratch_size(
const int& level,
const PerTeamValue& per_team) {
399 m_team_scratch_size[level] = per_team.value;
404 inline TeamPolicyInternal& set_scratch_size(
const int& level,
const PerThreadValue& per_thread) {
405 m_thread_scratch_size[level] = per_thread.value;
410 inline TeamPolicyInternal& set_scratch_size(
const int& level,
const PerTeamValue& per_team,
const PerThreadValue& per_thread) {
411 m_team_scratch_size[level] = per_team.value;
412 m_thread_scratch_size[level] = per_thread.value;
417 typedef Impl::HostThreadTeamMember< Kokkos::Serial > member_type ;
420 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
422 inline TeamPolicyInternal internal_set_chunk_size(
typename traits::index_type chunk_size_) {
423 m_chunk_size = chunk_size_;
428 inline TeamPolicyInternal internal_set_scratch_size(
const int& level,
const PerTeamValue& per_team) {
429 m_team_scratch_size[level] = per_team.value;
434 inline TeamPolicyInternal internal_set_scratch_size(
const int& level,
const PerThreadValue& per_thread) {
435 m_thread_scratch_size[level] = per_thread.value;
440 inline TeamPolicyInternal internal_set_scratch_size(
const int& level,
const PerTeamValue& per_team,
const PerThreadValue& per_thread) {
441 m_team_scratch_size[level] = per_team.value;
442 m_thread_scratch_size[level] = per_thread.value;
457 template<
class FunctorType ,
class ... Traits >
458 class ParallelFor< FunctorType ,
459 Kokkos::RangePolicy< Traits ... > ,
467 const FunctorType m_functor ;
468 const Policy m_policy ;
470 template<
class TagType >
471 typename std::enable_if< std::is_same< TagType , void >::value >::type
474 const typename Policy::member_type e = m_policy.end();
475 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
480 template<
class TagType >
481 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
485 const typename Policy::member_type e = m_policy.end();
486 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
495 { this->
template exec< typename Policy::work_tag >(); }
498 ParallelFor(
const FunctorType & arg_functor
499 ,
const Policy & arg_policy )
500 : m_functor( arg_functor )
501 , m_policy( arg_policy )
507 template<
class FunctorType ,
class ReducerType ,
class ... Traits >
508 class ParallelReduce< FunctorType
509 , Kokkos::RangePolicy< Traits ... >
517 typedef typename Policy::work_tag WorkTag ;
519 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
521 typedef typename ReducerConditional::type ReducerTypeFwd;
522 typedef typename Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, WorkTag,
void>::type WorkTagFwd;
524 typedef FunctorAnalysis< FunctorPatternInterface::REDUCE , Policy , FunctorType > Analysis ;
526 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTagFwd > ValueInit ;
528 typedef typename Analysis::pointer_type pointer_type ;
529 typedef typename Analysis::reference_type reference_type ;
531 const FunctorType m_functor ;
532 const Policy m_policy ;
533 const ReducerType m_reducer ;
534 const pointer_type m_result_ptr ;
536 template<
class TagType >
538 typename std::enable_if< std::is_same< TagType , void >::value >::type
539 exec( reference_type update )
const
541 const typename Policy::member_type e = m_policy.end();
542 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
543 m_functor( i , update );
547 template<
class TagType >
549 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
550 exec( reference_type update )
const
554 const typename Policy::member_type e = m_policy.end();
555 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
556 m_functor( t , i , update );
565 const size_t pool_reduce_size =
566 Analysis::value_size( ReducerConditional::select(m_functor , m_reducer) );
567 const size_t team_reduce_size = 0 ;
568 const size_t team_shared_size = 0 ;
569 const size_t thread_local_size = 0 ;
571 serial_resize_thread_team_data( pool_reduce_size
574 , thread_local_size );
576 HostThreadTeamData & data = *serial_get_thread_team_data();
579 m_result_ptr ? m_result_ptr : pointer_type(data.pool_reduce_local());
581 reference_type update =
582 ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
584 this->
template exec< WorkTag >( update );
586 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , WorkTagFwd >::
587 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
590 template<
class HostViewType >
591 ParallelReduce(
const FunctorType & arg_functor ,
592 const Policy & arg_policy ,
593 const HostViewType & arg_result_view ,
594 typename std::enable_if<
595 Kokkos::is_view< HostViewType >::value &&
596 !Kokkos::is_reducer_type<ReducerType>::value
597 ,
void*>::type = NULL)
598 : m_functor( arg_functor )
599 , m_policy( arg_policy )
600 , m_reducer( InvalidType() )
601 , m_result_ptr( arg_result_view.data() )
603 static_assert( Kokkos::is_view< HostViewType >::value
604 ,
"Kokkos::Serial reduce result must be a View" );
606 static_assert( std::is_same< typename HostViewType::memory_space , HostSpace >::value
607 ,
"Kokkos::Serial reduce result must be a View in HostSpace" );
611 ParallelReduce(
const FunctorType & arg_functor
613 ,
const ReducerType& reducer )
614 : m_functor( arg_functor )
615 , m_policy( arg_policy )
616 , m_reducer( reducer )
617 , m_result_ptr( reducer.view().data() )
628 template<
class FunctorType ,
class ... Traits >
629 class ParallelScan< FunctorType
630 , Kokkos::RangePolicy< Traits ... >
637 typedef typename Policy::work_tag WorkTag ;
639 typedef FunctorAnalysis< FunctorPatternInterface::SCAN , Policy , FunctorType > Analysis ;
641 typedef Kokkos::Impl::FunctorValueInit< FunctorType , WorkTag > ValueInit ;
643 typedef typename Analysis::pointer_type pointer_type ;
644 typedef typename Analysis::reference_type reference_type ;
646 const FunctorType m_functor ;
647 const Policy m_policy ;
649 template<
class TagType >
651 typename std::enable_if< std::is_same< TagType , void >::value >::type
652 exec( reference_type update )
const
654 const typename Policy::member_type e = m_policy.end();
655 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
656 m_functor( i , update ,
true );
660 template<
class TagType >
662 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
663 exec( reference_type update )
const
666 const typename Policy::member_type e = m_policy.end();
667 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
668 m_functor( t , i , update ,
true );
677 const size_t pool_reduce_size = Analysis::value_size( m_functor );
678 const size_t team_reduce_size = 0 ;
679 const size_t team_shared_size = 0 ;
680 const size_t thread_local_size = 0 ;
682 serial_resize_thread_team_data( pool_reduce_size
685 , thread_local_size );
687 HostThreadTeamData & data = *serial_get_thread_team_data();
689 reference_type update =
690 ValueInit::init( m_functor , pointer_type(data.pool_reduce_local()) );
692 this->
template exec< WorkTag >( update );
696 ParallelScan(
const FunctorType & arg_functor
697 ,
const Policy & arg_policy
699 : m_functor( arg_functor )
700 , m_policy( arg_policy )
705 template<
class FunctorType ,
class ReturnType,
class ... Traits >
706 class ParallelScanWithTotal< FunctorType
707 , Kokkos::RangePolicy< Traits ... >
715 typedef typename Policy::work_tag WorkTag ;
717 typedef FunctorAnalysis< FunctorPatternInterface::SCAN , Policy , FunctorType > Analysis ;
719 typedef Kokkos::Impl::FunctorValueInit< FunctorType , WorkTag > ValueInit ;
721 typedef typename Analysis::pointer_type pointer_type ;
722 typedef typename Analysis::reference_type reference_type ;
724 const FunctorType m_functor ;
725 const Policy m_policy ;
728 template<
class TagType >
730 typename std::enable_if< std::is_same< TagType , void >::value >::type
731 exec( reference_type update )
const
733 const typename Policy::member_type e = m_policy.end();
734 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
735 m_functor( i , update ,
true );
739 template<
class TagType >
741 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
742 exec( reference_type update )
const
745 const typename Policy::member_type e = m_policy.end();
746 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
747 m_functor( t , i , update ,
true );
756 const size_t pool_reduce_size = Analysis::value_size( m_functor );
757 const size_t team_reduce_size = 0 ;
758 const size_t team_shared_size = 0 ;
759 const size_t thread_local_size = 0 ;
761 serial_resize_thread_team_data( pool_reduce_size
764 , thread_local_size );
766 HostThreadTeamData & data = *serial_get_thread_team_data();
768 reference_type update =
769 ValueInit::init( m_functor , pointer_type(data.pool_reduce_local()) );
771 this->
template exec< WorkTag >( update );
773 m_returnvalue = update;
777 ParallelScanWithTotal(
const FunctorType & arg_functor
778 ,
const Policy & arg_policy
781 : m_functor( arg_functor )
782 , m_policy( arg_policy )
783 , m_returnvalue( arg_returnvalue )
798 template<
class FunctorType ,
class ... Traits >
799 class ParallelFor< FunctorType ,
800 Kokkos::MDRangePolicy< Traits ... > ,
806 typedef Kokkos::MDRangePolicy< Traits ... > MDRangePolicy ;
807 typedef typename MDRangePolicy::impl_range_policy Policy ;
809 typedef typename Kokkos::Impl::HostIterateTile< MDRangePolicy, FunctorType, typename MDRangePolicy::work_tag, void > iterate_type;
811 const FunctorType m_functor ;
812 const MDRangePolicy m_mdr_policy ;
813 const Policy m_policy ;
818 const typename Policy::member_type e = m_policy.end();
819 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
820 iterate_type( m_mdr_policy, m_functor )( i );
831 ParallelFor(
const FunctorType & arg_functor
832 ,
const MDRangePolicy & arg_policy )
833 : m_functor( arg_functor )
834 , m_mdr_policy( arg_policy )
835 , m_policy( Policy(0, m_mdr_policy.m_num_tiles).set_chunk_size(1) )
840 template<
class FunctorType ,
class ReducerType ,
class ... Traits >
841 class ParallelReduce< FunctorType
842 , Kokkos::MDRangePolicy< Traits ... >
849 typedef Kokkos::MDRangePolicy< Traits ... > MDRangePolicy ;
850 typedef typename MDRangePolicy::impl_range_policy Policy ;
852 typedef typename MDRangePolicy::work_tag WorkTag ;
854 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
855 typedef typename ReducerConditional::type ReducerTypeFwd;
856 typedef typename Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, WorkTag,
void>::type WorkTagFwd;
858 typedef FunctorAnalysis< FunctorPatternInterface::REDUCE , MDRangePolicy , FunctorType > Analysis ;
860 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTagFwd > ValueInit ;
862 typedef typename Analysis::pointer_type pointer_type ;
863 typedef typename Analysis::value_type value_type ;
864 typedef typename Analysis::reference_type reference_type ;
867 using iterate_type =
typename Kokkos::Impl::HostIterateTile< MDRangePolicy
874 const FunctorType m_functor ;
875 const MDRangePolicy m_mdr_policy ;
876 const Policy m_policy ;
877 const ReducerType m_reducer ;
878 const pointer_type m_result_ptr ;
882 exec( reference_type update )
const
884 const typename Policy::member_type e = m_policy.end();
885 for (
typename Policy::member_type i = m_policy.begin() ; i < e ; ++i ) {
886 iterate_type( m_mdr_policy, m_functor, update )( i );
895 const size_t pool_reduce_size =
896 Analysis::value_size( ReducerConditional::select(m_functor , m_reducer) );
897 const size_t team_reduce_size = 0 ;
898 const size_t team_shared_size = 0 ;
899 const size_t thread_local_size = 0 ;
901 serial_resize_thread_team_data( pool_reduce_size
904 , thread_local_size );
906 HostThreadTeamData & data = *serial_get_thread_team_data();
909 m_result_ptr ? m_result_ptr : pointer_type(data.pool_reduce_local());
911 reference_type update =
912 ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
914 this-> exec( update );
916 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , WorkTagFwd >::
917 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
920 template<
class HostViewType >
921 ParallelReduce(
const FunctorType & arg_functor ,
922 const MDRangePolicy & arg_policy ,
923 const HostViewType & arg_result_view ,
924 typename std::enable_if<
925 Kokkos::is_view< HostViewType >::value &&
926 !Kokkos::is_reducer_type<ReducerType>::value
927 ,
void*>::type = NULL)
928 : m_functor( arg_functor )
929 , m_mdr_policy( arg_policy )
930 , m_policy( Policy(0, m_mdr_policy.m_num_tiles).set_chunk_size(1) )
931 , m_reducer( InvalidType() )
932 , m_result_ptr( arg_result_view.data() )
934 static_assert( Kokkos::is_view< HostViewType >::value
935 ,
"Kokkos::Serial reduce result must be a View" );
937 static_assert( std::is_same< typename HostViewType::memory_space , HostSpace >::value
938 ,
"Kokkos::Serial reduce result must be a View in HostSpace" );
942 ParallelReduce(
const FunctorType & arg_functor
943 , MDRangePolicy arg_policy
944 ,
const ReducerType& reducer )
945 : m_functor( arg_functor )
946 , m_mdr_policy( arg_policy )
947 , m_policy( Policy(0, m_mdr_policy.m_num_tiles).set_chunk_size(1) )
948 , m_reducer( reducer )
949 , m_result_ptr( reducer.view().data() )
969 template<
class FunctorType ,
class ... Properties >
970 class ParallelFor< FunctorType
971 , Kokkos::TeamPolicy< Properties ... >
977 enum { TEAM_REDUCE_SIZE = 512 };
979 typedef TeamPolicyInternal< Kokkos::Serial , Properties ...> Policy ;
980 typedef typename Policy::member_type Member ;
982 const FunctorType m_functor ;
986 template<
class TagType >
988 typename std::enable_if< std::is_same< TagType , void >::value >::type
989 exec( HostThreadTeamData & data )
const
991 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
992 m_functor( Member(data,ileague,m_league) );
996 template<
class TagType >
998 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
999 exec( HostThreadTeamData & data )
const
1002 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
1003 m_functor( t , Member(data,ileague,m_league) );
1010 void execute()
const
1012 const size_t pool_reduce_size = 0 ;
1013 const size_t team_reduce_size = TEAM_REDUCE_SIZE ;
1014 const size_t team_shared_size = m_shared ;
1015 const size_t thread_local_size = 0 ;
1017 serial_resize_thread_team_data( pool_reduce_size
1020 , thread_local_size );
1022 HostThreadTeamData & data = *serial_get_thread_team_data();
1024 this->
template exec< typename Policy::work_tag >( data );
1027 ParallelFor(
const FunctorType & arg_functor
1028 ,
const Policy & arg_policy )
1029 : m_functor( arg_functor )
1030 , m_league( arg_policy.league_size() )
1031 , m_shared( arg_policy.scratch_size(0) +
1032 arg_policy.scratch_size(1) +
1033 FunctorTeamShmemSize< FunctorType >::value( arg_functor , 1 ) )
1039 template<
class FunctorType ,
class ReducerType ,
class ... Properties >
1040 class ParallelReduce< FunctorType
1041 , Kokkos::TeamPolicy< Properties ... >
1048 enum { TEAM_REDUCE_SIZE = 512 };
1050 typedef TeamPolicyInternal< Kokkos::Serial, Properties ... > Policy ;
1052 typedef FunctorAnalysis< FunctorPatternInterface::REDUCE , Policy , FunctorType > Analysis ;
1054 typedef typename Policy::member_type Member ;
1055 typedef typename Policy::work_tag WorkTag ;
1057 typedef Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, FunctorType, ReducerType> ReducerConditional;
1058 typedef typename ReducerConditional::type ReducerTypeFwd;
1059 typedef typename Kokkos::Impl::if_c< std::is_same<InvalidType,ReducerType>::value, WorkTag,
void>::type WorkTagFwd;
1061 typedef Kokkos::Impl::FunctorValueInit< ReducerTypeFwd , WorkTagFwd > ValueInit ;
1063 typedef typename Analysis::pointer_type pointer_type ;
1064 typedef typename Analysis::reference_type reference_type ;
1066 const FunctorType m_functor ;
1067 const int m_league ;
1068 const ReducerType m_reducer ;
1069 pointer_type m_result_ptr ;
1070 const int m_shared ;
1072 template<
class TagType >
1074 typename std::enable_if< std::is_same< TagType , void >::value >::type
1075 exec( HostThreadTeamData & data , reference_type update )
const
1077 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
1078 m_functor( Member(data,ileague,m_league) , update );
1082 template<
class TagType >
1084 typename std::enable_if< ! std::is_same< TagType , void >::value >::type
1085 exec( HostThreadTeamData & data , reference_type update )
const
1089 for (
int ileague = 0 ; ileague < m_league ; ++ileague ) {
1090 m_functor( t , Member(data,ileague,m_league) , update );
1097 void execute()
const
1099 const size_t pool_reduce_size =
1100 Analysis::value_size( ReducerConditional::select(m_functor, m_reducer));
1102 const size_t team_reduce_size = TEAM_REDUCE_SIZE ;
1103 const size_t team_shared_size = m_shared ;
1104 const size_t thread_local_size = 0 ;
1106 serial_resize_thread_team_data( pool_reduce_size
1109 , thread_local_size );
1112 HostThreadTeamData & data = *serial_get_thread_team_data();
1115 m_result_ptr ? m_result_ptr : pointer_type(data.pool_reduce_local());
1117 reference_type update =
1118 ValueInit::init( ReducerConditional::select(m_functor , m_reducer) , ptr );
1120 this->
template exec< WorkTag >( data , update );
1122 Kokkos::Impl::FunctorFinal< ReducerTypeFwd , WorkTagFwd >::
1123 final( ReducerConditional::select(m_functor , m_reducer) , ptr );
1126 template<
class ViewType >
1127 ParallelReduce(
const FunctorType & arg_functor
1128 ,
const Policy & arg_policy
1129 ,
const ViewType & arg_result ,
1130 typename std::enable_if<
1131 Kokkos::is_view< ViewType >::value &&
1132 !Kokkos::is_reducer_type<ReducerType>::value
1133 ,
void*>::type = NULL)
1134 : m_functor( arg_functor )
1135 , m_league( arg_policy.league_size() )
1136 , m_reducer( InvalidType() )
1137 , m_result_ptr( arg_result.data() )
1138 , m_shared( arg_policy.scratch_size(0) +
1139 arg_policy.scratch_size(1) +
1140 FunctorTeamShmemSize< FunctorType >::value( m_functor , 1 ) )
1142 static_assert( Kokkos::is_view< ViewType >::value
1143 ,
"Reduction result on Kokkos::Serial must be a Kokkos::View" );
1145 static_assert( std::is_same<
typename ViewType::memory_space
1147 ,
"Reduction result on Kokkos::Serial must be a Kokkos::View in HostSpace" );
1151 ParallelReduce(
const FunctorType & arg_functor
1153 ,
const ReducerType& reducer )
1154 : m_functor( arg_functor )
1155 , m_league( arg_policy.league_size() )
1156 , m_reducer( reducer )
1157 , m_result_ptr( reducer.view().data() )
1158 , m_shared( arg_policy.scratch_size(0) +
1159 arg_policy.scratch_size(1) +
1160 FunctorTeamShmemSize< FunctorType >::value( arg_functor , 1 ) )
1175 namespace Kokkos {
namespace Experimental {
1178 class UniqueToken< Serial, UniqueTokenScope::Instance>
1181 using execution_space = Serial;
1182 using size_type = int;
1187 UniqueToken( execution_space
const& = execution_space() ) noexcept {}
1190 KOKKOS_INLINE_FUNCTION
1191 int size() const noexcept {
return 1; }
1194 KOKKOS_INLINE_FUNCTION
1195 int acquire() const noexcept {
return 0; }
1198 KOKKOS_INLINE_FUNCTION
1199 void release(
int ) const noexcept {}
1203 class UniqueToken< Serial, UniqueTokenScope::Global>
1206 using execution_space = Serial;
1207 using size_type = int;
1212 UniqueToken( execution_space
const& = execution_space() ) noexcept {}
1215 KOKKOS_INLINE_FUNCTION
1216 int size() const noexcept {
return 1; }
1219 KOKKOS_INLINE_FUNCTION
1220 int acquire() const noexcept {
return 0; }
1223 KOKKOS_INLINE_FUNCTION
1224 void release(
int ) const noexcept {}
1229 #include <impl/Kokkos_Serial_Task.hpp>
1231 #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.