300 likes | 446 Views
Dynamic Conditional Branch Balancing during the High-Level Synthesis of Control-Intensive Designs. Sumit Gupta 1 Nikil Dutt 1 Rajesh Gupta 2 Alex Nicolau 1. 1 School of Information and Computer Science University of California, Irvine. 2 Department of Computer Science And Engineering
E N D
Dynamic Conditional Branch Balancing during the High-Level Synthesis of Control-Intensive Designs Sumit Gupta1 Nikil Dutt1 Rajesh Gupta2 Alex Nicolau1 1School of Information and Computer Science University of California, Irvine 2Department of Computer Science And Engineering University of California, San Diego Center for Embedded Computer Systems http://www.cecs.uci.edu/~spark Supported by Semiconductor Research Corporation
M e m o r y Control ALU Data path High Level Synthesis: From Behavior to Hardware x = a + b c = a < b x = a + b; c = a < b; if (c) then d = e – f; else g = h + i; j = d x g; l = e + x; If Node c T F d = e - f g = h + i j = d x g l = e + x • Our approach targets descriptions with nested conditionals and loops
Synthesizing Control-Intensive Designs • Programming style and control constructs have tremendous impact on the quality of HLS results • Operation placement is for programming convenience: not optimized for synthesis • Restructure and duplicate code using Parallelizing Compiler Transformations: Speculative Code Motions • We present heuristics that carefully guide and increase the scope of the speculative code motions – particularly operation duplication (Conditional Speculation )
Toolbox Approach to Scheduling Scheduling Framework Transformations Toolbox Heuristics Percolation/Trailblazing Speculative Code Motions CSE/IVA/Copy Prop Operation Chaining Loop Transformations Scheduling Code Motion Dynamic CSE Loop Transformations • Scheduling Heuristics employ Code Transformations from Transformations Toolbox
Resource Allocation Across If Block + + BB 0 a + c + + Speculate BB 1 b + BB 2 BB 3 BB 4 BB 5 Speculate BB 6 BB 7 BB 8 BB 9 + d Scheduling using Speculative Code Motions BB 0 a + BB 1 b + BB 2 BB 3 BB 4 BB 5 c + BB 6 BB 7 BB 8 BB 9 + d
Resource Allocation + + + + d d + + Conditional Speculation Across If Block + d Scheduling using Speculative Code Motions BB 0 BB 0 a a c + + + BB 1 BB 1 b b + + BB 2 BB 3 BB 2 BB 3 BB 4 BB 4 BB 5 BB 5 c + • Conditional Speculation • Duplicates Operations into the branches of a Conditional Block BB 6 BB 7 BB 6 BB 7 BB 8 BB 8 BB 9 BB 9 + d
Resource Allocation Longest Path + If Node If Node BB 0 BB 0 T F T F BB 2 BB 2 BB 1 BB 1 S0 _ _ d d c a a + + S1 b b + + _ _ c BB 3 S2 BB 3 BB 4 e _ _ BB 4 S3 e Unbalanced Conditional Scheduled Design Increasing the Scope of Code Motions • A scheduling step is a set of concurrent operations inside a basic block • A basic block is a sequence of scheduling steps with no control branches/merges between them Original Design
Resource Allocation + If Node BB 0 T F BB 2 BB 1 S0 _ _ d a + S1 b + _ _ c S2 BB 3 _ _ BB 4 S3 e Insert New Scheduling Step in Shorter Branch If Node BB 0 T F BB 2 BB 1 d c a + b + BB 3 BB 4 e Original Design Scheduled Design
Resource Allocation + If Node BB 0 T F BB 2 BB 1 _ _ d a + b + _ _ c BB 3 _ _ _ BB 4 e Insert New Scheduling Step in Shorter Branch If Node BB 0 T F BB 2 BB 1 S0 d c a + S1 b e e + BB 3 S2 BB 4 • Insert scheduling steps into shorter conditional branch • Enables further code compaction S3 Original Design Scheduled Design
Organization of Scheduling Heuristics Scheduler IR Walker Traverses Design to find next basic block to schedule Traverses Design to find Candidate Operations to schedule Candidate Provider Scheduling Heuristic Chooses one of the Candidate Operations to Schedule Candidate Mover Moves, duplicates and schedules chosen Operation
Check if BBDCM will Enable Code Motion Organization of Scheduling Heuristics Scheduler BBDT Branch Balancing During Traversal IR Walker Candidate Provider Scheduling Heuristic BBDCM Branch Balancing During Code Motion Candidate Mover
Schedule Design starting from first basic block in Design On each call, returns next step in current basic block If last step in basic block is reached If current BB is a Branch of a Conditional C If basic blocks in other branches of C are scheduled and have more scheduling steps, Insert new step in currBB Traverse design and get next basic block Return first step from next basic block _ _ _ _ BBDT: Get Next Step to Schedule BB 0 a If Node BB 1 T F BB 3 BB 2 e c b + d + BB 4 BB 5 f
Schedule Design starting from first basic block in Design On each call, returns next step in current basic block If last step in basic block is reached If current BB is a Branch of a Conditional C If basic blocks in other branches of C are scheduled and have more scheduling steps, Insert new step in currBB Traverse design and get next basic block Return first step from next basic block _ _ _ _ Unbalanced Conditional BBDT: Insert Scheduling Steps while Getting Next Step to Schedule BB 0 a If Node BB 1 T F BB 3 BB 2 e c b + d + BB 4 BB 5 f
Schedule Design starting from first basic block in Design On each call, returns next step in current basic block If last step in basic block is reached If current BB is a Branch of a Conditional C If basic blocks in other branches of C are scheduled and have more scheduling steps, Insert new step in currBB Traverse design and get next basic block Return first step from next basic block _ _ _ _ BBDT: Insert Scheduling Steps while Getting Next Step to Schedule BB 0 a If Node BB 1 T F BB 3 BB 2 e c b + d + BB 4 BB 5 f
+ _ _ Scheduled Being Scheduled Resource Constraints Scope of BBDT If Node 1 • Scheduling order: • BB1, BB3 and BB4 • After scheduling the step in BB4 • BBDT adds one new step in BB3 & BB4 since number of steps in BB1 is larger BB 0 T F If Node 2 BB 2 T F BB 4 BB 1 BB 3 a d c + + b BB 5 BB 6 BB 7 f +
+ _ _ Scheduled Being Scheduled Resource Constraints Scope of BBDT If Node 1 • Scheduling order: • BB1, BB3 and BB4 • After scheduling the step in BB4 • BBDT adds one new step in BB3 & BB4 since number of steps in BB1 is larger • The new step in BB4 is now scheduled • Operation f can be duplicated up into BB1, BB3 and BB4 BB 0 T F If Node 2 BB 2 T F BB 4 BB 1 BB 3 a d c + + b BB 5 BB 6 BB 7 f +
Scope of BBDT • Inserts steps (Balances Branches) after scheduling last branch of conditional • Needs all other branches to be scheduled already • To get an accurate picture of the number of steps and the resource utilization in all the conditional branches • Continues to schedule the new scheduling step in the last branch
+ _ _ _ Scheduled Being Scheduled Resource Constraints Limitations of BBDT If Node 1 • Scheduling order: • BB1, BB3 and BB4 • BBDT can add new steps/balance branches After scheduling last branch in conditional • BBDT adds new step in BB3 after scheduling BB4, so we cannot do CS of operation f BB 0 T F If Node 2 BB 2 T F BB 4 BB 1 BB 3 a d c + + e b BB 5 BB 6 BB 7 f +
+ _ _ _ Scheduled Being Scheduled Resource Constraints Limitations of BBDT If Node 1 • Scheduling order: • BB1, BB3 and BB4 • BBDT can add new steps/balance branches After scheduling last branch in conditional • BBDT adds new step in BB3 after scheduling BB4, so we cannot do CS of operation f BB 0 T F If Node 2 BB 2 T F BB 4 BB 1 BB 3 a d c + + e b BB 5 BB 6 No backtracking/re-scheduling of basic blocks/branches that have already been scheduled BB 7 f +
BBDCM: Branch Balancing During Code Motion • Operates while checking if an operation can be conditionally speculated into the scheduling step under consideration • Checks resource utilization of all the basic blocks that the operation will be duplicated in • Tries to Find Idle Resources in all branches of the conditional • Inserts new step whenever possible if there is no idle resource: This is the Modification to Balance Branches
A resource is said to be Idle in a scheduling step if There is no operation scheduled on it in that step For multi-cycle resources if there is no operation scheduled on previous step(s) if there is no operation scheduled on next step(s) Previous Step _ Next Step _ Idle Resources 2 Cycle Multiplier BB 0 a If Node BB 1 T F BB 3 BB 2 X e d + BB 4 BB 5
+ _ _ _ Scheduled Allow CS ? Being Scheduled Resource Constraints BBDCM: Allow Conditional Speculation ? If Node 1 BB 0 • While considering CS in last conditional BB • Find Idle Resources in each basic block to duplicate in • If no idle resource in any BB • If number of steps in BB ≤ number of steps in any other BB • Insert New scheduling step T F If Node 2 BB 2 T F BB 4 BB 1 BB 3 a d c + + + + e b BB 5 BB 6 BB 7 BB 7 f +
+ _ _ _ Scheduled Allow CS ? Being Scheduled Resource Constraints BBDCM: Allow Conditional Speculation ? If Node 1 BB 0 • While considering CS in last conditional BB • Find Idle Resources in each basic block to duplicate in • If no idle resource in any BB • If number of steps in BB ≤ number of steps in any other BB • Insert New scheduling step T F If Node 2 BB 2 T F BB 4 BB 1 BB 3 a d c + + + + + e b BB 5 BB 6 BB 7 BB 7 f +
+ _ _ _ Scheduled Being Scheduled Resource Constraints BBDCM: Allow Conditional Speculation ? If Node 1 BB 0 • While considering CS in last conditional BB • Find Idle Resources in each basic block to duplicate in • If no idle resource in any BB • If number of steps in BB ≤ number of steps in any other BB • Insert New scheduling step T F If Node 2 BB 2 T F BB 4 BB 1 BB 3 a d c + + e f f b + + f + BB 5 BB 6 • BBDCM inserts new scheduling steps while applying code motions if it enables Conditional Speculation BB 7 BB 7
Branch Balancing Algorithms Integrate with Scheduling Heursitics Implementation: SPARK High Level Synthesis Framework • C Input => RTL VHDL Output • VHDL => Logic Synthesis Results • Customizable Scheduler • Modular toolbox of transformations • Heuristics select transformations
Experiments: Target Applications • MPEG-1 Prediction Block • GIMP Image Processing software
Effectiveness of Conditional Speculation is limited without Branch Balancing Algorithms Inserting Scheduling Steps during Traversal (BBDT) and while applying Conditional Speculation (BBDCM) improves Scheduling Results by 30-40 % CS+Algo 1: Add Steps during Scheduling All Code Motions except CS + Conditional Spec (CS) CS+Algo 2: Insert steps during CS All Code Motions+CS+Algo 1+Algo 2 Experimental Results CS+BBDT: Add Steps during Traversal All Code Motions except CS + Conditional Spec (CS) CS+BBDCM: Add steps during CS All Code Motions+CS+BBDT+BBDCM
Conclusions • Two Branch Balancing Techniques to Increase the Effectiveness of Code Motions – specifically Conditional Speculation • Manage resource utilization of multiple basic blocks • Insert Scheduling Steps in Unbalanced Conditional Branches dynamically during scheduling • Implemented in comprehensive High-Level Synthesis framework: Synthesizes Behavioral C to RTL VHDL • Demonstrated effectiveness on large industrial applications • With Profiling Information: insert steps in less taken Conditional Branches
Recent Related Work • Scheduling designs with conditionals • Condition Vector List Scheduling [Wakabayashi 89] • Path Based Scheduling [Camposano 91] • Symbolic Scheduling [Radivojevic 96] • WaveSched Scheduler [Lakshminarayana 98] • Basic Block Control Graph Scheduling [Santos 99] • Early work was on data-intensive DSP algorithms • Pipelining, Algorithmic transformations