Legion Runtime
Loading...
Searching...
No Matches
buffers.h
Go to the documentation of this file.
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
24#include "legion/api/data.h"
25#include "legion/api/values.h"
26
27namespace Legion {
28
34 public:
35 DeferredBufferRequest(void) = default;
36 // Convenience constructors
38 Memory mem, 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::Kind kind, const Domain& bounds, 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 mem, 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);
53 Memory::Kind kind, const IndexSpace& space, size_t size,
54 size_t align = alignof(std::max_align_t),
55 bool fortran_order_dims = false, const void* initial = nullptr,
56 bool escaping = true);
57 public:
58 size_t field_size = 0;
59 size_t alignment = alignof(std::max_align_t);
60 const void* initial_value = nullptr;
61 std::vector<DimensionKind> dim_order;
62 union {
63 Memory exact = Memory::NO_MEMORY;
64 Memory::Kind kind;
65 } memory;
66 union {
67 Domain value;
68 IndexSpace name;
69 } bounds = {Domain::NO_DOMAIN};
70 bool is_exact = true;
71 bool is_value = true;
72 bool can_fail = false;
73 bool escaping = true;
74 };
75
93 template<
94 typename T, int DIM, typename COORD_T = coord_t,
95#ifdef LEGION_BOUNDS_CHECKS
96 bool CHECK_BOUNDS = true>
97#else
98 bool CHECK_BOUNDS = false>
99#endif
101 private:
102 static_assert(DIM > 0, "DIM must be positive");
103 static_assert(DIM <= LEGION_MAX_DIM, "DIM must be <= LEGION_MAX_DIM");
104 static_assert(std::is_integral<COORD_T>::value, "must be integral type");
105 public:
106 DeferredBuffer(void);
107 public: // Constructors specifying a generic memory kind
109 Memory::Kind kind, const Domain& bounds,
110 const T* initial_value = nullptr,
111 size_t alignment = std::alignment_of<T>(),
112 bool fortran_order_dims = false, bool escaping = true);
114 const Rect<DIM, COORD_T>& bounds, Memory::Kind kind,
115 const T* initial_value = nullptr,
116 size_t alignment = std::alignment_of<T>(),
117 bool fortran_order_dims = false, bool escaping = true);
118 public: // Constructors specifying a specific memory
120 Memory memory, const Domain& bounds, const T* initial_value = nullptr,
121 size_t alignment = std::alignment_of<T>(),
122 bool fortran_order_dims = false, bool escaping = true);
124 const Rect<DIM, COORD_T>& bounds, Memory memory,
125 const T* initial_value = nullptr,
126 size_t alignment = std::alignment_of<T>(),
127 bool fortran_order_dims = false, bool escaping = true);
128 public: // Constructors specifying a specific ordering
130 Memory::Kind kind, const Domain& bounds,
131 std::array<DimensionKind, DIM> ordering,
132 const T* initial_value = nullptr,
133 size_t alignment = std::alignment_of<T>(), bool escaping = true);
135 const Rect<DIM, COORD_T>& bounds, Memory::Kind kind,
136 std::array<DimensionKind, DIM> ordering,
137 const T* initial_value = nullptr,
138 size_t alignment = std::alignment_of<T>(), bool escaping = true);
140 Memory memory, const Domain& bounds,
141 std::array<DimensionKind, DIM> ordering,
142 const T* initial_value = nullptr,
143 size_t alignment = std::alignment_of<T>(), bool escaping = true);
145 const Rect<DIM, COORD_T>& bounds, Memory memory,
146 std::array<DimensionKind, DIM> ordering,
147 const T* initial_value = nullptr,
148 size_t alignment = std::alignment_of<T>(), bool escaping = true);
149 public:
150 __LEGION_CUDA_HD__
151 inline T read(const Point<DIM, COORD_T>& p) const;
152 __LEGION_CUDA_HD__
153 inline void write(const Point<DIM, COORD_T>& p, T value) const;
154 __LEGION_CUDA_HD__
155 inline T* ptr(const Point<DIM, COORD_T>& p) const;
156 __LEGION_CUDA_HD__
157 inline T* ptr(const Rect<DIM, COORD_T>& r) const; // must be dense
158 __LEGION_CUDA_HD__
159 inline T* ptr(const Rect<DIM, COORD_T>& r, size_t strides[DIM]) const;
160 __LEGION_CUDA_HD__
161 inline T& operator[](const Point<DIM, COORD_T>& p) const;
162 public:
163 inline bool exists(void) const { return instance.exists(); }
164 inline void destroy(Realm::Event precondition = Realm::Event::NO_EVENT);
165 __LEGION_CUDA_HD__
166 inline Realm::RegionInstance get_instance(void) const;
167 __LEGION_CUDA_HD__
168 inline Rect<DIM, COORD_T> get_bounds(void) const;
169 public:
170 typedef T value_type;
171 typedef T& reference;
172 typedef const T& const_reference;
173 protected:
174 friend class OutputRegion;
175 friend class UntypedDeferredBuffer<COORD_T>;
176 Realm::RegionInstance instance;
177 Realm::AffineAccessor<T, DIM, COORD_T> accessor;
178 std::array<DimensionKind, DIM> ordering;
179 Rect<DIM, COORD_T> bounds;
180 size_t alignment;
181 };
182
189 template<typename COORD_T = coord_t>
191 private:
192 static_assert(std::is_integral<COORD_T>::value, "must be integral type");
193 public:
195 public: // Constructors specifying a generic memory kind
197 size_t field_size, int dims, Memory::Kind kind, const Domain& bounds,
198 const void* initial_value = nullptr, size_t alignment = 16,
199 bool fortran_order_dims = false, bool escaping = true);
201 size_t field_size, int dims, Memory::Kind kind, IndexSpace bounds,
202 const void* initial_value = nullptr, size_t alignment = 16,
203 bool fortran_order_dims = false, bool escaping = true);
204 public: // Constructors specifying a specific memory
206 size_t field_size, int dims, Memory memory, const Domain& bounds,
207 const void* initial_value = nullptr, size_t alignment = 16,
208 bool fortran_order_dims = false, bool escaping = true);
210 size_t field_size, int dims, Memory memory, IndexSpace bounds,
211 const void* initial_value = nullptr, size_t alignment = 16,
212 bool fortran_order_dims = false, bool escaping = true);
213 public:
214 template<typename T, int DIM>
215 UntypedDeferredBuffer(const DeferredBuffer<T, DIM, COORD_T>& rhs);
216 public:
217 template<typename T, int DIM, bool BC>
218 inline operator DeferredBuffer<T, DIM, COORD_T, BC>(void) const;
219 public:
220 inline bool exists(void) const { return instance.exists(); }
221 void destroy(Realm::Event precondition = Realm::Event::NO_EVENT);
222 inline Realm::RegionInstance get_instance(void) const { return instance; }
223 private:
224 static UntypedDeferredBuffer<COORD_T> allocate_buffer(
225 const DeferredBufferRequest& request);
226 static void report_nondense_rect(void);
227 friend class Runtime;
228 template<PrivilegeMode, typename, int, typename, typename, bool>
229 friend class FieldAccessor;
230 template<typename, bool, int, typename, typename, bool>
231 friend class ReductionAccessor;
232 template<typename, int, typename, bool>
233 friend class DeferredBuffer;
234 Realm::RegionInstance instance;
235 size_t field_size;
236 int dims;
237 };
238
239} // namespace Legion
240
241#include "legion/api/buffers.inl"
242
243#endif // __LEGION_DEFERRED_BUFFERS_H__
Definition buffers.h:100
Definition geometry.h:159
Definition accessors.h:76
Definition data.h:35
Definition output_region.h:34
Definition accessors.h:384
Definition runtime.h:108
Definition types.h:343
Definition buffers.h:190
Definition accessors.h:29
Definition buffers.h:33