a
    h                     @   s&   d dl Z d dlmZ G dd dZdS )    Nc                   @   sz   e Zd ZdZdZg dZg dZee ZddddZd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )PythonDispatcherZ__test__foo)ZCPUZAutogradCPUZFPGAZAutogradOtherZXLAZAutogradXLAZLazyZAutogradLazy)CompositeExplicitAutogradZAutogradCompositeImplicitAutogradN)returnc                 C   s.   t | j t d| jd| _| jd d S )NZFRAGMENT zfoo(Tensor x) -> Tensor)CZ_dispatch_check_invariantsnameZ_dispatch_library	namespacerefZdef_self r   F/var/www/auris/lib/python3.9/site-packages/torch/_python_dispatcher.py__init__I   s    zPythonDispatcher.__init__c                 C   s   | j S N)supported_keysr   r   r   r   keysS   s    zPythonDispatcher.keysc                 C   s   t t|t |kr$td| dd|v r<d|v r<td|D ]:}|| jvrdt| d| j d| jjd|d| d	 q@d S )
Nz2Overridden is not allowed but found duplicates in .r   r   z\Registration to both CompositeImplicitAutograd and CompositeExplicitAutograd is not allowed.z3 is not supported, please select a dispatch key in r   Zfn_)dispatchdebug)lensetRuntimeErrorr   r   Zimpl_t_t)r   ZdispatchKeyskeyr   r   r   register^   s"    

zPythonDispatcher.registerc                 C   s   |dd| dS )Nz<15 
r   )r   r   kernelr   r   r   _format_linew   s    zPythonDispatcher._format_linec                 C   s(   d| d}||  dd7 }|d7 }|S )Nr   r   r   z---------------------------
)r   )r   headersr   r   r   _format_header~   s    zPythonDispatcher._format_headerc                 C   s   t | j d| j S N::)r   Z_dispatch_dumpr
   r	   r   r   r   r   rawRegistrations   s    z!PythonDispatcher.rawRegistrationsc                 C   s   t | j d| j S r#   )r   Z_dispatch_dump_tabler
   r	   r   r   r   r   rawDispatchTable   s    z!PythonDispatcher.rawDispatchTablec                    sx   |  d}|  }|d}|D ]R}|dd  t fdd| jD r |dd dd	 }||  |7 }q |S )
NzRegistered Kernelsr   :r   c                 3   s   | ]}  |V  qd S r   )
startswith).0kfirstr   r   	<genexpr>       z1PythonDispatcher.registrations.<locals>.<genexpr>r$   r      )r"   r%   splitanyr   r   )r   outputstateZstate_entriesliner   r   r+   r   registrations   s    

zPythonDispatcher.registrationsc                 C   sr   |  d}|  }|d}td}|D ]B}|dd }|| jv r*|d|}|| ||dd 7 }q*|S )	NzComputed Dispatch Tabler   z)registered at .*FallbackKernel\.cpp.*(\[)r'   r   [z: r/   )r"   r&   r0   recompileruntime_keyssubr   )r   r2   tableZtable_entriesregexr4   r*   entryr   r   r   dispatchTable   s    



zPythonDispatcher.dispatchTable)__name__
__module____qualname__r
   r	   r9   Z
alias_keysr   r   r   r   r   r"   r%   r&   r5   r>   r   r   r   r   r   7   s   
r   )r7   Ztorch._CZ_Cr   r   r   r   r   r   <module>   s   3