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 virtual void free_bytes_local(off_t offset, size_t size);
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
64 protected:
65 // these must be called with the mutex held
66 off_t do_alloc(size_t size);
67 void do_free(off_t offset, size_t size);
70
71 Mutex mutex; // protection for resizing vectors
72 std::map<off_t, off_t> free_blocks;
73 char *base;
76 };
77
78 // helper routine to free IB whether it is local or remote
79 void free_intermediate_buffer(Memory mem, off_t offset, size_t size);
80
81 // active messages related to IB allocation/release
82
85 size_t size;
86 uintptr_t req_op;
87 unsigned req_index;
89
90 static void handle_message(NodeID sender, const RemoteIBAllocRequestSingle &args,
91 const void *data, size_t msglen);
92 };
93
97 uintptr_t req_op;
99
100 static void handle_message(NodeID sender, const RemoteIBAllocRequestMultiple &args,
101 const void *data, size_t msglen);
102 };
103
105 uintptr_t req_op;
106 unsigned req_index;
107 off_t offset;
108
109 static void handle_message(NodeID sender, const RemoteIBAllocResponseSingle &args,
110 const void *data, size_t msglen);
111 };
112
114 uintptr_t req_op;
116
117 static void handle_message(NodeID sender, const RemoteIBAllocResponseMultiple &args,
118 const void *data, size_t msglen);
119 };
120
123 size_t size;
124 off_t offset;
125
126 static void handle_message(NodeID sender, const RemoteIBReleaseSingle &args,
127 const void *data, size_t msglen);
128 };
129
131 unsigned count;
132
133 static void handle_message(NodeID sender, const RemoteIBReleaseMultiple &args,
134 const void *data, size_t msglen);
135 };
136
137}; // namespace Realm
138
139#endif
Definition ib_memory.h:30
off_t do_alloc(size_t size)
virtual void * get_direct_ptr(off_t offset, size_t size)
void enqueue_requests(PendingIBRequests *reqs)
std::map< off_t, off_t > free_blocks
Definition ib_memory.h:72
void free_multiple(size_t count, const off_t *offsets, const size_t *sizes)
PendingIBRequests * satisfy_pending_reqs()
Mutex mutex
Definition ib_memory.h:71
char * base
Definition ib_memory.h:73
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)
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:75
virtual off_t alloc_bytes_local(size_t size)
PendingIBRequests * ibreq_head
Definition ib_memory.h:74
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)
virtual ~IBMemory()
void do_free(off_t offset, size_t size)
void forward_satisfied_reqs(PendingIBRequests *reqs)
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:264
Definition timers.h:129
Definition mutex.h:223
#define REALM_INTERNAL_API_EXTERNAL_LINKAGE
Definition compiler_support.h:218
Definition activemsg.h:38
void free_intermediate_buffer(Memory mem, off_t offset, size_t size)
int NodeID
Definition nodeset.h:40
Definition ib_memory.h:94
unsigned curr_index
Definition ib_memory.h:96
unsigned count
Definition ib_memory.h:96
NodeID requestor
Definition ib_memory.h:95
bool immediate
Definition ib_memory.h:98
static void handle_message(NodeID sender, const RemoteIBAllocRequestMultiple &args, const void *data, size_t msglen)
unsigned first_index
Definition ib_memory.h:96
uintptr_t req_op
Definition ib_memory.h:97
Definition ib_memory.h:83
static void handle_message(NodeID sender, const RemoteIBAllocRequestSingle &args, const void *data, size_t msglen)
bool immediate
Definition ib_memory.h:88
uintptr_t req_op
Definition ib_memory.h:86
Memory memory
Definition ib_memory.h:84
size_t size
Definition ib_memory.h:85
unsigned req_index
Definition ib_memory.h:87
Definition ib_memory.h:113
uintptr_t req_op
Definition ib_memory.h:114
static void handle_message(NodeID sender, const RemoteIBAllocResponseMultiple &args, const void *data, size_t msglen)
unsigned first_index
Definition ib_memory.h:115
unsigned count
Definition ib_memory.h:115
Definition ib_memory.h:104
static void handle_message(NodeID sender, const RemoteIBAllocResponseSingle &args, const void *data, size_t msglen)
off_t offset
Definition ib_memory.h:107
uintptr_t req_op
Definition ib_memory.h:105
unsigned req_index
Definition ib_memory.h:106
Definition ib_memory.h:130
unsigned count
Definition ib_memory.h:131
static void handle_message(NodeID sender, const RemoteIBReleaseMultiple &args, const void *data, size_t msglen)
Definition ib_memory.h:121
size_t size
Definition ib_memory.h:123
static void handle_message(NodeID sender, const RemoteIBReleaseSingle &args, const void *data, size_t msglen)
off_t offset
Definition ib_memory.h:124
Memory memory
Definition ib_memory.h:122
NodeID src
Definition ucp_internal.h:1