From 5bee006eaaf21175a87678e9568a583700b130e0 Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Tue, 10 Jan 2023 14:37:07 +0100 Subject: [PATCH] Added some documentation for the compute graph. Some details about the inner working of the schedule generation algorithm. --- ComputeGraph/MATHS.md | 71 ++++++++++++++++++++ ComputeGraph/documentation/graph_math1.png | Bin 0 -> 5073 bytes ComputeGraph/documentation/math-matrix1.png | Bin 0 -> 1580 bytes 3 files changed, 71 insertions(+) create mode 100644 ComputeGraph/MATHS.md create mode 100644 ComputeGraph/documentation/graph_math1.png create mode 100644 ComputeGraph/documentation/math-matrix1.png diff --git a/ComputeGraph/MATHS.md b/ComputeGraph/MATHS.md new file mode 100644 index 00000000..c49bc214 --- /dev/null +++ b/ComputeGraph/MATHS.md @@ -0,0 +1,71 @@ +# Mathematical principles + +This document explains the mathematical ideas used in the algorithm (Python script) to compute the static (or cyclo-static) scheduling. + +The details and demonstrations (for the static scheduling) can be found in the reference paper: + +> Static Scheduling of Synchronous Data Flow Programs for Digital Signal Processing +> EDWARD ASHFORD LEE, MEMBER, IEEE, AND DAVID G. MESSERSCHMITT, FELLOW, IEEE + +## Static scheduling + +The following graph will be used as an example for the explanations: + +![graph_math1](documentation/graph_math1.png) + +A topology matrix can be created from each graph where the columns describe the nodes, and the rows describe the edges. + +The values represent how many samples are produced or consumed on each edge. + +The following matrix `M` is created from the previous graph. The first column represents the filter. The second column represents the sink and the last column represents the source. + +![math-matrix1](documentation/math-matrix1.png) + +The first row thus mean that an execution of the filter is consuming 7 samples on the first edge and execution of the source is producing 5 samples. The sink is not connected to the first edge so the value is 0. + + + +If a node is run `nb` times then the matrix can be used to compute the state of the edges after this execution. + +A vector `s` can be used to represent how many time each node is executed. Then `M.s` is the amount of data produced / consumed on each edge. + +If `f` is the state of the edges (amount of data on each edge) then we have: + +`f' = M . s + f` + +where `f'` is the new state after the execution of the nodes. + +If we want to find a scheduling of this graph allowing to stream samples from the source to the sink, then a periodic solution must be found. It is equivalent to finding a solution of: + +`M.s = 0` + +The theory is showing that if the graph is schedulable, the space of solution has dimension 1. So we can find a solution with minimal integer values for the coefficients by just scaling any solution. + +In the above example, we find the scheduling vector : `s={5,5,7}` + +Once we know how many time each node must be executed, we can try to find a schedule minimizing the memory usage. The algorithm computes a topological sort of the graph and starts from the sinks. A node is scheduled if it has enough data on its edges : a normalized measure is being used on each edge. The amount of data is not directly used but it is normalized by the amount of data read or produced by the node in a given execution. The idea is to run the node as soon as enough data is available to make the execution of the node possible. + +The graph is structured in layers : nodes are in the same layer if their distance to the sinks is the same. + +To select a node in a layer, a round robin strategy is used so that all nodes are given equal chances to be executed. A node having enough data on its edges won't be executed if it has recently been executed. + +The scheduling is stopping as soon as each node has been executed the number of times described by the scheduling vector. This scheduling is a period and by executing several time this schedule we stream the samples through the compute graph from the sources to the sinks. + +## Cyclo static scheduling + +In case a node is not always producing or consuming the same amount of data, but is periodically doing so, we can reuse the previous theory and methods. + +If we look at a node `n` connected to other nodes, we know that if we want a possible schedule we need to find a periodic execution. + +The node `n` will see a similar environment only when all surrounding node periods have been executed. It implies that the node must be executed a number of times which is a multiple of the least common multiple of the periods. + +For instance, if the node is connected to a node of period 3 and a node of period 5, then it is only after 15 executions minimum that we can expect to have a periodic execution. For less than 15 executions, one of the nodes will be still running its cycle. + +Of course, it does not mean that, from a data point of view, 15 may be enough. But we know that it will be a multiple of 15. + +So we can reuse the previous theory if we assume that each node execution is in fact the least common multiple of the periods of the surrounding nodes. + +Once we have computed the matrix and the scheduling solution, the details of the schedule are computed using a different granularity : the cycles are no more considered as a whole but instead each execution step inside each cycle is used. + +As consequence, the effect of the cyclo static scheduling is just to increase the length of the final scheduling sequence since each node will have to be executed a number of times which is constrained by the least common multiples of the period of the connected nodes. + diff --git a/ComputeGraph/documentation/graph_math1.png b/ComputeGraph/documentation/graph_math1.png new file mode 100644 index 0000000000000000000000000000000000000000..a32f58c93d2068028b5971bf1c55e15d5c6402d8 GIT binary patch literal 5073 zcmbuDcTiK$x4?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PJLSyCDPn171ehu20i1IDQn3a{(G~;$@urR9}yPZ;UN)|Req2s z8q25RPJK$^ZQYGjvfnSubB%M~Y?W#;ivNjU$v>y+R_9O9pRh->fywzRGTcNGVqYz#nZ|Xhs8( z+*LPYPhi4K29}r+1Bw&Say#~L=Sro<0V4;z5Iz(ekI`0 z)Du6}<)#$pnz$SHs($kZ z+4y}l?(+}GE{-y$cB}75tuv>1{5N9q&DL726wA`1-)ADbsgu&~eFB*IVZ!S5JF9q9 zJ{X;%$)4EJd{gOgUbN6<{*8)SnB2#(HvQ}Fd%dJ>p4~Eibw}c`H)--VK7I_v27#D~ z1vAi7L43P5-KUlCifXZrjRvkzEOFzo+AF$I?fv%aiO*d1_MA4m7_gMG z=T1`<_n3&-*0%`oKM+OfW_1PYBqRR(Pp|!adL@$H7j7r3_Gkn2B{QYQCMrMeqoh-O zN0wF$pdn=8r%5s@0M2q~Qwg83Laj?E(Z#5y!Ax!^WZ7#BkLaiOxHyWuOd0x+p}2xE zW`y~@=7!XGCz0p);q|eERQjckOD@E$+lufV!}XL&`|2(jk`d-eD0u9O;4-HDay2Y*3^|ea(~|b!n1}& z^PdbuaMa1e!nSju0gYqHgbrt##z5-bXY|+0kC=jS4DFsdIXPbeW~y?)sRn9PTH}VXO((P|0E|EvXz&d%%HYAY;gc^OVY1m zms)GJhnpaF83%eucnYu^8FNRmhbpR^if7&N(MpP}hbNfvr0zU3z)8zxBaE}MT_9WB zhZmP>-3R85cGsNTyA(gqq_;Jo@8}rtw|48@SN~fM5_I_A%0B<2$kHrH($v&UebAM1 zn1L?)`Slq!u$nbC&iM_o0J4_CE1aUDP`wAHAfSi?6nRi%p4N7DzqvXr1J}oIW)fMy zhMSzY0eKcE{W!TlJNSZGe#TEmEusFFr(OvB%>RGasX%t;feILnVA|3t75yI^|8XYtDyIv{uln$^z{G$ literal 0 HcmV?d00001 diff --git a/ComputeGraph/documentation/math-matrix1.png b/ComputeGraph/documentation/math-matrix1.png new file mode 100644 index 0000000000000000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