
    çg                        d dl mZ 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          d6d                                    Zej         e
ddg           ed          ej        d6d                                                Zej         e
ddg           ed          ej        d6d                                                Zej         e
ddg           ed          ej        d6d                                                Zej         e
ddg           ed          ej        d6d                                                Zej         e
ddg           ed          ej        d6d                                                Zej         e
ddg           ed          ej        d6d                                                 Zej         e
ddg           ed!          ej        d6d"                                                Zej         e
dg           ed#          ej        d6d$                                                Zej         e
ddg           ed%          ej        d6d&                                                Zej         ed'          ej        d6d(                                    Zej         ed)          d7d+                        Zej         e
dg           ed,          d6d-                                    Zej         e
ddg           ed.          ej        d6d/                                                Zej         e
ddg           ed0          ej        d6d1                                                Zej         e
ddg           ed2          ej        d6d3                                                Z ej         ed4          d6d5                        Z!dS )8   )core)semantic    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     P/var/www/html/ai-engine/env/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_docstrr2   "   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>._decorator3   s&     }}$}//r   r0   r1   s   ` r   _add_math_2arg_docstrr5   1   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>._decoratorD   s&    	 }}$}//r   r0   r1   s   ` r   _add_math_3arg_docstrr8   B   s7     q       r   )int32int64uint32uint64)r
   z-most significant N bits of the 2N-bit productNc                     t          j        | |          } t          j        ||          }t          j        | ||          \  } }t          j        |                    | j        |j                  | j                  S N)r   
_to_tensorbinary_op_type_legalizationr   create_umulhihandler   xy_builders      r   umulhirG   U   sf     	8$$A8$$A+Aq(;;DAq;x--ahAA16JJJr   fp32fp64exponentialc                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   
create_exprB   r   rD   rF   s     r   exprN   _   9    
 	8$$A;x**1844af===r   zexponential (base 2)c                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   create_exp2rB   r   rM   s     r   exp2rR   h   9    
 	8$$A;x++AH55qv>>>r   znatural logarithmc                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   
create_logrB   r   rM   s     r   logrV   q   rO   r   zlogarithm (base 2)c                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   create_log2rB   r   rM   s     r   log2rY   z   rS   r   cosinec                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   
create_cosrB   r   rM   s     r   cosr]      rO   r   sinec                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   
create_sinrB   r   rM   s     r   sinra      rO   r   zfast square rootc                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   create_sqrtrB   r   rM   s     r   sqrtrd      rS   r   z)precise square root (rounding to nearest)c                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   create_precise_sqrtrB   r   rM   s     r   sqrt_rnrg      s9    
 	8$$A;x33AH==qvFFFr   zinverse square rootc                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   create_rsqrtrB   r   rM   s     r   rsqrtrj      9    
 	8$$A;x,,QX66???r   zabsolute valuec                 ~   t          j        | |          } | j        }|                                r_t          j        | j        dt           j        |          }t          j        |                    | j	        |j	                  | j
                  S |                                r2t          j        |                    | j	                  | j
                  S |                                r2t          j        |                    | j	                  | j
                  S |                                r| S J d|             )N   )rF   FzUnexpected dtype )r   r?   dtypeis_fp8e4b15fullshapeint8r   
create_andrB   r   is_floatingcreate_fabsis_int_signedcreate_iabsis_int_unsigned)rD   rF   rn   masks       r   absrz      s    	8$$AGE 
2y$	HEEE{8..qxEEqvNNN					 2{8//9916BBB					 2{8//9916BBB				 	  211%11111r   zfast divisionFc                     t          j        |          }t          j        | |          } t          j        ||          }t          j        | |||          S r>   )r   _constexpr_to_valuer?   r   fdiv)rD   rE   ieee_roundingrF   s       r   r}   r}      sL     ,];;M8$$A8$$A=A}h777r   z&precise division (rounding to nearest)c                     t          j        | |          } t          j        ||          }t          j        | ||          \  } }t          j        |                    | j        |j                  | j                  S r>   )r   r?   r@   r   create_precise_divfrB   r   rC   s      r   div_rnr      sf     	8$$A8$$A+Aq(;;DAq;x33AHahGGPPPr   zerror functionc                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   
create_erfrB   r   rM   s     r   erfr      rO   r   floorc                     t          j        | |          } t          j        |                    | j                  | j                  S r>   )r   r?   r   create_floorrB   r   rM   s     r   r   r      rk   r   ceilc                     t          j        | |          } t          j        |                    | j                  | j                  S 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        | ||          \  } }t          j        || |          \  }} t          j        |||          \  }}t          j        |                    | j        |j        |j                  | j                  S r>   )r   r?   r@   r   
create_fmarB   r   )rD   rE   zrF   s       r   fmar      s     	8$$A8$$A8$$A+Aq(;;DAq+Aq(;;DAq+Aq(;;DAq;x**18QXqxHH!&QQQr   r>   )FN)" r   r   	functoolsr   typingr   TypeVarr	   strr%   Callabler2   r5   r8   builtinrG   _tensor_member_fnrN   rR   rV   rY   r]   ra   rd   rg   rj   rz   r}   r   r   r   r   r   r   r   r   <module>r      sC                          DLc q    2 qc1f(=     qc1f(=    " qc1f(=    & ;;;<<<FGGK K K HG =< K ff%&&&}%%> > >  &% '& >
 ff%&&&-..? ? ?  /. '& ?
 ff%&&&*++> > >  ,+ '& >
 ff%&&&+,,? ? ?  -, '& ?
 ff%&&&x  > > >  !  '& >
 ff%&&&v> > >   '& >
 ff%&&&)**? ? ?  +* '& ?
 fXBCCG G G  DC  G
 ff%&&&,--@ @ @  .- '& @
 '((2 2 2  )( 2  ''8 8 8 (' 8 fX?@@Q Q Q A@  Q ff%&&&'((> > >  )( '& >
 ff%&&&w@ @ @    '& @
 ff%&&&v? ? ?   '& ?
 +,,R R R -, R R Rr   