o
    Zh/                     @  s^  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
r6d dlZd dlmZ ejddkrHedd(ddZnd(ddZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZ dS ))    )annotationsN)	lru_cache)AnyOptionalTYPE_CHECKING)BackendCompilerFailedShortenTraceback)_CudaDevicePropertiesZTORCHINDUCTOR_WRITE_MISSING_OPS1targetr   returnNonec                 C  sL   t t  dd}|t| d  W d    d S 1 sw   Y  d S )Nz/missing_ops.txta
)opentempfile
gettempdirwritestr)r   fd r   B/var/www/auris/lib/python3.10/site-packages/torch/_inductor/exc.py_record_missing_op   s   "r   c                 C  s   d S )Nr   )r   r   r   r   r      s   c                   @  s   e Zd Zedd	d
ZdS )OperatorIssuer   r   args	list[Any]kwargsdict[str, Any]r   r   c                 C  sD   d|  gdd t |D  }|r|d|  td|dS )Nztarget: c                 S  s    g | ]\}}d | d| qS )zargs[z]: r   ).0iargr   r   r   
<listcomp>!   s    z.OperatorIssue.operator_str.<locals>.<listcomp>zkwargs: r   z  )	enumerateappendtextwrapindentjoin)r   r   r   linesr   r   r   operator_str   s   zOperatorIssue.operator_strN)r   r   r   r   r   r   r   r   )__name__
__module____qualname__staticmethodr(   r   r   r   r   r      s    r   c                         e Zd Zd fd	d
Z  ZS )MissingOperatorWithoutDecompr   r   r   r   r   r   r   r   c                   s(   t | t d| |||  d S )Nzmissing lowering
)r   super__init__r(   selfr   r   r   	__class__r   r   r0   *   s    z%MissingOperatorWithoutDecomp.__init__r   r   r   r   r   r   r   r   r)   r*   r+   r0   __classcell__r   r   r3   r   r.   )       r.   c                      r-   )MissingOperatorWithDecompr   r   r   r   r   r   r   r   c                   s:   t | t d| ||| td| d  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   r/   r0   r(   r$   dedentr1   r3   r   r   r0   0   s   z"MissingOperatorWithDecomp.__init__r5   r6   r   r   r3   r   r9   /   r8   r9   c                      s   e Zd Zd fddZ  ZS )LoweringExceptionexc	Exceptionr   r   r   r   r   r   r   r   c                   s0   t  t|j d| d| |||  d S )N: r   )r/   r0   typer)   r(   )r2   r<   r   r   r   r3   r   r   r0   @   s   "zLoweringException.__init__)
r<   r=   r   r   r   r   r   r   r   r   r6   r   r   r3   r   r;   ?   r8   r;   c                   @     e Zd ZdS )SubgraphLoweringExceptionNr)   r*   r+   r   r   r   r   rA   H       rA   c                      s   e Zd Zd fddZ  ZS )InvalidCxxCompilerr   r   c                   s.   ddl m} t d|j d|jj  d S )N   )configz!No working C++ compiler found in z
.cpp.cxx: ) rF   r/   r0   r)   cppZcxx)r2   rF   r3   r   r   r0   M   s   zInvalidCxxCompiler.__init__)r   r   r6   r   r   r3   r   rD   L   r8   rD   c                         e Zd Zd fddZ  ZS )CppWrapperCodegenErrormsgr   r   r   c                   s   t  d|  d S )NzC++ wrapper codegen error: r/   r0   )r2   rK   r3   r   r   r0   V   s   zCppWrapperCodegenError.__init__)rK   r   r   r   r6   r   r   r3   r   rJ   U   r8   rJ   c                         e Zd Zd	 fddZ  ZS )
CppCompileErrorcmd	list[str]outputr   r   r   c                   s>   t |tr
|d}t td jd	||d d S )Nzutf-8z
                    C++ compile error

                    Command:
                    {cmd}

                    Output:
                    {output}
                 )rO   rQ   )

isinstancebytesdecoder/   r0   r$   r:   stripformatr&   )r2   rO   rQ   r3   r   r   r0   [   s   

zCppCompileError.__init__)rO   rP   rQ   r   r   r   r6   r   r   r3   r   rN   Z   r8   rN   c                   @  r@   )CUDACompileErrorNrB   r   r   r   r   rX   p   rC   rX   c                      rI   )TritonMissingfirst_useful_frameOptional[types.FrameType]r   r   c                   s   t  jd|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rZ   rL   )r2   rZ   r3   r   r   r0   u   s   
zTritonMissing.__init__)rZ   r[   r   r   r6   r   r   r3   r   rY   t   r8   rY   c                      rM   )
GPUTooOldForTritondevice_propsr	   rZ   r[   r   r   c                   s,   t  jd|j d|j d|j |d 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 .r\   )r/   r0   namemajorminor)r2   r^   rZ   r3   r   r   r0      s   

zGPUTooOldForTriton.__init__)r^   r	   rZ   r[   r   r   r6   r   r   r3   r   r]   ~   r8   r]   c                   @  s   e Zd ZdZddd	Zd
S )InductorErrorZinductorinner_exceptionr=   rZ   r[   r   r   c                 C  s*   || _ tj| t|j d| |d d S )Nr>   r\   )rd   r   r0   r?   r)   )r2   rd   rZ   r   r   r   r0      s   
zInductorError.__init__N)rd   r=   rZ   r[   r   r   )r)   r*   r+   backend_namer0   r   r   r   r   rc      s    rc   )r   r   r   r   )!
__future__r   osr   r$   	functoolsr   typingr   r   r   Ztorch._dynamo.excr   r   typesZ
torch.cudar	   environgetr   RuntimeErrorr   r.   r9   r;   rA   rD   rJ   rN   rX   rY   r]   rc   r   r   r   r   <module>   s4    
		
