
    i                       d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZmZ e
r
d dlZd dlmZ ej"                  j%                  d      dk(  r ed      d#d	       Znd#d
Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z y)$    )annotationsN)	lru_cache)AnyOptionalTYPE_CHECKING)BackendCompilerFailedShortenTraceback)_CudaDevicePropertiesTORCHINDUCTOR_WRITE_MISSING_OPS1c                    t        t        j                          dd      5 }|j                  t	        |       dz          d d d        y # 1 sw Y   y xY w)Nz/missing_ops.txta
)opentempfile
gettempdirwritestr)targetfds     M/var/www/html/engine/venv/lib/python3.12/site-packages/torch/_inductor/exc.py_record_missing_opr      sJ    X((*++;<cB 	)bHHS[4'(	) 	) 	)s   A		Ac                     y N )r   s    r   r   r      s        c                      e Zd Zedd       Zy)OperatorIssuec           	         d|  gt        |      D cg c]  \  }}d| d|  c}}z   }|r|j                  d|        t        j                  dj	                  |      d      S c c}}w )Nztarget: zargs[z]: zkwargs: r   z  )	enumerateappendtextwrapindentjoin)r   argskwargsiargliness         r   operator_strzOperatorIssue.operator_str   su    F8$%.7o)
$*AseA3c#)
 
 LL8F8,-tyy/66)
s   A'N)r   r   r%   	list[Any]r&   dict[str, Any]returnr   )__name__
__module____qualname__staticmethodr*   r   r   r   r   r      s    7 7r   r   c                        e Zd Zd fdZ xZS )MissingOperatorWithoutDecompc                b    t        |       t        | 	  d| j                  |||              y )Nzmissing lowering
)r   super__init__r*   selfr   r%   r&   	__class__s       r   r6   z%MissingOperatorWithoutDecomp.__init__*   s0    6"-d.?.?f.U-VWXr   r   r   r%   r+   r&   r,   r-   Noner.   r/   r0   r6   __classcell__r9   s   @r   r3   r3   )   s    Y Yr   r3   c                        e Zd Zd fdZ xZS )MissingOperatorWithDecompc                    t        |       t        | 	  d| j                  |||       t	        j
                  d| d      z          y )Nzmissing decomposition
z9

                There is a decomposition available for z in
                torch._decomp.get_decompositions().  Please add this operator to the
                `decompositions` list in torch._inductor.decomposition
                )r   r5   r6   r*   r"   dedentr7   s       r   r6   z"MissingOperatorWithDecomp.__init__0   sX    6"%d&7&7f&M%NOoo88>x @
	
r   r:   r<   r>   s   @r   r@   r@   /   s    
 
r   r@   c                  4     e Zd Z	 	 	 	 	 	 	 	 	 	 d fdZ xZS )LoweringExceptionc                |    t         |   t        |      j                   d| d| j	                  |||              y )N: r   )r5   r6   typer.   r*   )r8   excr   r%   r&   r9   s        r   r6   zLoweringException.__init__@   sA     	Cy!!""SED,=,=fdF,S+TU	
r   )
rH   	Exceptionr   r   r%   r+   r&   r,   r-   r;   r<   r>   s   @r   rD   rD   ?   s5    

&)
1:
DR
	
 
r   rD   c                      e Zd Zy)SubgraphLoweringExceptionNr.   r/   r0   r   r   r   rK   rK   H       r   rK   c                        e Zd Zd fdZ xZS )InvalidCxxCompilerc                x    ddl m} t        |   d|j                   d|j
                  j                          y )N   )configz!No working C++ compiler found in z
.cpp.cxx: ) rR   r5   r6   r.   cppcxx)r8   rR   r9   s     r   r6   zInvalidCxxCompiler.__init__M   s1    //@
6::>>JZ[	
r   )r-   r;   r<   r>   s   @r   rO   rO   L   s    
 
r   rO   c                        e Zd Zd fdZ xZS )CppWrapperCodegenErrorc                *    t         |   d|        y )NzC++ wrapper codegen error: r5   r6   )r8   msgr9   s     r   r6   zCppWrapperCodegenError.__init__V   s    6se<=r   )rZ   r   r-   r;   r<   r>   s   @r   rW   rW   U   s    > >r   rW   c                  (     e Zd Zd fdZddZ xZS )CppCompileErrorc                   t        |t              r|j                  d      }|| _        || _        t
        |   t        j                  d      j                         j                  dj                  |      |             y )Nzutf-8z
                    C++ compile error

                    Command:
                    {cmd}

                    Output:
                    {output}
                 )cmdoutput)
isinstancebytesdecoder_   r`   r5   r6   r"   rB   stripformatr$   )r8   r_   r`   r9   s      r   r6   zCppCompileError.__init__[   sf    fe$]]7+FOO
 UWVfV5	
r   c                J    | j                   | j                  | j                  ffS r   )r9   r_   r`   )r8   s    r   
__reduce__zCppCompileError.__reduce__r   s    4;; 788r   )r_   z	list[str]r`   r   r-   r;   )r-   z"tuple[type, tuple[list[str], str]])r.   r/   r0   r6   rg   r=   r>   s   @r   r\   r\   Z   s    
.9r   r\   c                      e Zd Zy)CUDACompileErrorNrL   r   r   r   ri   ri   v   rM   r   ri   c                        e Zd Zd fdZ xZS )TritonMissingc                (    t         |   d|       y )NzCannot find a working triton installation. Either the package is not installed or it is too old. More information on installing Triton can be found at: https://github.com/triton-lang/tritonfirst_useful_framerY   )r8   rn   r9   s     r   r6   zTritonMissing.__init__{   s     k  2	 	 	
r   )rn   Optional[types.FrameType]r-   r;   r<   r>   s   @r   rk   rk   z   s    
 
r   rk   c                  ,     e Zd Z	 	 	 	 	 	 d fdZ xZS )GPUTooOldForTritonc                v    t         |   d|j                   d|j                   d|j                   |       y )NzFound z which is too old to be supported by the triton GPU compiler, which is used as the backend. Triton only supports devices of CUDA Capability >= 7.0, but your device is of CUDA capability .rm   )r5   r6   namemajorminor)r8   device_propsrn   r9   s      r   r6   zGPUTooOldForTriton.__init__   sN    
 	\&&' (55A5G5G4H,J\J\I]_  2	 	 	
r   )rw   r
   rn   ro   r-   r;   r<   r>   s   @r   rq   rq      s)    

+

 6

 
	

 

r   rq   c                  $    e Zd ZdZ	 	 	 	 	 	 ddZy)InductorErrorinductorc                r    || _         t        j                  | t        |      j                   d| |       y )NrF   rm   )inner_exceptionr	   r6   rG   r.   )r8   r|   rn   s      r   r6   zInductorError.__init__   s;    
  /!!O$--.b0AB1	
r   N)r|   rI   rn   ro   r-   r;   )r.   r/   r0   backend_namer6   r   r   r   ry   ry      s(    L

"

 6

 
	

r   ry   )r   r   r-   r;   )!
__future__r   osr   r"   	functoolsr   typingr   r   r   torch._dynamo.excr   r	   types
torch.cudar
   environgetr   RuntimeErrorr   r3   r@   rD   rK   rO   rW   r\   ri   rk   rq   ry   r   r   r   <module>r      s    " 	    / / E 0::>>34;t_) )7L 7Y= Y
 
 
 
	 	
 
>\ >
9l 98	 	
$ 

) 

) 
r   