o
    n0j                     @  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r;d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Zd^ddZd_ddZdd Zd`ddZi d d!d"d!d#d!d$d!d%d&d'd(d)d*d+d&d,d-d.d-d/d(d0d1d2d1d3d4d5d4d6d7d8d9d9d:d:d;d<d=d=d>d?d@dAdBdCdDZee D ]Zeee< qdEdF ZdGdH Zi dIdJ dKD dLdJ dKD dMdJ dND dOdJ dPD dQd dRZdSedT< e  D ]
\Z!Zee ee!< qdadXdYZ"dZd[ Z#d\S )b    )annotationsreduce)AnyCallableTYPE_CHECKINGUnionListDict   core.i   iterableIterableTypepathObjPathreturnr   c                 C  s   t dd || S )Nc                 S  s   | | S N )aidxr   r   T/home/wildlama/miniconda3/envs/lam_a2e/lib/python3.10/site-packages/triton/_utils.py<lambda>   s    z#get_iterable_path.<locals>.<lambda>r   )r   r   r   r   r   get_iterable_path      r   tuple[int, ...]valc                 C  sb   ddl m} t|dksJ t|dkr| nt| |d d }t||js'J ||d | d S )Nr   r   r   )languager   lenr   
isinstancetupleZ_setitem)r   r   r   r   prevr   r   r   set_iterable_path   s
   "r#   Union[IterableType, Any]predCallable[[ObjPath, Any], bool]list[ObjPath]c                   sF   ddl m fddi d fd	d
  d|  t S )Nr   r   c                   s   t | tt j jfS r   )r    listr!   
tuple_typexr   r   r   r      s    zfind_paths_if.<locals>.<lambda>r   r   currentr   c                   sL   |rt |D ]\}} g | |R | qd S | |r$d | < d S d S r   )	enumerate)r   r,   r   item)_implis_iterabler%   retr   r   r/       s   
zfind_paths_if.<locals>._implr   )r   r   r,   r   )r   r   r(   keys)r   r%   r   )r/   r   r0   r%   r1   r   find_paths_if   s   
r3   c                 C  s   | | d @ dkS )Nr   r   r   r*   r   r   r   is_power_of_two,   r   r4   shape	List[int]c                 C  s|   d}t | D ]&\}}t|tstd| dt| dt|s(td| d||9 }q|tkr<t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typer4   
ValueErrorTRITON_MAX_TENSOR_NUMEL)r5   Znumelidr   r   r   validate_block_shape0   s   

r@   boolu1Zint1Zuint1i1Z
float8e4nvZfp8e4nvZfloat8e5Zfp8e5Zfloat8e4b15Zfp8e4b15Zfloat8_e4m3fnZ
float8e4b8Zfp8e4b8Zfloat8_e4m3fnuzZfloat8_e5m2Zfloat8e5b16Zfp8e5b16Zfloat8_e5m2fnuzZhalfZfp16Zfloat16Zbfloat16bf16floatZfp32Zfp64i8Zi16Zi32Zi64u8u16u32Zu64void)Zfloat32doubleZfloat64Zint8Zint16r9   Zint32Zint64Zuint8Zuint16Zuint32Zuint64rJ   c                 C  s   t | dd }t| S )N.r   )strsplittype_canonicalisation_dict)dtypeZ	dtype_strr   r   r   canonicalize_dtypeg   s   rQ   c                 C  s   |rdnd t |  S )Nz*k*)rQ   )rP   Zis_constr   r   r   canonicalize_ptr_dtypel   s   rS   c                 C     i | ]}d | |qS )ur   .0nr   r   r   
<dictcomp>q       rY   )r             @   c                 C  rT   )r>   r   rV   r   r   r   rY   s   rZ   c                 C  rT   )fpr   rV   r   r   r   rY   u   rZ   )r\   r]   r^   c                 C  s   i | ]}d | dqS )Zfp8r[   r   )rW   suffixr   r   r   rY   w   rZ   )Ze4nvZe4b15Ze4b8Ze5Ze5b16r\   )rD   rJ   zDict[str, int]BITWIDTH_DICTrP   rM   r9   c                 C  s   t |  S r   )ra   )rP   r   r   r   get_primitive_bitwidth   s   rb   c                 C  s   t | tot| tot| dS )N_fields)r    r;   
issubclassr!   hasattr)r   r   r   r   is_namedtuple   s   rf   N)r   r   r   r   r   r   )r   r   r   r   r   r   )r   r$   r%   r&   r   r'   )r5   r6   )rP   rM   r   r9   )$
__future__r   	functoolsr   typingr   r   r   r   r	   r
   r   r   r(   r!   r)   r   r9   r   r=   r   r#   r3   r4   r@   rO   valuesvrQ   rS   ra   __annotations__itemskrb   rf   r   r   r   r   <module>   s      



	
%
	
