
    Xh                        d dl mZ ddlmZ ddlmZ  ej        d          Zdee         defdZ	d	edej
        egef         fd
Zd	edej
        egef         fdZd	edej
        egef         fdZej         e	g d           ed          d5d                                    Zej         e	ddg           ed          ej        d5d                                                Zej         e	ddg           ed          ej        d5d                                                Zej         e	ddg           ed          ej        d5d                                                Zej         e	ddg           ed          ej        d5d                                                Zej         e	ddg           ed          ej        d5d                                                Zej         e	ddg           ed          ej        d5d                                                Zej         e	ddg           ed           ej        d5d!                                                Zej         e	dg           ed"          ej        d5d#                                                Zej         e	ddg           ed$          ej        d5d%                                                Zej        ej         ed&          d5d'                                    Zej         ed(          d6d*                        Zej         e	dg           ed+          d5d,                                    Zej         e	ddg           ed-          ej        d5d.                                                Zej         e	ddg           ed/          ej        d5d0                                                Zej         e	ddg           ed1          ej        d5d2                                                Zej         ed3          d5d4                        Z dS )7   )core    wraps)ListTdtypesreturnc                       fd}|S )al  
    We're following libdevice's convention to check accepted data types for math functions.
    It is not a good practice to support all data types as accelerators/GPUs don't support
    many float16 and bfloat16 math operations.
    We should let the users know that they are using and invoke explicit cast to convert
    the data type to the supported one.
    c                 @     t                      fd            }|S )Nc                     t          |           t          |                                          z   }d |D             D ]9}|j        j        j        vr$t          d d|j        j        j                   : | i |S )Nc                 F    g | ]}t          |t          j                  |S  )
isinstancer   tensor).0as     f/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/triton/language/math.py
<listcomp>z@_check_dtype.<locals>.wrapper.<locals>.check.<locals>.<listcomp>   s)    JJJaz!T[/I/IJJJJ    zExpected dtype z	 but got )listvaluestypescalarname
ValueError)argskwargsall_argsargr	   fns       r   checkz,_check_dtype.<locals>.wrapper.<locals>.check   s     DzzD$9$99HJJ8JJJ ` `8?'v55$%^v%^%^H\%^%^___ 62t&v&&&r   r   )r!   r"   r	   s   ` r   wrapperz_check_dtype.<locals>.wrapper   s9    	r	' 	' 	' 	' 	' 
	' r   r   )r	   r#   s   ` r   _check_dtyper$      s#         Nr   r   c                 0     dt           dt           f fd}|S )Nfuncr
   c                 B    d}|                               | _        | S )Nzk
    Computes the element-wise {name} of :code:`x`.

    :param x: the input values
    :type x: Block
    r   format__doc__r&   docstrr   s     r   
_decoratorz)_add_math_1arg_docstr.<locals>._decorator#   s&     }}$}//r   r   r   r.   s   ` r   _add_math_1arg_docstrr1   !   s7     q       r   c                 0     dt           dt           f fd}|S )Nr&   r
   c                 B    d}|                               | _        | S )Nz
    Computes the element-wise {name} of :code:`x` and :code:`y`.

    :param x: the input values
    :type x: Block
    :param y: the input values
    :type y: Block
    r(   r)   r,   s     r   r.   z)_add_math_2arg_docstr.<locals>._decorator2   s&     }}$}//r   r/   r0   s   ` r   _add_math_2arg_docstrr4   0   s7    
 
q 
 
 
 
 
 
 r   c                 0     dt           dt           f fd}|S )Nr&   r
   c                 B    d}|                               | _        | S )Nz
    Computes the element-wise {name} of :code:`x`, :code:`y`, and :code:`z`.

    :param x: the input values
    :type x: Block
    :param y: the input values
    :type y: Block
    :param z: the input values
    :type z: Block
    r(   r)   r,   s     r   r.   z)_add_math_3arg_docstr.<locals>._decoratorC   s&    	 }}$}//r   r/   r0   s   ` r   _add_math_3arg_docstrr7   A   s7     q       r   )int32int64uint32uint64)r	   z-most significant N bits of the 2N-bit productNc                    |                     |           } |                     |          }t          j        | ||          \  } }t          j        |j                            | j        |j                  | j                  S N)	to_tensorr   binary_op_type_legalizationr   buildercreate_umulhihandler   xy	_semantics      r   umulhirG   T   sm     	AAAA+Aq)<<DAq;y(66qxJJAFSSSr   fp32fp64exponentialc                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   
create_exprB   r   rD   rF   s     r   exprN   ^   >    
 	AA;y(33AH==qvFFFr   zexponential (base 2)c                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   create_exp2rB   r   rM   s     r   exp2rR   g   >    
 	AA;y(44QX>>GGGr   znatural logarithmc                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   
create_logrB   r   rM   s     r   logrV   p   rO   r   zlogarithm (base 2)c                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   create_log2rB   r   rM   s     r   log2rY   y   rS   r   cosinec                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   
create_cosrB   r   rM   s     r   cosr]      rO   r   sinec                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   
create_sinrB   r   rM   s     r   sinra      rO   r   zfast square rootc                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   create_sqrtrB   r   rM   s     r   sqrtrd      rS   r   z?precise square root (rounding to nearest wrt the IEEE standard)c                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   create_precise_sqrtrB   r   rM   s     r   sqrt_rnrg      s>    
 	AA;y(<<QXFFOOOr   zinverse square rootc                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   create_rsqrtrB   r   rM   s     r   rsqrtrj      >    
 	AA;y(55ah??HHHr   zabsolute valuec                    |                     |           } | j        }|                                rdt          j        | j        dt          j        |          }t          j        |j        	                    | j
        |j
                  | j                  S |                                r7t          j        |j                            | j
                  | j                  S |                                r7t          j        |j                            | j
                  | j                  S |                                r| S J d|             )N   )rF   FzUnexpected dtype )r>   dtypeis_fp8e4b15r   fullshapeint8r   r@   
create_andrB   r   is_floatingcreate_fabsis_int_signedcreate_iabsis_int_unsigned)rD   rF   rn   masks       r   absrz      s!    	AAGE 
2y$	YGGG{9,77$+NNPQPVWWW					 2{9,88BBAFKKK					 2{9,88BBAFKKK				 	  211%11111r   zfast divisionFc                     t          j        |          }|                    |           } |                    |          }|                    | ||          S r=   )r   _unwrap_if_constexprr>   fdiv)rD   rE   ieee_roundingrF   s       r   r}   r}      sP     -m<<MAAAA>>!Q...r   z<precise division (rounding to nearest wrt the IEEE standard)c                    |                     |           } |                     |          }t          j        | ||          \  } }t          j        |j                            | j        |j                  | j                  S r=   )r>   r   r?   r   r@   create_precise_divfrB   r   rC   s      r   div_rnr      so     	AAAA+Aq)<<DAq;y(<<QXqxPPRSRXYYYr   zerror functionc                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   
create_erfrB   r   rM   s     r   erfr      rO   r   floorc                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   create_floorrB   r   rM   s     r   r   r      rk   r   ceilc                     |                     |           } t          j        |j                            | j                  | j                  S r=   )r>   r   r   r@   create_ceilrB   r   rM   s     r   r   r      rS   r   zfused multiply-addc                    |                     |           } |                     |          }|                     |          }t          j        | ||          \  } }t          j        || |          \  }} t          j        |||          \  }}t          j        |j                            | j        |j        |j                  | j                  S r=   )r>   r   r?   r   r@   
create_fmarB   r   )rD   rE   zrF   s       r   fmar      s     	AAAAAA+Aq)<<DAq+Aq)<<DAq+Aq)<<DAq;y(33AHahQQSTSYZZZr   r=   )FN)! r   	functoolsr   typingr   TypeVarr   strr$   Callabler1   r4   r7   builtinrG   _tensor_member_fnrN   rR   rV   rY   r]   ra   rd   rg   rj   rz   r}   r   r   r   r   r   r   r   r   <module>r      sU                    DLc q    2 qc1f(=     qc1f(=    " qc1f(=    & ;;;<<<FGGT T T HG =< T ff%&&&}%%G G G  &% '& G
 ff%&&&-..H H H  /. '& H
 ff%&&&*++G G G  ,+ '& G
 ff%&&&+,,H H H  -, '& H
 ff%&&&x  G G G  !  '& G
 ff%&&&vG G G   '& G
 ff%&&&)**H H H  +* '& H
 fXXYYP P P  ZY  P
 ff%&&&,--I I I  .- '& I
 '((2 2 2 )(  2  ''/ / / (' / fXUVVZ Z Z WV  Z ff%&&&'((G G G  )( '& G
 ff%&&&wI I I    '& I
 ff%&&&vH H H   '& H
 +,,[ [ [ -, [ [ [r   