a
    h/                     @  sj  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
rld dlZd dlmZ ejddkredd	d
dddZnd	d
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1r   None)targetreturnc                 C  sJ   t t  dd"}|t| d  W d    n1 s<0    Y  d S )Nz/missing_ops.txta
)opentempfile
gettempdirwritestr)r   fd r   A/var/www/auris/lib/python3.9/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ddddZdS )	OperatorIssuer   	list[Any]dict[str, Any]r   r   argskwargsr   c                 C  sD   d|  gdd t |D  }|r2|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)__name__
__module____qualname__staticmethodr)   r   r   r   r   r      s   r   c                      s(   e Zd Zddddd fddZ  ZS )MissingOperatorWithoutDecompr   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,   r0   __classcell__r   r   r3   r   r.   )   s   r.   c                      s(   e Zd Zddddd fddZ  ZS )MissingOperatorWithDecompr   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   r   r   r3   r   r7   /   s   r7   c                      s*   e Zd Zdddddd fddZ  ZS )	LoweringException	Exceptionr   r   r   r   )excr   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__r5   r   r   r3   r   r9   ?   s   r9   c                   @  s   e Zd ZdS )SubgraphLoweringExceptionNr*   r+   r,   r   r   r   r   r>   H   s   r>   c                      s"   e Zd Zd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: ) rB   r/   r0   r*   cppcxx)r2   rB   r3   r   r   r0   M   s    zInvalidCxxCompiler.__init__r5   r   r   r3   r   r@   L   s   r@   c                      s$   e Zd Zddd fddZ  ZS )CppWrapperCodegenErrorr   r   )msgr   c                   s   t  d|  d S )NzC++ wrapper codegen error: r/   r0   )r2   rG   r3   r   r   r0   V   s    zCppWrapperCodegenError.__init__r5   r   r   r3   r   rF   U   s   rF   c                      s&   e Zd Zdddd fddZ  ZS )CppCompileErrorz	list[str]r   r   )cmdoutputr   c                   s>   t |tr|d}t td jd	||d d S )Nzutf-8z
                    C++ compile error

                    Command:
                    {cmd}

                    Output:
                    {output}
                 )rJ   rK   )

isinstancebytesdecoder/   r0   r%   r8   stripformatr'   )r2   rJ   rK   r3   r   r   r0   [   s    


zCppCompileError.__init__r5   r   r   r3   r   rI   Z   s   rI   c                   @  s   e Zd ZdS )CUDACompileErrorNr?   r   r   r   r   rR   p   s   rR   c                      s$   e Zd Zddd fddZ  ZS )TritonMissingOptional[types.FrameType]r   )first_useful_framer   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rU   rH   )r2   rU   r3   r   r   r0   u   s    zTritonMissing.__init__r5   r   r   r3   r   rS   t   s   rS   c                      s&   e Zd Zdddd fddZ  ZS )GPUTooOldForTritonr	   rT   r   )device_propsrU   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 .rV   )r/   r0   namemajorminor)r2   rX   rU   r3   r   r   r0      s    
zGPUTooOldForTriton.__init__r5   r   r   r3   r   rW   ~   s   rW   c                   @  s"   e Zd ZdZddddddZdS )	InductorErrorZinductorr:   rT   r   )inner_exceptionrU   r   c                 C  s*   || _ tj| t|j d| |d d S )Nr<   rV   )r^   r   r0   r=   r*   )r2   r^   rU   r   r   r   r0      s    zInductorError.__init__N)r*   r+   r,   backend_namer0   r   r   r   r   r]      s   r]   )!
__future__r   osr   r%   	functoolsr   typingr   r   r   Ztorch._dynamo.excr   r   typesZ
torch.cudar	   environgetr   RuntimeErrorr   r.   r7   r9   r>   r@   rF   rI   rR   rS   rW   r]   r   r   r   r   <module>   s2   		
