Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
mem_impl.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// Memory implementations for Realm
19
20#ifndef REALM_MEMORY_IMPL_H
21#define REALM_MEMORY_IMPL_H
22
23#include "realm/memory.h"
24#include "realm/id.h"
25#include "realm/network.h"
26
27#include "realm/activemsg.h"
28#include "realm/operation.h"
29#include "realm/profiling.h"
30#include "realm/sampling.h"
31
32#include "realm/event_impl.h"
33#include "realm/rsrv_impl.h"
34
35#include <filesystem>
36
37namespace Realm {
38
39 namespace Config {
40 // if true, Realm memories attempt to satisfy instance allocation requests
41 // on the basis of deferred instance destructions
43 }; // namespace Config
44
45 class RegionInstanceImpl;
46 class NetworkModule;
47 class NetworkSegment;
48 class ByteArray;
49
51 public:
53 {
54 MKIND_SYSMEM, // directly accessible from CPU
55 MKIND_GLOBAL, // accessible via GASnet (spread over all nodes)
56 MKIND_RDMA, // remote, but accessible via RDMA
57 MKIND_REMOTE, // not accessible
58
59 // defined even if REALM_USE_CUDA isn't
60 // TODO: make kinds more extensible
61 MKIND_GPUFB, // GPU framebuffer memory (accessible via cudaMemcpy)
62 MKIND_MANAGED, // memory that is coherent for both CPU and GPU
63
64 MKIND_ZEROCOPY, // CPU memory, pinned for GPU access
65 MKIND_DISK, // disk memory accessible by owner node
66 MKIND_FILE, // file memory accessible by owner node
67#ifdef REALM_USE_HDF5
68 MKIND_HDF, // HDF memory accessible by owner node
69#endif
70 };
71
72 MemoryImpl(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, MemoryKind _kind,
73 Memory::Kind _lowlevel_kind, NetworkSegment *_segment);
74
75 virtual ~MemoryImpl(void);
76
77 // looks up an instance based on ID - creates a proxy object for
78 // unknown IDs (metadata must be requested explicitly)
80
81 // adds a new instance to this memory, to be filled in by caller
83
84 // releases a deleted instance so that it can be reused
86
87 // attempt to allocate storage for the specified instance
97
99 std::vector<RegionInstanceImpl *> &new_insts)
100 {
101 assert(0);
102 }
103
104 // default implementation falls through (directly or indirectly) to
105 // allocate_storage_immediate - method need only be overridden by
106 // memories that support deferred allocation
108 bool need_alloc_result,
109 Event precondition);
110
111 // release storage associated with an instance - this falls through to
112 // release_storage_immediate similarly to the above
113 virtual void release_storage_deferrable(RegionInstanceImpl *inst, Event precondition);
114
115 // reuse storage associated with an instance
116 virtual AllocationResult
118 std::vector<RegionInstanceImpl *> &new_insts,
119 Event precondition);
120
121 // should only be called by RegionInstance::DeferredCreate or from
122 // allocate_storage_deferrable
124 bool need_alloc_result,
125 bool poisoned,
126 TimeLimit work_until) = 0;
127
128 // should only be called by RegionInstance::DeferredDestroy or from
129 // release_storage_deferrable
130 virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned,
131 TimeLimit work_until) = 0;
132
133 virtual AllocationResult
135 std::vector<RegionInstanceImpl *> &new_insts, bool poisoned,
136 TimeLimit work_until);
137
138 // helpers used by the above when an instance being allocated or released
139 // is using an external resource
141 size_t &inst_offset);
143
144 // for re-registration purposes, generate an ExternalInstanceResource *
145 // (if possible) for a given instance, or a subset of one
148 span<const FieldID> fields, bool read_only);
149
150 // TODO: try to rip these out?
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;
153
154 virtual void *get_direct_ptr(off_t offset, size_t size) = 0;
155
156 virtual void *get_inst_ptr(RegionInstanceImpl *inst, off_t offset, size_t size);
157
158 // gets info related to rdma access from other nodes
159 const ByteArray *get_rdma_info(NetworkModule *network) const;
160
161 // rdma transfers need to use LocalAddress and RemoteAddress helper objects
162 // rather than raw pointers
163 virtual bool get_local_addr(off_t offset, LocalAddress &local_addr);
164 virtual bool get_remote_addr(off_t offset, RemoteAddress &remote_addr);
165
166 // gets the network segment info for potential registration
168
170
171 // A helper function to get the kind of a memory when we only have the memory ID
172 static Memory::Kind get_memory_kind(const RuntimeImpl *runtime_impl, Memory memory);
173
174 // A helper function to get the size of a memory when we only have the memory ID
175 static size_t get_memory_size(const RuntimeImpl *runtime_impl, Memory memory);
176
177 // TODO: lift into a helper superclass?
178 template <typename T>
180 template <typename T>
181 const T *find_module_specific() const;
182
184
185 RuntimeImpl *get_runtime_impl() const { return runtime_impl; }
186
188 std::vector<RegionInstanceImpl *> instances;
189 std::vector<size_t> free_list;
191 };
192
193 public:
195 size_t size{0};
197 Memory::Kind lowlevel_kind{Memory::Kind::NO_MEMKIND};
198 NetworkSegment *segment{nullptr};
199 ModuleSpecificInfo *module_specific{nullptr};
200
201 // we keep a dedicated instance list for locally created
202 // instances, but we use a map indexed by creator node for others,
203 // and protect lookups in it with its own mutex
204 std::map<NodeID, InstanceList *> instances_by_creator;
207
208 protected:
209 RuntimeImpl *runtime_impl{nullptr};
210 };
211
213 public:
215 virtual ~MemSpecificInfo() {}
216
218 };
219
221 public:
222 PendingIBRequests(NodeID _sender, uintptr_t _req_op, unsigned _count,
223 unsigned _first_req, unsigned _current_req);
224 PendingIBRequests(NodeID _sender, uintptr_t _req_op, unsigned _count,
225 unsigned _first_req, unsigned _current_req, const Memory *_memories,
226 const size_t *_sizes, const off_t *_offsets);
227
230 uintptr_t req_op;
231 unsigned count;
232 unsigned first_req;
233 unsigned current_req;
234 std::vector<Memory> memories;
235 std::vector<size_t> sizes;
236 std::vector<off_t> offsets;
237 };
238
239 // manages a basic free list of ranges (using range type RT) and allocated
240 // ranges, which are tagged (tag type TT)
241 // NOT thread-safe - must be protected from outside
242 template <typename RT, typename TT>
244 public:
245 struct Range {
246 // Range(RT _first, RT _last);
247
248 RT first, last; // half-open range: [first, last)
249 unsigned prev, next; // double-linked list of all ranges (by index)
250 unsigned prev_free, next_free; // double-linked list of just free ranges
251 };
252
253 std::map<TT, unsigned> allocated; // direct lookup of allocated ranges by tag
254#ifdef DEBUG_REALM
255 std::map<RT, unsigned> by_first; // direct lookup of all ranges by first
256 // TODO: sized-based lookup of free ranges
257#endif
258
259 static const unsigned SENTINEL = 0;
260 // TODO: small (medium?) vector opt
261 std::vector<Range> ranges;
262
265
269 BasicRangeAllocator &operator=(BasicRangeAllocator &&) noexcept = default;
270
271 void swap(BasicRangeAllocator<RT, TT> &swap_with);
272
273 void add_range(RT first, RT last);
274 bool can_allocate(TT tag, RT size, RT alignment);
275 bool allocate(TT tag, RT size, RT alignment, RT &first);
276 void deallocate(TT tag, bool missing_ok = false);
277
278 bool lookup(TT tag, RT &first, RT &size);
279 size_t split_range(TT old_tag, const std::vector<TT> &new_tags,
280 const std::vector<RT> &sizes, const std::vector<RT> &alignment,
281 std::vector<RT> &allocs_first, bool missing_ok = false);
282
283 // TODO(apryakhin@): consider ifdefing for debug builds only
293
294 protected:
296 unsigned alloc_range(RT first, RT last);
297 void deallocate(unsigned del_idx);
298 void free_range(unsigned index);
299 };
300
301 // An alternative memory allocator that keeps track of free ranges grouped
302 // by sizes, these free lists can optionally be kept in sorted order
303 template <typename RT, typename TT, bool SORTED>
305 public:
308
312 SizedRangeAllocator &operator=(SizedRangeAllocator &&) noexcept = default;
313
314 void swap(SizedRangeAllocator<RT, TT, SORTED> &swap_with);
315
316 void add_range(RT first, RT last);
317 bool can_allocate(TT tag, RT size, RT alignment);
318 bool allocate(TT tag, RT size, RT alignment, RT &first);
319 void deallocate(TT tag, bool missing_ok = false);
320 size_t split_range(TT old_tag, const std::vector<TT> &new_tags,
321 const std::vector<RT> &sizes, const std::vector<RT> &alignment,
322 std::vector<RT> &allocs_first, bool missing_ok = false);
323
324 static constexpr unsigned SENTINEL = BasicRangeAllocator<RT, TT>::SENTINEL;
325 using Range = typename BasicRangeAllocator<RT, TT>::Range;
326 void add_to_free_list(unsigned index, Range &range);
327 void remove_from_free_list(unsigned index, Range &range);
328 void grow_hole(unsigned index, Range &range, RT bound, bool before);
329
331
332 static unsigned floor_log2(uint64_t size);
333
334 protected:
335 // Free lists associated with a specific sizes by powers of 2
336 // entry[0] = sizes from [2^0,2^1)
337 // entry[1] = sizes from [2^1,2^2)
338 // entry[2] = sizes from [2^2,2^3)
339 // ...
340 std::vector<unsigned> size_based_free_lists;
341 };
342
343 // a memory that manages its own allocations
345 public:
346 LocalManagedMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size,
347 MemoryKind _kind, size_t _alignment, Memory::Kind _lowlevel_kind,
348 NetworkSegment *_segment);
349
350 virtual ~LocalManagedMemory(void);
351
353 bool need_alloc_result,
354 Event precondition);
355
356 virtual void release_storage_deferrable(RegionInstanceImpl *inst, Event precondition);
357
358 virtual AllocationResult
360 std::vector<RegionInstanceImpl *> &new_insts,
361 Event precondition);
362
364 bool need_alloc_result,
365 bool poisoned,
366 TimeLimit work_until);
367
368 virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned,
369 TimeLimit work_until);
370
371 virtual AllocationResult
373 std::vector<RegionInstanceImpl *> &new_insts, bool poisoned,
374 TimeLimit work_until);
375
376 protected:
377 // for internal use by allocation routines - must be called with
378 // allocator_mutex held!
380 size_t alignment, size_t &inst_offset);
381
382 // attempts to satisfy pending allocations based on reordering releases to
383 // move the ready ones first - assumes 'release_allocator' has been
384 // properly maintained. Any pending_releases entries with
385 // deferred_dealloc_notify set that get erased here are appended to
386 // 'deferred_dealloc_notifies' so the caller can fire their
387 // notify_deallocation() once the allocator_mutex has been released.
389 std::vector<std::pair<RegionInstanceImpl *, size_t>> &successful_allocs,
390 std::vector<RegionInstanceImpl *> &deferred_dealloc_notifies);
391
393 std::vector<RegionInstanceImpl *> &failed_allocs);
394
395 public:
396 size_t alignment;
397
399 // we keep up to three heap states:
400 // current: always valid - tracks all completed allocations and all
401 // releases that can be applied without risking deadlock
402 // future: valid if pending_allocs exist - tracks heap state including
403 // all pending allocs and releases
404 // release: valid if pending_allocs exist - models heap state with
405 // completed allocations and any ready releases
406
407 // Pick which kind of range allocator we want to use
409 // using RangeAllocator = SizedRangeAllocator<size_t, RegionInstance, false>;
410
411 RangeAllocator current_allocator, future_allocator, release_allocator;
415 size_t bytes, alignment;
417 PendingAlloc(RegionInstanceImpl *_inst, size_t _bytes, size_t _align,
418 unsigned _release_seqid);
419 };
422 std::vector<RegionInstance> redistrict_tags;
423 std::vector<size_t> redistrict_sizes;
424 std::vector<size_t> redistrict_alignments;
426 unsigned seqid;
427 // True when the inst's destroy is fully acknowledged from a
428 // release_allocator/future_allocator perspective, but its tag still
429 // lives in current_allocator because attempt_release_reordering could
430 // not (yet) drop it. notify_deallocation() (and the inst-slot recycle
431 // it triggers) must be delayed until this entry is drained from
432 // pending_releases - otherwise the slot can be handed back out by
433 // new_instance() while the allocator still tracks the stale tag,
434 // producing double-tracking that surfaces as assertion failures in
435 // BasicRangeAllocator::deallocate / split_range.
437
438 PendingRelease(RegionInstanceImpl *_inst, bool _ready, unsigned _seqid);
439 void record_redistrict(const std::vector<RegionInstanceImpl *> &insts);
440 void release(RangeAllocator &allocator, bool missing_ok = false);
441 size_t release(RangeAllocator &allocator, std::vector<size_t> &offsets,
442 bool missing_ok = false);
443 };
444 std::deque<PendingAlloc> pending_allocs;
445 std::deque<PendingRelease> pending_releases;
447 };
448
450 public:
451 static const size_t ALIGNMENT = 256;
452
453 LocalCPUMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, int numa_node,
454 Memory::Kind _lowlevel_kind, void *prealloc_base = 0,
455 NetworkSegment *_segment = 0, bool enable_ipc = true);
456
457 virtual ~LocalCPUMemory(void);
458
459 // LocalCPUMemory supports ExternalMemoryResource
461 size_t &inst_offset);
463
464 // for re-registration purposes, generate an ExternalInstanceResource *
465 // (if possible) for a given instance, or a subset of one
468 span<const FieldID> fields, bool read_only);
469
470 virtual void get_bytes(off_t offset, void *dst, size_t size);
471 virtual void put_bytes(off_t offset, const void *src, size_t size);
472 virtual void *get_direct_ptr(off_t offset, size_t size);
473
474 public:
475 const int numa_node;
476
477 public: // protected:
478 char *base, *base_orig;
481 };
482
484 public:
485 static const size_t ALIGNMENT = 256;
486
487 DiskMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size,
488 const std::filesystem::path &_file);
489
490 virtual ~DiskMemory(void);
491
492 virtual void get_bytes(off_t offset, void *dst, size_t size);
493
494 virtual void put_bytes(off_t offset, const void *src, size_t size);
495
496 virtual void *get_direct_ptr(off_t offset, size_t size);
497
500 span<const FieldID> fields, bool read_only);
501
503 size_t &inst_offset);
505
506 public:
507 int fd; // file descriptor
508 std::filesystem::path file; // file name
509 };
510
511 class FileMemory : public MemoryImpl {
512 public:
513 FileMemory(RuntimeImpl *_runtime_impl, Memory _me);
514
515 virtual ~FileMemory(void);
516
517 virtual void get_bytes(off_t offset, void *dst, size_t size);
518 void get_bytes(ID::IDType inst_id, off_t offset, void *dst, size_t size);
519
520 virtual void put_bytes(off_t offset, const void *src, size_t size);
521 void put_bytes(ID::IDType inst_id, off_t offset, const void *src, size_t size);
522 virtual void *get_direct_ptr(off_t offset, size_t size);
523
526 span<const FieldID> fields, bool read_only);
527
529 bool need_alloc_result,
530 bool poisoned,
531 TimeLimit work_until);
532
533 virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned,
534 TimeLimit work_until);
535
536 // FileMemory supports ExternalFileResource
538 size_t &inst_offset);
540
541 // the 'mem_specific' data for a file instance contains OpenFileInfo
543 public:
544 int fd;
545 size_t offset;
546 };
547 };
548
550 public:
551 RemoteMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, Memory::Kind k,
552 MemoryKind mk = MKIND_REMOTE);
553 virtual ~RemoteMemory(void);
554
556 bool need_alloc_result,
557 Event precondition);
558
559 virtual void release_storage_deferrable(RegionInstanceImpl *inst, Event precondition);
560
561 virtual AllocationResult
563 std::vector<RegionInstanceImpl *> &new_insts,
564 Event precondition);
565
567 bool need_alloc_result,
568 bool poisoned,
569 TimeLimit work_until);
570
571 virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned,
572 TimeLimit work_until);
573
574 virtual AllocationResult
576 std::vector<RegionInstanceImpl *> &new_insts, bool poisoned,
577 TimeLimit work_until);
578
579 // these are disallowed on a remote memory
580 virtual off_t alloc_bytes_local(size_t size);
581 virtual void free_bytes_local(off_t offset, size_t size);
582
583 virtual void get_bytes(off_t offset, void *dst, size_t size);
584 virtual void put_bytes(off_t offset, const void *src, size_t size);
585 virtual void *get_direct_ptr(off_t offset, size_t size);
586
587 private:
588 // For mapped remote memory, this is non-null
589 void *base;
590 };
591
592 // active messages
593
599
600 static void handle_message(NodeID sender, const MemStorageAllocRequest &msg,
601 const void *data, size_t datalen);
602 };
603
606 size_t offset;
608
609 static void handle_message(NodeID sender, const MemStorageAllocResponse &msg,
610 const void *data, size_t datalen, TimeLimit work_until);
611 };
612
617
618 static void handle_message(NodeID sender, const MemStorageReleaseRequest &msg,
619 const void *data, size_t datalen);
620 };
621
624
625 static void handle_message(NodeID sender, const MemStorageReleaseResponse &msg,
626 const void *data, size_t datalen);
627 };
628
633 std::string get_shm_name(realm_id_t id);
634
635}; // namespace Realm
636
637#endif // ifndef REALM_MEM_IMPL_H
638
639#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)
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
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()
bool lookup(TT tag, RT &first, RT &size)
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:483
virtual void unregister_external_resource(RegionInstanceImpl *inst)
int fd
Definition mem_impl.h:507
virtual bool attempt_register_external_resource(RegionInstanceImpl *inst, size_t &inst_offset)
std::filesystem::path file
Definition mem_impl.h:508
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 event.h:50
Definition instance.h:405
Definition mem_impl.h:542
int fd
Definition mem_impl.h:544
size_t offset
Definition mem_impl.h:545
Definition mem_impl.h:511
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)
Definition id.h:30
::realm_id_t IDType
Definition id.h:32
Definition indexspace.h:1115
Definition mem_impl.h:449
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:475
virtual bool attempt_register_external_resource(RegionInstanceImpl *inst, size_t &inst_offset)
NetworkSegment local_segment
Definition mem_impl.h:480
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:479
virtual ExternalInstanceResource * generate_resource_info(RegionInstanceImpl *inst, const IndexSpaceGeneric *subspace, span< const FieldID > fields, bool read_only)
char * base
Definition mem_impl.h:478
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:396
unsigned cur_release_seqid
Definition mem_impl.h:412
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:446
bool attempt_release_reordering(std::vector< std::pair< RegionInstanceImpl *, size_t > > &successful_allocs, std::vector< RegionInstanceImpl * > &deferred_dealloc_notifies)
std::deque< PendingRelease > pending_releases
Definition mem_impl.h:445
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:398
RangeAllocator current_allocator
Definition mem_impl.h:411
std::deque< PendingAlloc > pending_allocs
Definition mem_impl.h:444
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
Definition mem_impl.h:50
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)
Definition memory.h:33
Kind
Definition memory.h:59
Definition module.h:100
Definition network.h:144
Definition network.h:262
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 mutex.h:398
Definition inst_impl.h:54
Definition instance.h:66
Definition mem_impl.h:549
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:267
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)
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 & operator=(const SizedRangeAllocator &)=default
SizedRangeAllocator(const SizedRangeAllocator &)=default
Definition timers.h:129
Definition mutex.h:223
Definition utils.h:84
#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
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 network.h:58
size_t alignment
Definition mem_impl.h:415
PendingAlloc(RegionInstanceImpl *_inst, size_t _bytes, size_t _align, unsigned _release_seqid)
RegionInstanceImpl * inst
Definition mem_impl.h:414
unsigned last_release_seqid
Definition mem_impl.h:416
unsigned seqid
Definition mem_impl.h:426
std::vector< size_t > redistrict_alignments
Definition mem_impl.h:424
bool deferred_dealloc_notify
Definition mem_impl.h:436
bool is_ready
Definition mem_impl.h:425
RegionInstanceImpl * inst
Definition mem_impl.h:421
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:422
PendingRelease(RegionInstanceImpl *_inst, bool _ready, unsigned _seqid)
std::vector< size_t > redistrict_sizes
Definition mem_impl.h:423
void release(RangeAllocator &allocator, bool missing_ok=false)
Definition mem_impl.h:594
bool need_alloc_result
Definition mem_impl.h:597
Memory memory
Definition mem_impl.h:595
RegionInstance inst
Definition mem_impl.h:596
Event precondition
Definition mem_impl.h:598
static void handle_message(NodeID sender, const MemStorageAllocRequest &msg, const void *data, size_t datalen)
Definition mem_impl.h:604
RegionInstance inst
Definition mem_impl.h:605
MemoryImpl::AllocationResult result
Definition mem_impl.h:607
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:606
Definition mem_impl.h:613
Event precondition
Definition mem_impl.h:616
static void handle_message(NodeID sender, const MemStorageReleaseRequest &msg, const void *data, size_t datalen)
Memory memory
Definition mem_impl.h:614
RegionInstance inst
Definition mem_impl.h:615
Definition mem_impl.h:622
static void handle_message(NodeID sender, const MemStorageReleaseResponse &msg, const void *data, size_t datalen)
RegionInstance inst
Definition mem_impl.h:623
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
Definition network.h:46
NodeID src
Definition ucp_internal.h:1