
    &Vji@e                     	   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Zd dlZd dlZd dl	m
Z
 d dlmZ d dlmZ  e
d          Zg dZdMdZed             ZdNd	Zd
 Zd ZdOdZd ZefdZefdZefdZd Z G d d          Zd Zd ZdZd ee           dZ d Z!d Z"dZ#d Z$dPdZ%d Z&dOdZ'dOd efd!Z(e)d"k    rd dl*Zej+        ,                    ej+        -                    e.                    Z/e/ej+        v rej+        0                    e/           d dl1Z1d#Z2d$e2 Z3 e1j4        d%e2 &          Z5e56                    d'(          Z7d) Z8d*Z9e7:                    d+e9&          Z;e;<                    d,e3-           d.Z9e7:                    d/e9&          Z=e=<                    d,e3-           d0Z9e7:                    d1e9&          Z>e><                    d,e3-            e8e>           d2Z9e7:                    d3e9&          Z?e?<                    d,e3-            e8e?           d4Z9e7:                    d5e9&          Z@e@<                    d6e3-           e@<                    d7e3-            e8e@           d8ZAeAD ]\  ZBZ9e7:                    eBe9&          ZCeC<                    d,e3-           d9ZDeC<                    d:d;eEdeD<           d=ZDeC<                    d>d?d@eDA           eBdBk    rdCZDeC<                    dDdEdFeDG           e5F                                ZGdH ZHdI ZIeGjJ        d1k    r, eHeGjK                  ZL eIeGjM         eeL                     dS eGjJ        d3k    r, eHeGjK                  ZL eIeGjM         eeL                     dS eGjJ        d+k    r& eHeGjK                  ZL eN e!eL                     dS eGjJ        d/k    r& eHeGjK                  ZL eN e"eL                     dS eGjJ        d5k    r= eHeGjO                  ZO eHeGjP                  ZP eIeGjM         eeOeP                     dS eGjJ        dBk    r9 eHeGjK                  ZL eIeGjM         e%eLeGjQ        eGj        J                     dS eGjJ        dKk    r5 eHeGjK                  ZL eIeGjM         e(eLeGjQ        L                     dS dS dS )Q    N)	lru_cache)groupby)Any)format_flamegraphsegmentsmemorycompareFc                     | d         }| d         }|s|                     d          d         }| d         }| d| d| S )Nlinefilename/name:)split)ffull_filenameifnamefuncs        P/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/cuda/_memory_viz.py
_frame_fmtr      sW    	&	AjME %C  $V9D  a  $       c                 F    g d}g d}|D ]	}|| v r dS 
|D ]	}||v r dS 
dS )N)zunwind::unwindzCapturedTraceback::gathergather_with_cpp_start__libc_start_mainPyEval_	PyObject_PyFunction_)
zcore/boxingz	/Registerz/Redispatchzpythonrun.czModules/main.czObjects/call.czObjects/methodobject.czpycore_ceval.hzceval.czcpython/abstract.hFT )r   r   omit_functionsomit_filenamesofs        r   _frame_filterr%      ss    	 	 	N  N   ::55   >>55 4r   c                 B    |rt          |           } fd| D             S )Nc                 h    g | ].}t          |d          |d                   t          |          /S )r   r   )r%   r   ).0r   r   s     r   
<listcomp>z_frames_fmt.<locals>.<listcomp>B   sK       6AjM221m$$  r   )reversed)framesr   reverses    ` r   _frames_fmtr-   ?   sC     "&!!      r   c                     d| v r7| d         d                              dg           }| d         d         d         }n|                      d| d                   }g }||fS )Nhistoryr   r+   	real_sizerequested_sizesize)get)br+   r0   s      r   _block_extra_legacyr5   I   sd    A~~9a$$Xr22iLOK0		EE*AfI66	9r   c                 H    d| vrt          |           S | d         | d         fS )Nr+   r1   )r5   )r4   s    r   _block_extrar7   S   s0    q"1%%%X;*+++r   c                    |:t           j                            d          }t          j        |d           | d}t           j                            |          sdd l}dd l}t          d|            |                    dd	          5 }|j	        
                    d
|j                   	 t          j        |j        d           t          j        |j        |           n# t          $ r Y nw xY wd d d            n# 1 swxY w Y   |ddg}t          j        |t          j        t          j        d          }|j        J |j        J |j                            |            |j                                         |j                                        }|j                                         |                                 |                                dk    sJ |S )Nz	~/.cache/T)exist_okz/flamegraph.plr   zDownloading flamegraph.pl to: wbz.pl)modesuffixzNhttps://raw.githubusercontent.com/brendangregg/FlameGraph/master/flamegraph.pli  z--countnamebytesutf-8)stdinstdoutencoding)ospath
expandusermakedirsexiststempfileurllib.requestprintNamedTemporaryFilerequesturlretriever   chmodrenameOSError
subprocessPopenPIPEr?   r@   writeclosereadwait)	flamegraph_linesflamegraph_script	cache_dirrG   urllibr   argspresults	            r   r   r   Z   s    G&&{33	
I----(8887>>+,, B/@BBCCC((d5(AA 
	QN&&`  '''	!&"34444   
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 }g6DJOJOg	 	 	A 78GMM"###GMMOOOX]]__FHNNFFHHH6688q====Ms6   !D /4C$#D $
C1.D 0C11D  DDc                    d }|D ]}d|vrCt          |          \  }}|                     | d|d          d ||           d| d           n{d}|d         D ]p}|d         }||z  }d	|v r9|d	         }|                     | d|d          d ||           d| d           L|                     | d|d          d
| d           q|d         |z
  }	|	r$|                     | d|d          d|	 d           d S )Nc                 R    | sdS d                     t          | d                    S )Nz<non-python>;T)r,   )joinr-   )r+   s    r   frames_fragmentz&_write_blocks.<locals>.frames_fragment   s.     	"!>xxFD999:::r   r/   r`   state 
r   r0   r+   z;<no-context> r2   z;<gaps> )r7   rS   )
r   prefixblocksrb   r4   r+   accounted_for_sizehszgapss
             r   _write_blocksrl   ~   s   ; ; ;
  > >A)5a&F&GGYYAgJYY)@)@YYCUYYY    "#y\ J J{^"b("q==x[FGGvUU'
UU__V5L5LUUrUUUVVVVGGvHH'
HH"HHHIIIIy-- 	>GGv<<'
<<D<<<===%> >r   c                     t          j                    }| d         D ]-}d|d          d|d          }t          |||d                    . ||                                          S )Nr   stream_stream;seg_addressrg   ioStringIOrl   getvaluesnapshotr   r   segrf   s        r   r   r      sp    
A
# 0 0?3x=??s9~??aX////QZZ\\***r   c                     t          j                    }| d         D ]$}d|d          }t          |||d                    % ||                                          S )Nr   rn   ro   rg   rr   rv   s        r   r   r      sd    
A
# 0 0*3x=**aX////QZZ\\***r   c                    d d }t          j                    }fd| D             }fd|D             }t          dd ||z
  D                         t          dd ||z
  D                         | D ]2} |          |vr#t          |d	 ||           |d
                    3|D ]2} |          |vr#t          |d ||           |d
                    3 ||                                          S )Nc                 "    | d         | d         fS )Nrq   
total_sizer!   rx   s    r   _seg_keyzcompare.<locals>._seg_key   s    IL 122r   c                 *    d| d          d| d          S )Nrn   ro   rp   rq   r!   r}   s    r   	_seg_infozcompare.<locals>._seg_info   s     =X==S^===r   c                 &    h | ]} |          S r!   r!   r(   rx   r~   s     r   	<setcomp>zcompare.<locals>.<setcomp>   s!    333S88C==333r   c                 &    h | ]} |          S r!   r!   r   s     r   r   zcompare.<locals>.<setcomp>   s!    111C((3--111r   zonly_before = c                     g | ]\  }}|S r!   r!   r(   a_s      r   r)   zcompare.<locals>.<listcomp>   s    EEE$!QAEEEr   zonly_after = c                     g | ]\  }}|S r!   r!   r   s      r   r)   zcompare.<locals>.<listcomp>   s    DDDA1DDDr   zonly_before;rg   zonly_after;)rs   rt   rI   rl   ru   )	beforeafterr   r   r   before_segs
after_segsrx   r~   s	           @r   r	   r	      sg   3 3 3> > > 	A3333F333K11115111J	
GEE;+CEEE
G
GHHH	
FDD*{*BDDD
F
FGGG M M8C==
**!<IIcNN<<c(mLLL L L8C==++!;99S>>;;S]KKKQZZ\\***r   c                 \    dD ]$}t          |           dk     r
| d| dc S | dz  } %| ddS )N) KiMiGiTiPiEiZig      @z3.1fB.1fYiB)abs)numunits     r   _format_sizer      sX    >  s88f''''''''v????r   c                        e Zd Zd Zd Zd ZdS )Bytesc                     || _         d S N)value)selfr   s     r   __init__zBytes.__init__   s    


r   c                 0    t          | j        |z             S r   )r   r   )r   rhss     r   __add__zBytes.__add__   s    TZ#%&&&r   c                 *    t          | j                  S r   )r   r   )r   s    r   __repr__zBytes.__repr__   s    DJ'''r   N)__name__
__module____qualname__r   r   r   r!   r   r   r   r      sA          ' ' '( ( ( ( (r   r   c                 @    t          d | d         D                       S )Nc              3   >   K   | ]}|d          dk    |d         V  dS )rc   active_allocatedr2   Nr!   )r(   r4   s     r   	<genexpr>zcalc_active.<locals>.<genexpr>   s5      TTQ1W:AS3S3Sqy3S3S3S3STTr   rg   )sumr}   s    r   calc_activer      s#    TT#h-TTTTTTr   c                 `    | |z   }d}|dk    r||z  dz  }d|dd}t          |           | S )Nr   r   d   z (r   z% internal))r   )free_externalfree_internaltotalr<   pcts        r   _report_freer      sS    M)EFzzu$+*c****Ell$F$$$r   i  @zC
Legend:
    [a     ] - a segment in the allocator
     ^-- a page aU   of memory in the segment
    a-z: pages filled with a single block's content
    ' ': page is completely free
    *: page if completely full with multiple blocks
    0-9: page is partially full with tensors of multiple blocks (9 == 90% full)
    (X% internal) - of the free memory, X% is free because we rounded the size of the allocation.
c                    t          j                    }|                    dt          t                     d           d}d}d}d}t          | d         d           D ]}||d         z  }d}d}d}	g }
d}|d         D ]d}|d	         d
k    }|r>t          |          \  }}|
                    ||df           |	|z  }	||d         |z
  z  }n||d         z  }||d         z  }e||	z  }||z  }||z  }|d         dz
  t          z  dz   }d t          |          D             }d t          |          D             }d}t          |
          D ]\  }\  }}}||z  }||z   }|t          z  }|dz
  t          z  dz   }t          t          |rdnd          |dz  z             }t          ||          D ]}t          ||t          z            }t          ||dz   t          z            }||xx         ||z
  t          z  z  cc<   ||         dk    r"dt          ||         dz                     ||<   ~|||<   |d         dk    rdn
d|d          }d                    |          }||z   |	z   |d         k    sJ |d         dk    rd|d          nd}|d         t          k    rC|                    d| dt          |d                    dt!          ||           d| d	           |                    dt#          | d                    d           |                    d t          |           d           |                    d!t          |           d           |                    d"t!          ||           d           |                    t$                     ||z   |z   |k    sJ |                                S )#a  Visually reports how the allocator has filled its segments.

    This printout can help debug fragmentation issues since free fragments
    will appear as gaps in this printout.  The amount of free space is reported
    for each segment.
    We distinguish between internal free memory which occurs because the
    allocator rounds the allocation size, and external free memory, which are
    the gaps between allocations in a segment.
    Args:
        data: snapshot dictionary created from _snapshot()
    zSummary of segments >= z	 in size
r   r   c                 0    | d         t          |           fS )Nr|   )r   )xs    r   <lambda>zsegsum.<locals>.<lambda>  s    <+a..(I r   keyr|   rg   rc   r   Tr2      c                     g | ]}d S )rd   r!   r(   r   s     r   r)   zsegsum.<locals>.<listcomp>  s    ---AC---r   c                     g | ]}d S )g        r!   r   s     r   r)   zsegsum.<locals>.<listcomp>   s    ))))))r   r   A   rd   z0123456789*
   ro   r   z	, stream_z stream_[z] z allocated, z freere   z
segments: ztotal_reserved: ztotal_allocated: ztotal_free: )rs   rt   rS   r   	PAGE_SIZEsortedr7   appendrange	enumeratechrordmaxminintra   r   lenlegendru   ) dataouttotal_reservedtotal_allocatedr   r   rx   seg_free_externalseg_free_internalseg_allocated
all_rangesboffsetr4   activer   allocated_sizensegoccupiedfracactive_sizer   start_r2   finish_startfinishmjsero   bodys                                    r   segsumr      s    +--CIIDi(8(8DDDEEENOMMZII   6 6 	#l++
X 
	! 
	!AwZ#55F /$0OO!>!!7ND"ABBB/!QvY%??!!!QvY.!qy GG=(****L!A%)3a7--t---))U4[[))))2:)>)> 	$ 	$%A%f4KtmGi'Eki/!3FCv.3//1r6:;;A5&)) $ $I..!a%9!455QAEY..A;#%%"/DGbL0A0A"BHQKK"#HQKK$ 8}))/J3x=/J/Jwwx   11MASEVVVVV/28}/A/A+CM+++r|	))IIWD W WE#l"344 W W 13DEEW WLRW W W   II43tJ/00444555II:~!6!6:::;;;II<%"8"8<<<===IIK\-GGKKKLLLIIf=(?:nLLLL<<>>r   c                      t          j                     fd}t           d                   D ]+\  }}|r$                    d| d            ||           ,                                S )Nc                    g i }i }g dfd}fd}d}                     t          |            d           d}d         D ]}||d         z  }t          |           D ]\  }}|d         dk    rp|d	         |d
         }
}	 |            } ||	          \  }}|d}|	}n|	|z
  }                     | d| d| dt          |
           d           ||
|f||	<   ||
z  }|d         dk    rW|d	         |d
         }
}	|                    |	|	d d f          \  }}}                     d| dt          |
           d           |d         dk    ry|d	         |d
         }
}	||
z  }|                    |	|	d d f          \  }}}                     d| dt          |
           d           ||v r                    |           ||= j|d         dk    rd|d	         |d
         }
}	 |            }                     | d|	 dt          |
           d                               ||	|
f           |||	<   |d         dk    rm|d	         |d
         }
}	|                    |	|	          }                     d| dt          |
           d           ||v r                    |           ||= S|d         dk    rH|d
         }
|d         }                     d t          |
           d!t          |           d"                                | d                                d#t          |                      d S )$Nr   c                      r                                 S dz  dz  }} dz  t          t          d          |z              | dk    rdn|  S )Nr   r   r   r   r   )popr   r   )rr   
free_names	next_names     r   _namez$trace.<locals>.format.<locals>._nameO  sd     (!~~'''?INqANI#c((Q,''>qAvv1>>>r   c                     D ]\  }}}| |k    r| ||z   k     r||fc S t          d                   D ]-\  }}|d         }|d         }| |k    r| ||z   k     r	d| |fc S .dS )Nr   rq   r   seg_)NN)r   )addrr   saddrr2   r   rx   r   segment_intervalss         r   find_segmentz+trace.<locals>.format.<locals>.find_segmentW  s    %6 ' '!eT5==TEDL%8%8;&&&#D$455 - -3I+,5==TEDL%8%8%!::u,,,,:r   z	 entries
r   r|   actionallocr   r2   MEMz = r   r   z]
free_requestedzdel z # re   free_completedz# free completed for rd   segment_allocz = cudaMalloc(z, z)
segment_freez	cudaFree(z) # oomdevice_freezraise OutOfMemoryError # z requested, z free in CUDA
zTOTAL MEM: )rS   r   r   r   r3   r   )entriessegment_addr_to_nameallocation_addr_to_namer   r   countr   rx   r   r   r2   nseg_nameseg_addroffsetr   r   freer   r   r   r   r   s                     @@@r   formatztrace.<locals>.formatG  s@   "$!"$
		? 	? 	? 	? 	? 	?		 		 		 		 		 		 		S\\---...
# 	0 	0Cc,//NN!'** -	$ -	$HE1{g%%vY&	dEGG%1\$%7%7"(#$H!FF!H_F		QGG8GGfGGuT{{GGGHHH12D%0@'-8 000vY&	d488dD?QRR
a		999%++999::::8 000vY&	d488dD?QRR
a		H$HHtHHHIII222%%d+++/58//vY&	duww		TIIIItIIIJJJ!(($d);<<<-1$T**8..vY&	d+//d;;		?d??d???@@@///%%d+++,T28%%y'		edeeteee    		Q(((####		.e../////r   device_traceszDevice z ----------------
)rs   rt   r   rS   ru   )r   r  r   dr   s   `   @r   tracer  D  s    
+--CP0 P0 P0 P0 P0 P0d $/00  1 	II6666777F1III<<>>r   a  
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="module">
import {add_local_files} from "https://cdn.jsdelivr.net/gh/pytorch/pytorch@main/torch/utils/viz/MemoryViz.js"
const local_files = $SNAPSHOT
add_local_files(local_files, $VIZ_KIND)
</script>
</body>
c                    |t          j        dt          d           t          j        |           }|ddt          |          dz  z
  z  z  }t          j        |                              d          }t          j        d|dg          }t                              dt          |                                        d	|          S )
Nz;device argument is deprecated, plots now contain all device   )
stacklevel    r>   zsnapshot.pickle)r   base64z	$VIZ_KINDz	$SNAPSHOT)warningswarnFutureWarningpickledumpsr   r  	b64encodedecodejson_memory_viz_templatereplacerepr)r   viz_kinddevicebufferencoded_bufferjson_formats         r   _format_vizr&    s    I	
 	
 	
 	

 \$F
gS[[1_,--F%f--44W==N*'8NSSTUUK''T(^^DDLL[  r   c                 ,    t          | |sdnd|          S )a  Generate a visualization over time of the memory usage recorded by the trace as an html file.

    Args:
        data: Memory snapshot as generated from torch.cuda.memory._snapshot()
        device (torch.device, optional): Generate the trace for this device, needed if multiple devices have allocations.
        plot_segments (bool, optional): Plots memory returned from cudaMalloc, rather than individual allocations.
                                        Defaults to False.

    Returns:
        str: HTML of visualization
    Active Memory TimelinezActive Cached Memory Timeliner&  )r   r"  plot_segmentss      r   
trace_plotr+    s-     	-  ,  r   c           	         dd l }ddlm} ddlm}m} |                                 i j        j        D ]}|j	        |j
        k    ro|j        }g }|r3|j	        |j        |j        fv r|                    |           |j        }|3|                    |j                  }|r|j        j        dk    r||<   |j                                        d t)          dz             D             d t)          dz             D             dfddfd
	}	fd}
i }j        D ]\  }}\  }}}t-          ||          s||j        k    r |	|||          |||f<   9||j        k    r0 |
|                    ||f           |j                             t||j        k    rH |
|                    ||f           |j                              |	|||dz             |||dz   f<   ||j        k    r |	|||d          |||f<   fd|                                D             }t=          t?          |          tA          j!        d                    D ]\  }}d         |         }|d         }|D ]S\  }}}}||k     r!|d                             ||z
  dd           |d                             |d||d           ||z   }T||d         k     r'|d                             |d         |z
  dd           d d         D             d<   d         D ]D}|dxx         |d         z  cc<   |d         s$|d                             |d         dd           ES )Nr   )
_EventType)Action	TensorKeyc                     g | ]}g S r!   r!   r   s     r   r)   z(_profile_to_snapshot.<locals>.<listcomp>  s    >>>">>>r   r   c                     g | ]
}|d ddg dS )Nr   )r"  rq   r|   ro   rg   r!   )r(   r"  s     r   r)   z(_profile_to_snapshot.<locals>.<listcomp>  s@     	
 	
 	
  ! 	
 	
 	
r   )r  r   c                 ,    | j         dk    r| j        S S )Ncuda)typeindex)r"  device_counts    r   	to_devicez'_profile_to_snapshot.<locals>.to_device  s    ;&  <r   Tc                     |j                   }|j        j        }d         |         }|d         |d         |k    r||d<   t          |d         || z             |d<   j                            ||          }||j                                        nd}
                    |d          }d |D             }d|| d||d	}	|r!d
         |                             |	           |	S )Nr   rq   r|   unknownr!   c                 $    g | ]}d d|j         dS )noner   )r   r   r   )r   )r(   r\   s     r   r)   z:_profile_to_snapshot.<locals>.allocate.<locals>.<listcomp>  s$    PPPQfa@@PPPr   r   r   )r   r   r2   ro   r+   categoryr  )	r"  storageptrr   _categoriesr3   r   lowerr   )r2   
tensor_keyversionduring_tracer"  r   rx   r<  stackr   allocation_stacksmemory_profilerw   r7  s             r   allocatez&_profile_to_snapshot.<locals>.allocate  s   :,--!%z"6*y>!S^d%:%:!C	Ntd{
 
L "-11*gFF,4,@8=&&(((i!%%j"55PP%PPP 
 
  	8_%f-44Q777r   c           	          dD ];}d         |                              || d         | d         d| d         d           <d S )N)r   r   r  r   r2   r   r+   )r   r   r2   ro   r+   )r   )r   r"  r   rw   s      r   r  z"_profile_to_snapshot.<locals>.free  sh    5 		 		A_%f-44!&M!&M#Ho    		 		r   F)rC  c                 h    g | ].\  \  }}} |j                   |d          |d         |d         f/S )r   r2   r+   r"  )r(   rA  rB  eventr7  s       r   r)   z(_profile_to_snapshot.<locals>.<listcomp>=  sT       (!Z5 
:$	%	%uV}eFmU8_U  r   r   r   rq   rg   inactive)r2   rc   r   )r2   rc   r1   r+   r|   c                 "    g | ]}|d          
|S )rg   r!   )r(   rx   s     r   r)   z(_profile_to_snapshot.<locals>.<listcomp>U  s!    QQQC3x=QCQQQr   )T)"torchtorch._C._profilerr-  torch.profiler._memory_profilerr.  r/  _memory_profile_op_treesorted_nodestag
AllocationparentPyCallPyCCallr   from_allocationextra_fields
alloc_sizer3  r6  r   timeline
isinstanceCREATEDESTROYr   r"  INCREMENT_VERSIONPREEXISTINGitemsr   r   operator
itemgetter)profilerN  r-  r.  r/  rK  rV  python_parentsr   rG  r  
kv_to_elem_timer   rA  rB  r2   blocks_at_endr"  rg   rx   	last_addrr   r   r+   rE  r6  rF  rw   r7  s                            @@@@@r   _profile_to_snapshotrk    s   LLL------AAAAAAAA,,..N(5 8 89
---\FN ':*"3Z5G!HHH"))&111  ' ++E,>??C  8u)4q88)7!#&:**,,L>>eL1,<&=&=>>>	
 	
  q 011	
 	
 	
& &H                 4
 
 
 
 
 J 7E6M  2v,
Gd*i00 	V]""08z70S0SJ
G,--v~%%DW 566		*BS8T8TUUUUv///DW 566		*BS8T8TUUU4<Hj'A+5 5J
GaK011 v)))08j'1 1 1J
G,-
   ,6,<,<,>,>  M "&"7"7X=PQR=S=STTT  z"6*	N	%+ 	$ 	$!AtT64H$$dY.>%T%TUUUM   /&*$	    tIIs<(((M  \*Y6LL   RQ8J+?QQQHZ
# S SLS^+8} 	SM  #l*;j!Q!QRRROr   c                 B    t          |           }t          |d|          S )a}  Generate a visualization over time of the memory usage recorded by kineto memory profiling as an html file.

    Args:
        profile: profile as generated by `torch.profiler.profile(profile_memory=True)`
        device (torch.device, optional): Generate the trace for this device, needed if multiple devices have allocations.

    Returns:
        str: HTML of visualization
    r(  )rk  r&  )re  r"  rw   s      r   profile_plotrm  ^  s$     $G,,Hx!96BBBr   r   c                 $    t          | d|          S )NzAllocator State Historyr)  )r   r"  s     r   segment_plotro  l  s    t6???r   __main__ztorch.cuda.memory._snapshot()zpickled memory statistics from z#Visualize memory dumps produced by )descriptionr   )destc                 8    |                      dddd           d S )N-o--outputz
output.svgz$flamegraph svg (default: output.svg)defaulthelp)add_argument)r\   s    r   _outputrz    s3    	 7	 	 	
 	
 	
 	
 	
r   zmPrints overall allocation statistics and a visualization of how the allocators segments are currently filled.statsinput)rx  z`Prints buffer of the most recent allocation events embedded in the snapshot in a Pythonic style.r  zaGenerate a flamegraph that visualizes what memory is stored in each allocator segment (aka block)r   zNGenerate a flamegraph the program locations contributing to CUDA memory usage.r   zGenerate a flamegraph that shows segments (aka blocks) that have been added or removed between two different memorys snapshots.r	   r   r   ))r+  z]Generate a visualization over time of the memory usage recorded by the trace as an html file.)ro  zfVisualize how allocations are packed into allocator segments at each point in a trace as an html file.z]visualize trace from this device (default: chooses the only device with trace info or errors)z-dz--device)r4  rw  rx  z4path to save the visualization(default: output.html)rt  ru  zoutput.htmlrv  r+  z?visualize change to segments rather than individual allocationsz-sz
--segments
store_true)r   rx  c                     | dk    rt           j        j        }nt          | d          }t	          j        |          }t          |t                    r|g d}|S )N-rb)r   traces)sysr?   r#  openr  loadr]  list)r   r   r   s      r   _readr    sW    3;;	 AAT4  A{1~~dD!! 	4 $33Dr   c                     t          | d          5 }|                    |           d d d            d S # 1 swxY w Y   d S )Nw)r  rS   )r   r   r   s      r   _writer    s    $__ 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   488)r"  r*  ro  rJ  )F)FFr   )NF)Rr  rs   r  rc  rB   r  rP   r  r  	functoolsr   	itertoolsr   typingr   cache__all__r   r%   r-   r5   r7   r   rl   r   r   r	   r   r   r   r   r   r   r   r  r  r&  r+  rk  rm  ro  r   os.pathrC   realpathdirname__file__thedirremoveargparsefn_namepickledArgumentParserparseradd_subparsers
subparsersrz  rq  
add_parserstats_ary  trace_a
segments_amemory_a	compare_aplotscmdtrace_plot_arx  r   
parse_argsr[   r  r  r   r|  r   outputrI   r   r   r"  r!   r   r   <module>r     s    				   				      



                    		$
@
@
@! ! ! !   @     , , ,! ! ! !H> > >6 *; + + + + (9 + + + + .? + + + +4  ( ( ( ( ( ( ( (U U U% % % 	

 y!!	

 

 

O O OdY Y Yx   $   *E E EPC C C C@ @s @ @ @ @ zNNNWbgooh7788FOOO-G999G$X$C'CC  F &&H&55J
 
 
 BK##G#EEGw///tK##G#EEGw///uK&&z{&KKJG'222GJ 	Y  $$X;$GGH'000GH	>  %%i[%III8'2227111GI	E "  [!,,Sk,JJ!!'!888n!!$
dQU!VVVE!!$
MPT!UUU,TD%%l<d &    D     {j  uTZ  t{HHTNN+++++		 	 uTZ  t{FF4LL)))))			uTZ  ffTll			uTZ  eeDkk			!	!t{##dj!!t{GGFE2233333		$	$uTZ  KJtDKt}MMM	
 	
 	
 	
 	
 
	&	&uTZ  t{LLdkBBBCCCCCk f 
'	&r   