
    Ph                        d dl Z d dlZd dlZd dlmZ ddlmZ  e j                  e      Z		 e G d d             Z
dej                  defd	Zdej                  d
efdZdej                  d
e
fdZde
d
efdZde
d
efdZy)    N)	dataclass   )configc                   Z    e Zd ZU dZdZeed<   dZeed<   dedefdZ	defdZ
dedefd	Zy
)CacheSizeRelevantForFramea1  
    We track the number of cache entries that have same id_match objects as the
    given frame.

    TODO(janimesh) - Consider adding a map from tuple_of_match_ids to count -
    https://github.com/pytorch/pytorch/pull/107496#discussion_r1304564682 - this
    could be useful for debugging as well.
    r   num_cache_entriesnum_cache_entries_in_bucketlimitreturnc                 H    | j                  |      xs | j                         S N)will_compilation_exceed_bucketwill_compilation_exceed_totalselfr
   s     cC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/cache_size.pywill_compilation_exceedz1CacheSizeRelevantForFrame.will_compilation_exceedT   s&    //6 4113	
    c                 <    | j                   t        j                  k\  S r   )r   r   accumulated_cache_size_limit)r   s    r   r   z7CacheSizeRelevantForFrame.will_compilation_exceed_totalZ   s    %%)L)LLLr   c                      | j                   |k\  S r   )r	   r   s     r   r   z8CacheSizeRelevantForFrame.will_compilation_exceed_bucket]   s    //588r   N)__name__
__module____qualname____doc__r   int__annotations__r	   boolr   r   r    r   r   r   r   C   sU     s ()(
S 
T 
Mt M9C 9D 9r   r   frame
local_namec                     | j                   j                  |d       }d }	 t        j                  |      }|S # t        $ r Y |S w xY wr   )f_localsgetweakrefref	TypeError)r    r!   objweak_ids       r   _get_weakref_from_f_localsr*   a   sP    
..

Z
.CG++c" N  Ns   7 	AAr   c                     ddl m} |sy|j                  j                   |       k7  ry|j                  j                  j                         D ]   \  }} |       t        | |      }||k7  s  y y)z
    Checks if the ID_MATCH'd objects saved on cache_entry are same as the ones
    in frame.f_locals, and if the config hash used to compile the cache entry's
    optimized code is the same as the frame's.
    r   )"get_saved_else_current_config_hashFT)
eval_framer,   check_fnconfig_hashid_matched_objsitemsr*   )r    cache_entryr,   r!   weakref_from_cache_entryweakref_from_frames         r   _is_same_cache_bucketr5   k   sy     ?''+M+OO
 
			-	-	3	3	5	 #%1!;E:!N!%==	 
6 r   c                 p    d}d}|r%|dz  }t        | |      r|dz  }|j                  }|r%t        ||      S )Nr   r   )r5   nextr   )r    r2   r   r	   s       r   compute_cache_sizer8      sV     "#
Q !4'1,'!&&  %%68STTr   
cache_sizec                 $    | j                  d      S )z
    If the frame (earlier parsed by compute_cache_size) has more than 1 cache
    entry with same ID_MATCH'd objects, then its a recompilation.
    r   )r   r9   s    r   is_recompilationr<      s     --a00r   c                 @    | j                  t        j                        S )z:
    Checks if we are exceeding the cache size limit.
    )r   r   cache_size_limitr;   s    r   exceeds_cache_size_limitr?      s     --f.E.EFFr   )loggingtypesr%   dataclassesr    r   	getLoggerr   logr   	FrameTypestrr*   r   r5   r8   r<   r?   r   r   r   <module>rH      s       ! g!7t 9 9 9:eoo 3  $ 6U??UU*
1!: 
1t 
1G)B Gt Gr   