CkPttn 1.2.4
Loading...
Searching...
No Matches
FMBiGainCalc.hpp
Go to the documentation of this file.
6#pragma once
7
8// #include <cstddef> // for byte
9#include <cstdint> // for uint8_t
10#include <mywheel/dllist.hpp> // for Dllink
11#include <span> // for span
12#include <utility> // for pair
13#include <vector> // for vector
14
15#include "FMPmrConfig.hpp"
16// #include "moveinfo.hpp" // for MoveInfo
17
18// forward declare
19template <typename Gnl> class FMBiGainMgr;
20template <typename Node> struct MoveInfo;
21template <typename Node> struct MoveInfoV;
22
32template <typename Gnl> class FMBiGainCalc {
33 friend class FMBiGainMgr<Gnl>;
34
35 public:
36 using node_t = typename Gnl::node_t;
37 using Item = Dllink<std::pair<node_t, uint32_t>>;
38
39 private:
41 const Gnl& hyprgraph;
43 std::vector<Item> vertex_list;
45 std::vector<int> init_gain_list;
47 int total_cost{0};
49 static constexpr size_t stack_buf_size = 32768;
51 uint8_t stack_buf[stack_buf_size];
53 FMPmr::monotonic_buffer_resource rsrc;
54
55 public:
59 FMPmr::vector<node_t> idx_vec;
62
64 const auto& get_init_gain_list() const { return this->init_gain_list; }
65
71 explicit FMBiGainCalc(const Gnl& hyprgraph, std::uint8_t /*num_parts*/)
72 : hyprgraph{hyprgraph},
73 vertex_list(hyprgraph.number_of_modules()),
74 init_gain_list(hyprgraph.number_of_modules(), 0),
75 rsrc(stack_buf, sizeof stack_buf),
76 idx_vec(&rsrc) {
77 for (const auto& v : this->hyprgraph) {
78 this->vertex_list[v].data = std::make_pair(v, uint32_t(0));
79 }
80 }
81
92 auto init(std::span<const std::uint8_t> part) -> int {
93 this->total_cost = 0;
94 for (auto& vlink : this->vertex_list) {
95 vlink.data.second = 0U;
96 }
97 for (auto& elem : this->init_gain_list) {
98 elem = 0;
99 }
100 for (const auto& net : this->hyprgraph.nets) {
101 this->_init_gain(net, part);
102 }
103 return this->total_cost;
104 }
105
109 auto update_move_init() -> void {
110 // nothing to do in 2-way partitioning
111 }
112
122 void init_idx_vec(const node_t& module, const node_t& net);
123
134 auto update_move_2pin_net(std::span<const std::uint8_t> part, const MoveInfo<node_t>& move_info)
135 -> node_t;
136
147 auto update_move_3pin_net(std::span<const std::uint8_t> part, const MoveInfo<node_t>& move_info)
148 -> std::vector<int>;
149
160 auto update_move_general_net(std::span<const std::uint8_t> part,
161 const MoveInfo<node_t>& move_info) -> std::vector<int>;
162
163 private:
174 auto _modify_gain(const node_t& w, int weight) -> void {
175 // this->vertex_list[node_w].data.second += weight;
176 this->init_gain_list[w] += weight;
177 }
178
188 auto _increase_gain(const node_t& w, uint32_t weight) -> void {
189 // this->vertex_list[w].data.second += weight;
190 this->init_gain_list[w] += weight;
191 }
192
202 auto _decrease_gain(const node_t& w, uint32_t weight) -> void {
203 // this->vertex_list[w].data.second += weight;
204 this->init_gain_list[w] -= weight;
205 }
206
216 auto _init_gain(const node_t& net, std::span<const std::uint8_t> part) -> void;
217
227 auto _init_gain_2pin_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
228
238 auto _init_gain_3pin_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
239
249 auto _init_gain_general_net(const node_t& net, std::span<const std::uint8_t> part) -> void;
250};
PMR configuration and constants for FM algorithm.
Binary Fiduccia-Mattheyses Gain Calculator.
Definition FMBiGainCalc.hpp:32
FMBiGainCalc(const Gnl &hyprgraph, std::uint8_t)
Constructs a new FMBiGainCalc object.
Definition FMBiGainCalc.hpp:71
auto update_move_2pin_net(std::span< const std::uint8_t > part, const MoveInfo< node_t > &move_info) -> node_t
Update a 2-pin net during a move operation.
auto update_move_init() -> void
This function does nothing in 2-way partitioning.
Definition FMBiGainCalc.hpp:109
auto update_move_3pin_net(std::span< const std::uint8_t > part, const MoveInfo< node_t > &move_info) -> std::vector< int >
Update the gain values for a 3-pin net during a move operation.
void init_idx_vec(const node_t &module, const node_t &net)
Initializes the index vector for a given vertex and net.
bool special_handle_2pin_nets
Whether to use special handling for 2-pin nets (optimization)
Definition FMBiGainCalc.hpp:61
const auto & get_init_gain_list() const
Expose initial gain list for read-only use.
Definition FMBiGainCalc.hpp:64
auto update_move_general_net(std::span< const std::uint8_t > part, const MoveInfo< node_t > &move_info) -> std::vector< int >
Update the gain values for a general net during a move operation.
Dllink< std::pair< node_t, uint32_t > > Item
Definition FMBiGainCalc.hpp:37
int delta_gain_w
Delta gain for the winning partition.
Definition FMBiGainCalc.hpp:57
FMPmr::vector< node_t > idx_vec
Index vector for net vertex enumeration.
Definition FMBiGainCalc.hpp:59
auto init(std::span< const std::uint8_t > part) -> int
Initializes the FMBiGainCalc object.
Definition FMBiGainCalc.hpp:92
typename Gnl::node_t node_t
Definition FMBiGainCalc.hpp:36
Binary Fiduccia-Mattheyses Gain Manager.
Definition FMBiGainMgr.hpp:26
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