o
    Ih                     @   sF  U d dl Z d dlZd dlZd dlmZ d dlmZ d dlZd dlm	Z	m
Z
mZ zd dlmZ W n ey:   dZY nw daee ed< edurLdd Znd	d Zd
d ZejejejhZdd Zdd Z					dddZe					dddZG dd deZeeje eeje< eed< eed< eed< eed< eed< dS )     N)contextmanager)Optional)__allow_nonbracketed_mutationContextProp
PropModule)_cudnn__cudnn_versionc            	         s   t d u rrt a t } t }| \}}}|\}}}||kr!d}n|dk s(tjs-||k}n||k}|srtjdddkr>dS d| d|  d	}d
tjv rntjd
d t	 fdddD rgt
| d| t
| dt
|dS )NF   &PYTORCH_SKIP_CUDNN_COMPATIBILITY_CHECK01Tz=cuDNN version incompatibility: PyTorch was compiled  against z but found runtime version z. PyTorch already comes bundled with cuDNN. One option to resolving this error is to ensure PyTorch can find the bundled cuDNN. LD_LIBRARY_PATH c                 3   s    | ]}| v V  qd S N ).0	substringld_library_pathr   Q/var/www/vscode/kcb/lib/python3.10/site-packages/torch/backends/cudnn/__init__.py	<genexpr>:   s    
z_init.<locals>.<genexpr>)cudacudnnzLooks like your LD_LIBRARY_PATH contains incompatible version of cudnn. Please either remove it from the path or install cudnn zHone possibility is that there is a conflicting cuDNN in LD_LIBRARY_PATH.)r   r   getVersionIntgetRuntimeVersiongetCompileVersionis_cudaosenvirongetanyRuntimeError)	runtime_versioncompile_versionruntime_majorruntime_minor_compile_majorcompile_minorcudnn_compatiblebase_error_msgr   r   r   _init   sF   



	r+   c                   C   s   dS )NFr   r   r   r   r   r+   O   s   c                   C   s   t  sdS tS )zReturn the version of cuDNN.N)r+   r   r   r   r   r   versionS   s   r,   c                   C   s   t jjS )z9Return a bool indicating if CUDNN is currently available.)torch_C
_has_cudnnr   r   r   r   is_availablea   s   r0   c                 C   sl   t j sdS | jjdks| jtvrdS t st	d dS t
 s4t	djdddtjdd	 dS d
S )NFr   zPyTorch was compiled without cuDNN/MIOpen support. To use cuDNN/MIOpen, rebuild PyTorch making sure the library is visible to the build system.z4cuDNN/MIOpen library not found. Check your {libpath}DYLD_LIBRARY_PATHPATH)darwinwin32r   )libpathT)r-   r.   _get_cudnn_enableddevicetypedtypeCUDNN_TENSOR_DTYPESr0   warningswarnr+   formatr   sysplatform)tensorr   r   r   is_acceptablef   s&   

rA   c                 C   s   t j t j t sd nt j t j t j f}| d ur%t j|  |d ur/t j	| |d ur<t r<t j
| |d urFt j| |d urPt j| |S r   )r-   r.   r6   _get_cudnn_benchmarkr0   _cuda_get_cudnn_benchmark_limit_get_cudnn_deterministic_get_cudnn_allow_tf32_set_cudnn_enabled_set_cudnn_benchmark_cuda_set_cudnn_benchmark_limit_set_cudnn_deterministic_set_cudnn_allow_tf32)_enabled
_benchmark_benchmark_limit_deterministic_allow_tf32
orig_flagsr   r   r   	set_flags}   s"   rQ   F
   Tc                 c   s    t   t| ||||}W d    n1 sw   Y  zd V  W t   t|  W d    d S 1 s4w   Y  d S t   t|  W d    w 1 sMw   Y  w r   )r   rQ   )enabled	benchmarkbenchmark_limitdeterministic
allow_tf32rP   r   r   r   flags   s   

*
rX   c                       s   e Zd Z fddZeejjejjZ	eejj
ejjZeejjejjZdZe r3eejjejjZeejjejjZ  ZS )CudnnModulec                    s   t  || d S r   )super__init__)selfmname	__class__r   r   r[      s   zCudnnModule.__init__N)__name__
__module____qualname__r[   r   r-   r.   r6   rF   rS   rD   rI   rV   rB   rG   rT   rU   r0   rC   rH   rE   rJ   rW   __classcell__r   r   r_   r   rY      s$    rY   rS   rV   rT   rW   rU   )NNNNN)FFrR   FT) r   r>   r;   
contextlibr   typingr   r-   torch.backendsr   r   r   torch._Cr   ImportErrorr   int__annotations__r+   r,   halffloatdoubler:   r0   rA   rQ   rX   rY   modulesra   boolr   r   r   r   <module>   sV   
	
4
