a
    hc                     @  s   d dl mZ d dlm  mZ d dlm  mZ d dlmZ d dl	m
Z
 d dlmZmZmZ d dlmZ ddd	d
dZe
ddddddZe
ddddddZe
ddddddZdS )    )annotationsN)kernel_signature)with_native_function_and_index)BackendIndexNativeFunctionNativeFunctionsGroup)mapMayber   str)bankend_indexreturnc                 C  s&   | j r
dS ddi}|| jjdd S )N ZXPUZTORCH_XPU_API	TORCH_API )externalgetZdispatch_keyname)r
   Z!device_torch_api_key_word_mapping r   L/var/www/auris/lib/python3.9/site-packages/torchgen/dest/native_functions.pytorch_api_key_word_prefix   s    r   r   z
str | None)fbackend_indexr   c                 C  sZ   t | |}|| }|d u r d S d|jv r.d S |jr8dnd}| d|j|jd dS d S )Nzlegacy::Zstaticr   r   )r   ;)r   
get_kernelkernelr   decl)r   r   sigmetadataprefixr   r   r   gen_unstructured    s    


r   r   z	list[str])gr   r   c                 C  sd   t | }t| }|| }|d u r*g S t|}d| d|j d| dddd |D  d	gS )	Nzstruct Zstructured_z : public at::meta::structured_z {
void impl(z, c                 s  s   | ]}|  V  qd S N)r   ).0ar   r   r   	<genexpr>8       z!gen_structured.<locals>.<genexpr>z);
};
)metar   
structuredZimpl_argumentsr   r   r   join)r   r   Z	meta_nameZout_argsr   r   r   r   r   gen_structured-   s     


r(   z%NativeFunctionsGroup | NativeFunctionc                   sz     | }t| trZ|d ur>|jr> jr2tdqXt|  S qvtt fdd| 	 S nt
|  }|d u rpg S |gS d S )Nz>Structured external backend functions are not implemented yet.c                   s
   t |  S r    )r   )r   r   r   r   <lambda>P   r$   z5compute_native_function_declaration.<locals>.<lambda>)r   
isinstancer   r&   r   AssertionErrorr(   listr   Z	functionsr   )r   r   r   xr   r)   r   #compute_native_function_declaration@   s    


r/   )
__future__r   Ztorchgen.api.metaapir%   Ztorchgen.api.structuredr&   Ztorchgen.api.typesr   Ztorchgen.contextr   Ztorchgen.modelr   r   r   Ztorchgen.utilsr   r   r   r(   r/   r   r   r   r   <module>   s   