+
    &j_                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
Ht ^ RIHtHt ^ RIHtHt ^ RIt^ RIHu Ht ^ RIHt ^ RIHt ]P8                  P:                  t^ t]! R4      t]! R4      t ]! R	4      t!]"t#]"t$]"t%]"t&]PN                  ! ](4      t)]PT                  ! R
4      t+ ! R R]PX                  4      t-] ! R R4      4       t. ! R R]/4      t0 ! R R]04      t1 ! R R]/4      t2] ! R R4      4       t3 ! R R4      t4 ! R R4      t5 ! R R4      t6R R lt7R R  lt8 ! R! R"4      t9 ! R# R$]4      t: ! R% R&4      t;R' t<];! 4       t=R# )(a  
This module introduces CUDA Sanitizer, a tool for detecting synchronization errors between kernels ran on different streams.

It stores information on accesses to tensors to determine if they are synchronized
or not. When enabled in a python program and a possible data race is detected, a
detailed warning will be printed and the program will exit.

It can be enabled either by importing this module and calling
:func:`enable_cuda_sanitizer()` or by exporting the ``TORCH_CUDA_SANITIZER``
environment variable.
N)Iterator)	dataclassfield)AnyTypeVar)_pytree)TorchDispatchModeTKTVaTVbz(new_.*|.*_like)c                   j   a  ] tR t^5t o ]P
                  ! 4       t]P
                  ! 4       tR tRt	V t
R# )
AccessTypec                2    V \         P                  J d   R # R# )zreading fromz
writing to)r   READselfs   &m/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/torch/cuda/_sanitizer.py__str__AccessType.__str__9   s    !%!8~JlJ     N)__name__
__module____qualname____firstlineno__enumautor   WRITEr   __static_attributes____classdictcell____classdict__s   @r   r   r   5   s'     99;DIIKEK Kr   r   c                   0   a  ] tR t^=t o RtV 3R ltRtV tR# )Accessa/  Stores information about a single access to a tensor by a kernel.

Args:
    type: either AccessType.READ or AccessType.Write.
    seq_num: the sequential number of the kernel performing the access.
    stream: the stream id of the stream executing the kernel.
    operator: the schema of the launched kernel, which lists the
        arguments and return type.
    aliases: the arguments in the schema this access corresponds to.
    is_output: Whether the tensor was an output of the kernel.
    stack_trace: the stack summary object captured during access.
c                   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   S[S[,          ;R&   S[;R&   S[P                  ;R&   # )   typeseq_numstreamoperatoraliases	is_outputstack_trace)r   SeqNumStreamIdstrlistbool	tracebackStackSummary)formatr!   s   "r   __annotate__Access.__annotate__=   sg         O! " # $ M% & #Y' ( O) * '''+ r   r   N)r   r   r   r   __doc____annotate_func__r   r   r    s   @r   r#   r#   =   s       r   r#   c                       ] tR t^UtRtRtR# )SynchronizationErrorz1Base class for errors detected by CUDA Sanitizer.r   N)r   r   r   r   r7   r   r   r   r   r:   r:   U   s    ;r   r:   c                   <   a  ] tR t^Yt o RtV 3R lR ltR tRtV tR# )UnsynchronizedAccessErrorzIStores information about two unsynchronized accesses to one data pointer.c                T   < V ^8  d   QhRS[ RS[P                  R,          RS[RS[/# )r%   data_ptrallocation_stack_traceNcurrent_accessprevious_access)DataPtrr2   r3   r#   )r4   r!   s   "r   r5   &UnsynchronizedAccessError.__annotate__\   s>     
/ 
/
/ !* 6 6 =
/ 	
/
  
/r   c                6    Wn         W n        W0n        W@n        R # N)r>   r?   r@   rA   )r   r>   r?   r@   rA   s   &&&&&r   __init__"UnsynchronizedAccessError.__init__\   s     !&<#,.r   c                  a R  V3R llp\         P                  ! 4       ;_uu_ 4       oSP                  \        P                  ! RV P
                   RV P                  P                   R24      4       V! V P                  4       SP                  RV P                  P                   R24       V! V P                  4       V P                  '       d=   SP                  RRP                  V P                  P                  4       4       24       MSP                  R	4       SP                  4       uuR
R
R
4       #   + '       g   i     R
# ; i)c                $    V ^8  d   QhR\         /# )r%   access)r#   )r4   s   "r   r5   7UnsynchronizedAccessError.__str__.<locals>.__annotate__i   s     
	 
	& 
	r   c                   < SP                  V P                   R V P                   24       V P                  '       dU   SP                  RRP	                  V P                  4      ,           4       V P
                  '       d   SP                  R4       V P
                  '       d   SP                  R4       SP                  RRP	                  V P                  P                  4       4       R 24       R# )
z argument(s) z, z, and toz the outputz
With stack trace:
 N)writer)   r&   r*   joinr+   r,   r4   )rJ   messages   &r   format_access8UnsynchronizedAccessError.__str__.<locals>.format_accessi   s    MMV__-R}=>~~~o		&..0IIJ###MM*-m,MM'0B0B0I0I0K(L'MRPr   z                    ============================
                    CSAN detected a possible data race on tensor with data pointer z&
                    Access by stream z$ during kernel:
                    zPrevious access by stream z during kernel:
z'Tensor was allocated with stack trace:
rN   z&Trace for tensor allocation not found.N)ioStringIOrO   textwrapdedentr>   r@   r(   rA   r?   rP   r4   getvalue)r   rR   rQ   s   & @r   r   !UnsynchronizedAccessError.__str__h   s   
	 
	 [[]]gMMTTXTaTaSb c&&*&9&9&@&@%A B $--.MM,T-A-A-H-H,IIZ[ $../***>wwt::AACDEG
 FG##%1 ]]]s   DD99E
	)r?   r@   r>   rA   N	r   r   r   r   r7   rF   r   r   r   r    s   @r   r<   r<   Y   s     S
/ 
/%& %&r   r<   c                   <   a  ] tR t^t o RtV 3R lR ltR tRtV tR# )CUDASanitizerErrorsz4Wrapper class for errors reported by CUDA Sanitizer.c                0   < V ^8  d   QhRS[ S[,          /# )r%   errors)r0   r:   )r4   r!   s   "r   r5    CUDASanitizerErrors.__annotate__   s      t$89 r   c                    Wn         R # rE   r^   )r   r^   s   &&r   rF   CUDASanitizerErrors.__init__   s    r   c                4    R \        V P                  4       R2# )z	detected z errors)lenr^   r   s   &r   r   CUDASanitizerErrors.__str__   s    3t{{+,G44r   ra   NrZ   r    s   @r   r\   r\      s     > 5 5r   r\   c                   F   a  ] tR t^t o Rt]! ]R7      tRtV 3R lt	Rt
V tR# )
TensorInfoau  Stores information about a single tensor and recent accesses to it.

Args:
    allocation_stack_trace: the stack summary object captured during tensor
        allocation. Can be ``None`` if the allocation wasn't caught by CSAN.
    reads: list of read accesses to the tensor that were performed since
        the last write.
    write: the last write access to the tensor.
)default_factoryNc                ~   < V ^8  d   Qh/ S[ P                  R,          ;R&   S[S[,          ;R&   S[R,          ;R&   # )r%   Nr?   readsrO   )r2   r3   r0   r#   )r4   r!   s   "r   r5   TensorInfo.__annotate__   s?      &22T99  <5  D= r   r   )r   r   r   r   r7   r   r0   rj   rO   r8   r   r   r    s   @r   rg   rg      s"       5EE  r   rg   c                      a  ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )_TensorsAccessedc                   < V ^8  d   QhRR/# r%   returnNr   )r4   r!   s   "r   r5   _TensorsAccessed.__annotate__   s     6 6$ 6r   c                    / V n         R # rE   accessesr   s   &r   rF   _TensorsAccessed.__init__   s	    35r   c                $   < V ^8  d   QhRS[ RR/# r%   r>   rp   NrB   )r4   r!   s   "r   r5   rq      s     / /W / /r   c                z    WP                   9  d+   \        P                  R V4       V P                  VR4       R# R# )zFound tensor with pointer: %s, but no matching tensor allocation in the trace. Backfilling the trace now. Perhaps the sanitizer was enabled after some torch operations?N)rt   loggerinfocreate_tensorr   r>   s   &&r   ensure_tensor_exists%_TensorsAccessed.ensure_tensor_exists   s:    ==(KKQ 	 x. )r   c                $   < V ^8  d   QhRS[ RR/# rw   rx   )r4   r!   s   "r   r5   rq      s     	) 	)W 	) 	)r   c                x    WP                   9   d*   \        P                  R V4       V P                  V4       R# R# )zFound duplicate tensor allocation in the trace for tensor with pointer: %s. Assuming the trace for tensor deallocation wasn't caught and backfilling it now. Perhaps the sanitizer was enabled after some torch operations?N)rt   rz   r{   delete_tensorr}   s   &&r   ensure_tensor_does_not_exist-_TensorsAccessed.ensure_tensor_does_not_exist   s8    }}$KKQ  x( %r   c                L   < V ^8  d   QhRS[ RS[P                  R,          RR/# )r%   r>   r,   Nrp   rB   r2   r3   )r4   r!   s   "r   r5   rq      s0     : ::.7.D.Dt.K:	:r   c                6    \        V4      V P                  V&   R # rE   )rg   rt   r   r>   r,   s   &&&r   r|   _TensorsAccessed.create_tensor   s     #-["9hr   c                $   < V ^8  d   QhRS[ RR/# rw   rx   )r4   r!   s   "r   r5   rq      s     $ $g $$ $r   c                     V P                   V R # rE   rs   r}   s   &&r   r   _TensorsAccessed.delete_tensor   s    MM(#r   c                &   < V ^8  d   QhRS[ RS[/# r%   r>   rp   )rB   r1   )r4   r!   s   "r   r5   rq      s     3 3' 3d 3r   c                N    \        V P                  V,          P                  4      # rE   )r1   rt   rj   r}   s   &&r   !were_there_reads_since_last_write2_TensorsAccessed.were_there_reads_since_last_write   s    DMM(+1122r   c                H   < V ^8  d   QhRS[ RS[P                  R,          /# rw   r   )r4   r!   s   "r   r5   rq      s(     > >>			$	&>r   c                <    V P                   V,          P                  # rE   )rt   r?   r}   s   &&r   get_allocation_stack_trace+_TensorsAccessed.get_allocation_stack_trace   s     }}X&===r   c                4   < V ^8  d   QhRS[ RS[R,          /# rw   rB   r#   )r4   r!   s   "r   r5   rq      s     - -' -ftm -r   c                <    V P                   V,          P                  # rE   )rt   rO   r}   s   &&r   	get_write_TensorsAccessed.get_write       }}X&,,,r   c                6   < V ^8  d   QhRS[ RS[S[,          /# r   )rB   r0   r#   )r4   r!   s   "r   r5   rq      s     - -' -d6l -r   c                <    V P                   V,          P                  # rE   )rt   rj   r}   s   &&r   	get_reads_TensorsAccessed.get_reads   r   r   c                *   < V ^8  d   QhRS[ RS[RR/# r%   r>   rJ   rp   Nr   )r4   r!   s   "r   r5   rq      s"     5 5 5& 5T 5r   c                ^    V P                   V,          P                  P                  V4       R # rE   )rt   rj   appendr   r>   rJ   s   &&&r   add_read_TensorsAccessed.add_read   s    h%%,,V4r   c                *   < V ^8  d   QhRS[ RS[RR/# r   r   )r4   r!   s   "r   r5   rq      s"     + +' +6 +d +r   c                d    W P                   V,          n        . V P                   V,          n        R # rE   )rt   rO   rj   r   s   &&&r   	set_write_TensorsAccessed.set_write   s"    (.h%(*h%r   rs   N)r   r   r   r   rF   r~   r   r|   r   r   r   r   r   r   r   r   r   r    s   @r   rm   rm      ss     6 6/ /	) 	): :
$ $3 3> >
- -- -5 5+ +r   rm   c                   .  a  ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR # )!StreamSynchronizationsc                   < V ^8  d   QhRR/# ro   r   )r4   r!   s   "r   r5   #StreamSynchronizations.__annotate__   s     . .$ .r   c                Z    / V n         / V n        / V n        V P                  \        4       R # rE   )current_sync_statesrecorded_sync_stateshost_sync_statecreate_streamDEFAULT_STREAM_IDr   s   &r   rF   StreamSynchronizations.__init__   s)    KM KM!79,-r   c                $   < V ^8  d   QhRS[ RR/# r%   r(   rp   Nr.   )r4   r!   s   "r   r5   r      s     ' 'H ' 'r   c                x    WP                   9  d*   \        P                  R V4       V P                  V4       R# R# )zFound Stream with id: %s, but no matching stream creation in the trace. Backfilling the trace now. Perhaps the sanitizer was enabled after some torch operations?N)r   rz   r{   r   r   r(   s   &&r   _ensure_stream_exists,StreamSynchronizations._ensure_stream_exists   s:    111KKQ 	 v& 2r   c                $   < V ^8  d   QhRS[ RR/# r%   eventrp   NEventId)r4   r!   s   "r   r5   r      s     % %' %d %r   c                x    WP                   9  d*   \        P                  R V4       V P                  V4       R# R# )zFound Event with id: %s, but no matching event creation in the trace. Backfilling the trace now. Perhaps the sanitizer was enabled after some torch operations?N)r   rz   r{   create_eventr   r   s   &&r   _ensure_event_exists+StreamSynchronizations._ensure_event_exists   s:    111KKQ 	 e$ 2r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r      s     	% 	%' 	%d 	%r   c                x    WP                   9   d*   \        P                  R V4       V P                  V4       R# R# )zFound duplicate event creation in the trace for event with id: %s. Assuming the trace for event deletion wasn't caught and backfilling it now. Perhaps the sanitizer was enabled after some torch operations?N)r   rz   r{   delete_eventr   s   &&r   _ensure_event_does_not_exist3StreamSynchronizations._ensure_event_does_not_exist   s:    ---KKQ  e$ .r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r     s     
K 
KH 
K 
Kr   c                    WP                   9   d   \        P                  R V4       R# ^ V P                  V&   V P                  P	                  4       V P                   V&   R# )zFound duplicate Stream creation in the trace for Stream with id: %s. PyTorch Streams are only created once, so this trace entry is ignored.N)r   rz   r{   r   copyr   s   &&r   r   $StreamSynchronizations.create_stream  sU    ---KK* 	 ,-D  (/3/C/C/H/H/JD$$V,r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r     s     . .' .d .r   c                F    V P                  V4       / V P                  V&   R # rE   )r   r   r   s   &&r   r   #StreamSynchronizations.create_event  s     ))%0+-!!%(r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r     s     - -' -d -r   c                B    V P                  V4       V P                  V R # rE   )r   r   r   s   &&r   r   #StreamSynchronizations.delete_event  s    !!%(%%e,r   c                *   < V ^8  d   QhRS[ RS[RR/# )r%   r(   r'   rp   N)r.   r-   )r4   r!   s   "r   r5   r     s"     ; ;X ; ;4 ;r   c                R    V P                  V4       W P                  V,          V&   R # rE   )r   r   )r   r(   r'   s   &&&r   update_seq_num%StreamSynchronizations.update_seq_num  s#    ""6*3:  (0r   c                *   < V ^8  d   QhRS[ RS[RR/# r%   r   r(   rp   Nr   r.   )r4   r!   s   "r   r5   r      s'     S S' S8 S Sr   c                    V P                  V4       V P                  V4       V P                  V,          P                  4       V P                  V&   R # rE   )r   r   r   r   r   r   r   r(   s   &&&r   record_state#StreamSynchronizations.record_state   sB    !!%(""6*+/+C+CF+K+P+P+R!!%(r   c                V   < V ^8  d   QhRS[ S[S[3,          RS[ S[S[3,          RR/# )r%   stateotherrp   N)dictr.   r-   )r4   r!   s   "r   r5   r   %  s>     @ @(F*+@4869I4J@	@r   c                t    VP                  4        F#  w  r4\        VP                  VR4      V4      W&   K%  	  R# )   N)itemsmaxget)r   r   r   r(   r'   s   &&&  r   _state_wait_for_other,StreamSynchronizations._state_wait_for_other%  s/      %{{}OF		&" 5w?EM  -r   c                *   < V ^8  d   QhRS[ RS[RR/# )r%   r(   r   rp   N)r.   r   )r4   r!   s   "r   r5   r   +  s"     
 
H 
W 
 
r   c                    V P                  V4       V P                  V4       V P                  V P                  V,          V P                  V,          4       R # rE   )r   r   r   r   r   )r   r(   r   s   &&&r   stream_wait_for_event,StreamSynchronizations.stream_wait_for_event+  sG    ""6*!!%(""$$V,d.G.G.N	
r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r   2  s     
 
 
D 
r   c                    V P                  V4       V P                   F  pV P                  W!4       K  	  V P                  V P                  V P
                  V,          4       R # rE   )r   r   r   r   r   r   r   s   && r   all_streams_wait_for_event1StreamSynchronizations.all_streams_wait_for_event2  sT    !!%(..F&&v5 / 	""  $";";E"B	
r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r   ;  s     
 
( 
t 
r   c                   V P                  V4       V P                  P                  4        F%  pV P                  W P                  V,          4       K'  	  V P                  V P                  V P                  V,          4       R # rE   )r   r   valuesr   r   r   r(   r   s   && r   all_streams_wait_for_stream2StreamSynchronizations.all_streams_wait_for_stream;  sh    ""6*--446E&&u.F.Fv.NO 7 	""  $":":6"B	
r   c                   < V ^8  d   QhRR/# ro   r   )r4   r!   s   "r   r5   r   D  s     D D$ Dr   c                    V P                   P                  4        F  w  rW!,          V P                  V&   K  	  V P                   P                  4        F  pV P	                  W P                  4       K   	  R # rE   )r   r   r   r   r   r   s   &  r   sync_all_streams'StreamSynchronizations.sync_all_streamsD  s^    !55;;=MF+0=D  ( > --446E&&u.B.BC 7r   c                2   < V ^8  d   QhRS[ RS[RS[ RS[/# )r%   current_streamr'   other_streamrp   )r.   r-   r1   )r4   r!   s   "r   r5   r   K  s3     Y Y&Y17YGOY	Yr   c                    V P                  V4       V P                  V4       W P                  V,          P                  VR4      8*  # )r   r   )r   r   r   )r   r   r'   r  s   &&&&r   is_ordered_after'StreamSynchronizations.is_ordered_afterK  sB     	"">2""<022>BFF|UWXXXr   )r   r   r   N)r   r   r   r   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r    s   @r   r   r      s     . .' '% %	% 	%
K 
K. .- -; ;S S
@ @
 

 

 
D DY Yr   r   c                      a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )EventHandleriS  zAnalyzes CSAN trace for synchronization errors.

Stores information on each stream's synchronizations with other streams as well
as tensor accesses to determine whether a given kernel launch might cause a
data race.
c                   < V ^8  d   QhRR/# ro   r   )r4   r!   s   "r   r5   EventHandler.__annotate__[  s     ! !$ !r   c                P    \        4       V n        \        4       V n        ^ V n        R# )    N)rm   tensors_accessedr   syncsr'   r   s   &r   rF   EventHandler.__init__[  s     0 2+-
 r   c                   < V ^8  d   QhRS[ RS[S[,          RS[S[,          RS[S[,          RS[RS[S[S[S[,          3,          RS[S[,          /# )r%   r(   	read_only
read_writeoutputsr)   tensor_aliasesrp   )r.   setrB   r/   r   intr0   r:   )r4   r!   s   "r   r5   r  `  sy     H HH w<H L	H
 WH H S$s)^,H 
"	#Hr   c           
     2  a a R  VV 3R llp. oS ;P                   ^,          un         S P                  P                  VS P                   4       \        P                  P                  \        P                  ! \        P                  ! 4       4      RR7      pVP                  4        V F  p	S P                  P                  V	4       \        \        P                  S P                   VVWi,          W9   V4      p
V! WS P                  P                  V	4      4       S P                  P!                  W4       K  	  V F  p	S P                  P                  V	4       \        \        P"                  S P                   VVWi,          W9   V4      p
S P                  P%                  V	4      '       d-   S P                  P'                  V	4       F  pV! WV4       K  	  M"V! WS P                  P                  V	4      4       S P                  P)                  W4       K  	  S# )c                N    V ^8  d   QhR\         R\        R\        R,          RR/# )r%   r>   r@   rA   Nrp   r   )r4   s   "r   r5   8EventHandler._handle_kernel_launch.<locals>.__annotate__i  s1     	 		/5	HNQU		r   c                   < Vf   R # SP                   P                  VP                  VP                  VP                  4      '       g9   SP	                  \        V SP                  P                  V 4      VV4      4       R # R # rE   )r  r  r(   r'   r   r<   r  r   )r>   r@   rA   
error_listr   s   &&&r   check_conflict:EventHandler._handle_kernel_launch.<locals>.check_conflicti  sx     &::..%%'>'>@V@V  !!- --HHR&'	r   Flookup_lines)r'   r  r   r2   r3   extract
walk_stackinspectcurrentframereverser  r~   r#   r   r   r   r   r   r   r   r   )r   r(   r  r  r  r)   r  r  r,   r>   r@   rA   r  s   f&&&&&&     @r   _handle_kernel_launch"EventHandler._handle_kernel_launch`  s   	 	" 24


!!&$,,7,,44  !5!5!78u 5 

 	!H!!66x@#(#N $*?*?*I*I(*S !!**8D "  #H!!66x@#  (#N $$FFxPP'+'<'<'F'Fx'PO"8_M (Q d.C.C.M.Mh.W !!++HE% #( r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r         ' 'G ' 'r   c                <    V P                   P                  V4       R # rE   )r  r   r   s   &&r   _handle_event_creation#EventHandler._handle_event_creation      

&r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r    r&  r   c                <    V P                   P                  V4       R # rE   )r  r   r   s   &&r   _handle_event_deletion#EventHandler._handle_event_deletion  r*  r   c                *   < V ^8  d   QhRS[ RS[RR/# r   r   )r4   r!   s   "r   r5   r    s"     / /' /8 / /r   c                <    V P                   P                  W4       R # rE   )r  r   r   s   &&&r   _handle_event_record!EventHandler._handle_event_record  s    

.r   c                *   < V ^8  d   QhRS[ RS[RR/# r   r   )r4   r!   s   "r   r5   r    s"     8 8 8 8d 8r   c                <    V P                   P                  W!4       R # rE   )r  r   r   s   &&&r   _handle_event_waitEventHandler._handle_event_wait  s    

((7r   c                $   < V ^8  d   QhRS[ RR/# rw   rx   )r4   r!   s   "r   r5   r    s     
 
' 
d 
r   c                $   V P                   P                  V4       \        P                  P	                  \        P
                  ! \        P                  ! 4       4      R R7      pVP                  4        V P                   P                  VV4       R# )Fr  N)
r  r   r2   r3   r  r  r   r!  r"  r|   r   s   && r   _handle_memory_allocation&EventHandler._handle_memory_allocation  sr    ::8D,,44  !5!5!78u 5 

 	++	
r   c                $   < V ^8  d   QhRS[ RR/# rw   rx   )r4   r!   s   "r   r5   r    s     6 6G 6 6r   c                r    V P                   P                  V4       V P                   P                  V4       R # rE   )r  r~   r   r}   s   &&r   _handle_memory_deallocation(EventHandler._handle_memory_deallocation  s*    228<++H5r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r    s     ) )h )4 )r   c                <    V P                   P                  V4       R # rE   )r  r   r   s   &&r   _handle_stream_creation$EventHandler._handle_stream_creation  s    

  (r   c                   < V ^8  d   QhRR/# ro   r   )r4   r!   s   "r   r5   r    s     & & &r   c                :    V P                   P                  4        R # rE   )r  r   r   s   &r   _handle_device_synchronization+EventHandler._handle_device_synchronization  s    

##%r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r    s     7 7X 7$ 7r   c                <    V P                   P                  V4       R # rE   )r  r   r   s   &&r   _handle_stream_synchronization+EventHandler._handle_stream_synchronization  s    

..v6r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r4   r!   s   "r   r5   r    s     5 57 5t 5r   c                <    V P                   P                  V4       R # rE   )r  r   r   s   &&r   _handle_event_synchronization*EventHandler._handle_event_synchronization  s    

--e4r   )r'   r  r  N)r   r   r   r   r7   rF   r#  r(  r-  r1  r5  r9  r=  rA  rE  rI  rM  r   r   r    s   @r   r  r  S  s     ! !
H HT' '' '/ /8 8
 
6 6) )& &7 75 5r   r  c          
          V ^8  d   QhR\         \        \        3,          R\         \        \        3,          R\        \
        \        \        \        3,          ,          /# )r%   abrp   )r   r	   r
   r   r   tuple)r4   s   "r   r5   r5     sA     % %$r3w- %DSM %huRc\?R6S %r   c              #   h   "   V P                  4        F  w  r#W!9   g   K  W#W,          3x  K  	  R # 5irE   )r   )rP  rQ  argvalues   &&  r   
zip_by_keyrV    s)     ggi
8af$$  s   22c                    V ^8  d   QhR\         P                  R\        \        R3,          R\        \
        \        3,          R\        \        \         P                  \        3,          ,          /# )r%   schemaargs.kwargsrp   )torchFunctionSchemarR  r   r   r/   r   Argument)r4   s   "r   r5   r5     sU     	  	   	 (-c3h	 AEc3h	 eENNC'()	 r   c              #     "   V P                   R \        V4       pV P                   \        V4      R   Uu/ uF  qDP                  VbK  	  pp\        W14       R j  xL
  \	        WR4       F  w  rgpWx3x  K  	  R # u upi  L%5irE   )	argumentsrd   nameziprV  )	rX  rY  rZ  schema_argsrT  schema_kwargs_argumentrU  s	   &&&      r   zip_argumentsrf    s      "";SY/K.4.>.>s4y{.KL.KsXXs].KML;%%%(?U @	 M%s   3BA;
BB &Bc                   l   a  ] tR tRt o V 3R lR ltRV 3R lR lltV 3R lR ltV 3R	 lR
 ltRtV t	R# )ArgumentHandleri  c                   < V ^8  d   QhRR/# ro   r   )r4   r!   s   "r   r5   ArgumentHandler.__annotate__  s     + +$ +r   c                n    \        4       V n        \        4       V n        / V n        \        4       V n        R # rE   )r  dataptrs_readdataptrs_writtenr  r  r   s   &r   rF   ArgumentHandler.__init__  s'    +.5.1e8:%(Ur   Nc                J   < V ^8  d   QhRS[ RS[RS[RS[R,          RS[RR/# )r%   rU  is_writemetadata_onlyr`  Nr+   rp   )r   r1   r/   )r4   r!   s   "r   r5   rj    sK     + ++ + 	+
 Dj+ + 
+r   c                0   \        V\        P                  4      '       d   VP                  '       d   VP	                  4       '       d   VP	                  4       M
\        V4      pV'       d   V P                  P                  V4       M#V'       g   V P                  P                  V4       V P                  P                  V. 4       Ve#   V P                  V,          P                  V4       V'       d   V P                  P                  V4       R # R # R # R # rE   )
isinstancer[  Tensoris_cudar>   idrm  addrl  r  
setdefaultr   r  )r   rU  rp  rq  r`  r+   r>   s   &&&&&& r   _handle_argument ArgumentHandler._handle_argument  s     eU\\**u}}} ,1>>+;+;u~~'EH%%))(3"""&&x0**8R8##H-44T:  *  0=*r   c          
      t   < V ^8  d   QhRS[ P                  RS[S[R3,          RS[S[S[3,          RS[RR/# )r%   rX  rY  .rZ  
is_factoryrp   N)r[  r\  rR  r   r   r/   r1   )r4   r!   s   "r   r5   rj    sS      $$ CHo S#X	  
r   c          
        \        WV4       F  w  rVVP                  R J;'       d    VP                  P                  pT;'       g2    VP                  R J;'       d    VP                  P                  '       * p\        P                  ! \
        P                  ! V P                  VVP                  VR7      V4       K  	  R # )N)rp  r`  rq  )	rf  
alias_inforp  pytree	tree_map_	functoolspartialry  r`  )	r   rX  rY  rZ  r|  re  rU  rp  rq  s	   &&&&$    r   parse_inputsArgumentHandler.parse_inputs  s      -V6BOH**$6WW8;N;N;W;WH '  ##4/TT8K8K8T8T4T  !!))%!"/	   Cr   c                D   < V ^8  d   QhRS[ P                  RS[RS[RR/# )r%   rX  r  r|  rp   N)r[  r\  r   r1   )r4   r!   s   "r   r5   rj    s3      **58IM	r   c          
     8   \        VP                  V34       F~  w  rET;'       g2    VP                  R J;'       d    VP                  P                  '       * p\        P
                  ! \        P                  ! V P                  V'       * RVR7      V4       K  	  R # )NT)rp  r+   rq  )	ra  returnsr~  rp  r  r  r  r  ry  )r   rX  r  r|  resrU  rq  s   &&&$   r   parse_outputsArgumentHandler.parse_outputs  s     fnnwj9JC&  d*JJ3>>3J3J/J  !!))!..""/	 	 :r   )rl  rm  r  r  NF)
r   r   r   r   rF   ry  r  r  r   r   r    s   @r   rh  rh    s-     + ++ +. 2 r   rh  c                   <   a  ] tR tRt o V 3R lR ltRR ltRtV tR# )CUDASanitizerDispatchModei/  c                   < V ^8  d   QhRR/# ro   r   )r4   r!   s   "r   r5   &CUDASanitizerDispatchMode.__annotate__0  s      
  
$  
r   c                   \        4       V n        \        P                  P	                  4        \
        P                  ! V P                  P                  4       \
        P                  ! V P                  P                  4       \
        P                  ! V P                  P                  4       \
        P                  ! V P                  P                  4       \
        P                  ! V P                  P                  4       \
        P                   ! V P                  P"                  4       \
        P$                  ! V P                  P&                  4       \
        P(                  ! V P                  P*                  4       \
        P,                  ! V P                  P.                  4       \
        P0                  ! V P                  P2                  4       R # rE   )r  event_handlerr[  _C_activate_gpu_trace	gpu_trace$register_callback_for_event_creationr(  $register_callback_for_event_deletionr-  "register_callback_for_event_recordr1   register_callback_for_event_waitr5  'register_callback_for_memory_allocationr9  )register_callback_for_memory_deallocationr=  %register_callback_for_stream_creationrA  ,register_callback_for_device_synchronizationrE  ,register_callback_for_stream_synchronizationrI  +register_callback_for_event_synchronizationrM  r   s   &r   rF   "CUDASanitizerDispatchMode.__init__0  sP   )^$$&6655	
 	6655	
 	4433	
 	2211	
 	9988	
 	;;::	
 	7766	
 	>>==	
 	>>==	
 	==<<	
r   Nc                   Vf   / pV\         P                  P                  J d	   V! V/ VB # \        \        P                  VP                  P                  4      4      p\        4       pVP                  VP                  W4VR7       V! V/ VB pVP                  VP                  WuR7       V P                  P                  \        P                  P                  4       P                   VP"                  VP$                  ,
          VP$                  VP&                  VP                  VP(                  4      pV'       d0   V F  p	\+        V	\,        P.                  R7       K   	  \1        V4      hV# )N)r|  )file)atenrecord_streamdefaultr1   FACTORY_FUNCTION_REGEXmatch_schemar`  rh  r  r  r  r#  r[  cudar   cuda_streamrl  rm  r  r  printsysstderrr\   )
r   functypesrY  rZ  r|  argument_handlerr  r^   errors
   &&&&&     r   __torch_dispatch__,CUDASanitizerDispatchMode.__torch_dispatch__R  s*   >F 4%%---(((066t||7H7HIJ
*,%%dllDZ%X''&&t||W&T##99JJ%%'33**-=-N-NN--$$LL++
 e#**-  %f--r   )r  )r   N)r   r   r   r   rF   r  r   r   r    s   @r   r  r  /  s      
  
D r   r  c                   H   a  ] tR tRt o RtV 3R lR ltR tR tR tRt	V t
R	# )
CUDASanitizerir  au  Manages the lifetime of a CUDASanitizer dispatch mode object.

The CUDASanitizer class wraps the entering/exiting functions of the dispatch mode
context manager in the enable function/destructor, respectively. This is to
explicitly set the lifetime of the dispatch mode object to that of the application.
This approach was deemed more elegant than using the atexit module.
c                   < V ^8  d   QhRR/# ro   r   )r4   r!   s   "r   r5   CUDASanitizer.__annotate__{  s      $ r   c                2    \        4       V n        R V n        R# )FN)r  dispatchenabledr   s   &r   rF   CUDASanitizer.__init__{  s    13r   c                H    V P                   P                  4        R V n        R# )TN)r  	__enter__r  r   s   &r   enableCUDASanitizer.enable  s    !r   c                N    V P                   P                  R R R 4       RV n        R # r  )r  __exit__r  r   s   &r   disableCUDASanitizer.disable  s    tT40r   c                    \         eD   \         P                  ! 4       '       g'   V P                  '       d   V P                  4        R # R # R # R # rE   )r  is_finalizingr  r  r   s   &r   __del__CUDASanitizer.__del__  s4     Oc&7&7&9&9t|||LLN @L&9Or   )r  r  N)r   r   r   r   r7   rF   r  r  r  r   r   r    s   @r   r  r  r  s(      	 	r   r  c                 .    \         P                  4        R# )aO  Enable CUDA Sanitizer.

The sanitizer will begin to analyze low-level CUDA calls invoked by torch functions
for synchronization errors. All data races found will be printed to the standard
error output along with stack traces of suspected causes. For best results, the
sanitizer should be enabled at the very beginning of the program.
N)cuda_sanitizerr  r   r   r   enable_cuda_sanitizerr    s     r   )>r7   r   r  r   rT   loggingrer  rV   r2   collections.abcr   dataclassesr   r   typingr   r   r[  torch.cuda._gpu_tracer  
_gpu_tracer  torch.utilsr   r  torch.utils._python_dispatchr   opsr  r   r	   r
   r   r  rB   r.   r   r-   	getLoggerr   rz   compiler  Enumr   r#   	Exceptionr:   r<   r\   rg   rm   r   r  rV  rf  rh  r  r  r  r  r   r   r   <module>r     sv  
    	  	 
   $ (   ) ) ) : yy~~ T]enen

				8	$ $67 K K ( ( (.<9 <4& 4 4&n5) 5       4+ 4+nnY nYb~5 ~5B%	 F FR@ 1 @F B r   