From d4bcce80065c984ae3883c4240ddfcaf935feb43 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 9 Jul 2024 17:17:09 +0200 Subject: [PATCH 01/23] Update post_layout_optimization.hpp --- .../post_layout_optimization.hpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index b1f52f6b3..daf5515d7 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -514,7 +514,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& { const uint64_t y = k - x; - if (moved_gate || (num_gate_relocations >= max_gate_relocations)) + if (moved_gate || ((num_gate_relocations >= max_gate_relocations) && !lyt.is_po_tile(current_pos))) { break; } @@ -636,7 +636,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& } } - if (moved_gate || (num_gate_relocations >= max_gate_relocations)) + if (moved_gate || ((num_gate_relocations >= max_gate_relocations) & !lyt.is_po_tile(current_pos))) { break; } @@ -846,15 +846,14 @@ class post_layout_optimization_impl std::sort(gate_tiles.begin(), gate_tiles.end(), detail::compare_gate_tiles); - tile max_non_po; - // Iterate through the vector in reverse - for (auto it = gate_tiles.rbegin(); it != gate_tiles.rend(); ++it) + tile max_non_po{0, 0}; + // Determine minimal border for POs + for (auto gate_tile : gate_tiles) { - // Stop if a condition based on the element is met - if (!layout.is_po_tile(*it)) + if (!layout.is_po_tile(gate_tile)) { - max_non_po = *it; - break; + max_non_po.x = std::max(max_non_po.x, gate_tile.x); + max_non_po.y = std::max(max_non_po.y, gate_tile.y); } } moved_at_least_one_gate = false; From 379e92ef15e5a689026c437137e02559c1ecb480 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 9 Jul 2024 17:32:03 +0200 Subject: [PATCH 02/23] Update wiring_reduction.hpp --- .../physical_design/wiring_reduction.hpp | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/include/fiction/algorithms/physical_design/wiring_reduction.hpp b/include/fiction/algorithms/physical_design/wiring_reduction.hpp index 0893e0c41..5183bc72d 100644 --- a/include/fiction/algorithms/physical_design/wiring_reduction.hpp +++ b/include/fiction/algorithms/physical_design/wiring_reduction.hpp @@ -543,6 +543,55 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_coordinate(new_coord); wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y, 1}); + // special case: + // = + // ↓ + // = = + // ↓ ↓ + // =→& + // + // -> No crossing between coordinate to the left and coordinate above the gate + if (lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && + lyt.has_northern_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}) && + lyt.is_wire_tile({old_coord.x - 1, old_coord.y, old_coord.z}) && + lyt.is_wire_tile({old_coord.x, old_coord.y - 1, old_coord.z}) && + lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && + lyt.is_wire_tile({old_coord.x, old_coord.y - 2, old_coord.z}) && + !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y, old_coord.z})) && + !lyt.is_fanout(lyt.get_node({old_coord.x, old_coord.y - 1, old_coord.z})) && + !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y - 1, old_coord.z})) && + !lyt.is_fanout(lyt.get_node({old_coord.x, old_coord.y - 2, old_coord.z}))) + + { + if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) + { + wiring_reduction_lyt.obstruct_coordinate({new_coord.x - 1, new_coord.y, 0}); + wiring_reduction_lyt.obstruct_coordinate({new_coord.x - 1, new_coord.y, 1}); + } + } + // special case: + // =→= + // ↓ + // =→=→& + // + // -> No crossing between coordinate to the left and coordinate above the gate + if (lyt.has_western_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && + lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}) && + lyt.is_wire_tile({old_coord.x - 1, old_coord.y, old_coord.z}) && + lyt.is_wire_tile({old_coord.x, old_coord.y - 1, old_coord.z}) && + lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && + lyt.is_wire_tile({old_coord.x - 2, old_coord.y, old_coord.z}) && + !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y, old_coord.z})) && + !lyt.is_fanout(lyt.get_node({old_coord.x, old_coord.y - 1, old_coord.z})) && + !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y - 1, old_coord.z})) && + !lyt.is_fanout(lyt.get_node({old_coord.x - 2, old_coord.y, old_coord.z}))) + { + if (wiring_reduction_lyt.get_search_direction() == search_direction::VERTICAL) + { + wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y - 1, 0}); + wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y - 1, 1}); + } + } // special case: // +→= // ↓ ↓ From 5a37fbc8730874d20769ceac6dfa75209c4a6391 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:04:35 +0200 Subject: [PATCH 03/23] Update include/fiction/algorithms/physical_design/post_layout_optimization.hpp Co-authored-by: Marcel Walter Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> --- .../algorithms/physical_design/post_layout_optimization.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index daf5515d7..073192811 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -848,7 +848,7 @@ class post_layout_optimization_impl tile max_non_po{0, 0}; // Determine minimal border for POs - for (auto gate_tile : gate_tiles) + for (const auto& gate_tile : gate_tiles) { if (!layout.is_po_tile(gate_tile)) { From 5b5869c06420088035ec4870c7d12a98aa5f298f Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:37:19 +0200 Subject: [PATCH 04/23] Update wiring_reduction.hpp --- .../physical_design/wiring_reduction.hpp | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/include/fiction/algorithms/physical_design/wiring_reduction.hpp b/include/fiction/algorithms/physical_design/wiring_reduction.hpp index 5183bc72d..88c73a3d1 100644 --- a/include/fiction/algorithms/physical_design/wiring_reduction.hpp +++ b/include/fiction/algorithms/physical_design/wiring_reduction.hpp @@ -544,8 +544,28 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y, 1}); // special case: - // = - // ↓ + // +→= + // ↓ ↓ + // =→& + // + // -> No crossing between coordinate to the left and coordinate above the gate + if (lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && + lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z})) + { + if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) + { + wiring_reduction_lyt.obstruct_connection({new_coord.x - 1, new_coord.y, new_coord.z}, + {new_coord.x, new_coord.y - 1, new_coord.z}); + } + else + { + wiring_reduction_lyt.obstruct_connection({new_coord.x, new_coord.y - 1, new_coord.z}, + {new_coord.x - 1, new_coord.y, new_coord.z}); + } + } + // special case: + // +→= + // ↓ ↓ // = = // ↓ ↓ // =→& @@ -553,6 +573,8 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons // -> No crossing between coordinate to the left and coordinate above the gate if (lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && lyt.has_northern_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}) && + lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && + lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 2, old_coord.z}) && lyt.is_wire_tile({old_coord.x - 1, old_coord.y, old_coord.z}) && lyt.is_wire_tile({old_coord.x, old_coord.y - 1, old_coord.z}) && lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && @@ -570,13 +592,15 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons } } // special case: - // =→= - // ↓ + // +→=→= + // ↓ ↓ // =→=→& // // -> No crossing between coordinate to the left and coordinate above the gate if (lyt.has_western_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}) && + lyt.has_western_incoming_signal({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && + lyt.has_northern_incoming_signal({old_coord.x - 2, old_coord.y, old_coord.z}) && lyt.is_wire_tile({old_coord.x - 1, old_coord.y, old_coord.z}) && lyt.is_wire_tile({old_coord.x, old_coord.y - 1, old_coord.z}) && lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && @@ -592,27 +616,6 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y - 1, 1}); } } - // special case: - // +→= - // ↓ ↓ - // =→& - // - // -> No crossing between coordinate to the left and coordinate above the gate - if (!(lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}))) - { - return; - } - if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) - { - wiring_reduction_lyt.obstruct_connection({new_coord.x - 1, new_coord.y, new_coord.z}, - {new_coord.x, new_coord.y - 1, new_coord.z}); - } - else - { - wiring_reduction_lyt.obstruct_connection({new_coord.x, new_coord.y - 1, new_coord.z}, - {new_coord.x - 1, new_coord.y, new_coord.z}); - } } }); From 33ce0f7faab55109dca22e6f91f117566d0392c9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:37:32 +0000 Subject: [PATCH 05/23] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commit?= =?UTF-8?q?=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/fiction/algorithms/physical_design/wiring_reduction.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/physical_design/wiring_reduction.hpp b/include/fiction/algorithms/physical_design/wiring_reduction.hpp index 88c73a3d1..a6c26550c 100644 --- a/include/fiction/algorithms/physical_design/wiring_reduction.hpp +++ b/include/fiction/algorithms/physical_design/wiring_reduction.hpp @@ -550,7 +550,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons // // -> No crossing between coordinate to the left and coordinate above the gate if (lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z})) + lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z})) { if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) { From cf2560d7e9aac369dca73a2129b73b7f6b035e5e Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:38:46 +0200 Subject: [PATCH 06/23] Update post_layout_optimization.hpp --- .../algorithms/physical_design/post_layout_optimization.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 073192811..8cf37dffe 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -636,7 +636,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& } } - if (moved_gate || ((num_gate_relocations >= max_gate_relocations) & !lyt.is_po_tile(current_pos))) + if (moved_gate || ((num_gate_relocations >= max_gate_relocations) && !lyt.is_po_tile(current_pos))) { break; } From 7285b6489c9fcac2cce6340ffc00369bbfd97b0c Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:28:25 +0200 Subject: [PATCH 07/23] Update post_layout_optimization.hpp --- .../post_layout_optimization.hpp | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 8cf37dffe..29f887edd 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -523,7 +523,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& if (lyt.y() >= y && y >= min_y && lyt.x() >= x && x >= min_x && ((x + y) <= max_diagonal) && (((x + y) < max_diagonal) || (y <= max_y)) && ((!lyt.is_pi_tile(current_pos)) || (lyt.is_pi_tile(current_pos) && (x == 0 || y == 0))) && - !(lyt.is_po_tile(current_pos) && (((x <= max_non_po.x) && (y <= max_non_po.y)) || + !(lyt.is_po_tile(current_pos) && (((x < max_non_po.x) && (y < max_non_po.y)) || ((x + y) == static_cast(old_pos.x + old_pos.y))))) { new_pos = tile{x, y}; @@ -636,7 +636,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& } } - if (moved_gate || ((num_gate_relocations >= max_gate_relocations) && !lyt.is_po_tile(current_pos))) + if (moved_gate || ((num_gate_relocations >= max_gate_relocations) & !lyt.is_po_tile(current_pos))) { break; } @@ -763,6 +763,41 @@ void optimize_output_positions(Lyt& lyt) noexcept } } } + // calculate bounding box + auto bounding_box = bounding_box_2d(lyt); + lyt.resize({bounding_box.get_max().x, bounding_box.get_max().y, lyt.z()}); + + // Check for misplaced POs in second last row and move them down one row + for (uint64_t x = 0; x < lyt.x(); ++x) + { + if (lyt.is_po_tile({x, lyt.y() - 1, 0})) + { + std::vector> signals{}; + signals.reserve(lyt.fanin_size(lyt.get_node({x, lyt.y()}))); + lyt.foreach_fanin(lyt.get_node({x, lyt.y() - 1}), + [&signals](const auto& fanin) { signals.push_back(fanin); }); + lyt.move_node(lyt.get_node({x, lyt.y() - 1}), {x, lyt.y(), 0}, {}); + lyt.create_buf(signals[0], {x, lyt.y() - 1}); + lyt.move_node(lyt.get_node({x, lyt.y()}), {x, lyt.y(), 0}, + {lyt.make_signal(lyt.get_node({x, lyt.y() - 1}))}); + } + } + + // Check for misplaced POs in second last column and move them to the right one column + for (uint64_t y = 0; y < lyt.y(); ++y) + { + if (lyt.is_po_tile({lyt.x() - 1, y, 0})) + { + std::vector> signals{}; + signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), y}))); + lyt.foreach_fanin(lyt.get_node({lyt.x() - 1, y}), + [&signals](const auto& fanin) { signals.push_back(fanin); }); + lyt.move_node(lyt.get_node({lyt.x() - 1, y}), {lyt.x(), y, 0}, {}); + lyt.create_buf(signals[0], {lyt.x() - 1, y}); + lyt.move_node(lyt.get_node({lyt.x(), y}), {lyt.x(), y, 0}, + {lyt.make_signal(lyt.get_node({lyt.x() - 1, y}))}); + } + } } /** * Custom comparison function for sorting tiles based on the sum of their coordinates that breaks ties based on the @@ -848,7 +883,7 @@ class post_layout_optimization_impl tile max_non_po{0, 0}; // Determine minimal border for POs - for (const auto& gate_tile : gate_tiles) + for (auto gate_tile : gate_tiles) { if (!layout.is_po_tile(gate_tile)) { From 244256dff3bb003a510ee2bc4cf047e1c3b94025 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:31:28 +0200 Subject: [PATCH 08/23] Update wiring_reduction.hpp --- .../physical_design/wiring_reduction.hpp | 265 +++++++++--------- 1 file changed, 125 insertions(+), 140 deletions(-) diff --git a/include/fiction/algorithms/physical_design/wiring_reduction.hpp b/include/fiction/algorithms/physical_design/wiring_reduction.hpp index a6c26550c..b7fb3cf96 100644 --- a/include/fiction/algorithms/physical_design/wiring_reduction.hpp +++ b/include/fiction/algorithms/physical_design/wiring_reduction.hpp @@ -399,6 +399,35 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y, 1}); } + // Utility function to check if a tile hosts a single wire only, which is not a fanout or hosts a + // crossing: + // + // = + auto is_single_wire = [&lyt, &old_coord](uint64_t x_offset, uint64_t y_offset) + { + return lyt.is_wire_tile({old_coord.x - x_offset, old_coord.y - y_offset, 0}) && + !lyt.is_fanout(lyt.get_node({old_coord.x - x_offset, old_coord.y - y_offset, 0}) && + lyt.is_empty_tile({old_coord.x - x_offset, old_coord.y - y_offset, 1})); + }; + + // Utility function to check for crossings with outgoing wires to the bottom layer: + // + // +→= + // ↓ + // = + auto is_crossing = [&lyt, &old_coord](uint64_t x_offset, uint64_t y_offset) + { + return lyt.has_northern_incoming_signal({old_coord.x - x_offset, old_coord.y - y_offset + 1, 0}) && + lyt.has_western_incoming_signal({old_coord.x - x_offset + 1, old_coord.y - y_offset, 0}); + }; + + // Utility function to fully obstruct a coordinate + auto obstruct_coordinate = [&wiring_reduction_lyt, &new_coord](uint64_t x_offset, uint64_t y_offset) + { + wiring_reduction_lyt.obstruct_coordinate({new_coord.x - x_offset, new_coord.y - y_offset, 0}); + wiring_reduction_lyt.obstruct_coordinate({new_coord.x - x_offset, new_coord.y - y_offset, 1}); + }; + // Handle single input gates and wires if (const auto signals = lyt.incoming_data_flow(old_coord); signals.size() == 1) { @@ -416,59 +445,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons (lyt.has_northern_incoming_signal({old_coord}) && lyt.has_southern_outgoing_signal({old_coord}) && (wiring_reduction_lyt.get_search_direction() == search_direction::VERTICAL))) { - wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y, 0}); - wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y, 1}); - - if (old_coord.z == 0) - { - return; - } - - // special case 1: - // +→= - // ↓ ↓ - // =→+ - // - // special case 2: - // = - // ↓ - // = = - // ↓ ↓ - // =→+ - // - // special case 3: - // - // =→= - // ↓ - // =→=→+ - const auto special_case_1 = lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, 0}) && - lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, 0}); - const auto special_case_2 = lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, 0}) && - lyt.has_northern_incoming_signal({old_coord.x, old_coord.y - 1, 0}) && - lyt.is_wire_tile({old_coord.x, old_coord.y - 2, 0}) && - lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, 0}); - const auto special_case_3 = lyt.has_western_incoming_signal({old_coord.x - 1, old_coord.y, 0}) && - lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, 0}) && - lyt.is_wire_tile({old_coord.x - 2, old_coord.y, 0}) && - lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, 0}); - if (!(special_case_1 || special_case_2 || special_case_3)) - { - return; - } - - // -> No crossing between coordinate to the left and coordinate above the gate - if ((wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) && - (special_case_1 || special_case_2)) - { - wiring_reduction_lyt.obstruct_connection({new_coord.x - 1, new_coord.y, 0}, - {new_coord.x, new_coord.y - 1, 0}); - } - else if ((wiring_reduction_lyt.get_search_direction() == search_direction::VERTICAL) && - (special_case_1 || special_case_3)) - { - wiring_reduction_lyt.obstruct_connection({new_coord.x, new_coord.y - 1, 0}, - {new_coord.x - 1, new_coord.y, 0}); - } + obstruct_coordinate(0, 0); } // For bent wires from north to east, obstruct the connection between the wire and the @@ -477,21 +454,29 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons { if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) { - wiring_reduction_lyt.obstruct_connection(new_coord, - {new_coord.x + 1, new_coord.y + 1, new_coord.z}); - // special case: - // →= - // ↓ - // =→ - // - // -> Only one wire can be deleted - if (lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}) && - lyt.is_wire(lyt.get_node({old_coord.x, old_coord.y - 1, old_coord.z}))) { - wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y - 1, 0}); - wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y - 1, 1}); + wiring_reduction_lyt.obstruct_connection(new_coord, + {new_coord.x + 1, new_coord.y + 1, new_coord.z}); + + // Special cases: + // →= + // ↓ + // ... + // ↓ + // =→ + uint64_t i = 1; + while (is_single_wire(0, i)) + { + if (lyt.has_western_incoming_signal({old_coord.x, old_coord.y - i, old_coord.z})) + { + obstruct_coordinate(0, i); + break; + } + ++i; + } } } + else { wiring_reduction_lyt.obstruct_connection({new_coord.x - 1, new_coord.y - 1, new_coord.z}, @@ -512,17 +497,20 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons { wiring_reduction_lyt.obstruct_connection(new_coord, {new_coord.x + 1, new_coord.y + 1, new_coord.z}); - // special case: + + uint64_t i = 1; + // Special cases: // ↓ - // =→= - // ↓ - // - // -> Only one wire can be deleted - if (lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.is_wire(lyt.get_node({old_coord.x - 1, old_coord.y, old_coord.z}))) + // =→...→= + // ↓ + while (is_single_wire(i, 0)) { - wiring_reduction_lyt.obstruct_coordinate({new_coord.x - 1, new_coord.y, 0}); - wiring_reduction_lyt.obstruct_coordinate({new_coord.x - 1, new_coord.y, 1}); + if (lyt.has_northern_incoming_signal({old_coord.x - i, old_coord.y, old_coord.z})) + { + obstruct_coordinate(i, 0); + break; + } + ++i; } } } @@ -540,80 +528,75 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_connection(shifted_tile_a, new_coord); wiring_reduction_lyt.obstruct_connection(shifted_tile_b, new_coord); - wiring_reduction_lyt.obstruct_coordinate(new_coord); - wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y, 1}); + obstruct_coordinate(0, 0); + } - // special case: + if (const auto signals = lyt.incoming_data_flow(old_coord); (old_coord.z == 1) || (signals.size() == 2)) + { + // Special cases (where the crossing can also be placed further to the left or top): // +→= // ↓ ↓ // =→& // - // -> No crossing between coordinate to the left and coordinate above the gate - if (lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z})) - { - if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) - { - wiring_reduction_lyt.obstruct_connection({new_coord.x - 1, new_coord.y, new_coord.z}, - {new_coord.x, new_coord.y - 1, new_coord.z}); - } - else - { - wiring_reduction_lyt.obstruct_connection({new_coord.x, new_coord.y - 1, new_coord.z}, - {new_coord.x - 1, new_coord.y, new_coord.z}); - } - } - // special case: + // Or: + // // +→= // ↓ ↓ - // = = - // ↓ ↓ - // =→& - // - // -> No crossing between coordinate to the left and coordinate above the gate - if (lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.has_northern_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}) && - lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && - lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 2, old_coord.z}) && - lyt.is_wire_tile({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.is_wire_tile({old_coord.x, old_coord.y - 1, old_coord.z}) && - lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && - lyt.is_wire_tile({old_coord.x, old_coord.y - 2, old_coord.z}) && - !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y, old_coord.z})) && - !lyt.is_fanout(lyt.get_node({old_coord.x, old_coord.y - 1, old_coord.z})) && - !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y - 1, old_coord.z})) && - !lyt.is_fanout(lyt.get_node({old_coord.x, old_coord.y - 2, old_coord.z}))) - + // =→+ + if (is_single_wire(1, 0) && is_single_wire(0, 1)) { - if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) + uint64_t i = 1; + bool obstruct = false; + + while (true) { - wiring_reduction_lyt.obstruct_coordinate({new_coord.x - 1, new_coord.y, 0}); - wiring_reduction_lyt.obstruct_coordinate({new_coord.x - 1, new_coord.y, 1}); + if (is_crossing(1, 1)) + { + obstruct = true; + break; + } + if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) + { + if (!is_single_wire(1, i) || !is_single_wire(0, i + 1) || + !lyt.has_northern_incoming_signal({old_coord.x - 1, old_coord.y - i + 1, 0}) || + !lyt.has_northern_incoming_signal({old_coord.x, old_coord.y - i, 0})) + { + break; + } + if (is_crossing(1, i + 1)) + { + obstruct = true; + break; + } + ++i; + } + else + { + if (!is_single_wire(i, 1) || !is_single_wire(i + 1, 0) || + !lyt.has_western_incoming_signal({old_coord.x - i, old_coord.y, 0}) || + !lyt.has_western_incoming_signal({old_coord.x - i + 1, old_coord.y - i, 0})) + { + break; + } + if (is_crossing(i + 1, 1)) + { + obstruct = true; + break; + } + ++i; + } } - } - // special case: - // +→=→= - // ↓ ↓ - // =→=→& - // - // -> No crossing between coordinate to the left and coordinate above the gate - if (lyt.has_western_incoming_signal({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.has_western_incoming_signal({old_coord.x, old_coord.y - 1, old_coord.z}) && - lyt.has_western_incoming_signal({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && - lyt.has_northern_incoming_signal({old_coord.x - 2, old_coord.y, old_coord.z}) && - lyt.is_wire_tile({old_coord.x - 1, old_coord.y, old_coord.z}) && - lyt.is_wire_tile({old_coord.x, old_coord.y - 1, old_coord.z}) && - lyt.is_wire_tile({old_coord.x - 1, old_coord.y - 1, old_coord.z}) && - lyt.is_wire_tile({old_coord.x - 2, old_coord.y, old_coord.z}) && - !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y, old_coord.z})) && - !lyt.is_fanout(lyt.get_node({old_coord.x, old_coord.y - 1, old_coord.z})) && - !lyt.is_fanout(lyt.get_node({old_coord.x - 1, old_coord.y - 1, old_coord.z})) && - !lyt.is_fanout(lyt.get_node({old_coord.x - 2, old_coord.y, old_coord.z}))) - { - if (wiring_reduction_lyt.get_search_direction() == search_direction::VERTICAL) + + if (obstruct) { - wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y - 1, 0}); - wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y - 1, 1}); + if (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) + { + obstruct_coordinate(1, 0); + } + else + { + obstruct_coordinate(0, 1); + } } } } @@ -958,7 +941,7 @@ void adjust_tile(Lyt& lyt, const LytCpy& layout_copy, const WiringReductionLyt& std::vector> signals{}; signals.reserve(layout_copy.fanin_size(layout_copy.get_node(old_coord))); - // Iterate through fanin and create signals for the new coordinates + // Iterate through fanins and create signals for the new coordinates layout_copy.foreach_fanin( layout_copy.get_node(old_coord), [&lyt, &signals, &offset, &old_coord, &layout_copy, &offset_mtrx, &wiring_reduction_lyt](const auto& fi) @@ -979,13 +962,15 @@ void adjust_tile(Lyt& lyt, const LytCpy& layout_copy, const WiringReductionLyt& if (lyt.is_po(lyt.get_node(old_coord))) { if ((wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL) && - !lyt.is_empty_tile({new_coord.x + 1, new_coord.y, new_coord.z})) + !lyt.is_empty_tile({new_coord.x + 1, new_coord.y, new_coord.z}) && + lyt.has_western_incoming_signal({new_coord.x + 1, new_coord.y, new_coord.z})) { lyt.move_node(lyt.get_node({new_coord.x + 1, new_coord.y, new_coord.z}), {new_coord.x + 1, new_coord.y, new_coord.z}, {}); } if ((wiring_reduction_lyt.get_search_direction() == search_direction::VERTICAL) && - !lyt.is_empty_tile({new_coord.x, new_coord.y + 1, new_coord.z})) + !lyt.is_empty_tile({new_coord.x, new_coord.y + 1, new_coord.z}) && + lyt.has_northern_incoming_signal({new_coord.x, new_coord.y + 1, new_coord.z})) { lyt.move_node(lyt.get_node({new_coord.x, new_coord.y + 1, new_coord.z}), {new_coord.x, new_coord.y + 1, new_coord.z}, {}); From 25a7baff10af756b438edc28a9939c2403855683 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:37:09 +0200 Subject: [PATCH 09/23] Update post_layout_optimization.hpp --- .../algorithms/physical_design/post_layout_optimization.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 29f887edd..5c357ac6b 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -883,7 +883,7 @@ class post_layout_optimization_impl tile max_non_po{0, 0}; // Determine minimal border for POs - for (auto gate_tile : gate_tiles) + for (const auto& gate_tile : gate_tiles) { if (!layout.is_po_tile(gate_tile)) { From 4cbd5e91e88c441ef0b30996b954c1d9c2131391 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:28:44 +0200 Subject: [PATCH 10/23] Update test_post_layout_optimization.py --- .../physical_design/test_post_layout_optimization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py index 055cac44b..9eba535a6 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py @@ -44,9 +44,9 @@ def test_post_layout_optimization_with_stats(self): self.assertGreater(stats.time_total.total_seconds(), 0) self.assertEqual(stats.x_size_before, 6) self.assertEqual(stats.y_size_before, 8) - self.assertEqual(stats.x_size_after, 6) - self.assertEqual(stats.y_size_after, 4) - self.assertEqual(stats.area_improvement, 50.0) + self.assertEqual(stats.x_size_after, 5) + self.assertEqual(stats.y_size_after, 5) + self.assertEqual(stats.area_improvement, 47.5) def test_post_layout_optimization_with_stats_and_parameters(self): network = read_technology_network(dir_path + "/../../resources/mux21.v") From 7656af94e0f464ee440f1a631d4d30e44807039c Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:29:50 +0200 Subject: [PATCH 11/23] Update test_post_layout_optimization.py --- .../algorithms/physical_design/test_post_layout_optimization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py index 9eba535a6..7a45a4676 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py @@ -46,7 +46,7 @@ def test_post_layout_optimization_with_stats(self): self.assertEqual(stats.y_size_before, 8) self.assertEqual(stats.x_size_after, 5) self.assertEqual(stats.y_size_after, 5) - self.assertEqual(stats.area_improvement, 47.5) + self.assertEqual(stats.area_improvement, 47.48) def test_post_layout_optimization_with_stats_and_parameters(self): network = read_technology_network(dir_path + "/../../resources/mux21.v") From fe55e04d392aeec882eecbf450fcdcf534ae6eb8 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:25:30 +0200 Subject: [PATCH 12/23] Update test_post_layout_optimization.py --- .../algorithms/physical_design/test_post_layout_optimization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py index 7a45a4676..e73481b24 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py @@ -46,7 +46,7 @@ def test_post_layout_optimization_with_stats(self): self.assertEqual(stats.y_size_before, 8) self.assertEqual(stats.x_size_after, 5) self.assertEqual(stats.y_size_after, 5) - self.assertEqual(stats.area_improvement, 47.48) + self.assertEqual(stats.area_improvement, 47.92) def test_post_layout_optimization_with_stats_and_parameters(self): network = read_technology_network(dir_path + "/../../resources/mux21.v") From d4328a1227843a5b60e90b19dda916f70da86892 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:26:33 +0200 Subject: [PATCH 13/23] Update post_layout_optimization.hpp --- .../post_layout_optimization.hpp | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 5c357ac6b..313f49742 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -798,6 +798,34 @@ void optimize_output_positions(Lyt& lyt) noexcept {lyt.make_signal(lyt.get_node({lyt.x() - 1, y}))}); } } + + // update bounding box + bounding_box.update_bounding_box(); + lyt.resize({bounding_box.get_max().x, bounding_box.get_max().y, lyt.z()}); + + // Check if PO is located in bottom right corner and relocation would save more tiles (only possible for layouts with a single PO) + if (lyt.is_po_tile({lyt.x(), lyt.y(), 0}) && (lyt.num_pos() == 1)) + { + if (lyt.has_western_incoming_signal({lyt.x(), lyt.y(), 0}) && ((lyt.x() * (lyt.y() + 2)) < ((lyt.x() + 1) * (lyt.y() + 1)))) + { + std::vector> signals{}; + signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), lyt.y()}))); + lyt.foreach_fanin(lyt.get_node({lyt.x(), lyt.y()}), + [&signals](const auto& fanin) { signals.push_back(fanin); }); + lyt.resize({lyt.x(), lyt.y() + 1, lyt.z()}); + lyt.move_node(lyt.get_node({lyt.x(), lyt.y() - 1}), {lyt.x() - 1, lyt.y(), 0}, signals); + } + else if (lyt.has_northern_incoming_signal({lyt.x(), lyt.y(), 0}) && + (((lyt.x() + 2) * lyt.y()) < ((lyt.x() + 1) * (lyt.y() + 1)))) + { + std::vector> signals{}; + signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), lyt.y()}))); + lyt.foreach_fanin(lyt.get_node({lyt.x(), lyt.y()}), + [&signals](const auto& fanin) { signals.push_back(fanin); }); + lyt.resize({lyt.x() + 1, lyt.y(), lyt.z()}); + lyt.move_node(lyt.get_node({lyt.x() - 1, lyt.y()}), {lyt.x(), lyt.y() - 1, 0}, signals); + } + } } /** * Custom comparison function for sorting tiles based on the sum of their coordinates that breaks ties based on the @@ -883,7 +911,7 @@ class post_layout_optimization_impl tile max_non_po{0, 0}; // Determine minimal border for POs - for (const auto& gate_tile : gate_tiles) + for (auto gate_tile : gate_tiles) { if (!layout.is_po_tile(gate_tile)) { From ea98d0e0b9e3c31dc1415499023d7dd8d2666eb9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 14:26:45 +0000 Subject: [PATCH 14/23] =?UTF-8?q?=F0=9F=8E=A8=20Incorporated=20pre-commit?= =?UTF-8?q?=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithms/physical_design/post_layout_optimization.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 313f49742..365ddc653 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -803,10 +803,12 @@ void optimize_output_positions(Lyt& lyt) noexcept bounding_box.update_bounding_box(); lyt.resize({bounding_box.get_max().x, bounding_box.get_max().y, lyt.z()}); - // Check if PO is located in bottom right corner and relocation would save more tiles (only possible for layouts with a single PO) + // Check if PO is located in bottom right corner and relocation would save more tiles (only possible for layouts + // with a single PO) if (lyt.is_po_tile({lyt.x(), lyt.y(), 0}) && (lyt.num_pos() == 1)) { - if (lyt.has_western_incoming_signal({lyt.x(), lyt.y(), 0}) && ((lyt.x() * (lyt.y() + 2)) < ((lyt.x() + 1) * (lyt.y() + 1)))) + if (lyt.has_western_incoming_signal({lyt.x(), lyt.y(), 0}) && + ((lyt.x() * (lyt.y() + 2)) < ((lyt.x() + 1) * (lyt.y() + 1)))) { std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), lyt.y()}))); From 772c3c719cd08699d855d8a77fcc13a989011ce5 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 16:30:36 +0200 Subject: [PATCH 15/23] Update test_post_layout_optimization.py --- .../physical_design/test_post_layout_optimization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py index e73481b24..055cac44b 100644 --- a/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py +++ b/bindings/pyfiction/test/algorithms/physical_design/test_post_layout_optimization.py @@ -44,9 +44,9 @@ def test_post_layout_optimization_with_stats(self): self.assertGreater(stats.time_total.total_seconds(), 0) self.assertEqual(stats.x_size_before, 6) self.assertEqual(stats.y_size_before, 8) - self.assertEqual(stats.x_size_after, 5) - self.assertEqual(stats.y_size_after, 5) - self.assertEqual(stats.area_improvement, 47.92) + self.assertEqual(stats.x_size_after, 6) + self.assertEqual(stats.y_size_after, 4) + self.assertEqual(stats.area_improvement, 50.0) def test_post_layout_optimization_with_stats_and_parameters(self): network = read_technology_network(dir_path + "/../../resources/mux21.v") From 80db7e1c045c57c2b041ca11a25e56bfd2109dea Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:38:09 +0200 Subject: [PATCH 16/23] Update post_layout_optimization.hpp --- .../algorithms/physical_design/post_layout_optimization.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 365ddc653..5102474ec 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -636,7 +636,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& } } - if (moved_gate || ((num_gate_relocations >= max_gate_relocations) & !lyt.is_po_tile(current_pos))) + if (moved_gate || ((num_gate_relocations >= max_gate_relocations) && !lyt.is_po_tile(current_pos))) { break; } From 3861ed9cb72acc504dc449866cd5b273f94e64e9 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:50:25 +0200 Subject: [PATCH 17/23] Update wiring_reduction.hpp --- .../physical_design/wiring_reduction.hpp | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/include/fiction/algorithms/physical_design/wiring_reduction.hpp b/include/fiction/algorithms/physical_design/wiring_reduction.hpp index b7fb3cf96..a2fbb76cc 100644 --- a/include/fiction/algorithms/physical_design/wiring_reduction.hpp +++ b/include/fiction/algorithms/physical_design/wiring_reduction.hpp @@ -403,7 +403,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons // crossing: // // = - auto is_single_wire = [&lyt, &old_coord](uint64_t x_offset, uint64_t y_offset) + auto is_single_wire = [&lyt, &old_coord](const uint64_t x_offset, const uint64_t y_offset) { return lyt.is_wire_tile({old_coord.x - x_offset, old_coord.y - y_offset, 0}) && !lyt.is_fanout(lyt.get_node({old_coord.x - x_offset, old_coord.y - y_offset, 0}) && @@ -415,14 +415,15 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons // +→= // ↓ // = - auto is_crossing = [&lyt, &old_coord](uint64_t x_offset, uint64_t y_offset) + auto is_crossing = [&lyt, &old_coord](const uint64_t x_offset, const uint64_t y_offset) { return lyt.has_northern_incoming_signal({old_coord.x - x_offset, old_coord.y - y_offset + 1, 0}) && lyt.has_western_incoming_signal({old_coord.x - x_offset + 1, old_coord.y - y_offset, 0}); }; // Utility function to fully obstruct a coordinate - auto obstruct_coordinate = [&wiring_reduction_lyt, &new_coord](uint64_t x_offset, uint64_t y_offset) + auto obstruct_coordinate = + [&wiring_reduction_lyt, &new_coord](const uint64_t x_offset, const uint64_t y_offset) { wiring_reduction_lyt.obstruct_coordinate({new_coord.x - x_offset, new_coord.y - y_offset, 0}); wiring_reduction_lyt.obstruct_coordinate({new_coord.x - x_offset, new_coord.y - y_offset, 1}); @@ -464,15 +465,13 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons // ... // ↓ // =→ - uint64_t i = 1; - while (is_single_wire(0, i)) + for (uint64_t i = 1; is_single_wire(0, i); ++i) { if (lyt.has_western_incoming_signal({old_coord.x, old_coord.y - i, old_coord.z})) { obstruct_coordinate(0, i); break; } - ++i; } } } @@ -498,19 +497,17 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_connection(new_coord, {new_coord.x + 1, new_coord.y + 1, new_coord.z}); - uint64_t i = 1; // Special cases: // ↓ // =→...→= // ↓ - while (is_single_wire(i, 0)) + for (uint64_t i = 1; is_single_wire(i, 0); ++i) { if (lyt.has_northern_incoming_signal({old_coord.x - i, old_coord.y, old_coord.z})) { obstruct_coordinate(i, 0); break; } - ++i; } } } @@ -545,10 +542,9 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons // =→+ if (is_single_wire(1, 0) && is_single_wire(0, 1)) { - uint64_t i = 1; - bool obstruct = false; + bool obstruct = false; - while (true) + for (uint64_t i = 1; true; ++i) { if (is_crossing(1, 1)) { @@ -568,7 +564,6 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons obstruct = true; break; } - ++i; } else { @@ -583,7 +578,6 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons obstruct = true; break; } - ++i; } } From 92f08543d4b183cec5fac615dc3ede14b77c77f1 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:50:43 +0200 Subject: [PATCH 18/23] Update post_layout_optimization.hpp --- .../post_layout_optimization.hpp | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 5102474ec..6f6508324 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -636,7 +636,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& } } - if (moved_gate || ((num_gate_relocations >= max_gate_relocations) && !lyt.is_po_tile(current_pos))) + if (moved_gate || ((num_gate_relocations >= max_gate_relocations) & !lyt.is_po_tile(current_pos))) { break; } @@ -767,33 +767,47 @@ void optimize_output_positions(Lyt& lyt) noexcept auto bounding_box = bounding_box_2d(lyt); lyt.resize({bounding_box.get_max().x, bounding_box.get_max().y, lyt.z()}); - // Check for misplaced POs in second last row and move them down one row + // Check for misplaced POs in second last row and move them one row down for (uint64_t x = 0; x < lyt.x(); ++x) { if (lyt.is_po_tile({x, lyt.y() - 1, 0})) { + // Get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({x, lyt.y()}))); lyt.foreach_fanin(lyt.get_node({x, lyt.y() - 1}), [&signals](const auto& fanin) { signals.push_back(fanin); }); + + // Move PO one row down lyt.move_node(lyt.get_node({x, lyt.y() - 1}), {x, lyt.y(), 0}, {}); + + // Create a wire segment at the previous location of the PO and connect it with its fanin lyt.create_buf(signals[0], {x, lyt.y() - 1}); + + // Connect the PO with the new wire segment lyt.move_node(lyt.get_node({x, lyt.y()}), {x, lyt.y(), 0}, {lyt.make_signal(lyt.get_node({x, lyt.y() - 1}))}); } } - // Check for misplaced POs in second last column and move them to the right one column + // Check for misplaced POs in second last column and move them one column to the right for (uint64_t y = 0; y < lyt.y(); ++y) { if (lyt.is_po_tile({lyt.x() - 1, y, 0})) { + // Get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), y}))); lyt.foreach_fanin(lyt.get_node({lyt.x() - 1, y}), [&signals](const auto& fanin) { signals.push_back(fanin); }); + + // Move PO one column to the right lyt.move_node(lyt.get_node({lyt.x() - 1, y}), {lyt.x(), y, 0}, {}); + + // Create a wire segment at the previous location of the PO and connect it with its fanin lyt.create_buf(signals[0], {lyt.x() - 1, y}); + + // Connect the PO with the new wire segment lyt.move_node(lyt.get_node({lyt.x(), y}), {lyt.x(), y, 0}, {lyt.make_signal(lyt.get_node({lyt.x() - 1, y}))}); } @@ -807,24 +821,36 @@ void optimize_output_positions(Lyt& lyt) noexcept // with a single PO) if (lyt.is_po_tile({lyt.x(), lyt.y(), 0}) && (lyt.num_pos() == 1)) { + // Check if relocation would save tiles if (lyt.has_western_incoming_signal({lyt.x(), lyt.y(), 0}) && ((lyt.x() * (lyt.y() + 2)) < ((lyt.x() + 1) * (lyt.y() + 1)))) { + // Get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), lyt.y()}))); lyt.foreach_fanin(lyt.get_node({lyt.x(), lyt.y()}), [&signals](const auto& fanin) { signals.push_back(fanin); }); + + // Resize layout lyt.resize({lyt.x(), lyt.y() + 1, lyt.z()}); + + // Move PO one tile down and to the left lyt.move_node(lyt.get_node({lyt.x(), lyt.y() - 1}), {lyt.x() - 1, lyt.y(), 0}, signals); } + // Check if relocation would save tiles else if (lyt.has_northern_incoming_signal({lyt.x(), lyt.y(), 0}) && (((lyt.x() + 2) * lyt.y()) < ((lyt.x() + 1) * (lyt.y() + 1)))) { + // Get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), lyt.y()}))); lyt.foreach_fanin(lyt.get_node({lyt.x(), lyt.y()}), [&signals](const auto& fanin) { signals.push_back(fanin); }); + + // Resize layout lyt.resize({lyt.x() + 1, lyt.y(), lyt.z()}); + + // Move PO one tile up and to the right lyt.move_node(lyt.get_node({lyt.x() - 1, lyt.y()}), {lyt.x(), lyt.y() - 1, 0}, signals); } } @@ -913,7 +939,7 @@ class post_layout_optimization_impl tile max_non_po{0, 0}; // Determine minimal border for POs - for (auto gate_tile : gate_tiles) + for (const auto& gate_tile : gate_tiles) { if (!layout.is_po_tile(gate_tile)) { From d650614d384606d27ef26abfa3a8ed7640c85e4c Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:53:29 +0200 Subject: [PATCH 19/23] Update post_layout_optimization.hpp --- .../algorithms/physical_design/post_layout_optimization.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index 6f6508324..f8611a546 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -636,7 +636,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& } } - if (moved_gate || ((num_gate_relocations >= max_gate_relocations) & !lyt.is_po_tile(current_pos))) + if (moved_gate || ((num_gate_relocations >= max_gate_relocations) && !lyt.is_po_tile(current_pos))) { break; } From b179a96b335a8f9e1058ee0e43ab30fee634f8d2 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:06:00 +0200 Subject: [PATCH 20/23] Update wiring_reduction.hpp --- .../physical_design/wiring_reduction.hpp | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/include/fiction/algorithms/physical_design/wiring_reduction.hpp b/include/fiction/algorithms/physical_design/wiring_reduction.hpp index a2fbb76cc..55789779f 100644 --- a/include/fiction/algorithms/physical_design/wiring_reduction.hpp +++ b/include/fiction/algorithms/physical_design/wiring_reduction.hpp @@ -373,33 +373,33 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons static_assert(is_gate_level_layout_v, "Lyt is not a gate-level layout"); static_assert(is_cartesian_layout_v, "Lyt is not a Cartesian layout"); - // Create a wiring_reduction_layout with specified offsets + // create a wiring_reduction_layout with specified offsets wiring_reduction_layout> obs_wiring_reduction_layout{ {lyt.x() + x_offset + 1, lyt.y() + y_offset + 1, lyt.z()}, direction}; auto wiring_reduction_lyt = wiring_reduction_layout_type>(obs_wiring_reduction_layout); - // Iterate through nodes in the layout + // iterate through nodes in the layout lyt.foreach_node( [&lyt, &wiring_reduction_lyt, &x_offset, &y_offset](const auto& node) { const tile old_coord = lyt.get_tile(node); const tile new_coord{old_coord.x + x_offset, old_coord.y + y_offset, old_coord.z}; - // Skip if the tile is empty + // skip if the tile is empty if (lyt.is_empty_tile(old_coord)) { return; } - // Handle Primary Inputs (PI) and Primary Outputs (PO) + // handle Primary Inputs (PI) and Primary Outputs (PO) if (lyt.is_pi(node) || lyt.is_po(node)) { wiring_reduction_lyt.obstruct_coordinate(new_coord); wiring_reduction_lyt.obstruct_coordinate({new_coord.x, new_coord.y, 1}); } - // Utility function to check if a tile hosts a single wire only, which is not a fanout or hosts a + // utility function to check if a tile hosts a single wire only, which is not a fanout or hosts a // crossing: // // = @@ -410,7 +410,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons lyt.is_empty_tile({old_coord.x - x_offset, old_coord.y - y_offset, 1})); }; - // Utility function to check for crossings with outgoing wires to the bottom layer: + // utility function to check for crossings with outgoing wires to the bottom layer: // // +→= // ↓ @@ -421,7 +421,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons lyt.has_western_incoming_signal({old_coord.x - x_offset + 1, old_coord.y - y_offset, 0}); }; - // Utility function to fully obstruct a coordinate + // utility function to fully obstruct a coordinate auto obstruct_coordinate = [&wiring_reduction_lyt, &new_coord](const uint64_t x_offset, const uint64_t y_offset) { @@ -429,17 +429,17 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_coordinate({new_coord.x - x_offset, new_coord.y - y_offset, 1}); }; - // Handle single input gates and wires + // handle single input gates and wires if (const auto signals = lyt.incoming_data_flow(old_coord); signals.size() == 1) { const auto incoming_signal = signals[0]; const tile shifted_tile{incoming_signal.x + x_offset, incoming_signal.y + y_offset, incoming_signal.z}; - // Obstruct the connection between the gate and its incoming signal + // obstruct the connection between the gate and its incoming signal wiring_reduction_lyt.obstruct_connection(shifted_tile, new_coord); - // Obstruct horizontal/vertical wires, non-wire gates (inv) and fanouts + // obstruct horizontal/vertical wires, non-wire gates (inv) and fanouts if (!lyt.is_wire(node) || (lyt.fanout_size(node) != 1) || (old_coord.z != 0) || (lyt.has_western_incoming_signal({old_coord}) && lyt.has_eastern_outgoing_signal({old_coord}) && (wiring_reduction_lyt.get_search_direction() == search_direction::HORIZONTAL)) || @@ -449,7 +449,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons obstruct_coordinate(0, 0); } - // For bent wires from north to east, obstruct the connection between the wire and the + // for bent wires from north to east, obstruct the connection between the wire and the // coordinate to the bottom right/ top left else if (lyt.has_northern_incoming_signal({old_coord}) && lyt.has_eastern_outgoing_signal({old_coord})) { @@ -459,7 +459,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_connection(new_coord, {new_coord.x + 1, new_coord.y + 1, new_coord.z}); - // Special cases: + // special cases: // →= // ↓ // ... @@ -483,7 +483,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons } } - // For bent wires from west to south, obstruct the connection between the wire and the + // for bent wires from west to south, obstruct the connection between the wire and the // coordinate to the top left/ bottom right else if (lyt.has_western_incoming_signal({old_coord}) && lyt.has_southern_outgoing_signal({old_coord})) { @@ -497,7 +497,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons wiring_reduction_lyt.obstruct_connection(new_coord, {new_coord.x + 1, new_coord.y + 1, new_coord.z}); - // Special cases: + // special cases: // ↓ // =→...→= // ↓ @@ -513,7 +513,7 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons } } - // Handle double input gates (AND, OR, ...) + // handle double input gates (AND, OR, ...) else if (signals.size() == 2) { const auto signal_a = signals[0]; @@ -530,12 +530,12 @@ create_wiring_reduction_layout(const Lyt& lyt, const uint64_t x_offset = 0, cons if (const auto signals = lyt.incoming_data_flow(old_coord); (old_coord.z == 1) || (signals.size() == 2)) { - // Special cases (where the crossing can also be placed further to the left or top): + // special cases (where the crossing can also be placed further to the left or top): // +→= // ↓ ↓ // =→& // - // Or: + // or: // // +→= // ↓ ↓ @@ -613,14 +613,14 @@ void add_obstructions(WiringReductionLyt& lyt) noexcept { if (lyt.get_search_direction() == search_direction::HORIZONTAL) { - // Add obstructions to the top edge of the layout + // add obstructions to the top edge of the layout for (uint64_t x = 1; x <= lyt.x(); x++) { lyt.obstruct_coordinate({x, 0, 0}); lyt.obstruct_coordinate({x, 0, 1}); } - // Add obstructions to the bottom edge of the layout + // add obstructions to the bottom edge of the layout for (uint64_t x = 0; x < lyt.x(); x++) { lyt.obstruct_coordinate({x, lyt.y(), 0}); @@ -629,14 +629,14 @@ void add_obstructions(WiringReductionLyt& lyt) noexcept } else { - // Add obstructions to the left edge of the layout + // add obstructions to the left edge of the layout for (uint64_t y = 1; y <= lyt.y(); y++) { lyt.obstruct_coordinate({0, y, 0}); lyt.obstruct_coordinate({0, y, 1}); } - // Add obstructions to the right edge of the layout + // add obstructions to the right edge of the layout for (uint64_t y = 0; y < lyt.y(); y++) { lyt.obstruct_coordinate({lyt.x(), y, 0}); @@ -685,17 +685,17 @@ void update_to_delete_list(WiringReductionLyt& lyt, const layout_coordinate_path { for (const auto& coord : possible_path) { - // Check if the coordinate is not at the leftmost or rightmost position + // check if the coordinate is not at the leftmost or rightmost position if (((lyt.get_search_direction() == search_direction::HORIZONTAL) && coord.x != 0 && coord.x != lyt.x()) || ((lyt.get_search_direction() == search_direction::VERTICAL) && coord.y != 0 && coord.y != lyt.y())) { - // Create the corresponding coordinate on the original layout + // create the corresponding coordinate on the original layout const fiction::coordinate shifted_coord{coord.x - 1, coord.y - 1, 0}; - // Append the corresponding coordinate to the to-delete list + // append the corresponding coordinate to the to-delete list to_delete.append(shifted_coord); - // Obstruct the coordinate in both layers + // obstruct the coordinate in both layers lyt.obstruct_coordinate({coord.x, coord.y, 0}); lyt.obstruct_coordinate({coord.x, coord.y, 1}); } @@ -724,10 +724,10 @@ template calculate_offset_matrix(const WiringReductionLyt& lyt, const layout_coordinate_path& to_delete) noexcept { - // Initialize matrix with zeros + // initialize matrix with zeros offset_matrix matrix(lyt.y() + 1, std::vector(lyt.x() + 1, 0)); - // Update matrix based on coordinates + // update matrix based on coordinates for (const auto& coord : to_delete) { const auto x = coord.x; @@ -809,7 +809,7 @@ void adjust_tile_horizontal_search_dir(Lyt& lyt, const LytCpy& layout_copy, tile { bool traversing_deleted_wires = false; - // Check if traversing through deleted wires + // check if traversing through deleted wires if (offset_mtrx[fanin.y + 1][fanin.x] != offset_mtrx[fanin.y][fanin.x]) { fanin = {fanin.x, fanin.y, 0}; @@ -818,7 +818,7 @@ void adjust_tile_horizontal_search_dir(Lyt& lyt, const LytCpy& layout_copy, tile uint64_t offset_offset = 0; - // If traversing through deleted wires, update the offset + // if traversing through deleted wires, update the offset if (traversing_deleted_wires) { for (uint64_t o = 0; o < offset; ++o) @@ -837,7 +837,7 @@ void adjust_tile_horizontal_search_dir(Lyt& lyt, const LytCpy& layout_copy, tile } } - // Create signals for the new coordinates + // create signals for the new coordinates signals.push_back(lyt.make_signal(lyt.get_node({fanin.x, fanin.y - offset + offset_offset, fanin.z}))); } } @@ -871,7 +871,7 @@ void adjust_tile_vertical_search_dir(Lyt& lyt, const LytCpy& layout_copy, tile old_coord = {x, y, z}; - // Check if the tile is not empty and has an offset + // check if the tile is not empty and has an offset if (!(lyt.is_empty_tile(old_coord)) && (offset != 0)) { const auto new_coord = determine_new_coord(wiring_reduction_lyt, x, y, z, offset); std::vector> signals{}; signals.reserve(layout_copy.fanin_size(layout_copy.get_node(old_coord))); - // Iterate through fanins and create signals for the new coordinates + // iterate through fanins and create signals for the new coordinates layout_copy.foreach_fanin( layout_copy.get_node(old_coord), [&lyt, &signals, &offset, &old_coord, &layout_copy, &offset_mtrx, &wiring_reduction_lyt](const auto& fi) @@ -970,7 +970,7 @@ void adjust_tile(Lyt& lyt, const LytCpy& layout_copy, const WiringReductionLyt& {new_coord.x, new_coord.y + 1, new_coord.z}, {}); } } - // Move the node to the new coordinates + // move the node to the new coordinates lyt.move_node(lyt.get_node(old_coord), new_coord, signals); } } @@ -995,16 +995,16 @@ void delete_wires(Lyt& lyt, WiringReductionLyt& wiring_reduction_layout, const auto off_mat = calculate_offset_matrix(wiring_reduction_layout, to_delete); - // Create a copy of the original layout for reference + // create a copy of the original layout for reference const auto layout_copy = lyt.clone(); - // Clear tiles based on the to-delete list + // clear tiles based on the to-delete list for (const auto& tile_to_delete : to_delete) { lyt.clear_tile(tile_to_delete); } - // Iterate over the layout to delete wires and adjust the layout + // iterate over the layout to delete wires and adjust the layout for (uint64_t k = 0; k < lyt.x() + lyt.y() + 1; ++k) { for (uint64_t x = 0; x < k + 1; ++x) @@ -1020,12 +1020,12 @@ void delete_wires(Lyt& lyt, WiringReductionLyt& wiring_reduction_layout, } } - // Calculate bounding box for optimized layout size + // calculate bounding box for optimized layout size const auto bounding_box = bounding_box_2d(lyt); const auto optimized_layout_width = bounding_box.get_x_size(); const auto optimized_layout_height = bounding_box.get_y_size(); - // Resize the layout to the optimized size + // resize the layout to the optimized size lyt.resize({optimized_layout_width, optimized_layout_height, lyt.z()}); } @@ -1053,10 +1053,10 @@ class wiring_reduction_impl bool found_wires = true; - // Perform wiring reduction iteratively until no further wires can be deleted + // perform wiring reduction iteratively until no further wires can be deleted while (found_wires) { - // Continue until no further wires can be deleted + // continue until no further wires can be deleted found_wires = false; for (const auto direction : {search_direction::HORIZONTAL, search_direction::VERTICAL}) @@ -1065,24 +1065,24 @@ class wiring_reduction_impl add_obstructions(wiring_reduction_lyt); to_delete = {}; - // Get the initial possible path + // get the initial possible path auto possible_path = get_path(wiring_reduction_lyt, {0, 0}, {wiring_reduction_lyt.x(), wiring_reduction_lyt.y()}); - // Iterate while there is a possible path + // iterate while there is a possible path while (!possible_path.empty()) { update_to_delete_list>>(wiring_reduction_lyt, possible_path, to_delete); - // Update possible_path for the next iteration + // update possible_path for the next iteration possible_path = get_path(wiring_reduction_lyt, {0, 0}, {wiring_reduction_lyt.x(), wiring_reduction_lyt.y()}); } if (!to_delete.empty()) { - // Calculate offset matrix and delete wires based on to-delete list + // calculate offset matrix and delete wires based on to-delete list delete_wires(layout, wiring_reduction_lyt, to_delete); found_wires = true; } @@ -1143,14 +1143,14 @@ void wiring_reduction(const Lyt& lyt, wiring_reduction_stats* pst = nullptr) noe static_assert(is_gate_level_layout_v, "Lyt is not a gate-level layout"); static_assert(is_cartesian_layout_v, "Lyt is not a Cartesian layout"); - // Check if the clocking scheme is 2DDWave + // check if the clocking scheme is 2DDWave if (!lyt.is_clocking_scheme(clock_name::TWODDWAVE)) { std::cout << "[e] the given layout has to be 2DDWave-clocked\n"; return; } - // Initialize stats for runtime measurement + // initialize stats for runtime measurement wiring_reduction_stats st{}; detail::wiring_reduction_impl p{lyt, st}; From b7b08be608c8d4443da64895f703947ab2e83a61 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:08:48 +0200 Subject: [PATCH 21/23] Update post_layout_optimization.hpp --- .../post_layout_optimization.hpp | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp index f8611a546..027186cf9 100644 --- a/include/fiction/algorithms/physical_design/post_layout_optimization.hpp +++ b/include/fiction/algorithms/physical_design/post_layout_optimization.hpp @@ -279,22 +279,22 @@ template if (fanins_set.find(fanin) == fanins_set.cend()) { - // Add fanin to the respective route + // add fanin to the respective route add_fanin_to_route(op, fanins_set.empty(), ffd); add_fanin_to_route(fanin, fanins_set.empty(), ffd); - // Continue until gate or primary input (PI) is found + // continue until gate or primary input (PI) is found while (lyt.is_wire_tile(fanin) && lyt.fanout_size(lyt.get_node(fanin)) == 1 && !lyt.is_pi_tile(fanin)) { ffd.to_clear.push_back(fanin); fanin = lyt.incoming_data_flow(fanin).front(); - // Add fanin to the respective route + // add fanin to the respective route add_fanin_to_route(fanin, fanins_set.empty(), ffd); } - // Set the respective fanin based on the route + // set the respective fanin based on the route if (fanins_set.empty()) { fanin1 = fanin; @@ -316,22 +316,22 @@ template if (fanouts_set.find(fanout) == fanouts_set.cend()) { - // Add fanout to the respective route + // add fanout to the respective route add_fanout_to_route(op, fanouts_set.empty(), ffd); add_fanout_to_route(fanout, fanouts_set.empty(), ffd); - // Continue until gate or primary output (PO) is found + // continue until gate or primary output (PO) is found while (lyt.is_wire_tile(fanout) && lyt.fanout_size(lyt.get_node(fanout)) != 0 && lyt.fanout_size(lyt.get_node(fanout)) != 2) { ffd.to_clear.push_back(fanout); fanout = lyt.outgoing_data_flow(fanout).front(); - // Add fanout to the respective route + // add fanout to the respective route add_fanout_to_route(fanout, fanouts_set.empty(), ffd); } - // Set the respective fanout based on the route + // set the respective fanout based on the route if (fanouts_set.empty()) { fanout1 = fanout; @@ -387,7 +387,7 @@ layout_coordinate_path get_path_and_obstruct(Lyt& lyt, const tile& sta layout_coordinate_path path = a_star>(lyt, {start, end}, dist(), cost(), params); - // Obstruct the tiles along the computed path. + // obstruct the tiles along the computed path. for (const auto& tile : path) { lyt.obstruct_coordinate(tile); @@ -540,7 +540,7 @@ bool improve_gate_location(Lyt& lyt, const tile& old_pos, const tile& // get paths for fanins and fanouts layout_coordinate_path new_path_from_fanin_1_to_gate, new_path_from_fanin_2_to_gate, new_path_from_gate_to_fanout_1, new_path_from_gate_to_fanout_2; - // Get paths for fanins and fanouts + // get paths for fanins and fanouts if (!fanins.empty()) { new_path_from_fanin_1_to_gate = get_path_and_obstruct(lyt, fanins[0], new_pos); @@ -767,47 +767,47 @@ void optimize_output_positions(Lyt& lyt) noexcept auto bounding_box = bounding_box_2d(lyt); lyt.resize({bounding_box.get_max().x, bounding_box.get_max().y, lyt.z()}); - // Check for misplaced POs in second last row and move them one row down + // check for misplaced POs in second last row and move them one row down for (uint64_t x = 0; x < lyt.x(); ++x) { if (lyt.is_po_tile({x, lyt.y() - 1, 0})) { - // Get fanin signal of the PO + // get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({x, lyt.y()}))); lyt.foreach_fanin(lyt.get_node({x, lyt.y() - 1}), [&signals](const auto& fanin) { signals.push_back(fanin); }); - // Move PO one row down + // move PO one row down lyt.move_node(lyt.get_node({x, lyt.y() - 1}), {x, lyt.y(), 0}, {}); - // Create a wire segment at the previous location of the PO and connect it with its fanin + // create a wire segment at the previous location of the PO and connect it with its fanin lyt.create_buf(signals[0], {x, lyt.y() - 1}); - // Connect the PO with the new wire segment + // connect the PO with the new wire segment lyt.move_node(lyt.get_node({x, lyt.y()}), {x, lyt.y(), 0}, {lyt.make_signal(lyt.get_node({x, lyt.y() - 1}))}); } } - // Check for misplaced POs in second last column and move them one column to the right + // check for misplaced POs in second last column and move them one column to the right for (uint64_t y = 0; y < lyt.y(); ++y) { if (lyt.is_po_tile({lyt.x() - 1, y, 0})) { - // Get fanin signal of the PO + // get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), y}))); lyt.foreach_fanin(lyt.get_node({lyt.x() - 1, y}), [&signals](const auto& fanin) { signals.push_back(fanin); }); - // Move PO one column to the right + // move PO one column to the right lyt.move_node(lyt.get_node({lyt.x() - 1, y}), {lyt.x(), y, 0}, {}); - // Create a wire segment at the previous location of the PO and connect it with its fanin + // create a wire segment at the previous location of the PO and connect it with its fanin lyt.create_buf(signals[0], {lyt.x() - 1, y}); - // Connect the PO with the new wire segment + // connect the PO with the new wire segment lyt.move_node(lyt.get_node({lyt.x(), y}), {lyt.x(), y, 0}, {lyt.make_signal(lyt.get_node({lyt.x() - 1, y}))}); } @@ -817,40 +817,40 @@ void optimize_output_positions(Lyt& lyt) noexcept bounding_box.update_bounding_box(); lyt.resize({bounding_box.get_max().x, bounding_box.get_max().y, lyt.z()}); - // Check if PO is located in bottom right corner and relocation would save more tiles (only possible for layouts + // check if PO is located in bottom right corner and relocation would save more tiles (only possible for layouts // with a single PO) if (lyt.is_po_tile({lyt.x(), lyt.y(), 0}) && (lyt.num_pos() == 1)) { - // Check if relocation would save tiles + // check if relocation would save tiles if (lyt.has_western_incoming_signal({lyt.x(), lyt.y(), 0}) && ((lyt.x() * (lyt.y() + 2)) < ((lyt.x() + 1) * (lyt.y() + 1)))) { - // Get fanin signal of the PO + // get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), lyt.y()}))); lyt.foreach_fanin(lyt.get_node({lyt.x(), lyt.y()}), [&signals](const auto& fanin) { signals.push_back(fanin); }); - // Resize layout + // resize layout lyt.resize({lyt.x(), lyt.y() + 1, lyt.z()}); - // Move PO one tile down and to the left + // move PO one tile down and to the left lyt.move_node(lyt.get_node({lyt.x(), lyt.y() - 1}), {lyt.x() - 1, lyt.y(), 0}, signals); } - // Check if relocation would save tiles + // check if relocation would save tiles else if (lyt.has_northern_incoming_signal({lyt.x(), lyt.y(), 0}) && (((lyt.x() + 2) * lyt.y()) < ((lyt.x() + 1) * (lyt.y() + 1)))) { - // Get fanin signal of the PO + // get fanin signal of the PO std::vector> signals{}; signals.reserve(lyt.fanin_size(lyt.get_node({lyt.x(), lyt.y()}))); lyt.foreach_fanin(lyt.get_node({lyt.x(), lyt.y()}), [&signals](const auto& fanin) { signals.push_back(fanin); }); - // Resize layout + // resize layout lyt.resize({lyt.x() + 1, lyt.y(), lyt.z()}); - // Move PO one tile up and to the right + // move PO one tile up and to the right lyt.move_node(lyt.get_node({lyt.x() - 1, lyt.y()}), {lyt.x(), lyt.y() - 1, 0}, signals); } } @@ -895,7 +895,7 @@ class post_layout_optimization_impl uint64_t max_gate_relocations = ps.max_gate_relocations.value_or((plyt.x() + 1) * (plyt.y() + 1)); - // Optimization + // optimization auto layout = obstruction_layout(plyt); bool moved_at_least_one_gate = true; bool reduced_wiring = true; @@ -938,7 +938,7 @@ class post_layout_optimization_impl std::sort(gate_tiles.begin(), gate_tiles.end(), detail::compare_gate_tiles); tile max_non_po{0, 0}; - // Determine minimal border for POs + // determine minimal border for POs for (const auto& gate_tile : gate_tiles) { if (!layout.is_po_tile(gate_tile)) @@ -1026,14 +1026,14 @@ void post_layout_optimization(const Lyt& lyt, post_layout_optimization_params ps static_assert(is_gate_level_layout_v, "Lyt is not a gate-level layout"); static_assert(is_cartesian_layout_v, "Lyt is not a Cartesian layout"); - // Check if the clocking scheme is 2DDWave + // check if the clocking scheme is 2DDWave if (!lyt.is_clocking_scheme(clock_name::TWODDWAVE)) { std::cout << "[e] the given layout has to be 2DDWave-clocked\n"; return; } - // Initialize stats for runtime measurement + // initialize stats for runtime measurement post_layout_optimization_stats st{}; detail::post_layout_optimization_impl p{lyt, ps, st}; From b6de22e1f6b99dd54c3dfb01c53294f47285c203 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:21:23 +0200 Subject: [PATCH 22/23] Update pyfiction-docstring-generator.yml --- .github/workflows/pyfiction-docstring-generator.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pyfiction-docstring-generator.yml b/.github/workflows/pyfiction-docstring-generator.yml index 16de5998f..bf6a099f9 100644 --- a/.github/workflows/pyfiction-docstring-generator.yml +++ b/.github/workflows/pyfiction-docstring-generator.yml @@ -5,6 +5,10 @@ on: paths: - '**/*.hpp' - '.github/workflows/pyfiction-docstring-generator.yml' + pull_request: + paths: + - '**/*.hpp' + - '.github/workflows/pyfiction-docstring-generator.yml' workflow_dispatch: jobs: From 5cf674b93af9a678f742fa826dbc0ee1974e2561 Mon Sep 17 00:00:00 2001 From: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:33:46 +0200 Subject: [PATCH 23/23] Update pyfiction-docstring-generator.yml --- .github/workflows/pyfiction-docstring-generator.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/pyfiction-docstring-generator.yml b/.github/workflows/pyfiction-docstring-generator.yml index bf6a099f9..16de5998f 100644 --- a/.github/workflows/pyfiction-docstring-generator.yml +++ b/.github/workflows/pyfiction-docstring-generator.yml @@ -5,10 +5,6 @@ on: paths: - '**/*.hpp' - '.github/workflows/pyfiction-docstring-generator.yml' - pull_request: - paths: - - '**/*.hpp' - - '.github/workflows/pyfiction-docstring-generator.yml' workflow_dispatch: jobs: