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()
| __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
-
CGTy The cooperative group class template parameter.
- Parameters
-
g [in] The cooperative group for size returns.
- Note
- Implementation of publicly exposed
wrapperAPI on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.
◆ invoke_one()
| 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
-
Group The cooperative group class template parameter. Fn The type of the invocable. Args The 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]
| 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
-
Fn The type of the invocable. Args The 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]
| 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
-
Size The size of the thread block tile group. Parent The cooperative group class template parameter of the input group. Fn The type of the invocable. Args The 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()
| bool cooperative_groups::is_valid | ( | CGTy const & | g | ) |
Returns true if the group has not violated any API constraints.
- Template Parameters
-
CGTy The cooperative group class template parameter.
- Parameters
-
g [in] The cooperative group for validity check.
- Note
- Implementation of publicly exposed
wrapperAPI on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.
◆ sync()
| void cooperative_groups::sync | ( | CGTy const & | g | ) |
Synchronizes the threads in the group.
- Template Parameters
-
CGTy The cooperative group class template parameter.
- Parameters
-
g [in] The cooperative group for synchronization.
- Note
- Implementation of publicly exposed
wrapperAPI on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.
◆ thread_rank()
| __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
-
CGTy The cooperative group class template parameter.
- Parameters
-
g [in] The cooperative group for rank returns.
- Note
- Implementation of publicly exposed
wrapperAPI on top of basic cooperative group type APIs. This function is implemented on Linux and is under development on Microsoft Windows.