Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_ExecPolicy.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_EXECPOLICY_HPP
45 #define KOKKOS_EXECPOLICY_HPP
46 
47 #include <Kokkos_Core_fwd.hpp>
48 #include <impl/Kokkos_Traits.hpp>
49 #include <impl/Kokkos_StaticAssert.hpp>
50 #include <impl/Kokkos_Error.hpp>
51 #include <impl/Kokkos_Tags.hpp>
52 #include <impl/Kokkos_AnalyzePolicy.hpp>
53 #include <Kokkos_Concepts.hpp>
54 #include <iostream>
55 
56 //----------------------------------------------------------------------------
57 
58 namespace Kokkos {
59 
60 struct ParallelForTag {};
61 struct ParallelScanTag {};
62 struct ParallelReduceTag {};
63 
64 struct ChunkSize {
65  int value;
66  ChunkSize(int value_):value(value_) {}
67 };
68 
90 template<class ... Properties>
92  : public Impl::PolicyTraits<Properties ... >
93 {
94 private:
95  typedef Impl::PolicyTraits<Properties ... > traits;
96 
97  typename traits::execution_space m_space ;
98  typename traits::index_type m_begin ;
99  typename traits::index_type m_end ;
100  typename traits::index_type m_granularity ;
101  typename traits::index_type m_granularity_mask ;
102 
103 public:
106  typedef typename traits::index_type member_type ;
107  typedef typename traits::index_type index_type;
108 
109  KOKKOS_INLINE_FUNCTION const typename traits::execution_space & space() const { return m_space ; }
110  KOKKOS_INLINE_FUNCTION member_type begin() const { return m_begin ; }
111  KOKKOS_INLINE_FUNCTION member_type end() const { return m_end ; }
112 
113  //TODO: find a better workaround for Clangs weird instantiation order
114  // This thing is here because of an instantiation error, where the RangePolicy is inserted into FunctorValue Traits, which
115  // tries decltype on the operator. It tries to do this even though the first argument of parallel for clearly doesn't match.
116  void operator()(const int&) const {}
117 
118  RangePolicy(const RangePolicy&) = default;
119  RangePolicy(RangePolicy&&) = default;
120 
121  inline RangePolicy() : m_space(), m_begin(0), m_end(0) {}
122 
124  inline
125  RangePolicy( const typename traits::execution_space & work_space
126  , const member_type work_begin
127  , const member_type work_end
128  )
129  : m_space( work_space )
130  , m_begin( work_begin < work_end ? work_begin : 0 )
131  , m_end( work_begin < work_end ? work_end : 0 )
132  , m_granularity(0)
133  , m_granularity_mask(0)
134  {
135  set_auto_chunk_size();
136  }
137 
139  inline
140  RangePolicy( const member_type work_begin
141  , const member_type work_end
142  )
143  : RangePolicy( typename traits::execution_space()
144  , work_begin , work_end )
145  {
146  set_auto_chunk_size();
147  }
148 
150  template<class ... Args>
151  inline
152  RangePolicy( const typename traits::execution_space & work_space
153  , const member_type work_begin
154  , const member_type work_end
155  , Args ... args
156  )
157  : m_space( work_space )
158  , m_begin( work_begin < work_end ? work_begin : 0 )
159  , m_end( work_begin < work_end ? work_end : 0 )
160  , m_granularity(0)
161  , m_granularity_mask(0)
162  {
163  set_auto_chunk_size();
164  set(args...);
165  }
166 
168  template<class ... Args>
169  inline
170  RangePolicy( const member_type work_begin
171  , const member_type work_end
172  , Args ... args
173  )
174  : RangePolicy( typename traits::execution_space()
175  , work_begin , work_end )
176  {
177  set_auto_chunk_size();
178  set(args...);
179  }
180 
181 private:
182  inline void set() {}
183 
184 public:
185  template<class ... Args>
186  inline void set(Args ...) {
187  static_assert( 0 == sizeof...(Args), "Kokkos::RangePolicy: unhandled constructor arguments encountered.");
188  }
189 
190  template<class ... Args>
191  inline void set(const ChunkSize& chunksize, Args ... args) {
192  m_granularity = chunksize.value;
193  m_granularity_mask = m_granularity - 1;
194  }
195 
196 public:
198  inline member_type chunk_size() const {
199  return m_granularity;
200  }
201 
203  inline RangePolicy set_chunk_size(int chunk_size_) const {
204  RangePolicy p = *this;
205  p.m_granularity = chunk_size_;
206  p.m_granularity_mask = p.m_granularity - 1;
207  return p;
208  }
209 
210 private:
212  inline void set_auto_chunk_size() {
213 
214  typename traits::index_type concurrency = traits::execution_space::concurrency();
215  if( concurrency==0 ) concurrency=1;
216 
217  if(m_granularity > 0) {
218  if(!Impl::is_integral_power_of_two( m_granularity ))
219  Kokkos::abort("RangePolicy blocking granularity must be power of two" );
220  }
221 
222  member_type new_chunk_size = 1;
223  while(new_chunk_size*100*concurrency < m_end-m_begin)
224  new_chunk_size *= 2;
225  if(new_chunk_size < 128) {
226  new_chunk_size = 1;
227  while( (new_chunk_size*40*concurrency < m_end-m_begin ) && (new_chunk_size<128) )
228  new_chunk_size*=2;
229  }
230  m_granularity = new_chunk_size;
231  m_granularity_mask = m_granularity - 1;
232  }
233 
234 public:
239  struct WorkRange {
240  typedef typename RangePolicy::work_tag work_tag ;
241  typedef typename RangePolicy::member_type member_type ;
242 
243  KOKKOS_INLINE_FUNCTION member_type begin() const { return m_begin ; }
244  KOKKOS_INLINE_FUNCTION member_type end() const { return m_end ; }
245 
250  KOKKOS_INLINE_FUNCTION
251  WorkRange( const RangePolicy & range
252  , const int part_rank
253  , const int part_size
254  )
255  : m_begin(0), m_end(0)
256  {
257  if ( part_size ) {
258 
259  // Split evenly among partitions, then round up to the granularity.
260  const member_type work_part =
261  ( ( ( ( range.end() - range.begin() ) + ( part_size - 1 ) ) / part_size )
262  + range.m_granularity_mask ) & ~member_type(range.m_granularity_mask);
263 
264  m_begin = range.begin() + work_part * part_rank ;
265  m_end = m_begin + work_part ;
266 
267  if ( range.end() < m_begin ) m_begin = range.end() ;
268  if ( range.end() < m_end ) m_end = range.end() ;
269  }
270  }
271 
272  private:
273  member_type m_begin ;
274  member_type m_end ;
275  WorkRange();
276  WorkRange & operator = ( const WorkRange & );
277  };
278 };
279 
280 } // namespace Kokkos
281 
282 //----------------------------------------------------------------------------
283 //----------------------------------------------------------------------------
284 
285 namespace Kokkos {
286 
287 namespace Impl {
288 
289 template< class ExecSpace, class ... Properties>
290 class TeamPolicyInternal: public Impl::PolicyTraits<Properties ... > {
291 private:
292  typedef Impl::PolicyTraits<Properties ... > traits;
293 
294 public:
295 
296  typedef typename traits::index_type index_type;
297 
298  //----------------------------------------
309  template< class FunctorType >
310  static int team_size_max( const FunctorType & );
311 
322  template< class FunctorType >
323  static int team_size_recommended( const FunctorType & );
324 
325  template< class FunctorType >
326  static int team_size_recommended( const FunctorType & , const int&);
327 
328  template<class FunctorType>
329  int team_size_recommended( const FunctorType & functor , const int vector_length);
330 
331  //----------------------------------------
333  TeamPolicyInternal( const typename traits::execution_space & , int league_size_request , int team_size_request , int vector_length_request = 1 );
334 
335  TeamPolicyInternal( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 );
336 
338  TeamPolicyInternal( int league_size_request , int team_size_request , int vector_length_request = 1 );
339 
340  TeamPolicyInternal( int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 );
341 
342 /* TeamPolicyInternal( int league_size_request , int team_size_request );
343 
344  TeamPolicyInternal( int league_size_request , const Kokkos::AUTO_t & );*/
345 
351  KOKKOS_INLINE_FUNCTION int league_size() const ;
352 
358  KOKKOS_INLINE_FUNCTION int team_size() const ;
359 
360  inline typename traits::index_type chunk_size() const ;
361 
362 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
363  inline TeamPolicyInternal set_chunk_size(int chunk_size) const ;
364 #else
365  inline TeamPolicyInternal& set_chunk_size(int chunk_size);
366 #endif
367 
371  struct member_type {
372 
374  KOKKOS_INLINE_FUNCTION
375  typename traits::execution_space::scratch_memory_space team_shmem() const ;
376 
378  KOKKOS_INLINE_FUNCTION int league_rank() const ;
379 
381  KOKKOS_INLINE_FUNCTION int league_size() const ;
382 
384  KOKKOS_INLINE_FUNCTION int team_rank() const ;
385 
387  KOKKOS_INLINE_FUNCTION int team_size() const ;
388 
390  KOKKOS_INLINE_FUNCTION void team_barrier() const ;
391 
393  template< class JoinOp >
394  KOKKOS_INLINE_FUNCTION
395  typename JoinOp::value_type team_reduce( const typename JoinOp::value_type
396  , const JoinOp & ) const ;
397 
403  template< typename Type >
404  KOKKOS_INLINE_FUNCTION Type team_scan( const Type & value ) const ;
405 
415  template< typename Type >
416  KOKKOS_INLINE_FUNCTION Type team_scan( const Type & value , Type * const global_accum ) const ;
417  };
418 };
419 
420 
421  struct PerTeamValue {
422  int value;
423  PerTeamValue(int arg);
424  };
425 
426  struct PerThreadValue {
427  int value;
428  PerThreadValue(int arg);
429  };
430 
431  template<class iType, class ... Args>
432  struct ExtractVectorLength {
433  static inline iType value(typename std::enable_if<std::is_integral<iType>::value,iType>::type val, Args...) {
434  return val;
435  }
436  static inline typename std::enable_if<!std::is_integral<iType>::value,int>::type value(typename std::enable_if<!std::is_integral<iType>::value,iType>::type, Args...) {
437  return 1;
438  }
439  };
440 
441  template<class iType, class ... Args>
442  inline typename std::enable_if<std::is_integral<iType>::value,iType>::type extract_vector_length(iType val, Args...) {
443  return val;
444  }
445 
446  template<class iType, class ... Args>
447  inline typename std::enable_if<!std::is_integral<iType>::value,int>::type extract_vector_length(iType, Args...) {
448  return 1;
449  }
450 
451 }
452 
453 Impl::PerTeamValue PerTeam(const int& arg);
454 Impl::PerThreadValue PerThread(const int& arg);
455 
456 struct ScratchRequest {
457  int level;
458 
459  int per_team;
460  int per_thread;
461 
462  inline
463  ScratchRequest(const int& level_, const Impl::PerTeamValue& team_value) {
464  level = level_;
465  per_team = team_value.value;
466  per_thread = 0;
467  }
468 
469  inline
470  ScratchRequest(const int& level_, const Impl::PerThreadValue& thread_value) {
471  level = level_;
472  per_team = 0;
473  per_thread = thread_value.value;;
474  }
475 
476  inline
477  ScratchRequest(const int& level_, const Impl::PerTeamValue& team_value, const Impl::PerThreadValue& thread_value) {
478  level = level_;
479  per_team = team_value.value;
480  per_thread = thread_value.value;;
481  }
482 
483  inline
484  ScratchRequest(const int& level_, const Impl::PerThreadValue& thread_value, const Impl::PerTeamValue& team_value) {
485  level = level_;
486  per_team = team_value.value;
487  per_thread = thread_value.value;;
488  }
489 
490 };
491 
492 
517 template< class ... Properties>
518 class TeamPolicy: public
519  Impl::TeamPolicyInternal<
520  typename Impl::PolicyTraits<Properties ... >::execution_space,
521  Properties ...> {
522  typedef Impl::TeamPolicyInternal<
523  typename Impl::PolicyTraits<Properties ... >::execution_space,
524  Properties ...> internal_policy;
525 
526  typedef Impl::PolicyTraits<Properties ... > traits;
527 
528 public:
530 
531  TeamPolicy& operator = (const TeamPolicy&) = default;
532 
534  TeamPolicy( const typename traits::execution_space & , int league_size_request , int team_size_request , int vector_length_request = 1 )
535  : internal_policy(typename traits::execution_space(),league_size_request,team_size_request, vector_length_request) {first_arg = false;}
536 
537  TeamPolicy( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 )
538  : internal_policy(typename traits::execution_space(),league_size_request,Kokkos::AUTO(), vector_length_request) {first_arg = false;}
539 
541  TeamPolicy( int league_size_request , int team_size_request , int vector_length_request = 1 )
542  : internal_policy(league_size_request,team_size_request, vector_length_request) {first_arg = false;}
543 
544  TeamPolicy( int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 )
545  : internal_policy(league_size_request,Kokkos::AUTO(), vector_length_request) {first_arg = false;}
546 
547 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
548 
549  template<class ... Args>
550  TeamPolicy( const typename traits::execution_space & , int league_size_request , int team_size_request , int vector_length_request,
551  Args ... args)
552  : internal_policy(typename traits::execution_space(),league_size_request,team_size_request, vector_length_request) {
553  first_arg = false;
554  set(args...);
555  }
556 
557  template<class ... Args>
558  TeamPolicy( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & , int vector_length_request ,
559  Args ... args)
560  : internal_policy(typename traits::execution_space(),league_size_request,Kokkos::AUTO(), vector_length_request) {
561  first_arg = false;
562  set(args...);
563  }
564 
566  template<class ... Args>
567  TeamPolicy( int league_size_request , int team_size_request , int vector_length_request ,
568  Args ... args)
569  : internal_policy(league_size_request,team_size_request, vector_length_request) {
570  first_arg = false;
571  set(args...);
572  }
573 
574  template<class ... Args>
575  TeamPolicy( int league_size_request , const Kokkos::AUTO_t & , int vector_length_request ,
576  Args ... args)
577  : internal_policy(league_size_request,Kokkos::AUTO(), vector_length_request) {
578  first_arg = false;
579  set(args...);
580  }
581 
583  template<class ... Args>
584  TeamPolicy( const typename traits::execution_space & , int league_size_request , int team_size_request ,
585  Args ... args)
586  : internal_policy(typename traits::execution_space(),league_size_request,team_size_request,
587  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
588  first_arg = true;
589  set(args...);
590  }
591 
592  template<class ... Args>
593  TeamPolicy( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & ,
594  Args ... args)
595  : internal_policy(typename traits::execution_space(),league_size_request,Kokkos::AUTO(),
596  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
597  first_arg = true;
598  set(args...);
599  }
600 
602  template<class ... Args>
603  TeamPolicy( int league_size_request , int team_size_request ,
604  Args ... args)
605  : internal_policy(league_size_request,team_size_request,
606  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
607  first_arg = true;
608  set(args...);
609  }
610 
611  template<class ... Args>
612  TeamPolicy( int league_size_request , const Kokkos::AUTO_t & ,
613  Args ... args)
614  : internal_policy(league_size_request,Kokkos::AUTO(),
615  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
616  first_arg = true;
617  set(args...);
618  }
619 #endif
620 
621 private:
622  bool first_arg;
623  TeamPolicy(const internal_policy& p):internal_policy(p) {first_arg = false;}
624 
625 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
626  inline void set() {}
627 #endif
628 
629 public:
630 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
631  template<class ... Args>
632  inline void set(Args ...) {
633  static_assert( 0 == sizeof...(Args), "Kokkos::TeamPolicy: unhandled constructor arguments encountered.");
634  }
635 
636  template<class iType, class ... Args>
637  inline typename std::enable_if<std::is_integral<iType>::value>::type set(iType, Args ... args) {
638  if(first_arg) {
639  first_arg = false;
640  set(args...);
641  } else {
642  first_arg = false;
643  Kokkos::Impl::throw_runtime_exception("Kokkos::TeamPolicy: integer argument to constructor in illegal place.");
644  }
645  }
646 
647  template<class ... Args>
648  inline void set(const ChunkSize& chunksize, Args ... args) {
649  first_arg = false;
650  internal_policy::internal_set_chunk_size(chunksize.value);
651  set(args...);
652  }
653 
654  template<class ... Args>
655  inline void set(const ScratchRequest& scr_request, Args ... args) {
656  first_arg = false;
657  internal_policy::internal_set_scratch_size(scr_request.level,Impl::PerTeamValue(scr_request.per_team),
658  Impl::PerThreadValue(scr_request.per_thread));
659  set(args...);
660  }
661 
662  inline TeamPolicy set_chunk_size(int chunk) const {
663  return TeamPolicy(internal_policy::set_chunk_size(chunk));
664  }
665 
666  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerTeamValue& per_team) const {
667  return TeamPolicy(internal_policy::set_scratch_size(level,per_team));
668  }
669  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread) const {
670  return TeamPolicy(internal_policy::set_scratch_size(level,per_thread));
671  }
672  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerTeamValue& per_team, const Impl::PerThreadValue& per_thread) const {
673  return TeamPolicy(internal_policy::set_scratch_size(level, per_team, per_thread));
674  }
675  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread, const Impl::PerTeamValue& per_team) const {
676  return TeamPolicy(internal_policy::set_scratch_size(level, per_team, per_thread));
677  }
678 
679 #else
680  inline TeamPolicy& set_chunk_size(int chunk) {
681  static_assert(std::is_same<decltype(internal_policy::set_chunk_size(chunk)), internal_policy&>::value, "internal set_chunk_size should return a reference");
682  return static_cast<TeamPolicy&>(internal_policy::set_chunk_size(chunk));
683  }
684 
685  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerTeamValue& per_team) {
686  static_assert(std::is_same<decltype(internal_policy::set_scratch_size(level,per_team)), internal_policy&>::value, "internal set_chunk_size should return a reference");
687  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level,per_team));
688  }
689  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread) {
690  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level,per_thread));
691  }
692  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerTeamValue& per_team, const Impl::PerThreadValue& per_thread) {
693  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level, per_team, per_thread));
694  }
695  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread, const Impl::PerTeamValue& per_team) {
696  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level, per_team, per_thread));
697  }
698 #endif
699 
700 };
701 
702 namespace Impl {
703 
704 template<typename iType, class TeamMemberType>
705 struct TeamThreadRangeBoundariesStruct {
706 private:
707 
708  KOKKOS_INLINE_FUNCTION static
709  iType ibegin( const iType & arg_begin
710  , const iType & arg_end
711  , const iType & arg_rank
712  , const iType & arg_size
713  )
714  {
715  return arg_begin + ( ( arg_end - arg_begin + arg_size - 1 ) / arg_size ) * arg_rank ;
716  }
717 
718  KOKKOS_INLINE_FUNCTION static
719  iType iend( const iType & arg_begin
720  , const iType & arg_end
721  , const iType & arg_rank
722  , const iType & arg_size
723  )
724  {
725  const iType end_ = arg_begin + ( ( arg_end - arg_begin + arg_size - 1 ) / arg_size ) * ( arg_rank + 1 );
726  return end_ < arg_end ? end_ : arg_end ;
727  }
728 
729 public:
730 
731  typedef iType index_type;
732  const iType start;
733  const iType end;
734  enum {increment = 1};
735  const TeamMemberType& thread;
736 
737  KOKKOS_INLINE_FUNCTION
738  TeamThreadRangeBoundariesStruct( const TeamMemberType& arg_thread
739  , const iType& arg_end
740  )
741  : start( ibegin( 0 , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
742  , end( iend( 0 , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
743  , thread( arg_thread )
744  {}
745 
746  KOKKOS_INLINE_FUNCTION
747  TeamThreadRangeBoundariesStruct( const TeamMemberType& arg_thread
748  , const iType& arg_begin
749  , const iType& arg_end
750  )
751  : start( ibegin( arg_begin , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
752  , end( iend( arg_begin , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
753  , thread( arg_thread )
754  {}
755 };
756 
757 template<typename iType, class TeamMemberType>
758 struct ThreadVectorRangeBoundariesStruct {
759  typedef iType index_type;
760  const index_type start;
761  const index_type end;
762  enum {increment = 1};
763 
764  KOKKOS_INLINE_FUNCTION
765  constexpr ThreadVectorRangeBoundariesStruct ( const TeamMemberType, const index_type& count ) noexcept
766  : start( static_cast<index_type>(0) )
767  , end( count ) {}
768 
769  KOKKOS_INLINE_FUNCTION
770  constexpr ThreadVectorRangeBoundariesStruct ( const index_type& count ) noexcept
771  : start( static_cast<index_type>(0) )
772  , end( count ) {}
773 
774  KOKKOS_INLINE_FUNCTION
775  constexpr ThreadVectorRangeBoundariesStruct ( const TeamMemberType, const index_type& arg_begin, const index_type& arg_end ) noexcept
776  : start( static_cast<index_type>(arg_begin) )
777  , end( arg_end ) {}
778 
779  KOKKOS_INLINE_FUNCTION
780  constexpr ThreadVectorRangeBoundariesStruct ( const index_type& arg_begin, const index_type& arg_end ) noexcept
781  : start( static_cast<index_type>(arg_begin) )
782  , end( arg_end ) {}
783 };
784 
785 template<class TeamMemberType>
786 struct ThreadSingleStruct {
787  const TeamMemberType& team_member;
788  KOKKOS_INLINE_FUNCTION
789  ThreadSingleStruct( const TeamMemberType& team_member_ ) : team_member( team_member_ ) {}
790 };
791 
792 template<class TeamMemberType>
793 struct VectorSingleStruct {
794  const TeamMemberType& team_member;
795  KOKKOS_INLINE_FUNCTION
796  VectorSingleStruct( const TeamMemberType& team_member_ ) : team_member( team_member_ ) {}
797 };
798 
799 } // namespace Impl
800 
807 template<typename iType, class TeamMemberType>
808 KOKKOS_INLINE_FUNCTION
809 Impl::TeamThreadRangeBoundariesStruct<iType,TeamMemberType>
810 TeamThreadRange( const TeamMemberType&, const iType& count );
811 
818 template<typename iType1, typename iType2, class TeamMemberType>
819 KOKKOS_INLINE_FUNCTION
820 Impl::TeamThreadRangeBoundariesStruct<typename std::common_type<iType1, iType2>::type, TeamMemberType>
821 TeamThreadRange( const TeamMemberType&, const iType1& begin, const iType2& end );
822 
829 template<typename iType, class TeamMemberType>
830 KOKKOS_INLINE_FUNCTION
831 Impl::ThreadVectorRangeBoundariesStruct<iType,TeamMemberType>
832 ThreadVectorRange( const TeamMemberType&, const iType& count );
833 
834 template<typename iType, class TeamMemberType>
835 KOKKOS_INLINE_FUNCTION
836 Impl::ThreadVectorRangeBoundariesStruct<iType,TeamMemberType>
837 ThreadVectorRange( const TeamMemberType&, const iType& arg_begin, const iType& arg_end );
838 
839 #if defined(KOKKOS_ENABLE_PROFILING)
840 namespace Impl {
841 
842 template<typename FunctorType, typename TagType,
843  bool HasTag = !std::is_same<TagType, void>::value >
844 struct ParallelConstructName;
845 
846 template<typename FunctorType, typename TagType>
847 struct ParallelConstructName<FunctorType, TagType, true> {
848  ParallelConstructName(std::string const& label):label_ref(label) {
849  if (label.empty()) {
850  default_name = std::string(typeid(FunctorType).name()) + "/" +
851  typeid(TagType).name();
852  }
853  }
854  std::string const& get() {
855  return (label_ref.empty()) ? default_name : label_ref;
856  }
857  std::string const& label_ref;
858  std::string default_name;
859 };
860 
861 template<typename FunctorType, typename TagType>
862 struct ParallelConstructName<FunctorType, TagType, false> {
863  ParallelConstructName(std::string const& label):label_ref(label) {
864  if (label.empty()) {
865  default_name = std::string(typeid(FunctorType).name());
866  }
867  }
868  std::string const& get() {
869  return (label_ref.empty()) ? default_name : label_ref;
870  }
871  std::string const& label_ref;
872  std::string default_name;
873 };
874 
875 } // namespace Impl
876 #endif /* defined KOKKOS_ENABLE_PROFILING */
877 
878 } // namespace Kokkos
879 
880 #endif /* #define KOKKOS_EXECPOLICY_HPP */
881 
KOKKOS_INLINE_FUNCTION void team_barrier() const
Barrier among the threads of this team.
KOKKOS_INLINE_FUNCTION int team_rank() const
Rank of this thread within this team.
TeamPolicy(int league_size_request, int team_size_request, int vector_length_request=1)
Construct policy with the default instance of the execution space.
KOKKOS_INLINE_FUNCTION int team_size() const
Number of threads in this team.
RangePolicy set_chunk_size(int chunk_size_) const
set chunk_size to a discrete value
RangePolicy 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 typename traits::execution_space &work_space, const member_type work_begin, const member_type work_end)
Total range.
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 int league_rank() const
Rank of this team within the league of teams.
member_type chunk_size() const
return chunk_size
TeamPolicy(const typename traits::execution_space &, int league_size_request, int team_size_request, int vector_length_request=1)
Construct policy with the given instance of the execution space.
KOKKOS_INLINE_FUNCTION traits::execution_space::scratch_memory_space team_shmem() const
Handle to the currently executing team shared scratch memory.
KOKKOS_INLINE_FUNCTION Type team_scan(const Type &value) const
Intra-team exclusive prefix sum with team_rank() ordering.
KOKKOS_INLINE_FUNCTION WorkRange(const RangePolicy &range, const int part_rank, const int part_size)
Subrange for a partition&#39;s rank and size.
RangePolicy(const member_type work_begin, const member_type work_end, Args...args)
Total range.
RangePolicy(const typename traits::execution_space &work_space, const member_type work_begin, const member_type work_end, Args...args)
Total range.
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&#39;s rank and size.
KOKKOS_INLINE_FUNCTION int league_size() const
Number of teams in the league.
Execution policy for parallel work over a league of teams of threads.
Parallel execution of a functor calls the functor once with each member of the execution policy...