Ë
    4^(hPN  ã                   óô   — d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZ ddlmZ ddlmZ d„ Zd„ Zd	„ Zdd
„Zdd„Zdd„Z G d„ d«      Z G d„ d«      Zd„ Zdd„Zdd„Zd„ Zedd„«       Zdd„Zy)é    N)Úcontextmanager)ÚAnyÚDictÚListé   )Úlanguage)Úruntimec                 ó  — dj                  | «      } dddd| z   dg}t        j                  |«      }|j                  t        j
                  j                  «      j                  d«      }|D �cg c]  }t        |«      ‘Œ }}|S c c}w )Nú,ú
nvidia-smiú-iÚ0z--query-gpu=z--format=csv,noheader,nounits)	ÚjoinÚ
subprocessÚcheck_outputÚdecodeÚsysÚstdoutÚencodingÚsplitÚint)ÚattrsÚcmdÚoutÚretÚxs        úL/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/triton/testing.pyÚnvsmir      sy   € Ø�H‰H�U‹O€EØ˜˜s N°UÑ$:Ð<[Ð
\€CÜ
×
!Ñ
! #Ó
&€CØ
�*‰*”S—Z‘Z×(Ñ(Ó
)×
/Ñ
/°Ó
4€CØÖ
�aŒ3ˆq�6Ð
€CÐ
Ø€Jùò  s   Á-Bc                 ót   ‡ ‡— t        ‰ «      Št        ‰ «      Š ˆ ˆfd„}|D �cg c]
  } ||«      ‘Œ c}S c c}w )Nc                 óÞ   •— d| cxk  rdk  st        d«      ‚ t        d«      ‚| ‰dz
  z  }t        j                  |«      }t        j                  |«      }||z
  }d|z
  ‰|   z  |‰|   z  z   S )Nr   r   z%Quantiles must be in the range [0, 1])Ú
ValueErrorÚmathÚfloorÚceil)ÚqÚpointÚlowerÚupperÚtÚaÚns        €€r   Úget_quantilez_quantile.<locals>.get_quantile   s}   ø€ Ø�Q”˜!’ÜÐDÓEÐEð ÜÐDÓEÐEØ�Q˜‘U‘ˆÜ—
‘
˜5Ó!ˆÜ—	‘	˜%Ó ˆØ�E‰MˆØ�A‘˜˜5™Ñ! A¨¨%©¡LÑ0Ð0ó    )ÚlenÚsorted)r*   r%   r,   r+   s   `  @r   Ú	_quantiler0      s4   ù€ ÜˆA‹€AÜˆq‹	€Aõ1ð &'Ö' ‰L˜�OÒ'Ð'ùÒ's   £5c                 ó   — |�!t        | |«      }t        |«      dk(  r|d   }|S |dk(  r| S |dk(  rt        | «      S |dk(  rt        | «      S |dk(  rt	        j
                  | «      S |dk(  rt	        j                  | «      S y )Nr   r   ÚallÚminÚmaxÚmeanÚmedian)r0   r.   r3   r4   Ú
statisticsr5   r6   )ÚtimesÚ	quantilesÚreturn_moder   s       r   Ú_summarize_statisticsr;   *   s“   € ØÐÜ˜˜yÓ)ˆÜˆs‹8�qŠ=Ø�a‘&ˆCØˆ
Ø�eÒØˆØ	˜Ò	Ü�5‹zÐØ	˜Ò	Ü�5‹zÐØ	˜Ò	Ü�‰˜uÓ%Ð%Ø	˜Ò	 Ü× Ñ  Ó'Ð'ð 
!r-   c                 ó  — ddl }|dv sJ ‚|j                  j                  |j                  j                  «       «      5   | «        |�/|D ]*  }|j	                  «        |j                  d«       d|_        Œ, |j                  j                  d¬«      }|j                  j                  d¬«      }|j                  «        t        d«      D ]	  }	 | «        Œ |j                  «        |j                  j                  «        |j                  |«      dz  }
t        dt        ||
z  «      «      }|j                  j                  «       }|j                  j                  |«      5  t        |«      D ]  }	|�|D ]	  }d|_        Œ  | «        Œ 	 ddd«       |j                  j                  «        g }d}t        |«      D ]œ  }	|j                  j                  d¬«      }|j                  j                  d¬«      }|j                  «        |j!                  «        |j                  «        |j                  j                  «        ||j                  |«      |z  gz  }Œž t#        |||«      cddd«       S # 1 sw Y   ŒçxY w# 1 sw Y   yxY w)	aÊ  
    Benchmark the runtime of the provided function.

    :param fn: Function to benchmark
    :type fn: Callable
    :param rep: Repetition time (in ms)
    :type rep: int
    :param grad_to_none: Reset the gradient of the provided tensor to None
    :type grad_to_none: torch.tensor, optional
    :param return_mode: The statistical measure to return. Options are "min", "max", "mean", "median", or "all". Default is "mean".
    :type return_mode: str
    r   N©r3   r4   r5   r6   r2   T©Úenable_timingé   r   é
   )ÚtorchÚcudaÚstreamÚStreamÚdetach_Úrequires_grad_ÚgradÚEventÚrecordÚrangeÚsynchronizeÚelapsed_timer4   r   Ú	CUDAGraphÚgraphÚreplayr;   )ÚfnÚrepÚgrad_to_noner9   r:   rB   r   Ústart_eventÚ	end_eventÚ_Úestimate_msÚn_repeatÚgr   Ú	n_retriess                  r   Údo_bench_cudagraphr[   <   sS  € ó ØÐAÑAÐAÐAà	�‰×	Ñ	˜5Ÿ:™:×,Ñ,Ó.Ó	/ñ ,Bá
ŒØÐ#Ø!ò �Ø—	‘	”Ø× Ñ  Ô&Ø�•ðð —j‘j×&Ñ&°TÐ&Ó:ˆØ—J‘J×$Ñ$°4Ð$Ó8ˆ	Ø×ÑÔÜ�q“ò 	ˆAÙ�Dð	à×ÑÔØ�
‰
×ÑÔ Ø!×.Ñ.¨yÓ9¸AÑ=ˆÜ�qœ#˜c KÑ/Ó0Ó1ˆð �J‰J× Ñ Ó"ˆØ�Z‰Z×Ñ˜aÓ ñ 	Ü˜8“_ò �ØÐ+Ø)ò &˜Ø!%˜�ð&á•ñ	÷	ð 	�
‰
×ÑÔ àˆØˆ	Ü�yÓ!ò 	DˆAØŸ*™*×*Ñ*¸Ð*Ó>ˆKØŸ
™
×(Ñ(°tÐ(Ó<ˆIØ×ÑÔ Ø�H‰HŒJØ×ÑÔØ�J‰J×"Ñ"Ô$Ø�K×,Ñ,¨YÓ7¸(ÑBÐCÑC‰Cð	Dô % S¨)°[ÓA÷Y,Bñ ,B÷4	ð 	ú÷5,Bð ,Bús%   ¾D#I<Å!(I0Æ
CI<É0I9	É5I<É<Jc                 óú  — |dv sJ ‚t         j                  j                  j                  «       } | «        |j	                  «        t         j                  j                  j                  «       }|j                  d¬«      }|j                  d¬«      }	|j                  «        t        d«      D ]2  }
t         j                  j                  j                  |«        | «        Œ4 |	j                  «        |j	                  «        |j                  |	«      dz  }t        dt        ||z  «      «      }t        dt        ||z  «      «      }t        |«      D �cg c]  }|j                  d¬«      ‘Œ }}t        |«      D �cg c]  }|j                  d¬«      ‘Œ }	}t        |«      D ]	  }
 | «        Œ t        |«      D ]h  }|�|D ]	  }d|_        Œ t         j                  j                  j                  |«       ||   j                  «         | «        |	|   j                  «        Œj |j	                  «        t        ||	«      D ��cg c]  \  }}|j                  |«      ‘Œ }}}t        |||«      S c c}w c c}w c c}}w )aó  
    Benchmark the runtime of the provided function. By default, return the median runtime of :code:`fn` along with
    the 20-th and 80-th performance percentile.

    :param fn: Function to benchmark
    :type fn: Callable
    :param warmup: Warmup time (in ms)
    :type warmup: int
    :param rep: Repetition time (in ms)
    :type rep: int
    :param grad_to_none: Reset the gradient of the provided tensor to None
    :type grad_to_none: torch.tensor, optional
    :param quantiles: Performance percentile to return in addition to the median.
    :type quantiles: list[float], optional
    :param return_mode: The statistical measure to return. Options are "min", "max", "mean", "median", or "all". Default is "mean".
    :type return_mode: str
    r=   Tr>   r@   r   N)r	   ÚdriverÚactiveÚget_device_interfacerL   Úget_empty_cache_for_benchmarkrI   rJ   rK   Úclear_cacherM   r4   r   rH   Úzipr;   )rQ   ÚwarmuprR   rS   r9   r:   ÚdiÚcacherT   rU   rV   rW   Ún_warmuprX   Úir   ÚsÚer8   s                      r   Údo_benchrj   {   s*  € ð$ ÐAÑAÐAÐAä	�‰×	Ñ	×	3Ñ	3Ó	5€Bá„DØ‡N�NÔä�N‰N×!Ñ!×?Ñ?ÓA€Eð —(‘(¨�(Ó.€KØ—‘ t�Ó,€IØ×ÑÔÜ�1‹Xò ˆÜ�‰×Ñ×)Ñ)¨%Ô0Ù
�ðð ×ÑÔØ‡N�NÔØ×*Ñ*¨9Ó5¸Ñ9€Kô �1”c˜& ;Ñ.Ó/Ó0€HÜ�1”c˜# Ñ+Ó,Ó-€HÜ9>¸x»ÖI°A�2—8‘8¨$�8Õ/ÐI€KÐIÜ7<¸X³ÖG°!�—‘¨�Õ-ÐG€IÐGä�8‹_ò ˆÙ
�ðô �8‹_ò ˆð Ð#Ø!ò �Ø�•ðô 	�‰×Ñ×)Ñ)¨%Ô0à�A‰×ÑÔÙ
ŒØ�!‰×ÑÕðð ‡N�NÔÜ+.¨{¸IÓ+F×G¡4 1 aˆQ�^‰^˜AÕÐG€EÑGÜ  ¨	°;Ó?Ð?ùò- JùÚGùó( Hs   ÅI-Å;I2ÉI7c                 óÄ  — ddl }ddl}t        | |j                  «      s|j	                  | «      } t        ||j                  «      s|j	                  |«      }|€d}t        |«      r || j                  «      n|}|€d}t        |«      r || j                  «      n|}t        | |j                  «      rU| j                  |j                  k(  r| j                  «       } | j                  «       j                  «       j                  «       } t        ||j                  «      rU|j                  |j                  k(  r|j                  «       }|j                  «       j                  «       j                  «       }| j                  dkD  s|j                  dkD  r!|j                  j                  | |||d¬«       y|j                  | |||¬«      st        |› d	| › d
|› d|› d|› d�
«      ‚y)a  
    Asserts that two inputs are close within a certain tolerance.

    :param x: The first input.
    :type x: scala, list, numpy.ndarray, or torch.Tensor
    :param y: The second input.
    :type y: scala, list, numpy.ndarray, or torch.Tensor
    :param atol: The absolute tolerance. Default value is 1e-2.
    :type atol: float, optional
    :param rtol: The relative tolerance. Default value is 0.
    :type rtol: float, optional
    :param err_msg: The error message to use if the assertion fails.
    :type err_msg: str
    r   Ng{®Gáz„?g        r   T)ÚatolÚrtolÚ	equal_nan)rl   rm   ú z is not close to z (atol=z, rtol=ú))ÚnumpyrB   Ú
isinstanceÚTensorÚtensorÚcallableÚdtypeÚbfloat16ÚfloatÚcpuÚdetachÚsizeÚtestingÚassert_allcloseÚallcloseÚAssertionError)r   Úyrl   rm   Úerr_msgÚnprB   s          r   Úassert_closerƒ   ½   sˆ  € ó Ûô �a˜Ÿ™Ô&Ø�L‰L˜‹OˆÜ�a˜Ÿ™Ô&Ø�L‰L˜‹Oˆà€|ØˆÜ$ TœN‰4�—‘Œ=°€Dà€|ØˆÜ$ TœN‰4�—‘Œ=°€Dô �!�U—\‘\Ô"Ø�7‰7�e—n‘nÒ$Ø—‘“	ˆAØ�E‰E‹G�N‰NÓ×"Ñ"Ó$ˆÜ�!�U—\‘\Ô"Ø�7‰7�e—n‘nÒ$Ø—‘“	ˆAØ�E‰E‹G�N‰NÓ×"Ñ"Ó$ˆð 	‡v�v�‚z�Q—V‘V˜a’ZØ
�
‰
×"Ñ" 1 a¨d¸ÈÐ"ÔNØØ�;‰;�q˜! $¨Tˆ;Ô2Ü ˜y¨¨!¨Ð,=¸a¸SÀÈÀvÈWÐUYÐTZÐZ[Ð\Ó]Ð]ð 3r-   c                   ór   — e Zd ZdZ	 	 	 	 	 ddee   dee   dedee   dee   ded	eeef   d
edededefd„Z	y)Ú	Benchmarkzk
    This class is used by the :code:`perf_report` function to generate line plots with a concise API.
    NÚx_namesÚx_valsÚline_argÚ	line_valsÚ
line_namesÚ	plot_nameÚargsÚxlabelÚylabelÚx_logÚy_logc                 ó¬   — || _         || _        |
| _        || _        || _        || _        || _        || _        || _        |	| _	        || _
        || _        y)aq  
        Constructor.
        x_vals can be a list of scalars or a list of tuples/lists. If x_vals is a list
        of scalars and there are multiple x_names, all arguments will have the same value.
        If x_vals is a list of tuples/lists, each element should have the same length as
        x_names.

        :param x_names: Name of the arguments that should appear on the x axis of the plot.
        :type x_names: List[str]
        :param x_vals: List of values to use for the arguments in :code:`x_names`.
        :type x_vals: List[Any]
        :param line_arg: Argument name for which different values correspond to different lines in the plot.
        :type line_arg: str
        :param line_vals: List of values to use for the arguments in :code:`line_arg`.
        :type line_vals: List[Any]
        :param line_names: Label names for the different lines.
        :type line_names: List[str]
        :param plot_name: Name of the plot.
        :type plot_name: str
        :param args: Dictionary of keyword arguments to remain fixed throughout the benchmark.
        :type args: Dict[str, Any]
        :param xlabel: Label for the x axis of the plot.
        :type xlabel: str, optional
        :param ylabel: Label for the y axis of the plot.
        :type ylabel: str, optional
        :param x_log: Whether the x axis should be log scale.
        :type x_log: bool, optional
        :param y_log: Whether the y axis should be log scale.
        :type y_log: bool, optional
        :param styles: A list of tuples, where each tuple contains two elements: a color and a linestyle.
        :type styles: list[tuple[str, str]]
        N)r†   r‡   r�   rˆ   r‰   rŠ   r�   Ústylesr�   rŽ   r‹   rŒ   )Úselfr†   r‡   rˆ   r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r’   s                r   Ú__init__zBenchmark.__init__õ   sY   € ð^ ˆŒØˆŒØˆŒ
Ø ˆŒØ"ˆŒØ$ˆŒØˆŒ
ØˆŒàˆŒØˆŒØ"ˆŒØˆ�	r-   )Ú r•   FFN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r   Úboolr”   © r-   r   r…   r…   ð   s¡   „ ñð ØØØØñ;à�c‘ð;ð �S‘	ð;ð ð	;ð
 ˜‘9ð;ð ˜‘Ið;ð ð;ð �3˜�8‰nð;ð ð;ð ð;ð ð;ð ô;r-   r…   c            	       ó8   — e Zd Zd„ Z	 	 d	dedededefd„Zd
d„Zy)ÚMarkc                 ó    — || _         || _        y ©N©rQ   Ú
benchmarks)r“   rQ   r¢   s      r   r”   zMark.__init__5  s   € ØˆŒØ$ˆ�r-   ÚbenchÚ	save_pathÚ
show_plotsÚ
print_datac                 ó	  — dd l }dd lm}	 dd l}
|j                  }|j                  D �cg c]  }|› d�‘Œ	 }}|j                  D �cg c]  }|› d�‘Œ	 }}t        |j                  «      }|
j                  ||z   |z   |z   ¬«      }|j                  D ]õ  }t        |t
        t        f«      s|D �cg c]  }|‘Œ }}t        |«      t        |«      k7  rt        dt        |«      › d|› �«      ‚t        t        ||«      «      }g g g }}}|j                  D ]I  } | j                   di |¤|j"                  |i¤|j$                  ¤|¤Ž}	 |\  }}}||gz  }||gz  }||gz  }ŒK t        |«      |z   |z   |z   |j(                  t        |«      <   Œ÷ |j*                  �r|	j-                  «        |	j/                  «       }|d   }t1        |j                  «      D ]ò  \  }}||dz      ||dz      }}|j2                  r|j2                  |   d   nd }|j2                  r|j2                  |   d   nd }|j5                  ||   ||   |||¬«       |j7                  «       j9                  «       rŒ‘|j7                  «       j9                  «       rŒ°|j;                  t<        «      }|j;                  t<        «      }|j?                  ||   ||d	|¬
«       Œô |jA                  «        |jC                  |jD                  xs |«       |jG                  |jH                  «       |jK                  |jL                  rdnd«       |jO                  |jP                  rdnd«       |r|	jS                  «        |r8|	jU                  |jV                  jY                  ||j*                  › d�«      «       |||j                  z      }|r=|jZ                  d   dk(  r+|j\                  j_                  «       \  }}||   ||   z
  |d<   |r1ta        |j*                  dz   «       ta        |jc                  «       «       |r?|je                  |jV                  jY                  ||j*                  › d�«      d|› d�d¬«       |S c c}w c c}w c c}w # t&        $ r
 |d d }}}Y �Œ8w xY w)Nr   z-minz-max)Úcolumnsz	Expected z values, got r   )ÚlabelÚcolorÚlsg333333Ã?)Úalpharª   ÚlogÚlinearz.pngé   ÚDiffú:z.csvz%.ÚfF)Úfloat_formatÚindexrœ   )3ÚosÚmatplotlib.pyplotÚpyplotÚpandasrŠ   Úlistr†   Ú	DataFramer‡   rr   Útupler.   r!   Údictrb   r‰   rQ   rˆ   rŒ   Ú	TypeErrorÚlocr‹   ÚfigureÚsubplotÚ	enumerater’   ÚplotÚisnullr2   Úastyperx   Úfill_betweenÚlegendÚ
set_xlabelr�   Ú
set_ylabelrŽ   Ú
set_xscaler�   Ú
set_yscaler�   ÚshowÚsavefigÚpathr   Úshaper¨   ÚtolistÚprintÚ	to_stringÚto_csv)r“   r£   r¤   r¥   r¦   Údiff_colÚsave_precisionÚkwragsrµ   ÚpltÚpdÚy_meanr   Úy_minÚy_maxr†   ÚdfrV   Úx_argsÚrow_meanÚrow_minÚrow_maxr€   r   ÚaxÚfirst_xrg   ÚcolÚstyÚcol0Úcol1s                                  r   Ú_runz	Mark._run9  s!  € ãå'ÛØ×!Ñ!ˆØ%*×%5Ñ%5Ö6 �A�3�d’Ð6ˆÐ6Ø%*×%5Ñ%5Ö6 �A�3�d’Ð6ˆÐ6Ü�u—}‘}Ó%ˆØ�\‰\ '¨FÑ"2°UÑ":¸UÑ"Bˆ\ÓCˆØ—‘ò 	EˆAä˜a¤$¬ Ô/Ø 'Ö(˜1’QÐ(�Ð(ä�1‹vœ˜W›Ò%Ü  9¬S°«\¨N¸-ÈÀsÐ!KÓLÐLÜœ#˜g q›/Ó*ˆFà)+¨R°˜w�gˆHØ—_‘_ò #�Ø�d—g‘gÑV ÐV¨5¯>©>¸1Ð*=ÐVÀÇÁÐVÈvÑV�ð;Ø+.Ñ(�F˜E 5ð ˜V˜HÑ$�Ø˜E˜7Ñ"�Ø˜E˜7Ñ"‘ð#ô # 1›g¨Ñ0°7Ñ:¸WÑDˆB�F‰F”3�r“7ŠOð'	Eð* �?‹?Ø�J‰JŒLØ—‘“ˆBà˜a‘jˆGÜ! %×"2Ñ"2Ó3ò V‘��1Ø! ! f¡*™~¨r°!°f±*©~�u�Ø,1¯LªL�e—l‘l 1‘o aÒ(¸d�Ø,1¯LªL�e—l‘l 1‘o aÒ(¸d�Ø—‘˜˜7™ R¨¡U°!¸3À3�ÔGØ—|‘|“~×)Ñ)Õ+°E·L±L³N×4FÑ4FÕ4HØ!ŸL™L¬Ó/�EØ!ŸL™L¬Ó/�EØ—O‘O B w¡K°¸ÀTÐQT�OÕUðVð �I‰IŒKØ�M‰M˜%Ÿ,™,Ò1¨'Ô2Ø�M‰M˜%Ÿ,™,Ô'à�M‰M 5§;¢;™%°HÔ=Ø�M‰M 5§;¢;™%°HÔ=ÙØ—‘”
ÙØ—‘˜BŸG™GŸL™L¨°u·±Ð6GÀtÐ4LÓMÔNØ�˜%×*Ñ*Ñ*Ñ+ˆÙ˜Ÿ™ ™ qÒ(ØŸ™×*Ñ*Ó,‰JˆD�$Ø˜D™ B t¡HÑ,ˆBˆv‰JáÜ�%—/‘/ CÑ'Ô(Ü�"—,‘,“.Ô!ÙØ�I‰I�b—g‘g—l‘l 9°·±Ð0AÀÐ.FÓGÐXZÐ[iÐZjÐjkÐVlØ!ð ô #àˆ	ùòy 7ùÚ6ùò )øô !ò ;Ø+.°°d 5˜E“Fð;ús#   ©QÁQ#Â,	Q(ÅQ-Ñ-R Ñ?R c           	      ó  — t        | j                  t        «      }|r| j                  gn| j                  }g }|rRt        j                  |d¬«       t        t        j                  j                  |d«      d«      }	|	j                  d«       |D ]I  }
|j                   | j                  |
|||fi |¤Ž«       |sŒ+	j                  d|
j                  › d�«       ŒK |r!	j                  d«       |	j                  «        |r	|r|d	   S |S y )
NT)Úexist_okzresults.htmlÚwz<html><body>
z<image src="z.png"/>
z</body></html>
r   )rr   r¢   r…   rµ   ÚmakedirsÚopenrÍ   r   ÚwriteÚappendræ   r‹   Úclose)r“   r¥   r¦   r¤   Ú	return_dfÚkwargsÚhas_single_benchr¢   Ú
result_dfsÚhtmlr£   s              r   ÚrunzMark.run~  sì   € Ü% d§o¡o´yÓAÐÙ*:�d—o‘oÑ&ÀÇÁˆ
Øˆ
Ùä�K‰K˜	¨DÕ1ÜœŸ™Ÿ™ Y°Ó?ÀÓEˆDØ�J‰JÐ'Ô(Øò 	HˆEØ×Ñ˜i˜dŸi™i¨¨y¸*ÀjÑ[ÐTZÑ[Ô\ÚØ—
‘
˜]¨5¯?©?Ð*;¸:ÐFÕGð	Hñ Ø�J‰JÐ)Ô*Ø�J‰JŒLÙÙØ! !‘}Ð$à!Ð!Ør-   N)Fé   )FFr•   F)	r–   r—   r˜   r”   r…   rš   r›   ræ   rô   rœ   r-   r   rž   rž   3  s>   „ ò%ð chØñC˜)ð C°ð CÀð CÐSWó CôJr-   rž   c                 ó   ‡ — ˆ fd„}|S )zê
    Mark a function for benchmarking. The benchmark can then be executed by using the :code:`.run` method on the return value.

    :param benchmarks: Benchmarking configurations.
    :type benchmarks: List of :class:`Benchmark`
    c                 ó   •— t        | ‰«      S r    )rž   r¡   s    €r   ú<lambda>zperf_report.<locals>.<lambda>�  s   ø€ œ˜b *Ó-€ r-   rœ   )r¢   Úwrappers   ` r   Úperf_reportrú   –  s   ø€ ó .€GØ€Nr-   c                 ó  — ddl }ddlm} | s|j                  j	                  «       } |j
                  j                  j                  | «      d   }|j
                  j                  j                  | «      d   }||z  dz  dz  d	z  }|S )
z return DRAM bandwidth in GB/s r   Nr   ©r]   Úmem_clock_rateÚmem_bus_widthr¯   g    €„.Aé   )rB   r	   r]   rC   Úcurrent_devicer^   ÚutilsÚget_device_properties)ÚdevicerB   r]   Úmem_clock_khzÚ	bus_widthÚbw_gbpss         r   Úget_dram_gbpsr  ¡  sz   € ãåÙØ—‘×*Ñ*Ó,ˆØ—M‘M×'Ñ'×=Ñ=¸fÓEÐFVÑW€MØ—‘×#Ñ#×9Ñ9¸&ÓAÀ/ÑR€IØ˜iÑ'¨!Ñ+¨cÑ1°AÑ5€GØ€Nr-   c                 óJ  — dd l }ddlm} |s|j                  j	                  «       }|j
                  j                  j                  |«      d   dz  }|j                  j                  |«      }|d   dk  r| |j                  k(  sJ ‚d}n�| |j                  |j                  fv rd}nr| |j                  |j                  |j                  fv rd}nJ| |j                  t        j                   t        j"                  t        j$                  fv rd	}nt'        d
«      ‚||z  |z  dz  }|S )Nr   r   rü   Úmultiprocessor_counté   rÿ   é   i   i   údtype not supportedç•Ö&è.>)rB   r	   r]   rC   r   r^   r  r  Úget_device_capabilityÚfloat16Úfloat32Úint32rw   Úint16Úint8ÚtlÚ
float8e4nvÚfloat8e4b15Úfloat8e5ÚRuntimeError©	rv   Ú
clock_rater  rB   r]   Únum_subcoresÚ
capabilityÚops_per_sub_coreÚtflopss	            r   Úget_max_tensorcore_tflopsr  ®  s  € ÛåÙØ—‘×*Ñ*Ó,ˆà—=‘=×&Ñ&×<Ñ<¸VÓDÐE[Ñ\Ð_`Ñ`€LØ—‘×1Ñ1°&Ó9€JØ�!�}�qÒØ˜Ÿ™Ò%Ð%Ð%ØÑà�U—]‘] E§K¡KÐ0Ñ0Ø"ÑØ�u—}‘} e§n¡n°e·k±kÐBÑBØ"ÑØ�u—z‘z¤2§=¡=´"·.±.Ä"Ç+Á+ÐNÑNØ#ÑäÐ4Ó5Ð5Ø˜JÑ&Ð)9Ñ9¸DÑ@€FØ€Mr-   c                  ó   ‡ — ˆ fd„}|S )Nc                 óF   •‡ — t        j                  ‰ «      ˆˆ fd„«       }|S )Nc                  ór  •— dd l }|j                  t        j                  «       «      j	                  «       }‰
j                  «       |j                  «       k  }|rÖ|dk7  rÑt        j                  j                  ‰j                  d   «      }t        j                  d   ddœ}d|v sJ d«       ‚|d   j                  j                  j                  }|› d	‰j                  › d
|› d�}t        j                  ddd|gd|¬«      }	|	j                   dk(  sJ d«       ‚dt#        |	j$                  «      v sJ ‚y  ‰| i |¤Ž y )Nr   zcuda-memcheckÚ__file__ÚPATHÚ1)r$  ÚPYTORCH_NO_CUDA_MEMORY_CACHINGÚrequestz@memcheck'ed test must have a (possibly unused) `request` fixturez::ú[ú]Úpytestz-vsT)Úcapture_outputÚenvz7cuda-memcheck returned an error: bounds checking failedzERROR SUMMARY: 0 errors)ÚpsutilÚProcessrµ   ÚgetppidÚnameÚitemsrÍ   ÚrealpathÚ__globals__ÚenvironÚnodeÚcallspecÚidr–   r   rô   Ú
returncoderš   r   )rŒ   rð   r-  Ú	ppid_nameÚrun_cuda_memcheckrÍ   r,  Útest_idr   r   Útarget_kwargsÚtest_fns             €€r   rù   z1cuda_memcheck.<locals>.decorator.<locals>.wrapperÏ  s!  ø€ ãØŸ™¤r§z¡z£|Ó4×9Ñ9Ó;ˆIØ -× 3Ñ 3Ó 5¸¿¹»Ñ GÐÙ  Y°/Ò%AÜ—w‘w×'Ñ'¨×(;Ñ(;¸JÑ(GÓH�ä!Ÿz™z¨&Ñ1ÐUXÑY�Ø  FÑ*ÐnÐ,nÓnÐ*Ø  Ñ+×0Ñ0×9Ñ9×<Ñ<�Ø˜˜b ×!1Ñ!1Ð 2°!°G°9¸AÐ>�Ü —n‘n o°xÀÈÐ%LÐ]aÐgjÔk�Ø—~‘~¨Ò*ÐeÐ,eÓeÐ*Ø0´C¸¿
¹
³OÑCÐCÑCá˜Ð( Ó(r-   )Ú	functoolsÚwraps)r=  rù   r<  s   ` €r   Ú	decoratorz cuda_memcheck.<locals>.decoratorÍ  s%   ù€ ä	�‰˜Ó	!ô	)ó 
"ð	)ð" ˆr-   rœ   )r<  r@  s   ` r   Úcuda_memcheckrA  Ë  s   ø€ ôð, Ðr-   c           	   #   ó¨  K  — 	 t        j                  g d¢«       t        j                  dddd| › d| › �g«       t        j                  dddd|› d|› �g«       t        dg«      d	   }t        d
g«      d	   }t        || z
  «      dk  sJ d| › d�«       ‚t        ||z
  «      dk  sJ d|› d�«       ‚d| z  }d|z  dz  }||f–— t        j                  g d¢«       t        j                  g d¢«       t        j                  g d¢«       y # t        j                  g d¢«       t        j                  g d¢«       t        j                  g d¢«       w xY w­w)N)r   r   r   ú-pmr%  r   r   r   z--lock-gpu-clocks=r   z--lock-memory-clocks=zclocks.current.smr   zclocks.current.memoryrA   zGPU SMs must run at z MHzgÞ 3ßÁOÌ?i   gü©ñÒMbP?)r   r   r   rC  r   )r   r   r   z-rgc)r   r   r   z-rmc)r   r   r   Úabs)Úref_sm_clockÚref_mem_clockÚcur_sm_clockÚcur_mem_clockr  Úgbpss         r   Úset_gpu_clockrJ  æ  sm  è ø€ ðCÜ×ÑÒ EÔFÜ×ÑØØØØ   ¨a°¨~Ð>ð	!
ô 	ô 	×ÑØØØØ# M ?°!°M°?ÐCð	!
ô 	ô Ð1Ð2Ó3°AÑ6ˆÜÐ6Ð7Ó8¸Ñ;ˆÜ�< ,Ñ.Ó/°"Ò4Ð_Ð8LÈ\ÈNÐZ^Ð6_Ó_Ð4Ü�= =Ñ0Ó1°BÒ6ÐbÐ:NÈ}ÈoÐ]aÐ8bÓbÐ6Ø)¨LÑ8ˆØ˜Ñ&¨Ñ-ˆØ�dˆlÒä×ÑÒ EÔFÜ×ÑÒ AÔBÜ×ÑÒ AÕBøô 	×ÑÒ EÔFÜ×ÑÒ AÔBÜ×ÑÒ AÕBüs   ‚E„B>D ÃAEÄAEÅEc                 óÔ  — dd l }ddlm} |s|j                  j	                  «       }|j
                  j                  j                  |«      d   dz  }|j                  j                  «       }|d   dk  r/| |j                  k(  rd}nW| |j                  k(  rd}nEt        d	«      ‚| |j                  k(  rd}n(| |j                  |j                  fv rd}nt        d	«      ‚||z  |z  d
z  }|S )Nr   r   rü   r	  r
  rÿ   é    é@   r  r  )rB   r	   r]   rC   r   r^   r  r  r  r  r  r  rw   r  s	            r   Úget_max_simd_tflopsrN    sä   € ÛåÙØ—‘×*Ñ*Ó,ˆà—=‘=×&Ñ&×<Ñ<¸VÓDÐE[Ñ\Ð_`Ñ`€LØ—‘×1Ñ1Ó3€JØ�!�}�qÒØ�E—M‘MÒ!Ø!ÑØ�e—m‘mÒ#Ø!ÑäÐ4Ó5Ð5à�E—M‘MÒ!Ø!ÑØ�u—}‘} e§n¡nÐ5Ñ5Ø!ÑäÐ4Ó5Ð5Ø˜JÑ&Ð)9Ñ9¸DÑ@€FØ€Mr-   )é   NNr5   )é   éd   NNr5   )NNr•   r    )iF  i¿  )r>  r"   rµ   r7   r   r   Ú
contextlibr   Útypingr   r   r   r•   r   r  r	   r   r0   r;   r[   rj   rƒ   r…   rž   rú   r  r  rA  rJ  rN  rœ   r-   r   ú<module>rT     s“   ðÛ Û Û 	Û Û Û 
Ý %ß "Ñ "Ý Ý òò(ò (ó$<Bó~?@óD0^÷f@ñ @÷F`ñ `òFó
óò:ð6 òCó ðCô8r-   