You are on page 1of 45

EE384y: Packet Switch Architectures

Matchings, implementation and heuristics

H

S

Te

i

w

lec

g

i

.

om

h

tc

Ce

P

h

nte

e

i

W

r

r

n

ork

fo

sho

g

r

a

p:

Se

m

n

pt 4

a

d

1 ,

n

R

997

c

o

e

u

t

in

g

EE384y: Packet Switch Architectures Matchings, implementation and heuristics H S Te i w lec g i

Nick McKeown

Professor of Electrical Engineering and Computer Science, Stanford University

nickm@stanford.edu

www.stanford.edu/~nickm

Outline

Outline  Finding a maximum match.  Maximum network flow problems Definitions and example Augmenting paths

Finding a maximum match.

Maximum network flow problems

Definitions and example Augmenting paths

Maximum size/weight matchings as examples of maximum network flows

Maximum size matching Complexity of maximum size matchings and maximum weight matchings

What algorithms are used in practice?

Maximal Matches Wavefront Arbiter (WFA) Parallel Iterative Matching (PIM) iSLIP

Network Flows

a c 10 10 10 1 1 10 10 b d 1
a
c
10
10
10
1
1
10
10
b
d
1

Source

s

Sink

t

Let G = [V,E] be a directed graph with capacity cap(v,w) on edge [v,w].

A flow is an (integer) function, f, that is chosen

for each edge so that

f (v,w)

cap(v,w).

We wish to maximize the flow allocation.

A maximum network flow example

By inspection

a c 10 Source Sink 10 10 s 1 t 1 10 10 b d 1
a
c
10
Source
Sink
10
10
s
1
t
1
10
10
b
d
1
Step 1:
a
c
10, 10
Source
Sink
10, 10
s
1
10, 10
t
1
10
10
b
d
1

Flow is of size 10

A maximum network flow example

Step 2:

a c 10, 10 10, 10 1 10, 10 1 10, 1 b d 10, 1
a
c
10, 10
10, 10
1
10, 10
1
10, 1
b
d
10, 1
1, 1

Flow is of size 10+1 = 11

Source

s

Sink

t

  • Not

A maximum network flow example Step 2: a c 10, 10 10, 10 1 10, 10

Maximum flow:

a c 10, 9 10, 10 1,1 10, 10 1,1 10, 2 b d 10, 2
a
c
10, 9
10, 10
1,1
10, 10
1,1
10, 2
b
d
10, 2
1, 1

Source

s

Sink

t

obvious

A maximum network flow example Step 2: a c 10, 10 10, 10 1 10, 10

Flow is of size 10+2 = 12

Ford-Fulkerson method of augmenting paths

  • 1. Set f(v,w) = -f(w,v) on all edges.

  • 2. Define a Residual Graph, R, in which res(v,w) = cap(v,w) – f(v,w)

  • 3. Find paths from s to t for which there is positive residue.

  • 4. Increase the flow along the paths to augment them by the minimum residue along the path.

  • 5. Keep augmenting paths until there are no more to augment.

Example of Residual Graph

a c 10, 10 10, 10 1 10, 10 1 10 10 b d 1 Flow
a
c
10, 10
10, 10
1
10, 10
1
10
10
b
d
1
Flow is of size 10
res(v,w) = cap(v,w) – f(v,w)
c
10
10
1
a 10 1 10 10 b d 1
a
10
1
10
10
b
d
1

s

t

Residual Graph, R

s

t

Augmenting path

Example of Residual Graph

Step 2:

a c 10, 10 10, 10 s 1 10, 10 t 1 10, 1 b d
a
c
10, 10
10, 10
s
1
10, 10
t
1
10, 1
b
d
10, 1
1, 1

Flow is of size 10+1 = 11

Residual Graph a c 10 10 10 1 s t 1 1 1 b d 1
Residual Graph
a
c
10
10
10
1
s
t
1
1
1
b
d
1
9
9

Example of Residual Graph

Step 3:

a c 10, 9 10, 10 s 1, 1 10, 10 t 1, 1 10, 2
a
c
10, 9
10, 10
s
1, 1
10, 10
t
1, 1
10, 2
b
d
10, 2
1, 1

Flow is of size 10+2 = 12

1 Residual Graph a c 9 10 10 1 s 1 2 2 b d 1
1
Residual Graph
a
c
9
10
10
1
s
1
2
2
b
d
1
8
8

t

Complexity of network flow problems

In general, it is possible to find a solution by considering at most |V|.|E| paths, by

picking shortest augmenting path first.

There are many variations, such as picking

most augmenting path first.

Outline

Finding a maximum match.

Maximum network flow problems

Outline  Finding a maximum match.  Maximum network flow problems  Definitions and example Augmenting

Definitions and example Augmenting paths

Maximum size/weight matchings as examples of maximum network flows

Maximum size matching Complexity of maximum size matchings and maximum weight matchings

What algorithms are used in practice?

Maximal Matches Wavefront Arbiter (WFA) Parallel Iterative Matching (PIM) iSLIP

Finding a maximum size match

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

How do we find the maximum size (weight) match?

Network flows and bipartite matching

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

Sink

t

Source

s

Finding a maximum size bipartite matching is equivalent to solving a network flow problem with capacities and flows of size 1.

Network flows and bipartite matching

Ford-Fulkerson method

Residual Graph for first three paths:

s

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

t

Network flows and bipartite matching

Residual Graph for next two paths:

s

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

t

Network flows and bipartite matching

Residual Graph for augmenting path:

s

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

t

Network flows and bipartite matching

Residual Graph for last augmenting path:

s

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

t

Note that the path augments the match: no input and output is removed from the match during the augmenting step.

Spring 2006

Network flows and bipartite matching

Maximum flow graph:

s

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

t

Network flows and bipartite matching

Maximum Size Matching:

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

Complexity of Maximum Matchings

Maximum Size Matchings:

Algorithm by Dinic O(N 5/2 )

Maximum Weight Matchings

Algorithm by Kuhn O(N 3 )

In general:

Hard to implement in hardware Slooooow.

Outline

Finding a maximum match.

Maximum network flow problems

Definitions and example Augmenting paths

Maximum size/weight matchings as examples of maximum network flows

Maximum size matching Complexity of maximum size matchings and maximum weight matchings

What algorithms are used in practice?

Maximal Matches Wavefront Arbiter (WFA) Parallel Iterative Matching (PIM) iSLIP

Outline  Finding a maximum match.  Maximum network flow problems Definitions and example Augmenting paths

Maximal Matching

A maximal matching is one in which each edge is added one at a time, and is not later removed from the matching.

i.e. no augmenting paths allowed (they remove edges added earlier).

No input and output are left unnecessarily idle.

Example of Maximal Size Matching

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6
A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

Maximal Size Matching

A 1 B 2 C 3 D 4 E 5 F 6
A
1
B
2
C
3
D
4
E
5
F
6

Maximum Size Matching

Maximal Matchings

In general, maximal matching is simpler to implement, and has a faster running time.

A maximal size matching is at least half the size of a maximum size matching.

A maximal weight matching is defined in the obvious way.

A maximal weight matching is at least half the weight of a maximum weight matching.

Outline

Finding a maximum match.

Maximum network flow problems

Definitions and example Augmenting paths

Maximum size/weight matchings as examples of maximum network flows

Maximum size matching Complexity of maximum size matchings and maximum weight matchings

What algorithms are used in practice?

Maximal Matches Wavefront Arbiter (WFA) Parallel Iterative Matching (PIM) iSLIP

Outline  Finding a maximum match.  Maximum network flow problems Definitions and example Augmenting paths

Wave Front Arbiter

(Tamir)

 
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
     
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
     
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
   
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
 
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
   
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
 
   
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
 
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
 
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
 
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
     
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
Wave Front Arbiter (Tamir) Requests 1 1 2 2 3 3 4 4 Match 1 1
     
                 

Requests

1 1 2 2 3 3 4 4
1
1
2
2
3
3
4
4

Match

1 1 2 2 3 3 4 4
1
1
2
2
3
3
4
4

Wave Front Arbiter

Requests
Requests
 
Wave Front Arbiter Requests Match Spring 2006 27
     
Wave Front Arbiter Requests Match Spring 2006 27
   
Wave Front Arbiter Requests Match Spring 2006 27
 
   
Wave Front Arbiter Requests Match Spring 2006 27
Wave Front Arbiter Requests Match Spring 2006 27
 
Wave Front Arbiter Requests Match Spring 2006 27
Wave Front Arbiter Requests Match Spring 2006 27
     
         

Match

Wave Front Arbiter

Implementation

1,1 1,2 1,3 1,4 Simple combinational logic blocks 2,1 2,2 2,3 2,4 3,1 3,2 3,3 3,4
1,1
1,2
1,3
1,4
Simple combinational
logic blocks
2,1
2,2
2,3
2,4
3,1
3,2
3,3
3,4
4,1
4,2
4,3
4,4

Wave Front Arbiter

Wrapped WFA (WWFA)

N steps instead of 2N-1 Requests Match
N steps instead of
2N-1
Requests
Match

Spring 2006

Wavefront Arbiters

Properties

Feed-forward (i.e. non-iterative) design lends itself to pipelining. Always finds maximal match. Usually requires mechanism to prevent Q 11 from getting preferential service. In principle, can be distributed over multiple chips.

Outline

Finding a maximum match.

Maximum network flow problems

Definitions and example Augmenting paths

Maximum size/weight matchings as examples of maximum network flows

Maximum size matching Complexity of maximum size matchings and maximum weight matchings

What algorithms are used in practice?

Maximal Matches Wavefront Arbiter (WFA) Parallel Iterative Matching (PIM) iSLIP

Outline  Finding a maximum match.  Maximum network flow problems Definitions and example Augmenting paths

It e ra t io n :

#1

#2

Parallel Iterative Matching

uar selection uar selection 1 1 1 1 2 2 2 2 3 3 3 3
uar selection
uar selection
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
2: Grant
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
  • 1 1

#1 #2 Parallel Iterative Matching uar selection uar selection 1 1 1 1 2 2
  • 2 2

  • 3 3

  • 4 4

1: Requests

3: Accept/Match

1 1 2 2 3 3 4 4
1
1
2
2
3
3
4
4

PIM Properties

Guaranteed to find a maximal match in at most N iterations.

In each phase, each input and output arbiter can make decisions independently.

In general, will converge to a maximal match in < N iterations.

How many iterations should we run?

Parallel Iterative Matching

Convergence Time

Number of iterations to converge:

C = # of iterations required to resolve connections N 2 E [ U ] -------
C
=
# of iterations required to resolve connections
N 2
E
[
U
]
-------
i
i
N
=
# of ports
4
=
#
of unresolved connections after iteration i
E[C]
logN
U i

Parallel Iterative Matching

Spring 2006 35
Spring 2006
35

Parallel Iterative Matching

Parallel Iterative Matching PIM with a single iteration Spring 2006 36
PIM with a single iteration
PIM with a
single iteration
Spring 2006 36
Spring 2006
36

Parallel Iterative Matching

Parallel Iterative Matching PIM with 4 iterations Spring 2006 37
PIM with 4 iterations
PIM with 4
iterations
Spring 2006 37
Spring 2006
37

Outline

Finding a maximum match.

Maximum network flow problems

Definitions and example Augmenting paths

Maximum size/weight matchings as examples of maximum network flows

Maximum size matching Complexity of maximum size matchings and maximum weight matchings

What algorithms are used in practice?

Maximal Matches Wavefront Arbiter (WFA) Parallel Iterative Matching (PIM) iSLIP

Outline  Finding a maximum match.  Maximum network flow problems Definitions and example Augmenting paths
iSLIP 1 4 2 1 1 1 1 3 1 1 2 2 2 #1 2
iSLIP
1
4
2
1
1
1
1
3
1
1
2
2
2
#1
2
2
2
3
3
3
3
3
3
4
4
4
4
4
4
1: Requests
2: Grant
3: Accept/Match
1
1
1
1
1
1
2
2
2
2
2
2
#2
3
3
3
3
3
3
4
4
4
4
4
4
Spring 2006

iSLIP Operation

Grant phase: Each output selects the requesting input at the pointer, or the next input in round-robin order. It only updates

its pointer if the grant is accepted.

Accept phase: Each input selects the granting output at the pointer, or the next output in round-robin order.

Consequence: Under high load, grant pointers tend to move to unique values.

iSLIP

Properties

Random under low load TDM under high load Lowest priority to MRU 1 iteration: fair to outputs

Converges in at most N iterations. (On average, simulations suggest < log 2 N)

Implementation: N priority encoders 100% throughput for uniform i.i.d. traffic.

But…some pathological patterns can lead to low throughput.

iSLIP

Spring 2006 42
Spring 2006
42

iSLIP

Spring 2006 43
Spring 2006
43
iSLIP Programmable Priority Encoder Implementation N 1 1 log 2 N Grant Accept 2 2 N
iSLIP
Programmable
Priority Encoder
Implementation
N
1
1
log 2 N
Grant
Accept
2
2
N
log
N
2
Grant
Accept
State
Decision
N
N
N
log
N
2
Grant
Accept

Maximal Matches

Maximal matching algorithms are widely used in industry (PIM, iSLIP, WFA and others).

PIM and iSLIP are rarely run to completion (i.e. they are sub-maximal).

A maximal match with a speedup of 2 is stable for non-uniform traffic.