EE384y: Packet Switch Architectures
Matchings, implementation and heuristics
High Performance
Switching and Routing
Telecom Center Workshop: Sept 4, 1997.
Nick McKeown
Professor of Electrical Engineering
and Computer Science, Stanford University
nickm@stanford.edu
www.stanford.edu/~nickm
Spring 2008
1
Outline

Finding a maximum match.

Maximum network flow problems

Maximum size/weight matchings as examples of maximum
network flows
• Definitions and example
• Augmenting paths
• 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
Spring 2008
2
Network Flows
Source
s
10
10
•
•
•
a
c
10
1
b
1
1
d
10
10
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.
Spring 2008
3
A maximum network flow example
By inspection
Source
s
a
10
10
1
b
Step 1:
Source
s
a
1
1
10, 10
b
d
c
1
10, 10
10
c
10
1
1
d
10
10
10, 10
10
Sink
t
Sink
t
Flow is of size 10
Spring 2008
4
A maximum network flow example
Step 2:
Source
s
a
c
1
10, 10
10, 1
10, 10
b
1
1, 1
d
10, 10
Sink
t
10, 1
Flow is of size 10+1 = 11
Maximum flow:
Source
s
a
10, 10
10, 2
b
10, 9
c
1,1
1,1
1, 1
d
10, 10
Not
obvious
Sink
t
10, 2
Flow is of size 10+2 = 12
Spring 2008
5
Ford-Fulkerson method of
augmenting paths
1.
2.
3.
4.
5.
Set f(v,w) = -f(w,v) on all edges.
Define a Residual Graph, R, in which
res(v,w) = cap(v,w) – f(v,w)
Find paths from s to t for which there is
positive residue.
Increase the flow along the paths to
augment them by the minimum residue
along the path.
Keep augmenting paths until there are no
more to augment.
Spring 2008
6
Example of Residual Graph
a
s
10, 10
1
10, 10
10
b
c
1
1
d
10, 10
10
t
Flow is of size 10
Residual Graph, R
res(v,w) = cap(v,w) – f(v,w)
a 10
c
10
s
10
10
1
b
1
1
d
10
t
Augmenting path
Spring 2008
7
Example of Residual Graph
Step 2:
a
s
c
1
10, 10
10, 1
10, 10
b
1
d
1, 1
10, 10
t
10, 1
Flow is of size 10+1 = 11
Residual Graph
10
s
1
9
a
c
10
1
b
1
1
d
10
t
1
9
Spring 2008
8
Example of Residual Graph
Step 3:
a
s
1, 1
10, 10
10, 2
c
10, 9
b
1, 1
1, 1
d
10, 10
t
10, 2
Flow is of size 10+2 = 12
Residual Graph
10
s
2
8
a
1
c
9
1
b
1
1
d
10
t
2
8
Spring 2008
9
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.

Spring 2008
10
Outline

Finding a maximum match.

Maximum network flow problems

Maximum size/weight matchings as examples of maximum
network flows
• Definitions and example
• Augmenting paths
• 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
Spring 2008
11
Finding a maximum size match

A
1
B
2
C
3
D
4
E
5
F
6
How do we find the maximum size (weight) match?
Spring 2008
12
Network flows and bipartite matching
Source
s
A
1
B
2
C
3
D
4
E
5
F
6
Sink
t
Finding a maximum size bipartite matching is equivalent
to solving a network flow problem with capacities and
flows of size 1.
Spring 2008
13
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
t
Spring 2008
14
Network flows and bipartite matching
Residual Graph for next two paths:
s
A
1
B
2
C
3
D
4
E
5
F
6
t
Spring 2008
15
Network flows and bipartite matching
Residual Graph for augmenting path:
s
A
1
B
2
C
3
D
4
E
5
F
6
t
Spring 2008
16
Network flows and bipartite matching
Residual Graph for last augmenting path:
s
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 2008
17
Network flows and bipartite matching
Maximum flow graph:
s
A
1
B
2
C
3
D
4
E
5
F
6
t
Spring 2008
18
Network flows and bipartite matching
Maximum Size Matching:
A
1
B
2
C
3
D
4
E
5
F
6
Spring 2008
19
Complexity of Maximum
Matchings

Maximum Size Matchings:


Maximum Weight Matchings


Algorithm by Dinic O(N5/2)
Algorithm by Kuhn O(N3)
In general:


Hard to implement in hardware
Slooooow.
Spring 2008
20
Outline

Finding a maximum match.

Maximum network flow problems

Maximum size/weight matchings as examples of maximum
network flows
• Definitions and example
• Augmenting paths
• 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
Spring 2008
21
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.

Spring 2008
22
Example of Maximal Size Matching
A
1
A
1
A
1
B
2
B
2
B
2
C
3
C
3
C
3
D
4
D
4
4
E
5
D
E
5
5
F
6
F
6
E
F
6
Maximal
Size Matching
Maximum
Size Matching
Spring 2008
23
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.

Spring 2008
24
Outline

Finding a maximum match.

Maximum network flow problems

Maximum size/weight matchings as examples of maximum
network flows
• Definitions and example
• Augmenting paths
• 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
Spring 2008
25
Wave Front Arbiter
(Tamir)
Requests
Match
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
Spring 2008
26
Wave Front Arbiter
Requests
Match
Spring 2008
27
Wave Front Arbiter
Implementation
1,1
1,2
1,3
1,4
2,1
2,2
2,3
2,4
3,1
3,2
3,3
3,4
4,1
4,2
4,3
4,4
Simple combinational
logic blocks
Spring 2008
28
Wave Front Arbiter
Wrapped WFA (WWFA)
N steps instead of
2N-1
Requests
Match
Spring 2008
29
Wavefront Arbiters
Properties
Feed-forward (i.e. non-iterative) design
lends itself to pipelining.
 Always finds maximal match.
 Usually requires mechanism to prevent Q11
from getting preferential service.
 In principle, can be distributed over
multiple chips.

Spring 2008
30
Outline

Finding a maximum match.

Maximum network flow problems

Maximum size/weight matchings as examples of maximum
network flows
• Definitions and example
• Augmenting paths
• 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
Spring 2008
31
Parallel Iterative
Matching
uar selection
uar selection
#1
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
4
4
4
4
4
4
f1: Requests
f2: Grant
f3: Accept/Match
1
2
#2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
4
4
4
4
4
4
Spring 2008
32
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?

Spring 2008
33
Parallel Iterative Matching
Convergence Time
Number of iterations to converge:
N2
E U i   ------4i
E C   log N
C = # of iterations required to resolve connections
N = # of ports
U i = # of unresolved connections after iteration i
Spring 2008
34
Parallel Iterative Matching
Spring 2008
35
Parallel Iterative Matching
PIM with a
single iteration
Spring 2008
36
Parallel Iterative Matching
PIM with 4
iterations
Spring 2008
37
Outline

Finding a maximum match.

Maximum network flow problems

Maximum size/weight matchings as examples of maximum
network flows
• Definitions and example
• Augmenting paths
• 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
Spring 2008
38
iSLIP
1
4
#1
1
2
3
1
2
3
1
2
3
1
2
3
4
4
4
4
F1: Requests
F2: Grant
2
3
1
2
3
1
2
3
4
4
F3: Accept/Match
1
2
#2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
4
4
4
4
4
4
Spring 2008
39
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.

Spring 2008
40
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 < log2N)
Implementation: N priority encoders
100% throughput for uniform i.i.d. traffic.
But…some pathological patterns can lead to low
throughput.
Spring 2008
41
iSLIP
Spring 2008
42
iSLIP
Spring 2008
43
Programmable
Priority Encoder
N
N
iSLIP
Implementation
1
1
Grant
Accept
2
2
Grant
Accept
log2N
log2N
State
Decision
N
N
Grant
N
Accept
log2N
Spring 2008
44
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.

Spring 2008
45