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

✨ Post-Layout Optimization #260

Merged
merged 88 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
f8fffdb
post placement optimization
simon1hofmann Jun 14, 2023
d17697c
Merge branch 'marcelwa:main' into post_placement_optimization
simon1hofmann Jun 14, 2023
542b846
Some improvements
simon1hofmann Jun 22, 2023
71fcdb8
align with python implementation
simon1hofmann Jul 24, 2023
bee09b7
Merge branch 'cda-tum:main' into post_placement_optimization
simon1hofmann Jul 24, 2023
7c206cf
refactoring
simon1hofmann Jul 24, 2023
626ba80
fix bug
simon1hofmann Jul 24, 2023
495eeb4
comments
simon1hofmann Jul 24, 2023
05a477c
refactor
simon1hofmann Jul 25, 2023
7a0d924
reformat
simon1hofmann Jul 25, 2023
a084c58
Merge branch 'cda-tum:main' into post_placement_optimization
simon1hofmann Jul 25, 2023
05edbe6
Merge branch 'cda-tum:main' into post_placement_optimization
simon1hofmann Jul 26, 2023
04b0a41
comments
simon1hofmann Jul 26, 2023
acac70f
fix ouput bug
simon1hofmann Jul 26, 2023
65eecdc
fix bug
simon1hofmann Jul 26, 2023
4ba48a0
move code to header file
simon1hofmann Jul 27, 2023
30b1d45
Merge branch 'cda-tum:main' into post_placement_optimization
simon1hofmann Jul 27, 2023
200340a
rename
simon1hofmann Jul 27, 2023
442bb1e
reformat code
simon1hofmann Jul 27, 2023
59df106
use tuple instead of pair
simon1hofmann Jul 27, 2023
7be67ce
fix windows ci error
simon1hofmann Jul 28, 2023
3383107
add basic unit test
simon1hofmann Jul 31, 2023
d8a2faa
fix warnings
simon1hofmann Jul 31, 2023
6d6b3bd
add docstrings
simon1hofmann Jul 31, 2023
a0bc660
add unittests for detail functions
simon1hofmann Jul 31, 2023
ae93be9
also delete excess wiring in columns
simon1hofmann Aug 1, 2023
65a4fa2
disable failing test case
simon1hofmann Aug 1, 2023
1307fd1
reformat
simon1hofmann Aug 1, 2023
9e13d6d
:art: Refactor physical design optimization methods for general gate-…
marcelwa Aug 1, 2023
697e1bf
Merge remote-tracking branch 'origin/post_placement_optimization' int…
marcelwa Aug 1, 2023
ef35b91
resolve first batch of todos
simon1hofmann Aug 1, 2023
3f94e3d
optimize layout in-place
simon1hofmann Aug 1, 2023
5c24280
use own types for complex structures
simon1hofmann Aug 1, 2023
7ec41ef
add optimization algorithm to cli
simon1hofmann Aug 2, 2023
f007ae2
add optimiztaion algorithm to docs
simon1hofmann Aug 2, 2023
44f4d3d
fix small bug and increase coverage
simon1hofmann Aug 2, 2023
4f65595
clang-format
simon1hofmann Aug 2, 2023
f4cee3f
simplify code
simon1hofmann Aug 2, 2023
40d1bad
update clang-tidy-review version
simon1hofmann Aug 2, 2023
8c9e5c2
more expressive docstrings
simon1hofmann Aug 2, 2023
55c67f6
reformat code
simon1hofmann Aug 2, 2023
cabe049
typo
simon1hofmann Aug 2, 2023
aae125e
:art: Improved upon the structure of the code even further and added …
marcelwa Aug 2, 2023
e25dbbd
resolve ToDos
simon1hofmann Aug 3, 2023
e121e92
remove todo
simon1hofmann Aug 3, 2023
c706084
Merge branch 'main' into post_placement_optimization
simon1hofmann Aug 3, 2023
3c48aa9
remove debug output
simon1hofmann Aug 3, 2023
c9fe045
Merge remote-tracking branch 'origin/post_placement_optimization' int…
simon1hofmann Aug 3, 2023
8d9bde0
Merge branch 'main' into post_placement_optimization
simon1hofmann Aug 4, 2023
7dfd111
clang-tidy
simon1hofmann Aug 8, 2023
753f0cb
update docs
simon1hofmann Aug 8, 2023
8401f5f
Merge branch 'main' into post_placement_optimization
simon1hofmann Aug 22, 2023
e309137
rewrite delete wires algorithm to delete all rows and columns at once
simon1hofmann Aug 28, 2023
d7ec841
clang-tidy
simon1hofmann Aug 28, 2023
5f4785f
only calculate fanins for used coordinates
simon1hofmann Aug 28, 2023
53e1fbd
increase coverage to 100%
simon1hofmann Aug 28, 2023
4314e77
fix bug
simon1hofmann Aug 28, 2023
f8fdfde
Merge branch 'main' into post_placement_optimization
simon1hofmann Aug 29, 2023
d3c91da
:sparkles: Added a deep-copy `clone()` function to `gate_level_layout`
marcelwa Aug 29, 2023
320cb01
Merge remote-tracking branch 'origin/post_placement_optimization' int…
marcelwa Aug 29, 2023
689304a
Merge branch 'main' into post_placement_optimization
simon1hofmann Aug 30, 2023
863b944
:art: Some renaming and docstring updates
marcelwa Aug 30, 2023
2f5c07d
Merge remote-tracking branch 'origin/post_placement_optimization' int…
marcelwa Aug 30, 2023
da3a9be
:art: Some renaming and slight code cleanup
marcelwa Aug 30, 2023
14d636a
resolve todos in experiments
simon1hofmann Aug 30, 2023
6b28fa4
Apply suggestions from code review
simon1hofmann Aug 30, 2023
8fe871d
resolve todos
simon1hofmann Aug 30, 2023
89330af
Merge branch 'main' into post_placement_optimization
simon1hofmann Aug 30, 2023
a9757d7
fix failing tests
simon1hofmann Aug 30, 2023
b2fa5fb
Merge remote-tracking branch 'origin/post_placement_optimization' int…
simon1hofmann Aug 30, 2023
38e9e59
clang-tidy
simon1hofmann Aug 30, 2023
dc28eaa
further improvements
simon1hofmann Aug 31, 2023
ddd3a8d
Merge branch 'main' into post_placement_optimization
simon1hofmann Sep 1, 2023
8f69a7c
Merge branch 'main' into post_placement_optimization
simon1hofmann Sep 1, 2023
7b50979
:sparkles: Added `clone` functions to all core layouts
marcelwa Sep 1, 2023
899b443
clone layout
simon1hofmann Sep 2, 2023
443b331
:sparkles: Added working `clone` functions to all core layouts
marcelwa Sep 4, 2023
6e7f6ef
:bug: Fix compiler issue
marcelwa Sep 4, 2023
4985229
Merge branch 'main' into post_placement_optimization
marcelwa Sep 5, 2023
c86bc0a
:art: ClangFormat
marcelwa Sep 5, 2023
924aa3b
Merge branch 'main' into post_placement_optimization
marcelwa Sep 6, 2023
8d741bb
:rotating_light: Suppress `clang-tidy` warning
marcelwa Sep 6, 2023
b5283f0
Merge remote-tracking branch 'origin/post_placement_optimization' int…
marcelwa Sep 6, 2023
a840ceb
:rotating_light: Suppress `clang-tidy` warning
marcelwa Sep 6, 2023
193cf66
:art: Final polishing
marcelwa Sep 11, 2023
b3b81fb
:white_check_mark: Enabled commented-out test case
marcelwa Sep 11, 2023
1c5e587
Merge branch 'main' into post_placement_optimization
marcelwa Sep 14, 2023
9b1591f
:twisted_rightwards_arrows: Fix merge conflicts
marcelwa Sep 14, 2023
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
99 changes: 99 additions & 0 deletions cli/cmd/physical_design/optimize.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// Created by Simon Hofmann on 02.08.23.
//

#ifndef FICTION_CMD_OPTIMIZE_HPP
#define FICTION_CMD_OPTIMIZE_HPP

#include <fiction/algorithms/physical_design/post_layout_optimization.hpp>
#include <fiction/layouts/clocked_layout.hpp>
#include <fiction/traits.hpp>
#include <fiction/types.hpp>

#include <alice/alice.hpp>

#include <iostream>
#include <optional>
#include <variant>

namespace alice
{
/**
* Optimizes a 2DDWave-clocked Cartesian layout.
*/
class optimize_command : public command
{
public:
/**
* Standard constructor. Adds descriptive information, options, and flags.
*
* @param e alice::environment that specifies stores etc.
*/
explicit optimize_command(const environment::ptr& e) :
command(e, "Optimizes a 2DDWave-clocked Cartesian layout with respect to area. It achieves this objective "
"by strategically repositioning gates within the layout, removing excess wiring, and "
"effectively relocating outputs to more favorable positions.")
{}

protected:
/**
* Statistics.
*/
fiction::post_layout_optimization_stats st{};

/**
* Optimizes a 2DDWave-clocked Cartesian layout.
*/
void execute() override
{
auto& gls = store<fiction::gate_layout_t>();

// error case: empty gate-level layout store
if (gls.empty())
{
env->out() << "[w] no gate layout in store" << std::endl;
return;
}

const auto& lyt = gls.current();

const auto check_clocking_scheme = [](auto&& lyt_ptr)
{ return lyt_ptr->is_clocking_scheme(fiction::clock_name::TWODDWAVE); };

// error case: layout is not 2DDWave-clocked
if (const auto is_twoddwave_clocked = std::visit(check_clocking_scheme, lyt); !is_twoddwave_clocked)
{
env->out() << "[e] layout has to be 2DDWave-clocked" << std::endl;
return;
}

const auto apply_optimization = [this](auto&& lyt_ptr)
{
using Lyt = typename std::decay_t<decltype(lyt_ptr)>::element_type;

if constexpr (fiction::is_cartesian_layout_v<Lyt>)
{
fiction::post_layout_optimization(*lyt_ptr, &st);
}
else
{
std::cout << "[e] layout has to be Cartesian" << std::endl;
}
};

try
{
std::visit(apply_optimization, lyt);
}
catch (...)
{
env->out() << "[e] an error occurred while optimizing" << std::endl;
}
}
};

ALICE_ADD_COMMAND(optimize, "Physical Design")

} // namespace alice

#endif // FICTION_CMD_OPTIMIZE_HPP
1 change: 1 addition & 0 deletions cli/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "cmd/physical_design/exact.hpp"
#include "cmd/physical_design/hex.hpp"
#include "cmd/physical_design/onepass.hpp"
#include "cmd/physical_design/optimize.hpp"
#include "cmd/physical_design/ortho.hpp"
#include "cmd/technology/area.hpp"
#include "cmd/technology/cell.hpp"
Expand Down
1 change: 1 addition & 0 deletions docs/algorithms/algorithms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Physical Design
color_routing.rst
apply_gate_library.rst
hexagonalization.rst
post_layout_optimization.rst


Verification
Expand Down
13 changes: 13 additions & 0 deletions docs/algorithms/post_layout_optimization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _post_layout_optimization:

Optimizing 2DDWave-clocked Cartesian Layouts
--------------------------------------------

**Header:** ``fiction/algorithms/physical_design/post_layout_optimization.hpp``

This algorithm aims to decrease the overall layout area of a given 2DDWave-clocked Cartesian layout that has been
generated using either heuristic methods or machine learning techniques. It achieves this objective by strategically
repositioning gates within the layout, removing excess wiring, and effectively relocating outputs to more favorable
positions.

.. doxygenfunction:: fiction::post_layout_optimization
108 changes: 108 additions & 0 deletions experiments/post_layout_optimization/post_layout_optimization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "fiction_experiments.hpp"

#include <fiction/algorithms/physical_design/orthogonal.hpp> // scalable heuristic for physical design of FCN layouts
#include <fiction/algorithms/physical_design/post_layout_optimization.hpp> // scalable heuristic for physical design of FCN layouts
#include <fiction/algorithms/properties/critical_path_length_and_throughput.hpp> // critical path and throughput calculations
#include <fiction/algorithms/verification/equivalence_checking.hpp> // SAT-based equivalence checking

#include <fmt/format.h> // output formatting
#include <lorina/lorina.hpp> // Verilog/BLIF/AIGER/... file parsing
#include <mockturtle/io/verilog_reader.hpp> // call-backs to read Verilog files into networks

#include <cassert>
#include <chrono>
#include <cstdlib>
#include <string>

int main() // NOLINT
{
using gate_lyt =
fiction::gate_level_layout<fiction::clocked_layout<fiction::tile_based_layout<fiction::cartesian_layout<>>>>;

experiments::experiment<std::string, uint32_t, uint32_t, uint32_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t,
uint64_t, uint32_t, uint32_t, uint64_t, uint64_t, double, double, float, std::string>
optimization_exp{"optimization",
"benchmark",
"inputs",
"outputs",
"initial nodes",
"ortho layout width (in tiles)",
"ortho layout height (in tiles)",
"ortho layout area (in tiles)",
"optimized layout width (in tiles)",
"optimized layout height (in tiles)",
"optimized layout area (in tiles)",
"gates",
"wires",
"critical path",
"throughput",
"runtime ortho (in sec)",
"runtime optimization (in sec)",
"improvement (%)",
"equivalent"};

// stats for SMT-based physical design
fiction::orthogonal_physical_design_stats orthogonal_stats{};
fiction::post_layout_optimization_stats post_layout_optimization_stats{};

static constexpr const uint64_t bench_select =
fiction_experiments::all & ~fiction_experiments::epfl & ~fiction_experiments::iscas85;

for (const auto& benchmark : fiction_experiments::all_benchmarks(bench_select))
{
fmt::print("[i] processing {}\n", benchmark);

fiction::technology_network network{};

const auto read_verilog_result =
simon1hofmann marked this conversation as resolved.
Show resolved Hide resolved
lorina::read_verilog(fiction_experiments::benchmark_path(benchmark), mockturtle::verilog_reader(network));
assert(read_verilog_result == lorina::return_code::success);

// perform layout generation with an OGD-based heuristic algorithm
auto gate_level_layout = fiction::orthogonal<gate_lyt>(network, {}, &orthogonal_stats);

// compute critical path and throughput
fiction::critical_path_length_and_throughput_stats cp_tp_stats{};
fiction::critical_path_length_and_throughput(gate_level_layout, &cp_tp_stats);

// calculate bounding box
const auto bounding_box_before_optimization = fiction::bounding_box_2d(gate_level_layout);

const auto width_before_optimization = bounding_box_before_optimization.get_x_size() + 1;
const auto height_before_optimization = bounding_box_before_optimization.get_y_size() + 1;
const auto area_before_optimization = width_before_optimization * height_before_optimization;

// perform post-layout optimization
fiction::post_layout_optimization<gate_lyt>(gate_level_layout, &post_layout_optimization_stats);

// check equivalence
simon1hofmann marked this conversation as resolved.
Show resolved Hide resolved
fiction::equivalence_checking_stats eq_stats{};
fiction::equivalence_checking<fiction::technology_network, gate_lyt>(network, gate_level_layout, &eq_stats);

const std::string eq_result = eq_stats.eq == fiction::eq_type::STRONG ? "STRONG" :
eq_stats.eq == fiction::eq_type::WEAK ? "WEAK" :
"NO";

// calculate bounding box
const auto bounding_box_after_optimization = fiction::bounding_box_2d(gate_level_layout);

const auto width_after_optimization = bounding_box_after_optimization.get_x_size() + 1;
const auto height_after_optimization = bounding_box_after_optimization.get_y_size() + 1;
const auto area_after_optimization = width_after_optimization * height_after_optimization;

const float improv = 100 * static_cast<float>((area_before_optimization - area_after_optimization)) /
static_cast<float>(area_before_optimization);
// log results
optimization_exp(benchmark, network.num_pis(), network.num_pos(), network.num_gates(),
width_before_optimization, height_before_optimization, area_before_optimization,
width_after_optimization, height_after_optimization, area_after_optimization,
gate_level_layout.num_gates(), gate_level_layout.num_wires(), cp_tp_stats.critical_path_length,
cp_tp_stats.throughput, mockturtle::to_seconds(orthogonal_stats.time_total),
mockturtle::to_seconds(post_layout_optimization_stats.time_total), improv, eq_result);

optimization_exp.save();
optimization_exp.table();
}

return EXIT_SUCCESS;
}
Loading
Loading