Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
38 changes: 38 additions & 0 deletions docs/algorithms/pattern_generation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Expressive simulation pattern generation
----------------------------------------

**Header:** ``mockturtle/algorithms/pattern_generation.hpp``

The following example shows how to generate expressive simulation patterns
for an AIG network. It starts with 256 random patterns, generates stuck-at
patterns to make every node's signature has at least 3 bits of 0 and 3 bits
of 1 which are observable at at least 5 levels of fan-out. The generated
patterns are then written out to a file.

.. code-block:: c++

/* derive some AIG */
aig_network aig = ...;

pattern_generation_params ps;
ps.num_stuck_at = 3;
ps.odc_levels = 5;

partial_simulator sim( aig.num_pis(), 256 );
pattern_generation( aig, sim, ps );
write_patterns( sim, "patterns.pat" );


Parameters and statistics
~~~~~~~~~~~~~~~~~~~~~~~~~

.. doxygenstruct:: mockturtle::pattern_generation_params
:members:

.. doxygenstruct:: mockturtle::pattern_generation_stats
:members:

Algorithm
~~~~~~~~~

.. doxygenfunction:: mockturtle::pattern_generation
2 changes: 1 addition & 1 deletion docs/algorithms/simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Note that currently only AIG and XAG are supported.

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

.. doxygenfunction:: mockturtle::partial_simulator::write_patterns( const std::string& )
.. doxygenfunction:: mockturtle::partial_simulator::get_patterns()

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

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Welcome to mockturtle's documentation!
algorithms/xmg_optimization
algorithms/equivalence_classes
algorithms/circuit_validator
algorithms/pattern_generation

.. toctree::
:maxdepth: 2
Expand Down
9 changes: 9 additions & 0 deletions docs/io/writers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ Write into DOT files (Graphviz)
.. doxygenfunction:: mockturtle::write_dot(Ntk const&, std::string const&, Drawer const&)

.. doxygenfunction:: mockturtle::write_dot(Ntk const&, std::ostream&, Drawer const&)

Write simulation patterns into file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Header:** ``mockturtle/io/write_patterns.hpp``

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

.. doxygenfunction:: mockturtle::write_patterns(partial_simulator const&, std::ostream&)
67 changes: 67 additions & 0 deletions experiments/pattern_generation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* mockturtle: C++ logic network library
* Copyright (C) 2018-2020 EPFL
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include <string>
#include <vector>

#include <fmt/format.h>
#include <lorina/aiger.hpp>
#include <mockturtle/algorithms/simulation.hpp>
#include <mockturtle/algorithms/pattern_generation.hpp>
#include <mockturtle/algorithms/cleanup.hpp>
#include <mockturtle/io/aiger_reader.hpp>
#include <mockturtle/networks/aig.hpp>

#include <experiments.hpp>

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

experiment<std::string, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, float, float, float> exp( "pattern_generation", "benchmark", "#PI", "size", "#pat", "#pat gen", "#const", "t_total", "t_sim", "t_SAT" );

for ( auto const& benchmark : epfl_benchmarks() )
{
fmt::print( "[i] processing {}\n", benchmark );
aig_network aig;
lorina::read_aiger( benchmark_path( benchmark ), aiger_reader( aig ) );
auto size_before = aig.num_gates();

pattern_generation_params ps;
pattern_generation_stats st;

uint32_t num_random_pattern = 1000;
partial_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 ) );
}

exp.save();
exp.table();

return 0;
}
227 changes: 227 additions & 0 deletions experiments/pattern_generation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
[
{
"entries": [
{
"#PI": 256,
"#const": 0,
"#pat": 1000,
"#pat gen": 0,
"benchmark": "adder",
"size": 1020,
"t_SAT": 0.0,
"t_sim": 0.002587138907983899,
"t_total": 0.0027476809918880463
},
{
"#PI": 135,
"#const": 0,
"#pat": 1000,
"#pat gen": 0,
"benchmark": "bar",
"size": 3336,
"t_SAT": 0.0,
"t_sim": 0.011206761002540588,
"t_total": 0.012046649120748043
},
{
"#PI": 128,
"#const": 8,
"#pat": 1039,
"#pat gen": 39,
"benchmark": "div",
"size": 57247,
"t_SAT": 0.23106683790683746,
"t_sim": 0.3988635838031769,
"t_total": 0.6502119302749634
},
{
"#PI": 256,
"#const": 2,
"#pat": 1003,
"#pat gen": 3,
"benchmark": "hyp",
"size": 214335,
"t_SAT": 0.00014847799320705235,
"t_sim": 0.6856793761253357,
"t_total": 0.7315340042114258
},
{
"#PI": 32,
"#const": 162,
"#pat": 1093,
"#pat gen": 93,
"benchmark": "log2",
"size": 32060,
"t_SAT": 23.7200870513916,
"t_sim": 0.4002784192562103,
"t_total": 24.13776969909668
},
{
"#PI": 512,
"#const": 0,
"#pat": 1000,
"#pat gen": 0,
"benchmark": "max",
"size": 2865,
"t_SAT": 0.0,
"t_sim": 0.006821795832365751,
"t_total": 0.007972832769155502
},
{
"#PI": 128,
"#const": 0,
"#pat": 1008,
"#pat gen": 8,
"benchmark": "multiplier",
"size": 27062,
"t_SAT": 0.0003024929901584983,
"t_sim": 0.12204926460981369,
"t_total": 0.13171681761741638
},
{
"#PI": 24,
"#const": 19,
"#pat": 1049,
"#pat gen": 49,
"benchmark": "sin",
"size": 5416,
"t_SAT": 0.7237713932991028,
"t_sim": 0.06233770772814751,
"t_total": 0.788311243057251
},
{
"#PI": 128,
"#const": 0,
"#pat": 1000,
"#pat gen": 0,
"benchmark": "sqrt",
"size": 24618,
"t_SAT": 0.0,
"t_sim": 0.04817450791597366,
"t_total": 0.05268986523151398
},
{
"#PI": 64,
"#const": 0,
"#pat": 1003,
"#pat gen": 3,
"benchmark": "square",
"size": 18484,
"t_SAT": 6.385899905581027e-05,
"t_sim": 0.060539085417985916,
"t_total": 0.06628058850765228
},
{
"#PI": 256,
"#const": 0,
"#pat": 1005,
"#pat gen": 5,
"benchmark": "arbiter",
"size": 11839,
"t_SAT": 0.00031487300293520093,
"t_sim": 0.027791135013103485,
"t_total": 0.02998867630958557
},
{
"#PI": 10,
"#const": 0,
"#pat": 1007,
"#pat gen": 7,
"benchmark": "cavlc",
"size": 693,
"t_SAT": 0.0001512260059826076,
"t_sim": 0.0024142060428857803,
"t_total": 0.0027767519932240248
},
{
"#PI": 7,
"#const": 0,
"#pat": 1008,
"#pat gen": 8,
"benchmark": "ctrl",
"size": 174,
"t_SAT": 0.00011831099982373416,
"t_sim": 0.0005374409956857562,
"t_total": 0.0007138170185498893
},
{
"#PI": 8,
"#const": 0,
"#pat": 1206,
"#pat gen": 206,
"benchmark": "dec",
"size": 304,
"t_SAT": 0.003572395071387291,
"t_sim": 0.004423268139362335,
"t_total": 0.008258773013949394
},
{
"#PI": 147,
"#const": 0,
"#pat": 1039,
"#pat gen": 39,
"benchmark": "i2c",
"size": 1342,
"t_SAT": 0.0019028210081160069,
"t_sim": 0.007990111596882343,
"t_total": 0.010547489859163761
},
{
"#PI": 11,
"#const": 0,
"#pat": 1003,
"#pat gen": 3,
"benchmark": "int2float",
"size": 260,
"t_SAT": 0.00011678999726427719,
"t_sim": 0.0013045240193605423,
"t_total": 0.0015592729905620217
},
{
"#PI": 1204,
"#const": 1,
"#pat": 1406,
"#pat gen": 406,
"benchmark": "mem_ctrl",
"size": 46836,
"t_SAT": 0.12108956277370453,
"t_sim": 0.6603772640228271,
"t_total": 0.8064870834350586
},
{
"#PI": 128,
"#const": 0,
"#pat": 1001,
"#pat gen": 1,
"benchmark": "priority",
"size": 978,
"t_SAT": 5.066599987912923e-05,
"t_sim": 0.001871931948699057,
"t_total": 0.002103254897519946
},
{
"#PI": 60,
"#const": 0,
"#pat": 1046,
"#pat gen": 46,
"benchmark": "router",
"size": 257,
"t_SAT": 0.0015393260400742292,
"t_sim": 0.004502872005105019,
"t_total": 0.006205921061336994
},
{
"#PI": 1001,
"#const": 4,
"#pat": 1009,
"#pat gen": 9,
"benchmark": "voter",
"size": 13758,
"t_SAT": 1.8260704278945923,
"t_sim": 0.14073464274406433,
"t_total": 1.9711337089538574
}
],
"version": "b8503a5"
}
]
Loading