Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
ib_memory.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// IB (Intermediate Buffer) Memory implementations for Realm
19
20#ifndef REALM_IB_MEMORY_H
21#define REALM_IB_MEMORY_H
22
23#include "realm/realm_config.h"
24
25#include "realm/mem_impl.h"
26
27namespace Realm {
28
29 // a simple memory used for intermediate buffers in dma system
31 public:
32 IBMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, MemoryKind _kind,
33 Memory::Kind _lowlevel_kind, void *prealloc_base, NetworkSegment *_segment);
34
35 virtual ~IBMemory();
36
37 // old-style allocation used by IB memories
38 virtual off_t alloc_bytes_local(size_t size);
39 void free_bytes_local(off_t offset, size_t size, TimeLimit work_until);
40
41 virtual void *get_direct_ptr(off_t offset, size_t size);
42
43 // not used by IB memories
45 bool need_alloc_result,
46 bool poisoned,
47 TimeLimit work_until);
48
49 virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned,
50 TimeLimit work_until);
51
52 virtual void get_bytes(off_t offset, void *dst, size_t size);
53 virtual void put_bytes(off_t offset, const void *src, size_t size);
54
55 // attempts to allocate one or more IBs - either all succeed or all fail
56 bool attempt_immediate_allocation(NodeID requestor, uintptr_t req_op, size_t count,
57 const size_t *sizes, off_t *offsets);
58
59 // enqueues a batch of PendingIBRequests to be satisfied as soon as possible
61
62 void free_multiple(size_t count, const off_t *offsets, const size_t *sizes,
63 TimeLimit work_until);
64
65 protected:
66 // these must be called with the mutex held
67 off_t do_alloc(size_t size);
68 void do_free(off_t offset, size_t size);
71
72 Mutex mutex; // protection for resizing vectors
73 std::map<off_t, off_t> free_blocks;
74 char *base;
77 };
78
79 // helper routine to free IB whether it is local or remote
80 void free_intermediate_buffer(Memory mem, off_t offset, size_t size,
81 TimeLimit work_until);
82
83 // active messages related to IB allocation/release
84
87 size_t size;
88 uintptr_t req_op;
89 unsigned req_index;
91
92 static void handle_message(NodeID sender, const RemoteIBAllocRequestSingle &args,
93 const void *data, size_t msglen, TimeLimit work_until);
94 };
95
99 uintptr_t req_op;
101
102 static void handle_message(NodeID sender, const RemoteIBAllocRequestMultiple &args,
103 const void *data, size_t msglen, TimeLimit work_until);
104 };
105
107 uintptr_t req_op;
108 unsigned req_index;
109 off_t offset;
110
111 static void handle_message(NodeID sender, const RemoteIBAllocResponseSingle &args,
112 const void *data, size_t msglen, TimeLimit work_until);
113 };
114
116 uintptr_t req_op;
118
119 static void handle_message(NodeID sender, const RemoteIBAllocResponseMultiple &args,
120 const void *data, size_t msglen, TimeLimit work_until);
121 };
122
125 size_t size;
126 off_t offset;
127
128 static void handle_message(NodeID sender, const RemoteIBReleaseSingle &args,
129 const void *data, size_t msglen, TimeLimit work_until);
130 };
131
133 unsigned count;
134
135 static void handle_message(NodeID sender, const RemoteIBReleaseMultiple &args,
136 const void *data, size_t msglen, TimeLimit work_until);
137 };
138
139}; // namespace Realm
140
141#endif
Definition ib_memory.h:30
off_t do_alloc(size_t size)
virtual void * get_direct_ptr(off_t offset, size_t size)
std::map< off_t, off_t > free_blocks
Definition ib_memory.h:73
void free_multiple(size_t count, const off_t *offsets, const size_t *sizes, TimeLimit work_until)
PendingIBRequests * satisfy_pending_reqs()
Mutex mutex
Definition ib_memory.h:72
char * base
Definition ib_memory.h:74
virtual AllocationResult allocate_storage_immediate(RegionInstanceImpl *inst, bool need_alloc_result, bool poisoned, TimeLimit work_until)
bool attempt_immediate_allocation(NodeID requestor, uintptr_t req_op, size_t count, const size_t *sizes, off_t *offsets)
PendingIBRequests ** ibreq_tail
Definition ib_memory.h:76
virtual off_t alloc_bytes_local(size_t size)
PendingIBRequests * ibreq_head
Definition ib_memory.h:75
void enqueue_requests(PendingIBRequests *reqs, TimeLimit work_until)
void forward_satisfied_reqs(PendingIBRequests *reqs, TimeLimit work_until)
virtual void put_bytes(off_t offset, const void *src, size_t size)
IBMemory(RuntimeImpl *_runtime_impl, Memory _me, size_t _size, MemoryKind _kind, Memory::Kind _lowlevel_kind, void *prealloc_base, NetworkSegment *_segment)
void free_bytes_local(off_t offset, size_t size, TimeLimit work_until)
virtual ~IBMemory()
void do_free(off_t offset, size_t size)
virtual void get_bytes(off_t offset, void *dst, size_t size)
virtual void release_storage_immediate(RegionInstanceImpl *inst, bool poisoned, TimeLimit work_until)
Definition mem_impl.h:50
MemoryKind
Definition mem_impl.h:53
AllocationResult
Definition mem_impl.h:89
Definition memory.h:33
Kind
Definition memory.h:59
Definition network.h:262
Definition mem_impl.h:220
Definition inst_impl.h:54
Definition runtime_impl.h:267
Definition timers.h:129
Definition mutex.h:223
#define REALM_INTERNAL_API_EXTERNAL_LINKAGE
Definition compiler_support.h:218
Definition activemsg.h:38
int NodeID
Definition nodeset.h:40
void free_intermediate_buffer(Memory mem, off_t offset, size_t size, TimeLimit work_until)
Definition ib_memory.h:96
unsigned curr_index
Definition ib_memory.h:98
unsigned count
Definition ib_memory.h:98
static void handle_message(NodeID sender, const RemoteIBAllocRequestMultiple &args, const void *data, size_t msglen, TimeLimit work_until)
NodeID requestor
Definition ib_memory.h:97
bool immediate
Definition ib_memory.h:100
unsigned first_index
Definition ib_memory.h:98
uintptr_t req_op
Definition ib_memory.h:99
Definition ib_memory.h:85
bool immediate
Definition ib_memory.h:90
static void handle_message(NodeID sender, const RemoteIBAllocRequestSingle &args, const void *data, size_t msglen, TimeLimit work_until)
uintptr_t req_op
Definition ib_memory.h:88
Memory memory
Definition ib_memory.h:86
size_t size
Definition ib_memory.h:87
unsigned req_index
Definition ib_memory.h:89
Definition ib_memory.h:115
static void handle_message(NodeID sender, const RemoteIBAllocResponseMultiple &args, const void *data, size_t msglen, TimeLimit work_until)
uintptr_t req_op
Definition ib_memory.h:116
unsigned first_index
Definition ib_memory.h:117
unsigned count
Definition ib_memory.h:117
Definition ib_memory.h:106
static void handle_message(NodeID sender, const RemoteIBAllocResponseSingle &args, const void *data, size_t msglen, TimeLimit work_until)
off_t offset
Definition ib_memory.h:109
uintptr_t req_op
Definition ib_memory.h:107
unsigned req_index
Definition ib_memory.h:108
Definition ib_memory.h:132
unsigned count
Definition ib_memory.h:133
static void handle_message(NodeID sender, const RemoteIBReleaseMultiple &args, const void *data, size_t msglen, TimeLimit work_until)
Definition ib_memory.h:123
size_t size
Definition ib_memory.h:125
static void handle_message(NodeID sender, const RemoteIBReleaseSingle &args, const void *data, size_t msglen, TimeLimit work_until)
off_t offset
Definition ib_memory.h:126
Memory memory
Definition ib_memory.h:124
NodeID src
Definition ucp_internal.h:1