10#include <mywheel/dllist.hpp>
11#include <mywheel/robin.hpp>
20template <
typename Node>
struct MoveInfo;
35 using node_t =
typename Gnl::node_t;
36 using Item = Dllink<std::pair<node_t, uint32_t>>;
42 std::uint8_t num_parts;
44 fun::Robin<std::uint8_t> rr;
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;
80 : hyprgraph{hyprgraph},
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),
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)));
94 this->vertex_list.emplace_back(std::move(vec));
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;
114 for (
auto& vec : this->init_gain_list) {
115 for (
auto& elem : vec) {
119 for (
const auto& net : this->hyprgraph.nets) {
120 this->_init_gain(net, part);
122 return this->total_cost;
158 using ret_info = std::span<const std::vector<int>>;
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)) {
204 this->init_gain_list[k][v] += weight;
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)) {
222 this->init_gain_list[k][v] += weight;
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)) {
240 this->init_gain_list[k][v] -= weight;
253 auto _init_gain(
const node_t& net, std::span<const std::uint8_t> part) -> void;
264 auto _init_gain_2pin_net(
const node_t& net, std::span<const std::uint8_t> part) -> void;
275 auto _init_gain_3pin_net(
const node_t& net, std::span<const std::uint8_t> part) -> void;
286 auto _init_gain_general_net(
const node_t& net, std::span<const std::uint8_t> part) -> void;
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