§
    ƒÛgª  ã                   ó‚   — d Z ddlZddlZddlmZ  G d„ d¦  «        Z G d„ dej        ¦  «        Z G d„ d	e¦  «        ZdS )
z¢
Implement utils for supporting retargeting of dispatchers.

WARNING: Features defined in this file are experimental. The API may change
         without notice.
é    N)Úerrorsc                   ó>   — e Zd ZdZej        Zd„ Zd„ Zd„ Z	d„ Z
d„ ZdS )ÚRetargetCachez^Cache for retargeted dispatchers.

    The cache uses the original dispatcher as the key.
    c                 óT   — |                       ¦   «         | _        d| _        d| _        d S )Nr   )Úcontainer_typeÚ_cacheÚ	_stat_hitÚ
_stat_miss©Úselfs    úI/granary/edev/quantum/lib/python3.11/site-packages/numba/core/retarget.pyÚ__init__zRetargetCache.__init__   s'   € Ø×)Ò)Ñ+Ô+ˆŒØˆŒØˆŒˆˆó    c                 ó   — || j         |<   dS )z9Save a dispatcher associated with the given key.
        N)r   )r   Ú	orig_dispÚnew_disps      r   Ú
save_cachezRetargetCache.save_cache   s   € ð "*ˆŒ�IÑÐÐr   c                 ó€   — | j                              |¦  «        }|€| xj        dz  c_        n| xj        dz  c_        |S )z9Load a dispatcher associated with the given key.
        Né   )r   Úgetr
   r	   )r   r   Úouts      r   Ú
load_cachezRetargetCache.load_cache   sC   € ð Œk�oŠo˜iÑ(Ô(ˆØˆ;ØˆOŒO˜qÑ ˆOŒOˆOàˆNŒN˜aÑˆNŒNØˆ
r   c                 ó4   — | j                              ¦   «         S )z+Returns the contents of the cache.
        )r   Úitemsr   s    r   r   zRetargetCache.items(   s   € ð Œ{× Ò Ñ"Ô"Ð"r   c                 ó    — | j         | j        dœS )z0Returns stats regarding cache hit/miss.
        )ÚhitÚmiss)r	   r
   r   s    r   ÚstatszRetargetCache.stats-   s   € ð ”~¨t¬Ð?Ð?Ð?r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚweakrefÚWeakKeyDictionaryr   r   r   r   r   r   © r   r   r   r      sx   € € € € € ðð ð Ô.€Nðð ð ð
*ð *ð *ð
ð ð ð#ð #ð #ð
@ð @ð @ð @ð @r   r   c                   óR   — e Zd ZdZej        d„ ¦   «         Zej        d„ ¦   «         ZdS )ÚBaseRetargetz/Abstract base class for retargeting logic.
    c                 ó   — dS )z³Check that the retarget is compatible.

        This method does not return anything meaningful (e.g. None)
        Incompatibility is signalled via raising an exception.
        Nr%   ©r   r   s     r   Úcheck_compatiblezBaseRetarget.check_compatible6   s	   € ð 	ˆr   c                 ó   — dS )z²Retargets the given dispatcher and returns a new dispatcher-like
        callable. Or, returns the original dispatcher if the the target_backend
        will not change.
        Nr%   r)   s     r   ÚretargetzBaseRetarget.retarget?   ó	   € ð 	ˆr   N)r   r    r!   r"   ÚabcÚabstractmethodr*   r,   r%   r   r   r'   r'   3   sZ   € € € € € ðð àÔðð ñ Ôðð 	Ôðð ñ Ôðð ð r   r'   c                   ón   — e Zd ZdZeZd„ Zej        de	fd„¦   «         Z
ej        d„ ¦   «         Zd„ Zd„ ZdS )	ÚBasicRetargeta¯  A basic retargeting implementation for a single output target.

    This class has two abstract methods/properties that subclasses must define.

    - `output_target` must return output target name.
    - `compile_retarget` must define the logic to retarget the given dispatcher.

    By default, this class uses `RetargetCache` as the internal cache. This
    can be modified by overriding the `.cache_type` class attribute.

    c                 ó8   — |                       ¦   «         | _        d S )N)Ú
cache_typeÚcacher   s    r   r   zBasicRetarget.__init__V   s   € Ø—_’_Ñ&Ô&ˆŒ
ˆ
ˆ
r   Úreturnc                 ó   — dS )zhReturns the output target name.

        See numba/tests/test_retargeting.py for example usage.
        Nr%   r   s    r   Úoutput_targetzBasicRetarget.output_targetY   r-   r   c                 ó   — dS )zkReturns the retargeted dispatcher.

        See numba/tests/test_retargeting.py for example usage.
        Nr%   r)   s     r   Úcompile_retargetzBasicRetarget.compile_retargeta   r-   r   c                 óp   — |j         }| j        }|�#||k    rd|› d|› d�}t          j        |¦  «        ‚dS dS )zt
        This implementation checks that
        `self.output_target == orig_disp._required_target_backend`
        Nz2The output target does match the required target: z != ú.)Ú_required_target_backendr7   r   ÚCompilerError)r   r   Úrequired_targetr7   Úms        r   r*   zBasicRetarget.check_compatiblei   sj   € ð
 $Ô<ˆØÔ*ˆØÐ&Ø Ò/Ð/ð>Ø%ð>ð >Ø+:ð>ð >ð >�åÔ*¨1Ñ-Ô-Ð-ð	 'Ð&Ø/Ð/r   c                 óì   — | j         }|j        }|                     d¦  «        | j        k    r|S |                     |¦  «        }|€,|                      |¦  «        }|                     ||¦  «         n|}|S )zgApply retargeting to orig_disp.

        The retargeted dispatchers are cached for future use.
        Útarget_backend)r4   Útargetoptionsr   r7   r   r9   r   )r   r   r4   ÚoptsÚcachedr   s         r   r,   zBasicRetarget.retargetv   s‚   € ð
 ”
ˆØÔ&ˆà�8Š8Ð$Ñ%Ô%¨Ô);Ò;Ð;ØÐØ×!Ò! )Ñ,Ô,ˆàˆ>Ø×'Ò'¨	Ñ2Ô2ˆCØ×Ò˜Y¨Ñ,Ô,Ð,Ð,àˆCØˆ
r   N)r   r    r!   r"   r   r3   r   r.   ÚabstractpropertyÚstrr7   r/   r9   r*   r,   r%   r   r   r1   r1   H   sœ   € € € € € ð
ð 
ð €Jð'ð 'ð 'ð 	Ôð˜sð ð ð ñ Ôðð 	Ôðð ñ Ôðð.ð .ð .ðð ð ð ð r   r1   )	r"   r.   r#   Ú
numba.corer   r   ÚABCr'   r1   r%   r   r   ú<module>rI      sÆ   ððð ð €
€
€
Ø €€€à Ð Ð Ð Ð Ð ð#@ð #@ð #@ð #@ð #@ñ #@ô #@ð #@ðLð ð ð ð �3”7ñ ô ð ð*?ð ?ð ?ð ?ð ?�Lñ ?ô ?ð ?ð ?ð ?r   