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;
80 namespace Experimental {
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 typedef ImplWorkItemProperty<0> None_t;
99 typedef ImplWorkItemProperty<1> HintLightWeight_t;
100 typedef ImplWorkItemProperty<2> HintHeavyWeight_t;
101 typedef ImplWorkItemProperty<4> HintRegular_t;
102 typedef ImplWorkItemProperty<8> HintIrregular_t;
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)
177 namespace Experimental {
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)
202 #undef KOKKOS_IMPL_IS_CONCEPT
209 template <
class Object>
210 class has_member_team_shmem_size {
211 template <
typename T>
212 static int32_t test_for_member(decltype(&T::team_shmem_size)) {
215 template <
typename T>
216 static int64_t test_for_member(...) {
221 constexpr
static bool value =
222 sizeof(test_for_member<Object>(0)) ==
sizeof(int32_t);
225 template <
class Object>
226 class has_member_shmem_size {
227 template <
typename T>
228 static int32_t test_for_member(decltype(&T::shmem_size_me)) {
231 template <
typename T>
232 static int64_t test_for_member(...) {
237 constexpr
static bool value =
238 sizeof(test_for_member<Object>(0)) ==
sizeof(int32_t);
247 template <
class ExecutionSpace,
class MemorySpace>
249 static_assert(Kokkos::is_execution_space<ExecutionSpace>::value,
250 "Execution space is not valid");
251 static_assert(Kokkos::is_memory_space<MemorySpace>::value,
252 "Memory space is not valid");
253 typedef ExecutionSpace execution_space;
254 typedef MemorySpace memory_space;
255 typedef Device<execution_space, memory_space> device_type;
260 template <
typename T>
261 struct is_device_helper : std::false_type {};
263 template <
typename ExecutionSpace,
typename MemorySpace>
264 struct is_device_helper<Device<ExecutionSpace, MemorySpace>> : std::true_type {
269 template <
typename T>
271 typename Impl::is_device_helper<typename std::remove_cv<T>::type>::type;
275 template <
typename T>
278 template <
typename,
typename =
void>
279 struct exe : std::false_type {
283 template <
typename,
typename =
void>
284 struct mem : std::false_type {
288 template <
typename,
typename =
void>
289 struct dev : std::false_type {
293 template <
typename U>
294 struct exe<U, typename std::conditional<true, void,
295 typename U::execution_space>::type>
296 : std::is_same<U, typename U::execution_space>::type {
297 typedef typename U::execution_space space;
300 template <
typename U>
302 U, typename std::conditional<true, void, typename U::memory_space>::type>
303 : std::is_same<U, typename U::memory_space>::type {
304 typedef typename U::memory_space space;
307 template <
typename U>
309 U, typename std::conditional<true, void, typename U::device_type>::type>
310 : std::is_same<U, typename U::device_type>::type {
311 typedef typename U::device_type space;
314 typedef typename is_space::template exe<typename std::remove_cv<T>::type>
316 typedef typename is_space::template mem<typename std::remove_cv<T>::type>
318 typedef typename is_space::template dev<typename std::remove_cv<T>::type>
322 static constexpr
bool value = is_exe::value || is_mem::value || is_dev::value;
324 constexpr
operator bool() const noexcept {
return value; }
326 typedef typename is_exe::space execution_space;
327 typedef typename is_mem::space memory_space;
332 typedef typename std::conditional<
333 std::is_same<memory_space, Kokkos::HostSpace>::value
334 #if defined(KOKKOS_ENABLE_CUDA)
335 || std::is_same<memory_space, Kokkos::CudaUVMSpace>::value ||
336 std::is_same<memory_space, Kokkos::CudaHostPinnedSpace>::value
341 #if defined(KOKKOS_ENABLE_CUDA)
342 typedef typename std::conditional<
343 std::is_same<execution_space, Kokkos::Cuda>::value,
344 Kokkos::DefaultHostExecutionSpace, execution_space>::type
345 host_execution_space;
347 #if defined(KOKKOS_ENABLE_OPENMPTARGET)
348 typedef typename std::conditional<
349 std::is_same<execution_space, Kokkos::Experimental::OpenMPTarget>::value,
350 Kokkos::DefaultHostExecutionSpace, execution_space>::type
351 host_execution_space;
353 typedef execution_space host_execution_space;
357 typedef typename std::conditional<
358 std::is_same<execution_space, host_execution_space>::value &&
359 std::is_same<memory_space, host_memory_space>::value,
360 T, Kokkos::Device<host_execution_space, host_memory_space>>::type
368 using Kokkos::is_space;
384 template <
typename DstMemorySpace,
typename SrcMemorySpace>
386 static_assert(Kokkos::is_memory_space<DstMemorySpace>::value &&
387 Kokkos::is_memory_space<SrcMemorySpace>::value,
388 "template arguments must be memory spaces");
397 enum { assignable = std::is_same<DstMemorySpace, SrcMemorySpace>::value };
402 enum { accessible = assignable };
407 enum { deepcopy = assignable };
434 template <
typename AccessSpace,
typename MemorySpace>
437 static_assert(Kokkos::is_space<AccessSpace>::value,
438 "template argument #1 must be a Kokkos space");
440 static_assert(Kokkos::is_memory_space<MemorySpace>::value,
441 "template argument #2 must be a Kokkos memory space");
446 typename AccessSpace::execution_space::memory_space,
447 typename AccessSpace::memory_space>::accessible,
448 "template argument #1 is an invalid space");
451 typename AccessSpace::execution_space::memory_space, MemorySpace>
464 enum { accessible = exe_access::accessible };
472 assignable = is_memory_space<AccessSpace>::value && mem_access::assignable
476 enum { deepcopy = mem_access::deepcopy };
482 typedef typename std::conditional<
483 std::is_same<typename AccessSpace::memory_space, MemorySpace>::value ||
484 !exe_access::accessible,
486 Kokkos::Device<typename AccessSpace::execution_space, MemorySpace>>::type
502 #endif // KOKKOS_CORE_CONCEPTS_HPP
KOKKOS_INLINE_FUNCTION bool operator==(complex< RealType1 > const &x, complex< RealType2 > const &y) noexcept
Binary == operator for complex complex.
Can AccessSpace access MemorySpace ?
Memory management for host memory.
Specify Launch Bounds for CUDA execution.
Access relationship between DstMemorySpace and SrcMemorySpace.