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

Various minor fixes #458

Merged
merged 8 commits into from
May 5, 2021
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
40 changes: 0 additions & 40 deletions .github/workflows/coveralls.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[![Actions Status](https://github.com/lsils/mockturtle/workflows/Linux%20CI/badge.svg)](https://github.com/lsils/mockturtle/actions)
[![Actions Status](https://github.com/lsils/mockturtle/workflows/MacOS%20CI/badge.svg)](https://github.com/lsils/mockturtle/actions)
[![Actions Status](https://github.com/lsils/mockturtle/workflows/Windows%20CI/badge.svg)](https://github.com/lsils/mockturtle/actions)
[![Coverage Status](https://coveralls.io/repos/github/lsils/mockturtle/badge.svg?branch=master)](https://coveralls.io/github/lsils/mockturtle?branch=master)
[![Coverage Status](https://codecov.io/gh/lsils/mockturtle/branch/master/graph/badge.svg?token=KSC1MP2VCM)](https://codecov.io/gh/lsils/mockturtle)
[![Documentation Status](https://readthedocs.org/projects/mockturtle/badge/?version=latest)](http://mockturtle.readthedocs.io/en/latest/?badge=latest)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Expand Down
5 changes: 4 additions & 1 deletion experiments/aig_resubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

resubstitution_params ps;
resubstitution_stats st;
Expand Down
10 changes: 8 additions & 2 deletions experiments/cut_rewriting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig, aig2;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig2 ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig2 ) ) != lorina::return_code::success )
{
continue;
}

cut_rewriting_params ps;
ps.cut_enumeration_ps.cut_size = 4;
Expand Down
6 changes: 5 additions & 1 deletion experiments/equivalence_checking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

const auto orig = aig;

xag_npn_resynthesis<aig_network> resyn;
Expand Down
5 changes: 4 additions & 1 deletion experiments/functional_reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

functional_reduction_params ps;
functional_reduction_stats st;
Expand Down
5 changes: 4 additions & 1 deletion experiments/lut_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

lut_mapping_stats st;
mapping_view<aig_network, true> mapped_aig{aig};
Expand Down
11 changes: 9 additions & 2 deletions experiments/mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ int main()
std::vector<gate> gates;

std::istringstream in( mcnc_library );
lorina::read_genlib( in, genlib_reader( gates ) );
if ( lorina::read_genlib( in, genlib_reader( gates ) ) != lorina::return_code::success )
{
fmt::print( stderr, "[e] could not read genlib file\n" );
std::abort();
}

tech_library_params tps;
tech_library<5> lib( gates, tps );
Expand All @@ -87,7 +91,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

const uint32_t size_before = aig.num_gates();
const uint32_t depth_before = depth_view( aig ).depth();
Expand Down
5 changes: 4 additions & 1 deletion experiments/mig_resubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ int main()
fmt::print( "[i] processing {}\n", benchmark );

mig_network mig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( mig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( mig ) ) != lorina::return_code::success )
{
continue;
}

resubstitution_params ps;
resubstitution_stats st;
Expand Down
5 changes: 4 additions & 1 deletion experiments/node_resynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

lut_mapping_params ps;
ps.cut_enumeration_ps.cut_size = 4u;
Expand Down
6 changes: 5 additions & 1 deletion experiments/pattern_generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

auto size_before = aig.num_gates();

pattern_generation_params ps;
Expand Down
5 changes: 4 additions & 1 deletion experiments/satlut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

mapping_view<aig_network, true> mapped_aig{aig};
lut_mapping_params ps;
Expand Down
5 changes: 4 additions & 1 deletion experiments/sim_resubstitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

resubstitution_params ps;
resubstitution_stats st;
Expand Down
5 changes: 4 additions & 1 deletion experiments/sop_balancing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ int main()
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
continue;
}

balancing_params ps;
balancing_stats st4, st6;
Expand Down
68 changes: 48 additions & 20 deletions experiments/window_rewriting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,76 @@

#include <fmt/format.h>

using namespace mockturtle;

struct stats
{
uint32_t estimated_gain{0};
uint32_t real_gain{0};
uint32_t num_substitutions{0};
uint32_t num_iterations{0};
stopwatch<>::duration time_total{0};
};

aig_network optimize( aig_network const& aig, window_rewriting_params const& ps, window_rewriting_stats& st )
{
fanout_view faig{aig};
depth_view daig{faig};
color_view caig{daig};
window_rewriting( caig, ps, &st );
return cleanup_dangling( aig );
}

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

experiment<std::string, uint64_t, uint64_t, uint64_t, uint64_t, double, uint64_t, bool>
exp( "window_rewriting", "benchmark", "size_before", "size_after", "est. gain", "real gain", "runtime", "resubs", "equivalent" );
experiment<std::string, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, double, bool>
exp( "window_rewriting", "benchmark", "size_before", "size_after", "est. gain", "real gain", "resubs", "iterations", "runtime", "equivalent" );

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

/* read the benchmark */
aig_network ntk;
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( ntk ) ) != lorina::return_code::success )
aig_network aig;
if ( lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) ) != lorina::return_code::success )
{
fmt::print( "[e] could not read {}\n", benchmark );
continue;
}

/* optimize benchmark */
uint64_t const size_before{ntk.num_gates()};

fanout_view fntk{ntk};
depth_view dntk{fntk};
color_view aig{dntk};

window_rewriting_params ps;
ps.cut_size = 6u;
ps.num_levels = 5u;
ps.filter_cyclic_substitutions = benchmark == "c432" ? true : false;

window_rewriting_stats st;
window_rewriting( aig, ps, &st );
ntk = cleanup_dangling( ntk );
stats st{};

/* optimize benchmark until convergence */
uint64_t const size_before{aig.num_gates()};
uint64_t size_current{};
do
{
size_current = aig.num_gates();

window_rewriting_stats win_st;
aig = optimize( aig, ps, win_st );

/* add up statistics from each iteration */
st.real_gain += size_before - aig.num_gates();
st.estimated_gain += win_st.gain;
st.num_substitutions += win_st.num_substitutions;
++st.num_iterations;
st.time_total += win_st.time_total;

auto const cec = benchmark != "hyp" ? abc_cec( ntk, benchmark ) : true;
// st.report();
} while( aig.num_gates() < size_current );

st.report();
auto const cec = benchmark != "hyp" ? abc_cec( aig, benchmark ) : true;

exp( benchmark, size_before, ntk.num_gates(), st.gain, size_before - ntk.num_gates(), to_seconds( st.time_total ),
st.num_substitutions, cec );
exp( benchmark, size_before, aig.num_gates(),
st.estimated_gain, st.real_gain, st.num_substitutions, st.num_iterations,
to_seconds( st.time_total ), cec );
}

exp.save();
Expand Down
14 changes: 11 additions & 3 deletions include/mockturtle/io/write_aiger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ inline void encode( std::vector<unsigned char>& buffer, uint32_t lit )
} /* detail */

/*! \brief Writes a combinational AIG network in binary AIGER format into a file
*
* This function should be only called on "clean" aig_networks, e.g.,
* immediately after `cleanup_dangling`.
*
* **Required network functions:**
* - `num_cis`
Expand All @@ -74,6 +77,7 @@ inline void encode( std::vector<unsigned char>& buffer, uint32_t lit )
* - `foreach_po`
* - `get_node`
* - `is_complemented`
* - `node_to_index`
*
* \param aig Combinational AIG network
* \param os Output stream
Expand Down Expand Up @@ -104,18 +108,18 @@ inline void write_aiger( aig_network const& aig, std::ostream& os )

/* POs */
aig.foreach_po( [&]( signal const& f ){
sprintf( string_buffer, "%u\n", uint32_t(2*aig.get_node( f ) + aig.is_complemented( f )) );
sprintf( string_buffer, "%u\n", uint32_t(2*aig.node_to_index( aig.get_node( f ) ) + aig.is_complemented( f )) );
os.write( &string_buffer[0], sizeof( unsigned char )*strlen( string_buffer ) );
});

/* GATES */
std::vector<unsigned char> buffer;
aig.foreach_gate( [&]( node const& n ){
std::vector<uint32_t> lits;
lits.push_back( 2*n );
lits.push_back( 2*aig.node_to_index( n ) );

aig.foreach_fanin( n, [&]( signal const& fi ){
lits.push_back( 2*aig.get_node( fi ) + aig.is_complemented( fi ) );
lits.push_back( 2*aig.node_to_index( aig.get_node( fi ) ) + aig.is_complemented( fi ) );
});

if ( lits[1] > lits[2] )
Expand All @@ -140,6 +144,9 @@ inline void write_aiger( aig_network const& aig, std::ostream& os )
}

/*! \brief Writes a combinational AIG network in binary AIGER format into a file
*
* This function should be only called on "clean" aig_networks, e.g.,
* immediately after `cleanup_dangling`.
*
* **Required network functions:**
* - `num_cis`
Expand All @@ -149,6 +156,7 @@ inline void write_aiger( aig_network const& aig, std::ostream& os )
* - `foreach_po`
* - `get_node`
* - `is_complemented`
* - `node_to_index`
*
* \param aig Combinational AIG network
* \param filename Filename
Expand Down
Loading