ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaSwitch.c File Reference
#include "giaAig.h"
#include "base/main/main.h"
Include dependency graph for giaSwitch.c:

Go to the source code of this file.

Classes

struct  Gia_ParSwi_t_
 
struct  Gia_ManSwi_t_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Gia_ParSwi_t_ Gia_ParSwi_t
 DECLARATIONS ///.
 
typedef struct Gia_ManSwi_t_ Gia_ManSwi_t
 

Functions

void Gia_ManSetDefaultParamsSwi (Gia_ParSwi_t *p)
 FUNCTION DEFINITIONS ///.
 
Gia_ManSwi_tGia_ManSwiCreate (Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
 
void Gia_ManSwiDelete (Gia_ManSwi_t *p)
 
float Gia_ManSwiComputeSwitching (int nOnes, int nSimWords)
 
float Gia_ManSwiComputeProbOne (int nOnes, int nSimWords)
 
Vec_Int_tGia_ManSwiSimulate (Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
 
Vec_Int_tGia_ManComputeSwitchProbs (Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne)
 
Vec_Int_tGia_ManComputeSwitchProbs2 (Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne, int nRandPiFactor)
 
Vec_Int_tSaig_ManComputeSwitchProbs (Aig_Man_t *pAig, int nFrames, int nPref, int fProbOne)
 
float Gia_ManEvaluateSwitching (Gia_Man_t *p)
 
float Gia_ManComputeSwitching (Gia_Man_t *p, int nFrames, int nPref, int fProbOne)
 
Vec_Flt_tGia_ManPrintOutputProb (Gia_Man_t *p)
 

Typedef Documentation

◆ Gia_ManSwi_t

typedef struct Gia_ManSwi_t_ Gia_ManSwi_t

Definition at line 45 of file giaSwitch.c.

◆ Gia_ParSwi_t

typedef typedefABC_NAMESPACE_IMPL_START struct Gia_ParSwi_t_ Gia_ParSwi_t

DECLARATIONS ///.

CFile****************************************************************

FileName [giaSwitch.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Computing switching activity.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
giaSwitch.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 32 of file giaSwitch.c.

Function Documentation

◆ Gia_ManComputeSwitching()

float Gia_ManComputeSwitching ( Gia_Man_t * p,
int nFrames,
int nPref,
int fProbOne )

Function*************************************************************

Synopsis [Computes probability of switching (or of being 1).]

Description []

SideEffects []

SeeAlso []

Definition at line 808 of file giaSwitch.c.

809{
810 Vec_Int_t * vSwitching = Gia_ManComputeSwitchProbs( p, nFrames, nPref, fProbOne );
811 float * pSwi = (float *)Vec_IntArray(vSwitching), SwiTotal = 0;
812 Gia_Obj_t * pObj;
813 int i, k, iFan;
814 if ( Gia_ManHasMapping(p) )
815 {
816 Gia_ManForEachLut( p, i )
817 Gia_LutForEachFanin( p, i, iFan, k )
818 SwiTotal += pSwi[iFan];
819 }
820 else
821 {
822 Gia_ManForEachAnd( p, pObj, i )
823 SwiTotal += pSwi[Gia_ObjFaninId0(pObj, i)] + pSwi[Gia_ObjFaninId1(pObj, i)];
824 }
825 if ( 0 )
826 {
827 Gia_ManForEachObj( p, pObj, i )
828 {
829 printf( "Switch %6.2f ", pSwi[i] );
830 Gia_ObjPrint( p, pObj );
831 }
832 }
833 Vec_IntFree( vSwitching );
834 return SwiTotal;
835}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
Vec_Int_t * Gia_ManComputeSwitchProbs(Gia_Man_t *pGia, int nFrames, int nPref, int fProbOne)
Definition giaSwitch.c:658
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
#define Gia_ManForEachLut(p, i)
Definition gia.h:1157
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition gia.h:1161
void Gia_ObjPrint(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:1456
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManComputeSwitchProbs()

Vec_Int_t * Gia_ManComputeSwitchProbs ( Gia_Man_t * pGia,
int nFrames,
int nPref,
int fProbOne )

Function*************************************************************

Synopsis [Computes probability of switching (or of being 1).]

Description []

SideEffects []

SeeAlso []

Definition at line 658 of file giaSwitch.c.

659{
660 Gia_ParSwi_t Pars, * pPars = &Pars;
661 // set the default parameters
663 // override some of the defaults
664 pPars->nIters = nFrames; // set number of total timeframes
665 if ( Abc_FrameReadFlag("seqsimframes") )
666 pPars->nIters = atoi( Abc_FrameReadFlag("seqsimframes") );
667 pPars->nPref = nPref; // set number of first timeframes to skip
668 // decide what should be computed
669 if ( fProbOne )
670 {
671 // if the user asked to compute propability of 1, we do not need transition information
672 pPars->fProbOne = 1; // enable computing probabiblity of being one
673 pPars->fProbTrans = 0; // disable computing transition probability
674 }
675 else
676 {
677 // if the user asked for transition propabability, we do not need to compute probability of 1
678 pPars->fProbOne = 0; // disable computing probabiblity of being one
679 pPars->fProbTrans = 1; // enable computing transition probability
680 }
681 // perform the computation of switching activity
682 return Gia_ManSwiSimulate( pGia, pPars );
683}
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition mainFrame.c:69
void Gia_ManSetDefaultParamsSwi(Gia_ParSwi_t *p)
FUNCTION DEFINITIONS ///.
Definition giaSwitch.c:77
Vec_Int_t * Gia_ManSwiSimulate(Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
Definition giaSwitch.c:556
typedefABC_NAMESPACE_IMPL_START struct Gia_ParSwi_t_ Gia_ParSwi_t
DECLARATIONS ///.
Definition giaSwitch.c:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManComputeSwitchProbs2()

Vec_Int_t * Gia_ManComputeSwitchProbs2 ( Gia_Man_t * pGia,
int nFrames,
int nPref,
int fProbOne,
int nRandPiFactor )

Definition at line 684 of file giaSwitch.c.

685{
686 Gia_ParSwi_t Pars, * pPars = &Pars;
687 // set the default parameters
689 pPars->nRandPiFactor = nRandPiFactor;
690 // override some of the defaults
691 pPars->nIters = nFrames; // set number of total timeframes
692 if ( Abc_FrameReadFlag("seqsimframes") )
693 pPars->nIters = atoi( Abc_FrameReadFlag("seqsimframes") );
694 pPars->nPref = nPref; // set number of first timeframes to skip
695 // decide what should be computed
696 if ( fProbOne )
697 {
698 // if the user asked to compute propability of 1, we do not need transition information
699 pPars->fProbOne = 1; // enable computing probabiblity of being one
700 pPars->fProbTrans = 0; // disable computing transition probability
701 }
702 else
703 {
704 // if the user asked for transition propabability, we do not need to compute probability of 1
705 pPars->fProbOne = 0; // disable computing probabiblity of being one
706 pPars->fProbTrans = 1; // enable computing transition probability
707 }
708 // perform the computation of switching activity
709 return Gia_ManSwiSimulate( pGia, pPars );
710}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManEvaluateSwitching()

float Gia_ManEvaluateSwitching ( Gia_Man_t * p)

Function*************************************************************

Synopsis [Computes probability of switching (or of being 1).]

Description []

SideEffects []

SeeAlso []

Definition at line 746 of file giaSwitch.c.

747{
748 Gia_Obj_t * pObj;
749 float SwitchTotal = 0.0;
750 int i;
751 assert( p->pSwitching );
752 ABC_FREE( p->pRefs );
754 Gia_ManForEachObj( p, pObj, i )
755 SwitchTotal += (float)Gia_ObjRefNum(p, pObj) * p->pSwitching[i] / 255;
756 return SwitchTotal;
757}
#define ABC_FREE(obj)
Definition abc_global.h:267
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition giaUtil.c:779
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:

◆ Gia_ManPrintOutputProb()

Vec_Flt_t * Gia_ManPrintOutputProb ( Gia_Man_t * p)

Function*************************************************************

Synopsis [Determine probability of being 1 at the outputs.]

Description []

SideEffects []

SeeAlso []

Definition at line 848 of file giaSwitch.c.

849{
850 Vec_Flt_t * vSimData;
851 Gia_Man_t * pDfs = Gia_ManDup( p );
852 assert( Gia_ManObjNum(pDfs) == Gia_ManObjNum(p) );
853 vSimData = (Vec_Flt_t *)Gia_ManComputeSwitchProbs( pDfs, (Gia_ManRegNum(p) ? 16 : 1), 0, 1 );
854 Gia_ManStop( pDfs );
855 return vSimData;
856}
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
Definition vecFlt.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManSetDefaultParamsSwi()

void Gia_ManSetDefaultParamsSwi ( Gia_ParSwi_t * p)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [This procedure sets default parameters.]

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file giaSwitch.c.

78{
79 memset( p, 0, sizeof(Gia_ParSwi_t) );
80 p->nWords = 10; // the number of machine words of simulatation data
81 p->nIters = 48; // the number of all timeframes to simulate
82 p->nPref = 16; // the number of first timeframes to skip when computing switching
83 p->nRandPiFactor = 0; // primary input transition probability (-1=3/8; 0=1/2; 1=1/4; 2=1/8, etc)
84 p->fProbOne = 0; // compute probability of signal being one (if 0, compute probability of switching)
85 p->fProbTrans = 1; // compute signal transition probability (if 0, compute transition probability using probability of being one)
86 p->fVerbose = 0; // enables verbose output
87}
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManSwiComputeProbOne()

float Gia_ManSwiComputeProbOne ( int nOnes,
int nSimWords )

Function*************************************************************

Synopsis [Computes switching activity of one node.]

Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]

SideEffects []

SeeAlso []

Definition at line 539 of file giaSwitch.c.

540{
541 int nTotal = 32 * nSimWords;
542 return (float)nOnes / nTotal;
543}
int nTotal
DECLARATIONS ///.
Definition cutTruth.c:37
Here is the caller graph for this function:

◆ Gia_ManSwiComputeSwitching()

float Gia_ManSwiComputeSwitching ( int nOnes,
int nSimWords )

Function*************************************************************

Synopsis [Computes switching activity of one node.]

Description [Uses the formula: Switching = 2 * nOnes * nZeros / (nTotal ^ 2) ]

SideEffects []

SeeAlso []

Definition at line 522 of file giaSwitch.c.

523{
524 int nTotal = 32 * nSimWords;
525 return (float)2.0 * nOnes / nTotal * (nTotal - nOnes) / nTotal;
526}
Here is the caller graph for this function:

◆ Gia_ManSwiCreate()

Gia_ManSwi_t * Gia_ManSwiCreate ( Gia_Man_t * pAig,
Gia_ParSwi_t * pPars )

Function*************************************************************

Synopsis [Creates fast simulation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 100 of file giaSwitch.c.

101{
102 Gia_ManSwi_t * p;
103 p = ABC_ALLOC( Gia_ManSwi_t, 1 );
104 memset( p, 0, sizeof(Gia_ManSwi_t) );
105 p->pAig = Gia_ManFront( pAig );
106 p->pPars = pPars;
107 p->nWords = pPars->nWords;
108 p->pDataSim = ABC_ALLOC( unsigned, p->nWords * p->pAig->nFront );
109 p->pDataSimCis = ABC_ALLOC( unsigned, p->nWords * Gia_ManCiNum(p->pAig) );
110 p->pDataSimCos = ABC_ALLOC( unsigned, p->nWords * Gia_ManCoNum(p->pAig) );
111 p->pData1 = ABC_CALLOC( int, Gia_ManObjNum(pAig) );
112 return p;
113}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
struct Gia_ManSwi_t_ Gia_ManSwi_t
Definition giaSwitch.c:45
Gia_Man_t * Gia_ManFront(Gia_Man_t *p)
Definition giaFront.c:147
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManSwiDelete()

void Gia_ManSwiDelete ( Gia_ManSwi_t * p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file giaSwitch.c.

127{
128 Gia_ManStop( p->pAig );
129 ABC_FREE( p->pData1 );
130 ABC_FREE( p->pDataSim );
131 ABC_FREE( p->pDataSimCis );
132 ABC_FREE( p->pDataSimCos );
133 ABC_FREE( p );
134}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManSwiSimulate()

Vec_Int_t * Gia_ManSwiSimulate ( Gia_Man_t * pAig,
Gia_ParSwi_t * pPars )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 556 of file giaSwitch.c.

557{
558 Gia_ManSwi_t * p;
559 Gia_Obj_t * pObj;
560 Vec_Int_t * vSwitching;
561 float * pSwitching;
562 int i;
563 abctime clk, clkTotal = Abc_Clock();
564 if ( pPars->fProbOne && pPars->fProbTrans )
565 printf( "Conflict of options: Can either compute probability of 1, or probability of switching by observing transitions.\n" );
566 // create manager
567 clk = Abc_Clock();
568 p = Gia_ManSwiCreate( pAig, pPars );
569 if ( pPars->fVerbose )
570 {
571 printf( "Obj = %8d (%8d). F = %6d. ",
572 pAig->nObjs, Gia_ManCiNum(pAig) + Gia_ManAndNum(pAig), p->pAig->nFront );
573 printf( "AIG = %7.2f MB. F-mem = %7.2f MB. Other = %7.2f MB. ",
574 12.0*Gia_ManObjNum(p->pAig)/(1<<20),
575 4.0*p->nWords*p->pAig->nFront/(1<<20),
576 4.0*p->nWords*(Gia_ManCiNum(p->pAig) + Gia_ManCoNum(p->pAig))/(1<<20) );
577 ABC_PRT( "Time", Abc_Clock() - clk );
578 }
579 // perform simulation
580 Gia_ManRandom( 1 );
581 Gia_ManSwiSimInfoInit( p );
582 for ( i = 0; i < pPars->nIters; i++ )
583 {
584 Gia_ManSwiSimulateRound( p, i >= pPars->nPref );
585 if ( i == pPars->nIters - 1 )
586 break;
587 if ( pPars->fProbTrans )
588 Gia_ManSwiSimInfoTransferShift( p, pPars->nRandPiFactor );
589 else
590 Gia_ManSwiSimInfoTransfer( p, pPars->nRandPiFactor );
591 }
592 if ( pPars->fVerbose )
593 {
594 printf( "Simulated %d frames with %d words. ", pPars->nIters, pPars->nWords );
595 ABC_PRT( "Simulation time", Abc_Clock() - clkTotal );
596 }
597 // derive the result
598 vSwitching = Vec_IntStart( Gia_ManObjNum(pAig) );
599 pSwitching = (float *)vSwitching->pArray;
600 if ( pPars->fProbOne )
601 {
602 Gia_ManForEachObj( pAig, pObj, i )
603 pSwitching[i] = Gia_ManSwiComputeProbOne( p->pData1[i], pPars->nWords*(pPars->nIters-pPars->nPref) );
604 Gia_ManForEachCo( pAig, pObj, i )
605 {
606 if ( Gia_ObjFaninC0(pObj) )
607 pSwitching[Gia_ObjId(pAig,pObj)] = (float)1.0-pSwitching[Gia_ObjId(pAig,Gia_ObjFanin0(pObj))];
608 else
609 pSwitching[Gia_ObjId(pAig,pObj)] = pSwitching[Gia_ObjId(pAig,Gia_ObjFanin0(pObj))];
610 }
611 }
612 else if ( pPars->fProbTrans )
613 {
614 Gia_ManForEachObj( pAig, pObj, i )
615 pSwitching[i] = Gia_ManSwiComputeSwitching( p->pData1[i], pPars->nWords*(pPars->nIters-pPars->nPref) );
616 }
617 else
618 {
619 Gia_ManForEachObj( pAig, pObj, i )
620 pSwitching[i] = Gia_ManSwiComputeSwitching( p->pData1[i], pPars->nWords*(pPars->nIters-pPars->nPref) );
621 }
622/*
623 printf( "PI: " );
624 Gia_ManForEachPi( pAig, pObj, i )
625 printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
626 printf( "\n" );
627
628 printf( "LO: " );
629 Gia_ManForEachRo( pAig, pObj, i )
630 printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
631 printf( "\n" );
632
633 printf( "PO: " );
634 Gia_ManForEachPo( pAig, pObj, i )
635 printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
636 printf( "\n" );
637
638 printf( "LI: " );
639 Gia_ManForEachRi( pAig, pObj, i )
640 printf( "%d=%d (%f) ", i, p->pData1[Gia_ObjId(pAig,pObj)], pSwitching[Gia_ObjId(pAig,pObj)] );
641 printf( "\n" );
642*/
644 return vSwitching;
645
646}
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
float Gia_ManSwiComputeProbOne(int nOnes, int nSimWords)
Definition giaSwitch.c:539
float Gia_ManSwiComputeSwitching(int nOnes, int nSimWords)
Definition giaSwitch.c:522
void Gia_ManSwiDelete(Gia_ManSwi_t *p)
Definition giaSwitch.c:126
Gia_ManSwi_t * Gia_ManSwiCreate(Gia_Man_t *pAig, Gia_ParSwi_t *pPars)
Definition giaSwitch.c:100
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
int nObjs
Definition gia.h:103
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Saig_ManComputeSwitchProbs()

Vec_Int_t * Saig_ManComputeSwitchProbs ( Aig_Man_t * pAig,
int nFrames,
int nPref,
int fProbOne )

Definition at line 711 of file giaSwitch.c.

712{
713 Vec_Int_t * vSwitching, * vResult;
714 Gia_Man_t * p;
715 Aig_Obj_t * pObj;
716 int i;
717 // translate AIG into the intermediate form (takes care of choices if present!)
718 p = Gia_ManFromAigSwitch( pAig );
719 // perform the computation of switching activity
720 vSwitching = Gia_ManComputeSwitchProbs( p, nFrames, nPref, fProbOne );
721 // transfer the computed result to the original AIG
722 vResult = Vec_IntStart( Aig_ManObjNumMax(pAig) );
723 Aig_ManForEachObj( pAig, pObj, i )
724 {
725// if ( Aig_ObjIsCo(pObj) )
726// printf( "%d=%f\n", i, Abc_Int2Float( Vec_IntEntry(vSwitching, Abc_Lit2Var(pObj->iData)) ) );
727 Vec_IntWriteEntry( vResult, i, Vec_IntEntry(vSwitching, Abc_Lit2Var(pObj->iData)) );
728 }
729 // delete intermediate results
730 Vec_IntFree( vSwitching );
731 Gia_ManStop( p );
732 return vResult;
733}
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
Gia_Man_t * Gia_ManFromAigSwitch(Aig_Man_t *p)
Definition giaAig.c:252
int iData
Definition aig.h:88
Here is the call graph for this function:
Here is the caller graph for this function: