a
    zd                     @  sN   d dl mZ ddlmZmZ ddddddd	d
dZddddddddZdS )    )annotations   )coresemanticNstrlistdicttuple)lib_namelib_pathargsarg_type_symbol_dict	ret_shapec              
   C  s  t |dkrtdt t| d }t ||krLtdt | d| g }g }	|D ]B}
t|
tjr||
j |	|
j	 qX|t
|
 |	|
 qXt|}||vrtd|  d| nF|| d }|| d }|rt||}t| ||||	|||S dS )a  
        Dispatch a function to a library
        :param func: the function to dispatch
        :param lib_name: the name of the library
        :param lib_path: the path of the library
        :param args: the arguments of the function
        :param arg_type_symbol_dict: the type of the arguments
        :param ret_shape: the shape of the return value
        :param _builder: the builder
        :return: the return value of the function
    r   zarg_type_symbol_dict is emptyz+length of input args does not match.Expect z, got z,input arg type does not match.Expect one of r   N)len
ValueErrorr   keys
isinstancer   ZtensorappendZdtypehandletyper	   Z
block_typeZto_ir)funcr
   r   r   r   r   _buildernum_argsZ	arg_typesarg_listargsymbolZret_type r   _/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/triton/language/extern.pydispatch   s:    
r   )r
   r   r   r   c                 C  s   |  }d}d}tt|D ]*}t|| |||< || j rd}q|s|d }	t|D ]\}}
t	|
|	|\}}	q\tt|D ]}t	|| |	|\||< }q|	j
}t|d}t|| |||||S )af  
        Dispatch an elementwise function to a library
        :param lib_name: the name of the library
        :param lib_path: the path of the library
        :param args: the arguments of the function
        :param arg_type_symbol_dict: the type of the arguments
        :param _builder: the builder
        :return: the return value of the function
    TNFr   Zcreate_external_elementwise)copyranger   r   Z
_to_tensorr   Zis_block	enumerater   Zbinary_op_type_checking_implshapegetattrr   )r
   r   r   r   r   Zdispatch_argsZ
all_scalarr   iZbroadcast_argitem_r   r   r   r   elementwise0   s(    



r'   )N)N)
__future__r    r   r   r   r'   r   r   r   r   <module>   s   *