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	 ej
ddkr2e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dS )!    )annotationsN)	lru_cache)AnyList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   Q/home/ubuntu/transcripts/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   r-   #   s    z%MissingOperatorWithoutDecomp.__init__r   r   r   r   r   r   r	   r
   r&   r'   r(   r-   __classcell__r   r   r0   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   r,   r-   r%   r!   dedentr.   r0   r   r   r-   )   s   z"MissingOperatorWithDecomp.__init__r2   r3   r   r   r0   r   r6   (   r5   r6   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 )Nz: r   )r,   r-   typer&   r%   )r/   r9   r   r   r   r0   r   r   r-   9   s   "zLoweringException.__init__)
r9   r:   r   r   r   r   r   r   r	   r
   r3   r   r   r0   r   r8   8   r5   r8   c                   @     e Zd ZdS )SubgraphLoweringExceptionNr&   r'   r(   r   r   r   r   r=   A       r=   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: ) rB   r,   r-   r&   cppcxx)r/   rB   r0   r   r   r-   F   s   zInvalidCxxCompiler.__init__)r	   r
   r3   r   r   r0   r   r@   E   r5   r@   c                      s   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: )r,   r-   )r/   rG   r0   r   r   r-   O   s   zCppWrapperCodegenError.__init__)rG   r   r	   r
   r3   r   r   r0   r   rF   N   r5   rF   c                      s   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}
                 )rI   rK   )

isinstancebytesdecoder,   r-   r!   r7   stripformatr#   )r/   rI   rK   r0   r   r   r-   T   s   

zCppCompileError.__init__)rI   rJ   rK   r   r	   r
   r3   r   r   r0   r   rH   S   r5   rH   c                   @  r<   )CUDACompileErrorNr>   r   r   r   r   rR   i   r?   rR   )r   r   r	   r
   )
__future__r   osr   r!   	functoolsr   typingr   r   environgetr   RuntimeErrorr   r+   r6   r8   r=   r@   rF   rH   rR   r   r   r   r   <module>   s&    
		