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

Renato_gaudioso_cec #64

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
Empty file added .vs/CMake Overview
Empty file.
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "x64-Debug"
}
11 changes: 11 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ExpandedNodes": [
"",
"\\include",
"\\include\\mockturtle",
"\\include\\mockturtle\\algorithms",
"\\test",
"\\test\\algorithms"
],
"PreviewInSolutionExplorer": false
}
Binary file added .vs/mockturtle/v16/.suo
Binary file not shown.
Binary file added .vs/mockturtle/v16/Browse.VC.db
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
24 changes: 0 additions & 24 deletions include/mockturtle/algorithms/simulation.hpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
/* mockturtle: C++ logic network library
* Copyright (C) 2018-2021 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.
*/

/*!
\file simulation.hpp
Expand Down
175 changes: 121 additions & 54 deletions include/mockturtle/algorithms/simulation_cec.hpp
Original file line number Diff line number Diff line change
@@ -1,70 +1,97 @@
/* mockturtle: C++ logic network library
* Copyright (C) 2018-2021 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.
*/

/*!
\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"
#include <cmath>

namespace mockturtle
{

/* Statistics to be reported */
struct simulation_cec_stats
{
/*! \brief Split variable (simulation size). */
struct simulation_cec_stats{
//Here we write Split Variable, that is related to the simulation size



uint32_t split_var{ 0 };

/*! \brief Number of simulation rounds. */

//Number of simulation rounds

uint32_t rounds{ 0 };
};

namespace detail
{
namespace detail{

//start here---------------------------------------------------------------------

class split_var_renato{
public:

unsigned num_variables;

unsigned split_variable;

uint64_t others_round;
//Destructor of the class
split_var_renato() = delete;

//This is the contructor of the class
split_var_renato( unsigned num_variables, unsigned split_variable, uint64_t others_round ) : num_variables( num_variables ), split_variable{ split_variable }, others_round{ others_round } {}

kitty::dynamic_truth_table compute_constant( bool value ) const
{
kitty::dynamic_truth_table tt( split_variable );
return value ? ~tt : tt;
}

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 {

bool value = ( others_round >> ( index - split_variable ) ) & 1;
if ( !value ){
tt = ~tt;


}
}

return tt;
}

kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const& value ) const
{
return ~value;
}

private:


//uint64_t others_round;
};
//finish here --------------------------------------------------
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 )
Expand All @@ -73,31 +100,69 @@ class simulation_cec_impl

bool run()
{
/* TODO: write your implementation here */
return false;

// START HERE ----------------------
unsigned n = _ntk.num_pis();
unsigned split_variable;
unsigned V = _ntk.size();


if ( n <= 6 )
{
split_variable = n;
//or also _st.split_variable
}
else {


int m = 7;
while ( m < n && ( 32 + ( 1 << ( ( m + 1 ) - 3 ) ) ) * V <= 1 << 29 )
{
m++;
}
split_variable = m;
//or _st.split_variable
}

int rounds = 1 << ( n - split_variable );

// I store them in the statistics struct
_st.split_var = split_variable;
_st.rounds = rounds;

// This is the actual simulation...

for ( uint64_t others_round = 0; others_round < rounds; others_round++ )
{ // We iterate over all the possible assignations of the remaining variables
split_var_renato simul( _ntk.num_pis(), split_variable, others_round );
const auto tts = simulate<kitty::dynamic_truth_table>( _ntk, simul );

// const std::vector<kitty::dynamic_truth_table> tts
for ( auto& po : tts )
{
if ( !kitty::is_const0( po ) )
{
return false;
}
}
}

return true;
}


//FINISH HERE ---------------------------

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

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.
* The implementation creates a miter network and run several rounds of simulation
* to verify the functional equivalence. For memory and speed reasons this approach
* is limited up to 40 input networks. It returns an optional which is `nullopt`,
* 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 )
{
Expand Down Expand Up @@ -131,4 +196,6 @@ std::optional<bool> simulation_cec( Ntk const& ntk1, Ntk const& ntk2, simulation
return result;
}

} // namespace mockturtle


}