Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Morpheus_ContainerTraits_Impl.hpp
1
24#ifndef MORPHEUS_CONTAINERTRAITS_IMPL_HPP
25#define MORPHEUS_CONTAINERTRAITS_IMPL_HPP
26
27#include <Morpheus_TypeTraits.hpp>
28#include <Morpheus_SpaceTraits.hpp>
29#include <Morpheus_GenericBackend.hpp>
30
31#include <Kokkos_Core.hpp>
32
33namespace Morpheus {
34
35namespace Impl {
36
37template <typename ValueType, class... Properties>
39
40template <>
41struct ContainerTraits<void> {
42 using index_type = void;
43 using array_layout = void;
44 using backend = void;
45 using execution_space = void;
46 using memory_space = void;
47 using memory_traits = void;
48};
49
50template <class... Prop>
51struct ContainerTraits<void, void, Prop...> {
52 // Ignore an extraneous 'void'
53
54 using index_type = typename ContainerTraits<void, Prop...>::index_type;
55 using array_layout = typename ContainerTraits<void, Prop...>::array_layout;
56 using backend = typename ContainerTraits<void, Prop...>::backend;
57 using execution_space =
58 typename ContainerTraits<void, Prop...>::execution_space;
59 using memory_space = typename ContainerTraits<void, Prop...>::memory_space;
60 using memory_traits = typename ContainerTraits<void, Prop...>::memory_traits;
61};
62
63template <typename IndexType, class... Prop>
65 typename std::enable_if_t<std::is_integral<IndexType>::value>, IndexType,
66 Prop...> {
67 // Specify index type
68 // Keep subsequent layout, space and memory trait arguments
69
70 using index_type = IndexType;
71 using array_layout = typename ContainerTraits<void, Prop...>::array_layout;
72 using backend = typename ContainerTraits<void, Prop...>::backend;
73 using execution_space =
74 typename ContainerTraits<void, Prop...>::execution_space;
75 using memory_space = typename ContainerTraits<void, Prop...>::memory_space;
76 using memory_traits = typename ContainerTraits<void, Prop...>::memory_traits;
77};
78
79template <typename ArrayLayout, class... Prop>
81 typename std::enable_if_t<Morpheus::is_layout<ArrayLayout>::value>,
82 ArrayLayout, Prop...> {
83 // Specify Layout
84 // Keep Space and MemoryTraits arguments
85
86 using index_type = void;
87 using array_layout = ArrayLayout;
88 using backend = typename ContainerTraits<void, Prop...>::backend;
89 using execution_space =
90 typename ContainerTraits<void, Prop...>::execution_space;
91 using memory_space = typename ContainerTraits<void, Prop...>::memory_space;
92 using memory_traits = typename ContainerTraits<void, Prop...>::memory_traits;
93};
94
95template <class Space, class... Prop>
97 typename std::enable_if<Morpheus::is_space<Space>::value>::type, Space,
98 Prop...> {
99 // Specify Space, memory traits should be the only subsequent argument.
100
101 static_assert(
102 std::is_same<typename ContainerTraits<void, Prop...>::execution_space,
103 void>::value &&
104 std::is_same<typename ContainerTraits<void, Prop...>::memory_space,
105 void>::value &&
106 std::is_same<typename ContainerTraits<void, Prop...>::array_layout,
107 void>::value,
108 "Only one Container Execution or Memory Space template argument");
109
110 using index_type = void;
111 using array_layout = void;
112 using backend = typename std::conditional<
113 !Morpheus::has_backend<Space>::value, // means we are using
114 // Kokkos::<space>
116 using execution_space = typename backend::execution_space;
117 using memory_space = typename backend::memory_space;
118 using memory_traits = typename ContainerTraits<void, Prop...>::memory_traits;
119};
120
121template <class MemoryTraits, class... Prop>
122struct ContainerTraits<typename std::enable_if<
123 Kokkos::is_memory_traits<MemoryTraits>::value>::type,
124 MemoryTraits, Prop...> {
125 // Specify memory trait, should not be any subsequent arguments
126
127 static_assert(
128 std::is_same<typename ContainerTraits<void, Prop...>::execution_space,
129 void>::value &&
130 std::is_same<typename ContainerTraits<void, Prop...>::memory_space,
131 void>::value &&
132 std::is_same<typename ContainerTraits<void, Prop...>::array_layout,
133 void>::value &&
134 std::is_same<typename ContainerTraits<void, Prop...>::memory_traits,
135 void>::value,
136 "MemoryTrait is the final optional template argument for a Container");
137
138 using index_type = void;
139 using backend = void;
140 using execution_space = void;
141 using memory_space = void;
142 using array_layout = void;
143 using memory_traits = MemoryTraits;
144};
145
146} // namespace Impl
147} // namespace Morpheus
148#endif // MORPHEUS_CONTAINERTRAITS_IMPL_HPP
Checks if the given type T has a valid supported backend.
Definition: Morpheus_Spaces.hpp:62
Generic Morpheus interfaces.
Definition: dummy.cpp:24
A wrapper that converts a valid space into a generic backend.
Definition: Morpheus_GenericBackend.hpp:68
Definition: Morpheus_ContainerTraits_Impl.hpp:38
A wrapper that checks if the provided type is an integral type.
Definition: Morpheus_TypeTraits.hpp:73