TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
routable.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Router-in-the-loop placement (design doc 04 §3 G) and ECO placement (doc 04 §4).
4//
5// Both take the router as a callback (`RouteFn`), so this library does not depend on tm::route and the logic
6// can be tested with a synthetic router. The caller routes with a deterministic work budget, so every decision
7// here is reproducible. A placement is only ever accepted when it routes more connections than the incumbent
8// (transactions, CLAUDE.md rule 4); locked and otherwise fixed parts never move (rule 6).
9#include <array>
10#include <functional>
11#include <string>
12#include <vector>
13
14#include "place/congestion.hpp"
15#include "place/placer.hpp"
16
17namespace tmk::place {
18
19// What the router reports for one placement.
20struct RouteEval {
21 bool ok = false;
22 int connections = 0, routed = 0;
23 int unrouted() const { return connections - routed; }
24 struct Failure {
25 int part_a = -1, part_b = -1; // parts at both ends (-1: a zone or an unknown reference)
26 Point a, b; // end points (pad positions; b = a for zone connections)
27 std::string net;
28 };
29 std::vector<Failure> failed;
30 double seconds = 0;
31};
32using RouteFn = std::function<RouteEval(const Placement&)>;
33
34struct Candidate {
35 std::string label;
38 std::int64_t hpwl = 0; // Σ HPWL (nm) on the loop's problem
39 bool legal = true; // no overlap or outline violation involving a movable part, not just parts moved
40};
41// Better routed result: fewer unrouted connections, then shorter wirelength.
42bool better(const Candidate& a, const Candidate& b);
43
44// ---- ECO placement (doc 04 §4) ---------------------------------------------------------------------------------
45
46// Failure memory (doc 04 §4 step 4): moves already routed without improvement, by part, target and rotation.
47struct EcoMemory {
48 std::vector<std::array<std::int64_t, 8>> tried;
49};
50
51struct EcoOptions {
52 int rounds = 4; // commit rounds
53 int candidates = 5; // moves routed per round (the best-ranked ones)
54 Coord pitch = 500'000; // shift step
55 int max_steps = 4; // shifts of 1..max_steps pitches in each axis direction
56 Coord corridor = 1'500'000; // parts whose body is within this of a failed connection's box are candidates
57 double alpha_cross_mm = 2.0;
58 double beta = 1.0; // routability weight in the ranking cost
59 int weight_boost = 3; // failed nets weigh this many times more in the ranking cost
60 double disp_cost = 0.25; // ranking: one mm of displacement costs this many mm of signal HPWL
61 Coord room = 2'000'000; // ranking: clearance around a failed pad counts up to this distance
62 double room_gain = 4.0; // ranking: one mm more room around a failed pad is worth this many mm of signal HPWL
63 double via_mm = 0; // ranking: side-assignment via estimate (only when flipping is on; D48)
64 std::function<void(const std::string&)> log;
65 EcoMemory* memory = nullptr; // shared across calls (e.g. the rounds of the routability loop); null = local
66};
67
68struct EcoResult {
71 int routes = 0, committed = 0, ranked = 0;
72 std::vector<std::string> moves; // committed moves ("R3 shift +x 1.0 mm: 5 -> 3 unrouted")
73};
74
75// Small moves of movable parts near the failed connections of `start` (shift, rotate, swap with an identical
76// part), ranked by a geometric estimate (annealing cost with boosted failed nets, penalised congestion bins and a
77// displacement charge), the top ones routed; the best strictly improving move is committed per round. Moves that
78// failed are remembered and not tried again.
79EcoResult eco_place(const Problem& p, const Placement& start, const RouteEval& start_eval, const EcoOptions& o, const RouteFn& route);
80
81// ---- Routability loop (doc 04 §3 G) ----------------------------------------------------------------------------
82
84 PlaceOptions place; // annealing options for the re-placement rounds (mode is forced to refine)
85 double beta = 1.0; // routability weight (RUDY overflow) in the re-placement rounds
86 int rounds = 3; // penalty rounds after the seeds
87 double penalty = 0.6; // capacity factor applied per round to bins around failed connections
88 int weight_boost = 3; // failed nets weigh this many times more in the re-placement rounds
89 int eco_candidates = 4; // ECO moves routed per round (0 = no ECO step)
90 std::function<void(const std::string&)> log;
91 // Job wall-time stop (CLAUDE.md rule 5): checked between routes; when it returns true the loop stops and keeps
92 // the best candidate so far. The first seed (the input) is always routed.
93 std::function<bool()> out_of_time;
94 // Recording (video): called with a candidate's label whenever it becomes the incumbent. Re-placement stages
95 // reach o.place.trace as "<label>|<stage>".
96 std::function<void(const std::string& label)> on_incumbent;
97 std::function<void(const std::string& label)> on_route; // recording: a check route of this candidate starts
98 // --repair-input (D75): only seeds without any conflict can become the incumbent; the others are routed for
99 // reference. Off: every seed is eligible, as its caller checked it adds no conflict to the input's.
101 // With absolute_seed_legality: the first seed is the input whose minimal repair failed; it is compared as it is.
103};
104
107 std::vector<Candidate> tried; // every routed candidate (placements dropped), in order
108 int routes = 0, rounds = 0;
109};
110
111// Routes the seeds (those without a result), keeps the best, then for up to `rounds` rounds re-places around the
112// failed connections (refine annealing with β·RUDY over a capacity map shrunk where the router failed, boosted
113// weights for the failed nets, LNS windows centred on their parts) and tries ECO moves; a candidate replaces
114// the incumbent only if it leaves fewer connections unrouted.
115LoopResult routability_loop(const Problem& p, std::vector<Candidate> seeds, const LoopOptions& o, const RouteFn& route);
116
117} // namespace tmk::place
Routability estimate for placement (design doc 04 §3 B R(x), E β·RUDY overflow, G).
LoopResult routability_loop(const Problem &p, std::vector< Candidate > seeds, const LoopOptions &o, const RouteFn &route)
Routes the seeds (those without a result), keeps the best, then for up to rounds rounds re-places aro...
bool better(const Candidate &a, const Candidate &b)
Better routed result: fewer unrouted connections, then shorter wirelength.
EcoResult eco_place(const Problem &p, const Placement &start, const RouteEval &start_eval, const EcoOptions &o, const RouteFn &route)
Small moves of movable parts near the failed connections of start (shift, rotate, swap with an identi...
std::function< RouteEval(const Placement &)> RouteFn
Definition routable.hpp:32
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
The placement pipeline (design doc 04 §3): full runs A (quadratic B2B) → B (SimPL spreading) → C (rot...
bool legal
no overlap or outline violation involving a movable part, not just parts moved
Definition routable.hpp:39
std::int64_t hpwl
Σ HPWL (nm) on the loop's problem.
Definition routable.hpp:38
Failure memory (doc 04 §4 step 4): moves already routed without improvement, by part,...
Definition routable.hpp:47
std::vector< std::array< std::int64_t, 8 > > tried
Definition routable.hpp:48
double room_gain
ranking: one mm more room around a failed pad is worth this many mm of signal HPWL
Definition routable.hpp:62
Coord corridor
parts whose body is within this of a failed connection's box are candidates
Definition routable.hpp:56
std::function< void(const std::string &)> log
Definition routable.hpp:64
Coord room
ranking: clearance around a failed pad counts up to this distance
Definition routable.hpp:61
int max_steps
shifts of 1..max_steps pitches in each axis direction
Definition routable.hpp:55
int rounds
commit rounds
Definition routable.hpp:52
double via_mm
ranking: side-assignment via estimate (only when flipping is on; D48)
Definition routable.hpp:63
double beta
routability weight in the ranking cost
Definition routable.hpp:58
double disp_cost
ranking: one mm of displacement costs this many mm of signal HPWL
Definition routable.hpp:60
EcoMemory * memory
shared across calls (e.g. the rounds of the routability loop); null = local
Definition routable.hpp:65
Coord pitch
shift step
Definition routable.hpp:54
int candidates
moves routed per round (the best-ranked ones)
Definition routable.hpp:53
int weight_boost
failed nets weigh this many times more in the ranking cost
Definition routable.hpp:59
std::vector< std::string > moves
committed moves ("R3 shift +x 1.0 mm: 5 -> 3 unrouted")
Definition routable.hpp:72
std::function< void(const std::string &label)> on_route
recording: a check route of this candidate starts
Definition routable.hpp:97
bool absolute_seed_legality
–repair-input (D75): only seeds without any conflict can become the incumbent; the others are routed ...
Definition routable.hpp:100
double beta
routability weight (RUDY overflow) in the re-placement rounds
Definition routable.hpp:85
int eco_candidates
ECO moves routed per round (0 = no ECO step).
Definition routable.hpp:89
int rounds
penalty rounds after the seeds
Definition routable.hpp:86
PlaceOptions place
annealing options for the re-placement rounds (mode is forced to refine)
Definition routable.hpp:84
std::function< bool()> out_of_time
Job wall-time stop (CLAUDE.md rule 5): checked between routes; when it returns true the loop stops an...
Definition routable.hpp:93
int weight_boost
failed nets weigh this many times more in the re-placement rounds
Definition routable.hpp:88
std::function< void(const std::string &)> log
Definition routable.hpp:90
bool accept_first_seed_conflicts
With absolute_seed_legality: the first seed is the input whose minimal repair failed; it is compared ...
Definition routable.hpp:102
std::function< void(const std::string &label)> on_incumbent
Recording (video): called with a candidate's label whenever it becomes the incumbent.
Definition routable.hpp:96
double penalty
capacity factor applied per round to bins around failed connections
Definition routable.hpp:87
std::vector< Candidate > tried
every routed candidate (placements dropped), in order
Definition routable.hpp:107
int part_b
parts at both ends (-1: a zone or an unknown reference)
Definition routable.hpp:25
Point b
end points (pad positions; b = a for zone connections)
Definition routable.hpp:26
What the router reports for one placement.
Definition routable.hpp:20
int unrouted() const
Definition routable.hpp:23
std::vector< Failure > failed
Definition routable.hpp:29