a
    àñh
  ã                   @   s@   d dl Z d dlZe jdd„ ƒZe jdd„ ƒZejjZdd„ ZdS )é    Nc              	   c   s@   t j ¡ }t j | ¡ zdV  W t j |¡ nt j |¡ 0 dS )z|
    A context manager that controls whether the JIT's executor will run
    optimizations before executing a function.
    N)ÚtorchÚ_CZ_get_graph_executor_optimizeZ_set_graph_executor_optimize)Zshould_optimizeZstored_flag© r   úP/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torch/jit/_fuser.pyÚoptimized_execution   s
    
r   c              	   c   s¬  t j ¡ }t j ¡ }t j ¡ }t j ¡ }| dkrbt j d¡ t j d¡ t j d¡ t j 	d¡ n”| dkr´t j 
d¡}t j d¡}t j d¡ t j d¡ t j d¡ t j 	d¡ nB| dkrît j d¡ t j d¡ t j d¡ t j 	d¡ ntdƒ‚z\dV  W | dk�r"t j 
|¡ t j |¡ t j |¡ t j |¡ t j |¡ t j 	|¡ nT| dk�rvt j 
|¡ t j |¡ t j |¡ t j |¡ t j |¡ t j 	|¡ 0 dS )zÝ
    A context manager that facilitates switching between
    backend fusers.

    Valid names:
    * ``fuser0`` - enables only legacy fuser
    * ``fuser1`` - enables only NNC
    * ``fuser2`` - enables only nvFuser
    Zfuser0TFZfuser1Zfuser2zunrecognized fuser optionN)r   r   Z_jit_can_fuse_on_cpuZ_jit_can_fuse_on_gpuZ_jit_texpr_fuser_enabledZ_jit_nvfuser_enabledZ_jit_override_can_fuse_on_cpuZ_jit_override_can_fuse_on_gpuZ_jit_set_texpr_fuser_enabledZ_jit_set_nvfuser_enabledZ_jit_set_profiling_executorZ_jit_set_profiling_modeÚ	Exception)ÚnameZold_cpu_fuseZold_gpu_fuseZold_texpr_fuser_stateZold_nvfuser_stateZold_profiling_executorZold_profiling_moder   r   r   Úfuser   sL    




ù
r	   c                 O   s   | |i |¤Ž t ƒ S )N)Úlast_executed_optimized_graph)ÚselfÚargsÚkwargsr   r   r   Ú
_graph_forD   s    r   )	Ú
contextlibr   Úcontextmanagerr   r	   r   Z_last_executed_optimized_graphr
   r   r   r   r   r   Ú<module>   s   

.