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

Stefania_Valoti_CEC #66

Open
wants to merge 1 commit into
base: v2021-cec
Choose a base branch
from
Open
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
96 changes: 68 additions & 28 deletions include/mockturtle/algorithms/simulation_cec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,70 +26,119 @@
/*!
\file simulation_cec.hpp
\brief Simulation-based CEC

EPFL CS-472 2021 Final Project Option 2
*/

#pragma once

#include <kitty/constructors.hpp>
#include <kitty/dynamic_truth_table.hpp>
#include <kitty/operations.hpp>

#include "../utils/node_map.hpp"
#include "miter.hpp"
#include "simulation.hpp"

namespace mockturtle
{

/* Statistics to be reported */
struct simulation_cec_stats
{
/*! \brief Split variable (simulation size). */
uint32_t split_var{ 0 };

/*! \brief Number of simulation rounds. */
uint32_t round{ 0 };
uint32_t rounds{ 0 };
};

namespace detail
{

///////////////
class new_simulator
{
public:
new_simulator() = delete;
new_simulator(uint32_t num_var, uint32_t split_variable, uint32_t turni) :
num_vars(num_vars), split_variable(split_variable), turni(turni) {}
//already in the normal code
kitty::dynamic_truth_table compute_constant( bool value ) const
{
kitty::dynamic_truth_table tt( split_variable);
return value ? ~tt : tt; // depending if the value of value is true or false we have tt or tt negated bitwise.
}
kitty::dynamic_truth_table compute_pi( uint32_t index ) const
{
kitty::dynamic_truth_table tt(split_variable);
if(index < split_variable) {
kitty::create_nth_var(tt,index);}
else {
if (!((turni >> (index - split_variable)) & 1))
tt=~tt;
}
return tt;
}
kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const & value ) const
{
return ~value;
}
//up already in the normal code except the if-else-if
protected:
uint32_t num_vars;
uint32_t split_variable;
uint32_t turni;
};
/*! \brief Simulates truth tables.
*
* This simulator simulates truth tables. Each primary input is assigned the
* projection function according to the index. The number of variables must be
* known at compile time.
*/
//////////////
template<class Ntk>
class simulation_cec_impl
{
public:
using pattern_t = unordered_node_map<kitty::dynamic_truth_table, Ntk>;
using node = typename Ntk::node;
using signal = typename Ntk::signal;

public:
explicit simulation_cec_impl( Ntk& ntk, simulation_cec_stats& st )
: _ntk( ntk ),
_st( st )
{
}

bool run()
{
/* TODO: write your implementation here */
return false;
if (_ntk.num_pis() <= 6) {
_st.split_var = _ntk.num_pis();
} else {
uint32_t m = 7;
for(; ; m++) {
if (!(m < _ntk.num_pis() && (32 +(pow(2,(m-2))))*_ntk.size() <= pow(2, 29)))
break;
}
_st.split_var = m;
}
_st.rounds = pow(2,_ntk.num_pis() -_st.split_var);
_st.round = _st.rounds;
bool Solution = sim();
return Solution;
}

private:
/* you can add additional methods here */

bool sim() {
for(int k = 0; k < _st.round; k++){
new_simulator new_simulator(_ntk.num_pis(),_st.split_var, k);
const auto tts = simulate<kitty::dynamic_truth_table>(_ntk, new_simulator);
for(auto& po : tts) {
if(!kitty::is_const0(po))
return false;
}
}
return true;
}
private:
Ntk& _ntk;
simulation_cec_stats& _st;
/* you can add other attributes here */
};

} // namespace detail

/* Entry point for users to call */

/*! \brief Simulation-based CEC.
*
* This function implements a simulation-based combinational equivalence checker.
Expand All @@ -99,8 +148,7 @@ class simulation_cec_impl
* if the network has more than 40 inputs.
*/
template<class Ntk>
std::optional<bool> simulation_cec( Ntk const& ntk1, Ntk const& ntk2, simulation_cec_stats* pst = nullptr )
{
std::optional<bool> simulation_cec( Ntk const& ntk1, Ntk const& ntk2, simulation_cec_stats* pst = nullptr ){
static_assert( is_network_type_v<Ntk>, "Ntk is not a network type" );
static_assert( has_num_pis_v<Ntk>, "Ntk does not implement the num_pis method" );
static_assert( has_size_v<Ntk>, "Ntk does not implement the size method" );
Expand All @@ -109,26 +157,18 @@ std::optional<bool> simulation_cec( Ntk const& ntk1, Ntk const& ntk2, simulation
static_assert( has_foreach_po_v<Ntk>, "Ntk does not implement the foreach_po method" );
static_assert( has_foreach_node_v<Ntk>, "Ntk does not implement the foreach_node method" );
static_assert( has_is_complemented_v<Ntk>, "Ntk does not implement the is_complemented method" );

simulation_cec_stats st;

bool result = false;

if ( ntk1.num_pis() > 40 )
return std::nullopt;

auto ntk_miter = miter<Ntk>( ntk1, ntk2 );

if ( ntk_miter.has_value() )
{
detail::simulation_cec_impl p( *ntk_miter, st );
result = p.run();
}

if ( pst )
*pst = st;

return result;
}

} // namespace mockturtle
36 changes: 36 additions & 0 deletions mockturtle.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="mockturtle" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/mockturtle" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/mockturtle" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Extensions />
</Project>
</CodeBlocks_project_file>
5 changes: 5 additions & 0 deletions mockturtle.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
</CodeBlocks_layout_file>
Binary file added obj/Debug/experiments/exact_mc_synthesis.o
Binary file not shown.