Docsity

Memory Efficient Software Synthesis from Dataflow Graph - Lab | Environ 8, Lab Reports of Environmental Science

Toggle sidebar
bg1
Memory Efficient Software Synthesis from Dataflow Graph
Wonyong Sung, Junedong Kim, Soonhoi Ha
Codesign and Parallel Processing Laboratory
Seoul National University
E-mail :
f
yong,june8th,sha
g
@comp.snu.ac.kr
Abstract
Due to the limited amount of memory resources in em-
bedded systems, minimizing the memory requirements is an
important goal of software synthesis. This paper presents a
set of techniques to reduce the code and data size for soft-
ware synthesis from graphical DSP programs based on the
synchronous dataflow (SDF) model. By sharing the kernel
code among multiple instances of a block, we can further
reduce the code size below the single appearance sched-
ule. And, a systematic approach is presented to give up
single appearance schedules to reduce the data buffer re-
quirements. Experimental results from two real examples
prove the significanceof the proposed techniques.
1 Introduction
Minimizing the memory requirements is very important
to synthesize code for embedded systems due to the limited
amount of memory. Especially, in an on-chip design, ex-
tra memory requirements over the on-chip memory size in-
cur additional memory cost, performance penalty, and dras-
tic increase of power consumption. Critical constraints on
the memory size have made assembly programming still a
popular way of software synthesis for embeddedsystems in
spite of low productivity.
Growing complexity of embedded systems, fast design
turn-around time, limited development budget, and short
life cycle of products, however, will make the use of high
level software design methodology mandatory: high level
language compiler or automatic code generation from block
diagram specification.
In this paper, we aim to reduce the code and data size for
software synthesis from graphical DSP programs based on
the synchronous dataflow (SDF) model, one of block dia-
gram specification models. An SDF graph is a coarse grain
This study was supported by the academic fund of Ministry of Educa-
tion, Republic of Korea,through Inter-University Semiconductor Research
Center (ISRC-98-E-2103) in Seoul National University.
dataflow where each node contains a kernel (code fragment)
of a host language tailored to an implementation engine
while the dataflow graph itself is a coordination language
among function modules. Numerous DSP design environ-
ments including a number of commercial tools support SDF
or closely related models ([1],[3],[4]) for both simulation
and code generation.
Software synthesis from an SDF graph includes deter-
mining a feasible schedule and a coding style, both of which
affect the memory requirements of the generated software
for code and data. One of main scheduling objectives for
software synthesis is to minimize the memory requirements.
Once the schedule is determined, codes are generated ac-
cording to the scheduled sequence. Since nodes are pre-
pared in libraries, the kernel inside a node is assumed al-
ready optimized and treated as a unit. Two popular coding
styles are inlining and functions. The former generates an
inline code for each node at the scheduled position while
the latter calls a function that contains the kernel.
Previous approaches first assume a coding style and de-
termine an optimal schedule afterwards. Also, they try to
minimize the code size first and the data size later. Even
though they produce good results for a set of applications,
they could not produce good codes for some applications
which we will demonstrate.
In this paper, we propose a pair of optimization tech-
niques to overcome their limitations by mixing the coding
style. The first technique is to reduce the code size by shar-
ing the kernel among multiple instances of the same block;
which requires function style code generation instead of in-
lining. The second technique is to give up single appear-
ance schedule, an important schedule class for the mini-
mum code size, for data memory minimization. By ap-
plying these two techniques, we could reduce the memory
requirements of two important examples by 10% and 23%
over the best results from SAS[7].
In section 2, we review the previous works. The pro-
posed techniques will be explained in section 3 and 4. Two
real life examples will be discussed in section 5. Section 6
will wrap up the paper with conclusions and future works.
pf3
pf4
pf5

Partial preview of the text

Download Memory Efficient Software Synthesis from Dataflow Graph - Lab | Environ 8 and more Lab Reports Environmental Science in PDF only on Docsity!

Memory Efficient Software Synthesis from Dataflow Graph 

Wonyong Sung, Junedong Kim, Soonhoi Ha

Codesign and Parallel Processing Laboratory

Seoul National University

E-mail : fyong,june8th,[email protected]

Abstract

Due to the limited amount of memory resources in em- bedded systems, minimizing the memory requirements is an important goal of software synthesis. This paper presents a set of techniques to reduce the code and data size for soft- ware synthesis from graphical DSP programs based on the synchronous dataflow (SDF) model. By sharing the kernel code among multiple instances of a block, we can further reduce the code size below the single appearance sched- ule. And, a systematic approach is presented to give up single appearance schedules to reduce the data buffer re- quirements. Experimental results from two real examples prove the significance of the proposed techniques.

1 Introduction

Minimizing the memory requirements is very important to synthesize code for embedded systems due to the limited amount of memory. Especially, in an on-chip design, ex- tra memory requirements over the on-chip memory size in- cur additional memory cost, performance penalty, and dras- tic increase of power consumption. Critical constraints on the memory size have made assembly programming still a popular way of software synthesis for embedded systems in spite of low productivity. Growing complexity of embedded systems, fast design turn-around time, limited development budget, and short life cycle of products, however, will make the use of high level software design methodology mandatory: high level language compiler or automatic code generation from block diagram specification. In this paper, we aim to reduce the code and data size for software synthesis from graphical DSP programs based on the synchronous dataflow (SDF) model, one of block dia- gram specification models. An SDF graph is a coarse grain

 This study was supported by the academic fund of Ministry of Educa- tion, Republic of Korea,through Inter-University Semiconductor Research Center (ISRC-98-E-2103) in Seoul National University.

dataflow where each node contains a kernel (code fragment) of a host language tailored to an implementation engine while the dataflow graph itself is a coordination language among function modules. Numerous DSP design environ- ments including a number of commercial tools support SDF or closely related models ([1],[3],[4]) for both simulation and code generation. Software synthesis from an SDF graph includes deter- mining a feasible schedule and a coding style, both of which affect the memory requirements of the generated software for code and data. One of main scheduling objectives for software synthesis is to minimize the memory requirements. Once the schedule is determined, codes are generated ac- cording to the scheduled sequence. Since nodes are pre- pared in libraries, the kernel inside a node is assumed al- ready optimized and treated as a unit. Two popular coding styles are inlining and functions. The former generates an inline code for each node at the scheduled position while the latter calls a function that contains the kernel. Previous approaches first assume a coding style and de- termine an optimal schedule afterwards. Also, they try to minimize the code size first and the data size later. Even though they produce good results for a set of applications, they could not produce good codes for some applications which we will demonstrate. In this paper, we propose a pair of optimization tech- niques to overcome their limitations by mixing the coding style. The first technique is to reduce the code size by shar- ing the kernel among multiple instances of the same block; which requires function style code generation instead of in- lining. The second technique is to give up single appear- ance schedule, an important schedule class for the mini- mum code size, for data memory minimization. By ap- plying these two techniques, we could reduce the memory requirements of two important examples by 10% and 23% over the best results from SAS[7]. In section 2, we review the previous works. The pro- posed techniques will be explained in section 3 and 4. Two real life examples will be discussed in section 5. Section 6 will wrap up the paper with conclusions and future works.

A

2

1 2 2

3

1 2 3

C

B D

[1] (6A)(4B)(3C)(2D) [2] (2(3A2B))(3C)(2D) for(i=0;i<2;i++){D}

for(i=0;i<3;i++){C}

for(i=0;i<4;i++){B}

main(){

}

for(i=0;i<6;i++){A}

Figure 1. An SDF example

2 Previous Works and Our Strategy

Figure 1 is an example SDF graph, and each arc is anno- tated with the number of tokens produced or consumed by an invocation(activation) of its source or destination node. Each arc is assigned to a data buffer whose size is equal to the maximum number of tokens accumulated during exe- cution of the graph. These data buffers compose the state of the SDF graph. We call an SDF graph consistent , when there exists a valid cyclic schedule which returns the graph to its original state after every repetition. A valid schedule fires each node at least once, does not deadlock, and pro- duces no net change in the number of tokens queued on each arc. A schedule  is a sequence of node executions. For ex- ample,  1 =(6A)(4B)(3C)(2D) and  2 =(2(3A2B))(3C)(2D) represent two valid schedules for figure 1. Here, a paren- thesized term (nS) specifies n successive firings of the sub- schedule S and such a term is used to be translated into a loop in the target code[5]. Among valid schedules for a con- sistent SDF graph, if every block appears exactly once in , the schedule  is called single appearance schedule(SAS or SA-schedule). Since each node has a kernel(code block) inside, if select the  1 , the generated C program is shown in figure1. Since a single appearance schedule guarantees the min- imum code size for inline code generation, a group of re- searches are focused on finding a single appearance sched- ule which minimize the data memory requirements. Bhat- tacharyya et. al. developed two heuristics: APGAN and RPMC, to find a schedule that minimizes the data memory requirements[6]. Ritz et. al. used an ILP formulation to minimize the data memory[10]. Their approach is different from Bhattacharyya’s in that they allow data buffer sharing based on flat single appearance schedule. Since a flat SA- schedule usually requires more data buffer than the optimal nested SA-schedule, the advantage of sharing data buffer is not evident in general. Both works([6], [10]) stick to single appearance schedule and do not exploit code sharing opti- mization, which is of main interest in this paper. Another group of researches try to minimize only data memory. Ade et. al. present an algorithm to determine the smallest possible data buffer size for arbitrary SDF applications[8]. Though their work is mainly targeted for mapping an SDF application onto Field Programmable Gate

Code sharing

Get single appearance schedule (^) Context size Code block size

Schedule adjustment

software Memory optimized

Data size Schedule info.

Figure 2. Optimizations in software synthesis

Array (FPGA) in their GRAPE environment, the efforts to compute the lower bound on buffer requirement can be ap- plicable to software synthesis. Govindarajan et. al.[9] de- veloped a rate optimal compile time schedule, which min- imizes the buffer requirement using linear programming formulation. Both do not discuss the code size, which is likely to be more important for memory requirement. Even though the inline coding style is preferred in those previous researches, we propose the use of functions for the nodes whose kernel would be repeated several times in the inline code. As a result, the proposed method generates a code mixed with inline kernels and functions. We start with a single appearance schedule obtained by the method described in [6]. Then, we apply our optimiza- tion techniques as shown in figure 2. In the code sharing optimization, we investigate the schedule to find multiple instances of a same block. Multiple instances are treated as different nodes in a single appearance schedule. The code sharing technique described in section 3 formulates the gain and the overhead of function code over inline code using the context size and code block size. Only when the gain is greater than the overhead, we make a function for the shar- ing block. In the next phase of schedule adjustment, we give up the SA-schedule to further reduce the data size if the gain is greater than the overhead. We express the SA-schedule with the BTLC(Binary Tree with Leaf Chain) data struc- ture. From BTLC, we could identify the possible location of schedule adjustment and obtain adjusted schedule.

3 Code Sharing Optimization

In an inline code from a single appearance schedule, multiple instances of the same block are regarded as dif- ferent blocks, and the same kernel, possibly with differ- ent local states, may appear several times in the generated code. We propose a technique to share the same kernel us- ing a function in this section. Figure 3 contains an example, which is a sample rate converter from compact disc to digi- tal audio tape. Figure 3(b) depicts one of the library blocks: fir filter. Since there are four instances of the fir filter, it becomes a candidate of code sharing. Each fir filter has its own state values such as tab values. Also, each input or

A B C 2(7A3B)5C

3 7 5 6

A

C

G

B

C

G

C

2

1

1

A B

(a)

2 5

7 3

[0,0,3] [7,0,5]

[21,0,15]

21 30

[0,0,21]

[0,21,30]

[0,30,0] [30,0,0]

[6,0,0]

(b) (c)

2 [6,0,0]

[6,0,0]

7 3 21 [0,0,3] [7,0,5]

[6,0,0]

[12,0,0]

[0,0,21] [21,0,15]

[0,21,15]

[0,12,6]

[0,6,0]

12

6

Figure 4. Schedule adjustment using BTLC

reference type.

 (t) =

36 if t = scalar(S) 32 if t = constant(C) 60 if t = array,state (AS) 128 if t = array,port (AP)

By counting the reference counts in a code block according to the reference type, we compute the reference overhead r ef er ence ,where  (t) is the reference count of type t in the kernel.

r ef er ence = t2fS;C;AS;AP g ( (t)   (t)) (6)

The constants we use in equations are highly machine dependent; the size of types and addressing mode of the pro- cessor will be a great concern. Since we can obtain the con- stant numbers easily from manuals or simple test program, our technique is applicable to other than Sparc/Solaris envi- ronment, In summary, we can compute the code sharing overhead of a block using the port count and the reference counts, which can be easily obtained from the kernel of the node. From equation (1),(2) and (4), it is obvious that if the con- text overhead is greater than the kernel size like the ramp block in figure 3(a), the node may not be shared.

4 Adjusting Single Appearance Schedule

4.1 Construction of BTLC

To compute a new schedule which requires less data memory than SAS, we devise a data structure BTLC(Binary Tree with Leaf Chain) to express a schedule and its buffer requirements as depicted in figures 4 and 6. Each leaf node of a BTLC corresponds to an SDF node which contains a library block(kernel). A loop count 1 is represented by an

(^1) Since ’ ’ successive firings of the subschedule ’S’ is translated into a loop in the target code, we call ’S’ a loop cluster(shortly cluster) and ’ ’ a loop counter.

ObL Ob R

IbL Wb^ x IbR

Obx

Ibx

b (^) L (α)

b R (β) (γ)

b x

Figure 5. Two clusters and its I/O

intermediate node of a tree. In the figures 4 and 6, the loop counter is used as the label of each intermediate node. If we visit each node of a BTLC with depth first search(DFS) method, we obtain a single appearance schedule of the orig- inal SDF graph, such as 2(7A3B)5C in the figure 4(b). Every node of a BTLC maintains the buffer requirement information as a tuple [I, W, O] : the set of input buffers, the buffer requirement between child nodes, and the set of output buffers. For compact representation, we use a tuple [jIj; jW j; jOj] rather than [I, W, O] in the figure 4 and 6. The I and O of a leaf node become the input and output buffers of corresponding node in SDF, and W becomes null. The I and O of an intermediate node are the set of input and output buffers of a cluster, and W is the buffer produced and consumed within the cluster. From the tuples of leaf nodes, other tuples are computed in a bottom up manner. For an intermediate node bx , which has two child nodes,bL and bR as shown in figure 5, we compute the tuple [Ibx ; Wbx ; Obx ] with the following equations.

Wbx = jObL \ IbR j (7) Ibx =  jIbL [ IbR Wbx j (8) Obx =  jObL [ ObR Wbx j (9)

Unless the jIj and jOj of the root node are zero, the corre- sponding SDF graph is not consistent. Chains along the leaf nodes represent the firing order in the schedule. The weight of a chain is the jW j value of the first common ancestor of two end nodes. The total sum of chain weights represents the buffer requirement needed by the schedule which the BTLC represents(jB T LC j). Fig- ure 4(b) shows the BTLC of an SDF graph and its schedule shown in 4(a), and its jB T LC j is 51.

4.2 Schedule Adjustment using BTLC

In figure 4(a), the buffer requirement between node B and C is 30 as shown in figure 4(b). If we give up SAS and construct a schedule as 2(7A3B2C)C, the buffer re- quirements is reduced to 18. In this section, we show how to obtain the reduced buffer requirements systematically by splitting a chain. A given schedule is adjusted to reduce total memory re- quirement. If we select a chain as an adjustment point, there

are two sub-clusters CL and CR connected by the chain, as shown in figure 5. Let and be the loop counts of them and be smaller than. To reduce the buffer require- ments between CL and CR , we merge the CR into CL. The merged portion of CR has a new loop count b  c. To be equivalent, remaining CR is required to be located outside the merged CL with a loop count %. Thus, the adjust- ment procedure is cloning and merging.

new =

(CL (  )CR )( % )CR ) if < ( % )CL ((  )CL CR ) other w ise

To find a schedule adjustment point, we compute the ‘Gain’ and ‘Cost’ of an adjustment at each chain and select a chain which has the largest difference between the ‘Gain’ and ‘Cost’. We perform schedule adjustment iteratively un- til we can not find a chain where the ’Gain’ is larger than the ’Cost’. For each chain, the new jB T LC j after adjustment and its ’Gain’ is computed as following, where jC l uster j is the jW j value of the common ancestor node in the old BTLC.

Gain = jB T LC jold jB T LC jnew (11)

=

b  c + ( % )  jC l uster j (12)

The ’Cost’ for adjustment is due to cloning a cluster, which is computed by following algorithm.

for(N 2 ClonedCluster)f if(N 2 IN) f if(Cost2FN(N)  BlockSize(N)) f Cost += Cost2FN(N); Move2FN(N); g else Cost += BlockSize(N); g else Cost += Cost4Call(N); /* N 2 FN,FS */ Cost += LoopOverhead; g

Since we generate the code in a hybrid style, which is a mixture of inlines, functions, and shared functions, we define three sets of blocks during adjustment procedure: IN , FN ,and FS. If a node in CR is a member of IN , we compare the cost of moving that node to FN with its ker- nel code size to decide whether we maintain the node in IN or move the node to FN. The kernel size or the mov- ing cost is added to the ’Cost’ based on the decision. The moving cost from IN to FN includes the function body over- head, the function call overhead, and the variable migration overhead. The function body overhead and the function call overhead are small; they are 12 and 8 bytes in Sparc/Solaris environment. The variable migration overhead is incurred by changing the local variables into the global variables. Since a function code can not see the local variables of other

1 F 1 1 (^1) M 1 (^1) R R1 S

S

8

X

X X

3

[0,6,56]

[0,56,280]

[0,1,6]

[0,1,1]

[0,0,2]

[0,0,1] [1,0,1]

1

(^0) [0,0,1]

(^1) [1,0,1]

[2,0,1]

[0,2,1] [0,1,2]

X fork [1,0,2]

[0,1,2]

[0,1,1]

2

1

1

1

2

7

7 40

G

F

F

F

[280,4,0] [56,0,40]

[7,0,5]

[7,0,4]

[3,0,4]

[6,0,8]

6 56

280

G

[0,35,0]

(^7 )

F 8

2

7

1

F

F [7,0,5] [3,0,4]

[6,0,8] 56

5

F

[0,56,40]

[0,35,35]

35

[35,4,0]

[1,0,0] [1,0,2]

split candidate

[4,0,0] [1,0,0]

4

4

4

[4,0,0]

[1,0,0] [1,0,0]

[4,0,0]

35

(a) (b)

4

[0,280,0]

4

[0,6,56]

[7,0,4] [35,4,0]

[7,0,4]^4

[56,0,40]

Figure 6. CD2DAT: BTLC data structure and schedule adjustment

functions, the local variables to store tokens among inline blocks should be replaced with global variables to store to- kens among functions. The variable migration also increase the size of code to access global variables compared to ac- cessing local variables. If a node is already in FN or FS , the additional cost is only one more function call. After the ‘Cost’ is computed for all the node in the cloned cluster, since the loop structure is also cloned, adding the loop clus- ter size finalize the cost computation. When the number of leaf node is NL , the complexity to compute the ‘Cost’ is O (NL ) and finding an adjustment point requires O (N (^) L^2 ) time complexity. Figure 6(a) is the BTLC of the cd2dat example in figure

  1. The chain (F 3 ; F 4) which has 280 units of data buffer requirement is chosen. The adjusted BTLC is depicted in figure 6(b) whose buffer requirement is reduced to 143 from 351; the gain is 208.

5 Experimental Results

We have implemented the proposed scheme in our devel- oping PeaCE environment, which is a Ptolemy extension as Codesign Environment. Two real life examples are chosen to show effectiveness of our approach; they are 8 channel filter bank and compact disk to digital audio tape converter, which are borrowed from the Ptolemy distribution. Table 1 shows the results of the stepwise optimization. The cd2dat example shows significant code size reduction from the code sharing optimization and data size reduction