Algorithm Search⌘K

Algorithmadvanced

Independent set matching

Also called cell matching detailed placement.

Picks a set of cells that share no nets and reassigns them to their positions by an optimal bipartite matching of wire length cost.

Time
O(n (n D + k^2 D + k^3)) worst · average · best
Space
O(n + k^2) extra
Where
D = the largest number of pins on the nets of one cell; k = the size of each independent set; n = the number of cells
Properties
deterministicnot exactiterative
Origin
Tung Chieh Chen, Zhe Wei Jiang, Tien Chang Hsu, Hsin Chen Chen, Yao Wen Chang, 2008

Independent set matching is a move of detailed placement. It picks a set of cells of the same width, close to each other, such that no two of them are on a common net, and puts them back onto the same set of positions in the best order. Because the cells share no net, the wirelength of each cell depends only on its own position, so the change of the total HPWL is a sum of one term per cell and position. The best reassignment is then an assignment problem, solved exactly by the Hungarian algorithm in O(k3)O(k^3) time for kk cells. The placement stays legal, and the HPWL never goes up. The choice of the sets is a greedy independent set in the graph of cells that share nets, so the method is a local search: it reaches a local minimum, not the best placement.

In plain words

Take a few parts of the same size that are close together, and that are not wired to each other. Lift them off the board, keeping their places empty. Now each part can go back into any of these places. Since the parts are not wired to each other, the cost of putting a part in a place does not depend on where the other parts go.

So write a table: one row per part, one column per place, and in each box the wire length of that part at that place. Choosing one box in each row and each column with the least sum is a classic problem with a fast exact method. Put the parts back that way. Then take the next group.

The problem

The input is a legal placement of a netlist H=(C∪Q,N)H = (C \cup Q, N) in rows: cell ii has its left edge xix_i on a site, its row, and an integer width WiW_i; the fixed pins QQ are pads. Every pin is at the center of its cell. Net ee has a weight wew_e, and

WL=∑e∈Nwe HPWL(e).\mathrm{WL} = \sum_{e \in N} w_e \, \mathrm{HPWL}(e).

The output is a legal placement with a WL\mathrm{WL} at most that of the input. One step takes a set S={c1,…,ck}S = \{c_1, \ldots, c_k\} of cells of the same width with no net that contains two of them, the set of their positions (slots) s1,…,sks_1, \ldots, s_k, where cac_a is at sas_a, and finds a permutation σ\sigma that minimizes WL\mathrm{WL} when cac_a moves to sσ(a)s_{\sigma(a)}. For a cell cc and a slot ss let

cost(c,s)=∑e∋cwe HPWL(e)with c at s and every other cell where it is.\mathrm{cost}(c, s) = \sum_{e \ni c} w_e \, \mathrm{HPWL}(e) \quad \text{with } c \text{ at } s \text{ and every other cell where it is.}

The algorithm

  1. INDEPENDENT-SET-MATCHING(placement, k, window)
  2. 1repeat for the given number of passes
  3. 2for each cell c₀ in the order of the rows
  4. 3S ← [c₀]; for each cell c of width W_{c₀} in the window of c₀, nearest first: if no net has both c and a cell of S, append c to S; stop at k cells
  5. 4if |S| ≥ 2
  6. 5s_a ← the position of S[a] for each a
  7. 6cost[a][b] ← cost(S[a], s_b) for all a, b
  8. 7σ ← the minimum cost assignment of cost, by the Hungarian algorithm
  9. 8move each S[a] to s_{σ(a)}

Line L3 is a greedy independent set in the graph whose vertices are the cells of width Wc0W_{c_0} in the window and whose edges join two cells on a common net. The equal width makes any cell fit into any slot of the set. Line L6 computes k2k^2 costs; each one needs the nets of one cell. Line L7 is an exact solve of the assignment problem. Line L8 moves the cells. The identity is one of the permutations, so the step never makes WL\mathrm{WL} larger.

Example

Three cells in a row. One row; cells aa, bb, cc of width 1 at x=0,2,4x = 0, 2, 4, so their centers are at 12,52,92\frac12, \frac52, \frac92, with y=12y = \frac12. Three pads on the same line: PP at x=5x = 5, QQ at x=0x = 0, RR at x=3x = 3. The nets {a,P}\{a, P\}, {b,Q}\{b, Q\}, {c,R}\{c, R\} all have weight 1, so no two of the cells share a net. The total is 92+52+32=172\frac92 + \frac52 + \frac32 = \frac{17}{2}. The cost table, from the implementation with Fractions:

cell slot x=0x = 0 slot x=2x = 2 slot x=4x = 4
aa (pad at 5) 92\frac92 52\frac52 12\frac12
bb (pad at 0) 12\frac12 52\frac52 92\frac92
cc (pad at 3) 52\frac52 12\frac12 32\frac32

The Hungarian algorithm gives a→4a \to 4, b→0b \to 0, c→2c \to 2 with the cost 12+12+12=32\frac12 + \frac12 + \frac12 = \frac32. The 6 permutations give the totals 172\frac{17}{2} (the identity), 192\frac{19}{2}, 92\frac92, 192\frac{19}{2}, 32\frac32 and 112\frac{11}{2}, each a sum of three boxes with one in each row and column, and 32\frac32 is the least. The HPWL drops from 172\frac{17}{2} to 32\frac32. A swap of two cells could not get there in one move: it is a cycle of three.

Why the cells must share no net. Cells aa at x=0x = 0 and bb at x=5x = 5 share a net of weight 2; aa also has a net to a pad at x=−1x = -1, and bb a net to a pad at x=7x = 7. The current WL\mathrm{WL} is 2⋅5+32+32=132 \cdot 5 + \frac32 + \frac32 = 13, and the swap gives 23. The cost table, computed as if the other cell stays put, is (232132132232)\begin{pmatrix} \frac{23}{2} & \frac{13}{2} \\ \frac{13}{2} & \frac{23}{2} \end{pmatrix}: in the swapped boxes each cell lands on the slot of the other and the shared net looks short. The table says the swap costs 13 and the identity 23, the wrong way round. So the matching would make the placement worse.

Correctness

The proof shows the following.

  • Separable cost. If no net contains two cells of SS, then for every permutation σ\sigma the new wirelength is WL0+∑acost(ca,sσ(a))\mathrm{WL}_0 + \sum_a \mathrm{cost}(c_a, s_{\sigma(a)}), where WL0\mathrm{WL}_0 is the wirelength of the nets with no pin in SS. The reason is that a net with a pin on cac_a has all its other pins fixed during the step.
  • Best permutation. So the minimum cost assignment of line L7 gives the least WL\mathrm{WL} over all k!k! permutations of the set, and WL\mathrm{WL} does not go up.
  • Legal. The cells of SS have the same width and only trade their positions, so the set of occupied sites is the same, and the placement stays legal.
  • Termination. Each pass does nn steps; with a bound on the passes it stops.

The step is exact for its set; the method is not exact for detailed placement, because the sets are chosen greedily and the result is a local minimum.

Proof: For cells that share no net, the wirelength is separable, so the assignment gives the best permutation, keeps the placement legal and never increases HPWLfull

Fix one step, with the set S={c1,…,ck}S = \{c_1, \ldots, c_k\} of line L3 and the slots s1,…,sks_1, \ldots, s_k of line L5, where cac_a is at sas_a before the step. For a permutation σ\sigma of {1,…,k}\{1, \ldots, k\}, let WL(σ)\mathrm{WL}(\sigma) be the wirelength when each cac_a is at sσ(a)s_{\sigma(a)} and every other cell is where it was. The identity is ι\iota.

Lemma 1 (the set is independent and of one width). Every cell of SS has the width Wc0W_{c_0}, and no net contains two cells of SS.

Proof. Line L3 takes only cells of width Wc0W_{c_0}. It appends a cell cc only if no net of cc is a net of a cell already in SS. So for two cells of SS, the later one shares no net with the earlier one. □\square

Lemma 2 (separable cost). Let NSN_S be the nets with a pin on a cell of SS, and WL0=∑e∉NSweHPWL(e)\mathrm{WL}_0 = \sum_{e \notin N_S} w_e \mathrm{HPWL}(e). For every permutation σ\sigma,

WL(σ)=WL0+∑a=1kcost(ca,sσ(a)).\mathrm{WL}(\sigma) = \mathrm{WL}_0 + \sum_{a=1}^{k} \mathrm{cost}(c_a, s_{\sigma(a)}).

Proof. A net e∉NSe \notin N_S has no pin on a cell of SS, so no pin moves, and its term is the same for every σ\sigma; together these terms give WL0\mathrm{WL}_0. By Lemma 1, each net e∈NSe \in N_S has a pin on exactly one cell cac_a of SS, and its other pins are on cells outside SS or on pads, which do not move. So under σ\sigma the HPWL of ee equals its HPWL with cac_a at sσ(a)s_{\sigma(a)} and all other cells where they were. Summing over the nets of cac_a gives cost(ca,sσ(a))\mathrm{cost}(c_a, s_{\sigma(a)}), and each net of NSN_S is counted once, for its one cell of SS. □\square

Theorem 1 (best permutation, no increase). After line L8, the wirelength is min⁡σWL(σ)≤WL(ι)\min_\sigma \mathrm{WL}(\sigma) \le \mathrm{WL}(\iota), the wirelength before the step.

Proof. Line L6 fills cost[a][b]=cost(ca,sb)\mathrm{cost}[a][b] = \mathrm{cost}(c_a, s_b). By Lemma 2, WL(σ)=WL0+∑acost[a][σ(a)]\mathrm{WL}(\sigma) = \mathrm{WL}_0 + \sum_a \mathrm{cost}[a][\sigma(a)], and WL0\mathrm{WL}_0 does not depend on σ\sigma. The Hungarian algorithm returns a permutation of least ∑acost[a][σ(a)]\sum_a \mathrm{cost}[a][\sigma(a)] (see the Hungarian algorithm for its proof), so it returns a σ\sigma of least WL(σ)\mathrm{WL}(\sigma). The identity is a permutation, so the least value is at most WL(ι)\mathrm{WL}(\iota). ■\blacksquare

Theorem 2 (legal). If the placement is legal before a step, it is legal after it.

Proof. By Lemma 1 all cells of SS have the same width WW. The slot sbs_b is the left edge and row of cbc_b before the step, so it is the interval [x,x+W)[x, x + W) of sites in a row, inside the row and free of every cell outside SS. After the step the cells of SS occupy the same kk intervals, one cell in each, because σ\sigma is a bijection. The cells outside SS do not move. So the set of occupied intervals is the same as before, and no two cells overlap. ■\blacksquare

Theorem 3 (termination and running time). With PP passes the algorithm stops after PnP n steps. One step costs O(nD+k2D+k3)O(n D + k^2 D + k^3) time, where DD bounds the number of pins on the nets of one cell (so also the number of its nets).

Proof. The loops of lines L1 and L2 run PP and nn times. Line L3 looks at each cell of the window once, at most nn cells, and keeps the nets of SS in a hash set, so each test costs the number of nets of the cell, at most DD, in expected O(1)O(1) time per net. Line L6 computes k2k^2 values; each needs the HPWL of the nets of one cell, O(D)O(D) pin positions, so O(k2D)O(k^2 D) in total. The Hungarian algorithm with potentials runs in O(k3)O(k^3) time, and line L8 in O(k)O(k). ■\blacksquare

Complexity

  • One step. Line L3 looks at the cells of the window, at most nn of them, and checks the at most DD nets of each against a hash set of the nets of SS: O(nD)O(n D). Line L6 computes k2k^2 costs; each one recomputes the HPWL of the nets of one cell, O(D)O(D) pins, so O(k2D)O(k^2 D). The Hungarian algorithm costs O(k3)O(k^3).
  • One pass. nn steps, so O(n(nD+k2D+k3))O(n (n D + k^2 D + k^3)). With a spatial index the window costs its own size instead of nn, and a pass is close to linear in nn for windows of fixed size.
  • Choice of kk. The exact solve grows as k3k^3 and the quality gain flattens out, so placers use small sets, around ten cells or less.
  • Space. The table O(k2)O(k^2) and the placement O(n)O(n).
  • The implementation uses exact Fractions for HPWL, so the tests compare totals exactly.

Properties

What is proved. Each step gives the best positions for its set among the slots of the set, keeps the placement legal, and never increases WL\mathrm{WL}. Nothing bounds the result against the best detailed placement.

What is measured. Placers that use independent set matching in detailed placement, such as NTUplace3, report the HPWL after detailed placement on the ISPD 2005 and 2006 contest benchmarks; the gain of each move is measured there, not proved. The tests here only check the exact claims on small random instances: the separable sum equals the HPWL computed directly, and the Hungarian result equals the best of all 120 permutations of 5 cells.

  • Moves of many cells at once. A step can carry out any permutation of kk cells, a cycle of length kk included, which a sequence of improving swaps may not reach.
  • Same width. Cells of different widths cannot trade slots in this form.
  • Local. The window keeps the cells close, so the wirelength model of the other nets stays valid and the step stays cheap.

Variants and improvements

  • Mixed widths. Allow cells of different widths by letting a slot be a gap of the right size, or by matching inside a row segment with a check of the total width.
  • Other independent sets. Choose the set by a coloring of the shared-net graph (greedy coloring) and match each color class, so that a whole region is improved in parallel.
  • Other objectives. Add timing or congestion terms to cost(c,s)\mathrm{cost}(c, s); any cost that depends only on the cell and the slot keeps the step exact.
  • Other detailed placement moves. Global swap, vertical swap, local reordering and single-segment clustering (FastDP) are the moves that ISM is usually combined with; see detailed placement.

When to use it

Use independent set matching in detailed placement after legalization, when many cells of the same width are in the same area, which is common for the most used standard cells. It is exact for its set and fast for small kk. It cannot change the order of cells of different widths and cannot fix overlap, so it needs a legal input and other moves next to it.

Pitfalls

  • Shared nets. The cost is separable only if no net has two cells of the set. Without the check, the matching uses wrong costs and can make the placement worse, as the second example shows.
  • Pin offsets. With pins at offsets inside the cell, cells of the same width can still have different pin offsets, which is fine, but flipped orientations change the offsets. Compute the cost with the orientation that the slot gives.
  • Large kk. The O(k3)O(k^3) solve and the k2k^2 cost evaluations grow fast: k=10k = 10 needs 100 cost evaluations, a swap of two cells needs 4.
  • Ties. Many permutations can tie, for example when a cell has no nets. Keep the identity on a tie, or the cells move without gain.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

independent_set_matching.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/independent-set-matching/. The authors are listed in prov/CJ581B.jsonl.

"""Independent set matching for detailed placement.

Cells 0 .. n-1 sit on sites: cell i has the integer left edge x[i], the row row[i] and the
integer width W[i]; rows have height h. A pin of a net is a cell index i < n, which stands for the
center of cell i, or an index n + j, which stands for the fixed pad pads[j] = (px, py).
Net k has the pin list nets[k] and the weight weights[k]. Wirelength is HPWL, computed exactly.
"""

from fractions import Fraction
from typing import Sequence


def pin_point(p, x, row, W, pads, h):
    n = len(x)
    if p < n:
        return Fraction(x[p]) + Fraction(W[p], 2), Fraction(row[p] * h) + Fraction(h, 2)
    px, py = pads[p - n]
    return Fraction(px), Fraction(py)


def net_hpwl(pins, x, row, W, pads, h=1) -> Fraction:
    pts = [pin_point(p, x, row, W, pads, h) for p in pins]
    xs = [a for a, _ in pts]
    ys = [b for _, b in pts]
    return (max(xs) - min(xs)) + (max(ys) - min(ys))


def total_hpwl(x, row, W, nets, weights, pads, h=1) -> Fraction:
    return sum(Fraction(weights[k]) * net_hpwl(nets[k], x, row, W, pads, h) for k in range(len(nets)))


def nets_of_cells(n: int, nets) -> list:
    out = [[] for _ in range(n)]
    for k, pins in enumerate(nets):
        for p in set(pins):
            if p < n:
                out[p].append(k)
    return out


def choose_set(seed, x, row, W, cell_nets, k, wx, wy) -> list:
    """Greedy independent set: the seed, then cells of the same width in the window, nearest first,
    each taken only if it shares no net with the cells taken before."""
    used = set(cell_nets[seed])
    chosen = [seed]
    cand = [c for c in range(len(x)) if c != seed and W[c] == W[seed]
            and abs(x[c] - x[seed]) <= wx and abs(row[c] - row[seed]) <= wy]
    cand.sort(key=lambda c: (abs(x[c] - x[seed]) + abs(row[c] - row[seed]), c))
    for c in cand:
        if len(chosen) == k:
            break
        if used.isdisjoint(cell_nets[c]):
            chosen.append(c)
            used.update(cell_nets[c])
    return chosen


def cost_matrix(S, x, row, W, nets, weights, pads, cell_nets, h=1) -> list:
    """cost[a][b]: the weighted HPWL of the nets of cell S[a] with S[a] at the slot of S[b]
    and every other cell where it is."""
    slots = [(x[c], row[c]) for c in S]
    cost = []
    for c in S:
        line = []
        old = (x[c], row[c])
        for sx, sr in slots:
            x[c], row[c] = sx, sr
            line.append(sum(Fraction(weights[k]) * net_hpwl(nets[k], x, row, W, pads, h) for k in cell_nets[c]))
        x[c], row[c] = old
        cost.append(line)
    return cost


def hungarian(cost) -> tuple:
    """Minimum cost perfect assignment of a square matrix by shortest augmenting paths with
    potentials, O(k^3). Returns (assign, value) with assign[a] = the column of row a."""
    k = len(cost)
    INF = None
    u = [Fraction(0)] * (k + 1)
    v = [Fraction(0)] * (k + 1)
    p = [0] * (k + 1)  # p[j]: the row matched to column j (1-based), 0 if none
    way = [0] * (k + 1)
    for i in range(1, k + 1):
        p[0] = i
        j0 = 0
        minv = [INF] * (k + 1)
        done = [False] * (k + 1)
        while True:
            done[j0] = True
            i0 = p[j0]
            delta, j1 = INF, 0
            for j in range(1, k + 1):
                if not done[j]:
                    cur = Fraction(cost[i0 - 1][j - 1]) - u[i0] - v[j]
                    if minv[j] is None or cur < minv[j]:
                        minv[j] = cur
                        way[j] = j0
                    if delta is None or minv[j] < delta:
                        delta, j1 = minv[j], j
            for j in range(k + 1):
                if done[j]:
                    u[p[j]] += delta
                    v[j] -= delta
                else:
                    minv[j] -= delta
            j0 = j1
            if p[j0] == 0:
                break
        while j0:
            j1 = way[j0]
            p[j0] = p[j1]
            j0 = j1
    assign = [0] * k
    for j in range(1, k + 1):
        assign[p[j] - 1] = j - 1
    return assign, sum(Fraction(cost[a][assign[a]]) for a in range(k))


def ism(x, row, W, nets, weights, pads, k=5, wx=4, wy=1, passes=1, h=1):
    """Return new (x, row) after the given number of passes of independent set matching.
    The input lists are not changed."""
    x, row = list(x), list(row)
    n = len(x)
    cell_nets = nets_of_cells(n, nets)
    for _ in range(passes):  # @line L1
        for seed in sorted(range(n), key=lambda c: (row[c], x[c], c)):  # @line L2
            S = choose_set(seed, x, row, W, cell_nets, k, wx, wy)  # @line L3
            if len(S) < 2:  # @line L4
                continue
            slots = [(x[c], row[c]) for c in S]  # @line L5
            cost = cost_matrix(S, x, row, W, nets, weights, pads, cell_nets, h)  # @line L6
            assign, _ = hungarian(cost)  # @line L7
            for a, c in enumerate(S):  # @line L8
                x[c], row[c] = slots[assign[a]]
    return x, row
test_independent_set_matching.py 145 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/independent-set-matching/. The authors are listed in prov/CJ581B.jsonl.

import random
from fractions import Fraction
from itertools import permutations

from independent_set_matching import (
    choose_set,
    cost_matrix,
    hungarian,
    ism,
    nets_of_cells,
    total_hpwl,
)


def brute_assignment(cost):
    k = len(cost)
    return min(sum(cost[a][perm[a]] for a in range(k)) for perm in permutations(range(k)))


def random_instance(rng, rows=3, sites=12, n=14, m=16, q=4):
    """Cells of width 1 or 2 packed on random distinct sites, random nets, pads on the border."""
    W = [rng.choice([1, 1, 2]) for _ in range(n)]
    x, row = [0] * n, [0] * n
    occupied = {r: set() for r in range(rows)}
    for i in range(n):
        while True:
            r = rng.randrange(rows)
            s = rng.randrange(sites - W[i] + 1)
            span = set(range(s, s + W[i]))
            if span.isdisjoint(occupied[r]):
                occupied[r] |= span
                x[i], row[i] = s, r
                break
    pads = [(rng.choice([0, sites]), rng.randint(0, rows)) for _ in range(q)]
    nets, weights = [], []
    for _ in range(m):
        size = rng.randint(2, 4)
        pins = rng.sample(range(n + q), size)
        nets.append(pins)
        weights.append(rng.randint(1, 3))
    return x, row, W, nets, weights, pads


def legal(x, row, W, sites):
    seen = set()
    for i in range(len(x)):
        for s in range(x[i], x[i] + W[i]):
            if (row[i], s) in seen or not (0 <= s < sites):
                return False
            seen.add((row[i], s))
    return True


def test_hungarian_against_all_permutations():
    rng = random.Random(7)
    for _ in range(300):
        k = rng.randint(1, 6)
        cost = [[Fraction(rng.randint(-20, 20), rng.randint(1, 4)) for _ in range(k)] for _ in range(k)]
        assign, value = hungarian(cost)
        assert sorted(assign) == list(range(k))
        assert value == sum(cost[a][assign[a]] for a in range(k))
        assert value == brute_assignment(cost)


def test_separable_cost_equals_direct_hpwl_and_matches_brute_force_on_5_cells():
    rng = random.Random(11)
    checked = 0
    for _ in range(400):
        x, row, W, nets, weights, pads = random_instance(rng)
        n = len(x)
        cell_nets = nets_of_cells(n, nets)
        seed = rng.randrange(n)
        S = choose_set(seed, x, row, W, cell_nets, 5, 12, 3)
        # the chosen cells share no net and have the same width
        for a in range(len(S)):
            assert W[S[a]] == W[seed]
            for b in range(a + 1, len(S)):
                assert set(cell_nets[S[a]]).isdisjoint(cell_nets[S[b]])
        if len(S) < 5:
            continue
        checked += 1
        slots = [(x[c], row[c]) for c in S]
        cost = cost_matrix(S, x, row, W, nets, weights, pads, cell_nets)
        base = total_hpwl(x, row, W, nets, weights, pads)
        rest = base - sum(cost[a][a] for a in range(5))
        best_direct = None
        for perm in permutations(range(5)):
            xx, rr = list(x), list(row)
            for a, c in enumerate(S):
                xx[c], rr[c] = slots[perm[a]]
            direct = total_hpwl(xx, rr, W, nets, weights, pads)
            assert direct == rest + sum(cost[a][perm[a]] for a in range(5))
            if best_direct is None or direct < best_direct:
                best_direct = direct
        _, value = hungarian(cost)
        assert rest + value == best_direct
    assert checked >= 30


def test_ism_pass_is_legal_and_never_increases_hpwl():
    rng = random.Random(3)
    for _ in range(25):
        x, row, W, nets, weights, pads = random_instance(rng)
        before = total_hpwl(x, row, W, nets, weights, pads)
        nx, nr = ism(x, row, W, nets, weights, pads, k=5, wx=6, wy=2, passes=2)
        after = total_hpwl(nx, nr, W, nets, weights, pads)
        assert legal(nx, nr, W, 12)
        assert sorted(zip(nr, nx, W)) == sorted(zip(row, x, W))  # the same slots, permuted
        assert after <= before


def test_page_example():
    # one row; cells a, b, c of width 1 at x = 0, 2, 4; pads P = (5, 1/2), Q = (0, 1/2), R = (3, 1/2)
    x, row, W = [0, 2, 4], [0, 0, 0], [1, 1, 1]
    pads = [(5, Fraction(1, 2)), (0, Fraction(1, 2)), (3, Fraction(1, 2))]
    nets = [[0, 3], [1, 4], [2, 5]]
    weights = [1, 1, 1]
    assert total_hpwl(x, row, W, nets, weights, pads) == Fraction(17, 2)
    cost = cost_matrix([0, 1, 2], x, row, W, nets, weights, pads, nets_of_cells(3, nets))
    assert cost == [[Fraction(9, 2), Fraction(5, 2), Fraction(1, 2)],
                    [Fraction(1, 2), Fraction(5, 2), Fraction(9, 2)],
                    [Fraction(5, 2), Fraction(1, 2), Fraction(3, 2)]]
    assign, value = hungarian(cost)
    assert assign == [2, 0, 1] and value == Fraction(3, 2)
    nx, _ = ism(x, row, W, nets, weights, pads, k=3, wx=4, wy=0)
    assert nx == [4, 0, 2] and total_hpwl(nx, row, W, nets, weights, pads) == Fraction(3, 2)


def test_shared_net_breaks_the_separable_cost():
    # a at x = 0 and b at x = 5 share a net of weight 2; a likes the left pad, b the right pad
    x, row, W = [0, 5], [0, 0], [1, 1]
    pads = [(-1, Fraction(1, 2)), (7, Fraction(1, 2))]
    nets = [[0, 1], [0, 2], [1, 3]]
    weights = [2, 1, 1]
    cell_nets = nets_of_cells(2, nets)
    cost = cost_matrix([0, 1], x, row, W, nets, weights, pads, cell_nets)
    assign, _ = hungarian(cost)
    assert assign == [1, 0]  # the matrix prefers the swap
    assert cost == [[Fraction(23, 2), Fraction(13, 2)], [Fraction(13, 2), Fraction(23, 2)]]
    swapped = total_hpwl([5, 0], row, W, nets, weights, pads)
    kept = total_hpwl(x, row, W, nets, weights, pads)
    assert (swapped, kept) == (23, 13)  # but the swap is worse

History

Placing objects on slots as an assignment goes back to the quadratic assignment model of Koopmans and Beckmann (1957), in which the cost of an object depends on where the others go. The restriction to cells that share no nets makes the assignment exact for the wirelength. In academic placers of the 2000s it became a standard move of detailed placement; NTUplace3 by Chen, Jiang, Hsu, Chen and Chang (2008) is a well known placer that uses it, next to cell swapping and reordering.

References

  1. Tung-Chieh Chen, Zhe-Wei Jiang, Tien-Chang Hsu, Hsin-Chen Chen and Yao-Wen Chang, NTUplace3, an analytical placer for large-scale mixed-size designs with preplaced blocks and density constraints, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 27(7), 1228 to 1240, 2008, the detailed placement stage, with the matching of independent cells (general locator)
  2. Peter Spindler, Ulf Schlichtmann and Frank M. Johannes, Abacus, fast legalization of standard cell circuits with minimal movement, Proceedings of the International Symposium on Physical Design (ISPD), 47 to 53, 2008, the legal placements that detailed placement starts from (general locator)
  3. Andrew B. Kahng, Jens Lienig, Igor L. Markov and Jin Hu, VLSI Physical Design, From Graph Partitioning to Timing Closure, second edition, Springer, 2022, Chapter 4, Global and Detailed Placement (detailed placement by local moves; general locator)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example