47 #ifndef KOKKOS_PARALLEL_HPP 48 #define KOKKOS_PARALLEL_HPP 51 #include <Kokkos_Core_fwd.hpp> 52 #include <Kokkos_View.hpp> 53 #include <Kokkos_ExecPolicy.hpp> 55 #if (KOKKOS_ENABLE_PROFILING) 56 #include <impl/Kokkos_Profiling_Interface.hpp> 60 #include <impl/Kokkos_Tags.hpp> 61 #include <impl/Kokkos_Traits.hpp> 62 #include <impl/Kokkos_FunctorAdapter.hpp> 64 #ifdef KOKKOS_HAVE_DEBUG 82 template<
class Functor
87 struct FunctorPolicyExecutionSpace {
88 typedef Kokkos::DefaultExecutionSpace execution_space ;
91 template<
class Functor ,
class Policy >
92 struct FunctorPolicyExecutionSpace
94 , typename enable_if_type< typename Functor::device_type >::type
95 , typename enable_if_type< typename Policy ::execution_space >::type
98 typedef typename Policy ::execution_space execution_space ;
101 template<
class Functor ,
class Policy >
102 struct FunctorPolicyExecutionSpace
104 , typename enable_if_type< typename Functor::execution_space >::type
105 , typename enable_if_type< typename Policy ::execution_space >::type
108 typedef typename Policy ::execution_space execution_space ;
111 template<
class Functor ,
class Policy ,
class EnableFunctor >
112 struct FunctorPolicyExecutionSpace
115 , typename enable_if_type< typename Policy::execution_space >::type
118 typedef typename Policy ::execution_space execution_space ;
121 template<
class Functor ,
class Policy ,
class EnablePolicy >
122 struct FunctorPolicyExecutionSpace
124 , typename enable_if_type< typename Functor::device_type >::type
128 typedef typename Functor::device_type execution_space ;
131 template<
class Functor ,
class Policy ,
class EnablePolicy >
132 struct FunctorPolicyExecutionSpace
134 , typename enable_if_type< typename Functor::execution_space >::type
138 typedef typename Functor::execution_space execution_space ;
170 template<
class ExecPolicy ,
class FunctorType >
173 ,
const FunctorType & functor
174 ,
const std::string& str =
"" 175 ,
typename Impl::enable_if< ! Impl::is_integral< ExecPolicy >::value >::type * = 0
178 #if (KOKKOS_ENABLE_PROFILING) 180 if(Kokkos::Profiling::profileLibraryLoaded()) {
181 Kokkos::Profiling::beginParallelFor(
"" == str ?
typeid(FunctorType).name() : str, 0, &kpID);
185 Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
187 Kokkos::Impl::shared_allocation_tracking_release_and_enable();
191 #if (KOKKOS_ENABLE_PROFILING) 192 if(Kokkos::Profiling::profileLibraryLoaded()) {
193 Kokkos::Profiling::endParallelFor(kpID);
198 template<
class FunctorType >
201 ,
const FunctorType & functor
202 ,
const std::string& str =
"" 206 Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
208 typedef RangePolicy< execution_space > policy ;
210 #if (KOKKOS_ENABLE_PROFILING) 212 if(Kokkos::Profiling::profileLibraryLoaded()) {
213 Kokkos::Profiling::beginParallelFor(
"" == str ?
typeid(FunctorType).name() : str, 0, &kpID);
217 Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
218 Impl::ParallelFor< FunctorType , policy > closure( functor , policy(0,work_count) );
219 Kokkos::Impl::shared_allocation_tracking_release_and_enable();
223 #if (KOKKOS_ENABLE_PROFILING) 224 if(Kokkos::Profiling::profileLibraryLoaded()) {
225 Kokkos::Profiling::endParallelFor(kpID);
230 template<
class ExecPolicy ,
class FunctorType >
233 ,
const ExecPolicy & policy
234 ,
const FunctorType & functor )
236 #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES 238 std::cout <<
"KOKKOS_DEBUG Start parallel_for kernel: " << str << std::endl;
243 #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES 245 std::cout <<
"KOKKOS_DEBUG End parallel_for kernel: " << str << std::endl;
252 #include <Kokkos_Parallel_Reduce.hpp> 412 template<
class ExecutionPolicy ,
class FunctorType >
414 void parallel_scan(
const ExecutionPolicy & policy
415 ,
const FunctorType & functor
416 ,
const std::string& str =
"" 417 ,
typename Impl::enable_if< ! Impl::is_integral< ExecutionPolicy >::value >::type * = 0
420 #if (KOKKOS_ENABLE_PROFILING) 422 if(Kokkos::Profiling::profileLibraryLoaded()) {
423 Kokkos::Profiling::beginParallelScan(
"" == str ?
typeid(FunctorType).name() : str, 0, &kpID);
427 Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
428 Impl::ParallelScan< FunctorType , ExecutionPolicy > closure( functor , policy );
429 Kokkos::Impl::shared_allocation_tracking_release_and_enable();
433 #if (KOKKOS_ENABLE_PROFILING) 434 if(Kokkos::Profiling::profileLibraryLoaded()) {
435 Kokkos::Profiling::endParallelScan(kpID);
441 template<
class FunctorType >
443 void parallel_scan(
const size_t work_count
444 ,
const FunctorType & functor
445 ,
const std::string& str =
"" )
448 Kokkos::Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
453 #if (KOKKOS_ENABLE_PROFILING) 455 if(Kokkos::Profiling::profileLibraryLoaded()) {
456 Kokkos::Profiling::beginParallelScan(
"" == str ?
typeid(FunctorType).name() : str, 0, &kpID);
460 Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
461 Impl::ParallelScan< FunctorType , policy > closure( functor , policy(0,work_count) );
462 Kokkos::Impl::shared_allocation_tracking_release_and_enable();
466 #if (KOKKOS_ENABLE_PROFILING) 467 if(Kokkos::Profiling::profileLibraryLoaded()) {
468 Kokkos::Profiling::endParallelScan(kpID);
474 template<
class ExecutionPolicy ,
class FunctorType >
476 void parallel_scan(
const std::string& str
477 ,
const ExecutionPolicy & policy
478 ,
const FunctorType & functor)
480 #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES 482 std::cout <<
"KOKKOS_DEBUG Start parallel_scan kernel: " << str << std::endl;
485 parallel_scan(policy,functor,str);
487 #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES 489 std::cout <<
"KOKKOS_DEBUG End parallel_scan kernel: " << str << std::endl;
502 template<
class FunctorType ,
class Enable =
void >
503 struct FunctorTeamShmemSize
505 KOKKOS_INLINE_FUNCTION
static size_t value(
const FunctorType & ,
int ) {
return 0 ; }
508 template<
class FunctorType >
509 struct FunctorTeamShmemSize< FunctorType , typename Impl::enable_if< 0 < sizeof( & FunctorType::team_shmem_size ) >::type >
511 static inline size_t value(
const FunctorType & f ,
int team_size ) {
return f.team_shmem_size( team_size ) ; }
514 template<
class FunctorType >
515 struct FunctorTeamShmemSize< FunctorType , typename Impl::enable_if< 0 < sizeof( & FunctorType::shmem_size ) >::type >
517 static inline size_t value(
const FunctorType & f ,
int team_size ) {
return f.shmem_size( team_size ) ; }
Implementation of the ParallelFor operator that has a partial specialization for the device...
void parallel_for(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename Impl::enable_if< ! Impl::is_integral< ExecPolicy >::value >::type *=0)
Execute functor in parallel according to the execution policy.
Execution policy for work over a range of an integral type.