a
    gh                     @  s  U d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 ervddlmZ eee eedf ejejf Zeedf ZdZdd	d
dddZddd
dddZddddddZdd ZddddZdddddd d!dd"d"d d#d#d$d$d%d&d&d'd'd(d)d*d*d+d,d-d.d/d0d1Zee D ]Zeee< qd2d3 Zi d4d5 d6D d7d5 d6D d8d5 d9D d:d5 d;D d<d d=Zd>ed?< e D ]\Z Zee ee < qd@dAdBdCdDZ!dES )F    )annotationsreduce)AnyCallableTYPE_CHECKINGUnionListDict   core.i   IterableTypeObjPathr   )iterablepathreturnc                 C  s   t dd || S )Nc                 S  s   | | S N )aidxr   r   ;/var/www/auris/lib/python3.9/site-packages/triton/_utils.py<lambda>       z#get_iterable_path.<locals>.<lambda>r   )r   r   r   r   r   get_iterable_path   s    r   tuple[int, ...])r   r   valc                 C  sB   t |dksJ t |dkr | nt| |d d }|||d < d S )Nr   r   )lenr   )r   r   r   prevr   r   r   set_iterable_path   s    "r    zUnion[IterableType, Any]zCallable[[ObjPath, Any], bool]zlist[ObjPath])r   predr   c                   sL   ddl m fddi ddd fdd	  d
|  t S )Nr   r   c                   s   t | tt j jfS r   )
isinstancelisttuple
tuple_typexr   r   r   r      r   zfind_paths_if.<locals>.<lambda>r   r   )r   currentc                   sF   |r0t |D ]\}} g | |R | qn| |rBd | < d S r   )	enumerate)r   r(   r   item)_implis_iterabler!   retr   r   r+      s
    
zfind_paths_if.<locals>._implr   )languager   r#   keys)r   r!   r   )r+   r   r,   r!   r-   r   find_paths_if   s    
r0   c                 C  s   | | d @ dkS )Nr   r   r   r&   r   r   r   is_power_of_two*   s    r1   z	List[int])shapec                 C  s|   d}t | D ]L\}}t|ts8td| dt| dt|sPtd| d||9 }q|tkrxtd| dt d|S )	Nr   zShape element z1 must have type `constexpr[int]`, got `constexpr[]z must be a power of 2znumel (z') exceeds triton maximum tensor numel ())r)   r"   int	TypeErrortyper1   
ValueErrorTRITON_MAX_TENSOR_NUMEL)r2   Znumelidr   r   r   validate_block_shape.   s    

r<   u1Zfp8e4nvZfp8e5Zfp8e4b15Zfp8e4b8Zfp8e5b16Zfp16bf16Zfp32Zfp64i8Zi16Zi32Zi64u8u16u32Zu64void)boolZint1Zuint1i1Z
float8e4nvZfloat8e5Zfloat8e4b15Zfloat8_e4m3fnZ
float8e4b8Zfloat8_e4m3fnuzZfloat8_e5m2Zfloat8e5b16Zfloat8_e5m2fnuzZhalffloat16Zbfloat16floatfloat32doublefloat64Zint8int16r5   int32int64Zuint8Zuint16Zuint32Zuint64rC   c                 C  s   t | dd }t| S )N.r   )strsplittype_canonicalisation_dict)dtypeZ	dtype_strr   r   r   canonicalize_dtypee   s    rS   c                 C  s   i | ]}d | |qS )ur   .0nr   r   r   
<dictcomp>k   s   rX   )r             @   c                 C  s   i | ]}d | |qS )r:   r   rU   r   r   r   rX   m   s   c                 C  s   i | ]}d | |qS )fpr   rU   r   r   r   rX   o   s   )rZ   r[   r\   c                 C  s   i | ]}d | dqS )Zfp8rY   r   )rV   suffixr   r   r   rX   q   s   )Ze4nvZe4b15Ze4b8Ze5Ze5b16rZ   )r>   rC   zDict[str, int]BITWIDTH_DICTrO   r5   )rR   r   c                 C  s   t |  S r   )r_   )rR   r   r   r   get_primitive_bitwidth{   s    r`   N)"
__future__r   	functoolsr   typingr   r   r   r   r	   r
   r.   r   r#   r$   r%   r   r5   r   r9   r   r    r0   r1   r<   rQ   valuesvrS   r_   __annotations__itemskr`   r   r   r   r   <module>   s     %	