From cd97e0cda1ecc4d628b95c1a877f5eb2ee158921 Mon Sep 17 00:00:00 2001 From: dinanli Date: Tue, 7 Dec 2021 13:57:58 +0100 Subject: [PATCH 1/7] first commit --- .gitignore | 1 + include/mockturtle/algorithms/simulation_cec.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 505680bc9..4329e653d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ examples/ docs/_build docs/doxyxml +.vs diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index 2b8cce16c..059c03fe8 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -74,6 +74,7 @@ class simulation_cec_impl bool run() { /* TODO: write your implementation here */ + // a simple test return false; } From 79816d22c2509c3d6b898bfa0cf4e7811f292be7 Mon Sep 17 00:00:00 2001 From: dinanli Date: Tue, 7 Dec 2021 15:56:45 +0100 Subject: [PATCH 2/7] Add calculation of splitting_var and rounds --- include/mockturtle/algorithms/cleanup.hpp | 2 +- .../mockturtle/algorithms/simulation_cec.hpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/mockturtle/algorithms/cleanup.hpp b/include/mockturtle/algorithms/cleanup.hpp index 57a7d7c13..f1bf32543 100644 --- a/include/mockturtle/algorithms/cleanup.hpp +++ b/include/mockturtle/algorithms/cleanup.hpp @@ -268,7 +268,7 @@ NtkDest cleanup_dangling( NtkSrc const& ntk ) std::vector> pis; ntk.foreach_pi( [&]( auto ) { pis.push_back( dest.create_pi() ); - } ); + } ); // record all the primiary inputs of ntk in pis for ( auto f : cleanup_dangling( ntk, dest, pis.begin(), pis.end() ) ) { diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index 059c03fe8..212db7841 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -74,14 +74,26 @@ class simulation_cec_impl bool run() { /* TODO: write your implementation here */ - // a simple test + // computing splitting_var and rounds + auto n = _ntk.num_pis(); + if ( n <= 6 ) + { + _st.split_var = n; + } + else + { + auto V = _ntk.num_gates(); + int max_m = std::log2l( std::pow(2, 29)/ V - 32 ) + 3; + _st.split_var = max_m > n ? n : max_m; + } + + _st.rounds = std::pow(2, n - _st.split_var ); + return false; } private: /* you can add additional methods here */ - -private: Ntk& _ntk; simulation_cec_stats& _st; /* you can add other attributes here */ From c4ca80c267a5bad07d1a34c54d4c3cb059ad4b6e Mon Sep 17 00:00:00 2001 From: dinanli Date: Tue, 7 Dec 2021 17:00:45 +0100 Subject: [PATCH 3/7] print message --- include/mockturtle/algorithms/simulation_cec.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index 212db7841..9e6274dc0 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -89,9 +89,16 @@ class simulation_cec_impl _st.rounds = std::pow(2, n - _st.split_var ); + std::cout << "pis and nodes: " << _ntk.num_pis() << " " << _ntk.num_gates() << std::endl; + std::cout << "spitting_vars: " << _st.split_var << std::endl; + std::cout << "rounds: " << _st.rounds << std::endl; + return false; } + // deriving patterns + + private: /* you can add additional methods here */ Ntk& _ntk; From eb156855332b7a8ce47b99f0ddf14d61c37a14c4 Mon Sep 17 00:00:00 2001 From: dinanli Date: Fri, 10 Dec 2021 12:31:24 +0100 Subject: [PATCH 4/7] generate pattern (not complete) --- include/mockturtle/algorithms/simulation_cec.hpp | 16 ++++++++++++++++ lib/kitty/kitty/dynamic_truth_table.hpp | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index 9e6274dc0..c8a233d93 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -40,6 +40,8 @@ #include "miter.hpp" #include "simulation.hpp" +#include // used for printing + namespace mockturtle { @@ -93,6 +95,20 @@ class simulation_cec_impl std::cout << "spitting_vars: " << _st.split_var << std::endl; std::cout << "rounds: " << _st.rounds << std::endl; + kitty::dynamic_truth_table pattern( n ); + std::cout << "truth table number of variables: " << pattern.num_vars() << std::endl + << "number of blocks: " << pattern.num_blocks() << std::endl + << "number of bits: " << pattern.num_bits() << std::endl; + + + for (auto i = 0; i < n; i ++) + { + kitty::create_nth_var( pattern, i ); + } + + std::bitset<64> x( pattern._bits[0] ); + std::cout << x << std::endl; + return false; } diff --git a/lib/kitty/kitty/dynamic_truth_table.hpp b/lib/kitty/kitty/dynamic_truth_table.hpp index 9963db4bd..764841ebd 100644 --- a/lib/kitty/kitty/dynamic_truth_table.hpp +++ b/lib/kitty/kitty/dynamic_truth_table.hpp @@ -58,7 +58,7 @@ struct dynamic_truth_table \param num_vars Number of variables */ explicit dynamic_truth_table( uint32_t num_vars ) - : _bits( ( num_vars <= 6 ) ? 1u : ( 1u << ( num_vars - 6 ) ) ), + : _bits( ( num_vars <= 6 ) ? 1u : ( 1u << ( num_vars - 6 ) ) ), // when variable size < 6, store in one block _num_vars( num_vars ) { } From 91e61ca78c6903db3cecb2565ab81a95734f2538 Mon Sep 17 00:00:00 2001 From: dinanli Date: Fri, 10 Dec 2021 12:31:44 +0100 Subject: [PATCH 5/7] short comment --- lib/kitty/kitty/constructors.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/kitty/kitty/constructors.hpp b/lib/kitty/kitty/constructors.hpp index a60b8c45f..cd3ed1b7a 100644 --- a/lib/kitty/kitty/constructors.hpp +++ b/lib/kitty/kitty/constructors.hpp @@ -150,7 +150,8 @@ void create_nth_var( TT& tt, uint8_t var_index, bool complement = false ) /*! \cond PRIVATE */ template -void create_nth_var( static_truth_table& tt, uint8_t var_index, bool complement = false ) +void create_nth_var( static_truth_table& tt, uint8_t var_index, bool complement = false ) +// cast to static truth table, can only have up to six varialbes { /* assign from precomputed table */ tt._bits = complement ? ~detail::projections[var_index] : detail::projections[var_index]; From 9dc98a4b1f95048c787fac2e087ed51286c41dc9 Mon Sep 17 00:00:00 2001 From: dinanli Date: Sun, 12 Dec 2021 13:16:15 +0100 Subject: [PATCH 6/7] First implementation --- include/mockturtle/algorithms/simulation.hpp | 31 ++++++++++++++++--- .../mockturtle/algorithms/simulation_cec.hpp | 22 ++++++++----- lib/kitty/kitty/constructors.hpp | 10 +++--- lib/kitty/kitty/detail/constants.hpp | 4 +-- lib/kitty/kitty/dynamic_truth_table.hpp | 2 +- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/include/mockturtle/algorithms/simulation.hpp b/include/mockturtle/algorithms/simulation.hpp index 2c43d88b3..3d8c60e2e 100644 --- a/include/mockturtle/algorithms/simulation.hpp +++ b/include/mockturtle/algorithms/simulation.hpp @@ -111,7 +111,8 @@ class default_simulator { public: default_simulator() = delete; - default_simulator( unsigned num_vars ) : num_vars( num_vars ) {} + default_simulator( unsigned num_vars, uint32_t split_var = 0, uint32_t round = 0, bool isMiter = false ) : num_vars( num_vars ), split_var(split_var), + round(round), isMiter(isMiter){} kitty::dynamic_truth_table compute_constant( bool value ) const { @@ -121,9 +122,29 @@ class default_simulator kitty::dynamic_truth_table compute_pi( uint32_t index ) const { - kitty::dynamic_truth_table tt( num_vars ); - kitty::create_nth_var( tt, index ); - return tt; + if ( !isMiter ) + { + kitty::dynamic_truth_table tt( num_vars ); + kitty::create_nth_var( tt, index ); + return tt; + } + else + { + kitty::dynamic_truth_table tt( num_vars ); + if ( index < split_var ) + { + kitty::create_nth_var( tt, index ); + } + else + { + bool flag = round >> ( index - split_var ) & 1; + if ( flag ) + { + tt = ~tt; + } + } + return tt; + } } kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const& value ) const @@ -133,6 +154,8 @@ class default_simulator private: unsigned num_vars; + bool isMiter; + uint32_t round, split_var; }; /*! \brief Simulates truth tables. diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index c8a233d93..be97765f5 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -95,21 +95,29 @@ class simulation_cec_impl std::cout << "spitting_vars: " << _st.split_var << std::endl; std::cout << "rounds: " << _st.rounds << std::endl; + // create the pattern with truth table + kitty::dynamic_truth_table pattern( n ); std::cout << "truth table number of variables: " << pattern.num_vars() << std::endl << "number of blocks: " << pattern.num_blocks() << std::endl << "number of bits: " << pattern.num_bits() << std::endl; - - for (auto i = 0; i < n; i ++) + for ( auto i = 0; i < _st.rounds; i++ ) { - kitty::create_nth_var( pattern, i ); + std::cout << "[running] round " << i << std::endl; + default_simulator sim( n, _st.split_var, i, true ); + auto res = simulate( _ntk, sim ); + + for ( auto& po : res ) + { + if ( !kitty::is_const0( po ) ) + { + return false; + } + } } - std::bitset<64> x( pattern._bits[0] ); - std::cout << x << std::endl; - - return false; + return true; } // deriving patterns diff --git a/lib/kitty/kitty/constructors.hpp b/lib/kitty/kitty/constructors.hpp index cd3ed1b7a..e3b6d02b8 100644 --- a/lib/kitty/kitty/constructors.hpp +++ b/lib/kitty/kitty/constructors.hpp @@ -109,7 +109,7 @@ void create_nth_var( TT& tt, uint8_t var_index, bool complement = false ) tt.mask_bits(); return; } - } + } // if partial_truth_table else { if ( tt.num_vars() <= 6 ) @@ -123,13 +123,13 @@ void create_nth_var( TT& tt, uint8_t var_index, bool complement = false ) } } - if ( var_index < 6 ) - { + if ( var_index < 6 ) // if index smaller than six + { // fill in all the bits with the same projection std::fill( std::begin( tt._bits ), std::end( tt._bits ), complement ? ~detail::projections[var_index] : detail::projections[var_index] ); } - else + else { - const auto c = 1 << ( var_index - 6 ); + const auto c = 1 << ( var_index - 6 ); // var_index 7, c 2 const auto zero = uint64_t( 0 ); const auto one = ~zero; auto block = uint64_t( 0u ); diff --git a/lib/kitty/kitty/detail/constants.hpp b/lib/kitty/kitty/detail/constants.hpp index 326044a3c..e5a985ae0 100644 --- a/lib/kitty/kitty/detail/constants.hpp +++ b/lib/kitty/kitty/detail/constants.hpp @@ -43,8 +43,8 @@ namespace detail { static constexpr uint64_t projections[] = { - UINT64_C( 0xaaaaaaaaaaaaaaaa ), - UINT64_C( 0xcccccccccccccccc ), + UINT64_C( 0xaaaaaaaaaaaaaaaa ), // 10101010... + UINT64_C( 0xcccccccccccccccc ), // 11001100... UINT64_C( 0xf0f0f0f0f0f0f0f0 ), UINT64_C( 0xff00ff00ff00ff00 ), UINT64_C( 0xffff0000ffff0000 ), diff --git a/lib/kitty/kitty/dynamic_truth_table.hpp b/lib/kitty/kitty/dynamic_truth_table.hpp index 764841ebd..05cd985f5 100644 --- a/lib/kitty/kitty/dynamic_truth_table.hpp +++ b/lib/kitty/kitty/dynamic_truth_table.hpp @@ -58,7 +58,7 @@ struct dynamic_truth_table \param num_vars Number of variables */ explicit dynamic_truth_table( uint32_t num_vars ) - : _bits( ( num_vars <= 6 ) ? 1u : ( 1u << ( num_vars - 6 ) ) ), // when variable size < 6, store in one block + : _bits( ( num_vars <= 6 ) ? 1u : ( 1u << ( num_vars - 6 ) ) ), // initialize length of _bits _num_vars( num_vars ) { } From 32d01f1201112448392f9409dbd67e13afc6e6cc Mon Sep 17 00:00:00 2001 From: dinanli Date: Thu, 23 Dec 2021 22:03:18 +0100 Subject: [PATCH 7/7] finished implementation --- include/mockturtle/algorithms/simulation.hpp | 27 +----- .../mockturtle/algorithms/simulation_cec.hpp | 92 ++++++++++++------- 2 files changed, 64 insertions(+), 55 deletions(-) diff --git a/include/mockturtle/algorithms/simulation.hpp b/include/mockturtle/algorithms/simulation.hpp index 3d8c60e2e..d475002b4 100644 --- a/include/mockturtle/algorithms/simulation.hpp +++ b/include/mockturtle/algorithms/simulation.hpp @@ -111,8 +111,7 @@ class default_simulator { public: default_simulator() = delete; - default_simulator( unsigned num_vars, uint32_t split_var = 0, uint32_t round = 0, bool isMiter = false ) : num_vars( num_vars ), split_var(split_var), - round(round), isMiter(isMiter){} + default_simulator( unsigned num_vars) : num_vars( num_vars ){} kitty::dynamic_truth_table compute_constant( bool value ) const { @@ -122,30 +121,11 @@ class default_simulator kitty::dynamic_truth_table compute_pi( uint32_t index ) const { - if ( !isMiter ) - { kitty::dynamic_truth_table tt( num_vars ); kitty::create_nth_var( tt, index ); return tt; - } - else - { - kitty::dynamic_truth_table tt( num_vars ); - if ( index < split_var ) - { - kitty::create_nth_var( tt, index ); - } - else - { - bool flag = round >> ( index - split_var ) & 1; - if ( flag ) - { - tt = ~tt; - } - } - return tt; - } - } + } + kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const& value ) const { @@ -545,7 +525,6 @@ node_map simulate_nodes( Ntk const& ntk, Simulator const& s } ); node_to_value[n] = ntk.compute( n, fanin_values.begin(), fanin_values.end() ); } ); - return node_to_value; } diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index be97765f5..b2915f4fe 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -58,6 +58,46 @@ struct simulation_cec_stats namespace detail { +class cec_simulator +{ +public: + cec_simulator(unsigned num_vars, uint32_t split_var, uint32_t round) : num_vars( num_vars ), split_var(split_var), + round(round) {} + + kitty::dynamic_truth_table compute_constant( bool value ) const + { + kitty::dynamic_truth_table tt( split_var ); + return value ? ~tt : tt; + } + + kitty::dynamic_truth_table compute_pi( uint32_t index ) const + { + kitty::dynamic_truth_table tt( split_var ); + if ( index < split_var ) + { + kitty::create_nth_var( tt, index ); + } + else{ + bool flag = round >> ( index - split_var ) & 1; + if ( !flag ) + { + tt = ~tt; + } + } + return tt; + } + + kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const& value ) const + { + return ~value; + } + +private: + unsigned int num_vars; + uint32_t round, split_var; +}; + + template class simulation_cec_impl { @@ -77,36 +117,14 @@ class simulation_cec_impl { /* TODO: write your implementation here */ // computing splitting_var and rounds - auto n = _ntk.num_pis(); - if ( n <= 6 ) - { - _st.split_var = n; - } - else - { - auto V = _ntk.num_gates(); - int max_m = std::log2l( std::pow(2, 29)/ V - 32 ) + 3; - _st.split_var = max_m > n ? n : max_m; - } - - _st.rounds = std::pow(2, n - _st.split_var ); - - std::cout << "pis and nodes: " << _ntk.num_pis() << " " << _ntk.num_gates() << std::endl; - std::cout << "spitting_vars: " << _st.split_var << std::endl; - std::cout << "rounds: " << _st.rounds << std::endl; - + gen_st(); // create the pattern with truth table - kitty::dynamic_truth_table pattern( n ); - std::cout << "truth table number of variables: " << pattern.num_vars() << std::endl - << "number of blocks: " << pattern.num_blocks() << std::endl - << "number of bits: " << pattern.num_bits() << std::endl; - for ( auto i = 0; i < _st.rounds; i++ ) { std::cout << "[running] round " << i << std::endl; - default_simulator sim( n, _st.split_var, i, true ); - auto res = simulate( _ntk, sim ); + cec_simulator sim( _ntk.num_pis(), _st.split_var, i ); + const std::vector res = simulate( _ntk, sim ); for ( auto& po : res ) { @@ -115,19 +133,31 @@ class simulation_cec_impl return false; } } + return true; } - - return true; } - - // deriving patterns - - private: /* you can add additional methods here */ Ntk& _ntk; simulation_cec_stats& _st; /* you can add other attributes here */ + + void gen_st() + { + auto n = _ntk.num_pis(); + if ( n <= 6 ) + { + _st.split_var = n; + } + else + { + auto v = _ntk.size(); + int max_m = std::log2l( std::pow( 2, 29 ) / v - 32 ) + 3; + _st.split_var = max_m > n ? n : max_m; + } + + _st.rounds = std::pow( 2, n - _st.split_var ); + } }; } // namespace detail