o
    Ih/                     @  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)_CudaDeviceProperties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   G/var/www/vscode/kcb/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   r1   *   s    z%MissingOperatorWithoutDecomp.__init__r   r   r   r   r   r   r   r   r*   r+   r,   r1   __classcell__r   r   r4   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   r0   r1   r)   r%   dedentr2   r4   r   r   r1   0   s   z"MissingOperatorWithDecomp.__init__r6   r7   r   r   r4   r   r:   /   r9   r:   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   )r0   r1   typer*   r)   )r3   r=   r   r   r   r4   r   r   r1   @   s   "zLoweringException.__init__)
r=   r>   r   r   r   r   r   r   r   r   r7   r   r   r4   r   r<   ?   r9   r<   c                   @     e Zd ZdS )SubgraphLoweringExceptionNr*   r+   r,   r   r   r   r   rB   H       rB   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: ) rG   r0   r1   r*   cppcxx)r3   rG   r4   r   r   r1   M   s   zInvalidCxxCompiler.__init__)r   r   r7   r   r   r4   r   rE   L   r9   rE   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: r0   r1   )r3   rM   r4   r   r   r1   V   s   zCppWrapperCodegenError.__init__)rM   r   r   r   r7   r   r   r4   r   rL   U   r9   rL   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}
                 )rQ   rS   )

isinstancebytesdecoder0   r1   r%   r;   stripformatr'   )r3   rQ   rS   r4   r   r   r1   [   s   

zCppCompileError.__init__)rQ   rR   rS   r   r   r   r7   r   r   r4   r   rP   Z   r9   rP   c                   @  rA   )CUDACompileErrorNrC   r   r   r   r   rZ   p   rD   rZ   c                      rK   )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r\   rN   )r3   r\   r4   r   r   r1   u   s   
zTritonMissing.__init__)r\   r]   r   r   r7   r   r   r4   r   r[   t   r9   r[   c                      rO   )
GPUTooOldForTritondevice_propsr	   r\   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^   )r0   r1   namemajorminor)r3   r`   r\   r4   r   r   r1      s   

zGPUTooOldForTriton.__init__)r`   r	   r\   r]   r   r   r7   r   r   r4   r   r_   ~   r9   r_   c                   @  s   e Zd ZdZddd	Zd
S )InductorErrorinductorinner_exceptionr>   r\   r]   r   r   c                 C  s*   || _ tj| t|j d| |d d S )Nr?   r^   )rg   r   r1   r@   r*   )r3   rg   r\   r   r   r   r1      s   
zInductorError.__init__N)rg   r>   r\   r]   r   r   )r*   r+   r,   backend_namer1   r   r   r   r   re      s    re   )r   r   r   r   )!
__future__r   osr   r%   	functoolsr   typingr   r   r   torch._dynamo.excr   r   types
torch.cudar	   environgetr   RuntimeErrorr   r/   r:   r<   rB   rE   rL   rP   rZ   r[   r_   re   r   r   r   r   <module>   s4    
		
