mirror of https://github.com/YosysHQ/abc.git
Adding commands to generate data for experiments.
This commit is contained in:
parent
b1802e4fdc
commit
3c586f886e
|
|
@ -4863,6 +4863,10 @@ SOURCE=.\src\aig\gia\giaFx.c
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\src\aig\gia\giaGen.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\src\aig\gia\giaGig.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
|
|||
|
|
@ -0,0 +1,426 @@
|
|||
/**CFile****************************************************************
|
||||
|
||||
FileName [giaGen.c]
|
||||
|
||||
SystemName [ABC: Logic synthesis and verification system.]
|
||||
|
||||
PackageName [Scalable AIG package.]
|
||||
|
||||
Synopsis []
|
||||
|
||||
Author [Alan Mishchenko]
|
||||
|
||||
Affiliation [UC Berkeley]
|
||||
|
||||
Date [Ver. 1.0. Started - June 20, 2005.]
|
||||
|
||||
Revision [$Id: giaGen.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
#include "gia.h"
|
||||
#include "misc/util/utilTruth.h"
|
||||
|
||||
ABC_NAMESPACE_IMPL_START
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// DECLARATIONS ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// FUNCTION DEFINITIONS ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Populate internal simulation info.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
static inline word * Gia_ManObjSim( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
return Vec_WrdEntryP( p->vSims, p->nSimWords * iObj );
|
||||
}
|
||||
static inline void Gia_ManObjSimPi( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
int w;
|
||||
word * pSim = Gia_ManObjSim( p, iObj );
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = Gia_ManRandomW( 0 );
|
||||
// pSim[0] <<= 1;
|
||||
}
|
||||
static inline void Gia_ManObjSimPo( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
int w;
|
||||
Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
|
||||
word * pSimCo = Gia_ManObjSim( p, iObj );
|
||||
word * pSimDri = Gia_ManObjSim( p, Gia_ObjFaninId0(pObj, iObj) );
|
||||
if ( Gia_ObjFaninC0(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSimCo[w] = ~pSimDri[w];
|
||||
else
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSimCo[w] = pSimDri[w];
|
||||
}
|
||||
static inline void Gia_ManObjSimAnd( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
int w;
|
||||
Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
|
||||
word * pSim = Gia_ManObjSim( p, iObj );
|
||||
word * pSim0 = Gia_ManObjSim( p, Gia_ObjFaninId0(pObj, iObj) );
|
||||
word * pSim1 = Gia_ManObjSim( p, Gia_ObjFaninId1(pObj, iObj) );
|
||||
if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = ~pSim0[w] & ~pSim1[w];
|
||||
else if ( Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = ~pSim0[w] & pSim1[w];
|
||||
else if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = pSim0[w] & ~pSim1[w];
|
||||
else
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = pSim0[w] & pSim1[w];
|
||||
}
|
||||
int Gia_ManSimulateWords( Gia_Man_t * p, int nWords )
|
||||
{
|
||||
Gia_Obj_t * pObj; int i;
|
||||
// allocate simulation info for one timeframe
|
||||
Vec_WrdFreeP( &p->vSims );
|
||||
p->vSims = Vec_WrdStart( Gia_ManObjNum(p) * nWords );
|
||||
p->nSimWords = nWords;
|
||||
// perform simulation
|
||||
Gia_ManForEachObj1( p, pObj, i )
|
||||
{
|
||||
if ( Gia_ObjIsAnd(pObj) )
|
||||
Gia_ManObjSimAnd( p, i );
|
||||
else if ( Gia_ObjIsCi(pObj) )
|
||||
Gia_ManObjSimPi( p, i );
|
||||
else if ( Gia_ObjIsCo(pObj) )
|
||||
Gia_ManObjSimPo( p, i );
|
||||
else assert( 0 );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Gia_ManSimulateWordsInit( Gia_Man_t * p, Vec_Wrd_t * vSimsIn )
|
||||
{
|
||||
Gia_Obj_t * pObj; int i, Id;
|
||||
int nWords = Vec_WrdSize(vSimsIn) / Gia_ManCiNum(p);
|
||||
assert( Vec_WrdSize(vSimsIn) == nWords * Gia_ManCiNum(p) );
|
||||
// allocate simulation info for one timeframe
|
||||
Vec_WrdFreeP( &p->vSims );
|
||||
p->vSims = Vec_WrdStart( Gia_ManObjNum(p) * nWords );
|
||||
p->nSimWords = nWords;
|
||||
// set input sim info
|
||||
Gia_ManForEachCiId( p, Id, i )
|
||||
memcpy( Vec_WrdEntryP(p->vSims, Id*nWords), Vec_WrdEntryP(vSimsIn, i*nWords), sizeof(word)*nWords );
|
||||
// perform simulation
|
||||
Gia_ManForEachObj1( p, pObj, i )
|
||||
{
|
||||
if ( Gia_ObjIsAnd(pObj) )
|
||||
Gia_ManObjSimAnd( p, i );
|
||||
else if ( Gia_ObjIsCi(pObj) )
|
||||
continue;
|
||||
else if ( Gia_ObjIsCo(pObj) )
|
||||
Gia_ManObjSimPo( p, i );
|
||||
else assert( 0 );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Dump data files.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Gia_ManDumpFiles( Gia_Man_t * p, int nCexesT, int nCexesV, int Seed, char * pFileName )
|
||||
{
|
||||
int n, nSize[2] = {nCexesT*64, nCexesV*64};
|
||||
|
||||
char pFileNameOutTX[100];
|
||||
char pFileNameOutTY[100];
|
||||
char pFileNameOutVX[100];
|
||||
char pFileNameOutVY[100];
|
||||
|
||||
sprintf( pFileNameOutTX, "data/train_%s_%d_%d.data", pFileName ? pFileName : Gia_ManName(p), nSize[0], Gia_ManCiNum(p) );
|
||||
sprintf( pFileNameOutTY, "data/train_%s_%d_%d.data", pFileName ? pFileName : Gia_ManName(p), nSize[0], Gia_ManCoNum(p) );
|
||||
sprintf( pFileNameOutVX, "data/test_%s_%d_%d.data", pFileName ? pFileName : Gia_ManName(p), nSize[1], Gia_ManCiNum(p) );
|
||||
sprintf( pFileNameOutVY, "data/test_%s_%d_%d.data", pFileName ? pFileName : Gia_ManName(p), nSize[1], Gia_ManCoNum(p) );
|
||||
|
||||
Gia_ManRandomW( 1 );
|
||||
for ( n = 0; n < Seed; n++ )
|
||||
Gia_ManRandomW( 0 );
|
||||
for ( n = 0; n < 2; n++ )
|
||||
{
|
||||
int Res = Gia_ManSimulateWords( p, nSize[n] );
|
||||
|
||||
Vec_Bit_t * vBitX = Vec_BitAlloc( nSize[n] * Gia_ManCiNum(p) );
|
||||
Vec_Bit_t * vBitY = Vec_BitAlloc( nSize[n] * Gia_ManCoNum(p) );
|
||||
|
||||
FILE * pFileOutX = fopen( n ? pFileNameOutVX : pFileNameOutTX, "wb" );
|
||||
FILE * pFileOutY = fopen( n ? pFileNameOutVY : pFileNameOutTY, "wb" );
|
||||
|
||||
int i, k, Id, Num, Value, nBytes;
|
||||
for ( k = 0; k < nSize[n]; k++ )
|
||||
{
|
||||
Gia_ManForEachCiId( p, Id, i )
|
||||
{
|
||||
Vec_BitPush( vBitX, Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
//printf( "%d", Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
}
|
||||
//printf( " " );
|
||||
Gia_ManForEachCoId( p, Id, i )
|
||||
{
|
||||
Vec_BitPush( vBitY, Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
//printf( "%d", Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
}
|
||||
//printf( "\n" );
|
||||
}
|
||||
assert( Vec_BitSize(vBitX) <= Vec_BitCap(vBitX) );
|
||||
assert( Vec_BitSize(vBitY) <= Vec_BitCap(vBitY) );
|
||||
|
||||
Num = 2; Value = fwrite( &Num, 1, 4, pFileOutX ); assert( Value == 4 );
|
||||
Num = nSize[n]; Value = fwrite( &Num, 1, 4, pFileOutX ); assert( Value == 4 );
|
||||
Num = Gia_ManCiNum(p); Value = fwrite( &Num, 1, 4, pFileOutX ); assert( Value == 4 );
|
||||
|
||||
nBytes = nSize[n] * Gia_ManCiNum(p) / 8;
|
||||
assert( nSize[n] * Gia_ManCiNum(p) % 8 == 0 );
|
||||
Value = fwrite( Vec_BitArray(vBitX), 1, nBytes, pFileOutX );
|
||||
assert( Value == nBytes );
|
||||
|
||||
Num = 2; Value = fwrite( &Num, 1, 4, pFileOutY ); assert( Value == 4 );
|
||||
Num = nSize[n]; Value = fwrite( &Num, 1, 4, pFileOutY ); assert( Value == 4 );
|
||||
Num = Gia_ManCoNum(p); Value = fwrite( &Num, 1, 4, pFileOutY ); assert( Value == 4 );
|
||||
|
||||
nBytes = nSize[n] * Gia_ManCoNum(p) / 8;
|
||||
assert( nSize[n] * Gia_ManCoNum(p) % 8 == 0 );
|
||||
Value = fwrite( Vec_BitArray(vBitY), 1, nBytes, pFileOutY );
|
||||
assert( Value == nBytes );
|
||||
|
||||
fclose( pFileOutX );
|
||||
fclose( pFileOutY );
|
||||
|
||||
Vec_BitFree( vBitX );
|
||||
Vec_BitFree( vBitY );
|
||||
|
||||
Res = 0;
|
||||
}
|
||||
printf( "Finished dumping files \"%s\" and \"%s\".\n", pFileNameOutTX, pFileNameOutTY );
|
||||
printf( "Finished dumping files \"%s\" and \"%s\".\n", pFileNameOutVX, pFileNameOutVY );
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Dump data files.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Gia_ManDumpPlaFiles( Gia_Man_t * p, int nCexesT, int nCexesV, int Seed, char * pFileName )
|
||||
{
|
||||
int n, nSize[2] = {nCexesT*64, nCexesV*64};
|
||||
|
||||
char pFileNameOutT[100];
|
||||
char pFileNameOutV[100];
|
||||
|
||||
sprintf( pFileNameOutT, "data/train_%s_%d.pla", pFileName ? pFileName : Gia_ManName(p), nSize[0], Gia_ManCiNum(p) );
|
||||
sprintf( pFileNameOutV, "data/test_%s_%d.pla", pFileName ? pFileName : Gia_ManName(p), nSize[1], Gia_ManCiNum(p) );
|
||||
|
||||
Gia_ManRandomW( 1 );
|
||||
for ( n = 0; n < Seed; n++ )
|
||||
Gia_ManRandomW( 0 );
|
||||
for ( n = 0; n < 2; n++ )
|
||||
{
|
||||
int Res = Gia_ManSimulateWords( p, nSize[n] );
|
||||
int i, k, Id;
|
||||
|
||||
FILE * pFileOut = fopen( n ? pFileNameOutV : pFileNameOutT, "wb" );
|
||||
|
||||
fprintf( pFileOut, ".i %d\n", Gia_ManCiNum(p) );
|
||||
fprintf( pFileOut, ".o %d\n", Gia_ManCoNum(p) );
|
||||
fprintf( pFileOut, ".p %d\n", nSize[n] );
|
||||
for ( k = 0; k < nSize[n]; k++ )
|
||||
{
|
||||
Gia_ManForEachCiId( p, Id, i )
|
||||
{
|
||||
//Vec_BitPush( vBitX, Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
fprintf( pFileOut, "%d", Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
}
|
||||
fprintf( pFileOut, " " );
|
||||
Gia_ManForEachCoId( p, Id, i )
|
||||
{
|
||||
//Vec_BitPush( vBitY, Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
fprintf( pFileOut, "%d", Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
}
|
||||
fprintf( pFileOut, "\n" );
|
||||
}
|
||||
fprintf( pFileOut, ".e\n" );
|
||||
|
||||
fclose( pFileOut );
|
||||
|
||||
Res = 0;
|
||||
}
|
||||
printf( "Finished dumping files \"%s\" and \"%s\".\n", pFileNameOutT, pFileNameOutV );
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Gia_ManSimParamRead( char * pFileName, int * pnIns, int * pnWords )
|
||||
{
|
||||
int c, nIns = -1, nLines = 0, Count = 0, fReadDot = 0;
|
||||
FILE * pFile = fopen( pFileName, "rb" );
|
||||
if ( pFile == NULL )
|
||||
{
|
||||
printf( "Cannot open file \"%s\" for reading.\n", pFileName );
|
||||
return 0;
|
||||
}
|
||||
while ( (c = fgetc(pFile)) != EOF )
|
||||
{
|
||||
if ( c == '.' )
|
||||
fReadDot = 1;
|
||||
if ( c == '\n' )
|
||||
{
|
||||
if ( !fReadDot )
|
||||
{
|
||||
if ( nIns == -1 )
|
||||
nIns = Count;
|
||||
else if ( nIns != Count )
|
||||
{
|
||||
printf( "The number of symbols (%d) does not match other lines (%d).\n", Count, nIns );
|
||||
fclose( pFile );
|
||||
return 0;
|
||||
}
|
||||
Count = 0;
|
||||
nLines++;
|
||||
}
|
||||
fReadDot = 0;
|
||||
}
|
||||
if ( fReadDot )
|
||||
continue;
|
||||
if ( c != '0' && c != '1' )
|
||||
continue;
|
||||
Count++;
|
||||
}
|
||||
if ( nLines % 64 > 0 )
|
||||
{
|
||||
printf( "The number of lines (%d) is not divisible by 64.\n", nLines );
|
||||
fclose( pFile );
|
||||
return 0;
|
||||
}
|
||||
*pnIns = nIns - 1;
|
||||
*pnWords = nLines / 64;
|
||||
//printf( "Expecting %d inputs and %d words of simulation data.\n", *pnIns, *pnWords );
|
||||
return 1;
|
||||
}
|
||||
void Gia_ManSimFileRead( char * pFileName, int nIns, int nWords, Vec_Wrd_t * vSimsIn, Vec_Int_t * vValues )
|
||||
{
|
||||
int c, nPats = 0, Count = 0, fReadDot = 0;
|
||||
FILE * pFile = fopen( pFileName, "rb" );
|
||||
if ( pFile == NULL )
|
||||
{
|
||||
printf( "Cannot open file \"%s\" for reading.\n", pFileName );
|
||||
return;
|
||||
}
|
||||
assert( Vec_WrdSize(vSimsIn) % nWords == 0 );
|
||||
while ( (c = fgetc(pFile)) != EOF )
|
||||
{
|
||||
if ( c == '.' )
|
||||
fReadDot = 1;
|
||||
if ( c == '\n' )
|
||||
fReadDot = 0;
|
||||
if ( fReadDot )
|
||||
continue;
|
||||
if ( c != '0' && c != '1' )
|
||||
continue;
|
||||
if ( Count == nIns )
|
||||
{
|
||||
Vec_IntPush( vValues, c - '0' );
|
||||
Count = 0;
|
||||
nPats++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( c == '1' )
|
||||
Abc_TtSetBit( Vec_WrdEntryP(vSimsIn, Count * nWords), nPats );
|
||||
Count++;
|
||||
}
|
||||
}
|
||||
assert( nPats == 64*nWords );
|
||||
fclose( pFile );
|
||||
printf( "Read %d simulation patterns for %d inputs.\n", 64*nWords, nIns );
|
||||
}
|
||||
void Gia_ManCompareValues( Gia_Man_t * p, Vec_Wrd_t * vSimsIn, Vec_Int_t * vValues )
|
||||
{
|
||||
int i, Value, Count = 0, nWords = Vec_WrdSize(vSimsIn) / Gia_ManCiNum(p);
|
||||
word * pSims;
|
||||
assert( Vec_IntSize(vValues) == nWords * 64 );
|
||||
Gia_ManSimulateWordsInit( p, vSimsIn );
|
||||
assert( p->nSimWords == nWords );
|
||||
pSims = Gia_ManObjSim( p, Gia_ObjId(p, Gia_ManCo(p, 0)) );
|
||||
Vec_IntForEachEntry( vValues, Value, i )
|
||||
if ( Abc_TtGetBit(pSims, i) == Value )
|
||||
Count++;
|
||||
printf( "Total = %6d. Errors = %6d. Correct = %6d. (%6.2f %%)\n",
|
||||
Vec_IntSize(vValues), Vec_IntSize(vValues) - Count, Count, 100.0*Count/Vec_IntSize(vValues) );
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName )
|
||||
{
|
||||
Vec_Wrd_t * vSimsIn;
|
||||
Vec_Int_t * vValues;
|
||||
int nIns, nWords;
|
||||
if ( !Gia_ManSimParamRead( pFileName, &nIns, &nWords ) )
|
||||
return;
|
||||
vSimsIn = Vec_WrdStart( nIns * nWords );
|
||||
vValues = Vec_IntAlloc( nWords * 64 );
|
||||
Gia_ManSimFileRead( pFileName, nIns, nWords, vSimsIn, vValues );
|
||||
Gia_ManCompareValues( p, vSimsIn, vValues );
|
||||
Vec_WrdFree( vSimsIn );
|
||||
Vec_IntFree( vValues );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// END OF FILE ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
ABC_NAMESPACE_IMPL_END
|
||||
|
||||
|
|
@ -2221,167 +2221,6 @@ void Gia_ManUpdateCopy( Vec_Int_t * vCopy, Gia_Man_t * p )
|
|||
}
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Populate internal simulation info.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
static inline word * Gia_ManObjSim( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
return Vec_WrdEntryP( p->vSims, p->nSimWords * iObj );
|
||||
}
|
||||
static inline void Gia_ManObjSimPi( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
int w;
|
||||
word * pSim = Gia_ManObjSim( p, iObj );
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = Gia_ManRandomW( 0 );
|
||||
// pSim[0] <<= 1;
|
||||
}
|
||||
static inline void Gia_ManObjSimPo( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
int w;
|
||||
Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
|
||||
word * pSimCo = Gia_ManObjSim( p, iObj );
|
||||
word * pSimDri = Gia_ManObjSim( p, Gia_ObjFaninId0(pObj, iObj) );
|
||||
if ( Gia_ObjFaninC0(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSimCo[w] = ~pSimDri[w];
|
||||
else
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSimCo[w] = pSimDri[w];
|
||||
}
|
||||
static inline void Gia_ManObjSimAnd( Gia_Man_t * p, int iObj )
|
||||
{
|
||||
int w;
|
||||
Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
|
||||
word * pSim = Gia_ManObjSim( p, iObj );
|
||||
word * pSim0 = Gia_ManObjSim( p, Gia_ObjFaninId0(pObj, iObj) );
|
||||
word * pSim1 = Gia_ManObjSim( p, Gia_ObjFaninId1(pObj, iObj) );
|
||||
if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = ~pSim0[w] & ~pSim1[w];
|
||||
else if ( Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = ~pSim0[w] & pSim1[w];
|
||||
else if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = pSim0[w] & ~pSim1[w];
|
||||
else
|
||||
for ( w = 0; w < p->nSimWords; w++ )
|
||||
pSim[w] = pSim0[w] & pSim1[w];
|
||||
}
|
||||
int Gia_ManSimulateWords( Gia_Man_t * p, int nWords )
|
||||
{
|
||||
Gia_Obj_t * pObj; int i;
|
||||
// allocate simulation info for one timeframe
|
||||
Vec_WrdFreeP( &p->vSims );
|
||||
p->vSims = Vec_WrdStart( Gia_ManObjNum(p) * nWords );
|
||||
p->nSimWords = nWords;
|
||||
// perform simulation
|
||||
Gia_ManForEachObj1( p, pObj, i )
|
||||
{
|
||||
if ( Gia_ObjIsAnd(pObj) )
|
||||
Gia_ManObjSimAnd( p, i );
|
||||
else if ( Gia_ObjIsCi(pObj) )
|
||||
Gia_ManObjSimPi( p, i );
|
||||
else if ( Gia_ObjIsCo(pObj) )
|
||||
Gia_ManObjSimPo( p, i );
|
||||
else assert( 0 );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Dump data files.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Gia_ManDumpFiles( Gia_Man_t * p, int nCexesT, int nCexesV )
|
||||
{
|
||||
int n, nSize[2] = {nCexesT*64, nCexesV*64};
|
||||
|
||||
char pFileNameOutTX[100];
|
||||
char pFileNameOutTY[100];
|
||||
char pFileNameOutVX[100];
|
||||
char pFileNameOutVY[100];
|
||||
|
||||
sprintf( pFileNameOutTX, "data/%s_%d_%d.data", Gia_ManName(p), nSize[0], Gia_ManCiNum(p) );
|
||||
sprintf( pFileNameOutTY, "data/%s_%d_%d.data", Gia_ManName(p), nSize[0], Gia_ManCoNum(p) );
|
||||
sprintf( pFileNameOutVX, "data/%s_%d_%d.data", Gia_ManName(p), nSize[1], Gia_ManCiNum(p) );
|
||||
sprintf( pFileNameOutVY, "data/%s_%d_%d.data", Gia_ManName(p), nSize[1], Gia_ManCoNum(p) );
|
||||
|
||||
Gia_ManRandomW( 1 );
|
||||
for ( n = 0; n < 2; n++ )
|
||||
{
|
||||
int Res = Gia_ManSimulateWords( p, nSize[n] );
|
||||
|
||||
Vec_Bit_t * vBitX = Vec_BitAlloc( nSize[n] * Gia_ManCiNum(p) );
|
||||
Vec_Bit_t * vBitY = Vec_BitAlloc( nSize[n] * Gia_ManCoNum(p) );
|
||||
|
||||
FILE * pFileOutX = fopen( n ? pFileNameOutVX : pFileNameOutTX, "wb" );
|
||||
FILE * pFileOutY = fopen( n ? pFileNameOutVY : pFileNameOutTY, "wb" );
|
||||
|
||||
int i, k, Id, Num, Value, nBytes;
|
||||
for ( k = 0; k < nSize[n]; k++ )
|
||||
{
|
||||
Gia_ManForEachCiId( p, Id, i )
|
||||
{
|
||||
Vec_BitPush( vBitX, Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
//printf( "%d", Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
}
|
||||
//printf( " " );
|
||||
Gia_ManForEachCoId( p, Id, i )
|
||||
{
|
||||
Vec_BitPush( vBitY, Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
//printf( "%d", Abc_TtGetBit(Gia_ManObjSim(p, Id), k) );
|
||||
}
|
||||
//printf( "\n" );
|
||||
}
|
||||
assert( Vec_BitSize(vBitX) <= Vec_BitCap(vBitX) );
|
||||
assert( Vec_BitSize(vBitY) <= Vec_BitCap(vBitY) );
|
||||
|
||||
Num = 2; Value = fwrite( &Num, 1, 4, pFileOutX ); assert( Value == 4 );
|
||||
Num = nSize[n]; Value = fwrite( &Num, 1, 4, pFileOutX ); assert( Value == 4 );
|
||||
Num = Gia_ManCiNum(p); Value = fwrite( &Num, 1, 4, pFileOutX ); assert( Value == 4 );
|
||||
|
||||
nBytes = nSize[n] * Gia_ManCiNum(p) / 8;
|
||||
assert( nSize[n] * Gia_ManCiNum(p) % 8 == 0 );
|
||||
Value = fwrite( Vec_BitArray(vBitX), 1, nBytes, pFileOutX );
|
||||
assert( Value == nBytes );
|
||||
|
||||
Num = 2; Value = fwrite( &Num, 1, 4, pFileOutY ); assert( Value == 4 );
|
||||
Num = nSize[n]; Value = fwrite( &Num, 1, 4, pFileOutY ); assert( Value == 4 );
|
||||
Num = Gia_ManCoNum(p); Value = fwrite( &Num, 1, 4, pFileOutY ); assert( Value == 4 );
|
||||
|
||||
nBytes = nSize[n] * Gia_ManCoNum(p) / 8;
|
||||
assert( nSize[n] * Gia_ManCoNum(p) % 8 == 0 );
|
||||
Value = fwrite( Vec_BitArray(vBitY), 1, nBytes, pFileOutY );
|
||||
assert( Value == nBytes );
|
||||
|
||||
fclose( pFileOutX );
|
||||
fclose( pFileOutY );
|
||||
|
||||
Vec_BitFree( vBitX );
|
||||
Vec_BitFree( vBitY );
|
||||
|
||||
Res = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
|
@ -2449,6 +2288,7 @@ Gia_Man_t * Gia_ManDupWithMuxPos( Gia_Man_t * p )
|
|||
return pNew;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// END OF FILE ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ SRC += src/aig/gia/giaAig.c \
|
|||
src/aig/gia/giaFrames.c \
|
||||
src/aig/gia/giaFront.c \
|
||||
src/aig/gia/giaFx.c \
|
||||
src/aig/gia/giaGen.c \
|
||||
src/aig/gia/giaGig.c \
|
||||
src/aig/gia/giaGlitch.c \
|
||||
src/aig/gia/giaHash.c \
|
||||
|
|
|
|||
|
|
@ -411,6 +411,8 @@ static int Abc_CommandAbc9Trim ( Abc_Frame_t * pAbc, int argc, cha
|
|||
static int Abc_CommandAbc9Dfs ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9Sim ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9Sim3 ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9MLGen ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9MLTest ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9ReadSim ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9WriteSim ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9SimPat ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
|
|
@ -1124,6 +1126,8 @@ void Abc_Init( Abc_Frame_t * pAbc )
|
|||
Cmd_CommandAdd( pAbc, "ABC9", "&dfs", Abc_CommandAbc9Dfs, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&sim", Abc_CommandAbc9Sim, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&sim3", Abc_CommandAbc9Sim3, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&mlgen", Abc_CommandAbc9MLGen, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&mltest", Abc_CommandAbc9MLTest, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&read_sim", Abc_CommandAbc9ReadSim, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&write_sim", Abc_CommandAbc9WriteSim, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&simpat", Abc_CommandAbc9SimPat, 0 );
|
||||
|
|
@ -32482,6 +32486,172 @@ usage:
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Abc_CommandAbc9MLGen( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||
{
|
||||
extern void Gia_ManDumpFiles( Gia_Man_t * p, int nCexesT, int nCexesV, int Seed, char * pFileName );
|
||||
extern void Gia_ManDumpPlaFiles( Gia_Man_t * p, int nCexesT, int nCexesV, int Seed, char * pFileName );
|
||||
int c, Seed = 0, nWords = 10, fBinData = 0, fVerbose = 0;
|
||||
char * pFileName = NULL;
|
||||
char ** pArgvNew;
|
||||
int nArgcNew;
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "WSbvh" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'W':
|
||||
if ( globalUtilOptind >= argc )
|
||||
{
|
||||
Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
|
||||
goto usage;
|
||||
}
|
||||
nWords = atoi(argv[globalUtilOptind]);
|
||||
globalUtilOptind++;
|
||||
if ( nWords < 0 )
|
||||
goto usage;
|
||||
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++;
|
||||
if ( Seed < 0 )
|
||||
goto usage;
|
||||
break;
|
||||
case 'b':
|
||||
fBinData ^= 1;
|
||||
break;
|
||||
case 'v':
|
||||
fVerbose ^= 1;
|
||||
break;
|
||||
case 'h':
|
||||
goto usage;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
if ( pAbc->pGia == NULL )
|
||||
{
|
||||
Abc_Print( -1, "Abc_CommandAbc9MLGen(): There is no AIG.\n" );
|
||||
return 1;
|
||||
}
|
||||
if ( Gia_ManRegNum(pAbc->pGia) > 0 )
|
||||
{
|
||||
Abc_Print( -1, "Abc_CommandAbc9MLGen(): This command works only for combinational AIGs.\n" );
|
||||
return 0;
|
||||
}
|
||||
Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
|
||||
pArgvNew = argv + globalUtilOptind;
|
||||
nArgcNew = argc - globalUtilOptind;
|
||||
if ( nArgcNew == 0 )
|
||||
printf( "Default file names will be used.\n" );
|
||||
else
|
||||
pFileName = pArgvNew[0];
|
||||
if ( nArgcNew != 0 && nArgcNew != 1 )
|
||||
{
|
||||
Abc_Print( -1, "File name is not given on the command line.\n" );
|
||||
return 1;
|
||||
}
|
||||
if ( fBinData )
|
||||
Gia_ManDumpFiles( pAbc->pGia, nWords, nWords, Seed, pFileName );
|
||||
else
|
||||
Gia_ManDumpPlaFiles( pAbc->pGia, nWords, nWords, Seed, pFileName );
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
Abc_Print( -2, "usage: &mlgen [-WS num] [-bvh] <file>\n" );
|
||||
Abc_Print( -2, "\t generates data files for machine learning\n" );
|
||||
Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", nWords );
|
||||
Abc_Print( -2, "\t-S num : the random seed for simulation data (num < 10000) [default = %d]\n", Seed );
|
||||
Abc_Print( -2, "\t-b : toggle using binary data files [default = %s]\n", fBinData? "yes": "no" );
|
||||
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, "\t<file> : file to store the simulation info\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Abc_CommandAbc9MLTest( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||
{
|
||||
extern void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName );
|
||||
int c, fVerbose = 0;
|
||||
char * pFileName = NULL;
|
||||
char ** pArgvNew;
|
||||
int nArgcNew;
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'v':
|
||||
fVerbose ^= 1;
|
||||
break;
|
||||
case 'h':
|
||||
goto usage;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
if ( pAbc->pGia == NULL )
|
||||
{
|
||||
Abc_Print( -1, "Abc_CommandAbc9MLGen(): There is no AIG.\n" );
|
||||
return 1;
|
||||
}
|
||||
if ( Gia_ManRegNum(pAbc->pGia) > 0 )
|
||||
{
|
||||
Abc_Print( -1, "Abc_CommandAbc9MLGen(): This command works only for combinational AIGs.\n" );
|
||||
return 0;
|
||||
}
|
||||
Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
|
||||
pArgvNew = argv + globalUtilOptind;
|
||||
nArgcNew = argc - globalUtilOptind;
|
||||
if ( nArgcNew == 0 )
|
||||
{
|
||||
printf( "Expecting data file name on the command line.\n" );
|
||||
return 0;
|
||||
}
|
||||
pFileName = pArgvNew[0];
|
||||
if ( nArgcNew != 1 )
|
||||
{
|
||||
Abc_Print( -1, "File name is not given on the command line.\n" );
|
||||
return 1;
|
||||
}
|
||||
Gia_ManTestOneFile( pAbc->pGia, pFileName );
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
Abc_Print( -2, "usage: [-vh] <file>\n" );
|
||||
Abc_Print( -2, "\t testing command for machine learning data\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, "\t<file> : file with input simulation info\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
|
@ -32564,7 +32734,7 @@ int Abc_CommandAbc9ReadSim( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
usage:
|
||||
Abc_Print( -2, "usage: &read_sim [-W num] [-vh] <file>\n" );
|
||||
Abc_Print( -2, "\t reads simulation patterns from file\n" );
|
||||
Abc_Print( -2, "\t-W num : the number of frames to simulate [default = %d]\n", nWords );
|
||||
Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", nWords );
|
||||
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, "\t<file> : file to store the simulation info\n");
|
||||
|
|
|
|||
Loading…
Reference in New Issue