1 #ifndef DASH__MEMORY__GLOB_STATIC_MEMORY_H__INCLUDED 2 #define DASH__MEMORY__GLOB_STATIC_MEMORY_H__INCLUDED 7 #include <dash/Exception.h> 8 #include <dash/allocator/AllocationPolicy.h> 9 #include <dash/memory/MemorySpaceBase.h> 10 #include <dash/internal/Macro.h> 12 #include <cpp17/type_traits.h> 72 template <
class MSpaceDomainCategory,
class MSpaceTypeCategory>
73 inline MemorySpace<MSpaceDomainCategory, MSpaceTypeCategory>*
87 template <
class LMemSpace>
92 typename dash::memory_space_traits<
93 LMemSpace>::memory_space_type_category> {
94 static constexpr
size_t max_align =
alignof(max_align_t);
107 typename memory_traits::memory_space_type_category>;
110 using memory_space_domain_category =
111 typename base_t::memory_space_domain_category;
112 using memory_space_type_category =
113 typename base_t::memory_space_type_category;
117 using difference_type = index_type;
127 using local_void_pointer =
void*;
128 using const_local_void_pointer =
const void*;
133 GlobStaticMem(LMemSpace* r,
dash::Team const& team);
134 ~GlobStaticMem()
override =
default;
136 GlobStaticMem(
const GlobStaticMem&) =
delete;
137 GlobStaticMem& operator=(
const GlobStaticMem&) =
delete;
139 constexpr GlobStaticMem(GlobStaticMem&& other) noexcept {
140 *
this = std::move(other);
143 GlobStaticMem& operator=(GlobStaticMem&&) noexcept =
default;
145 constexpr size_type capacity()
const noexcept;
149 return m_local_sizes.at(uid);
164 auto soon_to_be_end = m_begin;
172 auto soon_to_be_end = m_begin;
180 void_pointer allocate(size_type nbytes, size_type alignment = max_align)
182 m_local_sizes.resize(m_team->
size());
183 return do_allocate(nbytes, alignment);
187 void_pointer gptr, size_type nbytes, size_type alignment = max_align)
189 do_deallocate(gptr, nbytes, alignment);
192 constexpr
dash::Team const& team()
const noexcept
197 constexpr
void barrier()
const 223 gptr.unitid = unit.id;
240 gptr.teamid, m_team->
dart_id(),
"invalid pointer to flush");
241 gptr.unitid = unit.id;
252 std::vector<size_type> m_local_sizes{};
257 mutable size_type m_size{std::numeric_limits<size_type>::max()};
260 void_pointer do_allocate(size_type nbytes, size_type alignment);
263 void_pointer gptr, size_type nbytes, size_type alignment);
268 template <
class LMemSpace>
270 : GlobStaticMem(
nullptr, team)
274 template <
class LMemSpace>
275 inline GlobStaticMem<LMemSpace>::GlobStaticMem(
282 typename memory_traits::memory_space_type_category>())
283 , m_local_sizes(std::max(team.
size(), std::size_t(1)))
285 DASH_LOG_DEBUG(
"< MemorySpace.MemorySpace");
287 DASH_LOG_DEBUG_VAR(
"MemorySpace.MemorySpace", team);
289 DASH_LOG_DEBUG(
"MemorySpace.MemorySpace >");
292 template <
class LMemSpace>
297 auto gptr = strategy.allocate_segment(
300 typename memory_traits::memory_space_type_category
>*>(
301 m_local_allocator.resource()),
306 DASH_ASSERT_EQ(m_team->
size(), m_local_sizes.size(),
"invalid setting");
315 m_local_sizes.data(),
327 template <
class LMemSpace>
329 void_pointer gptr, size_type nbytes, size_type alignment)
331 DASH_LOG_DEBUG(
"< MemorySpace.do_deallocate");
336 auto soon_to_be_lbegin = gptr;
339 auto* lbegin = gptr.
local();
342 strategy.deallocate_segment(
343 static_cast<dart_gptr_t>(gptr),
345 typename memory_traits::memory_space_type_category
>*>(
346 m_local_allocator.resource()),
355 DASH_LOG_DEBUG(
"MemorySpace.do_deallocate >");
358 template <
class LMemSpace>
359 constexpr
inline typename GlobStaticMem<LMemSpace>::size_type
362 if (m_size == std::numeric_limits<size_type>::max()) {
363 m_size = std::accumulate(
367 std::plus<size_type>());
DASH_CONSTEXPR void flush_local(void_pointer ptr, dash::team_unit_t unit=dash::team_unit_t{}) const
Locally complete all outstanding non-blocking operations to all units.
MemorySpace< MSpaceDomainCategory, MSpaceTypeCategory > * get_default_memory_space()
Forward declarations.
internal::default_unsigned_index default_size_t
Unsigned integer type used as default for size values.
value_type * local()
Conversion to local pointer.
constexpr auto end(RangeType &&range) -> decltype(std::forward< RangeType >(range).end())
This class is a simple memory pool which holds allocates elements of size ValueType.
dart_ret_t dart_allgather(const void *sendbuf, void *recvbuf, size_t nelem, dart_datatype_t dtype, dart_team_t team)
DART Equivalent to MPI allgather.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
Global memory with address space of static size.
constexpr void flush(void_pointer ptr, dash::team_unit_t unit=dash::team_unit_t{}) const
Complete all outstanding non-blocking operations to either all units or a specified unit...
dart_ret_t dart_flush_local(dart_gptr_t gptr)
Guarantee local completion of all outstanding operations involving a segment on a certain unit...
dart_ret_t dart_flush_all(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on all units.
size_t size() const
The number of units in this team.
Data type for storing a unit ID relative to a team.
void set_unit(team_unit_t unit_id) DASH_NOEXCEPT
Set the global pointer's associated unit.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
A Team instance specifies a subset of all available units.
Collective AllocationPolicy: Implements the mechanisms to allocate symmetrically from the global memo...
DART Global pointer type.
dart_ret_t dart_barrier(dart_team_t team)
DART Equivalent to MPI_Barrier.
#define DART_GPTR_ISNULL(gptr_)
Test for NULL global pointer.
Type trait for mapping to DART data types.
The MemorySpace concept follows the STL std::pmr::memory_resource.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
static Team & Null()
The invariant Team instance representing an undefined team.
typename MemSpace::memory_space_type_category memory_space_type_category
The underlying memory type (Host, CUDA, HBW, etc.)
dart_ret_t dart_flush_local_all(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on all units.
dart_team_t dart_id() const
Index of this team relative to global team dash::Team::All().
dart_ret_t dart_flush(dart_gptr_t gptr)
Guarantee completion of all outstanding operations involving a segment on a certain unit...