Sei sulla pagina 1di 33

www.jntuworld.

com

Partitioning

D L

system design

Decomposition of a complex system into smaller subsystems.

Module 1

Module 2

Module n

N J
Interface
1

Decomposition is carried out hierarchically until each subsystem is of managable size.

w w

. w

www.jntuworld.com

U T

Decomposition scheme has to minimize the interconnections among the subsystems.

u t jn

Each subsystem can be designed independently speeding up the design process.

r o w

. ld

m o c

www.jntuworld.com

Circuit Partitioning
Objective: Partition a circuit into parts such that every component is within a prescribed range and the # of connections among the components is minimized. More constraints are possible for some applications. Cutset? Cut size? Size of a component?
1 5 2 7 3 4

D L

w w
1 2 3 4

1 5 2 8 3 4 6

7 6

graph representation

N J
7 8

Cut size = 4

. w
6

u t jn
8

U T
7 3 6 4

r o w
1 2

. ld

m o c
8

Cut size = 2

www.jntuworld.com

www.jntuworld.com

Problem Denition: Partitioning


k-way partitioning: Given a graph G(V, E ), where each vertex v V has a size s(v ) and each edge e E has a weight w(e), the problem is to divide the set V into k disjoint subsets V1 , V2 , . . ., Vk , such that an objective function is optimized, subject to certain constraints. Bounded size constraint: The size of the i-th subset is bounded by Bi ( vVi s(v ) Bi). Is the partition balanced? Min-cut cost between two subsets: Minimize where p(u) is the partition # of node u.

D L

N J

The 2-way, balanced partitioning problem is NP-complete, even in its simple form with identical vertex sizes and unit edge weights.

w w

. w

u t jn

U T

r o w

. ld

m o c

e=(u,v )p(u)=p(v ) w (e),

www.jntuworld.com

www.jntuworld.com

Kernighan-Lin Algorithm
Kernighan and Lin, An ecient heuristic procedure for partitioning graphs, The Bell System Technical Journal, vol. 49, no. 2, Feb. 1970. An iterative, 2-way, balanced partitioning (bi-sectioning) heuristic. Till the cut size keeps decreasing

D L

This process continues until all the vertices are locked.

w w

N J
4

. w

www.jntuworld.com

U T

These vertices are then locked (and thus are prohibited from participating in any further exchanges).

u t jn

Vertex pairs which give the largest decrease or the smallest increase in cut size are exchanged.

r o w

. ld

m o c

www.jntuworld.com

Kernighan-Lin Algorithm: A Simple Example


Each edge has a unit weight.
a b c d e f g h a b c e f

D L

Questions: How to compute cost reduction? What pairs to be swapped? Consider the change of internal & external connections.

w w

N J

Step # 0 1 2 3 4

n j . w

Vertex pair {d, g} {c, f} {b, h} {a, e}

U T

w tu

Cost reduction 0 3 1 -2 -2

or
h

. ld

m o c
a b f g

e c d h

Cut cost 5 2 1 3 5

www.jntuworld.com

www.jntuworld.com

Properties
Two sets A and B such that |A| = n = |B | and A B = . External cost of a A: Ea = vB cav . Internal cost of a A: Ia = vA cav . D-value of a vertex a: Da = Ea Ia (cost reduction for moving a). Cost reduction (gain) for swapping a and b: gab = Da + Db 2cab . If a A and b B are interchanged, then the new D-values, D , are given by

D L

cxb A cxa

b B a

N J
before swap cxa +cxb

A a

w w
b
B:

. w

A a cxa x

U T
B

Dx = Dx + 2cxa 2cxb, x A {a} Dy = Dy + 2cyb 2cya , y B {b}.

u t jn
b cxb x

r o w

. ld

m o c
after swap

C +2cxa 2cxb

+cxa cxb

Gain a Gain b

D a c ab A : D b c ab

Internal cost vs. External cost

updating Dvalues

www.jntuworld.com

www.jntuworld.com

Kernighan-Lin Algorithm: A Weighted Example

D L

a b c d e f 2 2 2 4 0 2 4 1 1 3 2 0 1

b a f

a b

d 2 e f

a 0 1 2 3 b 1 0 1 4 c 2 1 0 3 d 3 4 3 0 e 2 2 2 4 f 4 1 1 3

Initial cut cost = (3+2+4)+(4+2+1)+(3+2+1) = 22

Iteration 1: Ia = 1 + 2 = 3; Ib = 1 + 1 = 2; Ic = 2 + 1 = 3; Id = 4 + 3 = 7; Ie = 4 + 2 = 6; If = 3 + 2 = 5;

N J

w w

Ea = 3 + 2 + 4 = 9; Eb = 4 + 2 + 1 = 7; Ec = 3 + 2 + 1 = 6; Ed = 3 + 4 + 3 = 10; Ee = 2 + 2 + 2 = 6; Ef = 4 + 1 + 1 = 6;

n j .

U T

w tu

or

. ld
c

m o c
2 4

costs associated with a

Da = Ea Ia = 9 3 = 6 Db = Eb Ib = 7 2 = 5 Dc = Ec Ic = 6 3 = 3 Dd = Ed Id = 10 7 = 3 De = Ee Ie = 6 6 = 0 Df = Ef If = 6 5 = 1

www.jntuworld.com

www.jntuworld.com

Weighted Example (contd)


Iteration 1:

D L

gxy = Dx + Dy 2cxy .
gad gae gaf gbd gbe gbf gcd gce gcf = = = = = = = = =

w w

Swap b and f ! (g 1 = 4)
8

www.jntuworld.com

N J

. w

u t jn

Da + Dd 2cad = 6 + 3 2 3 = 3 6+022=2 6 + 1 2 4 = 1 5+324=0 5+022=1 5 + 1 2 1 = 4 (maximum) 3+323=0 3 + 0 2 2 = 1 3+121=2

U T

Ia = 1 + 2 = 3; Ib = 1 + 1 = 2; Ic = 2 + 1 = 3; Id = 4 + 3 = 7; Ie = 4 + 2 = 6; If = 3 + 2 = 5;

Ea = 3 + 2 + 4 = 9; Eb = 4 + 2 + 1 = 7; Ec = 3 + 2 + 1 = 6; Ed = 3 + 4 + 3 = 10; Ee = 2 + 2 + 2 = 6; Ef = 4 + 1 + 1 = 6;

r o w

Da = Ea Ia = 9 3 = 6 Db = Eb Ib = 7 2 = 5 Dc = Ec Ic = 6 3 = 3 Dd = Ed Id = 10 7 = 3 De = Ee Ie = 6 6 = 0 Df = Ef If = 6 5 = 1

. ld

m o c

www.jntuworld.com

Weighted Example (contd)

D L

d e f

f a c

b d

b c

gad gae gcd gce

= = = =

Da + Dd 2cad = 0 + 1 2 3 = 5 Da + De 2cae = 0 + 0 2 2 = 4 Dc + Dd 2ccd = 3 + 1 2 3 = 2 Dc + De 2cce = 3 + 0 2 2 = 1 (maximum)


9

Swap c and e! (g 2 = 1)

www.jntuworld.com

N J

gxy = Dx + Dy 2cxy .

w w

. w

U T

Da Dc Dd De

= = = =

Da + 2cab 2caf = 6 + 2 1 2 4 = 0 Dc + 2ccb 2ccf = 3 + 2 1 2 1 = 3 Dd + 2cdf 2cdb = 3 + 2 3 2 4 = 1 De + 2cef 2ceb = 0 + 2 2 2 2 = 0

u t jn

Dx = Dx + 2cxp 2cxq , x A {p} (swap p and q , p A, q B )

r o w

. ld
e

m o c

www.jntuworld.com

Weighted Example (contd)

D L

b d

f e

a c

gxy = Dx + Dy 2cxy .

gad = Da + Dd 2cad = 0 + 3 2 3 = 3(g 3 = 3) Note that this step is redundant (


n i i=1 g

w w

Da Dd

= Da + 2cac 2cae = 0 + 2 2 2 2 = 0 = Dd + 2cde 2cdc = 1 + 2 4 2 3 = 3

= 0).
10

www.jntuworld.com

N J

. w

U T

Dx = Dx + 2cxp 2cxq , x A {p}

u t jn

r o w
c

. ld

m o c
c e

www.jntuworld.com

Summary: g 1 = gbf = 4, g 2 = gce = 1, g 3 = gad = 3. Largest partial sum max

D L

k i i=1 g

= 4 (k = 1) Swap b and f .

w w

www.jntuworld.com

N J

. w

u t jn

U T

r o w

. ld

m o c

www.jntuworld.com

Weighted Example (contd)

D L

a b c d e f a 0 1 2 3 b 1 0 1 4 c 2 1 0 3 d 3 4 3 0 e 2 2 2 4 f 4 1 1 3 2 2 2 4 0 2

f 4 a 1 c

1 3

Iteration 2: Repeat what we did at Iteration 1 (Initial cost= 22 4 = 18).

Largest partial sum = max

k i i=1 g

= 0 (k = 3) Stop!

N J

Summary: g 1 = gce = 1, g 2 = gab = 3, g 3 = gf d = 4.

w w

. w

U T

Initial cut cost = (1+3+2)+(1+3+2)+(1+3+2) = 18 (224)

u t jn

4 1 1 3 2 0

r o w

. ld
2

m o c
d e

11

www.jntuworld.com

www.jntuworld.com

D L

Algorithm: Kernighan-Lin(G) Input: G = (V, E ), |V | = 2n. Output: Balanced bi-partition A and B with small cut cost. 1 begin 2 Bipartition G into A and B such that |VA| = |VB |, VA VB = , and VA VB = V . 3 repeat 4 Compute Dv , v V . 5 for i = 1 to n do 6 Find a pair of unlocked vertices vai VA and vbi VB whose exchange makes the largest decrease or smallest increase in cut cost; 7 Mark vai and vbi as locked, store the gain g i , and compute the new Dv , for all unlocked v V ; 8 Find k, such that Gk = k i is maximized; i=1 g 9 if Gk > 0 then 10 Move va1 , . . . , vak from VA to VB and vb1 , . . . , vbk from VB to VA ; 11 Unlock v , v V . 12 until Gk 0; 13 end

w w

N J

. w

u t jn

U T

r o w

. ld

m o c

12

www.jntuworld.com

www.jntuworld.com

Time Complexity
Line 4: Initial computation of D: O(n2 )

D L

R
u t jn

Line 5: The for-loop: O(n) The body of the loop:

Lines 67: Step i takes (n i + 1)2 time.

Lines 411: Each pass of the repeat loop: O(n3 ).

The total running time: O(rn3 ).

w w

N J
13

. w

www.jntuworld.com

U T

Suppose the repeat loop terminates after r passes.

O(n2 ).

r o w

. ld

m o c

www.jntuworld.com

Extensions of K-L Algorithm


Unequal sized subsets (assume n1 < n2 ) 1. Partition: |A| = n1 and |B | = n2 . 2. Add n2 n1 dummy vertices to set A. connections to the original graph. 3. Apply the Kernighan-Lin algorithm. 4. Remove all dummy vertices.

D L

k-way partition

1. Partition the graph into k equal-sized sets. 2. Apply the Kernighan-Lin algorithm for each pair of subsets. 3. Time complexity? Can be reduced by recursive bi-partition.
14

www.jntuworld.com

N J

1. Assume that the smallest vertex has unit size. 2. Replace each vertex of size s with s vertices which are fully connected with edges of innite weight. 3. Apply the Kernighan-Lin algorithm.

w w

. w

U T

Unequal sized vertices

u t jn

r o w

. ld

Dummy vertices have no

m o c

www.jntuworld.com

A Better Implementation of K-L Algorithm


Sort the D-values in a non-increasing order: Da1 Da2 . . . Dan Db1 Db2 . . . Dbn

D L

Partition A = {a, b, c}: Da = 6; Db = 5; Dc = 3; Partition B = {d, e, f }: Dd = 3; Df = 1; De = 0; Compute g s gad = 3 gaf = 1 gae = 2 gbd = 0 gbf = 4 gbe = 1 gcd = 0 No need to compute gcf (Quit!) since Dc + Df gbf = 4.

w w

Note that the overall time complexity remains O(rn3 ).

N J
15

. w

u t jn

www.jntuworld.com

U T

. . . whenever Dai + Dbj Maximum gain found so far (Quit!).

Start with a1 , compute ga1 ,bi , bi Start with a2 , compute ga2 ,bi , bi

r o w

. ld

m o c

www.jntuworld.com

Drawbacks of the Kernighan-Lin Heuristic


The K-L heuristic handles only unit vertex weights.

D L

Vertex weights might represent block sizes, dierent from blocks to blocks. Reducing a vertex with weight w(v ) into a clique with w(v ) vertices and edges with a high cost increases the size of the graph substantially.

Need dummy vertices to handle the unbalanced problem. The K-L heuristic cannot handle hypergraphs. Need to handle multi-terminal nets directly. The time complexity of a pass is high, O(n3 ).

w w

N J
16

. w

www.jntuworld.com

U T

The K-L heuristic handles only exact bisections.

u t jn

r o w

. ld

m o c

www.jntuworld.com

Coping with Hypergraph


A hypergraph H = (N, L) consists of a set N of vertices and a set L of hyperedges, where each hyperedge corresponds to a subset Ni of distinct vertices with |Ni| 2.
b d a

D L

W
c

{A, B, E }, {C, D, F } is a good partition.

Should not assign the same weight for all edges.

w w

N J
17

n j . w

www.jntuworld.com

U T

Schweikert and Kernighan, A proper model for the partitioning of electrical circuits, 9th Design Automation Workshop, 1972. For multi-terminal nets, net cut is a more accurate measurement for cut cost (i.e., deal with hyperedges).

w tu

hyperedge

or

. ld
f e

m o c

www.jntuworld.com

net 1

D L
B C

A
net 2

D
net 5

A E

C F

net 3

net 4

R
u t jn

cost = 1

w w

www.jntuworld.com

N J

. w

U T

r o w

. ld

cost = 4?

m o c

www.jntuworld.com

Net-Cut Model
Let n(i) = # of cells associated with Net i.

D L

Edge weight wxy =

2 n(i)

for an edge connecting cells x and y .

net 1

A
net 2

B
net 3

C
net 4

N J
18

Easy modication of the K-L heuristic.

w w

. w

u t jn
F

U T

r o w
D
net 5

. ld
A
1

m o c
1/2

cost = 2

B
1

1/2

C
1

D
1

F
cost = 2

www.jntuworld.com

www.jntuworld.com

B y Dx : gain in moving x to B Dy : gain in moving y to A

D L
x

w w

www.jntuworld.com

N J

. w

u t jn

U T

gxy = D x + D y Correction(x, y)

r o w

. ld

m o c

www.jntuworld.com

Network Flow Based Partitioning


Min-cut balanced partitioning: Yang and Wong, ICCAD-94. Based on max-ow min-cut theorem.

D L

P1

Gate replication for partitioning: Yang and Wong, ICCAD-95.

Multi-way partitioning with area and pin constraints: Liu and Wong, ISPD-97. Multi-resource partitioning: Liu, Zhu, and Wong, FPGA-98. Partitioning for time-multiplexed FPGAs: Liu and Wong, ICCAD-98.
19

www.jntuworld.com

N J

Performance-driven multiple-chip partitioning: Yang and Wong, FPGA94, ED&TC-95.

w w

. w

u t jn

P2

U T

r o w

P3

. ld

m o c

www.jntuworld.com

Flow Networks

D L

A ow network G = (V, E ) is a directed graph in which each edge (u, v ) E has a capacity c(u, v ) > 0.

A ow f : V V R satises

Capacity constraint: f (u, v ) c(u, v ), u, v V . Skew symmetry: f (u, v ) = f (v, u), u, v V . Flow conservation:
v V f (u, v ) = 0, u V {s, t}. v V f (s, v ) = v V f (v, t)
20

w w

The value of a ow f : |f | =

www.jntuworld.com

N J

. w

u t jn

U T

There is exactly one node with no incoming (outgoing) edges, called the source s (sink t).

r o w

. ld

m o c

www.jntuworld.com

D L

Maximum-ow problem: Given a ow network G with source s and sink t, nd a ow of maximum value from s to t.
16/16

v1
4/10 0/4

12/12

R
v2
7/7

O
v4
4/4

19/20

7/13

w w

www.jntuworld.com

N J

n j . w

U T

v3

11/14

w tu

0/9

or

flow/capacity

max flow |f| = 16 + 7 = 23

. ld

m o c

www.jntuworld.com

Max-Flow Min-Cut
) of ow network G = (V, E ) is a partition of V A cut (X, X = V X such that s X and t X . into X and X

D L

Max-ow min-cut theorem Ford & Fulkerson, 1956.

16/16

s
7/13

w w
v1
4/10 0/4

12/12

v2
7/7

19/20

flow/capacity t

0/9

v3

11/14

v4

4/4

max flow |f| = 16 + 7 = 23 cap(X, X) = 12 + 7 + 4 = 23

N J
21

. w

www.jntuworld.com

U T

) for some min-cut f is a max-ow |f | = cap(X, X ). (X, X

u t jn

) = Capacity of a cut: cap(X, X only forward edges!)

r o w

. ld

c(u, v ). (Count uX,v X

m o c

www.jntuworld.com

Network Flow Algorithms


An augmenting path p is a simple path from s to t with the following properties: For every edge (u, v ) E on p in the forward direction (a forward edge), we have f (u, v ) < c(u, v ). For every edge (u, v ) E on p in the reverse direction (a backward edge), we have f (u, v ) > 0. f is a max-ow no more augmenting path.
v1
16 12

D L

13

w w
10 4 9

N J
t s
4 19/20

v3

. w
v2
20 7

u t jn
t s
13

U T
12/12

r o w
v1
10 4 9 14 12/12

. ld
12/20 7

m o c
16/16 13

12/16

v2

v1
4/10 4

12/12

v2
4/7

16/20

9 4/14 12/12

t
4

14

v4

v3

v4

v3

v4

16/16

v1

12/12

v2
7/7

19/20

16/16

v1
4/10 4

v2
7/7

16/16

v1
4/10 0/4

v2
7/7

19/20

s
3/13

4/10 4

9 7/14

t
4

s
7/13

9 11/14

t
4/4

s
7/13

0/9 11/14

t
4/4

v3

v4

v3

v4

v3

v4

22

www.jntuworld.com

www.jntuworld.com

First algorithm by Ford & Fulkerson in 1959: O(|E ||f |); First polynomial-time algorithm by Edmonds & Karp in 1969: O(|E |2|V |); Goldberg & Tarjan in 1985: O(|E ||V | lg(|V |2/|E |)), etc.

D L

w w

www.jntuworld.com

N J

. w

u t jn

U T

r o w

. ld

m o c

www.jntuworld.com

Network Flow Based Partitioning

D L

Why was the technique not wisely used in partitioning?

Works on graphs, not hypergraphs.

Yang & Wong, ICCAD-94.

Optimal algorithm for min-net-cut bipartition (unbalanced). Ecient implementation for repeated min-net-cut: same asymptotic time as one max-ow computation.
23

www.jntuworld.com

N J

Exact net modeling by ow network.

w w

. w

u t jn

U T

Results in unbalanced partitions; repeated min-cut for balance: |V | max-ows, time-consuming!

r o w

. ld

m o c

www.jntuworld.com

Min-Net-Cut Bipartition

D L

Net modeling by ow network:

v1 v2

Size of ow network: |V | 3|V |, |E | 2|E | + 3|V |. Time complexity: O(min-net-cut-size) |E | = O(|V ||E |).
24

www.jntuworld.com

N J

) in N A min-capacity-cut (X , X ) A min-net-cut (X, X in N .

w w

. w

u t jn

U T

r o w
v
OO

. ld
OO

n1

m o c
OO OO

v1 v2

n2

OO

OO

www.jntuworld.com

OO OO

D L

X
OO

OO

g
OO OO

c1 d1

c2 d2

OO

r
OO

b1

b2
OO

OO

t s

OO

w w

www.jntuworld.com

N J

. w

u t jn

U T

r o w

. ld
OO

m o c
OO

OO

OO

www.jntuworld.com

Repeated Min-Cut for Balanced Bipartition

D L

(FBB)

b a f s e i (X1, X1) j k g h

Allow component weights to deviate from (1 )W/2 to (1 + )W/2.


t

s 2

w w
b f i j

N J
b f i j (X3, X3)

. w
k

u t jn
l

U T
e

r o w
s 2
s

. ld
e

m o c
b f g i j k

h t l (X2, X2)

h g l k t

(X3, X3)

An unsaturated net

A saturated net

A node to be collapsed to s or t
25

www.jntuworld.com

www.jntuworld.com

Incremental Flow

D L

Repeatedly compute max-ow: very time-consuming. No need to compute max-ow from scratch in each iteration. Retain the ow function computed in the previous iteration. FBB time complexity: O(|V ||E |), same as one max-ow. At most 2|V | augmenting path computations. At each augmenting path computation, either an augmenting path is found, or a new cut is found, and at least 1 node is collapsed to s or t. At most |f | |V | augmenting paths found, since bridging edges have unit capacity.

w w

N J

. w

u t jn

U T

Find additional ow in each iteration. Still correct.

r o w

. ld

m o c

26

www.jntuworld.com

www.jntuworld.com

An augmenting path computation: O(|E |) time.


b f e i j

D L

b f

s 2

s 2

(X2, X2)

w w

www.jntuworld.com

N J

. w

u t jn

U T

r o w

. ld

m o c
i j k (X3, X3)

Potrebbero piacerti anche