From ea56dc9d084a694450d995d147b18a4de86e8b7c Mon Sep 17 00:00:00 2001 From: David Shah Date: Thu, 10 Jan 2019 16:42:29 +0000 Subject: HeAP: Add TAUCS wrapper and integration Signed-off-by: David Shah --- common/placer_heap.cc | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'common/placer_heap.cc') diff --git a/common/placer_heap.cc b/common/placer_heap.cc index 19d5a8e5..9f49e552 100644 --- a/common/placer_heap.cc +++ b/common/placer_heap.cc @@ -25,12 +25,13 @@ */ #include +#include #include #include "log.h" #include "nextpnr.h" #include "place_common.h" +#include "placer_math.h" #include "util.h" - NEXTPNR_NAMESPACE_BEGIN namespace { @@ -76,13 +77,44 @@ template struct EquationSystem } void add_rhs(int row, T val) { rhs[row] += val; } + + void solve(std::vector &x) + { + int nnz = std::accumulate(A.begin(), A.end(), 0, + [](int a, const std::vector> &vec) { return a + int(vec.size()); }); + taucif_system *sys = taucif_create_system(int(rhs.size()), int(A.size()), nnz); + for (int col = 0; col < int(A.size()); col++) { + auto &Ac = A[col]; + for (auto &el : Ac) { + if (col <= el.first) + taucif_set_matrix_value(sys, el.first, col, el.second); + // FIXME: in debug mode, assert really is symmetric + } + } + taucif_solve_system(sys, x.data(), rhs.data()); + taucif_free_system(sys); + } }; + } // namespace class HeAPPlacer { public: HeAPPlacer(Context *ctx) : ctx(ctx) {} + bool place() + { + taucif_init_solver(); + place_constraints(); + build_fast_bels(); + seed_placement(); + update_all_chains(); + + EquationSystem es(place_cells.size(), place_cells.size()); + build_equations(es, false); + solve_equations(es, false); + return true; + } private: Context *ctx; @@ -361,6 +393,19 @@ class HeAPPlacer }); } } + + // Build the system of equations for either X or Y + void solve_equations(EquationSystem &es, bool yaxis) + { + // Return the x or y position of a cell, depending on ydir + auto cell_pos = [&](CellInfo *cell) { return yaxis ? cell_locs.at(cell->name).y : cell_locs.at(cell->name).x; }; + build_equations(es, yaxis); + std::vector vals; + std::transform(place_cells.begin(), place_cells.end(), std::back_inserter(vals), cell_pos); + es.solve(vals); + } }; +bool placer_heap(Context *ctx) { return HeAPPlacer(ctx).place(); } + NEXTPNR_NAMESPACE_END \ No newline at end of file -- cgit v1.2.3