o
    j9:j                     @  sZ  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	 d dl
mZmZ e	r4d dlZd dlmZ ejddkrFe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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   Z/home/nk/hobo-godmode/plappi-mvp/.venv/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d fddZ  ZS )LoweringExceptionNexc	Exceptionr   r   r   r   r   r   stack_trace
str | Noner   r   c              	     sJ   t |j d| d| ||| }|r|| d| 7 }t | d S )N: r   z
Found from : 
 )typer*   r)   r0   r1   )r3   r=   r   r   r   r?   msgr4   r   r   r1   @   s   $zLoweringException.__init__r   )r=   r>   r   r   r   r   r   r   r?   r@   r   r   r7   r   r   r4   r   r<   ?   s    r<   c                   @     e Zd ZdS )SubgraphLoweringExceptionNr*   r+   r,   r   r   r   r   rE   N       rE   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: ) rJ   r0   r1   r*   cppcxx)r3   rJ   r4   r   r   r1   S   s   zInvalidCxxCompiler.__init__)r   r   r7   r   r   r4   r   rH   R   r9   rH   c                         e Zd Zd fddZ  ZS )CppWrapperCodegenErrorrC   r   r   r   c                   s   t  d|  d S )NzC++ wrapper codegen error: r0   r1   )r3   rC   r4   r   r   r1   \   s   zCppWrapperCodegenError.__init__)rC   r   r   r   r7   r   r   r4   r   rO   [   r9   rO   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}
                 )rR   rT   )
isinstancebytesdecoderR   rT   r0   r1   r%   r;   stripformatr'   )r3   rR   rT   r4   r   r   r1   a   s   

zCppCompileError.__init__"tuple[type, tuple[list[str], str]]c                 C  s   | j | j| jffS r   )r5   rR   rT   )r3   r   r   r   
__reduce__x   s   zCppCompileError.__reduce__)rR   rS   rT   r   r   r   )r   r[   )r*   r+   r,   r1   r\   r8   r   r   r4   r   rQ   `   s    rQ   c                   @  rD   )CUDACompileErrorNrF   r   r   r   r   r]   |   rG   r]   c                      rN   )TritonMissingfirst_useful_frametypes.FrameType | Noner   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_   rP   )r3   r_   r4   r   r   r1      s   
zTritonMissing.__init__)r_   r`   r   r   r7   r   r   r4   r   r^      r9   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 .ra   )r0   r1   namemajorminor)r3   rc   r_   r4   r   r   r1      s   

zGPUTooOldForTriton.__init__)rc   r   r_   r`   r   r   r7   r   r   r4   r   rb      r9   rb   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 )NrA   ra   )rj   r   r1   rB   r*   )r3   rj   r_   r   r   r   r1      s   
zInductorError.__init__N)rj   r>   r_   r`   r   r   )r*   r+   r,   backend_namer1   r   r   r   r   rh      s    rh   )r   r   r   r   ) 
__future__r   osr   r%   	functoolsr   typingr   r   torch._dynamo.excr   r   types
torch.cudar   environgetr   RuntimeErrorr   r/   r:   r<   rE   rH   rO   rQ   r]   r^   rb   rh   r   r   r   r   <module>   s4    
	
