
    Bj                    .   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	 d dl
mZmZ e	r
d dlZd dlmZ e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dS )(    )annotationsN)	lru_cache)AnyTYPE_CHECKING)BackendCompilerFailedShortenTraceback)_CudaDevicePropertiesTORCHINDUCTOR_WRITE_MISSING_OPS1targetr   returnNonec                    t          t          j                     dd          5 }|                    t	          |           dz              d d d            d S # 1 swxY w Y   d S )Nz/missing_ops.txta
)opentempfile
gettempdirwritestr)r   fds     V/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/torch/_inductor/exc.py_record_missing_opr      s    X(**<<<cBB 	)bHHS[[4'(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   &AAAc                    d S N )r   s    r   r   r      s        c                  &    e Zd Zedd	            Zd
S )OperatorIssuer   r   args	list[Any]kwargsdict[str, Any]r   r   c                    d|  gd t          |          D             z   }|r|                    d|            t          j        d                    |          d          S )Nztarget: c                $    g | ]\  }}d | d| S )zargs[z]: r   ).0iargs      r   
<listcomp>z.OperatorIssue.operator_str.<locals>.<listcomp>!   s:     )
 )
 )
$*AsA#)
 )
 )
r   zkwargs: r   z  )	enumerateappendtextwrapindentjoin)r   r    r"   liness       r   operator_strzOperatorIssue.operator_str   s|    $F$$% )
 )
.7oo)
 )
 )
 
  	.LL,F,,---tyy//666r   N)r   r   r    r!   r"   r#   r   r   )__name__
__module____qualname__staticmethodr0   r   r   r   r   r      s2        7 7 7 \7 7 7r   r   c                        e Zd Zd
 fd	Z xZS )MissingOperatorWithoutDecompr   r   r    r!   r"   r#   r   r   c                    t          |           t                                          d|                     |||                      d S )Nzmissing lowering
)r   super__init__r0   selfr   r    r"   	__class__s       r   r9   z%MissingOperatorWithoutDecomp.__init__*   sJ    6"""Wd.?.?f.U.UWWXXXXXr   r   r   r    r!   r"   r#   r   r   r1   r2   r3   r9   __classcell__r<   s   @r   r6   r6   )   sG        Y Y Y Y Y Y Y Y Y Yr   r6   c                        e Zd Zd
 fd	Z xZS )MissingOperatorWithDecompr   r   r    r!   r"   r#   r   r   c                    t          |           t                                          d|                     |||           t	          j        d| d          z              d S )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   r8   r9   r0   r,   dedentr:   s       r   r9   z"MissingOperatorWithDecomp.__init__0   s    6"""Od&7&7f&M&MOOo8>   
	
 
	
 
	
 
	
 
	
r   r=   r>   r@   s   @r   rB   rB   /   s=        
 
 
 
 
 
 
 
 
 
r   rB   c                  $     e Zd Z	 dd fdZ xZS )LoweringExceptionNexc	Exceptionr   r   r    r!   r"   r#   stack_trace
str | Noner   r   c           	         t          |          j         d| d|                     |||           }|r
|| d| z  }t                                          |           d S )N: r   z
Found from : 
 )typer1   r0   r8   r9   )r;   rG   r   r    r"   rI   msgr<   s          r   r9   zLoweringException.__init__@   sy     c#WWsWWd.?.?f.U.UWW 	;c::[:::Cr   r   )rG   rH   r   r   r    r!   r"   r#   rI   rJ   r   r   r>   r@   s   @r   rF   rF   ?   sG         #'          r   rF   c                      e Zd ZdS )SubgraphLoweringExceptionNr1   r2   r3   r   r   r   rP   rP   N           Dr   rP   c                        e Zd Zd fdZ xZS )InvalidCxxCompilerr   r   c                    ddl m} t                                          d|j         d|j        j                    d S )N   )configz!No working C++ compiler found in z
.cpp.cxx: ) rW   r8   r9   r1   cppcxx)r;   rW   r<   s     r   r9   zInvalidCxxCompiler.__init__S   sT    [[[6:>[[	
 	
 	
 	
 	
r   )r   r   r>   r@   s   @r   rT   rT   R   s=        
 
 
 
 
 
 
 
 
 
r   rT   c                        e Zd Zd fdZ xZS )CppWrapperCodegenErrorrN   r   r   r   c                P    t                                          d|            d S )NzC++ wrapper codegen error: r8   r9   )r;   rN   r<   s     r   r9   zCppWrapperCodegenError.__init__\   s*    <s<<=====r   )rN   r   r   r   r>   r@   s   @r   r\   r\   [   s=        > > > > > > > > > >r   r\   c                  (     e Zd Zd
 fdZdd	Z xZS )CppCompileErrorcmd	list[str]outputr   r   r   c                R   t          |t                    r|                    d          }|| _        || _        t                                          t          j        d          	                                
                    d                    |          |                     d S )Nzutf-8z
                    C++ compile error

                    Command:
                    {cmd}

                    Output:
                    {output}
                 )ra   rc   )
isinstancebytesdecodera   rc   r8   r9   r,   rD   stripformatr.   )r;   ra   rc   r<   s      r   r9   zCppCompileError.__init__a   s    fe$$ 	,]]7++FO
 
 UWWVfV55	
 	
 	
 	
 	
r   "tuple[type, tuple[list[str], str]]c                ,    | j         | j        | j        ffS r   )r<   ra   rc   )r;   s    r   
__reduce__zCppCompileError.__reduce__x   s    4; 788r   )ra   rb   rc   r   r   r   )r   rk   )r1   r2   r3   r9   rm   r?   r@   s   @r   r`   r`   `   sQ        
 
 
 
 
 
.9 9 9 9 9 9 9 9r   r`   c                      e Zd ZdS )CUDACompileErrorNrQ   r   r   r   ro   ro   |   rR   r   ro   c                        e Zd Zd fdZ xZS )TritonMissingfirst_useful_frametypes.FrameType | Noner   r   c                N    t                                          d|           d S )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rr   r^   )r;   rr   r<   s     r   r9   zTritonMissing.__init__   s9    k  2	 	 	
 	
 	
 	
 	
r   )rr   rs   r   r   r>   r@   s   @r   rq   rq      s=        
 
 
 
 
 
 
 
 
 
r   rq   c                        e Zd Zd fdZ xZS )	GPUTooOldForTritondevice_propsr	   rr   rs   r   r   c                ~    t                                          d|j         d|j         d|j         |           d S )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 .ru   )r8   r9   namemajorminor)r;   rx   rr   r<   s      r   r9   zGPUTooOldForTriton.__init__   sp     	_\& _ _5A5G_ _JVJ\_ _  2	 	 	
 	
 	
 	
 	
r   )rx   r	   rr   rs   r   r   r>   r@   s   @r   rw   rw      s=        
 
 
 
 
 
 
 
 
 
r   rw   c                      e Zd ZdZd
dZd	S )InductorErrorinductorinner_exceptionrH   rr   rs   r   r   c                p    || _         t          j        | t          |          j         d| |           d S )NrL   ru   )r   r   r9   rM   r1   )r;   r   rr   s      r   r9   zInductorError.__init__   sR    
  /!O$$-BBBB1	
 	
 	
 	
 	
 	
r   N)r   rH   rr   rs   r   r   )r1   r2   r3   backend_namer9   r   r   r   r   r      s-        L

 

 

 

 

 

r   r   )r   r   r   r   ) 
__future__r   osr   r,   	functoolsr   typingr   r   torch._dynamo.excr   r   types
torch.cudar	   environgetr   RuntimeErrorr   r6   rB   rF   rP   rT   r\   r`   ro   rq   rw   r   r   r   r   <module>r      s   " " " " " " 				         % % % % % % % % E E E E E E E E  1LLL000000:>>344;;Yt__) ) ) _) )   7 7 7 7 7L 7 7 7Y Y Y Y Y= Y Y Y
 
 
 
 
 
 
 
        	 	 	 	 	 	 	 	
 
 
 
 
 
 
 
> > > > >\ > > >
9 9 9 9 9l 9 9 98	 	 	 	 	 	 	 	
 
 
 
 
$ 
 
 

 
 
 
 
) 
 
 

 
 
 
 
) 
 
 
 
 
r   