DASH  0.3.0
MemorySpaceBase.h
1 #ifndef DASH__MEMORY__MEMORY_SPACE_BASE_H__INCLUDED
2 #define DASH__MEMORY__MEMORY_SPACE_BASE_H__INCLUDED
3 
4 #include <algorithm>
5 #include <atomic>
6 #include <cstddef>
7 #include <memory>
8 
9 #include <cpp17/polymorphic_allocator.h>
10 
11 
12 #include <dash/Meta.h>
13 #include <dash/Types.h>
14 
16 #include <dash/memory/internal/MemorySpaceRegistry.h>
17 
18 namespace dash {
19 
21 
22 template <typename ElementType, class MemorySpace>
23 class GlobPtr;
24 
66 };
68 };
69 
71 };
73 };
75 };
77 };
78 
80 
82  // Participating units allocate on construction. Acquired memory is never
83  // reclaimed upon destruction
84  //
85  // Methods:
86  // - allocate
87  // - deallocate
88 };
89 
91  // Participating units allocate local segments independent and subsequently
92  // attach it to global memory.
93  //
94  // Methods:
95  // - allocate_local
96  // - deallocate_local
97  // - attach
98  // - detach
99 };
100 
102 };
103 
105 };
106 
108 
110  // All allocations in memory are collective...
111  //
112  // => Requires that global memory allocation is always collective
113 };
114 
116  // Units allocate global memory independent from each other. Requires a
117  // synchronization mechanism to agree on a global memory state.
118  // See GlobHeapMem as an example.
119  //
120  // => Should support both point-to-point and collective synchronization
121  // within the team
122 };
123 
125  // Only a single unit participates in global memory memory allocation. It
126  // may then broadcast the global pointer to other units in the team.
127  //
128  // => See dash::Shared as an example.
129 };
130 
132 // MEMORY SPACE TRAITS
134 //
135 
136 namespace details {
137 
138 template <typename _D>
139 using is_local_memory_space = std::
140  integral_constant<bool, std::is_same<_D, memory_domain_local>::value>;
141 
142 template <typename _D>
143 using is_global_memory_space = std::
144  integral_constant<bool, std::is_same<_D, memory_domain_global>::value>;
145 
146 template <class _Ms>
147 using memspace_traits_is_global =
148  is_global_memory_space<typename _Ms::memory_space_domain_category>;
149 
150 template <class _Ms>
151 using memspace_traits_is_local =
152  is_local_memory_space<typename _Ms::memory_space_domain_category>;
153 
154 DASH__META__DEFINE_TRAIT__HAS_TYPE(void_pointer)
155 DASH__META__DEFINE_TRAIT__HAS_TYPE(const_void_pointer)
156 DASH__META__DEFINE_TRAIT__HAS_TYPE(memory_space_layout_tag)
157 
158 template <class _Ms, bool = has_type_void_pointer<_Ms>::value>
160  typedef typename _Ms::void_pointer type;
161 };
162 
163 template <class _Ms>
165  typedef typename std::conditional<
166  memspace_traits_is_global<_Ms>::value,
168  void*>::type type;
169 };
170 
171 template <class _Ms, bool = has_type_const_void_pointer<_Ms>::value>
173  typedef typename _Ms::const_void_pointer type;
174 };
175 
176 template <class _Ms>
178  typedef typename std::conditional<
179  memspace_traits_is_global<_Ms>::value,
181  const void*>::type type;
182 };
183 
184 template <class _Ms, bool = has_type_memory_space_layout_tag<_Ms>::value>
186  typedef typename _Ms::memory_space_layout_tag type;
187 };
188 
189 template <class _Ms>
190 struct memspace_traits_layout_tag<_Ms, false> {
192 };
193 
194 } // namespace details
195 
196 template <class MemSpace>
201  using memory_space_type = MemSpace;
206  typename MemSpace::memory_space_type_category;
207 
212  typename MemSpace::memory_space_domain_category;
213 
218  typename details::memspace_traits_layout_tag<MemSpace>::type;
219 
223  using is_global = typename details::memspace_traits_is_global<MemSpace>;
224 
230  using is_local = typename details::memspace_traits_is_local<MemSpace>;
231 
232  using void_pointer =
233  typename details::memspace_traits_void_pointer_type<MemSpace>::type;
234 
235  using const_void_pointer =
237  MemSpace>::type;
238 };
239 
241 // LOCAL MEMORY SPACE
243 
244 template <class MemoryType>
246  // We may add something here in figure
248 
249 public:
252  using memory_space_type_category = MemoryType;
253 };
254 
256 // GLOBAL MEMORY SPACE
258 
259 template <
261  class MemoryType>
263 public:
266  using memory_space_type_category = MemoryType;
267 public:
268  virtual ~GlobalMemorySpaceBase() = default;
269 
270 public:
271  GlobalMemorySpaceBase() = default;
274  GlobalMemorySpaceBase& operator=(const GlobalMemorySpaceBase&) = default;
275  GlobalMemorySpaceBase& operator=(GlobalMemorySpaceBase&&) = default;
276 };
277 
279 // MEMORY SPACE
281 
282 template <class MemoryDomain, class... Args>
284 
285 // Specialization for Local Memory Spaces
286 template <class... Args>
288  : public LocalMemorySpaceBase<Args...> {
289 };
290 
291 template <class... Args>
293  : public GlobalMemorySpaceBase<Args...> {
294 };
295 } // namespace dash
296 
297 #endif // DASH__MEMORY__MEMORY_SPACE_H__INCLUDED
typename details::memspace_traits_is_global< MemSpace > is_global
Whether the memory space type is specified for global address space.
typename details::memspace_traits_is_local< MemSpace > is_local
Whether the memory space type is specified for local address space.
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
typename MemSpace::memory_space_domain_category memory_space_domain_category
The underlying memory domain (local, global, etc.)
MemSpace memory_space_type
The Memory Space Type.
Allocation Policy.
The MemorySpace concept follows the STL std::pmr::memory_resource.
Pointer in global memory space with random access arithmetics.
Definition: GlobPtr.h:33
Synchronization Policy.
typename MemSpace::memory_space_type_category memory_space_type_category
The underlying memory type (Host, CUDA, HBW, etc.)
typename details::memspace_traits_layout_tag< MemSpace >::type memory_space_layout_tag
May be contiguous or noncontiguous.