-
Notifications
You must be signed in to change notification settings - Fork 0
Kokkos::TeamHandleConcept
Header File: Kokkos_Core.hpp
TeamHandleConcept defines the concept for the member_type
of TeamPolicy
and TeamTask
.
The actual type is defined through the policies, but meets the following API requirements.
Note that the specific classes are only part of the public API as provided by TeamPolicy
and
TeamTask
and only their parts as defined by the TeamHandleConcept
.
The actual name of the class, as well as potential template parameters, existing
constructors, member functions going beyond the concept, etc., are NOT part of the public Kokkos API
and are thus subject to change.
class TeamHandleConcept {
public:
// Constructor, Destructor, Assignment
TeamHandleConcept( TeamHandleConcept && ) = default ;
TeamHandleConcept( TeamHandleConcept const & ) = default ;
~TeamHandleConcept() = default ;
TeamHandleConcept & operator = ( TeamHandleConcept && ) = default ;
TeamHandleConcept & operator = ( TeamHandleConcept const & ) = default ;
// Indices
KOKKOS_INLINE_FUNCTION
int team_rank() const noexcept;
KOKKOS_INLINE_FUNCTION
int team_size() const noexcept;
KOKKOS_INLINE_FUNCTION
int league_rank() const noexcept;
KOKKOS_INLINE_FUNCTION
int league_size() const noexcept;
// Scratch Space
KOKKOS_INLINE_FUNCTION
const scratch_memory_space & team_shmem() const;
KOKKOS_INLINE_FUNCTION
const scratch_memory_space & team_scratch(int level) const;
KOKKOS_INLINE_FUNCTION
const scratch_memory_space & thread_scratch(int level) const;
// Team collectives
KOKKOS_INLINE_FUNCTION
void team_barrier() const noexcept;
template<typename T>
KOKKOS_INLINE_FUNCTION
void team_broadcast( T & value , const int source_team_rank ) const noexcept;
template<class Closure, typename T>
KOKKOS_INLINE_FUNCTION
void team_broadcast( Closure const & f , T & value , const int source_team_rank) const noexcept;
template< typename ReducerType >
KOKKOS_INLINE_FUNCTION
void team_reduce( ReducerType const & reducer ) const noexcept;
template< typename T >
KOKKOS_INLINE_FUNCTION
T team_scan( T const & value , T * const global = 0 ) const noexcept;
};
-
Default, move and copy constructors as well as destructor.
TeamHandleConcept() TeamHandleConcept(TeamHandleConcept && ) TeamHandleConcept(const TeamHandleConcept &) ~TeamHandleConcept()
-
Move assignment.
TeamHandleConcept & operator = ( TeamHandleConcept && )
-
Assignment operators. Returns:
TeamHandleConcept & operator = ( const TeamHandleConcept & )
*this
.
-
Returns: the number of threads associated with the team.
inline int team_size() const noexcept;
-
Returns: the index
inline int team_rank() const noexcept;
i
of the calling thread within the team with0 <= i < team_size()
-
Returns: the number of teams/workitems launched in the kernel.
inline int league_size() const noexcept;
-
Returns: the index
inline int league_rank() const noexcept;
i
of the calling team within the league with0 <= i < league_size()
-
This function returns a scratch memory handle shared by all threads in a team, which allows access to scratch memory. This handle can be given as the first argument to a
inline const scratch_memory_space & team_scratch(int level) const;
Kokkos::View
to make it use scratch memory.-
level
: The level of requested scratch memory is either0
or1
. Returns: a scratch memory handle to the team shared scratch memory specified by level.
-
-
This function returns a scratch memory handle specific to the calling thread, which allows access to its private scratch memory. This handle can be given as the first argument to a
inline const scratch_memory_space & thread_scratch(int level) const;
Kokkos::View
to make it use scratch memory.-
level
: The level of requested scratch memory is either0
or1
. Returns: a scratch memory handle to the thread scratch memory specified by level.
-
-
Equivalent to calling
inline const scratch_memory_space & team_shmem() const;
team_scratch(0)
.
The following functions must be called collectively by all members of a team. These calls must be lexically the same call, i.e. it is not legal to have some members of a team call a collective in one branch and the others in another branch of the code (see example).
-
All members of the team wait at the barrier, until the whole team arrived. This also issues a memory fence.
inline void team_barrier() const noexcept;
-
After this call
template<class T> inline void team_broadcast( T & var , const int source_team_rank ) const noexcept;
var
contains for every member of the team the value ofvar
from the thread for whichteam_rank() == source_team_rank
.-
var
: a variable of typeT
which gets overwritten by the value ofvar
from the source rank. -
source_team_rank
: identifies the broadcasting member of the team.
-
-
After this call
template<class Closure, class T> inline void team_broadcast( Closure const & f, T & var , const int source_team_rank ) const noexcept;
var
contains for every member of the team the value ofvar
from the thread for whichteam_rank() == source_team_rank
after applyingf
.-
f
: a function object with anvoid operator() ( T & )
which is applied tovar
before broadcasting it. -
var
: a variable of typeT
which gets overwritten by the value off(var)
from the source rank. -
source_team_rank
: identifies the broadcasting member of the team.
-
-
Performs a reduction accross all members of the team as specified by
template< class ReducerType > inline void team_reduce( ReducerType const & reducer ) const noexcept;
reducer
.ReducerType
must meet the concept ofKokkos::Reducer
. -
Performs an exclusive scan over the
template< class T > inline T team_scan( const T & var , T * const global = NULL ) cosnt noexcept;
var
provided by the team members. Lett = team_rank()
andVALUES[t]
the value ofvar
from threadt
. Returns:VALUES[0] + VALUES[1] +
...+ VALUES[t-1]
or zero fort==0
.-
global
if provided will be set toVALUES[0] + VALUES[1] +
...+ VALUES[team_size()-1]
, must be the same pointer for every team member.
-
typedef TeamPolciy<...> policy_type;
parallel_for(policy_type(N,TEAM_SIZE).set_scratch_size(PerTeam(0,4096)),
KOKKOS_LAMBDA (const typename policy_type::member_type& team_handle) {
int ts = team_handle.team_size(); // returns TEAM_SIZE
int tid = team_handle.team_rank(); // returns a number between 0 and TEAM_SIZE
int ls = team_handle.league_size(); // returns N
int lid = team_handle.league_rank(); // returns a number between 0 and N
int value = tid * 5;
team_handle.team_broadcast(value, 3);
// value==15 on every thread
value += tid;
team_handle.team_broadcast([&] (int & var) { var*=2 }, value, 2);
// value==34 on every thread
int global;
int scan = team_handle.team_scan(tid+1, &global);
// scan == tid*(tid+1)/2 on every thread
// global == ts*(ts-1)/2 on every thread
Kokkos::View<int*, policy_type::execution_space::scratch_memory_type>
a(team_handle.team_scratch(0), 1024);
});
new here from public (looks like a reorg)
Header File: Kokkos_Core.hpp
TeamHandleConcept defines the concept for the member_type
of TeamPolicy
and TeamTask
.
The actual type is defined through the policies, but meets the following API requirements.
Note that the specific classes are only part of the public API as provided by TeamPolicy
and
TeamTask
and only their parts as defined by the TeamHandleConcept
.
The actual name of the class, as well as potential template parameters, existing
constructors, member functions going beyond the concept, etc., are NOT part of the public Kokkos API
and are thus subject to change.
class TeamHandleConcept {
public:
// Constructor, Destructor, Assignment
TeamHandleConcept( TeamHandleConcept && ) = default ;
TeamHandleConcept( TeamHandleConcept const & ) = default ;
~TeamHandleConcept() = default ;
TeamHandleConcept & operator = ( TeamHandleConcept && ) = default ;
TeamHandleConcept & operator = ( TeamHandleConcept const & ) = default ;
// Indices
KOKKOS_INLINE_FUNCTION
int team_rank() const noexcept;
KOKKOS_INLINE_FUNCTION
int team_size() const noexcept;
KOKKOS_INLINE_FUNCTION
int league_rank() const noexcept;
KOKKOS_INLINE_FUNCTION
int league_size() const noexcept;
// Scratch Space
KOKKOS_INLINE_FUNCTION
const scratch_memory_space & team_shmem() const;
KOKKOS_INLINE_FUNCTION
const scratch_memory_space & team_scratch(int level) const;
KOKKOS_INLINE_FUNCTION
const scratch_memory_space & thread_scratch(int level) const;
// Team collectives
KOKKOS_INLINE_FUNCTION
void team_barrier() const noexcept;
template<typename T>
KOKKOS_INLINE_FUNCTION
void team_broadcast( T & value , const int source_team_rank ) const noexcept;
template<class Closure, typename T>
KOKKOS_INLINE_FUNCTION
void team_broadcast( Closure const & f , T & value , const int source_team_rank) const noexcept;
template< typename ReducerType >
KOKKOS_INLINE_FUNCTION
void team_reduce( ReducerType const & reducer ) const noexcept;
template< typename T >
KOKKOS_INLINE_FUNCTION
T team_scan( T const & value , T * const global = 0 ) const noexcept;
};
-
Default, move and copy constructors as well as destructor.
TeamHandleConcept() TeamHandleConcept(TeamHandleConcept && ) TeamHandleConcept(const TeamHandleConcept &) ~TeamHandleConcept()
-
Move assignment.
TeamHandleConcept & operator = ( TeamHandleConcept && )
-
Assignment operators. Returns:
TeamHandleConcept & operator = ( const TeamHandleConcept & )
*this
.
-
Returns: the number of threads associated with the team.
inline int team_size() const noexcept;
-
Returns: the index
inline int team_rank() const noexcept;
i
of the calling thread within the team with0 <= i < team_size()
-
Returns: the number of teams/workitems launched in the kernel.
inline int league_size() const noexcept;
-
Returns: the index
inline int league_rank() const noexcept;
i
of the calling team within the league with0 <= i < league_size()
-
This function returns a scratch memory handle shared by all threads in a team, which allows access to scratch memory. This handle can be given as the first argument to a
inline const scratch_memory_space & team_scratch(int level) const;
Kokkos::View
to make it use scratch memory.-
level
: The level of requested scratch memory is either0
or1
. Returns: a scratch memory handle to the team shared scratch memory specified by level.
-
-
This function returns a scratch memory handle specific to the calling thread, which allows access to its private scratch memory. This handle can be given as the first argument to a
inline const scratch_memory_space & thread_scratch(int level) const;
Kokkos::View
to make it use scratch memory.-
level
: The level of requested scratch memory is either0
or1
. Returns: a scratch memory handle to the thread scratch memory specified by level.
-
-
Equivalent to calling
inline const scratch_memory_space & team_shmem() const;
team_scratch(0)
.
The following functions must be called collectively by all members of a team. These calls must be lexically the same call, i.e. it is not legal to have some members of a team call a collective in one branch and the others in another branch of the code (see example).
-
All members of the team wait at the barrier, until the whole team arrived. This also issues a memory fence.
inline void team_barrier() const noexcept;
-
After this call
template<class T> inline void team_broadcast( T & var , const int source_team_rank ) const noexcept;
var
contains for every member of the team the value ofvar
from the thread for whichteam_rank() == source_team_rank
.-
var
: a variable of typeT
which gets overwritten by the value ofvar
from the source rank. -
source_team_rank
: identifies the broadcasting member of the team.
-
-
After this call
template<class Closure, class T> inline void team_broadcast( Closure const & f, T & var , const int source_team_rank ) const noexcept;
var
contains for every member of the team the value ofvar
from the thread for whichteam_rank() == source_team_rank
after applyingf
.-
f
: a function object with anvoid operator() ( T & )
which is applied tovar
before broadcasting it. -
var
: a variable of typeT
which gets overwritten by the value off(var)
from the source rank. -
source_team_rank
: identifies the broadcasting member of the team.
-
-
Performs a reduction accross all members of the team as specified by
template< class ReducerType > inline void team_reduce( ReducerType const & reducer ) const noexcept;
reducer
.ReducerType
must meet the concept ofKokkos::Reducer
. -
Performs an exclusive scan over the
template< class T > inline T team_scan( const T & var , T * const global = NULL ) cosnt noexcept;
var
provided by the team members. Lett = team_rank()
andVALUES[t]
the value ofvar
from threadt
. Returns:VALUES[0] + VALUES[1] +
...+ VALUES[t-1]
or zero fort==0
.-
global
if provided will be set toVALUES[0] + VALUES[1] +
...+ VALUES[team_size()-1]
, must be the same pointer for every team member.
-
typedef TeamPolciy<...> policy_type;
parallel_for(policy_type(N,TEAM_SIZE).set_scratch_size(PerTeam(0,4096)),
KOKKOS_LAMBDA (const typename policy_type::member_type& team_handle) {
int ts = team_handle.team_size(); // returns TEAM_SIZE
int tid = team_handle.team_rank(); // returns a number between 0 and TEAM_SIZE
int ls = team_handle.league_size(); // returns N
int lid = team_handle.league_rank(); // returns a number between 0 and N
int value = tid * 5;
team_handle.team_broadcast(value, 3);
// value==15 on every thread
value += tid;
team_handle.team_broadcast([&] (int & var) { var*=2 }, value, 2);
// value==34 on every thread
int global;
int scan = team_handle.team_scan(tid+1, &global);
// scan == tid*(tid+1)/2 on every thread
// global == ts*(ts-1)/2 on every thread
Kokkos::View<int*, policy_type::execution_space::scratch_memory_type>
a(team_handle.team_scratch(0), 1024);
});
Home:
- Introduction
- Machine Model
- Programming Model
- Compiling
- Initialization
- View
- Parallel Dispatch
- Hierarchical Parallelism
- Custom Reductions
- Atomic Operations
- Subviews
- Interoperability
- Kokkos and Virtual Functions
- Initialization and Finalization
- View
- Data Parallelism
- Execution Policies
- Spaces
- Task Parallelism
- Utilities
- STL Compatibility
- Numerics
- Detection Idiom