Skip to content

Commit

Permalink
✨ Flag for optimizing POs only (#461)
Browse files Browse the repository at this point in the history
* flag for updating POs only

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <[email protected]>

* style

* 🎨 Incorporated pre-commit fixes

* Update post_layout_optimization.hpp

---------

Signed-off-by: GitHub Actions <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 28, 2024
1 parent aa0c77d commit 1b52e73
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12654,6 +12654,8 @@ static const char *__doc_fiction_post_layout_optimization_params_max_gate_reloca
R"doc(Maximum number of relocations to try for each gate. Defaults to the
number of tiles in the given layout if not specified.)doc";

static const char *__doc_fiction_post_layout_optimization_params_optimize_pos_only = R"doc(Only optimize PO positions.)doc";

static const char *__doc_fiction_post_layout_optimization_stats =
R"doc(This struct stores statistics about the post-layout optimization
process.)doc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ struct post_layout_optimization_params
* specified.
*/
std::optional<uint64_t> max_gate_relocations = std::nullopt;
/**
* Only optimize PO positions.
*/
bool optimize_pos_only = false;
};

/**
Expand Down Expand Up @@ -795,8 +799,9 @@ class post_layout_optimization_impl
static_assert(is_cartesian_layout_v<Lyt>, "Lyt is not a Cartesian layout");

const mockturtle::stopwatch stop{pst.time_total};
pst.x_size_before = plyt.x() + 1;
pst.y_size_before = plyt.y() + 1;
pst.x_size_before = plyt.x() + 1;
pst.y_size_before = plyt.y() + 1;

uint64_t max_gate_relocations = ps.max_gate_relocations.value_or((plyt.x() + 1) * (plyt.y() + 1));

// Optimization
Expand All @@ -815,7 +820,7 @@ class post_layout_optimization_impl
{
reduced_wiring = false;
fiction::wiring_reduction_stats wiring_reduction_stats{};
if (moved_at_least_one_gate)
if (moved_at_least_one_gate && !ps.optimize_pos_only)
{
fiction::wiring_reduction(layout, &wiring_reduction_stats);
if ((wiring_reduction_stats.area_improvement != 0ull) ||
Expand Down Expand Up @@ -855,21 +860,24 @@ class post_layout_optimization_impl
moved_at_least_one_gate = false;
for (auto& gate_tile : gate_tiles)
{
if (detail::improve_gate_location(layout, gate_tile, max_non_po, max_gate_relocations))
if (!ps.optimize_pos_only || (ps.optimize_pos_only && layout.is_po_tile(gate_tile)))
{
moved_at_least_one_gate = true;
if (detail::improve_gate_location(layout, gate_tile, max_non_po, max_gate_relocations))
{
moved_at_least_one_gate = true;
}
}
}
// calculate bounding box
const auto bounding_box = bounding_box_2d(layout);
layout.resize({bounding_box.get_x_size(), bounding_box.get_y_size(), layout.z()});
layout.resize({bounding_box.get_max().x, bounding_box.get_max().y, layout.z()});
}
}
detail::optimize_output_positions(layout);

// calculate bounding box
const auto bounding_box = bounding_box_2d(layout);
layout.resize({bounding_box.get_x_size(), bounding_box.get_y_size(), layout.z()});
layout.resize({bounding_box.get_max().x, bounding_box.get_max().y, layout.z()});

pst.x_size_after = layout.x() + 1;
pst.y_size_after = layout.y() + 1;
Expand Down
14 changes: 14 additions & 0 deletions test/algorithms/physical_design/post_layout_optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ TEST_CASE("Layout equivalence", "[post_layout_optimization]")
check_eq(blueprints::mux21_network<technology_network>(), layout);
}
}

SECTION("Optimize POs only")
{
using gate_layout = gate_level_layout<clocked_layout<tile_based_layout<cartesian_layout<>>>>;

const auto layout = orthogonal<gate_layout>(blueprints::mux21_network<technology_network>(), {});

post_layout_optimization_stats stats{};
post_layout_optimization_params params{};
params.optimize_pos_only = true;
post_layout_optimization<gate_layout>(layout, params, &stats);

check_eq(blueprints::mux21_network<technology_network>(), layout);
}
}

TEST_CASE("Optimization steps", "[post_layout_optimization]")
Expand Down

0 comments on commit 1b52e73

Please sign in to comment.