U
    ªÊ¹j¼  ã                   @   s&   d dl Z d dlmZ G dd„ dƒZdS )é    Nc                   @   s‚   e Zd ZdZdZddddddd	d
gZdddgZee 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d„ Zd S )!ÚPythonDispatcherZ__test__ÚfooZCPUZAutogradCPUZFPGAZAutogradOtherZXLAZAutogradXLAZLazyZAutogradLazyÚCompositeExplicitAutogradZAutogradÚCompositeImplicitAutogradc                 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   úW/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/_python_dispatcher.pyÚ__init__H   s    zPythonDispatcher.__init__c                 C   s   | j S ©N)Úsupported_keysr   r   r   r   ÚkeysR   s    zPythonDispatcher.keysc                 C   s€   t t|ƒƒt |ƒkr$td|› d�ƒ‚d|kr<d|kr<tdƒ‚|D ]:}|| jkrdt|› d| j› d�ƒ‚| jjd|d| d	� q@d S )
Nz1Overriden 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_linev   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>    s     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kr*| d|¡}||  || d¡d ¡7 }q*|S )	NzComputed Dispatch Tabler   z)registered at .*FallbackKernel\.cpp.*(\[)r&   r   ú[z: r-   )r!   r%   r.   ÚreÚcompileÚruntime_keysÚsubr   )r   r0   ÚtableZtable_entriesÚregexr2   r)   Úentryr   r   r   ÚdispatchTable«   s    



zPythonDispatcher.dispatchTableN)Ú__name__Ú
__module__Ú__qualname__r	   r   r7   Z
alias_keysr   r   r   r   r   r!   r$   r%   r3   r<   r   r   r   r   r   6   s2       üý
r   )r5   Ztorch._CZ_Cr   r   r   r   r   r   Ú<module>   s   3