� 2��g�����ddlmZddlmZddlmZddlmZejd��Zdee defd �Z d e dej egeffd �Z d e dej egeffd �Z d e dej egeffd �Zeje gd����e d��d6d�������Zeje ddg���e d��ejd6d���������Zeje ddg���e d��ejd6d���������Zeje ddg���e d��ejd6d���������Zeje ddg���e d��ejd6d���������Zeje ddg���e d��ejd6d���������Zeje ddg���e d��ejd6d ���������Zeje ddg���e d!��ejd6d"���������Zeje dg���e d#��ejd6d$���������Zeje ddg���e d%��ejd6d&���������Zeje d'��ejd6d(�������Zeje d)��d7d+�����Zeje dg���e d,��d6d-�������Zeje ddg���e d.��ejd6d/���������Zeje ddg���e d0��ejd6d1���������Zeje ddg���e d2��ejd6d3���������Z ejed4��d6d5�����Z!dS)8�)�core)�semantic���wraps)�List�T�dtypes�returnc����fd�}|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�����fd���}|S)Nc���t|��t|�����z}d�|D��D]9}|jjj�vr$t d��d|jjj������:�|i|��S)Nc�F�g|]}t|tj���|��S�)� isinstancer�tensor)�.0�as �d/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/triton/language/math.py� <listcomp>z@_check_dtype.<locals>.wrapper.<locals>.check.<locals>.<listcomp>s)��J�J�J�a�z�!�T�[�/I�/I�J��J�J�J�zExpected dtype z but got )�list�values�type�scalar�name� ValueError)�args�kwargs�all_args�argr �fns ��r�checkz,_check_dtype.<locals>.wrapper.<locals>.checks�����D�z�z�D������$9�$9�9�H�J�J�8�J�J�J� `� `���8�?�'�v�5�5�$�%^�v�%^�%^����H\�%^�%^�_�_�_�6��2�t�&�v�&�&� &rr)r"r#r s` �r�wrapperz_check_dtype.<locals>.wrappers9���� �r��� '� '� '� '� '� �� '�� rr)r r$s` r� _check_dtyper% s#��� � � � � � �Nrrc�0��dtdtf�fd� }|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'�docstrrs �r� _decoratorz)_add_math_1arg_docstr.<locals>._decorator$s&����� �}�}�$�}�/�/�� �� r�r �rr/s` r�_add_math_1arg_docstrr2"s7������q������� �rc�0��dtdtf�fd� }|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 �rr/z)_add_math_2arg_docstr.<locals>._decorator3s&������}�}�$�}�/�/�� �� rr0r1s` r�_add_math_2arg_docstrr51s7��� �� �q� � � � � � � �rc�0��dtdtf�fd� }|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 �rr/z)_add_math_3arg_docstr.<locals>._decoratorDs&��� ���}�}�$�}�/�/�� �� rr0r1s` r�_add_math_3arg_docstrr8Bs7��� �� �q� � � � � � � �r)�int32�int64�uint32�uint64)r z-most significant N bits of the 2N-bit productNc���tj||��}tj||��}tj|||��\}}tj|�|j|j��|j��S�N)r� _to_tensor�binary_op_type_legalizationr� create_umulhi�handler��x�y�_builders r�umulhirGUsf�� ���8�$�$�A� ���8�$�$�A� � +�A�q�(� ;� ;�D�A�q� �;�x�-�-�a�h���A�A�1�6� J� J�Jr�fp32�fp64� exponentialc��tj||��}tj|�|j��|j��Sr>)rr?r� create_exprBr�rDrFs r�exprN_�9�� ���8�$�$�A� �;�x�*�*�1�8�4�4�a�f� =� =�=rzexponential (base 2)c��tj||��}tj|�|j��|j��Sr>)rr?r� create_exp2rBrrMs r�exp2rRh�9�� ���8�$�$�A� �;�x�+�+�A�H�5�5�q�v� >� >�>rznatural logarithmc��tj||��}tj|�|j��|j��Sr>)rr?r� create_logrBrrMs r�logrVqrOrzlogarithm (base 2)c��tj||��}tj|�|j��|j��Sr>)rr?r� create_log2rBrrMs r�log2rYzrSr�cosinec��tj||��}tj|�|j��|j��Sr>)rr?r� create_cosrBrrMs r�cosr]�rOr�sinec��tj||��}tj|�|j��|j��Sr>)rr?r� create_sinrBrrMs r�sinra�rOrzfast square rootc��tj||��}tj|�|j��|j��Sr>)rr?r� create_sqrtrBrrMs r�sqrtrd�rSrz)precise square root (rounding to nearest)c��tj||��}tj|�|j��|j��Sr>)rr?r�create_precise_sqrtrBrrMs r�sqrt_rnrg�s9�� ���8�$�$�A� �;�x�3�3�A�H�=�=�q�v� F� F�Frzinverse square rootc��tj||��}tj|�|j��|j��Sr>)rr?r� create_rsqrtrBrrMs r�rsqrtrj��9�� ���8�$�$�A� �;�x�,�,�Q�X�6�6��� ?� ?�?rzabsolute valuec�~�tj||��}|j}|���r_tj|jdtj|���}tj|�|j |j ��|j ��S|� ��r2tj|� |j ��|j ��S|� ��r2tj|�|j ��|j ��S|���r|SJd|�����)N�)rFFzUnexpected dtype )rr?�dtype� is_fp8e4b15�full�shape�int8r� create_andrBr� is_floating� create_fabs� is_int_signed� create_iabs�is_int_unsigned)rDrFrn�masks r�absrz�s�� ���8�$�$�A� �G�E� ����� 2��y���$�� �H�E�E�E���{�8�.�.�q�x���E�E�q�v�N�N�N� � � � � �2��{�8�/�/���9�9�1�6�B�B�B� � � � � �2��{�8�/�/���9�9�1�6�B�B�B� � � � � �2���1�1�%�1�1�1�1�urz fast divisionFc��tj|��}tj||��}tj||��}tj||||��Sr>)r�_constexpr_to_valuer?r�fdiv)rDrE� ieee_roundingrFs rr}r}�sL���,�]�;�;�M� ���8�$�$�A� ���8�$�$�A� �=��A�}�h� 7� 7�7rz&precise division (rounding to nearest)c���tj||��}tj||��}tj|||��\}}tj|�|j|j��|j��Sr>)rr?r@r�create_precise_divfrBrrCs r�div_rnr��sf�� ���8�$�$�A� ���8�$�$�A� � +�A�q�(� ;� ;�D�A�q� �;�x�3�3�A�H�a�h�G�G��� P� P�Przerror functionc��tj||��}tj|�|j��|j��Sr>)rr?r� create_erfrBrrMs r�erfr��rOr�floorc��tj||��}tj|�|j��|j��Sr>)rr?r� create_floorrBrrMs rr�r��rkr�ceilc��tj||��}tj|�|j��|j��Sr>)rr?r� create_ceilrBrrMs rr�r��rSrzfused multiply-addc��tj||��}tj||��}tj||��}tj|||��\}}tj|||��\}}tj|||��\}}tj|�|j|j|j��|j��Sr>)rr?r@r� create_fmarBr)rDrE�zrFs r�fmar��s��� ���8�$�$�A� ���8�$�$�A� ���8�$�$�A� � +�A�q�(� ;� ;�D�A�q� � +�A�q�(� ;� ;�D�A�q� � +�A�q�(� ;� ;�D�A�q� �;�x�*�*�1�8�Q�X�q�x�H�H�!�&� Q� Q�Qrr>)FN)"�rr� functoolsr�typingr�TypeVarr �strr%�Callabler2r5r8�builtinrG�_tensor_member_fnrNrRrVrYr]rardrgrjrzr}r�r�r�r�r�rrr�<module>r�sC���������������������������D�L�������c���q�����2 �� �� �q�c�1�f�(=� � � � ����� �q�c�1�f�(=�����"���� �q�c�1�f�(=�����&�� ��;�;�;�<�<�<���F�G�G�K�K�K�H�G�=�<���K��� ��f�f�%�&�&�&���}�%�%���>�>�>���&�%�'�&���>� �� ��f�f�%�&�&�&���-�.�.���?�?�?���/�.�'�&���?� �� ��f�f�%�&�&�&���*�+�+���>�>�>���,�+�'�&���>� �� ��f�f�%�&�&�&���+�,�,���?�?�?���-�,�'�&���?� �� ��f�f�%�&�&�&���x� � ���>�>�>���!� �'�&���>� �� ��f�f�%�&�&�&���v�����>�>�>�����'�&���>� �� ��f�f�%�&�&�&���)�*�*���?�?�?���+�*�'�&���?� �� ��f�X������B�C�C���G�G�G���D�C�����G� �� ��f�f�%�&�&�&���,�-�-���@�@�@���.�-�'�&���@� ����'�(�(��� 2� 2� 2���)�(��� 2� �����'�'�8�8�8�(�'���8��� ��f�X������?�@�@�Q�Q�Q�A�@�����Q��� ��f�f�%�&�&�&���'�(�(���>�>�>���)�(�'�&���>� �� ��f�f�%�&�&�&���w�����@�@�@��� ��'�&���@� �� ��f�f�%�&�&�&���v�����?�?�?�����'�&���?� ����+�,�,�R�R�R�-�,���R�R�Rr
Memory