Commit 6a03ece9 by Alan Mishchenko

Command &iwls21test for evaluating the results of 2021 IWLS Contest.

parent 66098723
......@@ -19,6 +19,7 @@
***********************************************************************/
#include "gia.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START
......
......@@ -416,6 +416,7 @@ static int Abc_CommandAbc9Sim ( Abc_Frame_t * pAbc, int argc, cha
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_CommandAbc9Iwls21Test ( 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_CommandAbc9PrintSim ( Abc_Frame_t * pAbc, int argc, char ** argv );
......@@ -1138,6 +1139,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
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", "&iwls21test", Abc_CommandAbc9Iwls21Test, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&sim_read", Abc_CommandAbc9ReadSim, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&sim_write", Abc_CommandAbc9WriteSim, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&sim_print", Abc_CommandAbc9PrintSim, 0 );
......@@ -33001,6 +33003,96 @@ usage:
SeeAlso []
***********************************************************************/
int Abc_CommandAbc9Iwls21Test( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Gia_ManTestWordFile( Gia_Man_t * p, char * pFileName, char * pDumpFile, int fVerbose );
int c, fVerbose = 0;
char * pDumpFile = NULL;
char ** pArgvNew;
int nArgcNew;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Dvh" ) ) != EOF )
{
switch ( c )
{
case 'D':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-D\" should be followed by a file name.\n" );
goto usage;
}
pDumpFile = argv[globalUtilOptind];
globalUtilOptind++;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
pArgvNew = argv + globalUtilOptind;
nArgcNew = argc - globalUtilOptind;
if ( nArgcNew == 2 )
{
Gia_Man_t * pAig = Gia_AigerRead( pArgvNew[0], 0, 0, 0 );
if ( pAig == NULL )
{
Abc_Print( -1, "Reading AIGER from file \"%s\" has failed.\n", pArgvNew[0] );
return 0;
}
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "Abc_CommandAbc9Iwls21Test(): There is no AIG.\n" );
return 1;
}
Gia_ManTestWordFile( pAig, pArgvNew[1], pDumpFile, fVerbose );
Gia_ManStop( pAig );
return 0;
}
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "Abc_CommandAbc9Iwls21Test(): There is no AIG.\n" );
return 1;
}
if ( nArgcNew != 1 )
{
Abc_Print( -1, "Abc_CommandAbc9Iwls21Test(): Expecting data file name on the command line.\n" );
return 0;
}
if ( Gia_ManRegNum(pAbc->pGia) > 0 )
{
Abc_Print( -1, "Abc_CommandAbc9Iwls21Test(): This command works only for combinational AIGs.\n" );
return 0;
}
Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
Gia_ManTestWordFile( pAbc->pGia, pArgvNew[0], pDumpFile, fVerbose );
return 0;
usage:
Abc_Print( -2, "usage: &iwls21test [-vh] [-D file] <file1> <file2>\n" );
Abc_Print( -2, "\t this command evaluates AIG for 2021 IWLS ML+LS Contest\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-D file : file name to dump statistics [default = none]\n" );
Abc_Print( -2, "\tfile1 : file with input AIG (or \"&read <file1.aig>; &iwls21test <file2>\" can be used)\n");
Abc_Print( -2, "\tfile2 : file with CIFAR10 image data (https://www.cs.toronto.edu/~kriz/cifar.html)\n");
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandAbc9ReadSim( Abc_Frame_t * pAbc, int argc, char ** argv )
{
int c, fOutputs = 0, nWords = 4, fVerbose = 0;
......@@ -2490,6 +2490,98 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Wlc_BstPar_t * pParIn )
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
float * Extra_FileReadFloat( FILE * pFile, int * pnFileSize )
{
float * pBuffer;
int RetValue, nFileSize;
fseek( pFile, 0, SEEK_END );
nFileSize = *pnFileSize = ftell( pFile );
rewind( pFile );
assert( nFileSize%4 == 0 );
pBuffer = ABC_CALLOC( float, nFileSize/4 );
RetValue = fread( pBuffer, nFileSize, 1, pFile );
return pBuffer;
}
float * Extra_FileReadFloatContents( char * pFileName, int * pnFileSize )
{
FILE * pFile;
float * pBuffer;
pFile = fopen( pFileName, "rb" );
pBuffer = pFile ? Extra_FileReadFloat( pFile, pnFileSize ) : NULL;
if ( pFile ) fclose( pFile );
return pBuffer;
}
static inline int Extra_FixedFound( int Value, int Fixed )
{
Value += 1 << (Fixed-1);
Value >>= Fixed;
return Value;
}
static inline int Extra_ConvertFloat8( float Value )
{
return Extra_FixedFound( (int)(Value * (1 << 16)), 8 );
}
Gia_Man_t * Wlc_BlastArray( char * pFileName )
{
int nFileSize = 0;
float * pBuffer = Extra_FileReadFloatContents( pFileName, &nFileSize );
int i, v, Value, nInputs = nFileSize/4 - 1;
Vec_Int_t * vArg0 = Vec_IntAlloc( 100 );
Vec_Int_t * vArg1 = Vec_IntAlloc( 100 );
Vec_Int_t * vTemp = Vec_IntAlloc( 100 );
Vec_Int_t * vRes = Vec_IntAlloc( 100 );
Vec_Int_t * vSum = Vec_IntAlloc( 100 );
Gia_Man_t * pTemp, * pNew = Gia_ManStart( 10000 );
pNew->pName = Abc_UtilStrsav( "blast" );
Gia_ManHashAlloc( pNew );
for ( i = 0; i < 8*nInputs; i++ )
Gia_ManAppendCi(pNew);
Value = (Extra_ConvertFloat8(pBuffer[0]) << 8) | (1 << 7);
for ( v = 0; v < 20; v++ )
Vec_IntPush( vSum, (Value >> v) & 1 );
for ( i = 0; i < nInputs; i++ )
{
Value = Extra_ConvertFloat8( pBuffer[1+i] );
Vec_IntClear( vArg0 );
for ( v = 0; v < 8; v++ )
Vec_IntPush( vArg0, Gia_ManCiLit(pNew, 8*i+v) );
Vec_IntClear( vArg1 );
for ( v = 0; v < 12; v++ )
Vec_IntPush( vArg1, (Value >> v) & 1 );
Wlc_BlastMultiplier( pNew, Vec_IntArray(vArg0), Vec_IntArray(vArg1), 8, 12, vTemp, vRes, 1 );
Wlc_BlastAdder( pNew, Vec_IntArray(vSum), Vec_IntArray(vRes), 20, 0 );
}
ABC_FREE( pBuffer );
for ( v = 8; v < 16; v++ )
Gia_ManAppendCo( pNew, Vec_IntEntry(vSum, v) );
Vec_IntFree( vArg0 );
Vec_IntFree( vArg1 );
Vec_IntFree( vTemp );
Vec_IntFree( vRes );
Vec_IntFree( vSum );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
return pNew;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment