1 #ifndef DASH__MEMORY__GLOB_LOCAL_MEMORY_H__INCLUDED 2 #define DASH__MEMORY__GLOB_LOCAL_MEMORY_H__INCLUDED 4 #include <dash/Exception.h> 5 #include <dash/allocator/AllocationPolicy.h> 6 #include <dash/memory/MemorySpaceBase.h> 11 template <
class MSpaceDomainCategory,
class MSpaceTypeCategory>
12 inline MemorySpace<MSpaceDomainCategory, MSpaceTypeCategory>*
17 template <
class ElementType,
class MemorySpace>
20 template <
class LMemSpace>
23 typename dash::memory_space_traits<
24 LMemSpace>::memory_space_type_category> {
26 std::is_same<LMemSpace, dash::HostSpace>::value,
27 "currently we support only dash::HostSpace for local memory " 30 static constexpr
size_t max_align =
alignof(dash::max_align_t);
44 using memory_space_type_category =
45 typename base_t::memory_space_type_category;
49 using difference_type = index_type;
61 using local_void_pointer =
void*;
62 using const_local_void_pointer =
void*;
68 typename memory_traits::memory_space_type_category>;
74 size_type pool_capacity = 0,
79 size_type pool_capacity = 0,
90 size_type size()
const DASH_ASSERT_NOEXCEPT
95 size_type capacity()
const DASH_ASSERT_NOEXCEPT
100 dash::Team const& team()
const DASH_ASSERT_NOEXCEPT
117 pointer allocate(size_type nbytes, size_type alignment = max_align)
119 return do_allocate(nbytes, alignment);
122 pointer gptr, size_type nbytes, size_type alignment = max_align)
124 return do_deallocate(gptr, nbytes, alignment);
133 DASH_ASSERT_MSG(gptr,
"cannot flush DART_GPTR_NULL");
142 DASH_ASSERT_MSG(gptr,
"cannot flush DART_GPTR_NULL");
152 DASH_ASSERT_MSG(gptr,
"cannot flush DART_GPTR_NULL");
163 DASH_ASSERT_MSG(gptr,
"cannot flush DART_GPTR_NULL");
172 size_type m_capacity{};
174 std::vector<std::pair<pointer, size_t>> m_segments;
178 pointer do_allocate(size_type nbytes, size_type );
179 void do_deallocate(
pointer gptr, size_type nbytes, size_type );
180 void do_segment_free(
181 typename std::vector<std::pair<pointer, size_t>>::iterator it_erase);
186 template <
class LMemSpace>
188 size_type local_capacity,
dash::Team const& team)
193 template <
class LMemSpace>
195 LMemSpace* r, size_type local_capacity,
dash::Team const& team)
199 local_capacity ? local_capacity
200 : std::numeric_limits<size_type>::max())
207 DASH_LOG_DEBUG(
"MemorySpace.MemorySpace >");
210 template <
class LMemSpace>
214 *
this = std::move(other);
217 template <
class LMemSpace>
221 if (
this == &other) {
227 m_team = other.m_team;
228 m_size = other.m_size;
229 m_capacity = other.m_capacity;
231 m_segments = std::move(other.m_segments);
233 other.m_segments.clear();
238 template <
class LMemSpace>
241 size_type nbytes, size_type )
244 "MemorySpace.do_allocate",
253 if ((m_capacity - m_size) < nbytes) {
254 throw std::bad_alloc{};
259 auto gptr = strategy.allocate_segment(
262 m_allocator.resource()),
267 m_segments.emplace_back(std::make_pair(
pointer{gptr}, nbytes));
269 return m_segments.back().first;
276 template <
class LMemSpace>
279 DASH_LOG_DEBUG(
"< MemorySpace.~MemorySpace");
283 DASH_LOG_DEBUG(
"MemorySpace.~MemorySpace >");
286 template <
class LMemSpace>
288 pointer gptr, size_type nbytes, size_type )
290 DASH_LOG_DEBUG(
"< MemorySpace.do_deallocate");
295 [gptr](
const std::pair<pointer, size_t>& item) {
296 return item.first == gptr;
299 if (it_seg !=
std::end(m_segments)) {
300 do_segment_free(it_seg);
301 m_segments.erase(it_seg);
305 DASH_LOG_DEBUG(
"MemorySpace.do_deallocate >");
307 template <
class LMemSpace>
317 template <
class LMemSpace>
319 typename std::vector<std::pair<pointer, size_t>>::iterator it_erase)
322 !(it_erase->first)) {
330 "local memory allocation works only with dash::Team::All()");
334 strategy.deallocate_segment(
338 m_allocator.resource()),
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.
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.
void flush_local(pointer gptr, dash::team_unit_t target)
Locally complete all outstanding non-blocking operations to the specified unit.
constexpr auto begin(RangeType &&range) -> decltype(std::forward< RangeType >(range).begin())
bool dart_initialized()
Whether the DASH runtime has been initialized.
void flush(pointer gptr)
Complete all outstanding non-blocking operations to all units.
GlobIter find_if(GlobIter first, GlobIter last, UnaryPredicate predicate)
Returns an iterator to the first element in the range [first,last) that satisfies the predicate p...
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.
void flush_local(pointer gptr)
Locally complete all outstanding non-blocking operations to all units.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
#define DART_GPTR_NULL
A NULL global pointer.
A Team instance specifies a subset of all available units.
Collective AllocationPolicy: Implements the mechanisms to allocate symmetrically from the global memo...
#define DART_GPTR_ISNULL(gptr_)
Test for NULL global pointer.
The MemorySpace concept follows the STL std::pmr::memory_resource.
constexpr dart_gptr_t dart_gptr() const DASH_NOEXCEPT
The pointer's underlying global address.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
Pointer in global memory space with random access arithmetics.
static Team & Null()
The invariant Team instance representing an undefined team.
void flush(pointer gptr, dash::team_unit_t target)
Complete all outstanding non-blocking operations to the specified unit.
static Team & All()
The invariant Team instance containing all available units.
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...