Skip to content

Commit

Permalink
🎨 experiments_file_cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
hibenj committed Oct 14, 2024
1 parent f5e0e49 commit ede1ff0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 172 deletions.
190 changes: 28 additions & 162 deletions experiments/legalization/legalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@
#include "experiments.hpp"
#include "fiction/algorithms/network_transformation/fanout_substitution.hpp"
#include "fiction/algorithms/properties/check_planarity_balanced.hpp"
#include "fiction/utils/debug/network_writer.hpp"
#include "fiction/layouts/clocked_layout.hpp"
#include "fiction/layouts/cartesian_layout.hpp"
#include "fiction/layouts/tile_based_layout.hpp"
#include "fiction/layouts/gate_level_layout.hpp"
#include "fiction/layouts/coordinates.hpp"
#include "fiction_experiments.hpp"

#include <fiction/algorithms/network_transformation/network_balancing.hpp>
#include <fiction/algorithms/network_transformation/node_duplication_planarization.hpp>
#include <fiction/algorithms/physical_design/orthogonal.hpp> // scalable heuristic for physical design
#include <fiction/algorithms/physical_design/wiring_reduction.hpp> // wiring reduction algorithm
#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 <fiction/algorithms/physical_design/orthogonal.hpp> // scalable heuristic for physical design
#include <fiction/algorithms/verification/design_rule_violations.hpp>
#include <fiction/algorithms/verification/virtual_miter.hpp>
#include <fiction/io/dot_drawers.hpp>
#include <fiction/io/network_reader.hpp> // read networks from files
#include <fiction/networks/technology_network.hpp>
#include <fiction/types.hpp>

#include <fmt/core.h>
#include <fmt/format.h> // output formatting
#include <mockturtle/algorithms/equivalence_checking.hpp>
#include <mockturtle/networks/aig.hpp>
#include <mockturtle/utils/stopwatch.hpp>
#include <mockturtle/views/rank_view.hpp>
#include <mockturtle/algorithms/miter.hpp>
#include <mockturtle/networks/klut.hpp>

#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <sstream>
#include <string>

Expand All @@ -49,12 +48,11 @@ Ntk read_ntk(const std::string& name)

int main() // NOLINT
{
experiments::experiment<std::string, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, bool, bool, bool>
experiments::experiment<std::string, std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t, bool, bool, bool>
wiring_reduction_exp{"planarization", "benchmark", "inputs", "virt_inputs",
"outputs", "initial nodes", "nodes buffered", "nodes planarized",
"is_planar", "equivalent(ntk)", "equivalent(lyt)"};

int x = 0;
for (const auto& entry :
std::filesystem::directory_iterator("/home/benjamin/Documents/Repositories/working/fiction/benchmarks/IWLS93"))
{
Expand Down Expand Up @@ -90,29 +88,10 @@ int main() // NOLINT

auto benchmark_network = *nets.front();

bool cont = false;
benchmark_network.foreach_pi(
[&benchmark_network, &cont](auto pi)
{
if (benchmark_network.is_po(pi))
{
cont = true;
// std::cout << "Pi is Po\n";
}
});
if (cont)
{
continue;
}

// fiction::debug::write_dot_network(benchmark_network);

// std::cout << benchmark_network.num_gates() << std::endl;

fiction::network_balancing_params ps;
ps.unify_outputs = true;

const auto _b = fiction::network_balancing<fiction::technology_network>(
const auto b = fiction::network_balancing<fiction::technology_network>(
fiction::fanout_substitution<fiction::technology_network>(benchmark_network), ps);

// happens with exp4.v
Expand All @@ -127,22 +106,12 @@ int main() // NOLINT
std::cout << "Node 9213: " << fc.fanin_nodes.size() << std::endl;
std::cout << "Node 9213: " << _b.is_buf(8771) << std::endl;*/

// std::cout << _b.num_gates() << std::endl;

// fiction::debug::write_dot_network(_b);

if (_b.size() > 10000)
if (b.size() > 10000)
{
/*wiring_reduction_exp(entry.path().filename().string(), benchmark_network.num_pis(), 0,
benchmark_network.num_pos(), benchmark_network.num_gates(), _b.num_gates(),
_b.num_gates(), 0, 0, 0);
wiring_reduction_exp.save();
wiring_reduction_exp.table();
std::cout << ++x << "\n";*/
continue;
}

const auto planarized_b = fiction::node_duplication_planarization<fiction::technology_network>(_b);
const auto planarized_b = fiction::node_duplication_planarization<fiction::technology_network>(b);
const auto is_planar = fiction::check_planarity(planarized_b);
if (planarized_b.size() > 20000)
{
Expand All @@ -152,123 +121,53 @@ int main() // NOLINT
const auto cec_m = mockturtle::equivalence_checking(
*fiction::virtual_miter<fiction::technology_network>(benchmark_network, planarized_b), {}, &st);
assert(cec_m.has_value());
std::cout << cec_m.value() << std::endl;

using gate_lyt = fiction::gate_level_layout<
fiction::clocked_layout<fiction::tile_based_layout<fiction::cartesian_layout<>>>>;

fiction::orthogonal_physical_design_stats stats{};
using gate_layout = fiction::gate_level_layout<
fiction::clocked_layout<fiction::tile_based_layout<fiction::cartesian_layout<fiction::offset::ucoord_t>>>>;
auto layout = fiction::orthogonal<gate_layout>(planarized_b, {}, &stats);

fiction::gate_level_drv_params ps_d{};
const fiction::gate_level_drv_params ps_d{};
fiction::gate_level_drv_stats st_d{};

fiction::gate_level_drvs(layout, ps_d, &st_d);

const auto miter = mockturtle::miter<mockturtle::klut_network>(planarized_b, layout);
bool eq;
bool eq = false;
if (miter)
{
mockturtle::equivalence_checking_stats st;
mockturtle::equivalence_checking_stats st_o;

const auto ce = mockturtle::equivalence_checking(*miter, {}, &st);
const auto ce = mockturtle::equivalence_checking(*miter, {}, &st_o);
eq = ce.value();
}
wiring_reduction_exp(entry.path().filename().string(), benchmark_network.num_pis(),
planarized_b.num_virtual_pis(), benchmark_network.num_pos(), benchmark_network.num_gates(),
_b.num_gates(), planarized_b.num_gates(), is_planar, cec_m.value(), eq);
b.num_gates(), planarized_b.num_gates(), is_planar, cec_m.value(), eq);
wiring_reduction_exp.save();
wiring_reduction_exp.table();
std::cout << ++x << "\n";
}

/*fiction::technology_network tec;
const auto pi0 = tec.create_pi();
const auto pi1 = tec.create_pi();
const auto pi2 = tec.create_pi();
const auto pi3 = tec.create_pi();
const auto pi4 = tec.create_pi();
const auto a0 = tec.create_and(pi0, pi1);
const auto o0 = tec.create_or(pi0, pi1);
const auto a1 = tec.create_and(pi3, pi4);
const auto o1 = tec.create_or(pi3, pi4);
const auto a2 = tec.create_and(o0, pi2);
const auto a3 = tec.create_and(o1, pi2);
const auto a4 = tec.create_and(a2, a3);
tec.create_po(a0);
tec.create_po(a4);
tec.create_po(a1);
fiction::network_balancing_params ps;
ps.unify_outputs = true;
const auto _b = fiction::network_balancing<fiction::technology_network>(
fiction::fanout_substitution<fiction::technology_network>(tec), ps);
const auto _b_topo = mockturtle::topo_view(_b);
const auto _b_rank = mockturtle::rank_view(_b);
fiction::node_duplication_planarization_params dps;
dps.random_output_order = false;
const auto planarized_b = fiction::node_duplication_planarization<fiction::technology_network>(_b, dps);
fiction::debug::write_dot_network(tec, "tec_test");
fiction::debug::write_dot_network(_b, "t_b");
fiction::debug::write_dot_network(planarized_b, "network_b");*/

static constexpr const uint64_t bench_select = (fiction_experiments::iscas85); // fiction_experiments::iscas85 & ~
// fiction_experiments::trindade16 | fiction_experiments::fontes18 | fiction_experiments::epfl |
// fiction_experiments::iscas85 static constexpr const uint64_t bench_select =
static constexpr const std::uint64_t bench_select = (fiction_experiments::trindade16 | fiction_experiments::fontes18);
for (const auto& benchmark : fiction_experiments::all_benchmarks(bench_select))
{
const auto benchmark_network = read_ntk<fiction::tec_nt>(benchmark);

fiction::network_balancing_params ps;
ps.unify_outputs = true;

bool cont = false;
benchmark_network.foreach_pi(
[&benchmark_network, &cont](auto pi)
{
if (benchmark_network.is_po(pi))
{
cont = true;
std::cout << "Pi is Po\n";
}
});
if (cont)
{
continue;
}

const auto _b = fiction::network_balancing<fiction::technology_network>(
const auto b = fiction::network_balancing<fiction::technology_network>(
fiction::fanout_substitution<fiction::technology_network>(benchmark_network), ps);

if (_b.size() > 10000)
{
/*wiring_reduction_exp(benchmark, benchmark_network.num_pis(), 0, benchmark_network.num_pos(),
benchmark_network.num_gates(), _b.num_gates(), _b.num_gates(), 0, 0, "TEST");
wiring_reduction_exp.save();
wiring_reduction_exp.table();*/
continue;
}

const auto planarized_b = fiction::node_duplication_planarization<fiction::technology_network>(_b);
const auto planarized_b = fiction::node_duplication_planarization<fiction::technology_network>(b);

const auto is_planar = fiction::check_planarity(planarized_b);

if (planarized_b.size() > 20000)
{
wiring_reduction_exp(benchmark, benchmark_network.num_pis(), planarized_b.num_virtual_pis(),
benchmark_network.num_pos(), benchmark_network.num_gates(), _b.num_gates(),
planarized_b.num_gates(), is_planar, 0, 0);
benchmark_network.num_pos(), benchmark_network.num_gates(), b.num_gates(),
planarized_b.num_gates(), is_planar, false, false);
wiring_reduction_exp.save();
wiring_reduction_exp.table();
continue;
Expand All @@ -280,62 +179,29 @@ int main() // NOLINT
*fiction::virtual_miter<fiction::technology_network>(benchmark_network, planarized_b), {}, &st);
assert(cec_m.has_value());

auto name = mockturtle::names_view(planarized_b);

fiction::restore_names(benchmark_network, name);

using gate_lyt = fiction::gate_level_layout<
fiction::clocked_layout<fiction::tile_based_layout<fiction::cartesian_layout<>>>>;

fiction::orthogonal_physical_design_stats stats{};
using gate_layout = fiction::gate_level_layout<
fiction::clocked_layout<fiction::tile_based_layout<fiction::cartesian_layout<fiction::offset::ucoord_t>>>>;
auto start = std::chrono::high_resolution_clock::now();
auto layout = fiction::orthogonal<gate_layout>(planarized_b, {}, &stats);
auto stop = std::chrono::high_resolution_clock::now();

std::chrono::duration<double> elapsed = stop - start;

std::cout << "Time elapsed: " << elapsed.count() << " s\n";

std::cout << "X size : " << stats.x_size << "\n";
std::cout << "Y size : " << stats.y_size << "\n";

std::cout << "PO benchmark : " << benchmark_network.num_pos() << "\n";
std::cout << "PO planarized : " << planarized_b.num_pos() << "\n";
std::cout << "PO layout : " << layout.num_pos() << "\n";

fiction::gate_level_drv_params ps_d{};
fiction::gate_level_drv_stats st_d{};

fiction::gate_level_drvs(layout, ps_d, &st_d);

/*fiction::equivalence_checking_stats eq_s_ortho{};
// check equivalence
const auto eq_stats_ortho =
fiction::equivalence_checking<decltype(planarized_b), gate_lyt>(planarized_b, layout, &eq_s_ortho);
std::cout << "eq_checking gone\n";
const std::string eq_result_ortho = eq_stats_ortho == fiction::eq_type::STRONG ? "STRONG" :
eq_stats_ortho == fiction::eq_type::WEAK ? "WEAK" :
"NO";*/

const auto miter = mockturtle::miter<mockturtle::klut_network>(planarized_b, layout);
bool eq;
bool eq = false;
if (miter)
{
mockturtle::equivalence_checking_stats st;
mockturtle::equivalence_checking_stats st_o;

const auto ce = mockturtle::equivalence_checking(*miter, {}, &st);
const auto ce = mockturtle::equivalence_checking(*miter, {}, &st_o);
eq = ce.value();
}

// fiction::debug::write_dot_layout(layout);
/*fiction::debug::write_dot_network(_b, "ntk_b");
fiction::debug::write_dot_network(planarized_b, "ntk_p");*/

// log results
wiring_reduction_exp(benchmark, benchmark_network.num_pis(), planarized_b.num_virtual_pis(),
benchmark_network.num_pos(), benchmark_network.num_gates(), _b.num_gates(),
benchmark_network.num_pos(), benchmark_network.num_gates(), b.num_gates(),
planarized_b.num_gates(), is_planar, cec_m.value(), eq);

wiring_reduction_exp.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#ifndef FICTION_NODE_DUPLICATION_PLANARIZATION_HPP
#define FICTION_NODE_DUPLICATION_PLANARIZATION_HPP

#include "fiction/algorithms/properties/check_planarity_balanced.hpp"
#include "fiction/networks/views/extended_rank_view.hpp"
#include "fiction/networks/virtual_pi_network.hpp"

#include <mockturtle/traits.hpp>
#include <mockturtle/utils/node_map.hpp>

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <optional>
#include <random>
#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -94,9 +94,9 @@ struct node_pair
* @param node2 The second node of the fanin-edged node.
* @param delayValue The delay value for the node.
*/
node_pair(mockturtle::node<Ntk> node1, mockturtle::node<Ntk> node2, uint64_t delayValue) :
node_pair(mockturtle::node<Ntk> node1, mockturtle::node<Ntk> node2, uint64_t delay_value) :
pair(node1, node2),
delay(delayValue),
delay(delay_value),
fanin_pair(nullptr)
{}
};
Expand Down
2 changes: 1 addition & 1 deletion libs/Catch2
2 changes: 1 addition & 1 deletion libs/json
2 changes: 1 addition & 1 deletion libs/mockturtle
Submodule mockturtle updated 61 files
+1 −1 experiments/experiments.hpp
+1 −1 include/mockturtle/algorithms/aig_balancing.hpp
+1 −1 include/mockturtle/algorithms/akers_synthesis.hpp
+1 −1 include/mockturtle/algorithms/aqfp/aqfp_db.hpp
+1 −1 include/mockturtle/algorithms/aqfp/aqfp_fanout_resyn.hpp
+1 −1 include/mockturtle/algorithms/aqfp/aqfp_retiming.hpp
+2 −2 include/mockturtle/algorithms/aqfp/buffer_insertion.hpp
+5 −4 include/mockturtle/algorithms/aqfp/detail/dag.hpp
+1 −1 include/mockturtle/algorithms/aqfp/detail/dag_cost.hpp
+1 −1 include/mockturtle/algorithms/aqfp/detail/dag_gen.hpp
+1 −1 include/mockturtle/algorithms/aqfp/detail/dag_util.hpp
+1 −1 include/mockturtle/algorithms/aqfp/detail/db_builder.hpp
+1 −1 include/mockturtle/algorithms/aqfp/mig_algebraic_rewriting_splitters.hpp
+1 −1 include/mockturtle/algorithms/cut_enumeration/spectr_cut.hpp
+4 −4 include/mockturtle/algorithms/emap.hpp
+2 −2 include/mockturtle/algorithms/experimental/cost_resyn.hpp
+1 −0 include/mockturtle/algorithms/linear_resynthesis.hpp
+3 −3 include/mockturtle/algorithms/lut_mapper.hpp
+1 −1 include/mockturtle/algorithms/mig_algebraic_rewriting.hpp
+1 −1 include/mockturtle/algorithms/reconv_cut.hpp
+2 −2 include/mockturtle/algorithms/resyn_engines/xag_resyn.hpp
+1 −1 include/mockturtle/algorithms/xag_balancing.hpp
+1 −1 include/mockturtle/algorithms/xmg_algebraic_rewriting.hpp
+1 −1 include/mockturtle/algorithms/xmg_resub.hpp
+6 −1 include/mockturtle/generators/control.hpp
+1 −1 include/mockturtle/generators/self_dualize.hpp
+83 −20 include/mockturtle/io/serialize.hpp
+1 −1 include/mockturtle/networks/aqfp.hpp
+2 −2 include/mockturtle/properties/aqfpcost.hpp
+1 −1 include/mockturtle/utils/struct_library.hpp
+4 −4 include/mockturtle/utils/tech_library.hpp
+6 −6 include/mockturtle/utils/window_utils.hpp
+2 −2 include/mockturtle/views/mffc_view.hpp
+2 −2 include/mockturtle/views/rank_view.hpp
+3 −1 lib/abcsat/abc/satVec.h
+24 −21 lib/bill/bill/dd/zdd.hpp
+3 −1 lib/bill/bill/sat/solver/abc/satVec.h
+54 −61 lib/fmt/fmt/args.h
+3,077 −0 lib/fmt/fmt/base.h
+335 −143 lib/fmt/fmt/chrono.h
+81 −112 lib/fmt/fmt/color.h
+52 −58 lib/fmt/fmt/compile.h
+4 −2,968 lib/fmt/fmt/core.h
+277 −27 lib/fmt/fmt/format-inl.h
+624 −732 lib/fmt/fmt/format.h
+86 −102 lib/fmt/fmt/os.h
+25 −59 lib/fmt/fmt/ostream.h
+117 −136 lib/fmt/fmt/printf.h
+314 −170 lib/fmt/fmt/ranges.h
+278 −116 lib/fmt/fmt/std.h
+109 −46 lib/fmt/fmt/xchar.h
+7 −0 lib/lorina/lorina/verilog.hpp
+1 −1 lib/parallel_hashmap/parallel_hashmap/phmap.h
+45 −16 lib/parallel_hashmap/parallel_hashmap/phmap_dump.h
+2 −2 lib/percy/percy/fence.hpp
+78 −2 test/io/serialize.cpp
+0 −1 test/io/write_aiger.cpp
+40 −3 test/test.cpp
+5 −5 test/utils/struct_library.cpp
+10 −10 test/utils/window_utils.cpp
+2 −1 test/views/rank_view.cpp
2 changes: 1 addition & 1 deletion libs/parallel-hashmap
Submodule parallel-hashmap updated 1 files
+10 −0 CITATION.cff
2 changes: 1 addition & 1 deletion libs/pybind11
Submodule pybind11 updated 50 files
+1 −1 .github/workflows/ci.yml
+1 −1 .github/workflows/pip.yml
+5 −5 .pre-commit-config.yaml
+4 −1 CMakeLists.txt
+3 −3 docs/advanced/cast/stl.rst
+3 −3 docs/advanced/smart_ptrs.rst
+7 −0 docs/basics.rst
+17 −0 docs/changelog.rst
+44 −0 docs/faq.rst
+16 −3 include/pybind11/detail/class.h
+3 −0 include/pybind11/detail/common.h
+77 −0 include/pybind11/detail/cpp_conduit.h
+71 −0 include/pybind11/detail/exception_translation.h
+8 −6 include/pybind11/detail/internals.h
+42 −1 include/pybind11/detail/type_caster_base.h
+2 −1 include/pybind11/eigen/matrix.h
+2 −1 include/pybind11/eigen/tensor.h
+7 −55 include/pybind11/pybind11.h
+2 −0 include/pybind11/pytypes.h
+5 −5 include/pybind11/stl/filesystem.h
+1 −3 include/pybind11/typing.h
+75 −0 include/pybind11/warnings.h
+8 −1 tests/CMakeLists.txt
+3 −3 tests/conftest.py
+103 −0 tests/exo_planet_c_api.cpp
+19 −0 tests/exo_planet_pybind11.cpp
+3 −0 tests/extra_python_package/test_files.py
+13 −0 tests/home_planet_very_lonely_traveler.cpp
+8 −8 tests/local_bindings.h
+1 −1 tests/test_async.py
+12 −0 tests/test_buffers.cpp
+7 −0 tests/test_buffers.py
+1 −1 tests/test_callbacks.cpp
+22 −0 tests/test_cpp_conduit.cpp
+162 −0 tests/test_cpp_conduit.py
+47 −0 tests/test_cpp_conduit_traveler_bindings.h
+25 −0 tests/test_cpp_conduit_traveler_types.h
+1 −1 tests/test_custom_type_setup.py
+2 −2 tests/test_eigen_matrix.cpp
+1 −1 tests/test_numpy_array.py
+1 −1 tests/test_opaque_types.cpp
+63 −0 tests/test_pytypes.cpp
+44 −2 tests/test_pytypes.py
+2 −2 tests/test_sequences_and_iterators.cpp
+9 −6 tests/test_smart_ptr.cpp
+1 −1 tests/test_stl.cpp
+1 −1 tests/test_tagbased_polymorphic.cpp
+1 −1 tests/test_virtual_functions.cpp
+46 −0 tests/test_warnings.cpp
+68 −0 tests/test_warnings.py
2 changes: 1 addition & 1 deletion libs/tinyxml2
Submodule tinyxml2 updated 1 files
+3 −3 tinyxml2.h

0 comments on commit ede1ff0

Please sign in to comment.