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 FMPmr::vector<int> delta_gain_v;
76 : hyprgraph{hyprgraph},
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),
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)));
90 this->vertex_list.emplace_back(std::move(vec));
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;
110 for (
auto& vec : this->init_gain_list) {
111 for (
auto& elem : vec) {
115 for (
const auto& net : this->hyprgraph.nets) {
116 this->_init_gain(net, part);
118 return this->total_cost;
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)) {
200 this->init_gain_list[k][v] += weight;
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)) {
218 this->init_gain_list[k][v] += weight;
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)) {
236 this->init_gain_list[k][v] -= weight;
249 auto _init_gain(
const node_t& net, std::span<const std::uint8_t> part) -> void;
260 auto _init_gain_2pin_net(
const node_t& net, std::span<const std::uint8_t> part) -> void;
271 auto _init_gain_3pin_net(
const node_t& net, std::span<const std::uint8_t> part) -> void;
282 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.
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