
    ɯwgDU                    Z   d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
mZmZmZmZmZmZ d dlZd dlZd dlmZ d dlmZ ddlmZmZ dd	lmZ dd
lmZmZm Z  ddl!m"Z"m#Z#  G d dejH                  jJ                        Z& G d de      Z' G d de      Z( G d d      Z) G d d      Z*y)    )annotationsN)autoEnum)AnyCallableDictList
NamedTupleOptionalSequenceTuple)identity)SymT   )configdependencies)index_prevent_reordering)cache_on_selfsympy_index_symbol_with_prefix
sympy_subs)opsVc                  n     e Zd Ze ej
                  d      d               Z fdZd fdZ fdZ	 xZ
S )InterpreterShimNc                 H    t         j                  j                  t              S N)torchfxsymbolic_tracer        ^/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/torch/_inductor/loop_body.py	_dummy_gmzInterpreterShim._dummy_gm   s     xx&&x00r!   c                    t         |   | j                         d       | | _        || _        || _        d| _        |j                  | _        d | _	        y )NF)garbage_collect_values)
super__init__r#   modulegraph
submodulesextra_traceback__getitem__
fetch_attrcurrent_node)selfr)   r*   	__class__s      r"   r'   zInterpreterShim.__init__   sP     	)%H
$$$00 r!   c                0    || _         t        | 	  |      S r   )r.   r&   run_node)r/   nr0   s     r"   r2   zInterpreterShim.run_node'   s    w""r!   c                x    t        j                  |       5  t        |   |i |cd d d        S # 1 sw Y   y xY wr   )r   set_interpreter_handlerr&   run)r/   argskwargsr0   s      r"   r6   zInterpreterShim.run+   s7    &&t, 	07;//	0 	0 	0s   09)r3   ztorch.fx.Nodereturnr   )__name__
__module____qualname__staticmethod	functools	lru_cacher#   r'   r2   r6   __classcell__r0   s   @r"   r   r      s>    Y1  1	!#0 0r!   r   c                  ,    e Zd ZU ded<   ded<   ded<   y)MemoryEntrystr
index_nameOptional[str]buffer_namemodeN)r:   r;   r<   __annotations__r    r!   r"   rC   rC   0   s    O
r!   rC   c                  n    e Zd Z e       Z e       Z e       Z e       Z e       Z e       Z	 e       Z
y)MemoryUsageTypeN)r:   r;   r<   r   LOAD	LOAD_SEEDSTORESTORE_REDUCTION
INDEX_EXPRCHECK_BOUNDS	BUCKETIZEr    r!   r"   rK   rK   6   s3    6DIFEfOJ6LIr!   rK   c                  >    e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<    fdZd Zd*dZd+dZd+dZ	e
d        Zed        Zed        Zd Zd Zd Zd Zd Zd,dZeZ	 	 d-	 	 	 	 	 	 	 d.d Zd! Zd" Zd# Zd$ Zd% Zd& Zd' Zd( Zd) Z xZ S )/LoopBodyz
    Captures the body of a Loops subclass into an FX graph.  Persists any
    indexing simplifications and makes it easier to analyze loop bodies.
    zDict[str, sympy.Expr]indexing_exprszDict[sympy.Expr, str]indexing_exprs_namezDict[str, Any]r*   zDict[str, LoopBodyBlock]	subblocksz	List[str]indirect_varszDict[sympy.Symbol, sympy.Expr]indirect_var_rangesLoopBodyBlock
root_blockz(Dict[MemoryUsageType, List[MemoryEntry]]memory_usagec                F   t         |           t        |j                               }|d t	        |       |t	        |      d  f| _        || _        || _        || _        t        |t              r| j                  ||       d | _        y | j                  ||       d | _        y r   )r&   r'   tuplevalueslensizes	iter_varsreduce_vars
var_ranges
isinstancerT   _init_with_copy_init_with_tracingindexing)r/   fnr7   rd   rb   rc   _flat_sizesr0   s          r"   r'   zLoopBody.__init__P   s    J--/0(#i.)I()


 #&$b(#  T*  ##B-r!   c                    i | _         i | _        d| j                  i| _        i | _        g | _        i | _        t        D ci c]  }|g  c}| _        t        | ||      | _
        | `yc c}w )z9Do an FX trace of an arbitrary callable to construct self	get_indexN)rU   rV   rl   r*   rW   rX   rY   rK   r\   rZ   r[   )r/   ri   r7   ts       r"   rg   zLoopBody._init_with_tracingd   sk     #% &7CE ,;<qQU<'b$7$ =s   
A&c           	        |j                  |      }|j                         D ci c]:  \  }}|t        j                  j                  j                  || j                        < c}}| _        |j                  j                         D ci c]  \  }}||j                  |        c}}| _        |j                  | _
        |j                  | _        |j                  | _        |j                  j                  |       | _        i |j                  }|j                  d       d| j                   i|j                         D ci c]  \  }}||j                  |        c}}| _        yc c}}w c c}}w c c}}w )z
        _init_with_tracing() is slow, so this is a fast path in the case
        where we are just reordering/merging/splitting the args of an
        existing LoopBody.
        rl   N)indexing_from_argsitemsr   r)   sizevarssimplify_with_rangesrd   rU   rW   clonerX   rY   r\   r[   r*   poprl   )	r/   otherr7   rU   nameexprkvr*   s	            r"   rf   zLoopBody._init_with_copyp   s>    11$7 -224
d !''""77dooNN
 8=7L7L7NOtq!!QWWT]*O"00#(#<#< !..**006)(()
{#
,6,<,<,>?DAqq!''$-?

 P @s   ?E(
E.E4c           	     >   | }| j                   }|j                  \  }}|\  }}g |j                  j                         }t        j
                  j                  j                  ||t        |||            \  }}	}
t        j
                  j                  j                  ||t        |||            \  }}}
t        j                  ||d      \  \  }}}t        | |	|       ||      g|||      }t        j                  ||d      \  \  }}}t        |||f|||      }|S )zU
        Merge both iteration and reduction loops and return a new LoopBody.
        rm   )prefixz)ra   varsrU   r_   r   r)   rq   _simplify_loopsr   r   index_vars_no_squeezerT   )r/   old_body	old_sizesold_iter_varsold_reduce_varsold_iter_sizesold_reduce_sizesindex_exprs
iter_sizesiter_reindex_reduce_sizesreduce_reindexrb   rc   rd   new_body
iter_vars2reduce_vars2var_ranges2	new_body2s                        r"   merge_loopszLoopBody.merge_loops   sH    JJ	)1&+4((9//6689&'gg&6&6&F&F$[-P'
#
L! +,''*:*:*J*J$[/CST+
'na( %::S
	 	
 )$n[&AB
 3?2T2TS3
/"\K z<0+z<
	 r!   c                    ddl m} | | j                  }t        |d         t        |      k(  sJ  ||      }|\   |      }|f}t	        j
                  |ddi\  \  }}}	t        |      D 
ci c]  \  }
}||

 c}}
t        t        |            D cg c]  }|   	 c}dfd}t        |||f|	||      }t	        j
                  |ddi\  \  }}}t        |||f|||      }|S c c}}
w c c}w )	zD
        Reorder iteration loops and return a new LoopBody.
        r   )same_reorderr   r{   rm   c                     t        t        j                  |        }t        |      t              t              z   k(  sJ |d t               }|t              d  }D cg c]  }||   	 }} ||      S c c}w r   )list	itertoolschainr`   )	indicesindexiter_idx
reduce_idxiinverse_order	iter_sizer   reduce_sizes	        r"   r   z-LoopBody.reorder_iter_loops.<locals>.new_body   s    '23Eu:Y#k2B!BBBB-s9~.Hs9~/0J-:;;H;Hj11 <s   "A9r|   )r   zSequence[sympy.Expr]r9   r   )	irr   ra   r`   r   r   	enumeraterangerT   )r/   	new_orderr   r   
reorder_fnnew_iter_size	new_sizesrb   rc   rd   abr   r   	loop_bodyr   r   r   r   r   r   r   s                     @@@@r"   reorder_iter_loopszLoopBody.reorder_iter_loops   s4    	%JJ	9Q< C	N222!),
!*	;"9-"K0	/;/Q/Q0
"0
, K* +4I*>?$!QA?38Y3HIaq)I	2 	2 y+.
I{
	
 3?2T2T3
"3
/"\K 
L1;
L
 - @Is   7C5C;c                j    | j                   J | j                  J | j                   | j                  fS r   )rb   rc   r/   s    r"   r}   zLoopBody.vars   s9    ~~)))+++~~t////r!   c                    t        j                  | j                  j                  fd | j                  j                         D              }|D cg c]  }|j                  D ]  }|  c}}S c c}}w )Nc              3  4   K   | ]  }|j                     y wr   )r)   ).0blocks     r"   	<genexpr>z%LoopBody.get_nodes.<locals>.<genexpr>   s     >UU[[>s   )r   r   r[   r)   rW   r_   nodes)r/   
all_graphsr)   nodes       r"   	get_nodeszLoopBody.get_nodes   s[    ____""$>dnn&;&;&=>

 #-EEEEEEs   A.c                    ddl m}  ||       S )Nr   )	BoundVars)boundsr   )r/   r   s     r"   r   zLoopBody.bounds   s     	&r!   c                    t        | j                  t        j                           D ],  }|j                  |k(  s| j
                  |j                     c S  t        |      r   )reversedr\   rK   rL   rG   rU   rE   KeyErrorr/   rG   entrys      r"   get_read_exprzLoopBody.get_read_expr  sY    d//0D0DEF 	=E  K/**5+;+;<<	= {##r!   c                   t        j                  | j                  t        j                     | j                  t        j
                           D ],  }|j                  |k(  s| j                  |j                     c S  t        |      r   )
r   r   r\   rK   rN   rO   rG   rU   rE   r   r   s      r"   get_write_exprzLoopBody.get_write_expr
  sv    __o334o==>
 	=E   K/**5+;+;<<	= {##r!   c                    | j                   t        j                     D cg c]  }| j                  |j                      c}S c c}w r   )r\   rK   rL   rU   rE   r/   r   s     r"   get_read_exprszLoopBody.get_read_exprs  sF     **?+?+?@
  0 01
 	
 
s    Ac                    t        j                  | j                  t        j                     | j                  t        j
                           D cg c]  }| j                  |j                      c}S c c}w r   )r   r   r\   rK   rN   rO   rU   rE   r   s     r"   get_write_exprszLoopBody.get_write_exprs  sf     #!!/"7"78!!/"A"AB
  0 01
 	
 
s    A2c           	        dt        | j                         g}|j                  | j                  j	                         D cg c]  \  }}| d|  c}}       |j                  t        j                  d| j                  fg| j                  j	                               D cg c]  \  }}|j                  |       c}}       dj                  |      S c c}}w c c}}w )Nzvar_ranges = z = body
)dictrd   extendrU   rp   r   r   r[   rW   	debug_strjoin)r/   linesrv   valr   s        r"   r   zLoopBody.debug_str"  s     doo!6 7899L9L9R9R9TUID#c#'UV $-??doo./1E1E1G$D% %	
 yy Vs   C
$C
c                   t        | j                  t        j                           dk(  xr` t        | j                  t        j                           dk(  xr5 t        | j
                        dk(  xr | j                  j                  d      S )zx
        True of this contains only a single loads and store.
        Note, this could involve a layout change.
        r   )loadstore)r`   r\   rK   rL   rN   r*   r[   contains_only_opsr   s    r"   is_memory_copyzLoopBody.is_memory_copy/  s}     !!/"6"678A= ED%%o&;&;<=BEDOO$)E 112CD		
r!   c                    | j                   j                  |      }|s6dt        | j                         }|| j                   |<   || j                  |<   | j                  |   j                  t        |||             |S )Nr   )rV   getr`   rU   r\   appendrC   )r/   rw   mtyperG   rH   rv   s         r"   add_index_exprzLoopBody.add_index_expr=  s|     ''++D13t22345D-1D$$T*(,D%% ''D+t(LMr!   c                    |d   j                         r|| j                  vr|}n| t        | j                         }|| j                  |<   |S )zaNot actually for nn.Modules, but subblocks in generated code are mapped to FX call_module opcodes)	isnumericr*   r`   )r/   r   r{   rv   s       r"   add_submodulezLoopBody.add_submoduleL  sM    ":!fDOO&CDXc$//234D %r!   c                    t        t        j                  t        | j                              }|| j
                  vsJ | j                  j                  |       || j
                  |<   |S r   )r   r   INDIRECTr`   rX   rY   r   )r/   sizevars      r"   add_indirectzLoopBody.add_indirectU  sZ    ,T]]C@R@R<ST$22222!!#&(,  %
r!   c           
         t        |      t        |      k(  ry| j                  J | j                  j                         D ci c]  \  }}|t        |||i       c}}| _        yc c}}w )z,Swap in a variable used in indirect indexingN)rD   rh   rp   r   )r/   oldnewrx   ry   s        r"   replace_indirectzLoopBody.replace_indirect\  s[    s8s3x}}(((BF--BUBUBWX$!QJq3*55XXs   A'c                <    | j                   J | j                   |   S r   )rh   )r/   rv   s     r"   rl   zLoopBody.get_indexc  s!    }}(((}}T""r!   c           	         g t         j                  j                  |      }t        |      t         j                        k(  sJ | j                  f       t         fd|D              sJ d j                  d|       t        t         j                  j                         |            } j                  j                         D ci c]  \  }}|t        ||       c}}S c c}}w )Nc              3  :   K   | ]  }|j                   v  y wr   )rd   )r   ry   r/   s     r"   r   z.LoopBody.indexing_from_args.<locals>.<genexpr>j  s      
)*AT__$
   zself.var_ranges=z
, indices=)r   r   from_iterabler`   rd   allr   zipkeysrU   rp   r   )r/   r   r   replacementsrv   rw   s   `     r"   ro   zLoopBody.indexing_from_argsg  s    9)////895zS11KE4??3KK1 
.3
 
 	-doo{',	- 
 C 4 4 6>? #11779
d *T<00
 	
 
s   C'c                `    | j                  |      | _        | j                         }d | _        |S r   )ro   rh   r[   )r/   r   results      r"   __call__zLoopBody.__call__s  s,    //8"r!   c                |      fd}t        j                  t        j                        |_        |S )Nc           	     j    j                  t        j                  j                  |              y r   )r   r   r   indirect_indexing)new_varcheckr/   r   r   wrap_negs    r"   set_indirectz5LoopBody.bind_set_indirect_shim.<locals>.set_indirectz  s+    !!QUU,,WdE8Lr!   )r   r   r   r   )r>   partialrT   bind_set_indirect_shimrs   )r/   r   r   r   r   r   s   ````` r"   r   zLoopBody.bind_set_indirect_shimy  s?    	 	
 '..++
 r!   c                f    fd}t        j                  t        j                        |_        |S )Nc                F    t         j                  j                  | |      S r   )r   r   scan)dtypesr_   
combine_fns     r"   shimz%LoopBody.bind_scan_shim.<locals>.shim  s    55::fj&99r!   )r   )r>   r   rT   bind_scan_shimrs   )r/   r   r   s    ` r"   r  zLoopBody.bind_scan_shim  s)    	: &&x'>'>:V
r!   c                j      fd}t        j                  t        j                        |_        |S )Nc                `    t         j                  j                  | j                     |      S r   )r   r   maskedrW   )maskru   rv   r/   s     r"   r   z'LoopBody.bind_masked_shim.<locals>.shim  s#    55<<dnnT&:EBBr!   )rv   )r>   r   rT   bind_masked_shimrs   )r/   rv   r   s   `` r"   r  zLoopBody.bind_masked_shim  s*    	C &&x'@'@tL
r!   )ru   rT   )r9   rT   r9   bool)NN)rw   
sympy.Exprr   rK   rG   rF   rH   rF   )!r:   r;   r<   __doc__rI   r'   rg   rf   r   r   propertyr}   r   r   r   r   r   r   r   r   r   __repr__r   r   r   r   rl   ro   r   r   r  r  r@   rA   s   @r"   rT   rT   A   s   
 *)..''77::(
%
08t*X 0 0
 F F  $$

 

 H &*"  #	
 Y#

r!   rT   c                  6    e Zd ZdZddZd Zd	dZd
dZddZy)rZ   a  
    Captures the body of a Loops subclass into an FX graph.
    In normal cases there will be a 1:1 mapping between LoopBody and
    LoopBodyBlock, hower in the case of ops.masked() the masked out
    operations will manifest as an extra LoopBodyBlock.
    c                   	
  _         d
fd	 G 	 
fddt        j                        }t        j                  j                         
t        j                  j                  
j                        
_        
j                  dddi       }dd	l
m} dd
lm}  | ||       j                   j                        }t        j                   r2 || j                   j                   j                   j"                        }t        j$                  |      5  t'        j(                   ||        d d d        
j                   _        y # 1 sw Y   xY w)Nc           	     R    j                  dd j                  | |fi |fi       S )Ncall_modulerl   )create_proxyr   )rw   r   r8   r   tracers      r"   	add_indexz)LoopBodyBlock.__init__.<locals>.add_index  s9    &&$$$T5;F;=	 r!   c                      e Zd ZdW _        d fdZdfdZd fd	Z fdZd Z fdZ	 fd	Z
	 	 	 	 	 	 	 	 d fd
Zedfd       Ze	 	 dfd       Zd Zd Zedfd	       Zefd       Zy)/LoopBodyBlock.__init__.<locals>.CaptureIndexingCaptureIndexingc                n     |t         j                  |      }| j                  j                  ||      S N)rG   )rK   rL   _innerr   )r/   rv   r   r  s      r"   r   z4LoopBodyBlock.__init__.<locals>.CaptureIndexing.load  s.    !%)=)=4P{{''e44r!   c                    t        |t              sJ j                  t        j                  |      t
        j                  |       | j                  j                  ||      S r  )	re   intr   sympyIntegerrK   rM   r  	load_seed)r/   rv   r   r   s      r"   r  z9LoopBodyBlock.__init__.<locals>.CaptureIndexing.load_seed  sV    !%---##MM%(/*C*CQU $  {{,,T599r!   Nc                t     |t         j                  ||      }| j                  j                  ||||      S )N)rG   rH   )rK   rN   r  r   )r/   rv   r   valuerH   r  s        r"   r   z5LoopBodyBlock.__init__.<locals>.CaptureIndexing.store  s9    !?00d {{((ueTBBr!   c                p     |t         j                  |      }| j                  j                  |||      S r  )rK   rO   r  store_reduction)r/   rv   r   r   r  s       r"   r"  z?LoopBodyBlock.__init__.<locals>.CaptureIndexing.store_reduction  s5    !?:: {{224FFr!   c                    | j                   j                  ||||      d|v rt        fdt        d      D              S S )Nwelfordc              3  (   K   | ]	  }|     y wr   r    r   r   r   s     r"   r   zLLoopBodyBlock.__init__.<locals>.CaptureIndexing.reduction.<locals>.<genexpr>  s      =q =      )r  	reductionr^   r   )r/   dtype	src_dtypereduction_typer   r   s        @r"   r)  z9LoopBodyBlock.__init__.<locals>.CaptureIndexing.reduction  s@    ..uiQVW.  =E!H ===r!   c                    t        |t        t        j                  f      r%| j                  j                  t        |      |      S  |t        j                        }| j                  j                  ||      S r   )	re   r  r  r  r  constantrK   rP   
index_expr)r/   r   r*  r  s      r"   r/  z:LoopBodyBlock.__init__.<locals>.CaptureIndexing.index_expr  sZ    ec5==%9:;;//E
EBB!%)C)CD{{--eU;;r!   c                     |t         j                        } |t         j                        }| j                  j                  ||||      S r   )rK   rQ   r  check_bounds)r/   r   r   lowerupperr  s        r"   r1  z<LoopBodyBlock.__init__.<locals>.CaptureIndexing.check_bounds  sB    !%)E)EF 'C'CD{{//tUEJJr!   c                t     |t         j                  |      }| j                  j                  |||||      S r  )rK   rR   r  	bucketize)r/   r_   offsets_nameoffsets_sizeindexing_dtyperightr  s         r"   r5  z9LoopBodyBlock.__init__.<locals>.CaptureIndexing.bucketize  s@      ) /";";  {{,,L, r!   c                (   j                   j                  dd      }j                   j                  |      j                   j                  |<   t	        j                   |g       j                   j
                  |<   j                  d|| |fi       S )zb
                Recursively capture the masked out body in another LoopBodyBlock
                Nmasked_subblockr  )r   r   r  r*   rZ   rW   r  )
mask_proxymasked_bodyother_proxyrv   r/   r  s       r"   r  z6LoopBodyBlock.__init__.<locals>.CaptureIndexing.masked  s    
 yy..t5FG-1YY-G-G-M		$$T*,9$))[RT,U		##D)**!4*k)BB r!   c                    j                   j                  |      }j                   j                  |d      }j                  d|| |fi       t	        fdt        t        |            D              S )Nr   r  c              3  (   K   | ]	  }|     y wr   r    r&  s     r"   r   zGLoopBodyBlock.__init__.<locals>.CaptureIndexing.scan.<locals>.<genexpr>  s     H1VAYHr'  )r   r  r   r  r^   r   r`   )dtype_proxyr   value_proxyr   rv   r   r/   r  s        @r"   r   z4LoopBodyBlock.__init__.<locals>.CaptureIndexing.scan  sm     yy//
;yy..tV<,,! +.	 Hc+6F0GHHHr!   c                    | j                   j                  ||||      t        fdt        t	        |            D              S )Nc              3  (   K   | ]	  }|     y wr   r    r&  s     r"   r   zGLoopBodyBlock.__init__.<locals>.CaptureIndexing.sort.<locals>.<genexpr>  s     C1VAYCr'  )r  sortr^   r   r`   )r/   r   r_   stable
descendingr   s        @r"   rE  z4LoopBodyBlock.__init__.<locals>.CaptureIndexing.sort  s7    ))&&&*MCc&k0BCCCr!   c                L    | j                   j                  |      }|d   |d   fS )Nr   r   )r  frexp)r/   rB  r   s      r"   rI  z5LoopBodyBlock.__init__.<locals>.CaptureIndexing.frexp  s)    **;7q	6!9--r!   c                    j                   j                  |      }j                   j                  ||||      }j                  dj                   j	                  |d|       | fi        |S )z
                Flow data from tensors into indexing formulas.
                Introduce a call_module to update the indexing.
                r  set_)r   r   r   r  r   )index_proxyr   r   r   r   r   r/   r  s         r"   r   zALoopBodyBlock.__init__.<locals>.CaptureIndexing.indirect_indexing  sr     ii,,T2#yy??uh  ##!II++LD,G N	 
r!   c                0    j                  dd| fi        y )Noutput)r  )r   r  s    r"   rN  z6LoopBodyBlock.__init__.<locals>.CaptureIndexing.output   s    ##Hh	2Fr!   )rv   rD   r   r	  )rv   rD   r   r  r   )r6  rD   r7  r	  r8  ztorch.dtyper9  r  )r=  Callable[..., Any])r   z=Callable[[Tuple[Any, ...], Tuple[Any, ...]], Tuple[Any, ...]])TT)r:   r;   r<   rv   r   r  r   r"  r)  r/  r1  r5  r=   r  r   rE  rI  r   rN  )r  r   r/   r  s   r"   r  r    s    )DI5:CG<K
 " )	
 !,  	 	 II I$D
.
  $ G Gr!   r  )
tracer_clsplaceholderr   r    r   )IndexPropagation)SimplifyIndexing)rw   r	  r   rK   )r   r   WrapperHandlerr   r   TracerGraphr0   r)   r  index_propagationrR  rq   rS  rd   r   constant_and_index_propagationrY   set_ops_handlerr   rN  )r/   r   ri   r7   r  	proxy_opsrR  rS  handlerr  r  s   ``       @@r"   r'   zLoopBodyBlock.__init__  s	   		x	G x	Ga.. x	Gt "xx~~1A1A~B''ub"E	7.'I&		(<(<
 00&--tyy/L/LG w' 	" JJr4y!	" \\
		" 	"s   EEc                    | j                   }| j                  j                  }t        ||      j	                  t        j                               S r   )r)   r   r*   r   r6   r   get_ops_handler)r/   r)   r*   s      r"   r   zLoopBodyBlock.__call__9  s;    

YY))
uj155a6G6G6IJJr!   c           
        t         j                  j                  | j                  j                  | j
                        j                  }t        j                  dd|j                         j                  dd| d            S )Nz;[^\n]* zdef forward(zdef ()r   r   GraphModuler   r*   r)   coderesubstripreplace)r/   rv   rb  s      r"   r   zLoopBodyBlock.debug_str?  sa    xx##DII$8$8$**EJJvvJJL  4vQ@	
 	
r!   c                `    t        fd| j                  j                  d      D              S )Nc              3  :   K   | ]  }|j                   v   y wr   )target)r   r   allowed_opss     r"   r   z2LoopBodyBlock.contains_only_ops.<locals>.<genexpr>I  s"      
 KK;&
r   call_method)op)r   r)   
find_nodes)r/   rj  s    `r"   r   zLoopBodyBlock.contains_only_opsH  s/     


---?
 
 	
r!   c                    t         j                  t               }|j                  j                  i | j                  d|i       |S )z'Shallow copy with a new parent LoopBodyr   )rZ   __new____dict__update)r/   r   copys      r"   rs   zLoopBodyBlock.cloneN  s:    $$]3<<vt<=r!   N)r   rT   ri   rO  r7   z	List[Any])r   r  )r   rT   )	r:   r;   r<   r
  r'   r   r   r   rs   r    r!   r"   rZ   rZ     s#    X"tK

r!   rZ   )+
__future__r   r>   r   rc  enumr   r   typingr   r   r   r	   r
   r   r   r   r  torch.fxr   torch._dynamo.utilsr   torch.utils._sympy.symbolr   r_  r   r   codegen.commonr   utilsr   r   r   virtualizedr   r   r   Interpreterr   rC   rK   rT   rZ   r    r!   r"   <module>r}     s    "   	  S S S   ( * " 4 L L 0ehh** 04* d S Sl
{ {r!   