Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 13 additions & 11 deletions experiments/mig_resubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,47 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include <string>
#include <vector>

#include <fmt/format.h>
#include <lorina/aiger.hpp>
#include <mockturtle/algorithms/mig_resub.hpp>
#include <mockturtle/algorithms/cleanup.hpp>
#include <mockturtle/io/aiger_reader.hpp>
#include <mockturtle/networks/mig.hpp>
#include <mockturtle/views/depth_view.hpp>
#include <mockturtle/views/fanout_view.hpp>
#include <lorina/aiger.hpp>

#include <experiments.hpp>
#include <fmt/format.h>
#include <string>

int main()
{
using namespace experiments;
using namespace mockturtle;

experiment<std::string, uint32_t, uint32_t, float, bool> exp( "mig_resubstitution", "benchmark", "size_before", "size_after", "runtime", "equivalent" );
experiment<std::string, uint32_t, uint32_t, float, bool>
exp( "mig_resubstitution", "benchmark", "size_before", "size_after", "runtime", "equivalent" );

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

mig_network mig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( mig ) );

resubstitution_params ps;
resubstitution_stats st;

ps.max_pis = 8u;
ps.max_inserts = 1u;
ps.progress = false;

const uint32_t size_before = mig.num_gates();
mig_resubstitution( mig, ps, &st );
depth_view depth_mig{mig};
fanout_view fanout_mig{depth_mig};

uint32_t const size_before = fanout_mig.num_gates();
mig_resubstitution( fanout_mig, ps, &st );
mig = cleanup_dangling( mig );

const auto cec = benchmark == "hyp" ? true : abc_cec( mig, benchmark );

bool const cec = benchmark == "hyp" ? true : abc_cec( fanout_mig, benchmark );
exp( benchmark, size_before, mig.num_gates(), to_seconds( st.time_total ), cec );
}

Expand Down
54 changes: 44 additions & 10 deletions include/mockturtle/algorithms/mig_resub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/*!
\file mig_resub.hpp
\brief Resubstitution
\brief Majority-specific resustitution rules

\author Heinz Riener
*/
Expand Down Expand Up @@ -643,11 +643,47 @@ struct mig_resub_functor
binate_divisors bdivs;
}; /* mig_resub_functor */

/*! \brief MIG-specific resubstitution algorithm.
*
* This algorithms iterates over each node, creates a
* reconvergence-driven cut, and attempts to re-express the node's
* function using existing nodes from the cut. Node which are no
* longer used (including nodes in their transitive fanins) can then
* be removed. The objective is to reduce the size of the network as
* much as possible while maintaing the global input-output
* functionality.
*
* **Required network functions:**
*
* - `clear_values`
* - `fanout_size`
* - `foreach_fanin`
* - `foreach_fanout`
* - `foreach_gate`
* - `foreach_node`
* - `get_constant`
* - `get_node`
* - `is_complemented`
* - `is_pi`
* - `level`
* - `make_signal`
* - `set_value`
* - `set_visited`
* - `size`
* - `substitute_node`
* - `value`
* - `visited`
*
* \param ntk A network type derived from mig_network
* \param ps Resubstitution parameters
* \param pst Resubstitution statistics
*/
template<class Ntk>
void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubstitution_stats* pst = nullptr )
{
/* TODO: check if basetype of ntk is aig */
static_assert( is_network_type_v<Ntk>, "Ntk is not a network type" );
static_assert( std::is_same_v<typename Ntk::base_type, mig_network>, "Network type is not mig_network" );

static_assert( has_clear_values_v<Ntk>, "Ntk does not implement the clear_values method" );
static_assert( has_fanout_size_v<Ntk>, "Ntk does not implement the fanout_size method" );
static_assert( has_foreach_fanin_v<Ntk>, "Ntk does not implement the foreach_fanin method" );
Expand All @@ -664,22 +700,20 @@ void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst
static_assert( has_substitute_node_v<Ntk>, "Ntk does not implement the has substitute_node method" );
static_assert( has_value_v<Ntk>, "Ntk does not implement the has_value method" );
static_assert( has_visited_v<Ntk>, "Ntk does not implement the has_visited method" );

using resub_view_t = fanout_view<depth_view<Ntk>>;
depth_view<Ntk> depth_view{ntk};
resub_view_t resub_view{depth_view};
static_assert( has_level_v<Ntk>, "Ntk does not implement the level method" );
static_assert( has_foreach_fanout_v<Ntk>, "Ntk does not implement the foreach_fanout method" );

if ( ps.max_pis == 8 )
{
using truthtable_t = kitty::static_truth_table<8u>;
using truthtable_dc_t = kitty::dynamic_truth_table;
using resub_impl_t = detail::resubstitution_impl<resub_view_t, typename detail::window_based_resub_engine<resub_view_t, truthtable_t, truthtable_dc_t, mig_resub_functor<resub_view_t, typename detail::window_simulator<resub_view_t, truthtable_t>, truthtable_dc_t>>>;
using resub_impl_t = detail::resubstitution_impl<Ntk, typename detail::window_based_resub_engine<Ntk, truthtable_t, truthtable_dc_t, mig_resub_functor<Ntk, typename detail::window_simulator<Ntk, truthtable_t>, truthtable_dc_t>>>;

resubstitution_stats st;
typename resub_impl_t::engine_st_t engine_st;
typename resub_impl_t::collector_st_t collector_st;

resub_impl_t p( resub_view, ps, st, engine_st, collector_st );
resub_impl_t p( ntk, ps, st, engine_st, collector_st );
p.run();

if ( ps.verbose )
Expand All @@ -698,13 +732,13 @@ void mig_resubstitution( Ntk& ntk, resubstitution_params const& ps = {}, resubst
{
using truthtable_t = kitty::dynamic_truth_table;
using truthtable_dc_t = kitty::dynamic_truth_table;
using resub_impl_t = detail::resubstitution_impl<resub_view_t, typename detail::window_based_resub_engine<resub_view_t, truthtable_t, truthtable_dc_t, mig_resub_functor<resub_view_t, typename detail::window_simulator<resub_view_t, truthtable_t>, truthtable_dc_t>>>;
using resub_impl_t = detail::resubstitution_impl<Ntk, typename detail::window_based_resub_engine<Ntk, truthtable_t, truthtable_dc_t, mig_resub_functor<Ntk, typename detail::window_simulator<Ntk, truthtable_t>, truthtable_dc_t>>>;

resubstitution_stats st;
typename resub_impl_t::engine_st_t engine_st;
typename resub_impl_t::collector_st_t collector_st;

resub_impl_t p( resub_view, ps, st, engine_st, collector_st );
resub_impl_t p( ntk, ps, st, engine_st, collector_st );
p.run();

if ( ps.verbose )
Expand Down
3 changes: 1 addition & 2 deletions include/mockturtle/algorithms/resubstitution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

/*!
\file resubstitution.hpp
\brief Generalized resubstitution framework

\brief Generic resubstitution framework

\author Heinz Riener
\author Siang-Yun Lee
Expand Down