From 0c6505a26a537dc911b6566f82d759521e527c08 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Wed, 30 Jan 2008 20:01:00 -0800 Subject: Version abc80130_2 --- src/base/abci/abcPart.c | 890 +++++++++++++++++++++++++++++------------------- 1 file changed, 533 insertions(+), 357 deletions(-) (limited to 'src/base/abci/abcPart.c') diff --git a/src/base/abci/abcPart.c b/src/base/abci/abcPart.c index 506010c7..85c4e918 100644 --- a/src/base/abci/abcPart.c +++ b/src/base/abci/abcPart.c @@ -19,77 +19,87 @@ ***********************************************************************/ #include "abc.h" -#include "hop.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// +typedef struct Supp_Man_t_ Supp_Man_t; +struct Supp_Man_t_ +{ + int nChunkSize; // the size of one chunk of memory (~1 Mb) + int nStepSize; // the step size in saving memory (~64 bytes) + char * pFreeBuf; // the pointer to free memory + int nFreeSize; // the size of remaining free memory + Vec_Ptr_t * vMemory; // the memory allocated + Vec_Ptr_t * vFree; // the vector of free pieces of memory +}; + +typedef struct Supp_One_t_ Supp_One_t; +struct Supp_One_t_ +{ + int nRefs; // the number of references + int nOuts; // the number of outputs + int nOutsAlloc; // the array size + int pOuts[0]; // the array of outputs +}; + +static inline int Supp_SizeType( int nSize, int nStepSize ) { return nSize / nStepSize + ((nSize % nStepSize) > 0); } +static inline char * Supp_OneNext( char * pPart ) { return *((char **)pPart); } +static inline void Supp_OneSetNext( char * pPart, char * pNext ) { *((char **)pPart) = pNext; } + //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* - Synopsis [Returns the number of common entries.] + Synopsis [Start the memory manager.] - Description [Assumes that the vectors are sorted in the increasing order.] + Description [] SideEffects [] SeeAlso [] ***********************************************************************/ -static inline int Vec_IntTwoCountCommon( Vec_Int_t * vArr1, Vec_Int_t * vArr2 ) +Supp_Man_t * Supp_ManStart( int nChunkSize, int nStepSize ) { - int i, k, Counter = 0; - for ( i = k = 0; i < Vec_IntSize(vArr1) && k < Vec_IntSize(vArr2); ) - { - if ( Vec_IntEntry(vArr1,i) == Vec_IntEntry(vArr2,k) ) - Counter++, i++, k++; - else if ( Vec_IntEntry(vArr1,i) < Vec_IntEntry(vArr2,k) ) - i++; - else - k++; - } - return Counter; + Supp_Man_t * p; + p = ALLOC( Supp_Man_t, 1 ); + memset( p, 0, sizeof(Supp_Man_t) ); + p->nChunkSize = nChunkSize; + p->nStepSize = nStepSize; + p->vMemory = Vec_PtrAlloc( 1000 ); + p->vFree = Vec_PtrAlloc( 1000 ); + return p; } /**Function************************************************************* - Synopsis [Returns the result of merging the two vectors.] + Synopsis [Stops the memory manager.] - Description [Assumes that the vectors are sorted in the increasing order.] + Description [] SideEffects [] SeeAlso [] ***********************************************************************/ -static inline Vec_Int_t * Vec_IntTwoMerge( Vec_Int_t * vArr1, Vec_Int_t * vArr2 ) +void Supp_ManStop( Supp_Man_t * p ) { - Vec_Int_t * vArr; - int i, k; - vArr = Vec_IntAlloc( Vec_IntSize(vArr1) ); - for ( i = k = 0; i < Vec_IntSize(vArr1) && k < Vec_IntSize(vArr2); ) - { - if ( Vec_IntEntry(vArr1,i) == Vec_IntEntry(vArr2,k) ) - Vec_IntPush( vArr, Vec_IntEntry(vArr1,i) ), i++, k++; - else if ( Vec_IntEntry(vArr1,i) < Vec_IntEntry(vArr2,k) ) - Vec_IntPush( vArr, Vec_IntEntry(vArr1,i) ), i++; - else - Vec_IntPush( vArr, Vec_IntEntry(vArr2,k) ), k++; - } - for ( ; i < Vec_IntSize(vArr1); i++ ) - Vec_IntPush( vArr, Vec_IntEntry(vArr1,i) ); - for ( ; k < Vec_IntSize(vArr2); k++ ) - Vec_IntPush( vArr, Vec_IntEntry(vArr2,k) ); - return vArr; + void * pMemory; + int i; + Vec_PtrForEachEntry( p->vMemory, pMemory, i ) + free( pMemory ); + Vec_PtrFree( p->vMemory ); + Vec_PtrFree( p->vFree ); + free( p ); } /**Function************************************************************* - Synopsis [Comparison procedure for two arrays.] + Synopsis [Fetches the memory entry of the given size.] Description [] @@ -98,18 +108,35 @@ static inline Vec_Int_t * Vec_IntTwoMerge( Vec_Int_t * vArr1, Vec_Int_t * vArr2 SeeAlso [] ***********************************************************************/ -static inline int Vec_VecSortCompare1( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 ) +char * Supp_ManFetch( Supp_Man_t * p, int nSize ) { - if ( Vec_PtrSize(*pp1) < Vec_PtrSize(*pp2) ) - return -1; - if ( Vec_PtrSize(*pp1) > Vec_PtrSize(*pp2) ) - return 1; - return 0; + int Type, nSizeReal; + char * pMemory; + assert( nSize > 0 ); + Type = Supp_SizeType( nSize, p->nStepSize ); + Vec_PtrFillExtra( p->vFree, Type + 1, NULL ); + if ( pMemory = Vec_PtrEntry( p->vFree, Type ) ) + { + Vec_PtrWriteEntry( p->vFree, Type, Supp_OneNext(pMemory) ); + return pMemory; + } + nSizeReal = p->nStepSize * Type; + if ( p->nFreeSize < nSizeReal ) + { + p->pFreeBuf = ALLOC( char, p->nChunkSize ); + p->nFreeSize = p->nChunkSize; + Vec_PtrPush( p->vMemory, p->pFreeBuf ); + } + assert( p->nFreeSize >= nSizeReal ); + pMemory = p->pFreeBuf; + p->pFreeBuf += nSizeReal; + p->nFreeSize -= nSizeReal; + return pMemory; } /**Function************************************************************* - Synopsis [Comparison procedure for two integers.] + Synopsis [Recycles the memory entry of the given size.] Description [] @@ -118,18 +145,18 @@ static inline int Vec_VecSortCompare1( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 ) SeeAlso [] ***********************************************************************/ -static inline int Vec_VecSortCompare2( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 ) +void Supp_ManRecycle( Supp_Man_t * p, char * pMemory, int nSize ) { - if ( Vec_PtrSize(*pp1) > Vec_PtrSize(*pp2) ) - return -1; - if ( Vec_PtrSize(*pp1) < Vec_PtrSize(*pp2) ) - return 1; - return 0; + int Type; + Type = Supp_SizeType( nSize, p->nStepSize ); + Vec_PtrFillExtra( p->vFree, Type + 1, NULL ); + Supp_OneSetNext( pMemory, Vec_PtrEntry(p->vFree, Type) ); + Vec_PtrWriteEntry( p->vFree, Type, pMemory ); } /**Function************************************************************* - Synopsis [Sorting the entries by their integer value.] + Synopsis [Fetches the memory entry of the given size.] Description [] @@ -138,19 +165,19 @@ static inline int Vec_VecSortCompare2( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 ) SeeAlso [] ***********************************************************************/ -static inline void Vec_VecSort( Vec_Vec_t * p, int fReverse ) +static inline Supp_One_t * Supp_ManFetchEntry( Supp_Man_t * p, int nWords, int nRefs ) { - if ( fReverse ) - qsort( (void *)p->pArray, p->nSize, sizeof(void *), - (int (*)(const void *, const void *)) Vec_VecSortCompare2 ); - else - qsort( (void *)p->pArray, p->nSize, sizeof(void *), - (int (*)(const void *, const void *)) Vec_VecSortCompare1 ); + Supp_One_t * pPart; + pPart = (Supp_One_t *)Supp_ManFetch( p, sizeof(Supp_One_t) + sizeof(int) * nWords ); + pPart->nRefs = nRefs; + pPart->nOuts = 0; + pPart->nOutsAlloc = nWords; + return pPart; } /**Function************************************************************* - Synopsis [Performs DFS for one node.] + Synopsis [Recycles the memory entry of the given size.] Description [] @@ -159,31 +186,16 @@ static inline void Vec_VecSort( Vec_Vec_t * p, int fReverse ) SeeAlso [] ***********************************************************************/ -void Abc_NtkNodeSupport_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vNodes ) +static inline void Supp_ManRecycleEntry( Supp_Man_t * p, Supp_One_t * pEntry ) { - Abc_Obj_t * pFanin; - int i; - assert( !Abc_ObjIsNet(pNode) ); - // if this node is already visited, skip - if ( Abc_NodeIsTravIdCurrent( pNode ) ) - return; - // mark the node as visited - Abc_NodeSetTravIdCurrent( pNode ); - // collect the CI - if ( Abc_ObjIsCi(pNode) || Abc_ObjFaninNum(pNode) == 0 ) - { - Vec_PtrPush( vNodes, pNode ); - return; - } - assert( Abc_ObjIsNode( pNode ) ); - // visit the transitive fanin of the node - Abc_ObjForEachFanin( pNode, pFanin, i ) - Abc_NtkNodeSupport_rec( Abc_ObjFanin0Ntk(pFanin), vNodes ); + assert( pEntry->nOuts <= pEntry->nOutsAlloc ); + assert( pEntry->nOuts >= pEntry->nOutsAlloc/2 ); + Supp_ManRecycle( p, (char *)pEntry, sizeof(Supp_One_t) + sizeof(int) * pEntry->nOutsAlloc ); } /**Function************************************************************* - Synopsis [Returns the set of CI nodes in the support of the given nodes.] + Synopsis [Merges two entries.] Description [] @@ -192,26 +204,37 @@ void Abc_NtkNodeSupport_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vNodes ) SeeAlso [] ***********************************************************************/ -Vec_Ptr_t * Abc_NtkNodeSupport( Abc_Ntk_t * pNtk, Abc_Obj_t ** ppNodes, int nNodes ) +Supp_One_t * Supp_ManMergeEntry( Supp_Man_t * pMan, Supp_One_t * p1, Supp_One_t * p2, int nRefs ) { - Vec_Ptr_t * vNodes; - int i; - // set the traversal ID - Abc_NtkIncrementTravId( pNtk ); - // start the array of nodes - vNodes = Vec_PtrAlloc( 100 ); - // go through the PO nodes and call for each of them - for ( i = 0; i < nNodes; i++ ) - if ( Abc_ObjIsCo(ppNodes[i]) ) - Abc_NtkNodeSupport_rec( Abc_ObjFanin0(ppNodes[i]), vNodes ); - else - Abc_NtkNodeSupport_rec( ppNodes[i], vNodes ); - return vNodes; + Supp_One_t * p = Supp_ManFetchEntry( pMan, p1->nOuts + p2->nOuts, nRefs ); + int * pBeg1 = p1->pOuts; + int * pBeg2 = p2->pOuts; + int * pBeg = p->pOuts; + int * pEnd1 = p1->pOuts + p1->nOuts; + int * pEnd2 = p2->pOuts + p2->nOuts; + while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 ) + { + if ( *pBeg1 == *pBeg2 ) + *pBeg++ = *pBeg1++, pBeg2++; + else if ( *pBeg1 < *pBeg2 ) + *pBeg++ = *pBeg1++; + else + *pBeg++ = *pBeg2++; + } + while ( pBeg1 < pEnd1 ) + *pBeg++ = *pBeg1++; + while ( pBeg2 < pEnd2 ) + *pBeg++ = *pBeg2++; + p->nOuts = pBeg - p->pOuts; + assert( p->nOuts <= p->nOutsAlloc ); + assert( p->nOuts >= p1->nOuts ); + assert( p->nOuts >= p2->nOuts ); + return p; } /**Function************************************************************* - Synopsis [Extra_UtilStrsav()] + Synopsis [Tranfers the entry.] Description [] @@ -220,16 +243,19 @@ Vec_Ptr_t * Abc_NtkNodeSupport( Abc_Ntk_t * pNtk, Abc_Obj_t ** ppNodes, int nNod SeeAlso [] ***********************************************************************/ -char * Extra_UtilStrsav( char * s ) +Vec_Int_t * Supp_ManTransferEntry( Supp_One_t * p ) { - if ( s == NULL ) - return s; - return strcpy(ALLOC(char, strlen(s)+1), s); + Vec_Int_t * vSupp; + int i; + vSupp = Vec_IntAlloc( p->nOuts ); + for ( i = 0; i < p->nOuts; i++ ) + Vec_IntPush( vSupp, p->pOuts[i] ); + return vSupp; } /**Function************************************************************* - Synopsis [Creates the network composed of several logic cones.] + Synopsis [Computes supports of the POs in the multi-output AIG.] Description [] @@ -238,196 +264,255 @@ char * Extra_UtilStrsav( char * s ) SeeAlso [] ***********************************************************************/ -Abc_Ntk_t * Abc_NtkCreateConeArray( Abc_Ntk_t * pNtk, Vec_Ptr_t * vRoots, int fUseAllCis ) +Vec_Ptr_t * Abc_NtkDfsNatural( Abc_Ntk_t * pNtk ) { - Abc_Ntk_t * pNtkNew; Vec_Ptr_t * vNodes; - Abc_Obj_t * pObj, * pFanin, * pNodeCoNew; - char Buffer[1000]; + Abc_Obj_t * pObj, * pNext; int i, k; - - assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsStrash(pNtk) ); - - // start the network - pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc ); - // set the name - sprintf( Buffer, "%s_part", pNtk->pName ); - pNtkNew->pName = Extra_UtilStrsav(Buffer); - - // establish connection between the constant nodes - if ( Abc_NtkIsStrash(pNtk) ) - Abc_AigConst1(pNtk->pManFunc)->pCopy = Abc_AigConst1(pNtkNew->pManFunc); - - // collect the nodes in the TFI of the output (mark the TFI) - vNodes = Abc_NtkDfsNodes( pNtk, (Abc_Obj_t **)Vec_PtrArray(vRoots), Vec_PtrSize(vRoots) ); - - // create the PIs - Abc_NtkForEachCi( pNtk, pObj, i ) - { - if ( fUseAllCis || Abc_NodeIsTravIdCurrent(pObj) ) // TravId is set by DFS - { - pObj->pCopy = Abc_NtkCreatePi(pNtkNew); -// Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL ); - Abc_NtkLogicStoreName( pObj->pCopy, Abc_ObjName(pObj) ); - } - } - - // copy the nodes - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - // if it is an AIG, add to the hash table - if ( Abc_NtkIsStrash(pNtk) ) - { - pObj->pCopy = Abc_AigAnd( pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) ); - } - else - { - Abc_NtkDupObj( pNtkNew, pObj ); - Abc_ObjForEachFanin( pObj, pFanin, k ) - Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy ); - } - } - Vec_PtrFree( vNodes ); - - // add the PO corresponding to the nodes - Vec_PtrForEachEntry( vRoots, pObj, i ) + assert( Abc_NtkIsStrash(pNtk) ); + vNodes = Vec_PtrAlloc( Abc_NtkObjNum(pNtk) ); + Abc_NtkIncrementTravId( pNtk ); + // add the constant-1 nodes + pObj = Abc_AigConst1(pNtk); + Abc_NodeSetTravIdCurrent( pObj ); + Vec_PtrPush( vNodes, pObj ); + // add the CIs/nodes/COs in the topological order + Abc_NtkForEachNode( pNtk, pObj, i ) { - // create the PO node - pNodeCoNew = Abc_NtkCreatePo( pNtkNew ); - // connect the internal nodes to the new CO - if ( Abc_ObjIsCo(pObj) ) - Abc_ObjAddFanin( pNodeCoNew, Abc_ObjChild0Copy(pObj) ); - else - Abc_ObjAddFanin( pNodeCoNew, pObj->pCopy ); - // assign the name -// Abc_ObjAssignName( pNodeCoNew, Abc_ObjName(pObj), NULL ); - Abc_NtkLogicStoreName( pNodeCoNew, Abc_ObjName(pObj) ); + // check the fanins and add CIs + Abc_ObjForEachFanin( pObj, pNext, k ) + if ( Abc_ObjIsCi(pNext) && !Abc_NodeIsTravIdCurrent(pNext) ) + { + Abc_NodeSetTravIdCurrent( pNext ); + Vec_PtrPush( vNodes, pNext ); + } + // add the node + Vec_PtrPush( vNodes, pObj ); + // check the fanouts and add COs + Abc_ObjForEachFanout( pObj, pNext, k ) + if ( Abc_ObjIsCo(pNext) && !Abc_NodeIsTravIdCurrent(pNext) ) + { + Abc_NodeSetTravIdCurrent( pNext ); + Vec_PtrPush( vNodes, pNext ); + } } - - if ( !Abc_NtkCheck( pNtkNew ) ) - fprintf( stdout, "Abc_NtkCreateConeArray(): Network check has failed.\n" ); - return pNtkNew; + return vNodes; } /**Function************************************************************* - Synopsis [Appends the second network to the first.] + Synopsis [Computes supports of the POs.] - Description [Modifies the first network by adding the logic of the second. - Performs structural hashing while appending the networks. Does not change - the second network. Returns 0 if the appending failed, 1 otherise.] + Description [Returns the ptr-vector of int-vectors.] SideEffects [] SeeAlso [] ***********************************************************************/ -int Abc_NtkAppendNew( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2 ) +Vec_Ptr_t * Abc_NtkComputeSupportsSmart( Abc_Ntk_t * pNtk ) { + Vec_Ptr_t * vSupports; + Vec_Ptr_t * vNodes; + Vec_Int_t * vSupp; + Supp_Man_t * p; + Supp_One_t * pPart0, * pPart1; Abc_Obj_t * pObj; -// char * pName; - int i, nNewCis; - // the first network should be an AIG - assert( Abc_NtkIsStrash(pNtk1) ); - assert( Abc_NtkIsStrash(pNtk2) ); - // check that the networks have the same PIs - // reorder PIs of pNtk2 according to pNtk1 -// if ( !Abc_NtkCompareSignals( pNtk1, pNtk2, 1, 1 ) ) -// printf( "Abc_NtkAppend(): The union of the network PIs is computed (warning).\n" ); - // perform strashing - nNewCis = 0; - Abc_NtkCleanCopy( pNtk2 ); - Abc_AigConst1(pNtk2->pManFunc)->pCopy = Abc_AigConst1(pNtk1->pManFunc); - Abc_NtkForEachCi( pNtk2, pObj, i ) + int i; + // set the number of PIs/POs + Abc_NtkForEachCi( pNtk, pObj, i ) + pObj->pNext = (Abc_Obj_t *)i; + Abc_NtkForEachCo( pNtk, pObj, i ) + pObj->pNext = (Abc_Obj_t *)i; + // start the support computation manager + p = Supp_ManStart( 1 << 20, 1 << 6 ); + // consider objects in the topological order + vSupports = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) ); + Abc_NtkCleanCopy(pNtk); + // order the nodes so that the PIs and POs follow naturally + vNodes = Abc_NtkDfsNatural( pNtk ); + Vec_PtrForEachEntry( vNodes, pObj, i ) { -// pName = Abc_ObjName(pObj); -// pObj->pCopy = Abc_NtkFindCi(pNtk1, Abc_ObjName(pObj)); - pObj->pCopy = Abc_NtkCi( pNtk1, i ); - if ( pObj->pCopy == NULL ) + if ( Abc_ObjIsNode(pObj) ) { - pObj->pCopy = Abc_NtkDupObj( pNtk1, pObj ); - nNewCis++; + pPart0 = (Supp_One_t *)Abc_ObjFanin0(pObj)->pCopy; + pPart1 = (Supp_One_t *)Abc_ObjFanin1(pObj)->pCopy; + pObj->pCopy = (Abc_Obj_t *)Supp_ManMergeEntry( p, pPart0, pPart1, Abc_ObjFanoutNum(pObj) ); + assert( pPart0->nRefs > 0 ); + if ( --pPart0->nRefs == 0 ) + Supp_ManRecycleEntry( p, pPart0 ); + assert( pPart1->nRefs > 0 ); + if ( --pPart1->nRefs == 0 ) + Supp_ManRecycleEntry( p, pPart1 ); + continue; } - } - if ( nNewCis ) - printf( "Warning: Procedure Abc_NtkAppend() added %d new CIs.\n", nNewCis ); - // add pNtk2 to pNtk1 while strashing - Abc_NtkForEachNode( pNtk2, pObj, i ) - { - if ( Abc_ObjFaninNum(pObj) == 0 ) + if ( Abc_ObjIsCo(pObj) ) + { + pPart0 = (Supp_One_t *)Abc_ObjFanin0(pObj)->pCopy; + // only save the CO if it is non-trivial + if ( Abc_ObjIsNode(Abc_ObjFanin0(pObj)) ) + { + vSupp = Supp_ManTransferEntry(pPart0); + Vec_IntPush( vSupp, (int)pObj->pNext ); + Vec_PtrPush( vSupports, vSupp ); + } + assert( pPart0->nRefs > 0 ); + if ( --pPart0->nRefs == 0 ) + Supp_ManRecycleEntry( p, pPart0 ); continue; - pObj->pCopy = Abc_AigAnd( pNtk1->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) ); - } - // add the COs of the second network - { - Abc_Obj_t * pObjOld, * pDriverOld, * pDriverNew; - int fCompl;//, iNodeId; - // OR the choices - Abc_NtkForEachCo( pNtk2, pObj, i ) + } + if ( Abc_ObjIsCi(pObj) ) { -// iNodeId = Nm_ManFindIdByNameTwoTypes( pNtk1->pManName, Abc_ObjName(pObj), ABC_OBJ_PO, ABC_OBJ_BI ); -// assert( iNodeId >= 0 ); -// pObjOld = Abc_NtkObj( pNtk1, iNodeId ); - pObjOld = Abc_NtkCo( pNtk1, i ); - - // derive the new driver - pDriverOld = Abc_ObjChild0( pObjOld ); - pDriverNew = Abc_ObjChild0Copy( pObj ); - pDriverNew = Abc_AigOr( pNtk1->pManFunc, pDriverOld, pDriverNew ); - if ( Abc_ObjRegular(pDriverOld) == Abc_ObjRegular(pDriverNew) ) - continue; - // replace the old driver by the new driver - fCompl = Abc_ObjRegular(pDriverOld)->fPhase ^ Abc_ObjRegular(pDriverNew)->fPhase; - Abc_ObjPatchFanin( pObjOld, Abc_ObjRegular(pDriverOld), Abc_ObjNotCond(Abc_ObjRegular(pDriverNew), fCompl) ); + if ( Abc_ObjFanoutNum(pObj) ) + { + pPart0 = (Supp_One_t *)Supp_ManFetchEntry( p, 1, Abc_ObjFanoutNum(pObj) ); + pPart0->pOuts[ pPart0->nOuts++ ] = (int)pObj->pNext; + pObj->pCopy = (Abc_Obj_t *)pPart0; + } + continue; } + if ( pObj == Abc_AigConst1(pNtk) ) + { + if ( Abc_ObjFanoutNum(pObj) ) + pObj->pCopy = (Abc_Obj_t *)Supp_ManFetchEntry( p, 0, Abc_ObjFanoutNum(pObj) ); + continue; + } + assert( 0 ); } - // make sure that everything is okay - if ( !Abc_NtkCheck( pNtk1 ) ) - { - printf( "Abc_NtkAppend: The network check has failed.\n" ); - return 0; - } - return 1; + Vec_PtrFree( vNodes ); +//printf( "Memory usage = %d Mb.\n", Vec_PtrSize(p->vMemory) * p->nChunkSize / (1<<20) ); + Supp_ManStop( p ); + // sort supports by size + Vec_VecSort( (Vec_Vec_t *)vSupports, 1 ); + // clear the number of PIs/POs + Abc_NtkForEachCi( pNtk, pObj, i ) + pObj->pNext = NULL; + Abc_NtkForEachCo( pNtk, pObj, i ) + pObj->pNext = NULL; +/* + Vec_PtrForEachEntry( vSupports, vSupp, i ) + printf( "%d ", Vec_IntSize(vSupp) ); + printf( "\n" ); +*/ + return vSupports; } - - /**Function************************************************************* - Synopsis [Prepare supports.] + Synopsis [Computes supports of the POs using naive method.] - Description [] + Description [Returns the ptr-vector of int-vectors.] SideEffects [] SeeAlso [] ***********************************************************************/ -Vec_Ptr_t * Abc_NtkPartitionCollectSupps( Abc_Ntk_t * pNtk ) +Vec_Ptr_t * Abc_NtkComputeSupportsNaive( Abc_Ntk_t * pNtk ) { Vec_Ptr_t * vSupp, * vSupports; Vec_Int_t * vSuppI; Abc_Obj_t * pObj, * pTemp; int i, k; + // set the PI numbers + Abc_NtkForEachCi( pNtk, pObj, i ) + pObj->pNext = (void *)i; + // save the CI numbers vSupports = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) ); Abc_NtkForEachCo( pNtk, pObj, i ) { + if ( !Abc_ObjIsNode(Abc_ObjFanin0(pObj)) ) + continue; vSupp = Abc_NtkNodeSupport( pNtk, &pObj, 1 ); vSuppI = (Vec_Int_t *)vSupp; Vec_PtrForEachEntry( vSupp, pTemp, k ) - Vec_IntWriteEntry( vSuppI, k, pTemp->Id ); + Vec_IntWriteEntry( vSuppI, k, (int)pTemp->pNext ); Vec_IntSort( vSuppI, 0 ); // append the number of this output Vec_IntPush( vSuppI, i ); // save the support in the vector Vec_PtrPush( vSupports, vSuppI ); } + // clean the CI numbers + Abc_NtkForEachCi( pNtk, pObj, i ) + pObj->pNext = NULL; // sort supports by size Vec_VecSort( (Vec_Vec_t *)vSupports, 1 ); +/* + Vec_PtrForEachEntry( vSupports, vSuppI, i ) + printf( "%d ", Vec_IntSize(vSuppI) ); + printf( "\n" ); +*/ return vSupports; } +/**Function************************************************************* + + Synopsis [Start bitwise support representation.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned * Abc_NtkSuppCharStart( Vec_Int_t * vOne, int nPis ) +{ + unsigned * pBuffer; + int i, Entry; + int nWords = Abc_BitWordNum(nPis); + pBuffer = ALLOC( unsigned, nWords ); + memset( pBuffer, 0, sizeof(unsigned) * nWords ); + Vec_IntForEachEntry( vOne, Entry, i ) + { + assert( Entry < nPis ); + Abc_InfoSetBit( pBuffer, Entry ); + } + return pBuffer; +} + +/**Function************************************************************* + + Synopsis [Add to bitwise support representation.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_NtkSuppCharAdd( unsigned * pBuffer, Vec_Int_t * vOne, int nPis ) +{ + int i, Entry; + Vec_IntForEachEntry( vOne, Entry, i ) + { + assert( Entry < nPis ); + Abc_InfoSetBit( pBuffer, Entry ); + } +} + +/**Function************************************************************* + + Synopsis [Find the common variables using bitwise support representation.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Abc_NtkSuppCharCommon( unsigned * pBuffer, Vec_Int_t * vOne ) +{ + int i, Entry, nCommon = 0; + Vec_IntForEachEntry( vOne, Entry, i ) + nCommon += Abc_InfoHasBit(pBuffer, Entry); + return nCommon; +} + /**Function************************************************************* Synopsis [Find the best partition.] @@ -439,8 +524,9 @@ Vec_Ptr_t * Abc_NtkPartitionCollectSupps( Abc_Ntk_t * pNtk ) SeeAlso [] ***********************************************************************/ -int Abc_NtkPartitionSmartFindPart( Vec_Ptr_t * vPartSuppsAll, Vec_Ptr_t * vPartsAll, int nPartSizeLimit, Vec_Int_t * vOne ) +int Abc_NtkPartitionSmartFindPart( Vec_Ptr_t * vPartSuppsAll, Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsChar, int nSuppSizeLimit, Vec_Int_t * vOne ) { +/* Vec_Int_t * vPartSupp, * vPart; double Attract, Repulse, Cost, CostBest; int i, nCommon, iBest; @@ -448,12 +534,12 @@ int Abc_NtkPartitionSmartFindPart( Vec_Ptr_t * vPartSuppsAll, Vec_Ptr_t * vParts CostBest = 0.0; Vec_PtrForEachEntry( vPartSuppsAll, vPartSupp, i ) { + vPart = Vec_PtrEntry( vPartsAll, i ); + if ( nPartSizeLimit > 0 && Vec_IntSize(vPart) >= nPartSizeLimit ) + continue; nCommon = Vec_IntTwoCountCommon( vPartSupp, vOne ); if ( nCommon == 0 ) continue; - vPart = Vec_PtrEntry( vPartsAll, i ); - if ( nPartSizeLimit > 0 && Vec_IntSize(vPart) > nPartSizeLimit ) - continue; if ( nCommon == Vec_IntSize(vOne) ) return i; Attract = 1.0 * nCommon / Vec_IntSize(vOne); @@ -471,6 +557,49 @@ int Abc_NtkPartitionSmartFindPart( Vec_Ptr_t * vPartSuppsAll, Vec_Ptr_t * vParts if ( CostBest < 0.6 ) return -1; return iBest; +*/ + + Vec_Int_t * vPartSupp;//, * vPart; + int Attract, Repulse, Value, ValueBest; + int i, nCommon, iBest; +// int nCommon2; + iBest = -1; + ValueBest = 0; + Vec_PtrForEachEntry( vPartSuppsAll, vPartSupp, i ) + { + // skip partitions with too many outputs +// vPart = Vec_PtrEntry( vPartsAll, i ); +// if ( nSuppSizeLimit > 0 && Vec_IntSize(vPart) >= nSuppSizeLimit ) +// continue; + // find the number of common variables between this output and the partitions +// nCommon2 = Vec_IntTwoCountCommon( vPartSupp, vOne ); + nCommon = Abc_NtkSuppCharCommon( Vec_PtrEntry(vPartSuppsChar, i), vOne ); +// assert( nCommon2 == nCommon ); + // if no common variables, continue searching + if ( nCommon == 0 ) + continue; + // if all variables are common, the best partition if found + if ( nCommon == Vec_IntSize(vOne) ) + return i; + // skip partitions whose size exceeds the limit + if ( nSuppSizeLimit > 0 && Vec_IntSize(vPartSupp) >= 2 * nSuppSizeLimit ) + continue; + // figure out might be the good partition for this one + Attract = 1000 * nCommon / Vec_IntSize(vOne); + if ( Vec_IntSize(vPartSupp) < 100 ) + Repulse = 1; + else + Repulse = 1+Extra_Base2Log(Vec_IntSize(vPartSupp)-100); + Value = Attract/Repulse; + if ( ValueBest < Value ) + { + ValueBest = Value; + iBest = i; + } + } + if ( ValueBest < 75 ) + return -1; + return iBest; } /**Function************************************************************* @@ -498,7 +627,7 @@ void Abc_NtkPartitionPrint( Abc_Ntk_t * pNtk, Vec_Ptr_t * vPartsAll, Vec_Ptr_t * if ( i == Vec_PtrSize(vPartsAll) - 1 ) break; } - assert( Counter == Abc_NtkCoNum(pNtk) ); +// assert( Counter == Abc_NtkCoNum(pNtk) ); printf( "\nTotal = %d. Outputs = %d.\n", Counter, Abc_NtkCoNum(pNtk) ); } @@ -513,20 +642,20 @@ void Abc_NtkPartitionPrint( Abc_Ntk_t * pNtk, Vec_Ptr_t * vPartsAll, Vec_Ptr_t * SeeAlso [] ***********************************************************************/ -void Abc_NtkPartitionCompact( Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsAll, int nPartSizeLimit ) +void Abc_NtkPartitionCompact( Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsAll, int nSuppSizeLimit ) { Vec_Int_t * vOne, * vPart, * vPartSupp, * vTemp; int i, iPart; - if ( nPartSizeLimit == 0 ) - nPartSizeLimit = 200; + if ( nSuppSizeLimit == 0 ) + nSuppSizeLimit = 200; // pack smaller partitions into larger blocks iPart = 0; vPart = vPartSupp = NULL; Vec_PtrForEachEntry( vPartSuppsAll, vOne, i ) { - if ( Vec_IntSize(vOne) < nPartSizeLimit ) + if ( Vec_IntSize(vOne) < nSuppSizeLimit ) { if ( vPartSupp == NULL ) { @@ -542,7 +671,7 @@ void Abc_NtkPartitionCompact( Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsAll, Vec_IntFree( vTemp ); Vec_IntFree( Vec_PtrEntry(vPartsAll, i) ); } - if ( Vec_IntSize(vPartSupp) < nPartSizeLimit ) + if ( Vec_IntSize(vPartSupp) < nSuppSizeLimit ) continue; } else @@ -578,37 +707,49 @@ void Abc_NtkPartitionCompact( Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsAll, Synopsis [Perform the smart partitioning.] - Description [] + Description [Returns the ptr-vector of int-vectors.] SideEffects [] SeeAlso [] ***********************************************************************/ -Vec_Vec_t * Abc_NtkPartitionSmart( Abc_Ntk_t * pNtk, int nPartSizeLimit, int fVerbose ) +Vec_Ptr_t * Abc_NtkPartitionSmart( Abc_Ntk_t * pNtk, int nSuppSizeLimit, int fVerbose ) { - Vec_Ptr_t * vSupps, * vPartsAll, * vPartsAll2, * vPartSuppsAll, * vPartPtr; + ProgressBar * pProgress; + Vec_Ptr_t * vPartSuppsChar; + Vec_Ptr_t * vSupps, * vPartsAll, * vPartsAll2, * vPartSuppsAll; Vec_Int_t * vOne, * vPart, * vPartSupp, * vTemp; - int i, iPart, iOut, clk; + int i, iPart, iOut, clk, clk2, timeFind = 0; // compute the supports for all outputs clk = clock(); - vSupps = Abc_NtkPartitionCollectSupps( pNtk ); +// vSupps = Abc_NtkComputeSupportsNaive( pNtk ); + vSupps = Abc_NtkComputeSupportsSmart( pNtk ); if ( fVerbose ) { PRT( "Supps", clock() - clk ); } + // start char-based support representation + vPartSuppsChar = Vec_PtrAlloc( 1000 ); // create partitions clk = clock(); vPartsAll = Vec_PtrAlloc( 256 ); vPartSuppsAll = Vec_PtrAlloc( 256 ); + pProgress = Extra_ProgressBarStart( stdout, Vec_PtrSize(vSupps) ); Vec_PtrForEachEntry( vSupps, vOne, i ) { + Extra_ProgressBarUpdate( pProgress, i, NULL ); +// if ( i % 1000 == 0 ) +// printf( "CIs = %6d. COs = %6d. Processed = %6d (out of %6d). Parts = %6d.\r", +// Abc_NtkCiNum(pNtk), Abc_NtkCoNum(pNtk), i, Vec_PtrSize(vSupps), Vec_PtrSize(vPartsAll) ); // get the output number iOut = Vec_IntPop(vOne); // find closely matching part - iPart = Abc_NtkPartitionSmartFindPart( vPartSuppsAll, vPartsAll, nPartSizeLimit, vOne ); +clk2 = clock(); + iPart = Abc_NtkPartitionSmartFindPart( vPartSuppsAll, vPartsAll, vPartSuppsChar, nSuppSizeLimit, vOne ); +timeFind += clock() - clk2; if ( iPart == -1 ) { // create new partition @@ -619,6 +760,8 @@ clk = clock(); // add this partition and its support Vec_PtrPush( vPartsAll, vPart ); Vec_PtrPush( vPartSuppsAll, vPartSupp ); + + Vec_PtrPush( vPartSuppsChar, Abc_NtkSuppCharStart(vOne, Abc_NtkCiNum(pNtk)) ); } else { @@ -631,11 +774,22 @@ clk = clock(); Vec_IntFree( vTemp ); // reinsert new support Vec_PtrWriteEntry( vPartSuppsAll, iPart, vPartSupp ); + + Abc_NtkSuppCharAdd( Vec_PtrEntry(vPartSuppsChar, iPart), vOne, Abc_NtkCiNum(pNtk) ); } } + Extra_ProgressBarStop( pProgress ); + + // stop char-based support representation + Vec_PtrForEachEntry( vPartSuppsChar, vTemp, i ) + free( vTemp ); + Vec_PtrFree( vPartSuppsChar ); + +//printf( "\n" ); if ( fVerbose ) { PRT( "Parts", clock() - clk ); +//PRT( "Find ", timeFind ); } clk = clock(); @@ -653,18 +807,20 @@ clk = clock(); // compact small partitions // Abc_NtkPartitionPrint( pNtk, vPartsAll, vPartSuppsAll ); - Abc_NtkPartitionCompact( vPartsAll, vPartSuppsAll, nPartSizeLimit ); - if ( fVerbose ) - Abc_NtkPartitionPrint( pNtk, vPartsAll, vPartSuppsAll ); + Abc_NtkPartitionCompact( vPartsAll, vPartSuppsAll, nSuppSizeLimit ); + if ( fVerbose ) { PRT( "Comps", clock() - clk ); } + if ( fVerbose ) + printf( "Created %d partitions.\n", Vec_PtrSize(vPartsAll) ); +// Abc_NtkPartitionPrint( pNtk, vPartsAll, vPartSuppsAll ); // cleanup Vec_VecFree( (Vec_Vec_t *)vSupps ); Vec_VecFree( (Vec_Vec_t *)vPartSuppsAll ); - +/* // converts from intergers to nodes Vec_PtrForEachEntry( vPartsAll, vPart, iPart ) { @@ -674,32 +830,52 @@ PRT( "Comps", clock() - clk ); Vec_IntFree( vPart ); Vec_PtrWriteEntry( vPartsAll, iPart, vPartPtr ); } - return (Vec_Vec_t *)vPartsAll; +*/ + return vPartsAll; } /**Function************************************************************* Synopsis [Perform the naive partitioning.] - Description [] + Description [Returns the ptr-vector of int-vectors.] SideEffects [] SeeAlso [] ***********************************************************************/ -Vec_Vec_t * Abc_NtkPartitionNaive( Abc_Ntk_t * pNtk, int nPartSize ) +Vec_Ptr_t * Abc_NtkPartitionNaive( Abc_Ntk_t * pNtk, int nPartSize ) { - Vec_Vec_t * vParts; + Vec_Ptr_t * vParts; Abc_Obj_t * pObj; int nParts, i; nParts = (Abc_NtkCoNum(pNtk) / nPartSize) + ((Abc_NtkCoNum(pNtk) % nPartSize) > 0); - vParts = Vec_VecStart( nParts ); + vParts = (Vec_Ptr_t *)Vec_VecStart( nParts ); Abc_NtkForEachCo( pNtk, pObj, i ) - Vec_VecPush( vParts, i / nPartSize, pObj ); + Vec_IntPush( Vec_PtrEntry(vParts, i / nPartSize), i ); return vParts; } +/**Function************************************************************* + + Synopsis [Converts from intergers to pointers for the given network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_NtkConvertCos( Abc_Ntk_t * pNtk, Vec_Int_t * vOuts, Vec_Ptr_t * vOutsPtr ) +{ + int Out, i; + Vec_PtrClear( vOutsPtr ); + Vec_IntForEachEntry( vOuts, Out, i ) + Vec_PtrPush( vOutsPtr, Abc_NtkCo(pNtk, Out) ); +} + /**Function************************************************************* Synopsis [Returns representative of the given node.] @@ -744,7 +920,6 @@ static inline Abc_Obj_t * Abc_NtkPartStitchCopy1( Vec_Ptr_t * vEquiv, Abc_Obj_t return Abc_ObjNotCond( pRepr->pCopy, pRepr->fPhase ^ pFan->fPhase ^ Abc_ObjFaninC1(pObj) ); } - /**Function************************************************************* Synopsis [] @@ -781,24 +956,18 @@ Hop_Man_t * Abc_NtkPartStartHop( Abc_Ntk_t * pNtk ) pMan->vObjs = Vec_PtrAlloc( Abc_NtkObjNumMax(pNtk) + 1 ); Vec_PtrPush( pMan->vObjs, Hop_ManConst1(pMan) ); // map constant node and PIs - Abc_AigConst1(pNtk->pManFunc)->pNext = (Abc_Obj_t *)Hop_ManConst1(pMan); + Abc_AigConst1(pNtk)->pNext = (Abc_Obj_t *)Hop_ManConst1(pMan); Abc_NtkForEachCi( pNtk, pObj, i ) pObj->pNext = (Abc_Obj_t *)Hop_ObjCreatePi(pMan); // map the internal nodes -// Abc_AigForEachAnd( pNtk, pObj, i ) - Abc_NtkForEachNode( pNtk, pObj, i ) + Abc_AigForEachAnd( pNtk, pObj, i ) { - if ( Abc_ObjFaninNum(pObj) == 0 ) - continue; pObj->pNext = (Abc_Obj_t *)Hop_And( pMan, Hop_ObjChild0Next(pObj), Hop_ObjChild1Next(pObj) ); assert( !Abc_ObjIsComplement(pObj->pNext) ); } // set the choice nodes -// Abc_AigForEachAnd( pNtk, pObj, i ) - Abc_NtkForEachNode( pNtk, pObj, i ) + Abc_AigForEachAnd( pNtk, pObj, i ) { - if ( Abc_ObjFaninNum(pObj) == 0 ) - continue; if ( pObj->pCopy ) ((Hop_Obj_t *)pObj->pNext)->pData = pObj->pCopy->pNext; } @@ -811,58 +980,6 @@ Hop_Man_t * Abc_NtkPartStartHop( Abc_Ntk_t * pNtk ) return pMan; } -/**Function************************************************************* - - Synopsis [Maps terminals of the old networks into those of the new network.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Abc_NtkPartMapTerminals( Vec_Ptr_t * vParts, Abc_Ntk_t * pNtkOld ) -{ - Abc_Ntk_t * pNtkNew; - stmm_table * tTablePi, * tTablePo; - Abc_Obj_t * pObj, * pTemp; - int i, k; - - // map names into old nodes - tTablePi = stmm_init_table( strcmp, stmm_strhash ); - tTablePo = stmm_init_table( strcmp, stmm_strhash ); - Abc_NtkForEachPi( pNtkOld, pObj, i ) - stmm_insert( tTablePi, Abc_ObjName(pObj), (char *)pObj ); - Abc_NtkForEachPo( pNtkOld, pObj, i ) - stmm_insert( tTablePo, Abc_ObjName(pObj), (char *)pObj ); - - // map new nodes into old nodes - Vec_PtrForEachEntry( vParts, pNtkNew, k ) - { - Abc_NtkForEachPi( pNtkNew, pObj, i ) - { - if ( !stmm_lookup(tTablePi, Abc_ObjName(pObj), (char **)&pTemp) ) - { - printf( "Cannot find PI node %s in the original network.\n", Abc_ObjName(pObj) ); - return; - } - pObj->pCopy = pTemp; - } - Abc_NtkForEachPo( pNtkNew, pObj, i ) - { - if ( !stmm_lookup(tTablePo, Abc_ObjName(pObj), (char **)&pTemp) ) - { - printf( "Cannot find PO node %s in the original network.\n", Abc_ObjName(pObj) ); - return; - } - pObj->pCopy = pTemp; - } - } - stmm_free_table( tTablePi ); - stmm_free_table( tTablePo ); -} - /**Function************************************************************* Synopsis [Stitches together several networks with choice nodes.] @@ -879,36 +996,23 @@ Abc_Ntk_t * Abc_NtkPartStitchChoices( Abc_Ntk_t * pNtk, Vec_Ptr_t * vParts ) extern Abc_Ntk_t * Abc_NtkHopRemoveLoops( Abc_Ntk_t * pNtk, Hop_Man_t * pMan ); Hop_Man_t * pMan; - Abc_Ntk_t * pNtkNew, * pNtkTemp; Vec_Ptr_t * vNodes; + Abc_Ntk_t * pNtkNew, * pNtkTemp; Abc_Obj_t * pObj, * pFanin; - int i, k; + int i, k, iNodeId; // start a new network similar to the original one assert( Abc_NtkIsStrash(pNtk) ); - pNtkNew = Abc_NtkStartFrom( pNtk, ABC_TYPE_STRASH, ABC_FUNC_AIG ); - + pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG ); // annotate parts to point to the new network Vec_PtrForEachEntry( vParts, pNtkTemp, i ) { assert( Abc_NtkIsStrash(pNtkTemp) ); Abc_NtkCleanCopy( pNtkTemp ); - } - - // perform mapping of terminals - Abc_NtkPartMapTerminals( vParts, pNtkNew ); - - - // annotate parts to point to the new network - Vec_PtrForEachEntry( vParts, pNtkTemp, i ) - { -// assert( Abc_NtkIsStrash(pNtkTemp) ); -// Abc_NtkCleanCopy( pNtkTemp ); // map the CI nodes - Abc_AigConst1(pNtkTemp->pManFunc)->pCopy = Abc_AigConst1(pNtkNew->pManFunc); -/* + Abc_AigConst1(pNtkTemp)->pCopy = Abc_AigConst1(pNtkNew); Abc_NtkForEachCi( pNtkTemp, pObj, k ) { iNodeId = Nm_ManFindIdByNameTwoTypes( pNtkNew->pManName, Abc_ObjName(pObj), ABC_OBJ_PI, ABC_OBJ_BO ); @@ -919,16 +1023,14 @@ Abc_Ntk_t * Abc_NtkPartStitchChoices( Abc_Ntk_t * pNtk, Vec_Ptr_t * vParts ) } pObj->pCopy = Abc_NtkObj( pNtkNew, iNodeId ); } -*/ + // add the internal nodes while saving representatives vNodes = Abc_AigDfs( pNtkTemp, 1, 0 ); Vec_PtrForEachEntry( vNodes, pObj, k ) { - if ( Abc_ObjFaninNum(pObj) == 0 ) - continue; pObj->pCopy = Abc_AigAnd( pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) ); assert( !Abc_ObjIsComplement(pObj->pCopy) ); - if ( Abc_NodeIsAigChoice(pObj) ) + if ( Abc_AigNodeIsChoice(pObj) ) for ( pFanin = pObj->pData; pFanin; pFanin = pFanin->pData ) pFanin->pCopy->pCopy = pObj->pCopy; } @@ -937,7 +1039,6 @@ Abc_Ntk_t * Abc_NtkPartStitchChoices( Abc_Ntk_t * pNtk, Vec_Ptr_t * vParts ) // map the CO nodes Abc_NtkForEachCo( pNtkTemp, pObj, k ) { -/* iNodeId = Nm_ManFindIdByNameTwoTypes( pNtkNew->pManName, Abc_ObjName(pObj), ABC_OBJ_PO, ABC_OBJ_BI ); if ( iNodeId == -1 ) { @@ -945,11 +1046,23 @@ Abc_Ntk_t * Abc_NtkPartStitchChoices( Abc_Ntk_t * pNtk, Vec_Ptr_t * vParts ) return NULL; } pObj->pCopy = Abc_NtkObj( pNtkNew, iNodeId ); -*/ Abc_ObjAddFanin( pObj->pCopy, Abc_ObjChild0Copy(pObj) ); } } + // connect the remaining POs +/* + Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew); + Abc_NtkForEachCi( pNtk, pObj, i ) + pObj->pCopy = Abc_NtkCi( pNtkNew, i ); + Abc_NtkForEachCo( pNtk, pObj, i ) + pObj->pCopy = Abc_NtkCo( pNtkNew, i ); +*/ + Abc_NtkForEachCo( pNtk, pObj, i ) + { + if ( Abc_ObjFaninNum(pObj->pCopy) == 0 ) + Abc_ObjAddFanin( pObj->pCopy, Abc_ObjChild0Copy(pObj) ); + } // transform into the HOP manager pMan = Abc_NtkPartStartHop( pNtkNew ); @@ -977,49 +1090,112 @@ Abc_Ntk_t * Abc_NtkPartStitchChoices( Abc_Ntk_t * pNtk, Vec_Ptr_t * vParts ) SeeAlso [] ***********************************************************************/ -Abc_Ntk_t * Abc_NtkFraigPartitioned( Abc_Ntk_t * pNtk, void * pParams ) +Abc_Ntk_t * Abc_NtkFraigPartitioned( Vec_Ptr_t * vStore, void * pParams ) { extern int Cmd_CommandExecute( void * pAbc, char * sCommand ); extern void * Abc_FrameGetGlobalFrame(); - Vec_Vec_t * vParts; - Vec_Ptr_t * vFraigs, * vOne; - Abc_Ntk_t * pNtkAig, * pNtkFraig; - int i; + Vec_Ptr_t * vParts, * vFraigs, * vOnePtr; + Vec_Int_t * vOne; + Abc_Ntk_t * pNtk, * pNtk2, * pNtkAig, * pNtkFraig; + int i, k; // perform partitioning + pNtk = Vec_PtrEntry( vStore, 0 ); assert( Abc_NtkIsStrash(pNtk) ); // vParts = Abc_NtkPartitionNaive( pNtk, 20 ); - vParts = Abc_NtkPartitionSmart( pNtk, 0, 0 ); + vParts = Abc_NtkPartitionSmart( pNtk, 300, 0 ); Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "unset progressbar" ); // fraig each partition - vFraigs = Vec_PtrAlloc( Vec_VecSize(vParts) ); - Vec_VecForEachLevel( vParts, vOne, i ) + vOnePtr = Vec_PtrAlloc( 1000 ); + vFraigs = Vec_PtrAlloc( Vec_PtrSize(vParts) ); + Vec_PtrForEachEntry( vParts, vOne, i ) { - pNtkAig = Abc_NtkCreateConeArray( pNtk, vOne, 0 ); - pNtkFraig = Abc_NtkFraig( pNtkAig, pParams, 0 ); + // start the partition + Abc_NtkConvertCos( pNtk, vOne, vOnePtr ); + pNtkAig = Abc_NtkCreateConeArray( pNtk, vOnePtr, 0 ); + // add nodes to the partition + Vec_PtrForEachEntryStart( vStore, pNtk2, k, 1 ) + { + Abc_NtkConvertCos( pNtk2, vOne, vOnePtr ); + Abc_NtkAppendToCone( pNtkAig, pNtk2, vOnePtr ); + } + printf( "Fraiging part %4d (out of %4d) PI = %5d. PO = %5d. And = %6d. Lev = %4d.\r", + i+1, Vec_PtrSize(vParts), Abc_NtkPiNum(pNtkAig), Abc_NtkPoNum(pNtkAig), + Abc_NtkNodeNum(pNtkAig), Abc_AigLevel(pNtkAig) ); + // fraig the partition + pNtkFraig = Abc_NtkFraig( pNtkAig, pParams, 1, 0 ); Vec_PtrPush( vFraigs, pNtkFraig ); Abc_NtkDelete( pNtkAig ); - - printf( "Finished part %d (out of %d)\r", i+1, Vec_VecSize(vParts) ); } - Vec_VecFree( vParts ); - printf( " \r" ); + printf( " \r" ); + Vec_VecFree( (Vec_Vec_t *)vParts ); Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "set progressbar" ); // derive the final network pNtkFraig = Abc_NtkPartStitchChoices( pNtk, vFraigs ); Vec_PtrForEachEntry( vFraigs, pNtkAig, i ) + Abc_NtkDelete( pNtkAig ); + Vec_PtrFree( vFraigs ); + Vec_PtrFree( vOnePtr ); + return pNtkFraig; +} + +/**Function************************************************************* + + Synopsis [Stitches together several networks with choice nodes.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_NtkFraigPartitionedTime( Abc_Ntk_t * pNtk, void * pParams ) +{ + extern int Cmd_CommandExecute( void * pAbc, char * sCommand ); + extern void * Abc_FrameGetGlobalFrame(); + + Vec_Ptr_t * vParts, * vFraigs, * vOnePtr; + Vec_Int_t * vOne; + Abc_Ntk_t * pNtkAig, * pNtkFraig; + int i; + int clk = clock(); + + // perform partitioning + assert( Abc_NtkIsStrash(pNtk) ); +// vParts = Abc_NtkPartitionNaive( pNtk, 20 ); + vParts = Abc_NtkPartitionSmart( pNtk, 300, 0 ); + + Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "unset progressbar" ); + + // fraig each partition + vOnePtr = Vec_PtrAlloc( 1000 ); + vFraigs = Vec_PtrAlloc( Vec_PtrSize(vParts) ); + Vec_PtrForEachEntry( vParts, vOne, i ) { -// Abc_NtkPrintStats( stdout, pNtkAig, 0 ); + Abc_NtkConvertCos( pNtk, vOne, vOnePtr ); + pNtkAig = Abc_NtkCreateConeArray( pNtk, vOnePtr, 0 ); + pNtkFraig = Abc_NtkFraig( pNtkAig, pParams, 0, 0 ); + Vec_PtrPush( vFraigs, pNtkFraig ); Abc_NtkDelete( pNtkAig ); + + printf( "Finished part %5d (out of %5d)\r", i+1, Vec_PtrSize(vParts) ); } - Vec_PtrFree( vFraigs ); + Vec_VecFree( (Vec_Vec_t *)vParts ); - return pNtkFraig; + Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "set progressbar" ); + + // derive the final network + Vec_PtrForEachEntry( vFraigs, pNtkAig, i ) + Abc_NtkDelete( pNtkAig ); + Vec_PtrFree( vFraigs ); + Vec_PtrFree( vOnePtr ); + PRT( "Partitioned fraiging time", clock() - clk ); } //////////////////////////////////////////////////////////////////////// -- cgit v1.2.3