TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
placer.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// The placement pipeline (design doc 04 §3): `full` runs A (quadratic B2B) → B (SimPL spreading) →
4// C (rotations) → D (legalisation) → E (annealing); `refine` starts from the current placement and runs
5// D (only for illegal parts) → E. Both report the exact lower bounds of doc 04 §1 (L4) and what was achieved.
6#include <array>
7#include <cstdint>
8#include <functional>
9#include <optional>
10#include <string>
11
12#include <nlohmann/json_fwd.hpp>
13
14#include "place/anneal.hpp"
15#include "place/legality.hpp"
16
17namespace tmk::place {
18
20 std::string mode = "full"; // full | refine
21 std::uint64_t seed = 1;
22 int threads = 0; // 0 = min(hardware, 16)
23 int runs = 0; // annealing runs (0 = threads)
24 double effort = 4.0; // annealing moves per run = effort × 4000 × movable parts
25 double alpha_cross_mm = 2.0;
26 double time_limit_s = 0; // wall-time stop for the annealer (0 = none)
27 bool verbose = false;
28 // M8 (doc 04 §3 E, G): see AnnealOptions.
29 bool tempering = false; // parallel tempering over the runs instead of independent runs
30 double lns_rate = 0; // share of annealing steps that are LNS windows
31 int lns_window = 6;
32 int lns_polish = 0; // LNS windows run on the annealing result (deterministic polish; 0 = none)
33 double beta_congestion = 0; // routability weight (0 = off)
34 const CongestionMap* congestion = nullptr;
35 std::vector<int> focus; // LNS seed parts
36 // Side assignment (doc 04 §3 C/E, D48): see AnnealOptions. The problem must be extracted with
37 // ExtractOptions::flip for any part to be allowed to flip.
38 bool flip = false;
39 double via_mm = 2.0;
40 double flip_rate = 0.1;
41 // Recording (video): receives intermediate placements with a stage name. Never affects the result.
42 // `t` is when the state existed (trace_now()); annealing snapshots are delivered after the run.
43 std::function<void(const std::string& stage, const Placement& pl, double t)> trace;
44};
45
46struct Metrics {
47 std::int64_t whpwl = 0; // Σ weight·HPWL (signal nets weight 10, power nets 1), nm
48 std::int64_t hpwl = 0; // Σ HPWL over all nets, nm
49 std::int64_t crossings = 0; // MST airwire crossings between different signal nets
50 int flipped = 0; // parts on the other side than in the input
51 std::int64_t side_vias = 0; // via estimate of the side assignment (unweighted side_vias)
52 int overlaps = 0, outside = 0; // violations involving movable parts
54 // Relative to a reference (the input) placement: violations where at least one involved movable part was
55 // moved. Pairs whose parts both stayed put existed in the input and are not ours.
57 std::vector<std::string> conflicts; // "A/B" pairs and "A/outline" (movable-involved)
58};
59
61 std::string mode;
62 int parts = 0, movable = 0, nets = 0, pins = 0;
64 std::int64_t lb_fixed_rot = 0; // L4 bound with the input's rotations
65 std::int64_t lb_any_rot = 0; // L4 bound valid for any rotations (bounds the final placement)
66 std::int64_t quadratic_whpwl = -1; // weighted HPWL of the B2B quadratic optimum (A), full mode
68 std::array<double, 2> utilisation{0, 0}; // movable demand / free area per side
71 std::vector<std::string> legalise_failures; // references of the parts that found no position
73 std::int64_t legal_start_whpwl = 0; // weighted HPWL entering the annealer
75 std::uint64_t lns_tried = 0, lns_improved = 0; // polish stage
76 double seconds_total = 0;
77 std::vector<std::pair<std::string, double>> stage_seconds;
78 std::vector<std::string> notes, log;
79 bool legal = false; // no new violation (relative to the input) in the result
80};
81
82Metrics measure(const Problem& p, const Placement& pl, const Placement* reference = nullptr);
83// Minimal repair: re-place only conflicting movable parts at the nearest legal spot (refine's legaliser).
84// Empty if no legal repair is found; `moved` returns the number of parts re-placed.
85std::optional<Placement> repaired(const Problem& p, const Placement& pl, int* moved = nullptr);
87nlohmann::json report_json(const Problem& p, const PlaceReport& r);
88
89} // namespace tmk::place
(E) Detailed placement by simulated annealing (design doc 04 §3 E; Kirkpatrick, Gelatt,...
Placement legality (design doc 04 §3 D/E): exact integer tests of courtyards, through-hole obstacles,...
std::optional< Placement > repaired(const Problem &p, const Placement &pl, int *moved=nullptr)
Minimal repair: re-place only conflicting movable parts at the nearest legal spot (refine's legaliser...
PlaceReport place(const Problem &p, Placement &pl, const PlaceOptions &o)
nlohmann::json report_json(const Problem &p, const PlaceReport &r)
Metrics measure(const Problem &p, const Placement &pl, const Placement *reference=nullptr)
std::int64_t crossings
MST airwire crossings between different signal nets.
Definition placer.hpp:49
int flipped
parts on the other side than in the input
Definition placer.hpp:50
std::int64_t whpwl
Σ weight·HPWL (signal nets weight 10, power nets 1), nm.
Definition placer.hpp:47
std::int64_t hpwl
Σ HPWL over all nets, nm.
Definition placer.hpp:48
std::vector< std::string > conflicts
"A/B" pairs and "A/outline" (movable-involved)
Definition placer.hpp:57
int outside
violations involving movable parts
Definition placer.hpp:52
std::int64_t side_vias
via estimate of the side assignment (unweighted side_vias)
Definition placer.hpp:51
int new_overlaps
Relative to a reference (the input) placement: violations where at least one involved movable part wa...
Definition placer.hpp:56
double beta_congestion
routability weight (0 = off)
Definition placer.hpp:33
int threads
0 = min(hardware, 16)
Definition placer.hpp:22
double time_limit_s
wall-time stop for the annealer (0 = none)
Definition placer.hpp:26
bool flip
Side assignment (doc 04 §3 C/E, D48): see AnnealOptions.
Definition placer.hpp:38
std::string mode
full | refine
Definition placer.hpp:20
std::uint64_t seed
Definition placer.hpp:21
const CongestionMap * congestion
Definition placer.hpp:34
double effort
annealing moves per run = effort × 4000 × movable parts
Definition placer.hpp:24
bool tempering
M8 (doc 04 §3 E, G): see AnnealOptions.
Definition placer.hpp:29
int lns_polish
LNS windows run on the annealing result (deterministic polish; 0 = none).
Definition placer.hpp:32
std::function< void(const std::string &stage, const Placement &pl, double t)> trace
Recording (video): receives intermediate placements with a stage name.
Definition placer.hpp:43
double lns_rate
share of annealing steps that are LNS windows
Definition placer.hpp:30
int runs
annealing runs (0 = threads)
Definition placer.hpp:23
std::vector< int > focus
LNS seed parts.
Definition placer.hpp:35
std::array< double, 2 > utilisation
movable demand / free area per side
Definition placer.hpp:68
std::uint64_t lns_tried
Definition placer.hpp:75
std::vector< std::string > notes
Definition placer.hpp:78
std::vector< std::pair< std::string, double > > stage_seconds
Definition placer.hpp:77
std::int64_t lb_any_rot
L4 bound valid for any rotations (bounds the final placement).
Definition placer.hpp:65
std::vector< std::string > log
Definition placer.hpp:78
std::int64_t legal_start_whpwl
weighted HPWL entering the annealer
Definition placer.hpp:73
std::vector< std::string > legalise_failures
references of the parts that found no position
Definition placer.hpp:71
AnnealResult anneal
Definition placer.hpp:74
std::int64_t lb_fixed_rot
L4 bound with the input's rotations.
Definition placer.hpp:64
std::uint64_t lns_improved
polish stage
Definition placer.hpp:75
std::int64_t quadratic_whpwl
weighted HPWL of the B2B quadratic optimum (A), full mode
Definition placer.hpp:66
bool legal
no new violation (relative to the input) in the result
Definition placer.hpp:79