User-exposed API of Cooperative groups

User-exposed API of Cooperative groups#

HIP Runtime API Reference: User-exposed API of Cooperative groups
User-exposed API of Cooperative groups
Collaboration diagram for User-exposed API of Cooperative groups:

Functions

template<class CGTy >
__hip_uint32_t cooperative_groups::group_size (CGTy const &g)
 Returns the size of the group.
 
template<class CGTy >
__hip_uint32_t cooperative_groups::thread_rank (CGTy const &g)
 Returns the rank of thread of the group.
 
template<class CGTy >
bool cooperative_groups::is_valid (CGTy const &g)
 Returns true if the group has not violated any API constraints.
 
template<class CGTy >
void cooperative_groups::sync (CGTy const &g)
 Synchronizes the threads in the group.
 
template<typename Group , typename Fn , typename... Args>
void cooperative_groups::invoke_one (const Group &g, Fn &&fn, Args &&... args)
 Calls an invocable on a single thread of the group.
 
template<typename Fn , typename... Args>
auto cooperative_groups::invoke_one_broadcast (const coalesced_group &g, Fn &&fn, Args &&... args) -> typename __hip_internal::remove_reference< decltype(impl::forward< Fn >(fn)(impl::forward< Args >(args)...))>::type
 Calls an invocable on a single thread of the group and broadcasts the result.
 
template<unsigned int Size, typename Parent , typename Fn , typename... Args>
auto cooperative_groups::invoke_one_broadcast (const thread_block_tile< Size, Parent > &g, Fn &&fn, Args &&... args) -> typename __hip_internal::remove_reference< decltype(impl::forward< Fn >(fn)(impl::forward< Args >(args)...))>::type
 Calls an invocable on a single thread of the group and broadcasts the result.
 

Detailed Description

Function Documentation

◆ group_size()

template<class CGTy >
__hip_uint32_t cooperative_groups::group_size ( CGTy const &  g)

Returns the size of the group.

Total number of threads in the thread group, and this serves the purpose for all derived cooperative group types because their size is directly saved during the construction.

Template Parameters
CGTyThe cooperative group class template parameter.
Parameters
g[in] The cooperative group for size returns.
Note
Implementation of publicly exposed wrapper API on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.

◆ invoke_one()

template<typename Group , typename Fn , typename... Args>
void cooperative_groups::invoke_one ( const Group &  g,
Fn &&  fn,
Args &&...  args 
)

Calls an invocable on a single thread of the group.

Selects one thread of the group and uses it to call the supplied function with specified arguments. All group types are supported. The group is not synchronized, so communication or synchronization within the calling group is not allowed inside function.

Template Parameters
GroupThe cooperative group class template parameter.
FnThe type of the invocable.
ArgsThe types of the arguments of the invocable.
Parameters
g[in] The group to select the thread from.
fn[in] The invocable called by the selected thread.
args[in] The arguments passed to the invocable.

◆ invoke_one_broadcast() [1/2]

template<typename Fn , typename... Args>
auto cooperative_groups::invoke_one_broadcast ( const coalesced_group &  g,
Fn &&  fn,
Args &&...  args 
) -> typename __hip_internal::remove_reference<decltype(impl::forward<Fn>(fn)( impl::forward<Args>(args)...))>::type

Calls an invocable on a single thread of the group and broadcasts the result.

Selects one thread of the group and uses it to call the supplied function with specified arguments and then, distributes the returned value to all threads of the group. The group is not synchronized, so communication or synchronization within the calling group is not allowed inside function. The return type of the function must be trivially copyable and at most 32 bytes in size.

Template Parameters
FnThe type of the invocable.
ArgsThe types of the arguments of the invocable.
Parameters
g[in] The group to select the thread from.
fn[in] The invocable called by the selected thread.
args[in] The arguments passed to the invocable.

◆ invoke_one_broadcast() [2/2]

template<unsigned int Size, typename Parent , typename Fn , typename... Args>
auto cooperative_groups::invoke_one_broadcast ( const thread_block_tile< Size, Parent > &  g,
Fn &&  fn,
Args &&...  args 
) -> typename __hip_internal::remove_reference<decltype(impl::forward<Fn>(fn)( impl::forward<Args>(args)...))>::type

Calls an invocable on a single thread of the group and broadcasts the result.

Selects one thread of the group and uses it to call the supplied function with specified arguments and then, distributes the returned value to all threads of the group. The group is not synchronized, so communication or synchronization within the calling group is not allowed inside function. The return type of the function must be trivially copyable and at most 32 bytes in size.

Template Parameters
SizeThe size of the thread block tile group.
ParentThe cooperative group class template parameter of the input group.
FnThe type of the invocable.
ArgsThe types of the arguments of the invocable.
Parameters
g[in] The group to select the thread from.
fn[in] The invocable called by the selected thread.
args[in] The arguments passed to the invocable.

◆ is_valid()

template<class CGTy >
bool cooperative_groups::is_valid ( CGTy const &  g)

Returns true if the group has not violated any API constraints.

Template Parameters
CGTyThe cooperative group class template parameter.
Parameters
g[in] The cooperative group for validity check.
Note
Implementation of publicly exposed wrapper API on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.

◆ sync()

template<class CGTy >
void cooperative_groups::sync ( CGTy const &  g)

Synchronizes the threads in the group.

Template Parameters
CGTyThe cooperative group class template parameter.
Parameters
g[in] The cooperative group for synchronization.
Note
Implementation of publicly exposed wrapper API on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.

◆ thread_rank()

template<class CGTy >
__hip_uint32_t cooperative_groups::thread_rank ( CGTy const &  g)

Returns the rank of thread of the group.

Rank of the calling thread within [0, num_threads() ).

Template Parameters
CGTyThe cooperative group class template parameter.
Parameters
g[in] The cooperative group for rank returns.
Note
Implementation of publicly exposed wrapper API on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.