Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
id.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// IDs (globally-usable handles) for Realm
19
20#ifndef REALM_ID_H
21#define REALM_ID_H
22
23#include "realm/realm_c.h"
24#include "realm/utils.h"
25
26#include <iostream>
27
28namespace Realm {
29
30 class ID {
31 public:
33
34 // Realm IDs are 64-bit values that uniquely encode both the type of the referred-to
35 // Realm
36 // object and its identity. Different types use different fields and some need more
37 // bits than others, so even the type field is variable length. The field order
38 // shown below is packed with the first field (the type tag) in the most significant
39 // bits of the 64-bit ID.
40
41 // EVENT: tag:1 = 0b1, creator_node:16, gen_event_idx: 27, generation: 20
42 // BARRIER: tag:4 = 0x2, creator_node:16, barrier_idx: 24, generation: 20
43 // RESERVATION: tag:8 = 0x1f, creator_node:16, (unused):8, rsrv_idx: 32
44 // MEMORY: tag:8 = 0x1e, owner_node:16, (unused):32, mem_idx: 8
45 // IB_MEMORY: tag:8 = 0x1a, owner_node:16, (unused):32, mem_idx: 8
46 // INSTANCE: tag:2 = 0b01, owner_node:16, creator_node:16, mem_idx: 8, inst_idx :
47 // 22 PROCESSOR: tag:8 = 0x1d, owner_node:16, (unused):28, proc_idx: 12 PROCGROUP:
48 // tag:8 = 0x1c, owner_node:16, creator_node:16, pgroup_idx: 24 SPARSITY: tag:4 =
49 // 0x3, owner_node:16, creator_node:16, sparsity_idx: 28 COMPQUEUE: tag:8 = 0x19,
50 // owner_node:16, (unused):28, cq_idx: 12 SUBGRAPH: tag:8 = 0x18,
51 // creator_node:16, (unused):16, subgraph_idx: 24
52
53 static const int NODE_FIELD_WIDTH = 16;
54 static const unsigned MAX_NODE_ID =
55 (1U << NODE_FIELD_WIDTH) - 2; // reserve all 1's for special cases
56 static const int EVENT_GENERATION_WIDTH =
57 REALM_EVENT_GENERATION_BITS; // fom realm_config.h
58 static const int MEMORY_INDEX_WIDTH = 8;
59 static const int INSTANCE_INDEX_WIDTH = 22;
60
61#define ACCESSOR(structname, name, field) \
62 bitpack<IDType>::bitsliceref<structname::field> name##_##field() \
63 { \
64 return id.slice<structname::field>(); \
65 } \
66 bitpack<IDType>::constbitsliceref<structname::field> name##_##field() const \
67 { \
68 return id.slice<structname::field>(); \
69 }
70
81
82 ACCESSOR(FMT_Event, event, type_tag)
83 ACCESSOR(FMT_Event, event, creator_node)
84 ACCESSOR(FMT_Event, event, gen_event_idx)
85 ACCESSOR(FMT_Event, event, generation)
86
87 struct FMT_Barrier {
92 generation; // MUST MATCH FMT_Event::generation size
93
94 static const IDType TAG_VALUE = 2;
95 };
96
97 ACCESSOR(FMT_Barrier, barrier, type_tag)
98 ACCESSOR(FMT_Barrier, barrier, creator_node)
99 ACCESSOR(FMT_Barrier, barrier, barrier_idx)
100 ACCESSOR(FMT_Barrier, barrier, generation)
101
105 // middle bits unused
107
108 static const IDType TAG_VALUE = 0x1f;
109 };
110
111 ACCESSOR(FMT_Reservation, rsrv, type_tag)
112 ACCESSOR(FMT_Reservation, rsrv, creator_node)
113 ACCESSOR(FMT_Reservation, rsrv, rsrv_idx)
114
115 struct FMT_Memory {
119 // middle bits unused
121
122 static const IDType TAG_VALUE = 0x1e;
123 };
124
125 ACCESSOR(FMT_Memory, memory, type_tag)
126 ACCESSOR(FMT_Memory, memory, owner_node)
127 ACCESSOR(FMT_Memory, memory, mem_idx)
128
129 // IB memories use the same encoding as memories, but a different tag
130 struct FMT_IB_Memory : public FMT_Memory {
131 static const IDType TAG_VALUE = 0x1a;
132 };
133
143
144 ACCESSOR(FMT_Instance, instance, type_tag)
145 ACCESSOR(FMT_Instance, instance, owner_node)
146 ACCESSOR(FMT_Instance, instance, creator_node)
147 ACCESSOR(FMT_Instance, instance, mem_idx)
148 ACCESSOR(FMT_Instance, instance, inst_idx)
149
153 // middle bits unused
155
156 static const IDType TAG_VALUE = 0x1d;
157 };
158
159 ACCESSOR(FMT_Processor, proc, type_tag)
160 ACCESSOR(FMT_Processor, proc, owner_node)
161 ACCESSOR(FMT_Processor, proc, proc_idx)
162
171
172 ACCESSOR(FMT_ProcGroup, pgroup, type_tag)
173 ACCESSOR(FMT_ProcGroup, pgroup, owner_node)
174 ACCESSOR(FMT_ProcGroup, pgroup, creator_node)
175 ACCESSOR(FMT_ProcGroup, pgroup, pgroup_idx)
176
185
186 ACCESSOR(FMT_Sparsity, sparsity, type_tag)
187 ACCESSOR(FMT_Sparsity, sparsity, owner_node)
188 ACCESSOR(FMT_Sparsity, sparsity, creator_node)
189 ACCESSOR(FMT_Sparsity, sparsity, sparsity_idx)
190
194 // middle bits unused
196
197 static const IDType TAG_VALUE = 0x19;
198 };
199
200 ACCESSOR(FMT_CompQueue, compqueue, type_tag)
201 ACCESSOR(FMT_CompQueue, compqueue, owner_node)
202 ACCESSOR(FMT_CompQueue, compqueue, cq_idx)
203
212
213 ACCESSOR(FMT_Subgraph, subgraph, type_tag)
214 ACCESSOR(FMT_Subgraph, subgraph, owner_node)
215 ACCESSOR(FMT_Subgraph, subgraph, creator_node)
216 ACCESSOR(FMT_Subgraph, subgraph, subgraph_idx)
217
218 static ID make_event(unsigned creator_node, unsigned gen_event_idx,
219 unsigned generation);
220 static ID make_barrier(unsigned creator_node, unsigned barrier_idx,
221 unsigned generation);
222 static ID make_reservation(unsigned creator_node, unsigned rsrv_idx);
223 static ID make_memory(unsigned owner_node, unsigned mem_idx);
224 static ID make_ib_memory(unsigned owner_node, unsigned mem_idx);
225 static ID make_instance(unsigned owner_node, unsigned creator_node, unsigned mem_idx,
226 unsigned inst_idx);
227 static ID make_processor(unsigned owner_node, unsigned proc_idx);
228 static ID make_procgroup(unsigned owner_node, unsigned creator_node,
229 unsigned pgroup_idx);
230 static ID make_sparsity(unsigned owner_node, unsigned creator_node,
231 unsigned sparsity_idx);
232 static ID make_compqueue(unsigned owner_node, unsigned cq_idx);
233 static ID make_subgraph(unsigned owner_node, unsigned creator_node,
234 unsigned subgraph_idx);
235
236 bool is_null(void) const;
237 bool is_event(void) const;
238 bool is_barrier(void) const;
239 bool is_reservation(void) const;
240 bool is_memory(void) const;
241 bool is_ib_memory(void) const;
242 bool is_instance(void) const;
243 bool is_processor(void) const;
244 bool is_procgroup(void) const;
245 bool is_sparsity(void) const;
246 bool is_compqueue(void) const;
247 bool is_subgraph(void) const;
248
268
269 static const IDType ID_NULL = 0;
270
271 ID(void);
272 ID(IDType _id);
273 ID(const ID &copy_from);
274
275 ID &operator=(const ID &copy_from);
276
277 template <class T>
278 ID(T thing_to_get_id_from);
279
280 bool operator==(const ID &rhs) const;
281 bool operator!=(const ID &rhs) const;
282
283 template <class T>
284 T convert(void) const;
285
287
288 friend std::ostream &operator<<(std::ostream &os, ID id);
289 };
290
291}; // namespace Realm
292
293#include "realm/id.inl"
294
295#endif // ifndef REALM_ID_H
Definition id.h:30
bool is_memory(void) const
bool operator!=(const ID &rhs) const
bool is_reservation(void) const
static const int INSTANCE_INDEX_WIDTH
Definition id.h:59
static const IDType ID_NULL
Definition id.h:269
static ID make_event(unsigned creator_node, unsigned gen_event_idx, unsigned generation)
bool is_event(void) const
ID(IDType _id)
bool is_procgroup(void) const
static ID make_instance(unsigned owner_node, unsigned creator_node, unsigned mem_idx, unsigned inst_idx)
bool operator==(const ID &rhs) const
bitpack< IDType > id
Definition id.h:286
ID_Types
Definition id.h:250
@ ID_EVENT
Definition id.h:253
@ ID_INDEXSPACE
Definition id.h:261
@ ID_UNUSED_5
Definition id.h:256
@ ID_SPECIAL
Definition id.h:251
@ ID_MEMORY
Definition id.h:257
@ ID_SUBGRAPH
Definition id.h:263
@ ID_SPARSITY
Definition id.h:262
@ ID_PROCESSOR
Definition id.h:259
@ ID_PROCGROUP
Definition id.h:260
@ ID_BARRIER
Definition id.h:254
@ ID_UNUSED_1
Definition id.h:252
@ ID_LOCK
Definition id.h:255
@ ID_IB_MEMORY
Definition id.h:258
@ ID_UNUSED_15
Definition id.h:266
@ ID_INSTANCE
Definition id.h:265
@ ID_UNUSED_13
Definition id.h:264
static ID make_subgraph(unsigned owner_node, unsigned creator_node, unsigned subgraph_idx)
bool is_processor(void) const
static ID make_ib_memory(unsigned owner_node, unsigned mem_idx)
static ID make_procgroup(unsigned owner_node, unsigned creator_node, unsigned pgroup_idx)
bool is_subgraph(void) const
static ID make_barrier(unsigned creator_node, unsigned barrier_idx, unsigned generation)
static const unsigned MAX_NODE_ID
Definition id.h:54
static const int MEMORY_INDEX_WIDTH
Definition id.h:58
static const int NODE_FIELD_WIDTH
Definition id.h:53
bool is_sparsity(void) const
bool is_barrier(void) const
static ID make_reservation(unsigned creator_node, unsigned rsrv_idx)
static ID make_compqueue(unsigned owner_node, unsigned cq_idx)
bool is_ib_memory(void) const
static ID make_processor(unsigned owner_node, unsigned proc_idx)
static const int EVENT_GENERATION_WIDTH
Definition id.h:56
bool is_instance(void) const
ID & operator=(const ID &copy_from)
ID(const ID &copy_from)
T convert(void) const
::realm_id_t IDType
Definition id.h:32
friend std::ostream & operator<<(std::ostream &os, ID id)
static ID make_memory(unsigned owner_node, unsigned mem_idx)
bool is_null(void) const
ID(T thing_to_get_id_from)
static ID make_sparsity(unsigned owner_node, unsigned creator_node, unsigned sparsity_idx)
bool is_compqueue(void) const
Definition utils.h:217
#define ACCESSOR(structname, name, field)
Definition id.h:61
Definition activemsg.h:38
unsigned long long realm_id_t
Definition realm_c.h:64
#define REALM_EVENT_GENERATION_BITS
Definition realm_config.h:30
Definition id.h:87
bitfield< EVENT_GENERATION_WIDTH, 0 > generation
Definition id.h:92
bitfield< 24, EVENT_GENERATION_WIDTH > barrier_idx
Definition id.h:90
bitfield< NODE_FIELD_WIDTH, 60 - NODE_FIELD_WIDTH > creator_node
Definition id.h:89
bitfield< 4, 60 > type_tag
Definition id.h:88
Definition id.h:191
bitfield< NODE_FIELD_WIDTH, 56 - NODE_FIELD_WIDTH > owner_node
Definition id.h:193
bitfield< 12, 0 > cq_idx
Definition id.h:195
bitfield< 8, 56 > type_tag
Definition id.h:192
Definition id.h:71
bitfield< 1, 63 > type_tag
Definition id.h:72
bitfield< EVENT_GENERATION_WIDTH, 0 > generation
Definition id.h:77
bitfield< NODE_FIELD_WIDTH, 63 - NODE_FIELD_WIDTH > creator_node
Definition id.h:73
static const IDType TAG_VALUE
Definition id.h:79
bitfield< 63 - NODE_FIELD_WIDTH - EVENT_GENERATION_WIDTH, EVENT_GENERATION_WIDTH > gen_event_idx
Definition id.h:76
Definition id.h:130
Definition id.h:134
bitfield< MEMORY_INDEX_WIDTH, INSTANCE_INDEX_WIDTH > mem_idx
Definition id.h:138
bitfield< 2, 62 > type_tag
Definition id.h:135
bitfield< INSTANCE_INDEX_WIDTH, 0 > inst_idx
Definition id.h:139
static const IDType TAG_VALUE
Definition id.h:141
bitfield< NODE_FIELD_WIDTH, 62 - 2 *NODE_FIELD_WIDTH > creator_node
Definition id.h:137
bitfield< NODE_FIELD_WIDTH, 62 - NODE_FIELD_WIDTH > owner_node
Definition id.h:136
Definition id.h:115
bitfield< 8, 56 > type_tag
Definition id.h:116
bitfield< MEMORY_INDEX_WIDTH, 0 > mem_idx
Definition id.h:120
bitfield< NODE_FIELD_WIDTH, 64 - NODE_FIELD_WIDTH - MEMORY_INDEX_WIDTH > owner_node
Definition id.h:118
Definition id.h:163
bitfield< 24, 0 > pgroup_idx
Definition id.h:167
bitfield< NODE_FIELD_WIDTH, 56 - NODE_FIELD_WIDTH > owner_node
Definition id.h:165
bitfield< 8, 56 > type_tag
Definition id.h:164
bitfield< NODE_FIELD_WIDTH, 56 - 2 *NODE_FIELD_WIDTH > creator_node
Definition id.h:166
Definition id.h:150
bitfield< 12, 0 > proc_idx
Definition id.h:154
bitfield< 8, 56 > type_tag
Definition id.h:151
bitfield< NODE_FIELD_WIDTH, 56 - NODE_FIELD_WIDTH > owner_node
Definition id.h:152
Definition id.h:102
bitfield< NODE_FIELD_WIDTH, 56 - NODE_FIELD_WIDTH > creator_node
Definition id.h:104
bitfield< 8, 56 > type_tag
Definition id.h:103
bitfield< 32, 0 > rsrv_idx
Definition id.h:106
Definition id.h:177
bitfield< NODE_FIELD_WIDTH, 60 - 2 *NODE_FIELD_WIDTH > creator_node
Definition id.h:180
bitfield< 28, 0 > sparsity_idx
Definition id.h:181
bitfield< NODE_FIELD_WIDTH, 60 - NODE_FIELD_WIDTH > owner_node
Definition id.h:179
bitfield< 4, 60 > type_tag
Definition id.h:178
Definition id.h:204
bitfield< 24, 0 > subgraph_idx
Definition id.h:208
bitfield< NODE_FIELD_WIDTH, 56 - 2 *NODE_FIELD_WIDTH > creator_node
Definition id.h:207
bitfield< 8, 56 > type_tag
Definition id.h:205
bitfield< NODE_FIELD_WIDTH, 56 - NODE_FIELD_WIDTH > owner_node
Definition id.h:206
Definition utils.h:202