Kokkos Core Kernels Package  Version of the Day
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 ChunkSize {
61  int value;
62  ChunkSize(int value_):value(value_) {}
63 };
64 
86 template<class ... Properties>
88  : public Impl::PolicyTraits<Properties ... >
89 {
90 private:
91  typedef Impl::PolicyTraits<Properties ... > traits;
92 
93  typename traits::execution_space m_space ;
94  typename traits::index_type m_begin ;
95  typename traits::index_type m_end ;
96  typename traits::index_type m_granularity ;
97  typename traits::index_type m_granularity_mask ;
98 
99 public:
102  typedef typename traits::index_type member_type ;
103  typedef typename traits::index_type index_type;
104 
105  KOKKOS_INLINE_FUNCTION const typename traits::execution_space & space() const { return m_space ; }
106  KOKKOS_INLINE_FUNCTION member_type begin() const { return m_begin ; }
107  KOKKOS_INLINE_FUNCTION member_type end() const { return m_end ; }
108 
109  //TODO: find a better workaround for Clangs weird instantiation order
110  // This thing is here because of an instantiation error, where the RangePolicy is inserted into FunctorValue Traits, which
111  // tries decltype on the operator. It tries to do this even though the first argument of parallel for clearly doesn't match.
112  void operator()(const int&) const {}
113 
114  RangePolicy(const RangePolicy&) = default;
115  RangePolicy(RangePolicy&&) = default;
116 
117  inline RangePolicy() : m_space(), m_begin(0), m_end(0) {}
118 
120  inline
121  RangePolicy( const typename traits::execution_space & work_space
122  , const member_type work_begin
123  , const member_type work_end
124  )
125  : m_space( work_space )
126  , m_begin( work_begin < work_end ? work_begin : 0 )
127  , m_end( work_begin < work_end ? work_end : 0 )
128  , m_granularity(0)
129  , m_granularity_mask(0)
130  {
131  set_auto_chunk_size();
132  }
133 
135  inline
136  RangePolicy( const member_type work_begin
137  , const member_type work_end
138  )
139  : RangePolicy( typename traits::execution_space()
140  , work_begin , work_end )
141  {
142  set_auto_chunk_size();
143  }
144 
146  template<class ... Args>
147  inline
148  RangePolicy( const typename traits::execution_space & work_space
149  , const member_type work_begin
150  , const member_type work_end
151  , Args ... args
152  )
153  : m_space( work_space )
154  , m_begin( work_begin < work_end ? work_begin : 0 )
155  , m_end( work_begin < work_end ? work_end : 0 )
156  , m_granularity(0)
157  , m_granularity_mask(0)
158  {
159  set_auto_chunk_size();
160  set(args...);
161  }
162 
164  template<class ... Args>
165  inline
166  RangePolicy( const member_type work_begin
167  , const member_type work_end
168  , Args ... args
169  )
170  : RangePolicy( typename traits::execution_space()
171  , work_begin , work_end )
172  {
173  set_auto_chunk_size();
174  set(args...);
175  }
176 
177 private:
178  inline void set() {}
179 
180 public:
181  template<class ... Args>
182  inline void set(Args ...) {
183  static_assert( 0 == sizeof...(Args), "Kokkos::RangePolicy: unhandled constructor arguments encountered.");
184  }
185 
186  template<class ... Args>
187  inline void set(const ChunkSize& chunksize, Args ... args) {
188  m_granularity = chunksize.value;
189  m_granularity_mask = m_granularity - 1;
190  }
191 
192 public:
194  inline member_type chunk_size() const {
195  return m_granularity;
196  }
197 
199  inline RangePolicy set_chunk_size(int chunk_size_) const {
200  RangePolicy p = *this;
201  p.m_granularity = chunk_size_;
202  p.m_granularity_mask = p.m_granularity - 1;
203  return p;
204  }
205 
206 private:
208  inline void set_auto_chunk_size() {
209 
210  typename traits::index_type concurrency = traits::execution_space::concurrency();
211  if( concurrency==0 ) concurrency=1;
212 
213  if(m_granularity > 0) {
214  if(!Impl::is_integral_power_of_two( m_granularity ))
215  Kokkos::abort("RangePolicy blocking granularity must be power of two" );
216  }
217 
218  member_type new_chunk_size = 1;
219  while(new_chunk_size*100*concurrency < m_end-m_begin)
220  new_chunk_size *= 2;
221  if(new_chunk_size < 128) {
222  new_chunk_size = 1;
223  while( (new_chunk_size*40*concurrency < m_end-m_begin ) && (new_chunk_size<128) )
224  new_chunk_size*=2;
225  }
226  m_granularity = new_chunk_size;
227  m_granularity_mask = m_granularity - 1;
228  }
229 
230 public:
235  struct WorkRange {
236  typedef typename RangePolicy::work_tag work_tag ;
237  typedef typename RangePolicy::member_type member_type ;
238 
239  KOKKOS_INLINE_FUNCTION member_type begin() const { return m_begin ; }
240  KOKKOS_INLINE_FUNCTION member_type end() const { return m_end ; }
241 
246  KOKKOS_INLINE_FUNCTION
247  WorkRange( const RangePolicy & range
248  , const int part_rank
249  , const int part_size
250  )
251  : m_begin(0), m_end(0)
252  {
253  if ( part_size ) {
254 
255  // Split evenly among partitions, then round up to the granularity.
256  const member_type work_part =
257  ( ( ( ( range.end() - range.begin() ) + ( part_size - 1 ) ) / part_size )
258  + range.m_granularity_mask ) & ~member_type(range.m_granularity_mask);
259 
260  m_begin = range.begin() + work_part * part_rank ;
261  m_end = m_begin + work_part ;
262 
263  if ( range.end() < m_begin ) m_begin = range.end() ;
264  if ( range.end() < m_end ) m_end = range.end() ;
265  }
266  }
267 
268  private:
269  member_type m_begin ;
270  member_type m_end ;
271  WorkRange();
272  WorkRange & operator = ( const WorkRange & );
273  };
274 };
275 
276 } // namespace Kokkos
277 
278 //----------------------------------------------------------------------------
279 //----------------------------------------------------------------------------
280 
281 namespace Kokkos {
282 
283 namespace Impl {
284 
285 template< class ExecSpace, class ... Properties>
286 class TeamPolicyInternal: public Impl::PolicyTraits<Properties ... > {
287 private:
288  typedef Impl::PolicyTraits<Properties ... > traits;
289 
290 public:
291 
292  typedef typename traits::index_type index_type;
293 
294  //----------------------------------------
305  template< class FunctorType >
306  static int team_size_max( const FunctorType & );
307 
318  template< class FunctorType >
319  static int team_size_recommended( const FunctorType & );
320 
321  template< class FunctorType >
322  static int team_size_recommended( const FunctorType & , const int&);
323  //----------------------------------------
325  TeamPolicyInternal( const typename traits::execution_space & , int league_size_request , int team_size_request , int vector_length_request = 1 );
326 
327  TeamPolicyInternal( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 );
328 
330  TeamPolicyInternal( int league_size_request , int team_size_request , int vector_length_request = 1 );
331 
332  TeamPolicyInternal( int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 );
333 
334 /* TeamPolicyInternal( int league_size_request , int team_size_request );
335 
336  TeamPolicyInternal( int league_size_request , const Kokkos::AUTO_t & );*/
337 
343  KOKKOS_INLINE_FUNCTION int league_size() const ;
344 
350  KOKKOS_INLINE_FUNCTION int team_size() const ;
351 
352  inline typename traits::index_type chunk_size() const ;
353 
354 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
355  inline TeamPolicyInternal set_chunk_size(int chunk_size) const ;
356 #else
357  inline TeamPolicyInternal& set_chunk_size(int chunk_size);
358 #endif
359 
363  struct member_type {
364 
366  KOKKOS_INLINE_FUNCTION
367  typename traits::execution_space::scratch_memory_space team_shmem() const ;
368 
370  KOKKOS_INLINE_FUNCTION int league_rank() const ;
371 
373  KOKKOS_INLINE_FUNCTION int league_size() const ;
374 
376  KOKKOS_INLINE_FUNCTION int team_rank() const ;
377 
379  KOKKOS_INLINE_FUNCTION int team_size() const ;
380 
382  KOKKOS_INLINE_FUNCTION void team_barrier() const ;
383 
385  template< class JoinOp >
386  KOKKOS_INLINE_FUNCTION
387  typename JoinOp::value_type team_reduce( const typename JoinOp::value_type
388  , const JoinOp & ) const ;
389 
395  template< typename Type >
396  KOKKOS_INLINE_FUNCTION Type team_scan( const Type & value ) const ;
397 
407  template< typename Type >
408  KOKKOS_INLINE_FUNCTION Type team_scan( const Type & value , Type * const global_accum ) const ;
409  };
410 };
411 
412 
413  struct PerTeamValue {
414  int value;
415  PerTeamValue(int arg);
416  };
417 
418  struct PerThreadValue {
419  int value;
420  PerThreadValue(int arg);
421  };
422 
423  template<class iType, class ... Args>
424  struct ExtractVectorLength {
425  static inline iType value(typename std::enable_if<std::is_integral<iType>::value,iType>::type val, Args...) {
426  return val;
427  }
428  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...) {
429  return 1;
430  }
431  };
432 
433  template<class iType, class ... Args>
434  inline typename std::enable_if<std::is_integral<iType>::value,iType>::type extract_vector_length(iType val, Args...) {
435  return val;
436  }
437 
438  template<class iType, class ... Args>
439  inline typename std::enable_if<!std::is_integral<iType>::value,int>::type extract_vector_length(iType, Args...) {
440  return 1;
441  }
442 
443 }
444 
445 Impl::PerTeamValue PerTeam(const int& arg);
446 Impl::PerThreadValue PerThread(const int& arg);
447 
448 struct ScratchRequest {
449  int level;
450 
451  int per_team;
452  int per_thread;
453 
454  inline
455  ScratchRequest(const int& level_, const Impl::PerTeamValue& team_value) {
456  level = level_;
457  per_team = team_value.value;
458  per_thread = 0;
459  }
460 
461  inline
462  ScratchRequest(const int& level_, const Impl::PerThreadValue& thread_value) {
463  level = level_;
464  per_team = 0;
465  per_thread = thread_value.value;;
466  }
467 
468  inline
469  ScratchRequest(const int& level_, const Impl::PerTeamValue& team_value, const Impl::PerThreadValue& thread_value) {
470  level = level_;
471  per_team = team_value.value;
472  per_thread = thread_value.value;;
473  }
474 
475  inline
476  ScratchRequest(const int& level_, const Impl::PerThreadValue& thread_value, const Impl::PerTeamValue& team_value) {
477  level = level_;
478  per_team = team_value.value;
479  per_thread = thread_value.value;;
480  }
481 
482 };
483 
484 
509 template< class ... Properties>
510 class TeamPolicy: public
511  Impl::TeamPolicyInternal<
512  typename Impl::PolicyTraits<Properties ... >::execution_space,
513  Properties ...> {
514  typedef Impl::TeamPolicyInternal<
515  typename Impl::PolicyTraits<Properties ... >::execution_space,
516  Properties ...> internal_policy;
517 
518  typedef Impl::PolicyTraits<Properties ... > traits;
519 
520 public:
522 
523  TeamPolicy& operator = (const TeamPolicy&) = default;
524 
526  TeamPolicy( const typename traits::execution_space & , int league_size_request , int team_size_request , int vector_length_request = 1 )
527  : internal_policy(typename traits::execution_space(),league_size_request,team_size_request, vector_length_request) {first_arg = false;}
528 
529  TeamPolicy( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 )
530  : internal_policy(typename traits::execution_space(),league_size_request,Kokkos::AUTO(), vector_length_request) {first_arg = false;}
531 
533  TeamPolicy( int league_size_request , int team_size_request , int vector_length_request = 1 )
534  : internal_policy(league_size_request,team_size_request, vector_length_request) {first_arg = false;}
535 
536  TeamPolicy( int league_size_request , const Kokkos::AUTO_t & , int vector_length_request = 1 )
537  : internal_policy(league_size_request,Kokkos::AUTO(), vector_length_request) {first_arg = false;}
538 
539 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
540 
541  template<class ... Args>
542  TeamPolicy( const typename traits::execution_space & , int league_size_request , int team_size_request , int vector_length_request,
543  Args ... args)
544  : internal_policy(typename traits::execution_space(),league_size_request,team_size_request, vector_length_request) {
545  first_arg = false;
546  set(args...);
547  }
548 
549  template<class ... Args>
550  TeamPolicy( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & , int vector_length_request ,
551  Args ... args)
552  : internal_policy(typename traits::execution_space(),league_size_request,Kokkos::AUTO(), vector_length_request) {
553  first_arg = false;
554  set(args...);
555  }
556 
558  template<class ... Args>
559  TeamPolicy( int league_size_request , int team_size_request , int vector_length_request ,
560  Args ... args)
561  : internal_policy(league_size_request,team_size_request, vector_length_request) {
562  first_arg = false;
563  set(args...);
564  }
565 
566  template<class ... Args>
567  TeamPolicy( int league_size_request , const Kokkos::AUTO_t & , int vector_length_request ,
568  Args ... args)
569  : internal_policy(league_size_request,Kokkos::AUTO(), vector_length_request) {
570  first_arg = false;
571  set(args...);
572  }
573 
575  template<class ... Args>
576  TeamPolicy( const typename traits::execution_space & , int league_size_request , int team_size_request ,
577  Args ... args)
578  : internal_policy(typename traits::execution_space(),league_size_request,team_size_request,
579  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
580  first_arg = true;
581  set(args...);
582  }
583 
584  template<class ... Args>
585  TeamPolicy( const typename traits::execution_space & , int league_size_request , const Kokkos::AUTO_t & ,
586  Args ... args)
587  : internal_policy(typename traits::execution_space(),league_size_request,Kokkos::AUTO(),
588  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
589  first_arg = true;
590  set(args...);
591  }
592 
594  template<class ... Args>
595  TeamPolicy( int league_size_request , int team_size_request ,
596  Args ... args)
597  : internal_policy(league_size_request,team_size_request,
598  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
599  first_arg = true;
600  set(args...);
601  }
602 
603  template<class ... Args>
604  TeamPolicy( int league_size_request , const Kokkos::AUTO_t & ,
605  Args ... args)
606  : internal_policy(league_size_request,Kokkos::AUTO(),
607  Kokkos::Impl::extract_vector_length<Args...>(args...)) {
608  first_arg = true;
609  set(args...);
610  }
611 #endif
612 
613 private:
614  bool first_arg;
615  TeamPolicy(const internal_policy& p):internal_policy(p) {first_arg = false;}
616 
617 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
618  inline void set() {}
619 #endif
620 
621 public:
622 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
623  template<class ... Args>
624  inline void set(Args ...) {
625  static_assert( 0 == sizeof...(Args), "Kokkos::TeamPolicy: unhandled constructor arguments encountered.");
626  }
627 
628  template<class iType, class ... Args>
629  inline typename std::enable_if<std::is_integral<iType>::value>::type set(iType, Args ... args) {
630  if(first_arg) {
631  first_arg = false;
632  set(args...);
633  } else {
634  first_arg = false;
635  Kokkos::Impl::throw_runtime_exception("Kokkos::TeamPolicy: integer argument to constructor in illegal place.");
636  }
637  }
638 
639  template<class ... Args>
640  inline void set(const ChunkSize& chunksize, Args ... args) {
641  first_arg = false;
642  internal_policy::internal_set_chunk_size(chunksize.value);
643  set(args...);
644  }
645 
646  template<class ... Args>
647  inline void set(const ScratchRequest& scr_request, Args ... args) {
648  first_arg = false;
649  internal_policy::internal_set_scratch_size(scr_request.level,Impl::PerTeamValue(scr_request.per_team),
650  Impl::PerThreadValue(scr_request.per_thread));
651  set(args...);
652  }
653 
654  inline TeamPolicy set_chunk_size(int chunk) const {
655  return TeamPolicy(internal_policy::set_chunk_size(chunk));
656  }
657 
658  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerTeamValue& per_team) const {
659  return TeamPolicy(internal_policy::set_scratch_size(level,per_team));
660  }
661  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread) const {
662  return TeamPolicy(internal_policy::set_scratch_size(level,per_thread));
663  }
664  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerTeamValue& per_team, const Impl::PerThreadValue& per_thread) const {
665  return TeamPolicy(internal_policy::set_scratch_size(level, per_team, per_thread));
666  }
667  inline TeamPolicy set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread, const Impl::PerTeamValue& per_team) const {
668  return TeamPolicy(internal_policy::set_scratch_size(level, per_team, per_thread));
669  }
670 
671 #else
672  inline TeamPolicy& set_chunk_size(int chunk) {
673  static_assert(std::is_same<decltype(internal_policy::set_chunk_size(chunk)), internal_policy&>::value, "internal set_chunk_size should return a reference");
674  return static_cast<TeamPolicy&>(internal_policy::set_chunk_size(chunk));
675  }
676 
677  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerTeamValue& per_team) {
678  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");
679  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level,per_team));
680  }
681  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread) {
682  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level,per_thread));
683  }
684  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerTeamValue& per_team, const Impl::PerThreadValue& per_thread) {
685  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level, per_team, per_thread));
686  }
687  inline TeamPolicy& set_scratch_size(const int& level, const Impl::PerThreadValue& per_thread, const Impl::PerTeamValue& per_team) {
688  return static_cast<TeamPolicy&>(internal_policy::set_scratch_size(level, per_team, per_thread));
689  }
690 #endif
691 
692 };
693 
694 namespace Impl {
695 
696 template<typename iType, class TeamMemberType>
697 struct TeamThreadRangeBoundariesStruct {
698 private:
699 
700  KOKKOS_INLINE_FUNCTION static
701  iType ibegin( const iType & arg_begin
702  , const iType & arg_end
703  , const iType & arg_rank
704  , const iType & arg_size
705  )
706  {
707  return arg_begin + ( ( arg_end - arg_begin + arg_size - 1 ) / arg_size ) * arg_rank ;
708  }
709 
710  KOKKOS_INLINE_FUNCTION static
711  iType iend( const iType & arg_begin
712  , const iType & arg_end
713  , const iType & arg_rank
714  , const iType & arg_size
715  )
716  {
717  const iType end_ = arg_begin + ( ( arg_end - arg_begin + arg_size - 1 ) / arg_size ) * ( arg_rank + 1 );
718  return end_ < arg_end ? end_ : arg_end ;
719  }
720 
721 public:
722 
723  typedef iType index_type;
724  const iType start;
725  const iType end;
726  enum {increment = 1};
727  const TeamMemberType& thread;
728 
729  KOKKOS_INLINE_FUNCTION
730  TeamThreadRangeBoundariesStruct( const TeamMemberType& arg_thread
731  , const iType& arg_end
732  )
733  : start( ibegin( 0 , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
734  , end( iend( 0 , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
735  , thread( arg_thread )
736  {}
737 
738  KOKKOS_INLINE_FUNCTION
739  TeamThreadRangeBoundariesStruct( const TeamMemberType& arg_thread
740  , const iType& arg_begin
741  , const iType& arg_end
742  )
743  : start( ibegin( arg_begin , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
744  , end( iend( arg_begin , arg_end , arg_thread.team_rank() , arg_thread.team_size() ) )
745  , thread( arg_thread )
746  {}
747 };
748 
749 template<typename iType, class TeamMemberType>
750 struct ThreadVectorRangeBoundariesStruct {
751  typedef iType index_type;
752  const index_type start;
753  const index_type end;
754  enum {increment = 1};
755 
756  KOKKOS_INLINE_FUNCTION
757  constexpr ThreadVectorRangeBoundariesStruct ( const TeamMemberType, const index_type& count ) noexcept
758  : start( static_cast<index_type>(0) )
759  , end( count ) {}
760 
761  KOKKOS_INLINE_FUNCTION
762  constexpr ThreadVectorRangeBoundariesStruct ( const index_type& count ) noexcept
763  : start( static_cast<index_type>(0) )
764  , end( count ) {}
765 
766  KOKKOS_INLINE_FUNCTION
767  constexpr ThreadVectorRangeBoundariesStruct ( const TeamMemberType, const index_type& arg_begin, const index_type& arg_end ) noexcept
768  : start( static_cast<index_type>(arg_begin) )
769  , end( arg_end ) {}
770 
771  KOKKOS_INLINE_FUNCTION
772  constexpr ThreadVectorRangeBoundariesStruct ( const index_type& arg_begin, const index_type& arg_end ) noexcept
773  : start( static_cast<index_type>(arg_begin) )
774  , end( arg_end ) {}
775 };
776 
777 template<class TeamMemberType>
778 struct ThreadSingleStruct {
779  const TeamMemberType& team_member;
780  KOKKOS_INLINE_FUNCTION
781  ThreadSingleStruct( const TeamMemberType& team_member_ ) : team_member( team_member_ ) {}
782 };
783 
784 template<class TeamMemberType>
785 struct VectorSingleStruct {
786  const TeamMemberType& team_member;
787  KOKKOS_INLINE_FUNCTION
788  VectorSingleStruct( const TeamMemberType& team_member_ ) : team_member( team_member_ ) {}
789 };
790 
791 } // namespace Impl
792 
799 template<typename iType, class TeamMemberType>
800 KOKKOS_INLINE_FUNCTION
801 Impl::TeamThreadRangeBoundariesStruct<iType,TeamMemberType>
802 TeamThreadRange( const TeamMemberType&, const iType& count );
803 
810 template<typename iType1, typename iType2, class TeamMemberType>
811 KOKKOS_INLINE_FUNCTION
812 Impl::TeamThreadRangeBoundariesStruct<typename std::common_type<iType1, iType2>::type, TeamMemberType>
813 TeamThreadRange( const TeamMemberType&, const iType1& begin, const iType2& end );
814 
821 template<typename iType, class TeamMemberType>
822 KOKKOS_INLINE_FUNCTION
823 Impl::ThreadVectorRangeBoundariesStruct<iType,TeamMemberType>
824 ThreadVectorRange( const TeamMemberType&, const iType& count );
825 
826 template<typename iType, class TeamMemberType>
827 KOKKOS_INLINE_FUNCTION
828 Impl::ThreadVectorRangeBoundariesStruct<iType,TeamMemberType>
829 ThreadVectorRange( const TeamMemberType&, const iType& arg_begin, const iType& arg_end );
830 
831 #if defined(KOKKOS_ENABLE_PROFILING)
832 namespace Impl {
833 
834 template<typename FunctorType, typename TagType,
835  bool HasTag = !std::is_same<TagType, void>::value >
836 struct ParallelConstructName;
837 
838 template<typename FunctorType, typename TagType>
839 struct ParallelConstructName<FunctorType, TagType, true> {
840  ParallelConstructName(std::string const& label):label_ref(label) {
841  if (label.empty()) {
842  default_name = std::string(typeid(FunctorType).name()) + "/" +
843  typeid(TagType).name();
844  }
845  }
846  std::string const& get() {
847  return (label_ref.empty()) ? default_name : label_ref;
848  }
849  std::string const& label_ref;
850  std::string default_name;
851 };
852 
853 template<typename FunctorType, typename TagType>
854 struct ParallelConstructName<FunctorType, TagType, false> {
855  ParallelConstructName(std::string const& label):label_ref(label) {
856  if (label.empty()) {
857  default_name = std::string(typeid(FunctorType).name());
858  }
859  }
860  std::string const& get() {
861  return (label_ref.empty()) ? default_name : label_ref;
862  }
863  std::string const& label_ref;
864  std::string default_name;
865 };
866 
867 } // namespace Impl
868 #endif /* defined KOKKOS_ENABLE_PROFILING */
869 
870 } // namespace Kokkos
871 
872 #endif /* #define KOKKOS_EXECPOLICY_HPP */
873 
member_type chunk_size() const
return chunk_size
TeamPolicy(int league_size_request, int team_size_request, int vector_length_request=1)
Construct policy with the default instance of the execution space.
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.
RangePolicy(const typename traits::execution_space &work_space, const member_type work_begin, const member_type work_end, Args ... args)
Total range.
KOKKOS_INLINE_FUNCTION int team_rank() const
Rank of this thread within this team.
KOKKOS_INLINE_FUNCTION int league_size() const
Number of teams in the league.
KOKKOS_INLINE_FUNCTION int league_rank() const
Rank of this team within the league of teams.
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 WorkRange(const RangePolicy &range, const int part_rank, const int part_size)
Subrange for a partition&#39;s rank and size.
KOKKOS_INLINE_FUNCTION Type team_scan(const Type &value) const
Intra-team exclusive prefix sum with team_rank() ordering.
RangePolicy(const member_type work_begin, const member_type work_end)
Total range.
KOKKOS_INLINE_FUNCTION void team_barrier() const
Barrier among the threads of this team.
KOKKOS_INLINE_FUNCTION Impl::ThreadVectorRangeBoundariesStruct< iType, TeamMemberType > ThreadVectorRange(const TeamMemberType &, const iType &count)
Execution policy for a vector parallel loop.
RangePolicy set_chunk_size(int chunk_size_) const
set chunk_size to a discrete value
Execution policy for work over a range of an integral type.
KOKKOS_INLINE_FUNCTION int team_size() const
Number of threads in this team.
Subrange for a partition&#39;s rank and size.
Execution policy for parallel work over a league of teams of threads.
RangePolicy(const member_type work_begin, const member_type work_end, Args ... args)
Total range.
Parallel execution of a functor calls the functor once with each member of the execution policy...
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 traits::execution_space::scratch_memory_space team_shmem() const
Handle to the currently executing team shared scratch memory.