
    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     d/var/www/vps2.regionflexible.com/Desarrollo/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                  :     e Zd Z	 d	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )LoweringExceptionc           	         t        |      j                   d| d| j                  |||       }|r
|| d| z  }t        |   |       y )N: r   z
Found from : 
 )typer.   r*   r5   r6   )r8   excr   r%   r&   stack_tracemsgr9   s          r   r6   zLoweringException.__init__@   s\     c##$Bse2d.?.?f.U-VWcU,[M::Cr   r   )rH   	Exceptionr   r   r%   r+   r&   r,   rI   zOptional[str]r-   r;   r<   r>   s   @r   rD   rD   ?   sL     &*  	
  # 
 r   rD   c                      e Zd Zy)SubgraphLoweringExceptionNr.   r/   r0   r   r   r   rM   rM   N       r   rM   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: ) rT   r5   r6   r.   cppcxx)r8   rT   r9   s     r   r6   zInvalidCxxCompiler.__init__S   s1    //@
6::>>JZ[	
r   )r-   r;   r<   r>   s   @r   rQ   rQ   R   s    
 
r   rQ   c                        e Zd Zd fdZ xZS )CppWrapperCodegenErrorc                *    t         |   d|        y )NzC++ wrapper codegen error: r5   r6   )r8   rJ   r9   s     r   r6   zCppWrapperCodegenError.__init__\   s    6se<=r   )rJ   r   r-   r;   r<   r>   s   @r   rY   rY   [   s    > >r   rY   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`   ra   r5   r6   r"   rB   stripformatr$   )r8   r`   ra   r9   s      r   r6   zCppCompileError.__init__a   sf    fe$]]7+FOO
 UWVfV5	
r   c                J    | j                   | j                  | j                  ffS r   )r9   r`   ra   )r8   s    r   
__reduce__zCppCompileError.__reduce__x   s    4;; 788r   )r`   z	list[str]ra   r   r-   r;   )r-   z"tuple[type, tuple[list[str], str]])r.   r/   r0   r6   rh   r=   r>   s   @r   r]   r]   `   s    
.9r   r]   c                      e Zd Zy)CUDACompileErrorNrN   r   r   r   rj   rj   |   rO   r   rj   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_framer[   )r8   ro   r9   s     r   r6   zTritonMissing.__init__   s     k  2	 	 	
r   )ro   Optional[types.FrameType]r-   r;   r<   r>   s   @r   rl   rl      s    
 
r   rl   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 .rn   )r5   r6   namemajorminor)r8   device_propsro   r9   s      r   r6   zGPUTooOldForTriton.__init__   sN     	\&&' (55A5G5G4H,J\J\I]_  2	 	 	
r   )rx   r
   ro   rp   r-   r;   r<   r>   s   @r   rr   rr      s+    
 ,
 6	

 

 
r   rr   c                  $    e Zd ZdZ	 	 	 	 	 	 ddZy)InductorErrorinductorc                r    || _         t        j                  | t        |      j                   d| |       y )NrF   rn   )inner_exceptionr	   r6   rG   r.   )r8   r}   ro   s      r   r6   zInductorError.__init__   s;    
  /!!O$--.b0AB1	
r   N)r}   rK   ro   rp   r-   r;   )r.   r/   r0   backend_namer6   r   r   r   rz   rz      s(    L

"

 6

 
	

r   rz   )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   rM   rQ   rY   r]   rj   rl   rr   rz   r   r   r   <module>r      s    " 	    / / E 0::>>34;t_) )7L 7Y= Y
 
  	 	
 
>\ >
9l 98	 	
$ 

) 

) 
r   