17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22#ifndef KOKKOS_CORE_CONCEPTS_HPP
23#define KOKKOS_CORE_CONCEPTS_HPP
28#include <Kokkos_Core_fwd.hpp>
30#include <Kokkos_DetectionIdiom.hpp>
44 static_assert(std::is_same<T, Static>::value ||
45 std::is_same<T, Dynamic>::value,
46 "Kokkos: Invalid Schedule<> type.");
47 using schedule_type = Schedule;
54 static_assert(std::is_integral<T>::value,
"Kokkos: Invalid IndexType<>.");
55 using index_type = IndexType;
60struct WorkItemProperty {
61 template <
unsigned long Property>
62 struct ImplWorkItemProperty {
63 static const unsigned value = Property;
64 using work_item_property = ImplWorkItemProperty<Property>;
67 constexpr static const ImplWorkItemProperty<0> None =
68 ImplWorkItemProperty<0>();
69 constexpr static const ImplWorkItemProperty<1> HintLightWeight =
70 ImplWorkItemProperty<1>();
71 constexpr static const ImplWorkItemProperty<2> HintHeavyWeight =
72 ImplWorkItemProperty<2>();
73 constexpr static const ImplWorkItemProperty<4> HintRegular =
74 ImplWorkItemProperty<4>();
75 constexpr static const ImplWorkItemProperty<8> HintIrregular =
76 ImplWorkItemProperty<8>();
77 constexpr static const ImplWorkItemProperty<16> ImplForceGlobalLaunch =
78 ImplWorkItemProperty<16>();
79 using None_t = ImplWorkItemProperty<0>;
80 using HintLightWeight_t = ImplWorkItemProperty<1>;
81 using HintHeavyWeight_t = ImplWorkItemProperty<2>;
82 using HintRegular_t = ImplWorkItemProperty<4>;
83 using HintIrregular_t = ImplWorkItemProperty<8>;
84 using ImplForceGlobalLaunch_t = ImplWorkItemProperty<16>;
87template <
unsigned long pv1,
unsigned long pv2>
88inline constexpr WorkItemProperty::ImplWorkItemProperty<pv1 | pv2> operator|(
89 WorkItemProperty::ImplWorkItemProperty<pv1>,
90 WorkItemProperty::ImplWorkItemProperty<pv2>) {
91 return WorkItemProperty::ImplWorkItemProperty<pv1 | pv2>();
94template <
unsigned long pv1,
unsigned long pv2>
95inline constexpr WorkItemProperty::ImplWorkItemProperty<pv1 & pv2> operator&(
96 WorkItemProperty::ImplWorkItemProperty<pv1>,
97 WorkItemProperty::ImplWorkItemProperty<pv2>) {
98 return WorkItemProperty::ImplWorkItemProperty<pv1 & pv2>();
101template <
unsigned long pv1,
unsigned long pv2>
102inline constexpr bool operator==(WorkItemProperty::ImplWorkItemProperty<pv1>,
103 WorkItemProperty::ImplWorkItemProperty<pv2>) {
113template <
unsigned int maxT = 0
115 unsigned int minB = 0
120 static unsigned int constexpr maxTperB{
maxT};
121 static unsigned int constexpr minBperSM{
minB};
131#define KOKKOS_IMPL_IS_CONCEPT(CONCEPT) \
132 template <typename T> \
133 struct is_##CONCEPT { \
135 template <typename U> \
136 using have_t = typename U::CONCEPT; \
137 template <typename U> \
138 using have_type_t = typename U::CONCEPT##_type; \
141 static constexpr bool value = \
142 std::is_base_of<detected_t<have_t, T>, T>::value || \
143 std::is_base_of<detected_t<have_type_t, T>, T>::value; \
144 constexpr operator bool() const noexcept { return value; } \
146 template <typename T> \
147 inline constexpr bool is_##CONCEPT##_v = is_##CONCEPT<T>::value;
151KOKKOS_IMPL_IS_CONCEPT(memory_space)
152KOKKOS_IMPL_IS_CONCEPT(memory_traits)
153KOKKOS_IMPL_IS_CONCEPT(execution_space)
154KOKKOS_IMPL_IS_CONCEPT(execution_policy)
155KOKKOS_IMPL_IS_CONCEPT(array_layout)
156KOKKOS_IMPL_IS_CONCEPT(reducer)
157KOKKOS_IMPL_IS_CONCEPT(team_handle)
159KOKKOS_IMPL_IS_CONCEPT(work_item_property)
160KOKKOS_IMPL_IS_CONCEPT(hooks_policy)
167KOKKOS_IMPL_IS_CONCEPT(thread_team_member)
168KOKKOS_IMPL_IS_CONCEPT(host_thread_team_member)
169KOKKOS_IMPL_IS_CONCEPT(graph_kernel)
173#undef KOKKOS_IMPL_IS_CONCEPT
180template <
class Object>
181class has_member_team_shmem_size {
182 template <
typename T>
183 static int32_t test_for_member(
decltype(&T::team_shmem_size)) {
186 template <
typename T>
187 static int64_t test_for_member(...) {
192 constexpr static bool value =
193 sizeof(test_for_member<Object>(
nullptr)) ==
sizeof(int32_t);
196template <
class Object>
197class has_member_shmem_size {
198 template <
typename T>
199 static int32_t test_for_member(
decltype(&T::shmem_size_me)) {
202 template <
typename T>
203 static int64_t test_for_member(...) {
208 constexpr static bool value =
209 sizeof(test_for_member<Object>(0)) ==
sizeof(int32_t);
218template <
class ExecutionSpace,
class MemorySpace>
221 "Execution space is not valid");
223 "Memory space is not valid");
224 using execution_space = ExecutionSpace;
225 using memory_space = MemorySpace;
226 using device_type = Device<execution_space, memory_space>;
232struct is_device_helper : std::false_type {};
234template <
typename ExecutionSpace,
typename MemorySpace>
235struct is_device_helper<Device<ExecutionSpace, MemorySpace>> : std::true_type {
241using is_device =
typename Impl::is_device_helper<std::remove_cv_t<T>>::type;
244inline constexpr bool is_device_v = is_device<T>::value;
251 template <
typename,
typename =
void>
252 struct exe : std::false_type {
256 template <
typename,
typename =
void>
257 struct mem : std::false_type {
261 template <
typename,
typename =
void>
262 struct dev : std::false_type {
266 template <
typename U>
267 struct exe<U, std::conditional_t<true, void, typename U::execution_space>>
268 : std::is_same<U, typename U::execution_space>::type {
269 using space =
typename U::execution_space;
272 template <
typename U>
273 struct mem<U, std::conditional_t<true, void, typename U::memory_space>>
274 : std::is_same<U, typename U::memory_space>::type {
275 using space =
typename U::memory_space;
278 template <
typename U>
279 struct dev<U, std::conditional_t<true, void, typename U::device_type>>
280 : std::is_same<U, typename U::device_type>::type {
281 using space =
typename U::device_type;
284 using is_exe =
typename is_space<T>::template exe<std::remove_cv_t<T>>;
285 using is_mem =
typename is_space<T>::template mem<std::remove_cv_t<T>>;
286 using is_dev =
typename is_space<T>::template dev<std::remove_cv_t<T>>;
289 static constexpr bool value = is_exe::value || is_mem::value || is_dev::value;
291 constexpr operator bool() const noexcept {
return value; }
293 using execution_space =
typename is_exe::space;
294 using memory_space =
typename is_mem::space;
303 using do_not_use_host_memory_space = std::conditional_t<
304 std::is_same<memory_space, Kokkos::HostSpace>::value
305#if defined(KOKKOS_ENABLE_CUDA)
306 || std::is_same<memory_space, Kokkos::CudaUVMSpace>::value ||
307 std::is_same<memory_space, Kokkos::CudaHostPinnedSpace>::value
308#elif defined(KOKKOS_ENABLE_HIP)
309 || std::is_same<memory_space, Kokkos::HIPHostPinnedSpace>::value ||
310 std::is_same<memory_space, Kokkos::HIPManagedSpace>::value
311#elif defined(KOKKOS_ENABLE_SYCL)
312 || std::is_same<memory_space,
313 Kokkos::Experimental::SYCLSharedUSMSpace>::value ||
314 std::is_same<memory_space,
315 Kokkos::Experimental::SYCLHostUSMSpace>::value
320 using do_not_use_host_execution_space = std::conditional_t<
321#if defined(KOKKOS_ENABLE_CUDA)
322 std::is_same<execution_space, Kokkos::Cuda>::value ||
323#elif defined(KOKKOS_ENABLE_HIP)
324 std::is_same<execution_space, Kokkos::HIP>::value ||
325#elif defined(KOKKOS_ENABLE_SYCL)
326 std::is_same<execution_space, Kokkos::Experimental::SYCL>::value ||
327#elif defined(KOKKOS_ENABLE_OPENMPTARGET)
328 std::is_same<execution_space,
329 Kokkos::Experimental::OpenMPTarget>::value ||
332 Kokkos::DefaultHostExecutionSpace, execution_space>;
347template <
typename DstMemorySpace,
typename SrcMemorySpace>
351 "template arguments must be memory spaces");
360 enum { assignable = std::is_same<DstMemorySpace, SrcMemorySpace>::value };
365 enum { accessible = assignable };
370 enum { deepcopy = assignable };
397template <
typename AccessSpace,
typename MemorySpace>
400 static_assert(Kokkos::is_space<AccessSpace>::value,
401 "template argument #1 must be a Kokkos space");
404 "template argument #2 must be a Kokkos memory space");
409 typename AccessSpace::execution_space::memory_space,
410 typename AccessSpace::memory_space>::accessible,
411 "template argument #1 is an invalid space");
414 typename AccessSpace::execution_space::memory_space, MemorySpace>;
426 enum { accessible = exe_access::accessible };
438 enum { deepcopy = mem_access::deepcopy };
444 using space = std::conditional_t<
445 std::is_same<typename AccessSpace::memory_space, MemorySpace>::value ||
446 !exe_access::accessible,
A thread safe view to a bitset.
Memory management for host memory.
Access relationship between DstMemorySpace and SrcMemorySpace.
Specify Launch Bounds for CUDA execution.
Can AccessSpace access MemorySpace ?