� 2��gL3��h�ddlmZddlmZddlmZddlmZd�ZdCd �ZdCd �Z ej ed �����Z ej eej d ��d�������Z ej eej d��dDd�������Zej ed�����Zed���Zed���Zed���Zed���Zed���Zed���Zed���Zej eejddd���dEd �������Zej eejd!d"�#��dFd$�������Zed%���Zed&���Zed'���Zed(���Zej eejd)dd���dEd*�������Zej eejd+d"�#��dFd,�������Zed-���Z ej eejd.��dGd/�������Z!ed0���Z"ej ej#ejd1��dHd2�������Z$ej eej%d3��dId4�������Z&ed5���Z'ej eej%d6��dId7�������Z(edJd9���Z)edKd<���Z*ej edej+fdLd?�����Z,d@�Z-ej edMdA�����Z.edB���Z/dS)N�)� annotations�)�jit�)�core)�mathc�H�t|tj��r|jn|S�N)� isinstancer� constexpr�value)�os �h/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/triton/language/standard.py�_unwrap_if_constexprr s�� ��D�N�3�3� :�1�7�7��:��i�core.constexprc�h�d}|j}|dkr|dz}|dz }|dk�tj|��S)Nrr�r rr )r�log2�ns r�_log2rsF�� �D� ��A� �a�%�%� �a��� �� �� �a�%�%� �>�$� � �rc�X�|j}tj||dz zdko|dk��S)Nrrr)rrs r�_is_power_of_twors/�� ��A� �>�1��A��;�1�,�7��a�� 8� 8�8rc��||zdz |zS)z� Computes the ceiling division of :code:`x` by :code:`div` :param x: the input number :type x: Block :param div: the divisor :param div: Block r�)�x�divs r�cdivr!s�� ��G�a�K�C� �r�sigmoidc�8�ddtj| ��zz S)Nr)r�exp�rs rr r /s�� ��D�H�a�R�L�L� � !�!r�softmaxFc��|t|d��z }tj|��}t|d��}tj|||��S)Nr)�maxrr"�sum�fdiv)r� ieee_rounding�z�num�dens rr$r$6sC�� �C��1�I�I� �A� �(�1�+�+�C� �c�1�+�+�C� �9�S�#�}� -� -�-rc�<�tj||jgd���S)zn Returns a contiguous flattened view of :code:`x`. :param x: the input tensor :type x: Block T)� can_reorder)r�reshape�numelr#s r�ravelr1@s�� �<��A�G�9�$� 7� 7� 7�7rc��||z|z}||z}||z}||z}tj||z |��}|||zz} ||z|z} | | fS)a� Transforms indices of a row-major :code:`size_i * size_j` matrix into those of one where the indices are col-major for each group of :code:`size_g` rows. For example, for :code:`size_i = size_j = 4` and :code:`size_g = 2`, it will transform :: [[0 , 1 , 2 , 3 ], [4 , 5 , 6 , 7 ], [8 , 9 , 10, 11], [12, 13, 14, 15]] into :: [[0, 2, 4 , 6 ], [1, 3, 5 , 7 ], [8, 10, 12, 14], [9, 11, 13, 15]] �r�minimum) r�j�size_i�size_j�size_g�ij�size_gj�group_id�off_i�new_i�new_js r� swizzle2dr?Lsj��. �V��a��B��v�o�G��W�}�H� �v� �E� �\�&�5�.�&� 1� 1�F� �R�&�[� !�E� �'�\�f� $�E� �%�<�rc�.�tj|d|��S)a' Returns a tensor filled with the scalar value 0 for the given :code:`shape` and :code:`dtype`. :param shape: Shape of the new array, e.g., (8, 16) or (8, ) :type shape: tuple of ints :param dtype: Data-type of the new array, e.g., :code:`tl.float16` :type dtype: DType r)r�full)�shape�dtypes r�zerosrDss�� �9�U�A�u� %� %�%rc�6�t|j|j��S)zS Creates a tensor of zeros with the same shape and type as a given tensor. )rDrBrC)�inputs r� zeros_likerG�s�� ���e�k� *� *�*rc��|r ||ko||k}nd}||kp|}tj|||��}tj|||��}||fS�NF�r�where) �value1�index1�value2�index2�tie_break_left�tie�gt�v_ret�i_rets r�_argmax_combinerU�sb�������2�6�F�?����� �&�� �C�B� �J�r�6�6� *� *�E� �J�r�6�6� *� *�E� �%�<�rc�(�t||||d��S�NT�rU�rLrMrNrOs r�_argmax_combine_tie_break_leftrZ���� �6�6�6�6�4� @� @�@rc�(�t||||d��SrIrXrYs r�_argmax_combine_tie_break_fastr]���� �6�6�6�6�5� A� A�Arc�,�tj||��Sr )r�maximum��a�bs r�_elementwise_maxrd���� �<��1� � �rr`�return_indices�return_indices_tie_break_left)�return_indices_arg� tie_break_argNTc�b�tj|��}|r<|rtj||t|���Stj||t|���Stj|jj��tjd��kr�tj|j�����r |� tj ��}nB|j� ��s Jd���|� tj ��}tj ||t|���S�N�� keep_dims� z"Expecting input to be integer type)r�_promote_bfloat16_to_float32�_reduce_with_indicesrZr]r rC�primitive_bitwidth� is_floating�to�float32�is_int�int32�reducerd�rF�axisrfrgrms rr&r&�s�� � -�e� 4� 4�E�� O� (� o��,�U�D�:X�dm�n�n�n� n��,�U�D�:X�dm�n�n�n� n� �>�%�+�8� 9� 9�D�N�2�<N�<N� N� N��~�e�k�5�5�7�7�8�8� -������.�.����{�)�)�+�+�Q�Q�-Q�Q�Q�+������,�,���{�5�$�(8�I�N�N�N�Nrz maximum indexrP)ric�4�t||d||���\}}|S�NT)rfrgrm)r&�rFryrPrm�_�rets r�argmaxr�s'���5�$�t�Sa�mv�w�w�w�H�Q�� �Jrc��|r ||ko||k}nd}||kp|}tj|||��}tj|||��}||fSrIrJ) rLrMrNrOrPrQ�lt� value_ret� index_rets r�_argmin_combiner��sc�������2�6�F�?����� �&�� �C�B�� �2�v�v�.�.�I�� �2�v�v�.�.�I� �i� �rc�(�t||||d��SrW�r�rYs r�_argmin_combine_tie_break_leftr��r[rc�(�t||||d��SrIr�rYs r�_argmin_combine_tie_break_fastr��r^rc�,�tj||��Sr r3ras r�_elementwise_minr��rerr4c�>�tj|��}|r<|rtj||t|���Stj||t|���Stj|jj��dkr�tj|j�����r |� tj ��}nB|j� ��s Jd���|� tj ��}tj ||t|���Srk)rrorpr�r�r rCrqrrrsrtrurvrwr�rxs r�minr��s��� � -�e� 4� 4�E�� O� (� o��,�U�D�:X�dm�n�n�n� n��,�U�D�:X�dm�n�n�n� n� �>�%�+�8� 9� 9�B� >� >��~�e�k�5�5�7�7�8�8� -������.�.����{�)�)�+�+�Q�Q�-Q�Q�Q�+������,�,���{�5�$�(8�I�N�N�N�Nrz minimum indexc�4�t||d||���\}}|Sr{)r�r|s r�argminr��s'�����T�Q_�kt� u� u� u�F�A�s� �Jrc� �||zSr rras r� _sum_combiner��� �� �q�5�Lrr'c�d�tj|��}tj||t|���S)Nrl)rrorwr�)rFryrms rr'r's-�� � -�e� 4� 4�E� �;�u�d�L�I� F� F� F�Frc� �||z Sr rras r� _xor_combiner�r�rzxor sumc���|jj}|���std���t j||���}t j||t|||���S)Nz#xor_sum only supported for integers)�_builder)rmr�� _generator)�type�scalarru� ValueErrorrrorwr�)rFryrmr�r�� scalar_tys r�xor_sumr�sf��� �!�I� � � � � �@��>�?�?�?� � -�e�h� G� G� G�E� �;�u�d�L�I�PX�eo� p� p� p�pr�cumsumc�b�tj|��}tj||t|��Sr )rro�associative_scanr��rFry�reverses rr�r�%s+�� � -�e� 4� 4�E� � ���l�G� D� D�Drc� �||zSr rras r� _prod_combiner�1r�r�cumprodc�b�tj|��}tj||t|��Sr )rror�r�r�s rr�r�6s+�� � -�e� 4� 4�E� � ���m�W� E� E�Er�n_dimsc�D�|j|z }|d|zzdd||z dz zg}tj||��}tjdd��ddd�df}tjt |d|z zd��dd�ddd�f|��}tjt ||zd��dd�ddd�f|��} tj||j��}tj| |j��} tj|jj d���} |� | d���} | � | d���} |� | d���} | tj || k|z | | z t| ����z }|� |jd���S)NrrrT)�bitwidth�signed)�bitcast) r0rr/�arange� broadcast_tor'rB� get_int_dtyperCrqrsrKrG)r�fliprr��n_outerrB�y�mask�left�right�idtype�ileft�iright�ixr~s r�_compare_and_swapr�Bs����g��/�G�$�q�!�t�^�Q��F�Q�J��N�0C�D�E� � �Q����A� �;�q�!� � �T�1�1�1�d�]� +�D� � �S��a�$�h���3�3�A�A�A�t�Q�Q�Q�J�?�� G� G�D� � �c�!�d�(�A�.�.�q�q�q�$����z�:�E� B� B�E� �<��a�g� &� &�D� �L���� (� (�E� � ���)C�D� Q� Q� Q�F� �G�G�F�D�G� )� )�E� �X�X�f�d�X� +� +�F� ���f�d�� #� #�B� �t�z�4�%�<�4�/�����B���P�P� P�C� �6�6�!�'�4�6� (� (�(r�stage�orderc�x�|j|z }tj||k��|dkr`|d|dz |z zzdd|zg}tjtjtjdd��ddd�df|��|j��}n|}tj|��D]}t|||||z z|��}�|S)zb order_type 0 == ascending order_type 1 == descending order_type 2 == alternating rrrN) r0r� static_assertr/r�r�rB� static_ranger�)rr�r�r�r�rBr�rs r�_bitonic_merger�Vs��� �g��/�G���u���'�'�'�  ��z�z�!(�1�v��z�E�/A�+B�!B�A�q�%�x� P���|�D�-�d�k�!�Q�.?�.?��a�a�a�� �.N�PU�V�V�XY�X_�`�`����� � �u� %� %�E�E�� �a��q�F�U�N�';�V� D� D��� �Hr�dim� descendingc�6�|�t|j��dz n|}tj|t|j��dz kd��t |j|��}tjd|dz��D]}t ||||krdn||��}�|S)Nrz+only minor dimension is currently supportedr)�lenrBrr�rr�r�)rr�r��_dimr�rs r�sortr�os���03�{�3�q�w�<�<�!�+�+��D���t�s�1�7�|�|�a�/�/�1^�_�_�_�"�1�7�4�=�1�1�F� � �q�&�1�*� -� -�J�J�� �1�a�a�&�j�j���j�&� I� I��� �Hrc���t|��}t|��}|�t|��dz }|t|��dz ks Jd���tj|��S)Nrz2Currently only support flipping the last dimension)rr�rr )r�rBs r� _get_flip_dimr�sd�� �s� #� #�C� �� '� '�E� �{��%�j�j�1�n�� �#�e�*�*�q�.� � � �"V� � � � �>�#� � �rc �`�tjt|jt ||j������tjt|j����t |j��}t |j��t |jt ||j����z }tj|dg|z��}tj||��}tj dd��dd�dfdtj dd��z k}tj ||��D][}|}tj d|dz��D]&}||kr||dzkrtj||��}�'t||z|dzd���}�\tj||j��}|S)z� Flips a tensor `x` along the dimension `dim`. :param x: the first input tensor :type x: Block :param dim: the dimension to flip along (currently only final dimension supported) :type dim: int rrNrTrl) rr�rrBr�r0rr/� expand_dimsr�r�r') rr��steps�startr�r�r�flip2r5s rr�r��s��� ��'��� �c�1�7�0K�0K�(L�M�M�N�N�N���'���0�0�1�1�1�"�!�'�N�N�E�!�!�'�N�N�U�1�7�=��a�g�;V�;V�3W�-X�-X�X�E� � �Q���e� �$�$�A� ���E�"�"�A� �K��1� � �a�a�a��g� &�!�d�k�!�Q�.?�.?�*?� ?�D� � �u�e� ,� ,�2�2�����"�1�e�a�i�0�0� 3� 3�A��A�v�v�!�q�1�u�*�*��(���2�2��� ��E� �1�q�5�D� 1� 1� 1��� � �Q��� � �A� �Hrc��tj||��}t|jt��sJ�t |j��dkr|Stj||jdd�d|jdzgz��S)z� Interleaves the values of two tensors along their last dimension. The two tensors must have the same shape. Equivalent to `tl.join(a, b).reshape(a.shape[-1:] + [2 * a.shape[-1]])` rN�����r)r�joinr rB�listr�r/)rbrc�cs r� interleaver��ss�� � �!�Q���A� �a�g�t� $� $�$�$� $� �1�7�|�|�q����� �|�A�q�w�s��s�|�q�1�7�2�;��.?�?�@�@�@r)rr)F)NFTF)TFrI)NFNN)rF)rrr�r)r�rr�rr�r)r�rr�rr )0� __future__r� runtime.jitr�rrrrr�_tensor_member_fnr�_add_math_1arg_docstrr r$r1r?rDrGrUrZr]rd�_add_reduction_docstrr&rr�r�r�r�r�r�r�r'r��builtinr��_add_scan_docstrr�r�r�r�r�� CONSTEXPR_0r�r�r�r�rrr�<module>r�sJ��"�"�"�"�"�"������������������� ;�;�;� � � � �9�9�9�9����  �  �����  �������I�&�&�"�"�'�&�����"�������I�&�&�.�.�.�'�&�����.����8�8�����8��#�#���#�L� &� &��� &��+�+���+��������A�A���A��B�B���B�������������I�:J�*I�K�K�K�O�O�O�K�K�����O�"������O�;K�L�L�L����M�L������� � ��� ��A�A���A��B�B���B�������������I�:J�*I�K�K�K�O�O�O�K�K�����O�"������O�;K�L�L�L����M�L������ ������������E�"�"�G�G�G�#�"�����G� �������������I�&�&�q�q�q�'�&�����q�������x� � �E�E�E�!� �����E�������������y�!�!�F�F�F�"�!�����F��)�)�)���)�&� � � ��� �0���"&�T�EU� � � � ����� ������� � � ����� �8�A�A���A�A�Ar
Memory