
    JTh                         S SK r S SKr/ SQrSS\S\SS4S jjrS r\ R                  SS\S\4S jj5       rS\4S	 jr	S\4S
 jr
\ R                  S\4S j5       rg)    N)startstopprofilemetal_captureis_metal_capture_enabledis_capturing_metalmodewait_until_completedreturnc                     U R                  5       R                  SS5      n[        R                  R	                  X!5        g)aE  Start OS Signpost tracing from MPS backend.

The generated OS Signposts could be recorded and viewed in
XCode Instruments Logging tool.

Args:
    mode(str): OS Signpost tracing mode could be "interval", "event",
        or both "interval,event".
        The interval mode traces the duration of execution of the operations,
        whereas event mode marks the completion of executions.
        See document `Recording Performance Data`_ for more info.
    wait_until_completed(bool): Waits until the MPS Stream complete
        executing each encoded GPU operation. This helps generating single
        dispatches on the trace's timeline.
        Note that enabling this option would affect the performance negatively.

.. _Recording Performance Data:
   https://developer.apple.com/documentation/os/logging/recording_performance_data
  N)lowerreplacetorch_C_mps_profilerStartTrace)r	   r
   mode_normalizeds      J/var/www/auris/envauris/lib/python3.13/site-packages/torch/mps/profiler.pyr   r      s.    ( jjl**33O	HH$$_K    c                  @    [         R                  R                  5         g)z6Stops generating OS Signpost tracing from MPS backend.N)r   r   _mps_profilerStopTrace r   r   r   r   )   s    	HH##%r   c              #   ^   #     [        X5        Sv   [        5         g! [        5         f = f7f)a
  Context Manager to enabling generating OS Signpost tracing from MPS backend.

Args:
    mode(str): OS Signpost tracing mode could be "interval", "event",
        or both "interval,event".
        The interval mode traces the duration of execution of the operations,
        whereas event mode marks the completion of executions.
        See document `Recording Performance Data`_ for more info.
    wait_until_completed(bool): Waits until the MPS Stream complete
        executing each encoded GPU operation. This helps generating single
        dispatches on the trace's timeline.
        Note that enabling this option would affect the performance negatively.

.. _Recording Performance Data:
   https://developer.apple.com/documentation/os/logging/recording_performance_data
N)r   r   )r	   r
   s     r   r   r   .   s     $d)s   - -*-c                  >    [         R                  R                  5       $ )zlChecks if `metal_capture` context manager is usable
To enable metal capture, set MTL_CAPTURE_ENABLED envvar
)r   r   _mps_isCaptureEnabledr   r   r   r   r   G   s     88))++r   c                  >    [         R                  R                  5       $ )z%Cheks if metal capture is in progress)r   r   _mps_isCapturingr   r   r   r   r   N   s    88$$&&r   fnamec              #     #     [         R                  R                  U 5        Sv   [         R                  R	                  5         [         R                  R                  5         g! [         R                  R                  5         f = f7f)zBConext manager that enables capturing of Metal calls into gputraceN)r   r   _mps_startCapturempssynchronize_mps_stopCapture)r   s    r   r   r   S   sO     $""5)		!!#!!#s   BAA$ B$ BB)intervalF)
contextlibr   __all__strboolr   r   contextmanagerr   r   r   r   r   r   r   <module>r+      s     L L L L0&
 # $  0,$ ,'D '
 $ $ $r   