o
    vZhc                     @  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Ze
dddZe
dddZe
dddZdS )    )annotationsN)kernel_signature)with_native_function_and_index)BackendIndexNativeFunctionNativeFunctionsGroup)mapMaybebankend_indexr   returnstrc                 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   M/var/www/auris/lib/python3.10/site-packages/torchgen/dest/native_functions.pytorch_api_key_word_prefix   s   r   fr   backend_index
str | Nonec                 C  sV   t | |}|| }|d u rd S d|jv rd S |jrdnd}| d|j|jd dS )Nzlegacy::Zstaticr   r   )r   ;)r   
get_kernelkernelr   decl)r   r   sigmetadataprefixr   r   r   gen_unstructured    s   


r   gr   	list[str]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   s    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)   %NativeFunctionsGroup | NativeFunctionc                   sp     | }t| tr*|d ur|jr jrtdt|  S tt fdd| 	 S t
|  }|d u r5g S |gS )Nz>Structured external backend functions are not implemented yet.c                   s
   t |  S r"   )r   )r   r   r   r   <lambda>P   s   
 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   



r1   )r	   r   r
   r   )r   r   r   r   r
   r   )r    r   r   r   r
   r!   )r    r*   r   r   r
   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)   r1   r   r   r   r   <module>   s    
