o
    i                     @  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   I/home/ubuntu/vllm_env/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   r2   *   s    z%MissingOperatorWithoutDecomp.__init__r   r   r   r   r   r   r   r   r+   r,   r-   r2   __classcell__r   r   r5   r   r0   )       r0   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   r1   r2   r*   r&   dedentr3   r5   r   r   r2   0   s   z"MissingOperatorWithDecomp.__init__r7   r8   r   r   r5   r   r;   /   r:   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   )r1   r2   typer+   r*   )r4   r>   r   r   r   r5   r   r   r2   @   s   "zLoweringException.__init__)
r>   r?   r   r   r   r   r   r   r   r   r8   r   r   r5   r   r=   ?   r:   r=   c                   @     e Zd ZdS )SubgraphLoweringExceptionNr+   r,   r-   r   r   r   r   rC   H       rC   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: ) rH   r1   r2   r+   cppcxx)r4   rH   r5   r   r   r2   M   s   zInvalidCxxCompiler.__init__)r   r   r8   r   r   r5   r   rF   L   r:   rF   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: r1   r2   )r4   rN   r5   r   r   r2   V   s   zCppWrapperCodegenError.__init__)rN   r   r   r   r8   r   r   r5   r   rM   U   r:   rM   c                      s(   e Zd Zd fddZdd
dZ  ZS )CppCompileErrorcmd	list[str]outputr   r   r   c                   sJ   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decoderQ   rS   r1   r2   r&   r<   stripformatr(   )r4   rQ   rS   r5   r   r   r2   [   s   

zCppCompileError.__init__"tuple[type, tuple[list[str], str]]c                 C  s   | j | j| jffS r   )r6   rQ   rS   )r4   r   r   r   
__reduce__r   s   zCppCompileError.__reduce__)rQ   rR   rS   r   r   r   )r   rZ   )r+   r,   r-   r2   r[   r9   r   r   r5   r   rP   Z   s    rP   c                   @  rB   )CUDACompileErrorNrD   r   r   r   r   r\   v   rE   r\   c                      rL   )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^   rO   )r4   r^   r5   r   r   r2   {   s   
zTritonMissing.__init__)r^   r_   r   r   r8   r   r   r5   r   r]   z   r:   r]   c                      s   e Zd Zd	 fddZ  ZS )
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`   )r1   r2   namemajorminor)r4   rb   r^   r5   r   r   r2      s   

zGPUTooOldForTriton.__init__)rb   r	   r^   r_   r   r   r8   r   r   r5   r   ra      r:   ra   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`   )ri   r   r2   rA   r+   )r4   ri   r^   r   r   r   r2      s   
zInductorError.__init__N)ri   r?   r^   r_   r   r   )r+   r,   r-   backend_namer2   r   r   r   r   rg      s    rg   )r   r   r   r   )!
__future__r   osr   r&   	functoolsr   typingr   r   r   torch._dynamo.excr   r   types
torch.cudar	   environgetr   RuntimeErrorr   r0   r;   r=   rC   rF   rM   rP   r\   r]   ra   rg   r   r   r   r   <module>   s4    
		
