CkPttn 1.2.5
Loading...
Searching...
No Matches
FMKWayGainCalc.hpp
Go to the documentation of this file.
6#pragma once
7
8// #include <algorithm> // for fill
9#include <cstdint> // for uint8_t
10#include <mywheel/dllist.hpp> // for Dllink
11#include <mywheel/robin.hpp> // for fun::Robin<>...
12#include <span> // for span
13#include <utility> // for pair
14#include <vector> // for vector
15
16#include "FMPmrConfig.hpp" // for FMPmr::monotonic_buffer_resource, FMPmr::vector
17
18// forward declare
19template <typename Gnl> class FMKWayGainMgr;
20template <typename Node> struct MoveInfo;
21template <typename Node> struct MoveInfoV;
22
33template <typename Gnl> class FMKWayGainCalc {
34 friend class FMKWayGainMgr<Gnl>;
35 using node_t = typename Gnl::node_t;
36 using Item = Dllink<std::pair<node_t, uint32_t>>;
37
38 private:
40 const Gnl& hyprgraph;
42 std::uint8_t num_parts;
44 fun::Robin<std::uint8_t> rr;
45 // size_t num_modules;
47 int total_cost{0};
49 static constexpr size_t stack_buf_size = 65536;
51 uint8_t stack_buf[stack_buf_size];
53 FMPmr::monotonic_buffer_resource rsrc;
55 std::vector<std::vector<Item>> vertex_list{};
57 std::vector<std::vector<int>> init_gain_list;
59 std::vector<std::vector<int>> delta_gain_buf;
61 std::vector<std::uint8_t> num_buf;
63 FMPmr::vector<int> delta_gain_v;
64
65 public:
67 FMPmr::vector<int> delta_gain_w;
69 FMPmr::vector<node_t> idx_vec;
71 bool special_handle_2pin_nets{true}; // @TODO should be template parameter
72
79 FMKWayGainCalc(const Gnl& hyprgraph, std::uint8_t num_parts)
80 : hyprgraph{hyprgraph},
81 num_parts{num_parts},
82 rr{num_parts},
83 rsrc(stack_buf, sizeof stack_buf),
84 init_gain_list(num_parts, std::vector<int>(hyprgraph.number_of_modules(), 0)),
85 delta_gain_v(num_parts, 0, &rsrc),
86 delta_gain_w(num_parts, 0, &rsrc),
87 idx_vec(&rsrc) {
88 for (auto part_idx = 0U; part_idx != this->num_parts; ++part_idx) {
89 auto vec = std::vector<Item>{};
90 vec.reserve(hyprgraph.number_of_modules());
91 for (const auto& v : this->hyprgraph) {
92 vec.emplace_back(Item(std::make_pair(v, 0)));
93 }
94 this->vertex_list.emplace_back(std::move(vec));
95 }
96 }
97
107 auto init(std::span<const std::uint8_t> part) -> int {
108 this->total_cost = 0;
109 for (auto& vec : this->vertex_list) {
110 for (auto& vlink : vec) {
111 vlink.data.second = 0U;
112 }
113 }
114 for (auto& vec : this->init_gain_list) {
115 for (auto& elem : vec) {
116 elem = 0;
117 }
118 }
119 for (const auto& net : this->hyprgraph.nets) {
120 this->_init_gain(net, part);
121 }
122 return this->total_cost;
123 }
124
131 auto update_move_init() -> void;
132
144 auto update_move_2pin_net(std::span<const std::uint8_t> part, const MoveInfo<node_t>& move_info)
145 -> node_t;
146
156 void init_idx_vec(const node_t& v, const node_t& net);
157
158 using ret_info = std::span<const std::vector<int>>;
159
171 auto update_move_3pin_net(std::span<const std::uint8_t> part, const MoveInfo<node_t>& move_info)
172 -> ret_info;
173
186 auto update_move_general_net(std::span<const std::uint8_t> part,
187 const MoveInfo<node_t>& move_info) -> ret_info;
188
189 private:
201 auto _modify_gain(const node_t& v, std::uint8_t part_v, int weight) -> void {
202 for (const auto& k : this->rr.exclude(part_v)) {
203 // this->vertex_list[k][v].data.second += weight;
204 this->init_gain_list[k][v] += weight;
205 }
206 }
207
219 auto _increase_gain(const node_t& v, std::uint8_t part_v, uint32_t weight) -> void {
220 for (const auto& k : this->rr.exclude(part_v)) {
221 // this->vertex_list[k][v].data.second += weight;
222 this->init_gain_list[k][v] += weight;
223 }
224 }
225
237 auto _decrease_gain(const node_t& v, std::uint8_t part_v, uint32_t weight) -> void {
238 for (const auto& k : this->rr.exclude(part_v)) {
239 // this->vertex_list[k][v].data.second += weight;
240 this->init_gain_list[k][v] -= weight;
241 }
242 }
243
253 auto _init_gain(const node_t& net, std::span<const std::uint8_t> part) -> void;
254
264 auto _init_gain_2pin_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
265
275 auto _init_gain_3pin_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
276
286 auto _init_gain_general_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
287};
PMR configuration and constants for FM algorithm.
K-Way Fiduccia-Mattheyses Gain Calculator.
Definition FMKWayGainCalc.hpp:33
void init_idx_vec(const node_t &v, const node_t &net)
Initializes the index vector for a given vertex and net.
auto update_move_3pin_net(std::span< const std::uint8_t > part, const MoveInfo< node_t > &move_info) -> ret_info
Updates the gain for a 3-pin net after a move.
auto init(std::span< const std::uint8_t > part) -> int
Initializes the FMKWayGainCalc object.
Definition FMKWayGainCalc.hpp:107
FMKWayGainCalc(const Gnl &hyprgraph, std::uint8_t num_parts)
Constructs a new FMKWayGainCalc object.
Definition FMKWayGainCalc.hpp:79
std::span< const std::vector< int > > ret_info
Definition FMKWayGainCalc.hpp:158
auto update_move_general_net(std::span< const std::uint8_t > part, const MoveInfo< node_t > &move_info) -> ret_info
Updates the gain for a general net after a move.
FMPmr::vector< node_t > idx_vec
Index vector for net vertex enumeration.
Definition FMKWayGainCalc.hpp:69
FMPmr::vector< int > delta_gain_w
Delta gain values for each partition.
Definition FMKWayGainCalc.hpp:67
auto update_move_init() -> void
Resets the delta gain vector to 0.
auto update_move_2pin_net(std::span< const std::uint8_t > part, const MoveInfo< node_t > &move_info) -> node_t
Updates the gain for a 2-pin net after a move.
bool special_handle_2pin_nets
Whether to use special handling for 2-pin nets (optimization)
Definition FMKWayGainCalc.hpp:71
K-Way Fiduccia-Mattheyses Gain Manager.
Definition FMKWayGainMgr.hpp:27
Move information for a single vertex (without net reference)
Definition moveinfo.hpp:37
Move information for a single vertex in a net.
Definition moveinfo.hpp:18