
    Ϧi                        S SK r S SKrS SKrS SKrS SKrS SKJr  S SK	r	S SK
Jr  S SKJrJr  S SKJrJr  / SQr/ SQr\\-   r/ SQr\\-   r\S/-   rS	S
/rS/\-   S/-   \-   S/-   rS rS rS rS rS rSS\\   4S jjrSS\R@                  S\\\RB                  4   4S jjr"S\#4S jr$S r%S r&\	RN                  RQ                  \&" 5       (       + SS9r)g)    N)RandomState)OptionalUnion)TensorWrapperreinterpret)int8int16int32int64)uint8uint16uint32uint64)float16float32float64bfloat16float8_e4m3fnfloat8_e5m2boolr   c                  H    [         R                  R                  SS5      S:H  $ )NTRITON_INTERPRET01)osenvironget     W/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/triton/_internal_testing.pyis_interpreterr!      s    ::>>,c2c99r   c                      [        5       (       a  g [        R                  R                  R                  R                  5       $ N)r!   tritonruntimedriveractiveget_current_targetr   r   r    r(   r(      s-    >>  ''::<<r   c                  >    [        5       n U c  S$ U R                  S:H  $ )NFcudar(   backendtargets    r    is_cudar/   !   s"    !FN5@&(@@r   c                  >    [        5       n U c  S$ U R                  S:H  $ )NFhipr+   r-   s    r    is_hipr2   &   s"    !FN5?%(??r   c                  J    [        5       n U c  S$ [        U R                  5      $ )N )r(   strarchr-   s    r    get_archr7   +   s"    !F25S%55r   rsc                 Z   [        U [        5      (       a  U 4n Uc	  [        SS9nU[        [        -   ;   a  [
        R                  " [        [
        U5      5      nUc  UR                  O[        X5R                  5      nUc  UR                  O[        XER                  5      n[        [
        U5      nUR                  X4XS9nSXwS:H  '   U$ U(       a(  SU;   a"  UR                  SSU [
        R                  S9nU$ U[        ;   a"  UR                  SSU 5      R                  U5      $ US	:X  aW  UR                  SSU 5      R                  S
5      R                  S5      [
        R                   " S5      -  R                  S
5      $ US;   a  UR                  SSU 5      S:  $ [#        SU 35      e)zd
Override `rs` if you're calling this function twice and don't want the same
result for both calls.
   )seed)dtype   r   float8   (   r   r   r   l      )r   int1bool_g        zUnknown dtype )
isinstanceintr   
int_dtypesuint_dtypesnpiinfogetattrminmaxrandintr   float_dtypesnormalastypeviewr   RuntimeError)shape	dtype_strr8   lowhighrH   r<   xs           r    numpy_randomrW   0   su   
 %		zb!J,,Y/0;eiiCYY,? Luyyc$		.BI&JJs%J5q&		x9,JJr2uBGGJ4	l	"yyAu%,,Y77	j	 		!Q&--i8==hG"))T^J__eefopp	/	/yyAu%++^I;788r   rV   returnc                    U R                   R                  nU[        ;   a\  UR                  S5      nU R	                  [        [        U5      5      n[        [        R                  " XQS9[        [        U5      5      $ U(       a2  SU;   a,  [        [        R                  " XS9[        [        U5      5      $ US:X  a(  US:X  a"  [        R                  " XS9R                  5       $ [        R                  " XS9$ )z
Note: We need dst_type because the type of x can be different from dst_type.
      For example: x is of type `float32`, dst_type is `bfloat16`.
      If dst_type is None, we infer dst_type from x.
u)devicer>   r   r   )r<   namerF   lstriprO   rI   rG   r   torchtensortlr   )rV   r[   dst_typetsigned_type_namex_signeds         r    	to_tritonre   N   s     	
AK88C=88GB(89:5<<@'"a.QQH,u||A=wr8?TUU	>h*4<<1::<<||A--r   c                 :   [        U [        R                  R                  5      (       a  U R                  $ [        U [
        R                  5      (       a1  [        R                  " S[        U 5      5      nUR                  S5      $ [        S[        U 5       35      e)Nz^torch\.(\w+)$r=   znot a triton or torch dtype: )rC   r$   languager<   r\   r^   rematchr5   group	TypeErrortype)r<   ms     r    torch_dtype_namern   a   sn    %..//zz	E5;;	'	'HH&E
3wwqz7U}EFFr   c                    [        U [        5      (       aX  U R                  R                  5       R	                  5       R                  [        [        [        U R                  5      5      5      $ [        U [        R                  5      (       ag  U R                  [        R                  L a,  U R                  5       R                  5       R	                  5       $ U R                  5       R	                  5       $ [        SU  35      e)Nz Not a triton-compatible tensor: )rC   r   basecpunumpyrO   rI   rG   rn   r<   r^   Tensorr   float
ValueError)rV   s    r    to_numpyrv   l   s    !]##vvzz|!!#**727G7P+QRR	Au||	$	$77enn$557==?((**uuw}};A3?@@r   c                  l    [        5       =(       a$    [        R                  R                  5       S   S:  $ )Nr   	   )r/   r^   r*   get_device_capabilityr   r   r    supports_tmarz   w   s&    9C99;A>!CCr   z.Requires TMA support (NVIDIA Hopper or higher))reason)NNNr#   )*r   rh   rr   rG   r^   r$   triton.languagerg   r`   pytestnumpy.randomr   typingr   r   triton.runtime.jitr   r   rE   rF   integral_dtypesrM   dtypesdtypes_with_bfloat16torch_float8_dtypestorch_dtypesr!   r(   r/   r2   r7   rW   ndarrayrs   re   r5   rn   rv   rz   markskipifrequires_tmar   r   r    <module>r      s	   	 	      $ " 90
5{*0	<	', &6 x*$y0<?:,N:=A
@
6
9x'< 9<. .u]ELL=X7Y .&Gs GAD {{!!ln"4=m!nr   