Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
nodeset.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// dynamic node set implementation for Realm
19
20#ifndef REALM_NODESET_H
21#define REALM_NODESET_H
22
23#include "realm/realm_config.h"
24#include "realm/mutex.h"
25
26#include <stdint.h>
27#include <iterator>
28
29#ifdef DEBUG_REALM
30// define DEBUG_REALM_NODESET
31#endif
32
33#ifdef DEBUG_REALM_NODESET
34#include <set>
35#endif
36
37namespace Realm {
38
39 // TODO: optimize for fairly-common case of 'short' being sufficient?
40 typedef int NodeID;
41
42 class NodeSet;
43
44 // we do not support mutation of a nodeset, so we're a const_iterator
46 public:
47 // explicitly set iterator traits
48 typedef std::input_iterator_tag iterator_category;
50 typedef std::ptrdiff_t difference_type;
51 typedef NodeID *pointer;
52 typedef NodeID &reference;
53
55 NodeSetIterator(const NodeSet &_nodeset);
56
57 bool operator==(const NodeSetIterator &compare_to) const;
58 bool operator!=(const NodeSetIterator &compare_to) const;
59
61 const NodeID *operator->() const;
62
64 NodeSetIterator operator++(int /*postfix*/);
65
66 protected:
69 short iter_pos; // needed for non-bitmask encodings
70 };
71
73 protected:
75
76 public:
77 static void configure_allocator(NodeID _max_node_id, size_t _bitsets_per_chunk,
78 bool _use_twolevel);
79 static void free_allocations();
80
82 static NodeSetBitmask *clone_bitmask(const NodeSetBitmask *clone_from);
83
84 static void release_bitmask(NodeSetBitmask *bitmask, bool already_empty);
85
86 size_t set_bit(NodeID id);
87 size_t clear_bit(NodeID id);
88
89 size_t set_range(NodeID lo, NodeID hi);
90 size_t clear_range(NodeID lo, NodeID hi);
91
92 bool is_set(NodeID id) const;
93
95 NodeID next_set(NodeID after) const;
96
97 void copy(const NodeSetBitmask *copy_from);
98
99 protected:
100 void l2_set(int elmt_idx);
101 void l2_clear(int elmt_idx);
102 int l2_find(int first_idx) const;
103
104 typedef uint64_t bitmask_elem_t;
105
106 static const size_t BITS_PER_ELEM = 8 * sizeof(bitmask_elem_t);
107
109
111 static size_t bitset_elements, bitsets_per_chunk;
112 static size_t bitset_twolevel;
113 static uintptr_t alloc_chain_head, free_list_head;
115 };
116
118 public:
121
122 NodeSet(const NodeSet &copy_from);
123
124 NodeSet &operator=(const NodeSet &copy_from);
125
126 void swap(NodeSet &swap_with);
127
128 bool empty() const;
129 size_t size() const;
130
131 void add(NodeID id);
132 void remove(NodeID id);
133
134 void add_range(NodeID lo, NodeID hi);
136
137 void clear();
138
139 bool contains(NodeID id) const;
140
142
145
146 protected:
147 friend class NodeSetIterator;
148
149 unsigned count;
150
151 enum
152 {
154 ENC_VALS, // one or more distinct values
155 ENC_RANGES, // one or more non-overlapping ranges
156 ENC_BITMASK, // full (externally-allocated) bitmask
157 };
158 unsigned char enc_format;
160 static const short MAX_VALUES = 4;
161 static const short MAX_RANGES = 2;
163 NodeID values[MAX_VALUES];
164 struct {
166 } ranges[MAX_RANGES];
168 };
170#ifdef DEBUG_REALM_NODESET
171 std::set<NodeID> reference_set;
172#endif
173
175 };
176
177}; // namespace Realm
178
179#include "realm/nodeset.inl"
180
181#endif // ifndef REALM_NODESET_H
Definition nodeset.h:72
static uintptr_t alloc_chain_head
Definition nodeset.h:113
void l2_set(int elmt_idx)
uint64_t bitmask_elem_t
Definition nodeset.h:104
size_t set_range(NodeID lo, NodeID hi)
NodeID first_set() const
size_t set_bit(NodeID id)
static size_t bitset_elements
Definition nodeset.h:111
static void free_allocations()
static void release_bitmask(NodeSetBitmask *bitmask, bool already_empty)
NodeID next_set(NodeID after) const
size_t clear_bit(NodeID id)
static NodeSetBitmask * clone_bitmask(const NodeSetBitmask *clone_from)
size_t clear_range(NodeID lo, NodeID hi)
static Mutex free_list_mutex
Definition nodeset.h:114
static size_t bitset_twolevel
Definition nodeset.h:112
static void configure_allocator(NodeID _max_node_id, size_t _bitsets_per_chunk, bool _use_twolevel)
static NodeID max_node_id
Definition nodeset.h:110
bool is_set(NodeID id) const
void copy(const NodeSetBitmask *copy_from)
void l2_clear(int elmt_idx)
int l2_find(int first_idx) const
static NodeSetBitmask * acquire_bitmask()
Definition nodeset.h:45
NodeSetIterator & operator++()
NodeSetIterator(const NodeSet &_nodeset)
std::input_iterator_tag iterator_category
Definition nodeset.h:48
const NodeSet * nodeset
Definition nodeset.h:67
bool operator==(const NodeSetIterator &compare_to) const
NodeID operator*() const
const NodeID * operator->() const
NodeID cur_node
Definition nodeset.h:68
bool operator!=(const NodeSetIterator &compare_to) const
NodeID & reference
Definition nodeset.h:52
short iter_pos
Definition nodeset.h:69
std::ptrdiff_t difference_type
Definition nodeset.h:50
NodeID * pointer
Definition nodeset.h:51
NodeID value_type
Definition nodeset.h:49
NodeSetIterator operator++(int)
Definition nodeset.h:117
const_iterator end() const
NodeSet(const NodeSet &copy_from)
size_t size() const
short range_count
Definition nodeset.h:159
NodeSet & operator=(const NodeSet &copy_from)
bool contains(NodeID id) const
EncodingUnion data
Definition nodeset.h:169
void add_range(NodeID lo, NodeID hi)
const_iterator begin() const
NodeSetIterator const_iterator
Definition nodeset.h:141
void remove(NodeID id)
bool empty() const
void convert_to_bitmask()
unsigned char enc_format
Definition nodeset.h:158
void remove_range(NodeID lo, NodeID hi)
void add(NodeID id)
@ ENC_VALS
Definition nodeset.h:154
@ ENC_RANGES
Definition nodeset.h:155
@ ENC_BITMASK
Definition nodeset.h:156
@ ENC_EMPTY
Definition nodeset.h:153
void swap(NodeSet &swap_with)
unsigned count
Definition nodeset.h:149
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
Definition nodeset.h:162
NodeSetBitmask * bitmask
Definition nodeset.h:167
NodeID hi
Definition nodeset.h:165