-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathGraphProcessingPipeline.html
More file actions
248 lines (246 loc) · 15.9 KB
/
Copy pathGraphProcessingPipeline.html
File metadata and controls
248 lines (246 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!-- HTML header for doxygen 1.13.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.13.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Taskflow: A General-purpose Task-parallel Programming System: Graph Processing Pipeline</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="custom.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="taskflow_logo.png"/></td>
<td id="projectalign">
<div id="projectname"><a href="https://github.com/taskflow/taskflow" style="color:inherit; text-decoration:none;">Taskflow: A General-purpose Task-parallel Programming System</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.13.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function(){initNavTree('GraphProcessingPipeline.html',''); initResizable(true); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div><div class="header">
<div class="headertitle"><div class="title">Graph Processing Pipeline</div></div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul>
<li class="level1">
<a href="#FormulateTheGraphProcessingPipelineProblem">Problem Formulation</a>
</li>
<li class="level1">
<a href="#CreateAGraphProcessingPipeline">Implementation</a>
<ul>
<li class="level2">
<a href="#GraphPipelineTopologicalOrder">Topological Order</a>
</li>
<li class="level2">
<a href="#GraphPipelineOutput">Sample Output</a>
</li>
</ul>
</li>
<li class="level1">
<a href="#GraphPipelineReference">Reference</a>
</li>
</ul>
</div>
<div class="textblock"><p>We study a graph processing pipeline that propagates a sequence of stage functions through the nodes of a DAG in topological order. This example shows how task graph parallelism and pipeline parallelism can be combined — and when one model outperforms the other.</p>
<h1><a class="anchor" id="FormulateTheGraphProcessingPipelineProblem"></a>
Problem Formulation</h1>
<p>Given a DAG where each node must execute three sequential stage functions <code>f1</code>, <code>f2</code>, <code>f3</code>, and where an edge <code>u→v</code> requires <code>fi(u)</code> to complete before <code>fi(v)</code> starts, we want to process all nodes as quickly as possible.</p>
<p>The following figure shows the per-node stage dependency for a three-node DAG with edges <code>A→B</code> and <code>A→C:</code> </p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_graph_pipeline_1.svg" width="267" height="256"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<p>One approach is pure task graph parallelism: one task per node that runs <code>f1</code>, <code>f2</code>, <code>f3</code> sequentially. This is simple but leaves pipeline stages idle whenever one stage finishes before the next node is ready.</p>
<p>A better approach transforms the problem into pipeline parallelism by finding a topological order of the DAG (e.g., <code>A</code>, <code>B</code>, <code>C</code>) and treating each node as a <em>token</em> that flows through a three-stage pipeline. The following figure shows the resulting pipeline execution:</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_graph_pipeline_2.svg" width="275" height="443"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<p>Stages on the same anti-diagonal can execute simultaneously. For example, <code>f3(A)</code>, <code>f2(B)</code>, and <code>f1(C)</code> can all run in parallel — this is <em>wavefront</em> <em>parallelism</em> over the (stage × node) grid.</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_graph_pipeline_3.svg" width="275" height="251"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<dl class="section note"><dt>Note</dt><dd>The relative performance of task graph parallelism vs pipeline parallelism depends on graph size and stage count. A small, wide graph with many short stage functions often favours task graph parallelism; a long chain with expensive stages favours pipelining. Benchmark both on your workload.</dd></dl>
<h1><a class="anchor" id="CreateAGraphProcessingPipeline"></a>
Implementation</h1>
<p>We create a three-serial-pipe pipeline. Each pipe calls the stage function for the node identified by the current token index into the topological order:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include <taskflow/taskflow.hpp></span></div>
<div class="line"><span class="preprocessor">#include <taskflow/algorithm/pipeline.hpp></span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> f1(<span class="keyword">const</span> std::string& node) { printf(<span class="stringliteral">"f1(%s)\n"</span>, node.c_str()); }</div>
<div class="line"><span class="keywordtype">void</span> f2(<span class="keyword">const</span> std::string& node) { printf(<span class="stringliteral">"f2(%s)\n"</span>, node.c_str()); }</div>
<div class="line"><span class="keywordtype">void</span> f3(<span class="keyword">const</span> std::string& node) { printf(<span class="stringliteral">"f3(%s)\n"</span>, node.c_str()); }</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> </div>
<div class="line"> tf::Taskflow taskflow(<span class="stringliteral">"graph pipeline"</span>);</div>
<div class="line"> tf::Executor executor;</div>
<div class="line"> </div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">size_t</span> num_lines = 2;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// topological order of the DAG: A → {B, C}</span></div>
<div class="line"> <span class="keyword">const</span> std::vector<std::string> nodes = {<span class="stringliteral">"A"</span>, <span class="stringliteral">"B"</span>, <span class="stringliteral">"C"</span>};</div>
<div class="line"> </div>
<div class="line"> tf::Pipeline pl(num_lines,</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// stage 1: run f1 for the current node, or stop when all are done</span></div>
<div class="line"> tf::Pipe{<a class="code hl_enumvalue" href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a>, [&](tf::Pipeflow& pf) {</div>
<div class="line"> <span class="keywordflow">if</span>(pf.token() == nodes.size()) {</div>
<div class="line"> pf.stop();</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span> {</div>
<div class="line"> f1(nodes[pf.token()]);</div>
<div class="line"> }</div>
<div class="line"> }},</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// stage 2: run f2 for the current node</span></div>
<div class="line"> tf::Pipe{<a class="code hl_enumvalue" href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a>, [&](tf::Pipeflow& pf) {</div>
<div class="line"> f2(nodes[pf.token()]);</div>
<div class="line"> }},</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// stage 3: run f3 for the current node</span></div>
<div class="line"> tf::Pipe{<a class="code hl_enumvalue" href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a>, [&](tf::Pipeflow& pf) {</div>
<div class="line"> f3(nodes[pf.token()]);</div>
<div class="line"> }}</div>
<div class="line"> );</div>
<div class="line"> </div>
<div class="line"> tf::Task init = taskflow.emplace([](){ std::cout << <span class="stringliteral">"ready\n"</span>; })</div>
<div class="line"> .name(<span class="stringliteral">"start"</span>);</div>
<div class="line"> tf::Task pipe = taskflow.composed_of(pl)</div>
<div class="line"> .name(<span class="stringliteral">"pipeline"</span>);</div>
<div class="line"> tf::Task done = taskflow.emplace([](){ std::cout << <span class="stringliteral">"done\n"</span>; })</div>
<div class="line"> .name(<span class="stringliteral">"stop"</span>);</div>
<div class="line"> </div>
<div class="line"> init.precede(pipe);</div>
<div class="line"> pipe.<a class="code hl_function" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(done);</div>
<div class="line"> </div>
<div class="line"> executor.<a class="code hl_function" href="classtf_1_1Executor.html#a519777f5783981d534e9e53b99712069">run</a>(taskflow).wait();</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="aclasstf_1_1Executor_html_a519777f5783981d534e9e53b99712069"><div class="ttname"><a href="classtf_1_1Executor.html#a519777f5783981d534e9e53b99712069">tf::Executor::run</a></div><div class="ttdeci">tf::Future< void > run(Taskflow &taskflow)</div><div class="ttdoc">runs a taskflow once</div></div>
<div class="ttc" id="aclasstf_1_1Task_html_a8c78c453295a553c1c016e4062da8588"><div class="ttname"><a href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">tf::Task::precede</a></div><div class="ttdeci">Task & precede(Ts &&... tasks)</div><div class="ttdoc">adds precedence links from this to other tasks</div><div class="ttdef"><b>Definition</b> task.hpp:1258</div></div>
<div class="ttc" id="anamespacetf_html_abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0"><div class="ttname"><a href="namespacetf.html#abb7a11e41fd457f69e7ff45d4c769564a7b804a28d6154ab8007287532037f1d0">tf::PipeType::SERIAL</a></div><div class="ttdeci">@ SERIAL</div><div class="ttdoc">serial type</div><div class="ttdef"><b>Definition</b> pipeline.hpp:117</div></div>
</div><!-- fragment --><h2><a class="anchor" id="GraphPipelineTopologicalOrder"></a>
Topological Order</h2>
<p>The pipeline only supports dependencies from the current token to a <em>previously</em> processed token (i.e., the pipeline flows in one direction). We satisfy this by feeding nodes in a valid topological order, so that for any edge <code>u→v</code>, <code>u</code> appears before <code>v</code> in the node sequence. In this example we hard-code it:</p>
<div class="fragment"><div class="line"><span class="keyword">const</span> std::vector<std::string> nodes = {<span class="stringliteral">"A"</span>, <span class="stringliteral">"B"</span>, <span class="stringliteral">"C"</span>};</div>
</div><!-- fragment --><p>In a general application, topological order can be computed via DFS or Kahn's algorithm on the input graph.</p>
<h2><a class="anchor" id="GraphPipelineOutput"></a>
Sample Output</h2>
<p>Three possible execution orderings for this pipeline:</p>
<div class="fragment"><div class="line"># output 1 — full pipelining</div>
<div class="line">ready</div>
<div class="line">f1(A)</div>
<div class="line">f2(A) f1(B)</div>
<div class="line">f3(A) f2(B) f1(C)</div>
<div class="line"> f3(B) f2(C)</div>
<div class="line"> f3(C)</div>
<div class="line">done</div>
<div class="line"> </div>
<div class="line"># output 2 — no overlap (sequential-like)</div>
<div class="line">ready</div>
<div class="line">f1(A) f2(A) f3(A)</div>
<div class="line">f1(B) f2(B) f3(B)</div>
<div class="line">f1(C) f2(C) f3(C)</div>
<div class="line">done</div>
</div><!-- fragment --><p>The task graph for this pipeline is shown below:</p>
<div class="dotgraph">
<iframe scrolling="no" frameborder="0" src="dot_graph_pipeline_4.svg" width="446" height="350"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<h1><a class="anchor" id="GraphPipelineReference"></a>
Reference</h1>
<p>This graph processing pipeline technique has been applied to accelerate timing analysis in VLSI circuit design. For details, see:</p>
<ul>
<li>Cheng-Hsiang Chiu and Tsung-Wei Huang, "Efficient Timing Propagation
with Simultaneous Structural and Pipeline Parallelisms," <em>DAC</em> 2022. </li>
</ul>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.13.1-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="Examples.html">Learning from Examples</a></li>
<li class="footer">
Maintained by <a href="https://tsung-wei-huang.github.io/">Dr. Tsung-Wei Huang</a>
—
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.13.1
</li>
</ul>
</div>