o
    &jn                     @   s@   d dl Z ddlmZ ddlmZ G dd dZG dd dZdS )	    N   )
DeviceItem)	wrap_treec                   @   s`   e Zd Zdd Zedd Zedd Zedd Zd	d
 Zdd Z	dd Z
dd Zdd ZdS )OperatorItemc                 C   s^   || _ d| _d| _d| _d| _td| _d| _td| _i | _	i | _
d| _td| _d| _d S )Nr   inf)namecallcpu_timegpu_timemax_cpu_timefloatmin_cpu_timemax_gpu_timemin_gpu_timedevicesoperator_innersgeneral_gpu_timemin_general_gpu_timemax_general_gpu_time)selfr    r   s/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/visualdl/component/profiler/parser/operator_parser.py__init__   s   



zOperatorItem.__init__c                 C      | j | j S N)r	   r   r   r   r   r   avg_cpu_time%      zOperatorItem.avg_cpu_timec                 C   r   r   )r
   r   r   r   r   r   avg_gpu_time)   r   zOperatorItem.avg_gpu_timec                 C   r   r   )r   r   r   r   r   r   avg_general_gpu_time-   r   z!OperatorItem.avg_general_gpu_timec                 C   2   || j kr|| _ || jk r|| _|  j|7  _d S r   )r   r   r	   r   timer   r   r   add_cpu_time1   
   

zOperatorItem.add_cpu_timec                 C   r    r   )r   r   r
   r!   r   r   r   add_gpu_time8   r$   zOperatorItem.add_gpu_timec                 C   r    r   )r   r   r   r!   r   r   r   add_general_gpu_time?   r$   z!OperatorItem.add_general_gpu_timec                 C   s   |  j d7  _ d S )Nr   )r   r   r   r   r   add_callF   s   zOperatorItem.add_callc                 C   s   |    | |j | |j | |j |jD ]}|jdkr8|j	| j
vr/t|j	| j
|j	< | j
|j	 | q|jD ]}|jD ]}|j	}|| jvrRt|| j|< | j| | qAq<d S )NOperator)r'   r#   r	   r%   r
   r&   r   Zchildren_nodetyper   r   r   add_itemZruntime_nodeZdevice_noder   r   )r   nodechildZruntimenodeZ
devicenoder   r   r   r   r*   I   s$   




zOperatorItem.add_itemN)__name__
__module____qualname__r   propertyr   r   r   r#   r%   r&   r'   r*   r   r   r   r   r      s    


r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )OperatorParserzT
    Analyse operator event in profiling data, correlate with its device event.
    c                 C   s   i | _ tt| _d S r   )itemscollectionsdefaultdictdictitems_with_input_shaper   r   r   r   r   a   s   zOperatorParser.__init__c                 C   sH   t |\}}| D ]\}}|dd D ]}|jdkr | | qq
dS )z;
        Analysis operator event in the nodetress.
        r   Nr(   )r   r2   r)   add_operator_item)r   Z	nodetreesZnode_statistic_treesZthread2host_statistic_nodesZthreadidZhost_statistic_nodesZhost_statistic_noder   r   r   parsee   s   

zOperatorParser.parsec                 C   s|   |j | jvrt|j | j|j < | |j}|| j|j  vr(t|j | j|j  |< | j|j  | | j|j  | | d S r   )r   r2   r   #_translate_op_input_shape_to_stringZinput_shapesr6   r*   )r   Zoperator_nodeZinput_shape_strr   r   r   r7   r   s.   z OperatorParser.add_operator_itemc                 C   s*   d}|  D ]\}}|d||7 }q|S )N z{}-{}	)r2   format)r   Zinput_shaperesultargshaper   r   r   r9      s   z2OperatorParser._translate_op_input_shape_to_stringN)r-   r.   r/   __doc__r   r8   r7   r9   r   r   r   r   r1   \   s    r1   )r3   Zkernel_parserr   utilsr   r   r1   r   r   r   r   <module>   s
   G