20#ifndef REALM_MEMORY_IMPL_H
21#define REALM_MEMORY_IMPL_H
45 class RegionInstanceImpl;
99 std::vector<RegionInstanceImpl *> &new_insts)
108 bool need_alloc_result,
118 std::vector<RegionInstanceImpl *> &new_insts,
124 bool need_alloc_result,
135 std::vector<RegionInstanceImpl *> &new_insts,
bool poisoned,
141 size_t &inst_offset);
151 virtual void get_bytes(off_t offset,
void *dst,
size_t size) = 0;
152 virtual void put_bytes(off_t offset,
const void *
src,
size_t size) = 0;
178 template <
typename T>
180 template <
typename T>
223 unsigned _first_req,
unsigned _current_req);
225 unsigned _first_req,
unsigned _current_req,
const Memory *_memories,
226 const size_t *_sizes,
const off_t *_offsets);
242 template <
typename RT,
typename TT>
255 std::map<RT, unsigned> by_first;
275 bool allocate(TT tag, RT size, RT alignment, RT &first);
278 bool lookup(TT tag, RT &first, RT &size);
280 const
std::vector<RT> &sizes, const
std::vector<RT> &alignment,
281 std::vector<RT> &allocs_first,
bool missing_ok = false);
303 template <
typename RT,
typename TT,
bool SORTED>
318 bool allocate(TT tag, RT size, RT alignment, RT &first);
321 const
std::vector<RT> &sizes, const
std::vector<RT> &alignment,
322 std::vector<RT> &allocs_first,
bool missing_ok = false);
353 bool need_alloc_result,
360 std::vector<RegionInstanceImpl *> &new_insts,
364 bool need_alloc_result,
373 std::vector<RegionInstanceImpl *> &new_insts,
bool poisoned,
380 size_t alignment,
size_t &inst_offset);
386 std::vector<std::pair<RegionInstanceImpl *, size_t>> &successful_allocs);
389 std::vector<RegionInstanceImpl *> &failed_allocs);
414 unsigned _release_seqid);
428 bool missing_ok =
false);
437 static const size_t ALIGNMENT = 256;
447 size_t &inst_offset);
456 virtual void get_bytes(off_t offset,
void *dst,
size_t size);
471 static const size_t ALIGNMENT = 256;
474 const std::filesystem::path &_file);
478 virtual void get_bytes(off_t offset,
void *dst,
size_t size);
489 size_t &inst_offset);
503 virtual void get_bytes(off_t offset,
void *dst,
size_t size);
515 bool need_alloc_result,
524 size_t &inst_offset);
542 bool need_alloc_result,
549 std::vector<RegionInstanceImpl *> &new_insts,
553 bool need_alloc_result,
562 std::vector<RegionInstanceImpl *> &new_insts,
bool poisoned,
569 virtual void get_bytes(off_t offset,
void *dst,
size_t size);
587 const void *data,
size_t datalen);
596 const void *data,
size_t datalen,
TimeLimit work_until);
605 const void *data,
size_t datalen);
612 const void *data,
size_t datalen);
625#include "realm/mem_impl.inl"
Definition mem_impl.h:243
void deallocate(unsigned del_idx)
bool allocate(TT tag, RT size, RT alignment, RT &first)
void deallocate(TT tag, bool missing_ok=false)
bool can_allocate(TT tag, RT size, RT alignment)
bool free_list_has_cycle()
void swap(BasicRangeAllocator< RT, TT > &swap_with)
unsigned alloc_range(RT first, RT last)
unsigned first_free_range
Definition mem_impl.h:295
void add_range(RT first, RT last)
static const unsigned SENTINEL
Definition mem_impl.h:259
bool has_invalid_ranges()
void free_range(unsigned index)
BasicRangeAllocator(const BasicRangeAllocator &)=default
std::map< TT, unsigned > allocated
Definition mem_impl.h:253
std::vector< Range > ranges
Definition mem_impl.h:261
MemoryStats get_allocator_stats()
~BasicRangeAllocator(void)
bool lookup(TT tag, RT &first, RT &size)
BasicRangeAllocator(void)
BasicRangeAllocator & operator=(const BasicRangeAllocator &)=default
size_t split_range(TT old_tag, const std::vector< TT > &new_tags, const std::vector< RT > &sizes, const std::vector< RT > &alignment, std::vector< RT > &allocs_first, bool missing_ok=false)
BasicRangeAllocator(BasicRangeAllocator &&) noexcept=default
Definition bytearray.h:53
Definition mem_impl.h:469
virtual void unregister_external_resource(RegionInstanceImpl *inst)
int fd
Definition mem_impl.h:493
virtual bool attempt_register_external_resource(RegionInstanceImpl *inst, size_t &inst_offset)
std::filesystem::path file
Definition mem_impl.h:494
virtual ~DiskMemory(void)
virtual void * get_direct_ptr(off_t offset, size_t size)
virtual ExternalInstanceResource * generate_resource_info(RegionInstanceImpl *inst, const IndexSpaceGeneric *subspace, span< const FieldID > fields, bool read_only)
virtual void put_bytes(off_t offset, const void *src, size_t size)
virtual void get_bytes(off_t offset, void *dst, size_t size)
DiskMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, const std::filesystem::path &_file)
Definition instance.h:405
Definition mem_impl.h:528
int fd
Definition mem_impl.h:530
size_t offset
Definition mem_impl.h:531
Definition mem_impl.h:497
virtual ~FileMemory(void)
virtual void * get_direct_ptr(off_t offset, size_t size)
virtual void unregister_external_resource(RegionInstanceImpl *inst)
virtual AllocationResult allocate_storage_immediate(RegionInstanceImpl *inst, bool need_alloc_result, bool poisoned, TimeLimit work_until)
virtual ExternalInstanceResource * generate_resource_info(RegionInstanceImpl *inst, const IndexSpaceGeneric *subspace, span< const FieldID > fields, bool read_only)
virtual void get_bytes(off_t offset, void *dst, size_t size)
FileMemory(RuntimeImpl *_runtime_impl, Memory _me)
void get_bytes(ID::IDType inst_id, off_t offset, void *dst, size_t size)
virtual bool attempt_register_external_resource(RegionInstanceImpl *inst, size_t &inst_offset)
void put_bytes(ID::IDType inst_id, off_t offset, const void *src, size_t size)
virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned, TimeLimit work_until)
virtual void put_bytes(off_t offset, const void *src, size_t size)
::realm_id_t IDType
Definition id.h:32
Definition indexspace.h:1115
Definition mem_impl.h:435
LocalCPUMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, int numa_node, Memory::Kind _lowlevel_kind, void *prealloc_base=0, NetworkSegment *_segment=0, bool enable_ipc=true)
virtual void unregister_external_resource(RegionInstanceImpl *inst)
const int numa_node
Definition mem_impl.h:461
virtual bool attempt_register_external_resource(RegionInstanceImpl *inst, size_t &inst_offset)
NetworkSegment local_segment
Definition mem_impl.h:466
virtual void put_bytes(off_t offset, const void *src, size_t size)
virtual ~LocalCPUMemory(void)
virtual void get_bytes(off_t offset, void *dst, size_t size)
virtual void * get_direct_ptr(off_t offset, size_t size)
bool prealloced
Definition mem_impl.h:465
virtual ExternalInstanceResource * generate_resource_info(RegionInstanceImpl *inst, const IndexSpaceGeneric *subspace, span< const FieldID > fields, bool read_only)
char * base
Definition mem_impl.h:464
Definition mem_impl.h:344
virtual AllocationResult allocate_storage_deferrable(RegionInstanceImpl *inst, bool need_alloc_result, Event precondition)
virtual AllocationResult reuse_storage_immediate(RegionInstanceImpl *old_inst, std::vector< RegionInstanceImpl * > &new_insts, bool poisoned, TimeLimit work_until)
size_t alignment
Definition mem_impl.h:392
unsigned cur_release_seqid
Definition mem_impl.h:408
virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned, TimeLimit work_until)
void remove_pending_release(RegionInstanceImpl *inst, std::vector< RegionInstanceImpl * > &failed_allocs)
ProfilingGauges::AbsoluteGauge< size_t > peak_footprint
Definition mem_impl.h:432
std::deque< PendingRelease > pending_releases
Definition mem_impl.h:431
bool attempt_release_reordering(std::vector< std::pair< RegionInstanceImpl *, size_t > > &successful_allocs)
virtual AllocationResult allocate_storage_immediate(RegionInstanceImpl *inst, bool need_alloc_result, bool poisoned, TimeLimit work_until)
LocalManagedMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, MemoryKind _kind, size_t _alignment, Memory::Kind _lowlevel_kind, NetworkSegment *_segment)
virtual AllocationResult reuse_storage_deferrable(RegionInstanceImpl *old_inst, std::vector< RegionInstanceImpl * > &new_insts, Event precondition)
virtual ~LocalManagedMemory(void)
AllocationResult attempt_deferrable_allocation(RegionInstanceImpl *inst, size_t bytes, size_t alignment, size_t &inst_offset)
Mutex allocator_mutex
Definition mem_impl.h:394
RangeAllocator current_allocator
Definition mem_impl.h:407
std::deque< PendingAlloc > pending_allocs
Definition mem_impl.h:430
virtual void release_storage_deferrable(RegionInstanceImpl *inst, Event precondition)
Definition mem_impl.h:212
MemSpecificInfo * next
Definition mem_impl.h:217
virtual ~MemSpecificInfo()
Definition mem_impl.h:215
virtual AllocationResult reuse_storage_deferrable(RegionInstanceImpl *old_inst, std::vector< RegionInstanceImpl * > &new_insts, Event precondition)
MemoryKind
Definition mem_impl.h:53
@ MKIND_DISK
Definition mem_impl.h:65
@ MKIND_REMOTE
Definition mem_impl.h:57
@ MKIND_GPUFB
Definition mem_impl.h:61
@ MKIND_MANAGED
Definition mem_impl.h:62
@ MKIND_FILE
Definition mem_impl.h:66
@ MKIND_RDMA
Definition mem_impl.h:56
@ MKIND_ZEROCOPY
Definition mem_impl.h:64
@ MKIND_GLOBAL
Definition mem_impl.h:55
@ MKIND_SYSMEM
Definition mem_impl.h:54
virtual void * get_direct_ptr(off_t offset, size_t size)=0
const T * find_module_specific() const
virtual void get_bytes(off_t offset, void *dst, size_t size)=0
void add_module_specific(ModuleSpecificInfo *info)
virtual ~MemoryImpl(void)
virtual void unregister_external_resource(RegionInstanceImpl *inst)
T * find_module_specific()
AllocationResult
Definition mem_impl.h:89
@ ALLOC_EVENTUAL_FAILURE
Definition mem_impl.h:94
@ ALLOC_EVENTUAL_SUCCESS
Definition mem_impl.h:93
@ ALLOC_DEFERRED
Definition mem_impl.h:92
@ ALLOC_INSTANT_SUCCESS
Definition mem_impl.h:90
@ ALLOC_INSTANT_FAILURE
Definition mem_impl.h:91
RuntimeImpl * get_runtime_impl() const
Definition mem_impl.h:185
RegionInstanceImpl * get_instance(ID id)
Memory::Kind get_kind(void) const
virtual bool attempt_register_external_resource(RegionInstanceImpl *inst, size_t &inst_offset)
static size_t get_memory_size(const RuntimeImpl *runtime_impl, Memory memory)
const ByteArray * get_rdma_info(NetworkModule *network) const
virtual bool get_local_addr(off_t offset, LocalAddress &local_addr)
MemoryImpl(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, MemoryKind _kind, Memory::Kind _lowlevel_kind, NetworkSegment *_segment)
virtual AllocationResult allocate_storage_deferrable(RegionInstanceImpl *inst, bool need_alloc_result, Event precondition)
void release_instance(RegionInstance inst)
virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned, TimeLimit work_until)=0
MemoryKind kind
Definition mem_impl.h:196
std::map< NodeID, InstanceList * > instances_by_creator
Definition mem_impl.h:204
virtual ExternalInstanceResource * generate_resource_info(RegionInstanceImpl *inst, const IndexSpaceGeneric *subspace, span< const FieldID > fields, bool read_only)
static Memory::Kind get_memory_kind(const RuntimeImpl *runtime_impl, Memory memory)
NetworkSegment * get_network_segment()
Mutex instance_map_mutex
Definition mem_impl.h:205
virtual void put_bytes(off_t offset, const void *src, size_t size)=0
virtual void * get_inst_ptr(RegionInstanceImpl *inst, off_t offset, size_t size)
virtual void reuse_allocated_range(RegionInstanceImpl *old_inst, std::vector< RegionInstanceImpl * > &new_insts)
Definition mem_impl.h:98
virtual bool get_remote_addr(off_t offset, RemoteAddress &remote_addr)
RegionInstanceImpl * new_instance(const ProfilingRequestSet &prs)
InstanceList local_instances
Definition mem_impl.h:206
virtual AllocationResult allocate_storage_immediate(RegionInstanceImpl *inst, bool need_alloc_result, bool poisoned, TimeLimit work_until)=0
virtual void release_storage_deferrable(RegionInstanceImpl *inst, Event precondition)
virtual AllocationResult reuse_storage_immediate(RegionInstanceImpl *old_inst, std::vector< RegionInstanceImpl * > &new_insts, bool poisoned, TimeLimit work_until)
Kind
Definition memory.h:59
Definition mem_impl.h:220
PendingIBRequests * next_req
Definition mem_impl.h:228
NodeID sender
Definition mem_impl.h:229
PendingIBRequests(NodeID _sender, uintptr_t _req_op, unsigned _count, unsigned _first_req, unsigned _current_req, const Memory *_memories, const size_t *_sizes, const off_t *_offsets)
unsigned current_req
Definition mem_impl.h:233
std::vector< off_t > offsets
Definition mem_impl.h:236
std::vector< size_t > sizes
Definition mem_impl.h:235
PendingIBRequests(NodeID _sender, uintptr_t _req_op, unsigned _count, unsigned _first_req, unsigned _current_req)
unsigned count
Definition mem_impl.h:231
unsigned first_req
Definition mem_impl.h:232
std::vector< Memory > memories
Definition mem_impl.h:234
uintptr_t req_op
Definition mem_impl.h:230
Definition profiling.h:363
Definition inst_impl.h:54
Definition mem_impl.h:535
virtual off_t alloc_bytes_local(size_t size)
virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned, TimeLimit work_until)
virtual ~RemoteMemory(void)
virtual void free_bytes_local(off_t offset, size_t size)
virtual AllocationResult allocate_storage_immediate(RegionInstanceImpl *inst, bool need_alloc_result, bool poisoned, TimeLimit work_until)
virtual AllocationResult reuse_storage_deferrable(RegionInstanceImpl *old_inst, std::vector< RegionInstanceImpl * > &new_insts, Event precondition)
virtual void get_bytes(off_t offset, void *dst, size_t size)
virtual AllocationResult reuse_storage_immediate(RegionInstanceImpl *old_inst, std::vector< RegionInstanceImpl * > &new_insts, bool poisoned, TimeLimit work_until)
RemoteMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, Memory::Kind k, MemoryKind mk=MKIND_REMOTE)
virtual AllocationResult allocate_storage_deferrable(RegionInstanceImpl *inst, bool need_alloc_result, Event precondition)
virtual void * get_direct_ptr(off_t offset, size_t size)
virtual void release_storage_deferrable(RegionInstanceImpl *inst, Event precondition)
virtual void put_bytes(off_t offset, const void *src, size_t size)
Definition runtime_impl.h:264
Definition mem_impl.h:304
void swap(SizedRangeAllocator< RT, TT, SORTED > &swap_with)
BasicRangeAllocator< RT, TT >::MemoryStats get_allocator_stats()
static unsigned floor_log2(uint64_t size)
void deallocate(TT tag, bool missing_ok=false)
bool can_allocate(TT tag, RT size, RT alignment)
typename BasicRangeAllocator< RT, TT >::Range Range
Definition mem_impl.h:325
void add_range(RT first, RT last)
size_t split_range(TT old_tag, const std::vector< TT > &new_tags, const std::vector< RT > &sizes, const std::vector< RT > &alignment, std::vector< RT > &allocs_first, bool missing_ok=false)
void remove_from_free_list(unsigned index, Range &range)
SizedRangeAllocator(void)
std::vector< unsigned > size_based_free_lists
Definition mem_impl.h:340
void grow_hole(unsigned index, Range &range, RT bound, bool before)
void add_to_free_list(unsigned index, Range &range)
bool allocate(TT tag, RT size, RT alignment, RT &first)
SizedRangeAllocator(SizedRangeAllocator &&) noexcept=default
static constexpr unsigned SENTINEL
Definition mem_impl.h:324
~SizedRangeAllocator(void)
SizedRangeAllocator & operator=(const SizedRangeAllocator &)=default
SizedRangeAllocator(const SizedRangeAllocator &)=default
#define REALM_INTERNAL_API_EXTERNAL_LINKAGE
Definition compiler_support.h:218
bool deferred_instance_allocation
Definition activemsg.h:38
int NodeID
Definition nodeset.h:40
std::string get_shm_name(realm_id_t id)
Returns the full path for use in SharedMemoryInfo::create and SharedMemoryInfo::open given the realm ...
Definition indexspace.h:1279
unsigned long long realm_id_t
Definition realm_c.h:64
#define REALM_NO_MEM
Definition realm_c.h:166
Definition mem_impl.h:284
size_t largest_free_blocksize
Definition mem_impl.h:288
size_t total_used_size
Definition mem_impl.h:287
size_t total_size
Definition mem_impl.h:285
size_t total_free_size
Definition mem_impl.h:286
Definition mem_impl.h:245
unsigned next
Definition mem_impl.h:249
unsigned prev_free
Definition mem_impl.h:250
unsigned prev
Definition mem_impl.h:249
RT last
Definition mem_impl.h:248
unsigned next_free
Definition mem_impl.h:250
RT first
Definition mem_impl.h:248
Definition mem_impl.h:409
size_t alignment
Definition mem_impl.h:411
PendingAlloc(RegionInstanceImpl *_inst, size_t _bytes, size_t _align, unsigned _release_seqid)
RegionInstanceImpl * inst
Definition mem_impl.h:410
unsigned last_release_seqid
Definition mem_impl.h:412
Definition mem_impl.h:416
unsigned seqid
Definition mem_impl.h:422
std::vector< size_t > redistrict_alignments
Definition mem_impl.h:420
bool is_ready
Definition mem_impl.h:421
RegionInstanceImpl * inst
Definition mem_impl.h:417
size_t release(RangeAllocator &allocator, std::vector< size_t > &offsets, bool missing_ok=false)
void record_redistrict(const std::vector< RegionInstanceImpl * > &insts)
std::vector< RegionInstance > redistrict_tags
Definition mem_impl.h:418
PendingRelease(RegionInstanceImpl *_inst, bool _ready, unsigned _seqid)
std::vector< size_t > redistrict_sizes
Definition mem_impl.h:419
void release(RangeAllocator &allocator, bool missing_ok=false)
Definition mem_impl.h:580
bool need_alloc_result
Definition mem_impl.h:583
Memory memory
Definition mem_impl.h:581
RegionInstance inst
Definition mem_impl.h:582
Event precondition
Definition mem_impl.h:584
static void handle_message(NodeID sender, const MemStorageAllocRequest &msg, const void *data, size_t datalen)
Definition mem_impl.h:590
RegionInstance inst
Definition mem_impl.h:591
MemoryImpl::AllocationResult result
Definition mem_impl.h:593
static void handle_message(NodeID sender, const MemStorageAllocResponse &msg, const void *data, size_t datalen, TimeLimit work_until)
size_t offset
Definition mem_impl.h:592
Definition mem_impl.h:599
Event precondition
Definition mem_impl.h:602
static void handle_message(NodeID sender, const MemStorageReleaseRequest &msg, const void *data, size_t datalen)
Memory memory
Definition mem_impl.h:600
RegionInstance inst
Definition mem_impl.h:601
Definition mem_impl.h:608
static void handle_message(NodeID sender, const MemStorageReleaseResponse &msg, const void *data, size_t datalen)
RegionInstance inst
Definition mem_impl.h:609
Definition mem_impl.h:187
RWLock mutex
Definition mem_impl.h:190
std::vector< size_t > free_list
Definition mem_impl.h:189
std::vector< RegionInstanceImpl * > instances
Definition mem_impl.h:188
NodeID src
Definition ucp_internal.h:1