docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
device_buffer_reuse_pass.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
8#include "sdfg/passes/pass.h"
10#include "sdfg/types/type.h"
12
13namespace sdfg {
14namespace passes {
15
43public:
44 explicit DeviceBufferReusePass(bool consider_dataflow_branching = false);
45
46 std::string name() override;
47
49
50private:
52 bool consider_dataflow_branching_;
53};
54
55
56// A pure device-scratch buffer: it is allocated and freed without any host/device transfer, so its
57// storage can in principle be shared with another buffer whose live range does not overlap.
71
72
73// A pending allocation: a pure ALLOC seen during the traversal that has not yet been matched to a
74// kernel that uses it.
80
81// Single-traversal marker. Walks the SDFG in program order and builds both the candidate list and
82// the interference graph on demand: allocations wait in `unassigned_` until a using kernel is seen,
83// at which point they become live candidates interfering with everything currently live; frees end
84// a live range directly; buffers created in sibling if/else branches cross-interfere.
86public:
89 );
90
91 std::vector<Candidate> candidates;
92 std::vector<std::unordered_set<size_t>> adjacency;
93
94protected:
96
97private:
98 analysis::Users& users_;
99 StructuredSDFG& sdfg_;
100 std::unordered_map<std::string, AllocRec> unassigned_;
101 std::unordered_set<std::string> disqualified_;
102 std::vector<size_t> live_;
103 std::unordered_map<std::string, size_t> live_index_;
104
105 void add_edge(size_t a, size_t b);
106
107 // Promote a pending allocation to a live candidate once a using kernel has been found.
108 void assign(const std::string& container);
109
110 // End a buffer's live range at its free.
111 void close(
112 const std::string& container,
115 const data_flow::AccessNode* access
116 );
117
118 void process_block(structured_control_flow::Block& block);
119};
120
121} // namespace passes
122} // namespace sdfg
Definition structured_sdfg.h:30
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
Name does not match current function.
Definition data_offloading_node.h:49
bool visit_internal(structured_control_flow::Sequence &parent) override
BufferReuseMarker(builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager, analysis::Users &users)
std::vector< Candidate > candidates
Definition device_buffer_reuse_pass.h:91
std::vector< std::unordered_set< size_t > > adjacency
Definition device_buffer_reuse_pass.h:92
bool run_pass(builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
DeviceBufferReusePass(bool consider_dataflow_branching=false)
A control flow node representing a basic block with dataflow computations.
Definition block.h:42
A sequential container of control flow nodes.
Definition sequence.h:52
Definition user.h:28
Definition users.h:19
Very specific implementation, that technically visits the SDFG of an StructuredSDFGBuilder and not ju...
Definition structured_sdfg_visitor.h:16
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
Definition function_builder.h:10
Definition approximate_math.h:12
PrimitiveType
Enumeration of all primitive data types supported by sdfglib.
Definition type.h:35
Definition base_user_visitor.h:5
Definition analysis.h:7
Definition device_buffer_reuse_pass.h:75
offloading::DataOffloadingNode * node
Definition device_buffer_reuse_pass.h:77
structured_control_flow::Block * block
Definition device_buffer_reuse_pass.h:76
const data_flow::AccessNode * access
Definition device_buffer_reuse_pass.h:78
Definition device_buffer_reuse_pass.h:58
std::string container
Definition device_buffer_reuse_pass.h:59
offloading::DataOffloadingNode * alloc_node
Definition device_buffer_reuse_pass.h:64
structured_control_flow::Block * alloc_block
Definition device_buffer_reuse_pass.h:63
structured_control_flow::Block * free_block
Definition device_buffer_reuse_pass.h:67
symbolic::Expression size
Definition device_buffer_reuse_pass.h:61
types::PrimitiveType dtype
Definition device_buffer_reuse_pass.h:60
analysis::User * alloc_user
Definition device_buffer_reuse_pass.h:65
offloading::DataOffloadingNode * free_node
Definition device_buffer_reuse_pass.h:68
analysis::User * free_user
Definition device_buffer_reuse_pass.h:69
Core type system definitions for sdfglib.