o
    Hۂi                     @  sr   U d dl mZ d dlmZmZ d dlmZmZmZ d dl	m
Z
 e
dddZded	< G d
d dZG dd dZdS )    )annotations)CallableOptional)Executoras_completedFuture)
ContextVarasync_compile_active_modeN)defaultz&ContextVar[Optional[AsyncCompileMode]]active_modec                   @  s"   e Zd ZdddZddd
dZdS )FutureKernelfinalize_compiler   futurer   c                 C  s   || _ d | _|| _d S N)r   kernelr   )selfr   r    r   `/home/ubuntu/maya3_transcribe/venv/lib/python3.10/site-packages/triton/runtime/_async_compile.py__init__   s   
zFutureKernel.__init__Fignore_errorsboolc                 C  sN   | j d ur| j S z| j }W n ty   |rY d S  w | | || _ |S r   )r   r   result	Exceptionr   )r   r   r   r   r   r   r      s   

zFutureKernel.resultN)r   r   r   r   )F)r   r   )__name__
__module____qualname__r   r   r   r   r   r   r   	   s    
r   c                   @  s4   e Zd ZdddddZdd Zd	d
 Zdd ZdS )AsyncCompileModeF)r   executorr   c                C  s   || _ || _g | _i | _d S r   )r   r   raw_futuresfuture_kernels)r   r   r   r   r   r   r   "   s   
zAsyncCompileMode.__init__c                 C  sN   | j |}|d ur|S | j|}||_| j| t||}|| j |< |S r   )r   getr   submit_keyr   appendr   )r   key
compile_fnfinalize_fnr   future_kernelr   r   r   r!   (   s   

zAsyncCompileMode.submitc                 C  s"   t  d ur
tdt |  | S )Nz*Another AsyncCompileMode is already active)r   r    RuntimeErrorset)r   r   r   r   	__enter__4   s   
zAsyncCompileMode.__enter__c                 C  s2   t | jD ]}| j|j | j qtd  d S r   )r   r   r   r"   r   r   r   r)   )r   exc_type	exc_value	tracebackr   r   r   r   __exit__:   s   zAsyncCompileMode.__exit__N)r   r   )r   r   r   r   r!   r*   r.   r   r   r   r   r       s
    r   )
__future__r   typingr   r   concurrent.futuresr   r   r   contextvarsr   r   __annotations__r   r   r   r   r   r   <module>   s    