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
25 #include <type_traits>
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;
59 namespace Experimental {
60 struct 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>;
87 template <
unsigned long pv1,
unsigned long pv2>
88 inline constexpr WorkItemProperty::ImplWorkItemProperty<pv1 | pv2> operator|(
89 WorkItemProperty::ImplWorkItemProperty<pv1>,
90 WorkItemProperty::ImplWorkItemProperty<pv2>) {
91 return WorkItemProperty::ImplWorkItemProperty<pv1 | pv2>();
94 template <
unsigned long pv1,
unsigned long pv2>
95 inline constexpr WorkItemProperty::ImplWorkItemProperty<pv1 & pv2> operator&(
96 WorkItemProperty::ImplWorkItemProperty<pv1>,
97 WorkItemProperty::ImplWorkItemProperty<pv2>) {
98 return WorkItemProperty::ImplWorkItemProperty<pv1 & pv2>();
101 template <
unsigned long pv1,
unsigned long pv2>
102 inline constexpr
bool operator==(WorkItemProperty::ImplWorkItemProperty<pv1>,
103 WorkItemProperty::ImplWorkItemProperty<pv2>) {
113 template <
unsigned int maxT = 0
115 unsigned int minB = 0
120 static constexpr
unsigned int maxTperB{maxT};
121 static constexpr
unsigned int 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;
151 KOKKOS_IMPL_IS_CONCEPT(memory_space)
152 KOKKOS_IMPL_IS_CONCEPT(memory_traits)
153 KOKKOS_IMPL_IS_CONCEPT(execution_space)
154 KOKKOS_IMPL_IS_CONCEPT(execution_policy)
155 KOKKOS_IMPL_IS_CONCEPT(array_layout)
156 KOKKOS_IMPL_IS_CONCEPT(reducer)
157 KOKKOS_IMPL_IS_CONCEPT(team_handle)
158 namespace Experimental {
159 KOKKOS_IMPL_IS_CONCEPT(work_item_property)
160 KOKKOS_IMPL_IS_CONCEPT(hooks_policy)
167 KOKKOS_IMPL_IS_CONCEPT(thread_team_member)
168 KOKKOS_IMPL_IS_CONCEPT(host_thread_team_member)
169 KOKKOS_IMPL_IS_CONCEPT(graph_kernel)
173 #undef KOKKOS_IMPL_IS_CONCEPT
180 template <
class Object>
181 class 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);
196 template <
class Object>
197 class 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);
218 template <
class ExecutionSpace,
class MemorySpace>
220 static_assert(Kokkos::is_execution_space<ExecutionSpace>::value,
221 "Execution space is not valid");
222 static_assert(Kokkos::is_memory_space<MemorySpace>::value,
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>;
231 template <
typename T>
232 struct is_device_helper : std::false_type {};
234 template <
typename ExecutionSpace,
typename MemorySpace>
235 struct is_device_helper<Device<ExecutionSpace, MemorySpace>> : std::true_type {
240 template <
typename T>
241 using is_device =
typename Impl::is_device_helper<std::remove_cv_t<T>>::type;
243 template <
typename T>
244 inline constexpr
bool is_device_v = is_device<T>::value;
248 template <
typename T>
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>;
347 template <
typename DstMemorySpace,
typename SrcMemorySpace>
349 static_assert(Kokkos::is_memory_space<DstMemorySpace>::value &&
350 Kokkos::is_memory_space<SrcMemorySpace>::value,
351 "template arguments must be memory spaces");
360 enum { assignable = std::is_same<DstMemorySpace, SrcMemorySpace>::value };
365 enum { accessible = assignable };
370 enum { deepcopy = assignable };
397 template <
typename AccessSpace,
typename MemorySpace>
400 static_assert(Kokkos::is_space<AccessSpace>::value,
401 "template argument #1 must be a Kokkos space");
403 static_assert(Kokkos::is_memory_space<MemorySpace>::value,
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 };
434 assignable = is_memory_space<AccessSpace>::value && mem_access::assignable
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,
448 Kokkos::Device<typename AccessSpace::execution_space, MemorySpace>>;
455 #endif // KOKKOS_CORE_CONCEPTS_HPP
Can AccessSpace access MemorySpace ?
Memory management for host memory.
Specify Launch Bounds for CUDA execution.
Access relationship between DstMemorySpace and SrcMemorySpace.