-
Notifications
You must be signed in to change notification settings - Fork 30
Planar ortho pr #852
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
base: main
Are you sure you want to change the base?
Planar ortho pr #852
Changes from all commits
01db414
35099de
896c8b7
7488fd7
be30509
6b7da02
fe7fe1d
28838cb
86e65a8
447db87
fea6fda
12a817b
c2f2ca9
e3fc515
78c11ce
1a6f535
c493a05
9c43e06
263d0e3
a73295c
ec3197d
ee39d01
875f136
13c6bac
0d9677d
47121e6
7a51997
ecc189a
d2aeef5
0a3833e
f3c537f
b0be14a
18d3440
29c85a2
9da449e
aa1e9fd
3950220
cb06b6a
7bc1872
71972db
be3bad4
fee1f7d
699cdc5
6115d67
14ae015
58b8af7
ccb3704
7c9c5f8
3c40183
db8fd96
cb7db4f
d5186d9
cbb94ca
2b0d49b
264a78f
51b404d
daf845f
feca457
56eed96
de57c61
7678638
24f3c19
4af9552
013407e
98976eb
85fefbb
3cde343
46884ab
be38caa
40fda74
f0eb038
b12e84c
fd90c54
7464430
7abfccc
f93aa9a
ba10e4e
360cca5
e948de2
150a00b
d56ede7
86f66a4
11488fe
342a7bd
d0afed2
7ff571b
33973c9
7dfe329
4f4ddc3
46c38b1
1c9fde5
c180359
51e464f
0c1863b
f0edfe8
643925f
e3c229d
9228a06
0d0aac4
8a4b48d
45fa8a1
f7a554b
97bde8c
76857e8
02f28ec
68bbcc6
f71bb36
b000f61
cd66e74
123febd
77957dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // | ||
| // Created by benjamin on 21.11.25. | ||
| // | ||
|
|
||
| #ifndef FICTION_CMD_PLANE_HPP | ||
| #define FICTION_CMD_PLANE_HPP | ||
|
|
||
| #include <fiction/algorithms/network_transformation/fanout_substitution.hpp> | ||
| #include <fiction/algorithms/network_transformation/network_balancing.hpp> | ||
| #include <fiction/algorithms/network_transformation/node_duplication_planarization.hpp> | ||
| #include <fiction/algorithms/physical_design/planar_layout_from_network_embedding.hpp> | ||
|
|
||
| #include <alice/alice.hpp> | ||
| #include <nlohmann/json.hpp> | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace alice | ||
| { | ||
| /** | ||
| * Executes the physical design approach Planar Layout from Network Embedding (PLANE), which finds a valid placement and | ||
| * routing without crossings given a planar network embedding. | ||
| * | ||
| * See include/fiction/algorithms/physical_design/planar_layout_from_network_embedding.hpp for more details. | ||
| */ | ||
| class plane_command final : public command | ||
| { | ||
| public: | ||
| /** | ||
| * Standard constructor. Adds descriptive information, options, and flags. | ||
| * | ||
| * @param e alice::environment that specifies stores etc. | ||
| */ | ||
| explicit plane_command(const environment::ptr& e); | ||
|
|
||
| protected: | ||
| /** | ||
| * Function to perform the physical design call. Generates a placed and routed FCN gate layout. | ||
| */ | ||
| void execute() override; | ||
|
|
||
| /** | ||
| * Logs the resulting information in a log file. | ||
| * | ||
| * @return JSON object containing information about the physical design process. | ||
| */ | ||
| nlohmann::json log() const override; | ||
|
|
||
| private: | ||
| /** | ||
| * Parameters for fanout substitution. | ||
| */ | ||
| fiction::fanout_substitution_params fan_ps{}; | ||
| /** | ||
| * Parameters for network path balancing. | ||
| */ | ||
| fiction::network_balancing_params bal_ps{}; | ||
| /** | ||
| * Parameters for planarization via node duplication. | ||
| */ | ||
| fiction::node_duplication_planarization_params dup_ps{}; | ||
| /** | ||
| * Parameters for planar layout generation from the network embedding. | ||
| */ | ||
| fiction::planar_layout_from_network_embedding_params ps{}; | ||
| /** | ||
| * Statistics collected during planar layout generation. | ||
| */ | ||
| fiction::planar_layout_from_network_embedding_stats st{}; | ||
| /** | ||
| * Number of clock phases used in the layout. | ||
| */ | ||
| uint8_t num_clock_phases = 4u; | ||
| /** | ||
| * Determines whether primary output order is kept (0) or randomized (1). | ||
| */ | ||
| uint32_t po_order{0u}; | ||
| }; | ||
|
|
||
| } // namespace alice | ||
|
|
||
| #endif // FICTION_CMD_PLANE_HPP |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // | ||
| // Created by benjamin on 21.11.25. | ||
| // | ||
|
|
||
| #include "cmd/physical_design/include/plane.hpp" | ||
|
|
||
| #include "stores.hpp" // NOLINT(misc-include-cleaner) | ||
|
|
||
| #include <fiction/algorithms/network_transformation/fanout_substitution.hpp> | ||
| #include <fiction/algorithms/network_transformation/network_balancing.hpp> | ||
| #include <fiction/algorithms/network_transformation/node_duplication_planarization.hpp> | ||
| #include <fiction/algorithms/physical_design/planar_layout_from_network_embedding.hpp> | ||
| #include <fiction/layouts/clocking_scheme.hpp> | ||
| #include <fiction/networks/views/mutable_rank_view.hpp> | ||
| #include <fiction/types.hpp> | ||
| #include <fiction/utils/network_utils.hpp> | ||
|
|
||
| #include <alice/alice.hpp> | ||
| #include <fmt/format.h> | ||
| #include <mockturtle/utils/stopwatch.hpp> | ||
| #include <nlohmann/json.hpp> | ||
|
|
||
| #include <exception> | ||
| #include <memory> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <variant> | ||
|
|
||
| namespace alice | ||
| { | ||
|
|
||
| plane_command::plane_command(const environment::ptr& e) : | ||
| command(e, "First, a planar embedding is obtained by performing fanout substitution, path balancing, and " | ||
| "planarization (node duplication). Then, scalable placement and routing are carried out on the " | ||
| "planar layout of the current logic network in store. Compared to the gold algorithm, the " | ||
| "resulting layout may occupy more area, but it is generated in reasonable runtime.") | ||
| { | ||
| // fanout substitution options | ||
| fan_ps.degree = 2; | ||
| // balancing option | ||
| bal_ps.unify_outputs = true; | ||
| // planarization option | ||
| add_option("--po-order, -p", po_order, "PO order: keep=0, random=1")->set_type_name("{0,1}"); | ||
| // plane options | ||
| add_option("--clock_numbers,-n", num_clock_phases, "Number of clock phases to be used {3 or 4}"); | ||
| add_flag("--verbose,-v", ps.verbose, "Be verbose"); | ||
| } | ||
|
|
||
| void plane_command::execute() | ||
| { | ||
| auto& lns = store<fiction::logic_network_t>(); | ||
| auto& gls = store<fiction::gate_layout_t>(); | ||
|
|
||
| if (lns.empty()) | ||
| { | ||
| env->out() << "[w] no logic network in store\n"; | ||
| return; | ||
| } | ||
| // error case: phases out of range | ||
| if (num_clock_phases != 3u && num_clock_phases != 4u) | ||
| { | ||
| env->out() << "[e] only 3- and 4-phase clocking schemes are supported\n"; | ||
| ps = {}; | ||
| return; | ||
| } | ||
|
Comment on lines
+60
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent parameter reset on error path. On invalid clock phases, only 🔎 Suggested fix if (num_clock_phases != 3u && num_clock_phases != 4u)
{
env->out() << "[e] only 3- and 4-phase clocking schemes are supported\n";
- ps = {};
+ fan_ps = {};
+ bal_ps = {};
+ dup_ps = {};
+ ps = {};
return;
}And at end of execute(): fan_ps = {};
bal_ps = {};
dup_ps = {};
+ ps = {};
}
🤖 Prompt for AI Agents |
||
|
|
||
| ps.number_of_clock_phases = num_clock_phases == 3 ? fiction::num_clks::THREE : fiction::num_clks::FOUR; | ||
|
|
||
| switch (po_order) | ||
| { | ||
| case 0u: | ||
| { | ||
| dup_ps.po_order = fiction::node_duplication_planarization_params::output_order::KEEP_PO_ORDER; | ||
| break; | ||
| } | ||
| case 1u: | ||
| { | ||
| dup_ps.po_order = fiction::node_duplication_planarization_params::output_order::RANDOM_PO_ORDER; | ||
| break; | ||
| } | ||
| default: | ||
| { | ||
| env->out() << "[w] invalid --po-order, defaulting to keep\n"; | ||
| dup_ps.po_order = fiction::node_duplication_planarization_params::output_order::KEEP_PO_ORDER; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| const auto perform_fanouts_and_balance = [this](auto&& ntk_ptr) | ||
| { | ||
| auto tec_f = fiction::fanout_substitution<fiction::tec_nt>(*ntk_ptr, fan_ps); | ||
| return std::make_shared<fiction::tec_nt>(fiction::network_balancing<fiction::tec_nt>(tec_f, bal_ps)); | ||
| }; | ||
|
|
||
| auto tec_b = std::visit(perform_fanouts_and_balance, lns.current()); | ||
|
|
||
| const fiction::mutable_rank_view vpi_r(*tec_b); | ||
|
|
||
| auto planarized_ntk = fiction::node_duplication_planarization(vpi_r, dup_ps); | ||
|
|
||
| try | ||
| { | ||
| gls.extend() = std::make_shared<fiction::cart_gate_clk_lyt>( | ||
| fiction::plane<fiction::cart_gate_clk_lyt>(planarized_ntk, ps, &st)); | ||
| } | ||
| catch (const fiction::high_degree_fanin_exception& e) | ||
| { | ||
| env->out() << fmt::format("[e] {}\n", e.what()); | ||
| } | ||
| catch (const std::invalid_argument& e) | ||
| { | ||
| env->out() << fmt::format("[e] {}\n", e.what()); | ||
| } | ||
| catch (const std::exception& e) | ||
| { | ||
| env->out() << fmt::format("[e] unexpected error: {}\n", e.what()); | ||
| } | ||
|
|
||
| fan_ps = {}; | ||
| bal_ps = {}; | ||
| dup_ps = {}; | ||
| } | ||
|
|
||
| nlohmann::json plane_command::log() const | ||
| { | ||
| return nlohmann::json{{"runtime in seconds", mockturtle::to_seconds(st.time_total)}, | ||
| {"number of gates", st.num_gates}, | ||
| {"number of wires", st.num_wires}, | ||
| {"number of crossings", st.num_crossings}, | ||
| {"layout", {{"x-size", st.x_size}, {"y-size", st.y_size}, {"area", st.x_size * st.y_size}}}}; | ||
| } | ||
|
|
||
| } // namespace alice | ||
Uh oh!
There was an error while loading. Please reload this page.