Skip to content

Commit

Permalink
Updating command "rungen" to generate random functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanminko committed Nov 28, 2024
1 parent 1f3cf0a commit 14168eb
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 19 deletions.
81 changes: 64 additions & 17 deletions src/base/abci/abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7441,14 +7441,58 @@ int Abc_CommandRunEco( Abc_Frame_t * pAbc, int argc, char ** argv )
***********************************************************************/
int Abc_CommandRunGen( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Acb_NtkRunGen( char * pFileNames[2], int fVerbose );
char * pFileNames[4] = {NULL};
int c, fVerbose = 0;
extern void Acb_NtkRunGen( int nInputs, int nMints, int nFuncs, int Seed, int fVerbose, char * pScript );
int c, nInputs = 10, nMints = 10, nFuncs = 10, Seed = 0, fVerbose = 0; char * pScript = NULL;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "IMRSCvh" ) ) != EOF )
{
switch ( c )
{
case 'I':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
goto usage;
}
nInputs = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
break;
case 'M':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
goto usage;
}
nMints = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
break;
case 'R':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
goto usage;
}
nFuncs = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
break;
case 'S':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
goto usage;
}
Seed = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
break;
case 'C':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-C\" should be followed by a script.\n" );
goto usage;
}
pScript = argv[globalUtilOptind];
globalUtilOptind++;
break;
case 'v':
fVerbose ^= 1;
break;
Expand All @@ -7458,21 +7502,24 @@ int Abc_CommandRunGen( Abc_Frame_t * pAbc, int argc, char ** argv )
goto usage;
}
}
if ( argc - globalUtilOptind != 2 )
if ( pScript == NULL )
{
Abc_Print( 1, "Expecting two file names on the command line.\n" );
goto usage;
Abc_Print( -1, "Command line switch \"-C\" should be specified and followed by a string.\n" );
goto usage;
}
for ( c = 0; c < 2; c++ )
pFileNames[c] = argv[globalUtilOptind+c];
Acb_NtkRunGen( pFileNames, fVerbose );
Acb_NtkRunGen( nInputs, nMints, nFuncs, Seed, fVerbose, pScript );
return 0;

usage:
Abc_Print( -2, "usage: rungen [-vh] <file1> <file2>\n" );
Abc_Print( -2, "\t experimental command\n" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
Abc_Print( -2, "usage: rungen [-IMRS num] [-C script] [-vh]\n" );
Abc_Print( -2, "\t running the script on a set of randomly generated functions\n" );
Abc_Print( -2, "\t-I <num> : the number of input variables [default = %d]\n", nInputs );
Abc_Print( -2, "\t-M <num> : the number of positive minterms in the random function [default = %d]\n", nMints );
Abc_Print( -2, "\t-R <num> : the number of random functions to try [default = %d]\n", nFuncs );
Abc_Print( -2, "\t-S <num> : the random seed [default = %d]\n", Seed );
Abc_Print( -2, "\t-C <num> : the script to apply [default = provided by the user]\n" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}

Expand Down Expand Up @@ -9905,7 +9952,7 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'S':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-S\" should be followed by a file name.\n" );
Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
goto usage;
}
pPars->pSymStr = argv[globalUtilOptind];
Expand All @@ -9914,7 +9961,7 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'R':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-R\" should be followed by a file name.\n" );
Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
goto usage;
}
pPars->nRandFuncs = atoi(argv[globalUtilOptind]);
Expand All @@ -9923,7 +9970,7 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'M':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-M\" should be followed by a file name.\n" );
Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
goto usage;
}
pPars->nMintNum = atoi(argv[globalUtilOptind]);
Expand Down
84 changes: 82 additions & 2 deletions src/base/abci/abcRunGen.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@
***********************************************************************/

#include "base/abc/abc.h"
#include "opt/cut/cut.h"
#include "base/main/main.h"
#include "base/cmd/cmd.h"
#include "misc/util/utilTruth.h"

#ifdef WIN32
#include <process.h>
#define unlink _unlink
#else
#include <unistd.h>
#endif

ABC_NAMESPACE_IMPL_START

Expand All @@ -42,8 +51,79 @@ ABC_NAMESPACE_IMPL_START
SeeAlso []
***********************************************************************/
void Acb_NtkRunGen( char * pFileNames[2], int fVerbose )
int Abc_NtkRunGenOne( Abc_Ntk_t * p, char * pScript )
{
Abc_FrameReplaceCurrentNetwork( Abc_FrameGetGlobalFrame(), p );
if ( Abc_FrameIsBatchMode() )
{
if ( Cmd_CommandExecute(Abc_FrameGetGlobalFrame(), pScript) )
{
Abc_Print( 1, "Something did not work out with the command \"%s\".\n", pScript );
return 0;
}
}
else
{
Abc_FrameSetBatchMode( 1 );
if ( Cmd_CommandExecute(Abc_FrameGetGlobalFrame(), pScript) )
{
Abc_Print( 1, "Something did not work out with the command \"%s\".\n", pScript );
return 0;
}
Abc_FrameSetBatchMode( 0 );
}
Abc_Ntk_t * pTemp = Abc_FrameReadNtk(Abc_FrameGetGlobalFrame());
return Abc_NtkNodeNum(pTemp);
}
void Acb_NtkRunGen( int nInputs, int nMints, int nFuncs, int Seed, int fVerbose, char * pScript )
{
abctime clkStart = Abc_Clock();
Vec_Int_t * vNodes = Vec_IntAlloc( 1000 );
int i, k, nNodes, nWords = Abc_TtWordNum(nInputs);
word * pFun = ABC_ALLOC( word, nWords );
Abc_Ntk_t * pNtkNew; char * pTtStr, * pSop;
Abc_Random(1);
for ( i = 0; i < 10+Seed; i++ )
Abc_Random(0);
printf( "Synthesizing %d random %d-variable functions with %d positive minterms using script \"%s\".\n", nFuncs, nInputs, nMints, pScript );
for ( i = 0; i < nFuncs; i++ )
{
if ( nMints == 0 )
for ( k = 0; k < nWords; k++ )
pFun[k] = Abc_RandomW(0);
else {
Abc_TtClear( pFun, nWords );
for ( k = 0; k < nMints; k++ ) {
int iMint = 0;
do iMint = Abc_Random(0) % (1 << nInputs);
while ( Abc_TtGetBit(pFun, iMint) );
Abc_TtSetBit( pFun, iMint );
}
}
pTtStr = ABC_CALLOC( char, nInputs > 2 ? (1 << (nInputs-2)) + 1 : 2 );
Extra_PrintHexadecimalString( pTtStr, (unsigned *)pFun, nInputs );
pSop = Abc_SopFromTruthHex( pTtStr );
pNtkNew = Abc_NtkCreateWithNode( pSop );
nNodes = Abc_NtkRunGenOne( pNtkNew, pScript );
if ( nNodes >= Vec_IntSize(vNodes) )
Vec_IntSetEntry( vNodes, nNodes, 0 );
Vec_IntAddToEntry( vNodes, nNodes, 1 );

if ( fVerbose ) {
printf( "Iteration %3d : ", i );
printf( "Random function has %d positive minterms ", nMints );
printf( "and maps into %d nodes.\n", nNodes );
if ( fVerbose )
printf( "Truth table : %s\n", pTtStr );
}
ABC_FREE( pTtStr );
ABC_FREE( pSop );
}
Vec_IntForEachEntry( vNodes, i, k )
if ( i )
printf( "Nodes %3d : Functions %3d Ratio %5.2f %%\n", k, i, 100.0*i/nFuncs );
ABC_FREE( pFun );
Abc_PrintTime( 0, "Total time", Abc_Clock() - clkStart );
}

////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 14168eb

Please sign in to comment.