Legion Runtime
Loading...
Searching...
No Matches
buffers.h
1/* Copyright 2026 Stanford University, NVIDIA Corporation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __LEGION_DEFERRED_BUFFERS_H__
17#define __LEGION_DEFERRED_BUFFERS_H__
18
19#include "legion/api/data.h"
20#include "legion/api/values.h"
21
22namespace Legion {
23
29 public:
30 DeferredBufferRequest(void) = default;
31 // Convenience constructors
33 Memory mem, const Domain& bounds, size_t size,
34 size_t align = alignof(std::max_align_t),
35 bool fortran_order_dims = false, const void* initial = nullptr,
36 bool escaping = true);
38 Memory::Kind kind, const Domain& bounds, size_t size,
39 size_t align = alignof(std::max_align_t),
40 bool fortran_order_dims = false, const void* initial = nullptr,
41 bool escaping = true);
43 Memory mem, const IndexSpace& space, size_t size,
44 size_t align = alignof(std::max_align_t),
45 bool fortran_order_dims = false, const void* initial = nullptr,
46 bool escaping = true);
48 Memory::Kind kind, const IndexSpace& space, size_t size,
49 size_t align = alignof(std::max_align_t),
50 bool fortran_order_dims = false, const void* initial = nullptr,
51 bool escaping = true);
52 public:
53 size_t field_size = 0;
54 size_t alignment = alignof(std::max_align_t);
55 const void* initial_value = nullptr;
56 std::vector<DimensionKind> dim_order;
57 union {
58 Memory exact = Memory::NO_MEMORY;
59 Memory::Kind kind;
60 } memory;
61 union {
62 Domain value;
63 IndexSpace name;
64 } bounds = {Domain::NO_DOMAIN};
65 bool is_exact = true;
66 bool is_value = true;
67 bool can_fail = false;
68 bool escaping = true;
69 };
70
88 template<
89 typename T, int DIM, typename COORD_T = coord_t,
90#ifdef LEGION_BOUNDS_CHECKS
91 bool CHECK_BOUNDS = true>
92#else
93 bool CHECK_BOUNDS = false>
94#endif
96 private:
97 static_assert(DIM > 0, "DIM must be positive");
98 static_assert(DIM <= LEGION_MAX_DIM, "DIM must be <= LEGION_MAX_DIM");
99 static_assert(std::is_integral<COORD_T>::value, "must be integral type");
100 public:
101 DeferredBuffer(void);
102 public: // Constructors specifying a generic memory kind
104 Memory::Kind kind, const Domain& bounds,
105 const T* initial_value = nullptr,
106 size_t alignment = std::alignment_of<T>(),
107 bool fortran_order_dims = false, bool escaping = true);
109 const Rect<DIM, COORD_T>& bounds, Memory::Kind kind,
110 const T* initial_value = nullptr,
111 size_t alignment = std::alignment_of<T>(),
112 bool fortran_order_dims = false, bool escaping = true);
113 public: // Constructors specifying a specific memory
115 Memory memory, const Domain& bounds, const T* initial_value = nullptr,
116 size_t alignment = std::alignment_of<T>(),
117 bool fortran_order_dims = false, bool escaping = true);
119 const Rect<DIM, COORD_T>& bounds, Memory memory,
120 const T* initial_value = nullptr,
121 size_t alignment = std::alignment_of<T>(),
122 bool fortran_order_dims = false, bool escaping = true);
123 public: // Constructors specifying a specific ordering
125 Memory::Kind kind, const Domain& bounds,
126 std::array<DimensionKind, DIM> ordering,
127 const T* initial_value = nullptr,
128 size_t alignment = std::alignment_of<T>(), bool escaping = true);
130 const Rect<DIM, COORD_T>& bounds, Memory::Kind kind,
131 std::array<DimensionKind, DIM> ordering,
132 const T* initial_value = nullptr,
133 size_t alignment = std::alignment_of<T>(), bool escaping = true);
135 Memory memory, const Domain& bounds,
136 std::array<DimensionKind, DIM> ordering,
137 const T* initial_value = nullptr,
138 size_t alignment = std::alignment_of<T>(), bool escaping = true);
140 const Rect<DIM, COORD_T>& bounds, Memory memory,
141 std::array<DimensionKind, DIM> ordering,
142 const T* initial_value = nullptr,
143 size_t alignment = std::alignment_of<T>(), bool escaping = true);
144 public:
145 __LEGION_CUDA_HD__
146 inline T read(const Point<DIM, COORD_T>& p) const;
147 __LEGION_CUDA_HD__
148 inline void write(const Point<DIM, COORD_T>& p, T value) const;
149 __LEGION_CUDA_HD__
150 inline T* ptr(const Point<DIM, COORD_T>& p) const;
151 __LEGION_CUDA_HD__
152 inline T* ptr(const Rect<DIM, COORD_T>& r) const; // must be dense
153 __LEGION_CUDA_HD__
154 inline T* ptr(const Rect<DIM, COORD_T>& r, size_t strides[DIM]) const;
155 __LEGION_CUDA_HD__
156 inline T& operator[](const Point<DIM, COORD_T>& p) const;
157 public:
158 inline bool exists(void) const { return instance.exists(); }
159 inline void destroy(Realm::Event precondition = Realm::Event::NO_EVENT);
160 __LEGION_CUDA_HD__
161 inline Realm::RegionInstance get_instance(void) const;
162 __LEGION_CUDA_HD__
163 inline Rect<DIM, COORD_T> get_bounds(void) const;
164 public:
165 typedef T value_type;
166 typedef T& reference;
167 typedef const T& const_reference;
168 protected:
169 friend class OutputRegion;
170 friend class UntypedDeferredBuffer<COORD_T>;
171 Realm::RegionInstance instance;
172 Realm::AffineAccessor<T, DIM, COORD_T> accessor;
173 std::array<DimensionKind, DIM> ordering;
174 Rect<DIM, COORD_T> bounds;
175 size_t alignment;
176 };
177
184 template<typename COORD_T = coord_t>
186 private:
187 static_assert(std::is_integral<COORD_T>::value, "must be integral type");
188 public:
190 public: // Constructors specifying a generic memory kind
192 size_t field_size, int dims, Memory::Kind kind, const Domain& bounds,
193 const void* initial_value = nullptr, size_t alignment = 16,
194 bool fortran_order_dims = false, bool escaping = true);
196 size_t field_size, int dims, Memory::Kind kind, IndexSpace bounds,
197 const void* initial_value = nullptr, size_t alignment = 16,
198 bool fortran_order_dims = false, bool escaping = true);
199 public: // Constructors specifying a specific memory
201 size_t field_size, int dims, Memory memory, const Domain& bounds,
202 const void* initial_value = nullptr, size_t alignment = 16,
203 bool fortran_order_dims = false, bool escaping = true);
205 size_t field_size, int dims, Memory memory, IndexSpace bounds,
206 const void* initial_value = nullptr, size_t alignment = 16,
207 bool fortran_order_dims = false, bool escaping = true);
208 public:
209 template<typename T, int DIM>
210 UntypedDeferredBuffer(const DeferredBuffer<T, DIM, COORD_T>& rhs);
211 public:
212 template<typename T, int DIM, bool BC>
213 inline operator DeferredBuffer<T, DIM, COORD_T, BC>(void) const;
214 public:
215 inline bool exists(void) const { return instance.exists(); }
216 void destroy(Realm::Event precondition = Realm::Event::NO_EVENT);
217 inline Realm::RegionInstance get_instance(void) const { return instance; }
218 private:
219 static UntypedDeferredBuffer<COORD_T> allocate_buffer(
220 const DeferredBufferRequest& request);
221 static void report_nondense_rect(void);
222 friend class Runtime;
223 template<PrivilegeMode, typename, int, typename, typename, bool>
224 friend class FieldAccessor;
225 template<typename, bool, int, typename, typename, bool>
226 friend class ReductionAccessor;
227 template<typename, int, typename, bool>
228 friend class DeferredBuffer;
229 Realm::RegionInstance instance;
230 size_t field_size;
231 int dims;
232 };
233
234} // namespace Legion
235
236#include "legion/api/buffers.inl"
237
238#endif // __LEGION_DEFERRED_BUFFERS_H__
Definition buffers.h:95
Definition geometry.h:154
Definition accessors.h:71
Definition data.h:30
Definition output_region.h:29
Definition accessors.h:379
Definition runtime.h:103
Definition types.h:334
Definition buffers.h:185
Definition buffers.h:28