o
    ei                     @  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   ]/var/www/addictedbytheproject.nl/epg/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   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d fddZ  ZS )LoweringExceptionNexc	Exceptionr   r   r   r   r   r   stack_traceOptional[str]r   r   c              	     sJ   t |j d| d| ||| }|r|| d| 7 }t | d S )N: r   z
Found from : 
 )typer+   r*   r1   r2   )r4   r>   r   r   r   r@   msgr5   r   r   r2   @   s   $zLoweringException.__init__r   )r>   r?   r   r   r   r   r   r   r@   rA   r   r   r8   r   r   r5   r   r=   ?   s    r=   c                   @     e Zd ZdS )SubgraphLoweringExceptionNr+   r,   r-   r   r   r   r   rF   N       rF   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: ) rK   r1   r2   r+   cppcxx)r4   rK   r5   r   r   r2   S   s   zInvalidCxxCompiler.__init__)r   r   r8   r   r   r5   r   rI   R   r:   rI   c                         e Zd Zd fddZ  ZS )CppWrapperCodegenErrorrD   r   r   r   c                   s   t  d|  d S )NzC++ wrapper codegen error: r1   r2   )r4   rD   r5   r   r   r2   \   s   zCppWrapperCodegenError.__init__)rD   r   r   r   r8   r   r   r5   r   rP   [   r:   rP   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}
                 )rS   rU   )
isinstancebytesdecoderS   rU   r1   r2   r&   r<   stripformatr(   )r4   rS   rU   r5   r   r   r2   a   s   

zCppCompileError.__init__"tuple[type, tuple[list[str], str]]c                 C  s   | j | j| jffS r   )r6   rS   rU   )r4   r   r   r   
__reduce__x   s   zCppCompileError.__reduce__)rS   rT   rU   r   r   r   )r   r\   )r+   r,   r-   r2   r]   r9   r   r   r5   r   rR   `   s    rR   c                   @  rE   )CUDACompileErrorNrG   r   r   r   r   r^   |   rH   r^   c                      rO   )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`   rQ   )r4   r`   r5   r   r   r2      s   
zTritonMissing.__init__)r`   ra   r   r   r8   r   r   r5   r   r_      r:   r_   c                      s   e Zd Zd	 fddZ  ZS )
GPUTooOldForTritondevice_propsr	   r`   ra   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 .rb   )r1   r2   namemajorminor)r4   rd   r`   r5   r   r   r2      s   

zGPUTooOldForTriton.__init__)rd   r	   r`   ra   r   r   r8   r   r   r5   r   rc      r:   rc   c                   @  s   e Zd ZdZddd	Zd
S )InductorErrorinductorinner_exceptionr?   r`   ra   r   r   c                 C  s*   || _ tj| t|j d| |d d S )NrB   rb   )rk   r   r2   rC   r+   )r4   rk   r`   r   r   r   r2      s   
zInductorError.__init__N)rk   r?   r`   ra   r   r   )r+   r,   r-   backend_namer2   r   r   r   r   ri      s    ri   )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=   rF   rI   rP   rR   r^   r_   rc   ri   r   r   r   r   <module>   s4    
	
