45 #ifndef KOKKOS_CORE_CONCEPTS_HPP 46 #define KOKKOS_CORE_CONCEPTS_HPP 48 #include <type_traits> 51 #include <Kokkos_Core_fwd.hpp> 65 static_assert(std::is_same<T, Static>::value ||
66 std::is_same<T, Dynamic>::value,
67 "Kokkos: Invalid Schedule<> type.");
68 using schedule_type = Schedule;
75 static_assert(std::is_integral<T>::value,
"Kokkos: Invalid IndexType<>.");
76 using index_type = IndexType;
81 struct WorkItemProperty {
82 template <
unsigned long Property>
83 struct ImplWorkItemProperty {
84 static const unsigned value = Property;
85 using work_item_property = ImplWorkItemProperty<Property>;
88 constexpr
static const ImplWorkItemProperty<0>
None =
89 ImplWorkItemProperty<0>();
90 constexpr
static const ImplWorkItemProperty<1> HintLightWeight =
91 ImplWorkItemProperty<1>();
92 constexpr
static const ImplWorkItemProperty<2> HintHeavyWeight =
93 ImplWorkItemProperty<2>();
94 constexpr
static const ImplWorkItemProperty<4> HintRegular =
95 ImplWorkItemProperty<4>();
96 constexpr
static const ImplWorkItemProperty<8> HintIrregular =
97 ImplWorkItemProperty<8>();
98 using None_t = ImplWorkItemProperty<0>;
99 using HintLightWeight_t = ImplWorkItemProperty<1>;
100 using HintHeavyWeight_t = ImplWorkItemProperty<2>;
101 using HintRegular_t = ImplWorkItemProperty<4>;
102 using HintIrregular_t = ImplWorkItemProperty<8>;
105 template <
unsigned long pv1,
unsigned long pv2>
106 inline constexpr WorkItemProperty::ImplWorkItemProperty<pv1 | pv2> operator|(
107 WorkItemProperty::ImplWorkItemProperty<pv1>,
108 WorkItemProperty::ImplWorkItemProperty<pv2>) {
109 return WorkItemProperty::ImplWorkItemProperty<pv1 | pv2>();
112 template <
unsigned long pv1,
unsigned long pv2>
113 inline constexpr WorkItemProperty::ImplWorkItemProperty<pv1 & pv2> operator&(
114 WorkItemProperty::ImplWorkItemProperty<pv1>,
115 WorkItemProperty::ImplWorkItemProperty<pv2>) {
116 return WorkItemProperty::ImplWorkItemProperty<pv1 & pv2>();
119 template <
unsigned long pv1,
unsigned long pv2>
120 inline constexpr
bool operator==(WorkItemProperty::ImplWorkItemProperty<pv1>,
121 WorkItemProperty::ImplWorkItemProperty<pv2>) {
131 template <
unsigned int maxT = 0
133 unsigned int minB = 0
138 static unsigned int constexpr maxTperB{maxT};
139 static unsigned int constexpr minBperSM{minB};
149 #define KOKKOS_IMPL_IS_CONCEPT(CONCEPT) \ 150 template <typename T> \ 151 struct is_##CONCEPT { \ 153 template <typename, typename = std::true_type> \ 154 struct have : std::false_type {}; \ 155 template <typename U> \ 156 struct have<U, typename std::is_base_of<typename U::CONCEPT, U>::type> \ 157 : std::true_type {}; \ 158 template <typename U> \ 160 typename std::is_base_of<typename U::CONCEPT##_type, U>::type> \ 161 : std::true_type {}; \ 164 static constexpr bool value = \ 165 is_##CONCEPT::template have<typename std::remove_cv<T>::type>::value; \ 166 constexpr operator bool() const noexcept { return value; } \ 171 KOKKOS_IMPL_IS_CONCEPT(memory_space)
172 KOKKOS_IMPL_IS_CONCEPT(memory_traits)
173 KOKKOS_IMPL_IS_CONCEPT(execution_space)
174 KOKKOS_IMPL_IS_CONCEPT(execution_policy)
175 KOKKOS_IMPL_IS_CONCEPT(array_layout)
176 KOKKOS_IMPL_IS_CONCEPT(reducer)
178 KOKKOS_IMPL_IS_CONCEPT(work_item_property)
185 using Kokkos::is_array_layout;
186 using Kokkos::is_execution_policy;
187 using Kokkos::is_execution_space;
188 using Kokkos::is_memory_space;
189 using Kokkos::is_memory_traits;
193 KOKKOS_IMPL_IS_CONCEPT(iteration_pattern)
194 KOKKOS_IMPL_IS_CONCEPT(schedule_type)
195 KOKKOS_IMPL_IS_CONCEPT(index_type)
196 KOKKOS_IMPL_IS_CONCEPT(launch_bounds)
197 KOKKOS_IMPL_IS_CONCEPT(thread_team_member)
198 KOKKOS_IMPL_IS_CONCEPT(host_thread_team_member)
199 KOKKOS_IMPL_IS_CONCEPT(graph_kernel)
203 #undef KOKKOS_IMPL_IS_CONCEPT 210 template <
class Object>
211 class has_member_team_shmem_size {
212 template <
typename T>
213 static int32_t test_for_member(decltype(&T::team_shmem_size)) {
216 template <
typename T>
217 static int64_t test_for_member(...) {
222 constexpr
static bool value =
223 sizeof(test_for_member<Object>(
nullptr)) ==
sizeof(int32_t);
226 template <
class Object>
227 class has_member_shmem_size {
228 template <
typename T>
229 static int32_t test_for_member(decltype(&T::shmem_size_me)) {
232 template <
typename T>
233 static int64_t test_for_member(...) {
238 constexpr
static bool value =
239 sizeof(test_for_member<Object>(0)) ==
sizeof(int32_t);
248 template <
class ExecutionSpace,
class MemorySpace>
250 static_assert(Kokkos::is_execution_space<ExecutionSpace>::value,
251 "Execution space is not valid");
252 static_assert(Kokkos::is_memory_space<MemorySpace>::value,
253 "Memory space is not valid");
254 using execution_space = ExecutionSpace;
255 using memory_space = MemorySpace;
256 using device_type = Device<execution_space, memory_space>;
261 template <
typename T>
262 struct is_device_helper : std::false_type {};
264 template <
typename ExecutionSpace,
typename MemorySpace>
265 struct is_device_helper<Device<ExecutionSpace, MemorySpace>> : std::true_type {
270 template <
typename T>
272 typename Impl::is_device_helper<typename std::remove_cv<T>::type>::type;
276 template <
typename T>
279 template <
typename,
typename =
void>
280 struct exe : std::false_type {
284 template <
typename,
typename =
void>
285 struct mem : std::false_type {
289 template <
typename,
typename =
void>
290 struct dev : std::false_type {
294 template <
typename U>
295 struct exe<U, typename std::conditional<true, void,
296 typename U::execution_space>::type>
297 : std::is_same<U, typename U::execution_space>::type {
298 using space =
typename U::execution_space;
301 template <
typename U>
303 U, typename std::conditional<true, void, typename U::memory_space>::type>
304 : std::is_same<U, typename U::memory_space>::type {
305 using space =
typename U::memory_space;
308 template <
typename U>
310 U, typename std::conditional<true, void, typename U::device_type>::type>
311 : std::is_same<U, typename U::device_type>::type {
312 using space =
typename U::device_type;
316 typename is_space<T>::template exe<typename std::remove_cv<T>::type>;
318 typename is_space<T>::template mem<typename std::remove_cv<T>::type>;
320 typename is_space<T>::template dev<typename std::remove_cv<T>::type>;
323 static constexpr
bool value = is_exe::value || is_mem::value || is_dev::value;
325 constexpr
operator bool() const noexcept {
return value; }
327 using execution_space =
typename is_exe::space;
328 using memory_space =
typename is_mem::space;
333 using host_memory_space =
typename std::conditional<
334 std::is_same<memory_space, Kokkos::HostSpace>::value
335 #if defined(KOKKOS_ENABLE_CUDA) 336 || std::is_same<memory_space, Kokkos::CudaUVMSpace>::value ||
337 std::is_same<memory_space, Kokkos::CudaHostPinnedSpace>::value
342 #if defined(KOKKOS_ENABLE_CUDA) 343 using host_execution_space =
typename std::conditional<
344 std::is_same<execution_space, Kokkos::Cuda>::value,
345 Kokkos::DefaultHostExecutionSpace, execution_space>::type;
347 #if defined(KOKKOS_ENABLE_OPENMPTARGET) 348 using host_execution_space =
typename std::conditional<
349 std::is_same<execution_space, Kokkos::Experimental::OpenMPTarget>::value,
350 Kokkos::DefaultHostExecutionSpace, execution_space>::type;
352 using host_execution_space = execution_space;
356 using host_mirror_space =
typename std::conditional<
357 std::is_same<execution_space, host_execution_space>::value &&
358 std::is_same<memory_space, host_memory_space>::value,
359 T, Kokkos::Device<host_execution_space, host_memory_space>>::type;
366 using Kokkos::is_space;
382 template <
typename DstMemorySpace,
typename SrcMemorySpace>
384 static_assert(Kokkos::is_memory_space<DstMemorySpace>::value &&
385 Kokkos::is_memory_space<SrcMemorySpace>::value,
386 "template arguments must be memory spaces");
395 enum { assignable = std::is_same<DstMemorySpace, SrcMemorySpace>::value };
400 enum { accessible = assignable };
405 enum { deepcopy = assignable };
432 template <
typename AccessSpace,
typename MemorySpace>
435 static_assert(Kokkos::is_space<AccessSpace>::value,
436 "template argument #1 must be a Kokkos space");
438 static_assert(Kokkos::is_memory_space<MemorySpace>::value,
439 "template argument #2 must be a Kokkos memory space");
444 typename AccessSpace::execution_space::memory_space,
445 typename AccessSpace::memory_space>::accessible,
446 "template argument #1 is an invalid space");
449 typename AccessSpace::execution_space::memory_space, MemorySpace>;
461 enum { accessible = exe_access::accessible };
469 assignable = is_memory_space<AccessSpace>::value && mem_access::assignable
473 enum { deepcopy = mem_access::deepcopy };
479 using space =
typename std::conditional<
480 std::is_same<typename AccessSpace::memory_space, MemorySpace>::value ||
481 !exe_access::accessible,
483 Kokkos::Device<typename AccessSpace::execution_space, MemorySpace>>::type;
498 #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.