
    sg                        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 	 d dlmZ daee   ed<   ed Znd Zd	 Zej(                  ej*                  ej,                  hZd
 Zd Z	 	 	 	 	 ddZe	 	 	 	 	 dd       Z G 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<   y# e$ r dZY w xY w)    N)contextmanager)Optional)__allow_nonbracketed_mutationContextProp
PropModule)_cudnn__cudnn_versionc                  0  	 t         t        j                         a t        j                         } t        j                         }| \  }}}|\  }}}||k7  rd}n |dk  st        j
                  s||k(  }n||k\  }|st        j                  j                  dd      dk(  ryd| d|  d	}d
t        j                  v rRt        j                  j                  d
d      	t        	fddD              rt        | d|       t        | d      t        |      y)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   &   K   | ]  }|v  
 y wN ).0	substringld_library_paths     P/var/www/html/venv/lib/python3.12/site-packages/torch/backends/cudnn/__init__.py	<genexpr>z_init.<locals>.<genexpr>:   s      9B	_4s   )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   s
            @r   _initr-      sU   "$224O$668O$668O.=+M=!.=+M=! -#( "&..#0M#A #0M#A #::>>"JCPTWW55D4E F11@0A B34  %

2&(jjnn5F&KO FW  +-.VVeUfh  +-.DE  '~66    c                       y)NFr   r   r.   r   r-   r-   O   s    r.   c                  $    t               syt        S )zReturn the version of cuDNN.N)r-   r	   r   r.   r   versionr1   S   s    7r.   c                  6    t         j                  j                  S )z9Return a bool indicating if CUDNN is currently available.)torch_C
_has_cudnnr   r.   r   is_availabler6   a   s    88r.   c                 |   t         j                  j                         sy| j                  j                  dk7  s| j
                  t        vryt               st        j                  d       yt               sGt        j                  dj                  dddj                  t        j                  d      	             yy
)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)r3   r4   _get_cudnn_enableddevicetypedtypeCUDNN_TENSOR_DTYPESr6   warningswarnr-   formatr!   sysplatform)tensors    r   is_acceptablerH   f   s    88&&(}}V#v||;N'N>N	
 7BII#6HLLLL"3 J 	
 r.   c                    t         j                  j                         t         j                  j                         t	               sd nt         j                  j                         t         j                  j                         t         j                  j                         f}| t         j                  j                  |        |t         j                  j                  |       |)t	               rt         j                  j                  |       |t         j                  j                  |       |t         j                  j                  |       |S r   )r3   r4   r=   _get_cudnn_benchmarkr6   _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_flagss         r   	set_flagsrY   }   s     	##%%%' N(P(P(R))+&&(J ##H-%%j1#001AB!)).9&&{3r.   c              #     K   t               5  t        | ||||      }d d d        	 d  t               5  t          d d d        y # 1 sw Y   *xY w# 1 sw Y   y xY w# t               5  t          d d d        w # 1 sw Y   w xY wxY wwr   )r   rY   )enabled	benchmarkbenchmark_limitdeterministic
allow_tf32rX   s         r   flagsr`      s      
'	( 
Y



# +, 	#z"	# 	#
 
	# 	#*, 	#z"	# 	# 	#s_   B
AB
A 
B
	A	B
AB
AB
B)	A;2	B;B BB
c                       e Zd Z f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       r1 eej                  j$                  ej                  j&                        Z eej                  j(                  ej                  j*                        Z xZS )CudnnModulec                 &    t         |   ||       y r   )super__init__)selfmname	__class__s      r   re   zCudnnModule.__init__   s    D!r.   N)__name__
__module____qualname__re   r   r3   r4   r=   rN   r[   rL   rQ   r^   rJ   rO   r\   r]   r6   rK   rP   rM   rR   r_   __classcell__)ri   s   @r   rb   rb      s    " %((55uxx7R7RSG))588+L+LM %%uxx'D'DI O~%HH44HH44
 &&(F(FJr.   rb   r[   r^   r\   r_   r]   )NNNNN)FF
   FT) r   rE   rB   
contextlibr   typingr   r3   torch.backendsr   r   r   torch._Cr   ImportErrorr	   int__annotations__r-   r1   halffloatdoublerA   r6   rH   rY   r`   rb   modulesrj   boolr   r.   r   <module>r{      s   	 
  %   Q Q "&# %	0h 
JJ	KK	LL 
0 6 # #0* 0 $CKK$98DH  
   E  Fs   C CC