§
     ’Þj·	  ã                   ó²   — d Z ddlZddlmZ ddlmZmZmZ 	 ddlm	Z
 n# eeef$ r dZ
Y nw xY wej        ej        fZd„ Zd„ Zd	„ Z ej        ee¦  «         dS )
aª  Projections that MMGP row views compute in place from a fused weight interleaving its projections head by head (mmgp.row_views):
the Triton GEMM reads each projection's rows where they are (as precise as cuBLAS or better: FP32 accumulation, one rounding); the
PyTorch path runs one cuBLAS product per head. Registered with MMGP at import, which then keeps such weights fused instead of copying
their projections apart at load.é    N)Ú	row_viewsé   )ÚchooseÚcuda_inferenceÚtriton_dtype_supported)Úrowmap_tritonc                 óæ   — t           d uoht          | t          d¬¦  «        oQ|j        | j        k    oA|j        o:|                     d¦  «        dk    o!|                      d¦  «        dk    o|dz  dk    S )NT)ÚdtypesÚhipr   é@   r   )Ú_tritonr   Ú_DTYPESÚdtypeÚis_cudaÚstride)ÚxÚweightÚhead_dims      úDC:\Users\johnn\OneDrive\Documents\AI\shared\kernels\rowmap_linear.pyÚ_triton_usabler      sš   € Ý˜4Ðð A¥N°1½WÈ$Ð$OÑ$OÔ$Oð AØ” ¤Ò'ðAØ,2¬NðAØ?E¿}º}ÈQÑ?OÔ?OÐSTÒ?TðAØYZ×YaÒYaÐbcÑYdÔYdÐhiÒYiðAØnvÐy{Ñn{ð  @Aò  oAðBó    c           
      óø  — t          dt          | ||¦  «        ¬¦  «        rt          j        | |||||||¦  «        S |                      | j        d         ||z
  f¦  «        }t          |||¦  «        D ]‡}	|	|z  |z  |z  ||z  z   }
|dd…|	|z
  |	|z
  |z   …f         }|€(t          j        | ||
|
|z   …         j	        |¬¦  «         ŒTt          j
        ||
|
|z   …         | ||
|
|z   …         j	        |¬¦  «         Œˆ|S )z¡Columns [start, stop) (multiples of head_dim) of projection `slot` of a weight whose rows are (heads, slots, head_dim), for x of
    shape (tokens, in_features).zInterleaved Projections)Úowned_tritonr   N)Úout)r   r   r   ÚrowsÚ	new_emptyÚshapeÚrangeÚtorchÚmmÚTÚaddmm)r   r   ÚbiasÚslotÚslotsr   ÚstartÚstopr   ÚcolumnÚrowÚtargets               r   r   r      s6  € õ Ð'µnÀQÈÐPXÑ6YÔ6YÐZÑZÔZð QÝŒ|˜A˜v t¨T°5¸(ÀEÈ4ÑPÔPÐPØ
�+Š+�q”w˜q”z 4¨%¡<Ð0Ñ
1Ô
1€CÝ˜˜t XÑ.Ô.ð _ð _ˆØ˜Ñ  5Ñ(¨8Ñ3°d¸X±oÑEˆØ�Q�Q�Q˜ ™ v°¡~¸Ñ'@Ð@Ð@ÔAˆØˆ<ÝŒH�Q˜˜s 3¨¡>Ð1Ô2Ô4¸&ÐAÑAÔAÐAÐAåŒK˜˜S  x¡Ð/Ô0°!°V¸CÀÀhÁÐ<NÔ5OÔ5QÐW]Ð^Ñ^Ô^Ð^Ð^Ø€Jr   c                 óò   — t           duon| t          v oe|dz  dk    o\t          j                             ¦   «         o>t          t          j        dt          j                             ¦   «         ¦  «        | ¦  «        S )zWhether MMGP should keep a fused interleaved weight of this dtype: the Triton GEMM makes its projections as fast as split ones.Nr   r   Úcuda)r   r   r   r,   Úis_availabler   ÚdeviceÚcurrent_device)r   r   s     r   Ú	availabler0   '   st   € å˜4Ðð a E­WÐ$4ð a¸ÀB¹È!Ò9Kð aÕPUÔPZ×PgÒPgÑPiÔPið aÝ&¥u¤|°F½E¼J×<UÒ<UÑ<WÔ<WÑ'XÔ'XÐZ_Ñ`Ô`ðbr   )Ú__doc__r   Úmmgpr   Údispatchr   r   r   Ú r   r   ÚImportErrorÚOSErrorÚRuntimeErrorÚbfloat16Úfloat16r   r   r   r0   Úregister_kernel© r   r   ú<module>r<      sï   ðð$ð $ð €€€Ø Ð Ð Ð Ð Ð Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DðØ*Ð*Ð*Ð*Ð*Ð*Ð*øØ�W˜lÐ+ð ð ð Ø€G€G€Gðøøøð Œ>˜5œ=Ð
)€ðBð Bð Bð
ð ð ð bð bð bð €	Ô ˜$ 	Ñ *Ô *Ð *Ð *Ð *s   ˜ Ÿ
,«,