
    0Fie                        d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZmZ d dlmZ d dlmZ  G d de          Zd ZdS )    )annotationsN)dedent)without_property_validation)BasicTickerColumnDataSource	HoverToolNumeralTickFormatterOpenURLTapTool)figure)escape)format_bytes)DashboardComponentadd_periodic_callback)BOKEH_THEME
TICKS_1024)update)
log_errorsc                  0    e Zd ZdZddZed             ZdS )RMMMemoryUsagez
    GPU memory usage plot that includes information about memory
    managed by RMM. If an RMM pool is being used, shows the amount of
    pool memory utilized.
    X  c                ,   t                      5  d| _        || _        t          ddgddgddgddgddgddgdd	gddgddgdd	gd
d
gd          | _        t          d$ddt          |dz            dd|}|                    | j        dddddd          }d |_        |                    | j        dddddd          }d |_        |                    | j        dddddd          }d |_        t          d$i t          |j        d         _        t          d          |j        d         _        t           j         dz  |j        _        d|j        _        |fD ]l}d|j        _        d|j        _        d|j        _        t3          t5          d           !          }|                    |           d |_        d|j        _        mt;                      }d"|_        d#|_        |                    |           || _         d d d            d S # 1 swxY w Y   d S )%Nr         g      ?      g      @abz3RMM memory used: 1B/1B
Total GPU memory used: 1B/2B)rmm-usedrmm-used-half	rmm-totalrmm-total-halfexternal-usedexternal-used-xworker	gpu-indexyescaped_workerrmm_memory_textz
RMM Memory rmm_memory_histogram)titletoolswidthnamer    r'   r   z#76B900g      ?)sourcexr'   r.   heightcoloralphar"   r!   g      ?r$   r#   z0.0 b)format   Fz"./info/worker/@escaped_worker.html)url)callbackz@worker : @rmm_memory_textfollow_mouse )!r   last	schedulerr   r0   r   intrectnonselection_glyphr   r   axistickerr	   xaxis	formattermathpimajor_label_orientationx_rangestartminor_tick_line_alphayaxisvisibleygridr   r
   	add_toolstoolbar_locationr   tooltipspoint_policymemory_figure)	selfr<   r.   kwargsmemoryr>   figtaphovers	            Dlib/python3.11/site-packages/distributed/dashboard/components/rmm.py__init__zRMMMemoryUsage.__init__!   s   \\ V	( V	(DI&DN*!"A&)1X"#Q'(!f&'V()3x"Cj"#QQ'*CjNN(  DK&  "%!)nn+	 
  F ;;{!    D '+D#;;{"!   D '+D#;;{#%   D '+D#$/$=$=*$=$=FKN!(<G(L(L(LFLO%48G8b=FL0#$FN x * *23	/$)	!$)	!$)MNNN   c"""'+$$)	!!KKE9EN!/EU###!'DmV	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	( V	(s   G-H		HHc                   t                      5  t          | j        j                                                  }g }g }g }g }g }g }g }d}	g }
g }t          |          D ]\  }}	 |j        d         }|j        d         }|j        d         }n# t          $ r Y ;w xY w|d         }|d         }|d         }|d         }||z
  }|	                    |           |	                    |           |
	                    |           |	                    |           |	                    ||dz  z              |	                    |j
                   |	                    |           |	                    |           t          |	|          }	|	                    d	                    t          |          t          |          t          |          t          |                               t          d
                    t          t          |                    t          t          |                    t          t          g ||                    t          t          |
                                        | j        j        _        |||d |D             d |D             ||||d |D             |d}|	| j        j        _        t+          | j        |           d d d            d S # 1 swxY w Y   d S )Nr   rmmgpur!   r   zmemory-totalzmemory-usedr   z3RMM memory used: {}/{}
Total GPU memory used: {}/{}z]                RMM Utilization: {} / {}
                GPU Memory: {} / {}
                c                    g | ]}|d z  S r   r:   .0ms     rX   
<listcomp>z)RMMMemoryUsage.update.<locals>.<listcomp>   s    "="="=a16"="="=    c                    g | ]}|d z  S r^   r:   r_   s     rX   rb   z)RMMMemoryUsage.update.<locals>.<listcomp>   s    !;!;!;Q!q&!;!;!;rc   c                6    g | ]}t          j        |          S r:   )r   
url_escape)r`   ws     rX   rb   z)RMMMemoryUsage.update.<locals>.<listcomp>   s#    "H"H"HA6#4Q#7#7"H"H"Hrc   )r!   r   r#   r"   r    r$   r%   r&   r'   r(   r)   )r   listr<   workersvalues	enumeratemetricsextraKeyErrorappendaddressmaxr5   r   r   sumrQ   r,   textrG   endr   r0   )rR   ri   	rmm_totalrmm_usedexternal_used	gpu_indexr'   r%   external_used_x
memory_max	gpu_totalr)   idxwsrmm_metricsgpu_metricsgpu_informm_total_workerrmm_used_workergpu_total_workergpu_used_workerexternal_used_workerresults                          rX   r   zRMMMemoryUsage.updatez   s   \\ K	( K	(4>188::;;GIHMIAF OJI O$W--    R"$*U"3K"$*U"3K!xHH   H#.{#; "-j"9#+N#; "-m"<'69I'I$  !1222000  !1222$$%9:::&&'7:NQR:R'RSSSbj)))  %%% -=>>
&&JQQ$_55$%566$_55$%566	     -3 F X// Y00 %Ay%A=%A!B!BCC Y00	 	
- 
-D$) '$!."="=9"="="=!;!;(!;!;!;#2 &"H"H"H"H"H#2 F .8D&*4;'''WK	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	( K	(s7   AK%%'BK%
BK%BH>K%%K),K)N)r   )__name__
__module____qualname____doc__rY   r   r   r:   rc   rX   r   r      sX         W( W( W( W(r !L( L( ! L( L( L(rc   r   c                   t                      5  t          | d          }|                                 t          ||d           |                    |j                   t          |_        d d d            d S # 1 swxY w Y   d S )Nstretch_both)sizing_moded   )r   r   r   r   add_rootrQ   r   theme)r<   rm   docrmm_loads       rX   rmm_memory_docr      s    	    !)HHHc8S111X+,,,	                                   s   AA99A= A=) 
__future__r   rD   textwrapr   bokeh.core.propertiesr   bokeh.modelsr   r   r   r	   r
   r   bokeh.plottingr   tornador   
dask.utilsr    distributed.dashboard.componentsr   r   *distributed.dashboard.components.schedulerr   r   distributed.dashboard.utilsr   distributed.utilsr   r   r   r:   rc   rX   <module>r      sm   " " " " " "        = = = = = =                " ! ! ! ! !       # # # # # # V V V V V V V V N N N N N N N N . . . . . . ( ( ( ( ( (m( m( m( m( m(' m( m( m(`         rc   