CkPttn 1.2.4
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 FMPmr::vector<int> delta_gain_v;
60
61 public:
63 FMPmr::vector<int> delta_gain_w;
65 FMPmr::vector<node_t> idx_vec;
67 bool special_handle_2pin_nets{true}; // @TODO should be template parameter
68
75 FMKWayGainCalc(const Gnl& hyprgraph, std::uint8_t num_parts)
76 : hyprgraph{hyprgraph},
77 num_parts{num_parts},
78 rr{num_parts},
79 rsrc(stack_buf, sizeof stack_buf),
80 init_gain_list(num_parts, std::vector<int>(hyprgraph.number_of_modules(), 0)),
81 delta_gain_v(num_parts, 0, &rsrc),
82 delta_gain_w(num_parts, 0, &rsrc),
83 idx_vec(&rsrc) {
84 for (auto part_idx = 0U; part_idx != this->num_parts; ++part_idx) {
85 auto vec = std::vector<Item>{};
86 vec.reserve(hyprgraph.number_of_modules());
87 for (const auto& v : this->hyprgraph) {
88 vec.emplace_back(Item(std::make_pair(v, 0)));
89 }
90 this->vertex_list.emplace_back(std::move(vec));
91 }
92 }
93
103 auto init(std::span<const std::uint8_t> part) -> int {
104 this->total_cost = 0;
105 for (auto& vec : this->vertex_list) {
106 for (auto& vlink : vec) {
107 vlink.data.second = 0U;
108 }
109 }
110 for (auto& vec : this->init_gain_list) {
111 for (auto& elem : vec) {
112 elem = 0;
113 }
114 }
115 for (const auto& net : this->hyprgraph.nets) {
116 this->_init_gain(net, part);
117 }
118 return this->total_cost;
119 }
120
127 auto update_move_init() -> void;
128
140 auto update_move_2pin_net(std::span<const std::uint8_t> part, const MoveInfo<node_t>& move_info)
141 -> node_t;
142
152 void init_idx_vec(const node_t& v, const node_t& net);
153
154 using ret_info = std::vector<std::vector<int>>;
155
167 auto update_move_3pin_net(std::span<const std::uint8_t> part, const MoveInfo<node_t>& move_info)
168 -> ret_info;
169
182 auto update_move_general_net(std::span<const std::uint8_t> part,
183 const MoveInfo<node_t>& move_info) -> ret_info;
184
185 private:
197 auto _modify_gain(const node_t& v, std::uint8_t part_v, int weight) -> void {
198 for (const auto& k : this->rr.exclude(part_v)) {
199 // this->vertex_list[k][v].data.second += weight;
200 this->init_gain_list[k][v] += weight;
201 }
202 }
203
215 auto _increase_gain(const node_t& v, std::uint8_t part_v, uint32_t weight) -> void {
216 for (const auto& k : this->rr.exclude(part_v)) {
217 // this->vertex_list[k][v].data.second += weight;
218 this->init_gain_list[k][v] += weight;
219 }
220 }
221
233 auto _decrease_gain(const node_t& v, std::uint8_t part_v, uint32_t weight) -> void {
234 for (const auto& k : this->rr.exclude(part_v)) {
235 // this->vertex_list[k][v].data.second += weight;
236 this->init_gain_list[k][v] -= weight;
237 }
238 }
239
249 auto _init_gain(const node_t& net, std::span<const std::uint8_t> part) -> void;
250
260 auto _init_gain_2pin_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
261
271 auto _init_gain_3pin_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
272
282 auto _init_gain_general_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
283};
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.
std::vector< std::vector< int > > ret_info
Definition FMKWayGainCalc.hpp:154
auto init(std::span< const std::uint8_t > part) -> int
Initializes the FMKWayGainCalc object.
Definition FMKWayGainCalc.hpp:103
FMKWayGainCalc(const Gnl &hyprgraph, std::uint8_t num_parts)
Constructs a new FMKWayGainCalc object.
Definition FMKWayGainCalc.hpp:75
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:65
FMPmr::vector< int > delta_gain_w
Delta gain values for each partition.
Definition FMKWayGainCalc.hpp:63
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:67
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