docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
local_storage.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <string>
5#include <unordered_set>
6#include <vector>
7
22#include "sdfg/tiles/locality.h"
25#include "sdfg/types/type.h"
26
27namespace sdfg {
28namespace transformations {
29
39public:
41 struct TileInfo {
43 std::vector<symbolic::Expression> dimensions;
45 std::vector<symbolic::Expression> bases;
49 std::vector<symbolic::Expression> maxes;
51 std::vector<symbolic::Expression> strides;
54
57 std::vector<size_t> varying_dims() const;
59 std::vector<symbolic::Expression> varying_sizes() const;
67 std::vector<symbolic::Expression> original_subset(const std::vector<symbolic::Expression>& tile_indices) const;
70 std::vector<symbolic::Expression> local_index(const std::vector<symbolic::Expression>& access_subset) const;
71 };
72
76
77private:
79 const data_flow::AccessNode& access_node_;
80 std::string container_;
81 std::string local_name_;
82 types::StorageType storage_type_;
83 TileInfo tile_info_;
85 bool swizzle_layout_ = false;
86 bool lane_contiguous_ = false;
87 bool transpose_layout_ = false;
89 std::unordered_set<const data_flow::Memlet*> group_memlets_;
90 std::vector<structured_control_flow::Reduce*> reduce_retargets_;
92 std::vector<structured_control_flow::Reduce*> grid_reduce_owners_;
94 bool atomic_merge_ = false;
95 bool container_read_ = false;
96 bool container_written_ = false;
97
102 bool prepare(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager);
103
107 bool reduction_buffers_supported(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager);
108
112 void apply_prepared(builder::StructuredSDFGBuilder& builder, analysis::AnalysisManager& analysis_manager);
113
115 bool needs_copy_in() const {
116 return container_read_;
117 }
118
120 bool needs_copy_out() const {
121 return container_written_;
122 }
123
125 size_t max_tile_elements() const {
126 return 1u << 16;
127 }
128
134 symbolic::Condition boundary_guard(
135 const data_flow::Subset& tile_indices,
136 const symbolic::SymbolSet& params = {},
137 const symbolic::Assumptions& assums = {}
138 ) const;
139
143 void emit_private_copy(
144 builder::StructuredSDFGBuilder& builder,
145 analysis::AnalysisManager& analysis_manager,
146 structured_control_flow::Sequence& parent,
147 const tiles::PackedBuffer& buffer,
148 const types::IType& buffer_type,
149 const types::IType& pointer_type,
150 bool writeback
151 );
152
156 struct BuiltCopy {
157 tiles::TiledCopy plan;
158 std::vector<int> coop_axes;
159 tiles::TileGuard guard;
160 symbolic::Expression coop_threads;
161 size_t coop_lanes = 1;
162 };
163
170 BuiltCopy build_tiled_copy(
171 analysis::AnalysisManager& analysis_manager,
172 structured_control_flow::Sequence& guard_scope,
173 const tiles::PackedBuffer& buffer,
174 const types::IType& pointer_type,
175 const std::vector<symbolic::Expression>& slot_sizes,
176 const std::vector<symbolic::Expression>& slot_indices,
177 const std::vector<symbolic::Expression>& slot_indvars,
178 const std::vector<symbolic::Expression>& slot_inits,
179 const std::vector<symbolic::Expression>& slot_strides
180 );
181
185 void emit_copy_node(
186 builder::StructuredSDFGBuilder& builder,
187 structured_control_flow::Sequence& scope,
188 structured_control_flow::ControlFlowNode& anchor,
189 bool after,
190 const BuiltCopy& copy,
192 const types::IType& pointer_type,
193 tiles::CopyDirection direction,
194 bool leading_barrier,
195 bool trailing_barrier
196 );
197
200 tiles::TileGuard tile_boundary_guard(
201 analysis::AnalysisManager& analysis_manager,
202 structured_control_flow::Sequence& guard_scope,
203 const std::vector<symbolic::Expression>& vsizes
204 );
205
208 void rewrite_body(
209 builder::StructuredSDFGBuilder& builder,
210 analysis::AnalysisManager& analysis_manager,
211 const tiles::PackedBuffer& buffer,
212 const types::IType& buffer_type,
213 const std::vector<symbolic::Expression>& slot_indices
214 );
215
218 std::optional<math::tensor::TensorLayout> operand_view(
219 const analysis::MemoryTile& access,
220 const tiles::PackedBuffer& buffer,
221 const std::vector<symbolic::Expression>& slot_indices
222 ) const;
223
227 void choose_conflict_policy(
228 analysis::AnalysisManager& analysis_manager, tiles::PackedBuffer& buffer, types::PrimitiveType element_type
229 );
230
231public:
250 const data_flow::AccessNode& access_node,
251 bool swizzle_layout = false,
252 bool lane_contiguous = false,
253 bool transpose_layout = false
254 )
255 : loop_(loop), access_node_(access_node), container_(access_node.data()),
256 storage_type_(types::StorageType::CPU_Stack()), swizzle_layout_(swizzle_layout),
257 lane_contiguous_(lane_contiguous), transpose_layout_(transpose_layout) {
258 }
259
260 std::string name() const override {
261 return "LocalStorage";
262 }
263
271
275
277 void to_json(nlohmann::json& j) const override;
278
281
283 const std::string& local_container() const {
284 return local_name_;
285 }
286
288 const TileInfo& tile_info() const {
289 return tile_info_;
290 }
291
294 return storage_type_;
295 }
296};
297
298} // namespace transformations
299} // namespace sdfg
Access nodes for reading/writing data in the dataflow graph.
The destination side of a tiled copy — the packed local buffer — as a (possibly swizzled) Layout over...
Definition analysis.h:53
Note: Even though the class references unique_ptr, it will never delete an SDFG it has a reference to...
Definition structured_sdfg_builder.h:44
Node representing access to a data container in the dataflow graph.
Definition access_node.h:84
Base class for structured loop constructs.
Definition structured_loop.h:244
How a tile relates to its enclosing parallel loop nest, and the storage space that relationship deman...
Definition locality.h:24
static bool has_side_effect(structured_control_flow::StructuredLoop &loop)
True if any library node in loop's body has side effects (may touch memory outside the tracked memlet...
static LocalStorage from_json(builder::StructuredSDFGBuilder &builder, const nlohmann::json &j)
JSON deserialization.
LocalStorage(structured_control_flow::StructuredLoop &loop, const data_flow::AccessNode &access_node, bool swizzle_layout=false, bool lane_contiguous=false, bool transpose_layout=false)
Construct a local-storage transformation for access_node's container within loop.
Definition local_storage.h:248
const TileInfo & tile_info() const
Tile info (valid after can_be_applied() returns true).
Definition local_storage.h:288
const std::string & local_container() const
Name of the created local buffer (valid after apply()).
Definition local_storage.h:283
bool can_be_applied(builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
Precondition check: verifies the container is a pointer used in the loop, resolves a single tile grou...
const types::StorageType & storage_type() const
Storage type of the local buffer.
Definition local_storage.h:293
std::string name() const override
Get the name of this transformation.
Definition local_storage.h:260
void apply(builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
Allocate the buffer, emit the derived copies, and redirect loop-body accesses to the buffer.
void to_json(nlohmann::json &j) const override
JSON serialization.
Base class for all SDFG transformations.
Definition transformation.h:25
Represents the storage location and management characteristics of data.
Definition type.h:64
Integer integer(int64_t value)
Creates an integer constant.
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
std::set< Symbol, SymEngine::RCPBasicKeyLess > SymbolSet
Ordered set of symbols.
Definition symbolic.h:95
SymEngine::RCP< const SymEngine::Boolean > Condition
Reference-counted pointer to a boolean condition expression.
Definition symbolic.h:86
Edges in the dataflow graph representing data movement.
Analysis for inferring memory layouts of memlets.
Definition function_builder.h:10
StringEnum ImplementationType
Implementation type identifier for library nodes.
Definition library_node.h:75
symbolic::MultiExpression Subset
Type alias for a subset specification (array of symbolic expressions).
Definition memlet.h:103
math::tensor::TensorLayout Layout
The tiles geometry type is math::tensor::TensorLayout — the single source of truth for a (shape,...
Definition layout.h:11
CopyDirection
Which way the tile moves between the flat (global) side and the packed buffer.
Definition tiled_copy.h:38
Definition loop_parallelization.h:8
Definition symbolic.h:57
PrimitiveType
Enumeration of all primitive data types supported by sdfglib.
Definition type.h:35
Definition analysis.h:7
Reduction-ownership queries for localization: which Reduce nodes accumulate into a container relative...
Normalized tile description handed from can_be_applied() to apply().
Definition local_storage.h:41
std::vector< symbolic::Expression > varying_sizes() const
Extents of the varying dims, in dimension order.
std::vector< symbolic::Expression > dimensions
Overapproximated integer extents per delinearized dimension.
Definition local_storage.h:43
tiles::Layout source_layout() const
The source geometry as a tiles tiles::Layout over the varying tile coordinate (shape = varying extent...
symbolic::Expression offset
Layout offset from MemoryLayoutAnalysis.
Definition local_storage.h:53
std::vector< symbolic::Expression > strides
Layout strides from MemoryLayoutAnalysis (original re-linearization).
Definition local_storage.h:51
std::vector< size_t > varying_dims() const
Indices of the varying (extent > 1) dims, in dimension order.
std::vector< symbolic::Expression > local_index(const std::vector< symbolic::Expression > &access_subset) const
Per-varying-dim local tile index (access_subset[d] - base[d]) for a body access.
std::vector< symbolic::Expression > original_subset(const std::vector< symbolic::Expression > &tile_indices) const
Container linear address for per-varying-dim tile_indices (extent-1 dims use their base).
std::vector< symbolic::Expression > bases
Tile min indices per dimension (bases for index subtraction).
Definition local_storage.h:45
std::vector< symbolic::Expression > maxes
Tile max valid indices per dimension (from MemoryTile::max_subset), e.g.
Definition local_storage.h:49
Symbolic system for integer-based symbol analysis.
A tiled copy plan: move one tile between memory levels.
Core type system definitions for sdfglib.