17 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18 #include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22 #ifndef KOKKOS_UNIQUE_TOKEN_HPP
23 #define KOKKOS_UNIQUE_TOKEN_HPP
25 #include <Kokkos_Macros.hpp>
26 #include <Kokkos_MemoryTraits.hpp>
27 #include <Kokkos_Core_fwd.hpp>
30 namespace Experimental {
32 enum class UniqueTokenScope : int { Instance, Global };
39 template <
typename ExecutionSpace = Kokkos::DefaultExecutionSpace,
40 UniqueTokenScope = UniqueTokenScope::Instance>
43 using execution_space = ExecutionSpace;
44 using size_type =
typename execution_space::size_type;
49 UniqueToken(execution_space
const& = execution_space());
52 KOKKOS_INLINE_FUNCTION
53 size_type
size()
const;
56 KOKKOS_INLINE_FUNCTION
60 KOKKOS_INLINE_FUNCTION
69 template <
typename ExecutionSpace>
71 :
public UniqueToken<ExecutionSpace, UniqueTokenScope::Global> {
73 using execution_space = ExecutionSpace;
74 using size_type =
typename execution_space::size_type;
85 UniqueToken(size_type max_size, execution_space
const& = execution_space());
95 template <
typename ExecutionSpace,
96 UniqueTokenScope TokenScope = UniqueTokenScope::Instance>
99 using exec_space = ExecutionSpace;
100 using size_type =
typename exec_space::size_type;
105 size_type my_acquired_val;
109 : my_token(t), my_acquired_val(my_token.acquire()) {}
111 KOKKOS_FUNCTION ~AcquireUniqueToken() { my_token.
release(my_acquired_val); }
113 KOKKOS_FUNCTION size_type value()
const {
return my_acquired_val; }
121 template <
typename TeamPolicy>
124 using exec_space =
typename TeamPolicy::execution_space;
126 using size_type =
typename token_type::size_type;
127 using team_member_type =
typename TeamPolicy::member_type;
129 Kokkos::View<size_type,
typename exec_space::scratch_memory_space,
130 Kokkos::MemoryUnmanaged>;
134 size_type my_acquired_val;
136 team_member_type my_team;
148 KOKKOS_FUNCTION ~AcquireTeamUniqueToken();
149 KOKKOS_FUNCTION size_type value()
const {
return my_acquired_val; }
150 static std::size_t shmem_size() {
return scratch_view::shmem_size(); }
156 #endif // KOKKOS_UNIQUE_TOKEN_HPP
KOKKOS_INLINE_FUNCTION size_type acquire() const
acquire value such that 0 <= value < size()
RAII helper for per-thread unique token values.
class to generate unique ids base on the required amount of concurrency
UniqueToken(execution_space const &=execution_space())
create object size for concurrency on the given instance
KOKKOS_INLINE_FUNCTION void release(size_type) const
release a value acquired by generate
KOKKOS_INLINE_FUNCTION size_type size() const
upper bound for acquired values, i.e. 0 <= value < size()
RAII helper for per-team unique token values.