
    Vh/                       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     C/home/dcms/DCMS/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   r5   z%MissingOperatorWithoutDecomp.__init__*   s0    6"-d.?.?f.U-VWXr   r   r   r$   r*   r%   r+   r,   Noner-   r.   r/   r5   __classcell__r8   s   @r   r2   r2   )   s    Y Yr   r2   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   r4   r5   r)   r!   dedentr6   s       r   r5   z"MissingOperatorWithDecomp.__init__0   sX    6"%d&7&7f&M%NOoo88>x @
	
r   r9   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   )r4   r5   typer-   r)   )r7   excr   r$   r%   r8   s        r   r5   zLoweringException.__init__@   sA     	Cy!!""SED,=,=fdF,S+TU	
r   )
rG   	Exceptionr   r   r$   r*   r%   r+   r,   r:   r;   r=   s   @r   rC   rC   ?   s5    

&)
1:
DR
	
 
r   rC   c                      e Zd Zy)SubgraphLoweringExceptionNr-   r.   r/   r   r   r   rJ   rJ   H       r   rJ   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: ) rQ   r4   r5   r-   cppcxx)r7   rQ   r8   s     r   r5   zInvalidCxxCompiler.__init__M   s1    //@
6::>>JZ[	
r   )r,   r:   r;   r=   s   @r   rN   rN   L   s    
 
r   rN   c                        e Zd Zd fdZ xZS )CppWrapperCodegenErrorc                *    t         |   d|        y )NzC++ wrapper codegen error: r4   r5   )r7   msgr8   s     r   r5   zCppWrapperCodegenError.__init__V   s    6se<=r   )rY   r   r,   r:   r;   r=   s   @r   rV   rV   U   s    > >r   rV   c                        e Zd Zd f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decoder4   r5   r!   rA   stripformatr#   )r7   r^   r_   r8   s      r   r5   zCppCompileError.__init__[   sX    fe$]]7+FOO
 UWVfV5	
r   )r^   z	list[str]r_   r   r,   r:   r;   r=   s   @r   r[   r[   Z   s    
 
r   r[   c                      e Zd Zy)CUDACompileErrorNrK   r   r   r   rf   rf   p   rL   r   rf   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_framerX   )r7   rk   r8   s     r   r5   zTritonMissing.__init__u   s     k  2	 	 	
r   )rk   Optional[types.FrameType]r,   r:   r;   r=   s   @r   rh   rh   t   s    
 
r   rh   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 .rj   )r4   r5   namemajorminor)r7   device_propsrk   r8   s      r   r5   zGPUTooOldForTriton.__init__   sN    
 	\&&' (55A5G5G4H,J\J\I]_  2	 	 	
r   )rt   r
   rk   rl   r,   r:   r;   r=   s   @r   rn   rn   ~   s)    

+

 6

 
	

 

r   rn   c                  $    e Zd ZdZ	 	 	 	 	 	 ddZy)InductorErrorinductorc                r    || _         t        j                  | t        |      j                   d| |       y )NrE   rj   )inner_exceptionr	   r5   rF   r-   )r7   ry   rk   s      r   r5   zInductorError.__init__   s;    
  /!!O$--.b0AB1	
r   N)ry   rH   rk   rl   r,   r:   )r-   r.   r/   backend_namer5   r   r   r   rv   rv      s(    L

"

 6

 
	

r   rv   )r   r   r,   r:   )!
__future__r   osr   r!   	functoolsr   typingr   r   r   torch._dynamo.excr   r	   types
torch.cudar
   environgetr   RuntimeErrorr   r2   r?   rC   rJ   rN   rV   r[   rf   rh   rn   rv   r   r   r   <module>r      s    " 	    / / E 0::>>34;t_) )7L 7Y= Y
 
 
 
	 	
 
>\ >

l 
,	 	
$ 

) 

) 
r   