Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d09b1ec
AllowModify in cnf_view
lee30sonia Mar 25, 2020
2e81966
default constructors in bill
lee30sonia Mar 25, 2020
fd27853
restructure classes
lee30sonia Mar 25, 2020
51bfeba
constructor with existing network; adding unit clause for constant node
lee30sonia Mar 25, 2020
cc9d3e5
updates according to comments
lee30sonia Mar 25, 2020
120e3a0
add test cases
lee30sonia Mar 26, 2020
a65799e
Merge remote-tracking branch 'upstream/master'
lee30sonia Mar 27, 2020
3a55467
get lit for node and add_var with AllowModify
lee30sonia Mar 27, 2020
6ce8e70
Merge remote-tracking branch 'upstream/master'
lee30sonia Apr 6, 2020
cff6805
Merge remote-tracking branch 'upstream/master'
lee30sonia Apr 7, 2020
23a39b0
Merge remote-tracking branch 'upstream/master'
lee30sonia Apr 8, 2020
4d83133
fix merge error
lee30sonia Apr 8, 2020
c0abcbc
Merge remote-tracking branch 'upstream/master'
lee30sonia Apr 13, 2020
065c40e
Merge remote-tracking branch 'upstream/master'
lee30sonia Apr 22, 2020
f41e1dc
Merge remote-tracking branch 'upstream/master'
lee30sonia May 10, 2020
0900355
Merge remote-tracking branch 'upstream/master'
lee30sonia May 20, 2020
96b8b37
Merge remote-tracking branch 'upstream/master'
lee30sonia May 30, 2020
fb229f9
Merge remote-tracking branch 'upstream/master'
lee30sonia Jun 4, 2020
f2c2ce5
Merge remote-tracking branch 'upstream/master'
lee30sonia Jun 9, 2020
fbe876a
Merge remote-tracking branch 'upstream/master'
lee30sonia Jun 17, 2020
79bb3ee
Merge remote-tracking branch 'upstream/master'
lee30sonia Jul 5, 2020
12d2c87
Merge remote-tracking branch 'upstream/master'
lee30sonia Jul 29, 2020
952198e
bit packing
lee30sonia Aug 3, 2020
d4260bb
test
lee30sonia Aug 3, 2020
b96a8f7
more constructors & docs
lee30sonia Aug 3, 2020
32f3b85
use bit packing in pattern generation
lee30sonia Aug 3, 2020
f71c7b1
support computation with ODC window
lee30sonia Aug 4, 2020
17c4937
Merge branch 'master' into bit_packing
lee30sonia Aug 4, 2020
f76f624
debug support computation
lee30sonia Aug 10, 2020
88e97b5
try to not run test for bit packing on windows platform
lee30sonia Aug 10, 2020
5d620f2
add debug messages
lee30sonia Aug 10, 2020
e2846fd
add more debug messages
lee30sonia Aug 10, 2020
1be254f
more messages
lee30sonia Aug 10, 2020
c30b826
debug & remove cout
lee30sonia Aug 10, 2020
d68a460
add min invoke times in circuit_validator
lee30sonia Aug 20, 2020
2c5afad
fix warning
lee30sonia Aug 20, 2020
c56773f
typo in verbose report
lee30sonia Aug 24, 2020
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
22 changes: 20 additions & 2 deletions docs/algorithms/simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,34 @@ With ``partial_simulator``, adding new simulation patterns and re-simulation can
Incremental simulation is adopted, which speeds up simulation time by only re-simulating needed nodes and only re-computing the last block of ``partial_truth_table``.
Note that currently only AIG and XAG are supported.

**Constructors**

.. doxygenfunction:: mockturtle::partial_simulator::partial_simulator( unsigned, unsigned, std::default_random_engine::result_type )

.. doxygenfunction:: mockturtle::partial_simulator::partial_simulator( std::vector<kitty::partial_truth_table> const& )

.. doxygenfunction:: mockturtle::partial_simulator::partial_simulator( const std::string&, uint32_t )

**Interfaces**

.. doxygenfunction:: mockturtle::partial_simulator::add_pattern( std::vector<bool> const& )

.. doxygenfunction:: mockturtle::partial_simulator::num_bits()

.. doxygenfunction:: mockturtle::partial_simulator::get_patterns()

.. doxygenfunction:: mockturtle::simulate_nodes( Ntk const&, unordered_node_map<kitty::partial_truth_table, Ntk>&, partial_simulator const&, bool )
**Simulation**

.. doxygenfunction:: mockturtle::simulate_nodes( Ntk const&, unordered_node_map<kitty::partial_truth_table, Ntk>&, Simulator const&, bool )

.. doxygenfunction:: mockturtle::simulate_node( Ntk const&, typename Ntk::node const&, unordered_node_map<kitty::partial_truth_table, Ntk>&, Simulator const& )

**Bit Packing**

To reduce the size of simulation pattern set during pattern generation, ``bit_packed_simulator`` can be used instead of ``partial_simulator``, which has additional interfaces to specify care bits in patterns and to perform bit packing.

.. doxygenclass:: mockturtle::bit_packed_simulator

.. doxygenfunction:: mockturtle::bit_packed_simulator::add_pattern( std::vector<bool> const&, std::vector<bool> const& )

.. doxygenfunction:: mockturtle::simulate_node( Ntk const&, typename Ntk::node const&, unordered_node_map<kitty::partial_truth_table, Ntk>&, partial_simulator const& )
.. doxygenfunction:: mockturtle::bit_packed_simulator::pack_bits()
2 changes: 1 addition & 1 deletion experiments/pattern_generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main()
pattern_generation_stats st;

uint32_t num_random_pattern = 1000;
partial_simulator sim( aig.num_pis(), num_random_pattern );
bit_packed_simulator sim( aig.num_pis(), num_random_pattern );
pattern_generation( aig, sim, ps, &st );

exp( benchmark, aig.num_pis(), size_before, sim.num_bits(), st.num_generated_patterns, st.num_constant, to_seconds( st.time_total ), to_seconds( st.time_sim ), to_seconds( st.time_sat ) );
Expand Down
17 changes: 11 additions & 6 deletions include/mockturtle/algorithms/circuit_validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class circuit_validator
};

explicit circuit_validator( Ntk const& ntk, validator_params const& ps = {} )
: ntk( ntk ), ps( ps ), literals( ntk ), cex( ntk.num_pis() )
: ntk( ntk ), ps( ps ), literals( ntk ), num_invoke( 0u ), cex( ntk.num_pis() )
{
static_assert( is_network_type_v<Ntk>, "Ntk is not a network type" );
static_assert( has_foreach_fanin_v<Ntk>, "Ntk does not implement the foreach_fanin method" );
Expand Down Expand Up @@ -146,7 +146,7 @@ class circuit_validator
construct( ntk.get_node( d ) );
}
auto const res = validate( ntk.get_node( f ), lit_not_cond( literals[d], ntk.is_complemented( f ) ^ ntk.is_complemented( d ) ) );
if ( solver.num_clauses() > ps.max_clauses )
if ( solver.num_clauses() > ps.max_clauses && num_invoke >= MIN_NUM_INVOKE )
{
restart();
}
Expand All @@ -161,7 +161,7 @@ class circuit_validator
construct( ntk.get_node( d ) );
}
auto const res = validate( root, lit_not_cond( literals[d], ntk.is_complemented( d ) ) );
if ( solver.num_clauses() > ps.max_clauses )
if ( solver.num_clauses() > ps.max_clauses && num_invoke >= MIN_NUM_INVOKE )
{
restart();
}
Expand Down Expand Up @@ -231,7 +231,7 @@ class circuit_validator
pop();
}

if ( solver.num_clauses() > ps.max_clauses )
if ( solver.num_clauses() > ps.max_clauses && num_invoke >= MIN_NUM_INVOKE )
{
restart();
}
Expand Down Expand Up @@ -278,7 +278,7 @@ class circuit_validator
res = solve( {lit_not_cond( literals[root], value )} );
}

if ( solver.num_clauses() > ps.max_clauses )
if ( solver.num_clauses() > ps.max_clauses && num_invoke >= MIN_NUM_INVOKE )
{
restart();
}
Expand Down Expand Up @@ -345,7 +345,7 @@ class circuit_validator
}

pop();
if ( solver.num_clauses() > ps.max_clauses )
if ( solver.num_clauses() > ps.max_clauses && num_invoke >= MIN_NUM_INVOKE )
{
restart();
}
Expand All @@ -365,6 +365,7 @@ class circuit_validator
private:
void restart()
{
num_invoke = 0u;
solver.restart();
if constexpr ( randomize )
{
Expand Down Expand Up @@ -516,6 +517,7 @@ class circuit_validator

std::optional<bool> solve( std::vector<bill::lit_type> assumptions )
{
++num_invoke;
auto const res = solver.solve( assumptions, ps.conflict_limit );

if ( res == bill::result::states::satisfiable )
Expand Down Expand Up @@ -692,6 +694,9 @@ class circuit_validator
unordered_node_map<bill::lit_type, Ntk> literals;
bill::solver<Solver> solver;

static const uint32_t MIN_NUM_INVOKE = 20u;
uint32_t num_invoke;

bool between_push_pop = false;
std::vector<node> tmp;

Expand Down
130 changes: 112 additions & 18 deletions include/mockturtle/algorithms/pattern_generation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ struct pattern_generation_stats
namespace detail
{

template<class Ntk, bool use_odc = false>
template<class Ntk, class Simulator, bool use_odc = false>
class patgen_impl
{
public:
using node = typename Ntk::node;
using signal = typename Ntk::signal;
using TT = unordered_node_map<kitty::partial_truth_table, Ntk>;

explicit patgen_impl( Ntk& ntk, partial_simulator& sim, pattern_generation_params const& ps, validator_params& vps, pattern_generation_stats& st )
explicit patgen_impl( Ntk& ntk, Simulator& sim, pattern_generation_params const& ps, validator_params& vps, pattern_generation_stats& st )
: ntk( ntk ), ps( ps ), st( st ), vps( vps ), validator( ntk, vps ),
tts( ntk ), sim( sim )
{
Expand All @@ -130,12 +130,20 @@ class patgen_impl
stopwatch t( st.time_total );

call_with_stopwatch( st.time_sim, [&]() {
simulate_nodes<Ntk>( ntk, tts, sim );
simulate_nodes<Ntk>( ntk, tts, sim, true );
} );

if ( ps.num_stuck_at > 0 )
{
stuck_at_check();
if constexpr( std::is_same_v<Simulator, bit_packed_simulator> )
{
sim.pack_bits();
call_with_stopwatch( st.time_sim, [&]() {
tts.reset();
simulate_nodes<Ntk>( ntk, tts, sim, true );
} );
}
if ( ps.substitute_const )
{
for ( auto n : const_nodes )
Expand All @@ -151,6 +159,14 @@ class patgen_impl
if constexpr ( use_odc )
{
observability_check();
if constexpr( std::is_same_v<Simulator, bit_packed_simulator> )
{
sim.pack_bits();
call_with_stopwatch( st.time_sim, [&]() {
tts.reset();
simulate_nodes<Ntk>( ntk, tts, sim, true );
} );
}
}
}

Expand Down Expand Up @@ -226,7 +242,7 @@ class patgen_impl
}
}

new_pattern( validator.cex );
new_pattern( validator.cex, n );

if ( ps.num_stuck_at > 1 )
{
Expand All @@ -236,7 +252,7 @@ class patgen_impl
} );
for ( auto& pattern : generated )
{
new_pattern( pattern );
new_pattern( pattern, n );
}
}

Expand Down Expand Up @@ -311,7 +327,7 @@ class patgen_impl
{
if ( !( *res ) )
{
new_pattern( validator.cex );
new_pattern( validator.cex, n );
++st.unobservable_type2;

if ( ps.verbose )
Expand Down Expand Up @@ -348,7 +364,7 @@ class patgen_impl
{
if ( !( *res ) )
{
new_pattern( validator.cex );
new_pattern( validator.cex, n );
++st.unobservable_type2;

if ( ps.verbose )
Expand Down Expand Up @@ -376,9 +392,18 @@ class patgen_impl
}

private:
void new_pattern( std::vector<bool> const& pattern )
void new_pattern( std::vector<bool> const& pattern, node const& n )
{
sim.add_pattern( pattern );
if constexpr( std::is_same_v<Simulator, bit_packed_simulator> )
{
sim.add_pattern( pattern, compute_support( n ) );
}
else
{
(void)n;
sim.add_pattern( pattern );
}

++st.num_generated_patterns;

/* re-simulate */
Expand Down Expand Up @@ -411,11 +436,78 @@ class patgen_impl
} );
for ( auto& pattern : generated )
{
new_pattern( pattern );
new_pattern( pattern, n );
}
zero = sim.compute_constant( false );
}

std::vector<bool> compute_support( node const& n )
{
ntk.incr_trav_id();
if constexpr ( use_odc )
{
if ( ps.odc_levels != 0 )
{
std::vector<node> leaves;
mark_fanout_leaves_rec( n, 1, leaves );
ntk.foreach_po( [&]( auto const& f ) {
if ( ntk.visited( ntk.get_node( f ) ) == ntk.trav_id() )
{
leaves.emplace_back( ntk.get_node( f ) );
}
});

ntk.incr_trav_id();
for ( auto& l : leaves )
{
mark_support_rec( l );
}
}
}
mark_support_rec( n );

std::vector<bool> care( ntk.num_pis(), false );
ntk.foreach_pi( [&]( auto const& f, uint32_t i ) {
if ( ntk.visited( f ) == ntk.trav_id() )
{
care[i] = true;
}
});
return care;
}

void mark_support_rec( node const& n )
{
if ( ntk.visited( n ) == ntk.trav_id() )
{ return; }
ntk.set_visited( n, ntk.trav_id() );

ntk.foreach_fanin( n, [&]( auto const& f ) {
if ( ntk.visited( ntk.get_node( f ) ) == ntk.trav_id() )
{ return true; }
mark_support_rec( ntk.get_node( f ) );
return true;
});
}

void mark_fanout_leaves_rec( node const& n, int level, std::vector<node>& leaves )
{
ntk.foreach_fanout( n, [&]( auto const& fo ) {
if ( ntk.visited( fo ) == ntk.trav_id() )
{ return true; }
ntk.set_visited( fo, ntk.trav_id() );

if ( level == ps.odc_levels )
{
leaves.emplace_back( fo );
return true;
}

mark_fanout_leaves_rec( fo, level + 1, leaves );
return true;
} );
}

private:
Ntk& ntk;

Expand All @@ -428,7 +520,7 @@ class patgen_impl
TT tts;
std::vector<signal> const_nodes;

partial_simulator& sim;
Simulator& sim;
};

} /* namespace detail */
Expand All @@ -441,22 +533,24 @@ class patgen_impl
*
* [1] Simulation-Guided Boolean Resubstitution. IWLS 2020 (arXiv:2007.02579).
*
* \param sim Reference of a `partial_simulator` object where the generated
* patterns will be stored. It can be empty (`partial_simulator( ntk.num_pis(), 0 )`)
* \param sim Reference of a `partial_simulator` or `bit_packed_simulator`
* object where the generated patterns will be stored.
* It can be empty (`Simulator( ntk.num_pis(), 0 )`)
* or already containing some patterns generated from previous runs
* (`partial_simulator( filename )`) or randomly generated
* (`partial_simulator( ntk.num_pis(), num_random_patterns )`). The generated
* (`Simulator( filename )`) or randomly generated
* (`Simulator( ntk.num_pis(), num_random_patterns )`). The generated
* patterns can then be written out with `write_patterns`
* or directly be used by passing the simulator to another algorithm.
*/
template<class Ntk>
void pattern_generation( Ntk& ntk, partial_simulator& sim, pattern_generation_params const& ps = {}, pattern_generation_stats* pst = nullptr )
template<class Ntk, class Simulator>
void pattern_generation( Ntk& ntk, Simulator& sim, pattern_generation_params const& ps = {}, pattern_generation_stats* pst = nullptr )
{
static_assert( is_network_type_v<Ntk>, "Ntk is not a network type" );
static_assert( has_foreach_gate_v<Ntk>, "Ntk does not implement the foreach_gate method" );
static_assert( has_get_node_v<Ntk>, "Ntk does not implement the get_node method" );
static_assert( has_is_complemented_v<Ntk>, "Ntk does not implement the is_complemented method" );
static_assert( has_make_signal_v<Ntk>, "Ntk does not implement the make_signal method" );
static_assert( std::is_same_v<Simulator, partial_simulator> || std::is_same_v<Simulator, bit_packed_simulator>, "Simulator should be either partial_simulator or bit_packed_simulator" );

pattern_generation_stats st;
validator_params vps;
Expand All @@ -469,7 +563,7 @@ void pattern_generation( Ntk& ntk, partial_simulator& sim, pattern_generation_pa
using fanout_view_t = fanout_view<Ntk>;
fanout_view_t fanout_view{ntk};

detail::patgen_impl<fanout_view_t, true> p( fanout_view, sim, ps, vps, st );
detail::patgen_impl<fanout_view_t, Simulator, true> p( fanout_view, sim, ps, vps, st );
p.run();
}
else
Expand Down
4 changes: 2 additions & 2 deletions include/mockturtle/algorithms/sim_resub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ struct abc_resub_functor_stats
std::cout << fmt::format( "[i] #solution = {:6d}\n", num_success );
std::cout << fmt::format( "[i] #invoke = {:6d}\n", num_success + num_fail );
std::cout << fmt::format( "[i] ABC time: {:>5.2f} secs\n", to_seconds( time_compute_function ) );
std::cout << fmt::format( "[i] interface: {:>5.2f} secs\n", to_seconds( time_compute_function ) );
std::cout << fmt::format( "[i] interface: {:>5.2f} secs\n", to_seconds( time_interface ) );
// clang-format on
}
};
Expand Down Expand Up @@ -815,7 +815,7 @@ class simulation_based_resub_engine

/* first simulation: the whole circuit; from 0 bits. */
call_with_stopwatch( st.time_sim, [&]() {
simulate_nodes<Ntk>( ntk, tts, sim );
simulate_nodes<Ntk>( ntk, tts, sim, true );
});
}

Expand Down
Loading