Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Parameter to move inputs/outputs to top/bottom border after hexagonalization #692

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a44d83f
route pis to top border
simon1hofmann Mar 9, 2025
e70a9a6
:sparkles: Parameter to move PIs to first row after hexagonalization
simon1hofmann Mar 13, 2025
5ac940c
:memo: Update pyfiction docstrings
actions-user Mar 13, 2025
773e38e
:snake: Adapt python bindings
simon1hofmann Mar 13, 2025
f7e0a21
:memo: Update changelog
simon1hofmann Mar 13, 2025
67e2197
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 13, 2025
8161eb4
:snake: Typos in test names
simon1hofmann Mar 13, 2025
f42f87a
:rotating_light: Fix clang-tidy errors
simon1hofmann Mar 13, 2025
ec646f4
Merge branch 'main' into route_pis_to_top_border_after_hexagonalization
simon1hofmann Mar 13, 2025
abab6cd
:bug: Fixed gate creation
simon1hofmann Mar 13, 2025
563589a
:umbrella: Increase coverage
simon1hofmann Mar 13, 2025
48326e5
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 13, 2025
d39c8f3
:memo: Update pyfiction docstrings
actions-user Mar 13, 2025
49af8d0
:art: Error handling and more parameters
simon1hofmann Mar 14, 2025
e9f3371
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 14, 2025
2c41897
:memo: Update pyfiction docstrings
actions-user Mar 14, 2025
a9e987d
:snake: Python bindings
simon1hofmann Mar 14, 2025
1c6af41
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 14, 2025
e812e4a
:snake: Python bindings
simon1hofmann Mar 14, 2025
5c17d6c
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 14, 2025
b252cd3
Update bindings/mnt/pyfiction/test/algorithms/physical_design/test_he…
simon1hofmann Mar 14, 2025
6212a2c
Apply suggestions from code review
simon1hofmann Mar 17, 2025
97deef4
Merge branch 'main' into route_pis_to_top_border_after_hexagonalization
simon1hofmann Mar 17, 2025
6a416e4
:memo: Update pyfiction docstrings
actions-user Mar 17, 2025
08746b9
:memo: Update docstrings
simon1hofmann Mar 17, 2025
3b52a41
:memo: Update pyfiction docstrings
actions-user Mar 17, 2025
c0986a6
:art: Use enum instead of boolean flags
simon1hofmann Mar 17, 2025
06c8a78
:memo: Update pyfiction docstrings
actions-user Mar 17, 2025
eb41efd
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 17, 2025
1b7c2cc
:snake: Update bindings
simon1hofmann Mar 17, 2025
e288188
:rotating_light: Fixed compiler warnings
simon1hofmann Mar 17, 2025
59a88d6
:sparkles: Option to extend POs to bottom row
simon1hofmann Mar 19, 2025
cf5f90f
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 19, 2025
2028cc1
:memo: Update pyfiction docstrings
actions-user Mar 19, 2025
2a5e4d0
:snake: Update bindings
simon1hofmann Mar 19, 2025
7793e0d
Update changelog.rst
simon1hofmann Mar 20, 2025
fd154f0
:art: Changed hex cli options to flags
simon1hofmann Mar 20, 2025
5aede98
Merge remote-tracking branch 'origin/route_pis_to_top_border_after_he…
simon1hofmann Mar 20, 2025
ee80535
Merge branch 'main' into route_pis_to_top_border_after_hexagonalization
simon1hofmann Mar 21, 2025
725a684
:art: Fixed some minor inconsistencies
marcelwa Mar 22, 2025
dd6967e
Apply suggestions from code review
simon1hofmann Mar 23, 2025
cdf8ec6
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 23, 2025
9516419
Merge branch 'main' into route_pis_to_top_border_after_hexagonalization
simon1hofmann Mar 23, 2025
3a1f6f7
:art: Code review
Mar 23, 2025
27f9490
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 23, 2025
566f45f
:memo: Update pyfiction docstrings
actions-user Mar 23, 2025
009b04d
:snake: Python tests
Mar 23, 2025
fd98d0f
:snake: Fix bindings
Mar 23, 2025
9a1ee10
🎨 Incorporated pre-commit fixes
pre-commit-ci[bot] Mar 23, 2025
fea066b
:art: Code review
simon1hofmann Mar 25, 2025
5a15354
:memo: Update pyfiction docstrings
actions-user Mar 25, 2025
324eaa2
Merge branch 'main' into route_pis_to_top_border_after_hexagonalization
simon1hofmann Mar 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bindings/mnt/pyfiction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
hexagonal_layout,
hexagonal_obstruction_layout,
hexagonalization,
hexagonalization_io_pin_extension_mode,
hexagonalization_io_pin_routing_error,
hexagonalization_params,
hexagonalization_stats,
high_degree_fanin_exception,
inml_layout,
inml_technology,
Expand Down Expand Up @@ -488,6 +492,10 @@
"hexagonal_layout",
"hexagonal_obstruction_layout",
"hexagonalization",
"hexagonalization_io_pin_extension_mode",
"hexagonalization_io_pin_routing_error",
"hexagonalization_params",
"hexagonalization_stats",
"high_degree_fanin_exception",
"inml_layout",
"inml_technology",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,46 @@
namespace pyfiction
{

namespace detail
{

template <typename Lyt>
void hexagonalization(pybind11::module& m)
inline void hexagonalization(pybind11::module& m)
{
namespace py = pybind11;

m.def(
"hexagonalization", [](const Lyt& lyt) -> py_hexagonal_gate_layout
{ return fiction::hexagonalization<py_hexagonal_gate_layout, Lyt>(lyt); }, py::arg("layout"),
DOC(fiction_hexagonalization));
}

} // namespace detail

inline void hexagonalization(pybind11::module& m)
{
detail::hexagonalization<py_cartesian_gate_layout>(m);
py::register_exception<fiction::hexagonalization_io_pin_routing_error>(m, "hexagonalization_io_pin_routing_error",
PyExc_RuntimeError);

py::enum_<fiction::hexagonalization_params::io_pin_extension_mode>(
m, "hexagonalization_io_pin_extension_mode", DOC(fiction_hexagonalization_params_io_pin_extension_mode))
.value("NONE", fiction::hexagonalization_params::io_pin_extension_mode::NONE,
DOC(fiction_hexagonalization_params_io_pin_extension_mode_NONE))
.value("EXTEND", fiction::hexagonalization_params::io_pin_extension_mode::EXTEND,
DOC(fiction_hexagonalization_params_io_pin_extension_mode_EXTEND))
.value("EXTEND_PLANAR", fiction::hexagonalization_params::io_pin_extension_mode::EXTEND_PLANAR,
DOC(fiction_hexagonalization_params_io_pin_extension_mode_EXTEND_PLANAR))

;

py::class_<fiction::hexagonalization_params>(m, "hexagonalization_params", DOC(fiction_hexagonalization_params))
.def(py::init<>())
.def_readwrite("input_pin_extension", &fiction::hexagonalization_params::input_pin_extension,
DOC(fiction_hexagonalization_params_input_pin_extension))
.def_readwrite("output_pin_extension", &fiction::hexagonalization_params::output_pin_extension,
DOC(fiction_hexagonalization_params_output_pin_extension));

py::class_<fiction::hexagonalization_stats>(m, "hexagonalization_stats", DOC(fiction_hexagonalization_stats))
.def(py::init<>())
.def("__repr__",
[](const fiction::hexagonalization_stats& stats)
{
std::stringstream stream{};
stats.report(stream);
return stream.str();
})
.def_readonly("time_total", &fiction::hexagonalization_stats::time_total,
DOC(fiction_hexagonalization_stats_duration));

m.def("hexagonalization", &fiction::hexagonalization<py_hexagonal_gate_layout, py_cartesian_gate_layout>,
py::arg("layout"), py::arg("parameters") = fiction::hexagonalization_params{},
py::arg("statistics") = nullptr, DOC(fiction_hexagonalization));
}

} // namespace pyfiction
Expand Down
156 changes: 156 additions & 0 deletions bindings/mnt/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5574,6 +5574,70 @@ Parameter ``b``:
Returns:
`true` iff `a < b` based on the aforementioned rule.)doc";

static const char *__doc_fiction_detail_compute_num_inputs_left_to_middle_pi =
R"doc(This function iterates over all primary inputs in the given Cartesian
layout and counts those whose tile is at the western border. Such
inputs are considered to be positioned left of the middle primary
input when the layout is converted to a hexagonal format.

Template parameter ``CartLyt``:
Type of the Cartesian layout.

Parameter ``lyt``:
The Cartesian gate-level layout containing primary inputs.

Returns:
The number of primary inputs that are placed to the left of the
middle primary input.)doc";

static const char *__doc_fiction_detail_compute_num_inputs_right_to_middle_pi =
R"doc(This function iterates over all primary inputs in the given Cartesian
layout and counts those whose tiles are at the northern border. Such
inputs are considered to be positioned right of the middle primary
input when the layout is converted to a hexagonal format.

Template parameter ``CartLyt``:
Type of the Cartesian layout.

Parameter ``lyt``:
The Cartesian gate-level layout containing primary inputs.

Returns:
The number of primary inputs that are placed to the right of the
middle primary input.)doc";

static const char *__doc_fiction_detail_compute_num_outputs_left_to_middle_po =
R"doc(This function iterates over all primary outputs in the given Cartesian
layout and counts those whose tiles are at the southern border. Such
outputs are considered to be positioned left of the middle primary
output when the layout is converted to a hexagonal format.

Template parameter ``CartLyt``:
Type of the Cartesian layout.

Parameter ``lyt``:
The Cartesian gate-level layout containing primary outputs.

Returns:
The number of primary outputs that are placed to the left of the
middle primary output.)doc";

static const char *__doc_fiction_detail_compute_num_outputs_right_to_middle_po =
R"doc(This function iterates over all primary outputs in the given Cartesian
layout and counts those whose tile is at the eastern border. Such
outputs are considered to be positioned right of the middle primary
output when the layout is converted to a hexagonal format.

Template parameter ``CartLyt``:
Type of the Cartesian layout.

Parameter ``lyt``:
The Cartesian gate-level layout containing primary outputs.

Returns:
The number of primary outputs that are placed to the right of the
middle primary output.)doc";

static const char *__doc_fiction_detail_connect_and_place = R"doc()doc";

static const char *__doc_fiction_detail_connect_and_place_2 = R"doc()doc";
Expand Down Expand Up @@ -7459,6 +7523,12 @@ Parameter ``cartesian_layout_width``:
Parameter ``cartesian_layout_height``:
Height of the Cartesian layout.

Parameter ``input_mode``:
Adjust offset based on PIs relocated to the top row.

Parameter ``output_mode``:
Adjust offset based on POs relocated to the bottom row.

Returns:
offset.)doc";

Expand Down Expand Up @@ -8295,6 +8365,18 @@ Parameter ``network``:
The network with virtual primary inputs removed, or the original
network if unsupported.)doc";

static const char *__doc_fiction_detail_hexagonalization_impl = R"doc()doc";

static const char *__doc_fiction_detail_hexagonalization_impl_hexagonalization_impl = R"doc()doc";

static const char *__doc_fiction_detail_hexagonalization_impl_layout = R"doc(The 2DDWave-clocked layout to hexagonalize.)doc";

static const char *__doc_fiction_detail_hexagonalization_impl_ps = R"doc(Hexagonalization parameters.)doc";

static const char *__doc_fiction_detail_hexagonalization_impl_pst = R"doc(Hexagonalization statistics.)doc";

static const char *__doc_fiction_detail_hexagonalization_impl_run = R"doc()doc";

static const char *__doc_fiction_detail_is_balanced_impl = R"doc()doc";

static const char *__doc_fiction_detail_is_balanced_impl_balanced = R"doc()doc";
Expand Down Expand Up @@ -9998,6 +10080,42 @@ Parameter ``cell``:

static const char *__doc_fiction_detail_recursively_paint_edges = R"doc()doc";

static const char *__doc_fiction_detail_routing_objective_with_fanin_update_information =
R"doc(Encapsulates a routing objective with fanin update information.

This struct specifies a routing objective by defining the source and
target coordinates, and it includes a flag that indicates whether the
primary input was the first fanin for the corresponding fanout and the
fanout gate is asymmetric (e.g., greater than). If the flag is set to
true, the fanin signals need to be reordered.

Template parameter ``HexLyt``:
The type of the hexagonal layout.)doc";

static const char *__doc_fiction_detail_routing_objective_with_fanin_update_information_routing_objective_with_fanin_update_information =
R"doc(Constructs a routing objective with fanin update information.

Initializes the base routing objective with the given source and
target coordinates, and sets the update flag based on the provided
parameter.

Parameter ``src``:
The source coordinate of the routing objective.

Parameter ``tgt``:
The target coordinate of the routing objective.

Parameter ``update``:
(Optional) A flag that, if true, indicates that the primary input
was the first fanin and the fanout gate is asymmetric, which means
that the fanin signals need to be reordered. Defaults to false.)doc";

static const char *__doc_fiction_detail_routing_objective_with_fanin_update_information_update_first_fanin =
R"doc(Flag indicating whether the primary input was the first fanin and the
fanout gate is asymmetric.

If this flag is true, the fanin signals need to be reordered.)doc";

static const char *__doc_fiction_detail_sat_clocking_handler = R"doc()doc";

static const char *__doc_fiction_detail_sat_clocking_handler_assign_clock_numbers =
Expand Down Expand Up @@ -15276,9 +15394,47 @@ Template parameter ``CartLyt``:
Parameter ``lyt``:
2DDWave-clocked Cartesian gate-level layout to hexagonalize.

Parameter ``params``:
Parameters.

Parameter ``stats``:
Statistics.

Returns:
Hexagonal representation of the Cartesian layout.)doc";

static const char *__doc_fiction_hexagonalization_io_pin_routing_error =
R"doc(Exception thrown when an error occurs during moving inputs/outputs to
top/bottom border and rerouting.)doc";

static const char *__doc_fiction_hexagonalization_io_pin_routing_error_hexagonalization_io_pin_routing_error =
R"doc(Constructs a `hexagonalization_io_pin_routing_error` object with the
given error message.

Parameter ``msg``:
The error message describing the error.)doc";

static const char *__doc_fiction_hexagonalization_params =
R"doc(This structure encapsulates settings that determine how primary inputs
(PIs) and primary outputs (POs) are handled during the conversion from
a Cartesian to a hexagonal layout.)doc";

static const char *__doc_fiction_hexagonalization_params_input_pin_extension = R"doc(Input extension mode. Defaults to none)doc";

static const char *__doc_fiction_hexagonalization_params_io_pin_extension_mode =
R"doc(Specifies how primary inputs/outputs should be handled in the
hexagonalization process.)doc";

static const char *__doc_fiction_hexagonalization_params_io_pin_extension_mode_EXTEND = R"doc(Extend primary inputs/outputs to the top/bottom row.)doc";

static const char *__doc_fiction_hexagonalization_params_io_pin_extension_mode_EXTEND_PLANAR =
R"doc(Extend primary inputs/outputs to the top/bottom row with planar
rerouting (i.e., without crossings).)doc";

static const char *__doc_fiction_hexagonalization_params_io_pin_extension_mode_NONE = R"doc(Do not extend primary inputs/outputs to the top/bottom row (default).)doc";

static const char *__doc_fiction_hexagonalization_params_output_pin_extension = R"doc(Output extension mode. Defaults to none)doc";

static const char *__doc_fiction_hexagonalization_stats = R"doc(This struct stores statistics about the hexagonalization process.)doc";

static const char *__doc_fiction_hexagonalization_stats_duration = R"doc(Runtime of the hexagonalization process.)doc";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import os
import unittest

from mnt.pyfiction import eq_type, equivalence_checking, hexagonalization, orthogonal, read_technology_network
from mnt.pyfiction import (
eq_type,
equivalence_checking,
hexagonalization,
hexagonalization_io_pin_extension_mode,
hexagonalization_params,
hexagonalization_stats,
orthogonal,
read_technology_network,
)

dir_path = os.path.dirname(os.path.realpath(__file__))

Expand All @@ -15,6 +24,95 @@ def test_hexagonalization_default(self):
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)

def test_hexagonalization_with_parameters(self):
network = read_technology_network(dir_path + "/../../resources/mux21.v")
cart_layout = orthogonal(network)
self.assertEqual(equivalence_checking(network, cart_layout), eq_type.STRONG)
params = hexagonalization_params()
hex_layout = hexagonalization(cart_layout, params)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)

def test_hexagonalization_with_stats(self):
network = read_technology_network(dir_path + "/../../resources/mux21.v")
cart_layout = orthogonal(network)
self.assertEqual(equivalence_checking(network, cart_layout), eq_type.STRONG)
stats = hexagonalization_stats()
hex_layout = hexagonalization(cart_layout, statistics=stats)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)
self.assertGreater(stats.time_total.total_seconds(), 0)

def test_hexagonalization_with_stats_and_parameters(self):
network = read_technology_network(dir_path + "/../../resources/mux21.v")
cart_layout = orthogonal(network)
self.assertEqual(equivalence_checking(network, cart_layout), eq_type.STRONG)

params = hexagonalization_params()
params.input_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND
params.output_pin_extension = hexagonalization_io_pin_extension_mode.NONE
stats = hexagonalization_stats()
hex_layout = hexagonalization(cart_layout, params, stats)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)
self.assertGreater(stats.time_total.total_seconds(), 0)
for pi in hex_layout.pis():
self.assertEqual(pi.y, 0)

params.input_pin_extension = hexagonalization_io_pin_extension_mode.NONE
params.output_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND
stats = hexagonalization_stats()
hex_layout = hexagonalization(cart_layout, params, stats)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)
self.assertGreater(stats.time_total.total_seconds(), 0)
for po in hex_layout.pos():
self.assertEqual(po.y, hex_layout.y())

params.input_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND
params.output_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND
stats = hexagonalization_stats()
hex_layout = hexagonalization(cart_layout, params, stats)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)
self.assertGreater(stats.time_total.total_seconds(), 0)
for pi in hex_layout.pis():
self.assertEqual(pi.y, 0)
for po in hex_layout.pos():
self.assertEqual(po.y, hex_layout.y())

params.input_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND_PLANAR
params.output_pin_extension = hexagonalization_io_pin_extension_mode.NONE
stats = hexagonalization_stats()
hex_layout = hexagonalization(cart_layout, params, stats)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)
self.assertGreater(stats.time_total.total_seconds(), 0)
for pi in hex_layout.pis():
self.assertEqual(pi.y, 0)

params.input_pin_extension = hexagonalization_io_pin_extension_mode.NONE
params.output_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND_PLANAR
stats = hexagonalization_stats()
hex_layout = hexagonalization(cart_layout, params, stats)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)
self.assertGreater(stats.time_total.total_seconds(), 0)
for po in hex_layout.pos():
self.assertEqual(po.y, hex_layout.y())

params.input_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND_PLANAR
params.output_pin_extension = hexagonalization_io_pin_extension_mode.EXTEND_PLANAR
stats = hexagonalization_stats()
hex_layout = hexagonalization(cart_layout, params, stats)
self.assertEqual(equivalence_checking(network, hex_layout), eq_type.STRONG)
self.assertEqual(equivalence_checking(cart_layout, hex_layout), eq_type.STRONG)
self.assertGreater(stats.time_total.total_seconds(), 0)
for pi in hex_layout.pis():
self.assertEqual(pi.y, 0)
for po in hex_layout.pos():
self.assertEqual(po.y, hex_layout.y())


if __name__ == "__main__":
unittest.main()
Loading
Loading