DASH  0.3.0
MemorySpace.h
1 #ifndef DASH__MEMORY__MEMORY_SPACE_H__INCLUDED
2 #define DASH__MEMORY__MEMORY_SPACE_H__INCLUDED
3 
4 #include <dash/memory/HBWSpace.h>
5 #include <dash/memory/HostSpace.h>
6 
7 #include <dash/memory/GlobLocalMemoryPool.h>
8 #include <dash/memory/GlobStaticMem.h>
9 
10 #include <dash/GlobPtr.h>
11 
12 namespace dash {
13 
15 // HELPER FUNCTIONS
17 //
18 
19 // TODO rko: maybe there is a better way instead of all these specializations?
20 
21 namespace detail {
22 template <class, class>
23 struct dependent_false : std::false_type {
24 };
25 } // namespace detail
26 
27 template <class MSpaceDomainCategory, class MSpaceTypeCategory>
28 inline MemorySpace<MSpaceDomainCategory, MSpaceTypeCategory>*
30 {
31  static_assert(
32  detail::dependent_false<MSpaceDomainCategory, MSpaceTypeCategory>::
33  value,
34  "No default memory space for this configuration available");
35  // Current we have only a default host space
36  return nullptr;
37 }
38 
39 template <>
41 get_default_memory_space<memory_domain_local, memory_space_host_tag>();
42 
43 template <>
45 get_default_memory_space<memory_domain_local, memory_space_hbw_tag>();
46 
47 template <>
49 get_default_memory_space<memory_domain_global, memory_space_host_tag>();
50 
51 template <typename T>
53 {
54  using memory_t = GlobLocalMemoryPool<dash::HostSpace>;
55 
56  auto* mspace = dynamic_cast<memory_t*>(get_default_memory_space<
59 
60  DASH_ASSERT_MSG(mspace, "invalid default memory space");
61 
62  auto ptr = mspace->allocate(nelem * sizeof(T), alignof(T));
63 
64  return static_cast<dash::GlobPtr<T, memory_t>>(ptr);
65 }
66 
67 template <class T>
68 void memfree(
69  GlobPtr<T, GlobLocalMemoryPool<dash::HostSpace>> gptr, size_t nels)
70 {
71  using memory_t = GlobLocalMemoryPool<dash::HostSpace>;
72 
73  auto* mspace = dynamic_cast<memory_t*>(get_default_memory_space<
76 
77  DASH_ASSERT_MSG(mspace, "invalid default memory space");
78 
79  mspace->deallocate(gptr, nels * sizeof(T), alignof(T));
80 }
81 
87 template <class T>
88 using GlobMemAllocPtr = decltype(dash::memalloc<T>(size_t{}));
89 
90 } // namespace dash
91 
92 #endif
MemorySpace< MSpaceDomainCategory, MSpaceTypeCategory > * get_default_memory_space()
Forward declarations.
Definition: MemorySpace.h:29
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
The MemorySpace concept follows the STL std::pmr::memory_resource.
Pointer in global memory space with random access arithmetics.
Definition: GlobPtr.h:33
decltype(dash::memalloc< T >(size_t{})) GlobMemAllocPtr
Convenience Wrapper to retrieve easily the type allocated by dash::memalloc<T>
Definition: MemorySpace.h:88