Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
repl_heap.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// replicated (e.g. to gpus) internal heaps for Realm
19
20#ifndef REALM_REPL_HEAP_H
21#define REALM_REPL_HEAP_H
22
23#include "realm/realm_config.h"
24#include "realm/mutex.h"
25
26#include <set>
27
28namespace Realm {
29
31 public:
34
35 void init(size_t _chunk_size, size_t _max_chunks);
36 void cleanup();
37
38 // objects may be allocated and freed
39 virtual void *alloc_obj(size_t bytes, size_t alignment);
40 virtual void free_obj(void *ptr);
41
42 // writes to an object must be via the address at which is was allocated,
43 // and be followed by a call to commit_writes for the appropriate address
44 // range
45 void commit_writes(void *start, size_t bytes);
46
47 // heap listeners are told when new chunks are created and when data is
48 // updated (e.g. allowing software-managed coherency of mirrors of the
49 // heap)
50 class Listener {
51 public:
52 virtual ~Listener() {}
53
54 virtual void chunk_created(void *base, size_t bytes) {}
55 virtual void chunk_destroyed(void *base, size_t bytes) {}
56
57 virtual void data_updated(void *base, size_t bytes) {}
58 };
59
60 void add_listener(Listener *listener);
61 void remove_listener(Listener *listener);
62
63 protected:
64 struct ObjectHeader {
65 uint64_t state;
66 static const uint64_t STATE_FREE = 0x0102030405060708ULL;
67 static const uint64_t STATE_ALLOCD = 0x0F0E0D0C0B0A0908ULL;
68 static const uint64_t STATE_INVALID = 0;
69 uint64_t size;
70 };
71
73 uintptr_t base;
76 // fairly low-bandwidth allocator, so use simple best-fit algorithm
77 std::map<uint64_t, uint64_t> free_by_start;
78 std::multimap<uint64_t, uint64_t> free_by_size;
79 std::set<Listener *> listeners;
80 };
81
82}; // namespace Realm
83
84#endif
Definition repl_heap.h:50
virtual ~Listener()
Definition repl_heap.h:52
virtual void chunk_destroyed(void *base, size_t bytes)
Definition repl_heap.h:55
virtual void chunk_created(void *base, size_t bytes)
Definition repl_heap.h:54
virtual void data_updated(void *base, size_t bytes)
Definition repl_heap.h:57
Definition repl_heap.h:30
std::map< uint64_t, uint64_t > free_by_start
Definition repl_heap.h:77
Mutex mutex
Definition repl_heap.h:72
size_t peak_bytes
Definition repl_heap.h:75
size_t chunk_size
Definition repl_heap.h:74
void add_listener(Listener *listener)
uintptr_t base
Definition repl_heap.h:73
std::set< Listener * > listeners
Definition repl_heap.h:79
void commit_writes(void *start, size_t bytes)
void init(size_t _chunk_size, size_t _max_chunks)
void remove_listener(Listener *listener)
size_t max_chunks
Definition repl_heap.h:74
virtual void * alloc_obj(size_t bytes, size_t alignment)
size_t cur_bytes
Definition repl_heap.h:75
virtual void free_obj(void *ptr)
size_t cur_chunks
Definition repl_heap.h:74
std::multimap< uint64_t, uint64_t > free_by_size
Definition repl_heap.h:78
Definition mutex.h:223
Definition activemsg.h:38
Definition repl_heap.h:64
static const uint64_t STATE_FREE
Definition repl_heap.h:66
static const uint64_t STATE_ALLOCD
Definition repl_heap.h:67
static const uint64_t STATE_INVALID
Definition repl_heap.h:68
uint64_t size
Definition repl_heap.h:69
uint64_t state
Definition repl_heap.h:65