
    Αi                         S SK Jr  S SKrS SKJrJr  / r " S S5      r " S S5      r	 " S S	5      r
S
 rS rS rS rS rS rSS jrSS jr " S S5      rg)    )OrderedDictN)ProgramVariablec                   &    \ rS rSrS rS rS rSrg)
VarWrapper   c                 x    [        U[        5      (       d   e[        U[        5      (       d   eXl        X l        g N)
isinstancer   GraphWrapper_var_graph)selfvargraphs      X/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/hapi/static_flops.py__init__VarWrapper.__init__   s2    #x((((%....	    c                 .    U R                   R                  $ )z
Get the name of the variable.
)r   namer   s    r   r   VarWrapper.name   s     yy~~r   c                 .    U R                   R                  $ )z 
Get the shape of the variable.
)r   shaper   s    r   r   VarWrapper.shape%   s     yyr   )r   r   N)__name__
__module____qualname____firstlineno__r   r   r   __static_attributes__ r   r   r   r      s    r   r   c                   ,    \ rS rSrS rS rS rS rSrg)	OpWrapper,   c                 J    [        U[        5      (       d   eXl        X l        g r
   )r   r   _opr   )r   opr   s      r   r   OpWrapper.__init__-   s    %....r   c                 .    U R                   R                  $ )z 
Get the type of this operator.
)r'   typer   s    r   r+   OpWrapper.type2   s     xx}}r   c                     XR                   R                  ;   aD  U R                   R                  U5       Vs/ s H  o R                  R	                  U5      PM     sn$ / $ s  snf )z*
Get all the variables by the input name.
)r'   input_namesinputr   r   r   r   var_names      r   inputsOpWrapper.inputs8   sU     88''':>((..:N:Nh):N  I	s   $A c                     U R                   R                  U5       Vs/ s H  o R                  R                  U5      PM     sn$ s  snf )z+
Get all the variables by the output name.
)r'   outputr   r   r0   s      r   outputsOpWrapper.outputsC   s6     ;?((//$:OP:Oh):OPPPs   $A)r   r'   N)	r   r   r   r    r   r+   r2   r6   r!   r"   r   r   r$   r$   ,   s    
	Qr   r$   c                   B   ^  \ rS rSrSrS/ / 4U 4S jjrS rS rSrU =r	$ )r   J   a"  
It is a wrapper of paddle.base.framework.IrGraph with some special functions
for paddle slim framework.

Args:
    program(framework.Program): A program with
    in_nodes(dict): A dict to indicate the input nodes of the graph.
                    The key is user-defined and human-readable name.
                    The value is the name of Variable.
    out_nodes(dict): A dict to indicate the input nodes of the graph.
                    The key is user-defined and human-readable name.
                    The value is the name of Variable.
Nc                   > [         TU ]  5         Uc
  [        5       OUU l        0 U l        0 U l        U R                  R                  5        H.  nUR                  (       d  M  X@R                  UR                  '   M0     SU l	        Uc  / OUnUc  / OUn[        U5      U l        [        U5      U l        [        5       U l        g) N)superr   r   programpersistablesteacher_persistables	list_varspersistabler   compiled_graphr   in_nodes	out_nodes_attrs)r   r=   rC   rD   r   	__class__s        r   r   GraphWrapper.__init__Y   s    $+Owy$&!<<))+C.1!!#((+ , #!)2x#+B	#H-$Y/!mr   c                     / nU R                   R                   H0  nUR                   H  nUR                  [	        X05      5        M     M2     U$ )z;
Return all operator nodes included in the graph as a set.
)r=   blocksopsappendr$   )r   rJ   blockr(   s       r   rJ   GraphWrapper.opsi   sC     \\((Eii

9R./   ) 
r   c                     U R                   R                   H6  nUR                  U5      (       d  M  [        UR	                  U5      U 5      s  $    g)z$
Get the variable by variable name.
N)r=   rI   has_varr   r   )r   r   rL   s      r   r   GraphWrapper.vars   sA     \\((E}}T""!%))D/488 ) r   )rE   rB   rC   rD   r>   r=   r?   )
r   r   r   r    __doc__r   rJ   r   r!   __classcell__)rF   s   @r   r   r   J   s%      $bB $  r   r   c                 V   U R                  S5      S   R                  5       n[        R                  " USS  5      n[	        U R                  S5      5      S:  a  SOSn[        R                  " U R                  S5      S   R                  5       SS  5      nXBU-   -  n[        U5      nU$ )NFilterr      BiasOutput)r2   r   npprodlenr6   abs)r(   filter_shape
filter_opsbias_opsoutput_numel	total_opss         r   count_convNdra   }   s    99X&q)//1Lab)*J		&)*Q.qAH772::h/288:12>?LX 56IIIr   c                 x    [         R                  " U R                  S5      S   R                  5       SS  5      nU$ )NrW   r   rU   )rX   rY   r6   r   )r(   r`   s     r   count_leaky_relurc      s4    

8,Q/557;<Ir   c                     [         R                  " U R                  S5      S   R                  5       SS  5      nSU-  n[	        U5      nU$ )NYr   rU      )rX   rY   r6   r   r[   )r(   r_   r`   s      r   count_bnrg      sF    772::c?1-335ab9:LL IIIr   c                     U R                  S5      S   R                  5       S   n[        R                  " U R	                  S5      S   R                  5       SS  5      nX-  n[        U5      nU$ )Nre   r   OutrU   )r2   r   rX   rY   r6   r[   )r(   	total_mulnumelr`   s       r   count_linearrl      se    		#q!'')!,IGGBJJu%a(..045E!IIIr   c                 |   U R                  S5      S   R                  5       nU R                  S5      S   R                  5       n[        R                  " USS  5      [        R                  " USS  5      -  n[        R
                  " U5      nSnXE-   n[        R
                  " USS  5      nXg-  n[        U5      nU$ )NXr   ri   rf   rU   )r2   r   r6   rX   arrayrY   r[   )	r(   input_shapeoutput_shapekernel	total_add	total_div
kernel_opsnum_elementsr`   s	            r   count_pool2drw      s    ))C.#))+K::e$Q'--/LXXk!"o&"((<3C*DDFII&J77<+,L)IIIr   c                     U R                  S5      S   R                  5       n[        R                  " USS  5      n[	        U5      nU$ )Nrn   r   rU   )r2   r   rX   rY   r[   )r(   rp   r`   s      r   count_element_opry      s@    ))C.#))+KAB(IIIr   c                    [        U [        5      (       d   eSnSn[        / SQ5      nU R                  5        GH6  nSnUR	                  5       S;   a2  [        U5      nX#-  nUR                  S5      S   R                  5       nOUR	                  5       S:X  a  [        U5      nX#-  nOUR	                  5       S;   a2  [        U5      nX#-  nUR                  S5      S   R                  5       nOWUR	                  5       S	:X  a  [        U5      nX#-  nO3UR	                  5       R                  S
5      (       a  [        U5      nX#-  nUS:w  a!  UR                  UR	                  5       Xc/5        SnGM9     U(       a  UR                  5         U$ )Nr   )zOP Typez
Param nameFlopsr;   )conv2ddepthwise_conv2drT   pool2d)mulmatmulre   
batch_normelement)r   r   TablerJ   r+   ra   r2   r   rw   rl   rg   
startswithry   add_rowprint_table)r   detailflopsop_flopstabler(   
param_names          r   _graph_flopsr      sY   e\****EH45Eiik
77966#B'HE8,Q/446JWWY("#B'HEWWY++#B'HE3*//1JWWY,&|HEWWY!!),,'+HEq=MM2779j;<- . Lr   c                 *    [        U 5      n[        X!S9$ )N)r   )r   r   )r=   print_detailr   s      r   static_flopsr      s    !E33r   c                   2    \ rS rSrS rS rS rS rS rSr	g)	r      c                     Xl         / U l        / U l        [        U5      U l        U H'  nU R                  R                  [        U5      5        M)     g r
   )table_heads	table_lendatarZ   col_numrK   )r   r   heads      r   r   Table.__init__   sB    &	;'DNN!!#d),  r   c                    [        U[        5      (       d  [        S5        [        U5      U R                  :w  a$  [        S[        U5       SU R                   35        [        U R                  5       HO  n[        [        X   5      5      U R                  U   :  d  M,  [        [        X   5      5      U R                  U'   MQ     U R                  R                  U5        g )NzThe row_str should be a listzPThe length of row data should be equal the length of table heads, but the data: z is not equal table heads )
r   listprintrZ   r   rangestrr   r   rK   )r   row_stris      r   r   Table.add_row   s    '4((01w<4<<'bcfgncobp  qK  LP  LX  LX  KY  Z t||$A3wz?#dnnQ&77$'GJ$8q! % 			!r   c                     Sn[        U R                  5       H5  nUS[        X   5      R                  U R                  U   S-   5      -   -  nM7     US-  n[        U5        g )Nr;   |rf   )r   r   r   centerr   r   )r   rowstringr   s       r   	print_rowTable.print_row   sX    t||$AcCK..t~~a/@1/DEEEF %#fr   c                 n    SnU R                    H  nUS-  nUSUS-   -  -  nM     US-  n[        U5        g )Nr;   +-rf   )r   r   )r   r   lengths      r   print_shelfTable.print_shelf   sC    nnFcMFcVaZ((F % 	#fr   c                     U R                  5         U R                  U R                  5        U R                  5         U R                   H  nU R                  U5        M     U R                  5         g r
   )r   r   r   r   )r   r   s     r   r   Table.print_table   sR    t''(IIDNN4  r   )r   r   r   r   N)
r   r   r   r    r   r   r   r   r   r!   r"   r   r   r   r      s    -
"r   r   )F)collectionsr   numpyrX   paddle.staticr   r   __all__r   r$   r   ra   rc   rg   rl   rw   ry   r   r   r   r"   r   r   <module>r      si    $  +
 (Q Q<0 0f

B4
* *r   