Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
address_list.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Los Alamos National Laboratory, 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#ifndef ADDRESS_LIST
19#define ADDRESS_LIST
20
21#include "realm/realm_config.h"
22#include "realm/indexspace.h"
23#include "realm/id.h"
24
25#include <array>
26#include <cstring>
27#include <unordered_map>
28
29namespace Realm {
30
31 template <typename FieldID>
33 std::size_t count;
35
36 // allocate a FieldBlock via heap.alloc_obj and store n field IDs
37 template <typename Heap>
38 static FieldBlockBase<FieldID> *create(Heap &heap, const FieldID *src, size_t n,
39 size_t align = 16)
40 {
41 const size_t bytes = sizeof(FieldBlockBase<FieldID>) + (n - 1) * sizeof(FieldID);
42 void *mem = heap.alloc_obj(bytes, align);
44 field_block->count = n;
45 std::copy_n(src, n, field_block->fields);
46 return field_block;
47 }
48 };
49
51
52 // =================================================================================================
53 // AddressList
54 // =================================================================================================
56 public:
57 AddressList(size_t _max_entries = 1000);
58
59 // ─── entry construction ──────────────────────────────────────────────────────
60 [[nodiscard]] bool
61 append_entry(int dims, size_t contig_bytes, size_t total_bytes, size_t base_offset,
62 const std::unordered_map<int, std::pair<size_t, size_t>> &count_strides,
63 bool wrap_around = false);
64
65 [[nodiscard]] size_t *begin_entry(int max_dim, bool wrap_around = true);
66 void commit_entry(int act_dim, size_t bytes);
67 void attach_field_block(const FieldBlock *_field_block);
68
69 [[nodiscard]] size_t bytes_pending() const;
70 [[nodiscard]] size_t full_field_bytes();
71
72 // entry packs:
73 // the contiguous byte count (contig_bytes) in the upper bitsthe
74 // the actual dimension count (act_dim) in the lower 4 bits
75 [[nodiscard]] static size_t pack_entry_header(size_t contig_bytes, int dims);
76
77 // ─── layout constants ───────────────────────────────────────────────────────
78 static constexpr size_t SLOT_HEADER = 0;
79 static constexpr size_t SLOT_BASE = 1;
80 static constexpr size_t DIM_SLOTS = 2;
81 static constexpr size_t DIM_MASK = 0xF;
82 static constexpr size_t CONTIG_SHIFT = 4;
83
84 protected:
85 friend class AddressListCursor;
86 [[nodiscard]] const size_t *read_entry();
87
88 const FieldBlock *field_block{nullptr};
89
90 size_t total_bytes{0};
91 size_t write_pointer{0};
92 size_t read_pointer{0};
93 size_t max_entries{0};
94 std::vector<size_t> data;
95 };
96
97 // =================================================================================================
98 // AddressListCursor
99 // =================================================================================================
101 public:
103
104 void set_addrlist(AddressList *_addrlist);
105
106 // ─── layout accessors ──────────────────────────────────────────────────────
107 [[nodiscard]] int get_dim() const;
108 [[nodiscard]] uintptr_t get_offset() const;
109 [[nodiscard]] uintptr_t get_stride(int dim) const;
110 [[nodiscard]] size_t remaining(int dim) const;
111
112 // ─── progress───────────────────────────────────────────────────────────────
113 void advance(int dim, size_t amount, int f = 1);
114 void skip_bytes(size_t bytes);
115
116 // ─── field accessors ──────────────────────────────────────────────────────
117 [[nodiscard]] const FieldBlock *field_block() const;
118 [[nodiscard]] const FieldID *fields_data() const;
119 [[nodiscard]] size_t remaining_fields() const;
120
122 bool partial{false}; // inside a dimension
123
124 protected:
125 int partial_dim{0}; // dimension index
126 size_t partial_fields{0};
127 std::array<size_t, REALM_MAX_DIM + 1> pos{};
128 };
129
130 std::ostream &operator<<(std::ostream &os, const AddressListCursor &alc);
131} // namespace Realm
132
133#endif
Definition address_list.h:100
size_t partial_fields
Definition address_list.h:126
int partial_dim
Definition address_list.h:125
size_t remaining(int dim) const
uintptr_t get_offset() const
std::array< size_t, REALM_MAX_DIM+1 > pos
Definition address_list.h:127
void skip_bytes(size_t bytes)
void set_addrlist(AddressList *_addrlist)
size_t remaining_fields() const
const FieldBlock * field_block() const
void advance(int dim, size_t amount, int f=1)
uintptr_t get_stride(int dim) const
AddressList * addrlist
Definition address_list.h:121
bool partial
Definition address_list.h:122
const FieldID * fields_data() const
Definition address_list.h:55
size_t * begin_entry(int max_dim, bool wrap_around=true)
size_t max_entries
Definition address_list.h:93
bool append_entry(int dims, size_t contig_bytes, size_t total_bytes, size_t base_offset, const std::unordered_map< int, std::pair< size_t, size_t > > &count_strides, bool wrap_around=false)
std::vector< size_t > data
Definition address_list.h:94
size_t total_bytes
Definition address_list.h:90
void attach_field_block(const FieldBlock *_field_block)
static size_t pack_entry_header(size_t contig_bytes, int dims)
static constexpr size_t DIM_SLOTS
Definition address_list.h:80
void commit_entry(int act_dim, size_t bytes)
static constexpr size_t SLOT_BASE
Definition address_list.h:79
size_t full_field_bytes()
const FieldBlock * field_block
Definition address_list.h:88
static constexpr size_t SLOT_HEADER
Definition address_list.h:78
size_t read_pointer
Definition address_list.h:92
AddressList(size_t _max_entries=1000)
size_t write_pointer
Definition address_list.h:91
const size_t * read_entry()
static constexpr size_t CONTIG_SHIFT
Definition address_list.h:82
static constexpr size_t DIM_MASK
Definition address_list.h:81
size_t bytes_pending() const
Definition activemsg.h:38
realm_field_id_t FieldID
Definition instance.h:45
std::ostream & operator<<(std::ostream &os, const DenseRectangleList< N, T > &drl)
Definition address_list.h:32
static FieldBlockBase< FieldID > * create(Heap &heap, const FieldID *src, size_t n, size_t align=16)
Definition address_list.h:38
std::size_t count
Definition address_list.h:33
FieldID fields[1]
Definition address_list.h:34
NodeID src
Definition ucp_internal.h:1