
    3j                        % S SK Jr  S SKJrJr  S SKJrJrJr  S SK	J
r
  \
" SSS9rS\S	'    " S
 S5      r " S S5      rg)    )annotations)CallableOptional)Executoras_completedFuture)
ContextVarasync_compile_active_modeN)defaultz&ContextVar[Optional[AsyncCompileMode]]active_modec                  2    \ rS rSrSS jrSS	S jjrS rSrg)
FutureKernel	   c                *    Xl         S U l        X l        g N)finalize_compilekernelfuture)selfr   r   s      W/home/wildlama/miniconda3/lib/python3.13/site-packages/triton/runtime/_async_compile.py__init__FutureKernel.__init__   s     0    c                    U R                   b  U R                   $  U R                  R                  5       nU R	                  U5        X l         U$ ! [         a    U(       a   g e f = fr   )r   r   result	Exceptionr   )r   ignore_errorsr   s      r   r   FutureKernel.result   sa    ;;";;	[['')F 	f%  			s   A A#!A#c                6    [        U R                  5       U5      $ r   )getattrr   )r   names     r   __getattr__FutureKernel.__getattr__   s     t{{}d++r   )r   r   r   N)r   r   r   r   )F)r   bool)__name__
__module____qualname____firstlineno__r   r   r"   __static_attributes__ r   r   r   r   	   s    
,r   r   c                  8    \ rS rSrSS.S
S jjrS rS rS rSrg	)AsyncCompileMode%   F)r   c               8    Xl         X l        / U l        0 U l        g r   )executorr   raw_futuresfuture_kernels)r   r/   r   s      r   r   AsyncCompileMode.__init__'   s     * r   c                    U R                   R                  U5      nUb  U$ U R                  R                  U5      nXl        U R
                  R                  U5        [        X45      nXPR                   U'   U$ r   )r1   getr/   submit_keyr0   appendr   )r   key
compile_fnfinalize_fnr   future_kernels         r   r5   AsyncCompileMode.submit-   sn    $$((-M%%j1'$[9#0C r   c                p    [         R                  5       b  [        S5      e[         R                  U 5        U $ )Nz*Another AsyncCompileMode is already active)r   r4   RuntimeErrorset)r   s    r   	__enter__AsyncCompileMode.__enter__9   s,    ??(KLLr   c                    [        U R                  5       H5  nU R                  UR                     R	                  U R
                  5        M7     [        R                  S 5        g r   )r   r0   r1   r6   r   r   r   r?   )r   exc_type	exc_value	tracebackr   s        r   __exit__AsyncCompileMode.__exit__?   sF    "4#3#34F,33D4F4FG 5r   )r/   r1   r   r0   N)r/   r   )	r%   r&   r'   r(   r   r5   r@   rF   r)   r*   r   r   r,   r,   %   s    <A !
r   r,   )
__future__r   typingr   r   concurrent.futuresr   r   r   contextvarsr	   r   __annotations__r   r,   r*   r   r   <module>rM      s<    " % = = "6@A\fj6k3 k, ,8 r   