Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Morpheus_SpaceTraits.hpp
1
23#ifndef MORPHEUS_SPACETRAITS_HPP
24#define MORPHEUS_SPACETRAITS_HPP
25
26#include <Kokkos_Core.hpp>
27
28#include <type_traits>
29
30namespace Morpheus {
31
45template <class T>
47 typedef char yes[1];
48 typedef char no[2];
49
50 template <class U>
51 static yes& test(
52 U*, typename std::enable_if<std::is_same<U, Kokkos::HostSpace>::value ||
53#if defined(MORPHEUS_ENABLE_CUDA)
54 std::is_same<U, Kokkos::CudaSpace>::value ||
55#elif defined(MORPHEUS_ENABLE_HIP)
56 std::is_same<U, Kokkos::HIPSpace>::value ||
57#endif
58 false>::type* = nullptr);
59
60 template <class U>
61 static no& test(...);
62
63 public:
64 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
65};
66
72template <typename T>
74
80template <class T>
82 typedef char yes[1];
83 typedef char no[2];
84
85 template <class U>
86 static yes& test(
87 U*, typename std::enable_if<
88 is_memory_space_v<typename U::memory_space>>::type* = nullptr);
89
90 template <class U>
91 static no& test(...);
92
93 public:
94 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
95};
96
102template <typename T>
104
110template <class T>
112 typedef char yes[1];
113 typedef char no[2];
114
115 template <class U>
116 static yes& test(
117 U*, typename std::enable_if<
118 std::is_same<U, Kokkos::DefaultHostExecutionSpace>::value ||
119 std::is_same<U, Kokkos::DefaultExecutionSpace>::value ||
120#if defined(MORPHEUS_ENABLE_SERIAL)
121 std::is_same<U, Kokkos::Serial>::value ||
122#endif
123#if defined(MORPHEUS_ENABLE_OPENMP)
124 std::is_same<U, Kokkos::OpenMP>::value ||
125#endif
126#if defined(MORPHEUS_ENABLE_CUDA)
127 std::is_same<U, Kokkos::Cuda>::value ||
128#elif defined(MORPHEUS_ENABLE_HIP)
129 std::is_same<U, Kokkos::Experimental::HIP>::value ||
130#endif
131 false>::type* = nullptr);
132
133 template <class U>
134 static no& test(...);
135
136 public:
137 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
138};
139
145template <typename T>
147
153template <class T>
155 typedef char yes[1];
156 typedef char no[2];
157
158 template <class U>
159 static yes& test(
160 U*,
161 typename std::enable_if<
162 is_execution_space_v<typename U::execution_space>>::type* = nullptr);
163
164 template <class U>
165 static no& test(...);
166
167 public:
168 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
169};
170
176template <typename T>
178
185template <class T1, class T2>
187 typedef char yes[1];
188 typedef char no[2];
189
190 template <class U1, class U2>
191 static yes& test(
192 U1*, U2*,
193 typename std::enable_if<is_memory_space<U1>::value &&
195 std::is_same<U1, U2>::value>::type* = nullptr);
196
197 template <class U1, class U2>
198 static no& test(...);
199
200 public:
201 static const bool value =
202 sizeof(test<T1, T2>(nullptr, nullptr)) == sizeof(yes);
203};
204
211template <typename T1, typename T2>
212inline constexpr bool is_same_memory_space_v =
214
221template <class T1, class T2>
223 typedef char yes[1];
224 typedef char no[2];
225
226 template <class U1, class U2>
227 static yes& test(
228 U1*, U2*,
229 typename std::enable_if<is_same_memory_space<
230 typename U1::memory_space, typename U2::memory_space>::value>::type* =
231 nullptr);
232
233 template <class U1, class U2>
234 static no& test(...);
235
236 public:
237 static const bool value =
238 sizeof(test<T1, T2>(nullptr, nullptr)) == sizeof(yes);
239};
240
247template <typename T1, typename T2>
248inline constexpr bool has_same_memory_space_v =
250
256template <class T>
258 typedef char yes[1];
259 typedef char no[2];
260
261 template <class U>
262 static yes& test(U*, typename std::enable_if<
263#if defined(MORPHEUS_ENABLE_SERIAL) || defined(MORPHEUS_ENABLE_OPENMP)
264 std::is_same<U, Kokkos::HostSpace>::value ||
265#endif
266 false>::type* = nullptr);
267
268 template <class U>
269 static no& test(...);
270
271 public:
272 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
273};
274
280template <typename T>
282
288template <class T>
290 typedef char yes[1];
291 typedef char no[2];
292
293 template <class U>
294 static yes& test(U*,
295 typename std::enable_if<
296#if defined(MORPHEUS_ENABLE_SERIAL) || defined(MORPHEUS_ENABLE_OPENMP)
298#endif
299 false>::type* = nullptr);
300
301 template <class U>
302 static no& test(...);
303
304 public:
305 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
306};
307
313template <typename T>
315
321template <class T>
323 typedef char yes[1];
324 typedef char no[2];
325
326 template <class U>
327 static yes& test(
328 U*, typename std::enable_if<
329 std::is_same<U, Kokkos::DefaultHostExecutionSpace>::value ||
330#if defined(MORPHEUS_ENABLE_SERIAL)
331 std::is_same<U, Kokkos::Serial>::value ||
332#endif
333#if defined(MORPHEUS_ENABLE_OPENMP)
334 std::is_same<U, Kokkos::OpenMP>::value ||
335#endif
336 false>::type* = nullptr);
337
338 template <class U>
339 static no& test(...);
340
341 public:
342 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
343};
344
350template <typename T>
351inline constexpr bool is_host_execution_space_v =
353
359template <class T>
361 typedef char yes[1];
362 typedef char no[2];
363
364 template <class U>
365 static yes& test(U*, typename std::enable_if<is_host_execution_space_v<
366 typename U::execution_space>>::type* = nullptr);
367
368 template <class U>
369 static no& test(...);
370
371 public:
372 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
373};
374
380template <typename T>
381inline constexpr bool has_host_execution_space_v =
383
384#if defined(MORPHEUS_ENABLE_SERIAL)
390template <class T>
392 typedef char yes[1];
393 typedef char no[2];
394
395 template <class U>
396 static yes& test(U*, typename std::enable_if<
397#if defined(MORPHEUS_ENABLE_SERIAL)
398 std::is_same<U, Kokkos::Serial>::value ||
399#endif // MORPHEUS_ENABLE_SERIAL
400 false>::type* = nullptr);
401
402 template <class U>
403 static no& test(...);
404
405 public:
406 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
407};
408
414template <typename T>
415inline constexpr bool is_serial_execution_space_v =
417
423template <class T>
425 typedef char yes[1];
426 typedef char no[2];
427
428 template <class U>
429 static yes& test(
430 U*, typename std::enable_if<
431#if defined(MORPHEUS_ENABLE_SERIAL)
433#endif // MORPHEUS_ENABLE_SERIAL
434 false>::type* = nullptr);
435
436 template <class U>
437 static no& test(...);
438
439 public:
440 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
441};
442
448template <typename T>
449inline constexpr bool has_serial_execution_space_v =
451#endif // MORPHEUS_ENABLE_SERIAL
452
453#if defined(MORPHEUS_ENABLE_OPENMP)
459template <class T>
461 typedef char yes[1];
462 typedef char no[2];
463
464 template <class U>
465 static yes& test(U*, typename std::enable_if<
466#if defined(MORPHEUS_ENABLE_OPENMP)
467 std::is_same<U, Kokkos::OpenMP>::value ||
468#endif // MORPHEUS_ENABLE_OPENMP
469 false>::type* = nullptr);
470
471 template <class U>
472 static no& test(...);
473
474 public:
475 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
476};
477
483template <typename T>
484inline constexpr bool is_openmp_execution_space_v =
486
492template <class T>
494 typedef char yes[1];
495 typedef char no[2];
496
497 template <class U>
498 static yes& test(
499 U*, typename std::enable_if<
500#if defined(MORPHEUS_ENABLE_OPENMP)
502#endif // MORPHEUS_ENABLE_OPENMP
503 false>::type* = nullptr);
504
505 template <class U>
506 static no& test(...);
507
508 public:
509 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
510};
511
517template <typename T>
518inline constexpr bool has_openmp_execution_space_v =
520#endif // MORPHEUS_ENABLE_OPENMP
521
522#if defined(MORPHEUS_ENABLE_CUDA)
528template <class T>
530 typedef char yes[1];
531 typedef char no[2];
532
533 template <class U>
534 static yes& test(U*, typename std::enable_if<
535#if defined(MORPHEUS_ENABLE_CUDA)
536 std::is_same<U, Kokkos::Cuda>::value ||
537#endif // MORPHEUS_ENABLE_CUDA
538 false>::type* = nullptr);
539
540 template <class U>
541 static no& test(...);
542
543 public:
544 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
545};
546
552template <typename T>
553inline constexpr bool is_cuda_execution_space_v =
555
561template <class T>
563 typedef char yes[1];
564 typedef char no[2];
565
566 template <class U>
567 static yes& test(U*, typename std::enable_if<
568#if defined(MORPHEUS_ENABLE_CUDA)
570 typename U::execution_space>::value ||
571#endif // MORPHEUS_ENABLE_CUDA
572 false>::type* = nullptr);
573
574 template <class U>
575 static no& test(...);
576
577 public:
578 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
579};
580
586template <typename T>
587inline constexpr bool has_cuda_execution_space_v =
589#endif // MORPHEUS_ENABLE_CUDA
590
591#if defined(MORPHEUS_ENABLE_HIP)
597template <class T>
599 typedef char yes[1];
600 typedef char no[2];
601
602 template <class U>
603 static yes& test(U*, typename std::enable_if<
604#if defined(MORPHEUS_ENABLE_HIP)
605 std::is_same<U, Kokkos::HIP>::value ||
606#endif // MORPHEUS_ENABLE_HIP
607 false>::type* = nullptr);
608
609 template <class U>
610 static no& test(...);
611
612 public:
613 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
614};
615
621template <typename T>
622inline constexpr bool is_hip_execution_space_v =
624
630template <class T>
632 typedef char yes[1];
633 typedef char no[2];
634
635 template <class U>
636 static yes& test(U*,
637 typename std::enable_if<is_hip_execution_space<
638 typename U::execution_space>::value>::type* = nullptr);
639
640 template <class U>
641 static no& test(...);
642
643 public:
644 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
645};
646
652template <typename T>
653inline constexpr bool has_hip_execution_space_v =
655#endif // MORPHEUS_ENABLE_HIP
656
658namespace Impl {
659template <typename ExecSpace, typename... Ts>
660struct has_access;
661
662template <class T1, class T2>
663struct has_access<T1, T2> {
664 typedef char yes[1];
665 typedef char no[2];
666
667 template <class U1, class U2>
668 static yes& test(
669 U1*, U2*,
670 typename std::enable_if<
671 has_execution_space_v<U1> && has_memory_space_v<U2> &&
672 Kokkos::SpaceAccessibility<typename U1::execution_space,
673 typename U2::memory_space>::accessible>::
674 type* = nullptr);
675
676 template <class U1, class U2>
677 static no& test(...);
678
679 public:
680 static const bool value =
681 sizeof(test<T1, T2>(nullptr, nullptr)) == sizeof(yes);
682};
683
684template <typename ExecSpace, typename T, typename... Ts>
685struct has_access<ExecSpace, T, Ts...> {
686 static const bool value =
687 has_access<ExecSpace, T>::value && has_access<ExecSpace, Ts...>::value;
688};
689
690} // namespace Impl
701template <typename ExecSpace, typename... Ts>
703 static const bool value = Impl::has_access<ExecSpace, Ts...>::value;
704};
705
712template <typename ExecSpace, typename... Ts>
713inline constexpr bool has_access_v = has_access<ExecSpace, Ts...>::value;
714
721template <typename T>
722struct is_space {
723 typedef char yes[1];
724 typedef char no[2];
725
726 template <class U>
727 static yes& test(U*,
728 typename std::enable_if<
729 Kokkos::is_space<typename U::execution_space>::value ||
730 Kokkos::is_space<typename U::memory_space>::value ||
731 Kokkos::is_space<typename U::device_type>::value ||
732 Kokkos::is_space<U>::value>::type* = nullptr);
733
734 template <class U>
735 static no& test(...);
736
737 public:
738 static const bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
739};
740
746template <typename T>
747inline constexpr bool is_space_v = is_space<T>::value;
748
751} // namespace Morpheus
752
753#endif // MORPHEUS_SPACETRAITS_HPP
Checks if the given type T has a Cuda execution space.
Definition: Morpheus_SpaceTraits.hpp:562
Checks if the given type T has a valid supported execution space.
Definition: Morpheus_SpaceTraits.hpp:154
Checks if the given type T has a HIP execution space.
Definition: Morpheus_SpaceTraits.hpp:631
Checks if the given type T has a supported Host execution space.
Definition: Morpheus_SpaceTraits.hpp:360
Checks if the given type T has a valid supported Host memory space.
Definition: Morpheus_SpaceTraits.hpp:289
Checks if the given type T has a valid supported memory space.
Definition: Morpheus_SpaceTraits.hpp:81
Checks if the given type T has an OpenMP execution space.
Definition: Morpheus_SpaceTraits.hpp:493
Checks if the two types have the same valid supported memory space.
Definition: Morpheus_SpaceTraits.hpp:222
Checks if the given type T has a Serial execution space.
Definition: Morpheus_SpaceTraits.hpp:424
Checks if the given type T is a Cuda execution space.
Definition: Morpheus_SpaceTraits.hpp:529
Checks if the given type T is a valid supported execution space.
Definition: Morpheus_SpaceTraits.hpp:111
Checks if the given type T is a HIP execution space.
Definition: Morpheus_SpaceTraits.hpp:598
Checks if the given type T is a supported Host execution space.
Definition: Morpheus_SpaceTraits.hpp:322
Checks if the given type T is a valid supported Host memory space.
Definition: Morpheus_SpaceTraits.hpp:257
Checks if the given type T is a valid supported memory space.
Definition: Morpheus_SpaceTraits.hpp:46
Checks if the given type T is an OpenMP execution space.
Definition: Morpheus_SpaceTraits.hpp:460
Checks if the two types are in the same valid supported memory space.
Definition: Morpheus_SpaceTraits.hpp:186
Checks if the given type T is a Serial execution space.
Definition: Morpheus_SpaceTraits.hpp:391
Generic Morpheus interfaces.
Definition: dummy.cpp:24
constexpr bool has_memory_space_v
Short-hand to has_memory_space.
Definition: Morpheus_SpaceTraits.hpp:103
constexpr bool has_host_memory_space_v
Short-hand to has_host_memory_space.
Definition: Morpheus_SpaceTraits.hpp:314
constexpr bool is_openmp_execution_space_v
Short-hand to is_openmp_execution_space.
Definition: Morpheus_SpaceTraits.hpp:484
constexpr bool is_host_memory_space_v
Short-hand to is_host_memory_space.
Definition: Morpheus_SpaceTraits.hpp:281
constexpr bool is_same_memory_space_v
Short-hand to is_same_memory_space.
Definition: Morpheus_SpaceTraits.hpp:212
constexpr bool has_host_execution_space_v
Short-hand to has_host_execution_space.
Definition: Morpheus_SpaceTraits.hpp:381
constexpr bool has_serial_execution_space_v
Short-hand to has_serial_execution_space.
Definition: Morpheus_SpaceTraits.hpp:449
constexpr bool has_cuda_execution_space_v
Short-hand to has_cuda_execution_space.
Definition: Morpheus_SpaceTraits.hpp:587
constexpr bool is_cuda_execution_space_v
Short-hand to is_cuda_execution_space.
Definition: Morpheus_SpaceTraits.hpp:553
constexpr bool has_execution_space_v
Short-hand to has_execution_space.
Definition: Morpheus_SpaceTraits.hpp:177
constexpr bool has_hip_execution_space_v
Short-hand to has_hip_execution_space.
Definition: Morpheus_SpaceTraits.hpp:653
constexpr bool is_serial_execution_space_v
Short-hand to is_serial_execution_space.
Definition: Morpheus_SpaceTraits.hpp:415
constexpr bool is_memory_space_v
Short-hand to is_memory_space.
Definition: Morpheus_SpaceTraits.hpp:73
constexpr bool has_access_v
Short-hand to has_access.
Definition: Morpheus_SpaceTraits.hpp:713
constexpr bool has_openmp_execution_space_v
Short-hand to has_openmp_execution_space.
Definition: Morpheus_SpaceTraits.hpp:518
constexpr bool is_space_v
Short-hand to is_space.
Definition: Morpheus_SpaceTraits.hpp:747
constexpr bool is_execution_space_v
Short-hand to is_execution_space.
Definition: Morpheus_SpaceTraits.hpp:146
constexpr bool is_host_execution_space_v
Short-hand to is_host_execution_space.
Definition: Morpheus_SpaceTraits.hpp:351
constexpr bool has_same_memory_space_v
Short-hand to has_same_memory_space.
Definition: Morpheus_SpaceTraits.hpp:248
constexpr bool is_hip_execution_space_v
Short-hand to is_hip_execution_space.
Definition: Morpheus_SpaceTraits.hpp:622
Takes arbitrary number of containers and checks if ExecSpace has access to the memory space of all of...
Definition: Morpheus_SpaceTraits.hpp:702
Checks if the given type T is a valid supported space.
Definition: Morpheus_SpaceTraits.hpp:722