Ë
    ÄÓ^j++  ã                  ó°   — d dl mZ d dlmZmZ d dlmZmZ d dlZd dl	Zd dl
mZ d dlmZ ddlmZmZmZ er
d d	lmZ d dlZ G d
„ de«      Z G d„ de«      Zy)é    )Úannotations)ÚABCÚabstractmethod)ÚAnyÚTYPE_CHECKINGN)Úir)ÚVé   )ÚFixedLayoutÚFlexibleLayoutÚLayout)ÚSequencec                  óÆ   — e Zd ZdZ	 	 d	 	 	 	 	 dd„Zddd„Zedd„«       Zedd„«       Zdd„Z	dd„Z
dd	„Zdd
„Zdd„Zdd„Zdd„Zddd„Zedd„«       Zd d„Zed!d"d„«       Zy)#ÚKernelInputszÞ
    Class to store and provide access to input nodes for kernels.
    This class takes in a tuple of input nodes and provides methods to access
    information about these nodes, such as their device type and device.
    Nc                ón   — || _         d| _        |�|ni | _        || _        t	        |«      dkD  sJ d«       ‚y)z·
        Initialize with a tuple of input nodes.

        Args:
            input_nodes: A tuple of input nodes to store
            out_dtype: Optional output dtype to store
        Nr   z Expected at least one input node)Ú_input_nodesÚ_device_nameÚ_scalarsÚ
_out_dtypeÚlen)ÚselfÚinput_nodesÚscalarsÚ	out_dtypes       úh/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/_inductor/kernel_inputs.pyÚ__init__zKernelInputs.__init__   sB   € ð (ˆÔØ(,ˆÔØ#*Ð#6™¸BˆŒØ#ˆŒÜ�;Ó !Ò#ÐGÐ%GÓGÑ#ó    c                óö   — |€| j                   S t        | j                   «      t        |«      k(  s)J dt        | j                   «      › dt        |«      › �«       ‚|D �cg c]  }| j                   |   ‘Œ c}S c c}w )a7  
        Return the stored input nodes, optionally reordered.

        Args:
            reorder: Optional sequence of indices to reorder the nodes.
                    For example, (2, 0, 1) would return nodes in that order.

        Returns:
            The tuple of input nodes, optionally reordered
        zReorder length mismatch: ú vs )r   r   )r   ÚreorderÚis      r   ÚnodeszKernelInputs.nodes.   sz   € ð ˆ?Ø×$Ñ$Ð$Ü�4×$Ñ$Ó%¬¨W«Ò5ð 	
Ø'¬¨D×,=Ñ,=Ó(>Ð'?¸tÄCÈÃLÀ>ÐRó	
Ð5ð /6Ö6¨�×!Ñ! !Ó$Ò6Ð6ùÒ6s   ÁA6c                ó,   — t        | j                  «      S )zh
        Get the number of input nodes.

        Returns:
            The number of input nodes
        )r   r   ©r   s    r   ÚcountzKernelInputs.count@   s   € ô �4×$Ñ$Ó%Ð%r   c                óF   — t        j                  | j                  d   «      S )z|
        Get the device type of the first node.

        Returns:
            The device type (e.g., 'cuda', 'cpu')
        r   )r   Úget_device_typer   r$   s    r   Údevice_typezKernelInputs.device_typeJ   s    € ô ×!Ñ! $×"3Ñ"3°AÑ"6Ó7Ð7r   c                ó<   — | j                   d   j                  «       S )zn
        Get the device of the first node.

        Returns:
            The device of the first node
        r   )r   Ú
get_devicer$   s    r   ÚdevicezKernelInputs.deviceU   s   € ð × Ñ  Ñ#×.Ñ.Ó0Ð0r   c                óÐ   — | j                   €O| j                  «       }| j                  dk(  r0t        j                  j                  |«      }|j                  | _         | j                   S )zu
        Get the device name information.

        Returns:
            A tuple of (gpu_name, vendor, model)
        Úcuda)r   r+   r(   Útorchr-   Úget_device_propertiesÚgcnArchName)r   r+   Údevice_propertiess      r   Údevice_namezKernelInputs.device_name^   sX   € ð ×ÑÐ$Ø—[‘[“]ˆFØ×Ñ 6Ò)Ü$)§J¡J×$DÑ$DÀVÓ$LÐ!Ø$5×$AÑ$A�Ô!Ø× Ñ Ð r   c                ó:   — t        d„ | j                  D «       «      S )z‡
        Get the symbolic shapes of all input nodes.

        Returns:
            A tuple of shape tuples for each input node
        c              3  ó<   K  — | ]  }|j                  «       –— Œ y ­w©N)Úget_size©Ú.0Únodes     r   ú	<genexpr>z/KernelInputs.shapes_symbolic.<locals>.<genexpr>s   s   è ø€ ÒC¨�T—]‘]—_ÑCùó   ‚©Útupler   r$   s    r   Úshapes_symboliczKernelInputs.shapes_symbolicl   s   € ô ÑC°×1BÑ1BÔCÓCÐCr   c                ó:   — t        d„ | j                  D «       «      S )z 
        Get the size hints for shapes of all input nodes.

        Returns:
            A tuple of shape tuples with integer hints for each input node
        c              3  óŠ   K  — | ];  }t         j                  j                  j                  |j	                  «       «      –— Œ= y ­wr5   )r	   ÚgraphÚsizevarsÚoptimization_hintsr6   r7   s     r   r:   z-KernelInputs.shapes_hinted.<locals>.<genexpr>|   s3   è ø€ ò 
àô �G‰G×Ñ×/Ñ/°·±³×@ñ
ùó   ‚AAr<   r$   s    r   Úshapes_hintedzKernelInputs.shapes_hintedu   ó$   € ô ñ 
à×)Ñ)ô
ó 
ð 	
r   c                ó:   — t        d„ | j                  D «       «      S )z‰
        Get the symbolic strides of all input nodes.

        Returns:
            A tuple of stride tuples for each input node
        c              3  ó<   K  — | ]  }|j                  «       –— Œ y ­wr5   )Ú
get_strider7   s     r   r:   z0KernelInputs.strides_symbolic.<locals>.<genexpr>ˆ   s   è ø€ ÒE¨4�T—_‘_×&ÑEùr;   r<   r$   s    r   Ústrides_symboliczKernelInputs.strides_symbolic�   s   € ô ÑE°4×3DÑ3DÔEÓEÐEr   c                ó:   — t        d„ | j                  D «       «      S )z¢
        Get the size hints for strides of all input nodes.

        Returns:
            A tuple of stride tuples with integer hints for each input node
        c              3  óŠ   K  — | ];  }t         j                  j                  j                  |j	                  «       «      –— Œ= y ­wr5   )r	   rA   rB   rC   rI   r7   s     r   r:   z.KernelInputs.strides_hinted.<locals>.<genexpr>‘   s4   è ø€ ò 
àô �G‰G×Ñ×/Ñ/°·±Ó0A×Bñ
ùrD   r<   r$   s    r   Ústrides_hintedzKernelInputs.strides_hintedŠ   rF   r   c                ó:   — t        d„ | j                  D «       «      S )zx
        Get the dtypes of all input nodes.

        Returns:
            A tuple of dtypes for each input node
        c              3  ó<   K  — | ]  }|j                  «       –— Œ y ­wr5   )Ú	get_dtyper7   s     r   r:   z&KernelInputs.dtypes.<locals>.<genexpr>�   s   è ø€ ÒD¨$�T—^‘^×%ÑDùr;   r<   r$   s    r   ÚdtypeszKernelInputs.dtypes–   s   € ô ÑD°$×2CÑ2CÔDÓDÐDr   c                ó<   — | j                   |   j                  «       S )zÒ
        Get the dtype of a specific input node.

        Args:
            idx: Index of the node to get the dtype from (default: 0)

        Returns:
            The dtype of the specified input node
        )r   rP   )r   Úidxs     r   ÚdtypezKernelInputs.dtypeŸ   s   € ð × Ñ  Ñ%×/Ñ/Ó1Ð1r   c                 ó   — y)úƒ
        Get the output dtype, whether passed in or inferred from the nodes

        Returns:
            The output dtype
        N© r$   s    r   r   zKernelInputs.out_dtype«   ó   � r   c                óR   — || j                   v sJ d|› d�«       ‚| j                   |   S )z¢
        Get the scalar value for a given name.

        Args:
            name: Name of the scalar to get

        Returns:
            The scalar value
        zScalar z not found, but required)r   )r   Únames     r   Ú
get_scalarzKernelInputs.get_scalar´   s4   € ð �t—}‘}Ñ$ÐN¨°¨vÐ5MÐ&NÓNÐ$Ø�}‰}˜TÑ"Ð"r   c                 ó   — y)zñ
        Abstract method to handle output layout generation.

        Args:
            out_dtype: Optional output dtype. If not provided, infer from inputs
            flexible: If True, return FlexibleLayout, otherwise FixedLayout
        NrW   )r   Úflexibles     r   Úoutput_layoutzKernelInputs.output_layoutÁ   rX   r   )NN)r   ú	list[Any]r   údict[str, float | int] | Noner   útorch.dtype | Noner5   )r    zSequence[int] | NoneÚreturnr_   ©rb   Úint)rb   z
str | None)rb   ztorch.device)rb   ztuple[tuple[Any, ...], ...])rb   ztuple[tuple[int, ...], ...])rb   z%tuple[tuple[sympy.Integer, ...], ...])rb   ztuple[torch.dtype, ...])r   )rS   rd   rb   útorch.dtype©rb   re   )rZ   Ústrrb   zfloat | int©T©r]   Úboolrb   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   Úpropertyr%   r(   r+   r2   r>   rE   rJ   rM   rQ   rT   r   r   r[   r^   rW   r   r   r   r      s¹   „ ñð 26Ø(,ð	HàðHð /ðHð &ó	Hô&7ð$ ò&ó ð&ð ò8ó ð8ó1ó!óDó

óFó

óEô
2ð òó ðó#ð óó ñr   r   c                  óv   ‡ — e Zd ZdZ	 	 	 	 d		 	 	 	 	 	 	 	 	 d
ˆ fd„Z	 	 dd„Zdd„Zddd„Zdd„Zdd„Z	dd„Z
ˆ xZS )ÚMMKernelInputsz†
    Specialized KernelInputs for matrix multiplication operations.
    Provides additional methods to access M, N, K dimensions.
    c                óV  •— t         ‰| �  |||«       t        | j                  «      dk\  sJ d«       ‚||}}|dk  r|t        |«      z  }|dk  r|t        |«      z  }d|cxk  rt        |«      k  sn J d|› �«       ‚d|cxk  rt        |«      k  sn J d|› �«       ‚|| _        || _        y)z³
        Initialize with a tuple of input nodes.

        By default, we assume the last 2 input nodes are mat1 and mat2, but
        the caller can adjust when necessary
        é   zExpected at least 2 input nodesr   zInvalid mat1_idx: zInvalid mat2_idx: N)Úsuperr   r   r   Ú	_mat1_idxÚ	_mat2_idx)	r   r   r   r   Úmat1_idxÚmat2_idxÚm1_idxÚm2_idxÚ	__class__s	           €r   r   zMMKernelInputs.__init__Ò   sÆ   ø€ ô 	‰Ñ˜ g¨yÔ9ô �4×$Ñ$Ó%¨Ò*ÐMÐ,MÓMÐ*ð " 8�ˆØ�aŠ<Ø”c˜+Ó&Ñ&ˆFØ�aŠ<Ø”c˜+Ó&Ñ&ˆFà�FÔ-œS Ó-Ô-ÐNÐ1CÀHÀ:Ð/NÓNÐ-Ø�FÔ-œS Ó-Ô-ÐNÐ1CÀHÀ:Ð/NÓNÐ-à!ˆŒØ!ˆ�r   c                ól  — | j                  «       | j                     }| j                  «       | j                     }|j                  «       d   }|j                  «       d   }|j                  «       d   }|j                  «       d   }t        j
                  j                  j                  ||«       |||fS )a±  
        Get the symbolic M, N, K dimensions for matrix multiplication.
        Handles both 2D (MM) and 3D (BMM) tensors.

        M is extracted from the second-to-last dimension of the first operand (mat1).
        N is extracted from the last dimension of the second operand (mat2).
        K is extracted from the last dimension of the first operand (mat1).

        Returns:
            A tuple of (M, N, K) dimensions
        éþÿÿÿéÿÿÿÿ)r"   ru   rv   r6   r	   rA   rB   Úcheck_equals)r   Úmat1Úmat2ÚmÚkÚnÚk0s          r   Úmnk_symboliczMMKernelInputs.mnk_symbolicó   s”   € ð �z‰z‹|˜DŸN™NÑ+ˆØ�z‰z‹|˜DŸN™NÑ+ˆà�M‰M‹O˜BÑˆØ�M‰M‹O˜BÑˆØ�M‰M‹O˜BÑˆð �]‰]‹_˜RÑ ˆÜ	�‰×Ñ×%Ñ% a¨Ô,Ø�1�aˆyÐr   c                ót   — | j                   �| j                   S | j                  «       d   j                  «       S )rV   r   )r   Úmat1mat2rP   r$   s    r   r   zMMKernelInputs.out_dtype  s2   € ð �?‰?Ð&Ø—?‘?Ð"Ø�}‰}‹˜qÑ!×+Ñ+Ó-Ð-r   c                ó²  — | j                  «       \  }}| j                  «       }|j                  «       �^ }}}|j                  «       �^ }}	}
t        ||«      D ��cg c]/  \  }}t        j
                  j                  j                  ||«      ‘Œ1 c}}}g |¢|‘|
‘}|rt        | j                  «       ||«      S t        | j                  «       ||«      S c c}}w )zø
        Handle output layout generation for matrix multiplication.

        Args:
            out_dtype: Optional output dtype. If not provided, infer from inputs
            flexible: If True, return FlexibleLayout, otherwise FixedLayout
        )rˆ   r   r6   Úzipr	   rA   rB   Úcheck_equals_and_simplifyr   r+   r   )r   r]   r€   r�   r   Úb1r‚   Úk1Úb2Úk2r„   ÚaÚbÚsizes                 r   r^   zMMKernelInputs.output_layout  s·   € ð —]‘]“_‰
ˆˆdØ—N‘NÓ$ˆ	à—]‘]“_‰
ˆˆQ�Ø—]‘]“_‰
ˆˆR�ÜJMÈbÐRTË+×VÁ$À!ÀQŒQ�W‰W×Ñ×7Ñ7¸¸1Õ=ÓVˆØ�ˆz�Aˆz�qˆzˆÙÜ! $§+¡+£-°¸DÓAÐAä˜tŸ{™{›}¨i¸Ó>Ð>ùó Ws   Á4Cc                ó^   — | j                  «       }|| j                     || j                     fS )zj
        Get the mat1 and mat2 nodes.

        Returns:
            A tuple of (mat1, mat2) nodes
        )r"   ru   rv   )r   r"   s     r   rˆ   zMMKernelInputs.mat1mat2,  s,   € ð —
‘
“ˆØ�T—^‘^Ñ$ e¨D¯N©NÑ&;Ð;Ð;r   c                ó´   — | j                  «       }|| j                     }|| j                     }|d   }|d   }|d   }|d   }||k(  sJ d|› d|› �«       ‚|||fS )a   
        Get the hinted M, N, K dimensions for matrix multiplication.
        Handles both 2D (MM) and 3D (BMM) tensors.

        Uses shapes_hinted from the base class to get integer hints for dimensions.

        Returns:
            A tuple of (M, N, K) dimensions as integers
        r}   r~   zK dimensions don't match: r   )rE   ru   rv   )r   Úhinted_shapesÚ
mat1_shapeÚ
mat2_shaper‚   rƒ   r„   Úk_checks           r   Ú
mnk_hintedzMMKernelInputs.mnk_hinted6  s   € ð ×*Ñ*Ó,ˆØ" 4§>¡>Ñ2ˆ
Ø" 4§>¡>Ñ2ˆ
à�r‰NˆØ�r‰NˆØ�r‰Nˆð ˜R‘.ˆØ�GŠ|ÐJÐ9¸!¸¸DÀÀ	ÐJÓJˆ|à�1�aˆyÐr   c                óh   — | j                  «       }|| j                     }t        |«      dk\  r|d   S y)z¼
        Get the hinted batch size for batched matrix multiplication.
        Returns 1 for non-batched (2D) operations.

        Returns:
            The batch size as an integer
        é   éýÿÿÿr
   )rE   ru   r   )r   r•   r–   s      r   Úbatch_hintedzMMKernelInputs.batch_hintedN  s9   € ð ×*Ñ*Ó,ˆØ" 4§>¡>Ñ2ˆ
äˆz‹?˜aÒØ˜b‘>Ð!Ør   )NNr}   r~   )
r   r_   r   r`   r   ra   rw   rd   rx   rd   )rb   z2tuple[sympy.Integer, sympy.Integer, sympy.Integer]rf   rh   ri   )rb   ztuple[Any, Any])rb   ztuple[int, int, int]rc   )rk   rl   rm   rn   r   r†   r   r^   rˆ   r™   r�   Ú__classcell__)r{   s   @r   rq   rq   Ì   sr   ø„ ñð 26Ø(,ØØð"àð"ð /ð"ð &ð	"ð
 ð"ð õ"ðBà	;óó4	.ô?ó(<ó÷0r   rq   )Ú
__future__r   Úabcr   r   Útypingr   r   r.   Útorch._inductor.configÚtorch._inductorr   Útorch._inductor.virtualizedr	   r   r   r   Úcollections.abcr   Úsympyr   rq   rW   r   r   ú<module>r§      sH   ðÝ "ç #ß %ã Û Ý Ý )ç 3Ñ 3ñ Ý(ãôu�3ô uôpO�\õ Or   