Ë
    ›ÐVhã  ã                   óæ   — d dl Z d dlZd dlmZ d dlmZ ddlmZ ddlm	Z	  e j                  e«      Z	 e G d„ d«      «       Zd	e	d
efd„Zd	e	defd„Zd	e	defd„Zdedefd„Zdededeeef   fd„Zy)é    N)Ú	dataclass)Ú	CompileIdé   )Úconfig)ÚDynamoFrameTypec                   ó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_with_same_id_matched_objsÚlimitÚreturnc                 óH   — | j                  «       xs | j                  |«      S ©N)Ú)will_compilation_exceed_accumulated_limitÚ&will_compilation_exceed_specific_limit©Úselfr   s     úH/home/dcms/DCMS/lib/python3.12/site-packages/torch/_dynamo/cache_size.pyÚwill_compilation_exceedz1CacheSizeRelevantForFrame.will_compilation_exceedX   s)   € ð ×:Ñ:Ó<ò BØ×:Ñ:¸5ÓAð	
ó    c                 ó<   — | j                   t        j                  k\  S r   )r
   r   Úaccumulated_recompile_limit)r   s    r   r   zCCacheSizeRelevantForFrame.will_compilation_exceed_accumulated_limit_   s   € Ø×%Ñ%¬×)KÑ)KÑKÐKr   c                 ó    — | j                   |k\  S r   )r   r   s     r   r   z@CacheSizeRelevantForFrame.will_compilation_exceed_specific_limitb   s   € Ø×?Ñ?À5ÑHÐHr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚintÚ__annotations__r   Úboolr   r   r   © r   r   r	   r	   G   sX   … ñð ÐsÓð 89Ð/°Ó8ð
¨Sð 
°Tó 
ðL¸4ó LðI¸Cð IÀDô Ir   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,   f   sP   € Ø
.‰.×
Ñ
˜Z¨Ó
.€CØ€GðÜ—+‘+˜cÓ"ˆð €Nøô ò ØØ€Nðús    7 ·	AÁAr   c                 ó–   — |sy|j                   j                  j                  «       D ]  \  }} |«       €Œt        | |«      }||usŒ y y)zk
    Checks if the ID_MATCH'd objects saved on cache_entry are same as the ones
    in frame.f_locals.
    FT)Úguard_managerÚid_matched_objsÚitemsr,   )r"   Úcache_entryr#   Úweakref_from_cache_entryÚweakref_from_frames        r   Ú_has_same_id_matched_objsr4   p   s`   € ñ
 Øð
 
×	"Ñ	"×	2Ñ	2×	8Ñ	8Ó	:òñ 	ØØ á#Ó%Ñ1Ü!;¸EÀ:Ó!NÐØ!Ð)AÒAÙðð r   c                 óp   — d}d}|r%|dz  }t        | |«      r|dz  }|j                  }|rŒ%t        ||«      S )Nr   r   )r4   Únextr	   )r"   r1   r
   r   s       r   Úcompute_cache_sizer7   …   sZ   € ð ÐØ23Ð/á
Ø˜QÑÐô % U¨KÔ8Ø7¸1Ñ<Ð7Ø!×&Ñ&ˆò ô %ØÐFóð r   Ú
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   )r8   s    r   Úis_recompilationr:   š   s   € ð ×-Ñ-¨aÓ0Ð0r   Ú
compile_idc                 ó¾   — | j                  «       ry| j                  t        j                  «      ry|j                  €J ‚|j                  t        j
                  k\  ryy)z:
    Checks if we are exceeding the cache size limit.
    )Tr   )TÚrecompile_limit)FÚ )r   r   r   r=   Úframe_compile_idr   )r8   r;   s     r   Úexceeds_recompile_limitr@   §   sX   € ð ×;Ñ;Ô=Ø2Ø×8Ñ8¼×9OÑ9OÔPØ&ð ×&Ñ&Ð2Ð2Ð2Ø×"Ñ"¤f×&HÑ&HÒHØ2Ør   )Úloggingr'   Údataclassesr   Útorch._guardsr   r>   r   Útypesr   Ú	getLoggerr   Úlogr	   Ústrr,   r    r4   r7   r:   Útupler@   r!   r   r   ú<module>rI      sÂ   ðã Û Ý !å #å Ý "ð €g×Ñ˜Ó!€ð7ðt ÷Ið Ió ðIð< oð À3ó ð _ð Àdó ð*Øðàóð*
1Ð!:ð 
1¸tó 
1ðØ)ðØ7@ðà
ˆ4ˆ9Ñôr   