
    Vh                        U 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	Z	d dl
Zd dlmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d d	lmZ d d
lmZmZ d dlmZmZmZ  e j@                  e!      Z"e jF                  e$d<   d Z% ee%      Z& e       Z'e'rd dl(Z(de(jR                  jR                  v Z*ndZ*ejV                  jY                         xr e'Z-ej\                  jY                         xr e'Z/ej`                  jY                         Z1e-xs e/Z2 e       Z3 e4d eD              Z5defdZ6d Z7de8de8ddfdZ9 ejt                  ejv                  e2xs e1 d      Z< ejt                  ejv                  e' d      Z=d Z> ejt                  e7d      Z? ejt                  e7d      Z@ ejt                  e7d      ZA ed       ZB ed       ZC ed        ZDdefd!ZEd" ZFd$d#ZGy)%    N)CalledProcessError)make_fx)GraphLowering)shape_env_from_inputs)CppCodeCache)get_gpu_shared_memory
is_big_gpu)	GPU_TYPESget_gpu_type)
has_triton)LazyVal	IS_FBCODE)TestCaseIS_CI
IS_WINDOWSlogc                      	 t        j                  d       t         S # t        t        t
        j                  j                  j                  t
        j                  j                  j                  f$ r Y yw xY w)N F)
r   loadr   r   OSErrortorch	_inductorexcInvalidCxxCompilerCppCompileError     V/home/dcms/DCMS/lib/python3.12/site-packages/torch/testing/_internal/inductor_utils.pytest_cpur       s_    	"}..++	  s    AA65A6cpuFc              #      K   | ]E  }t        t        |      j                         xr! t        t        |      j                         d k\   G yw)   N)getattrr   is_availabledevice_count).0gpus     r   	<genexpr>r(   A   sF       E3$$&R75#+>+K+K+MQR+RRs   AAselfc                     d}d}|j                  d      }|D ]#  }d|v sd}t        j                  d|      !d} n | j                  |d|        | j                  |d|        y )	NF
zfor(Tz;.*ks.*;z)Failed to find dynamic for loop variable
)msgzFailed to find for loop
)splitresearch
assertTrue)r)   codefor_loop_foundhas_dynamiclineslines         r   _check_has_dynamic_shaper6   F   s     NKJJtE T>!Nyyd+7" 	OOEdVL   	OON&?v$FGr   c                $    | rfd}|S d }|S )Nc                 H     t        j                          fd       }|S )Nc                     t        | d      s(d}t        | d      r|dz  }t        j                  |       | j                  k(  rt	        j
                         | g|i |S )Ndevicez>Expect the test class to have attribute device but not found. device_typezBConsider using the skip device decorators in common_device_type.py)hasattrr   warningr:   unittestSkipTest)r)   argskwargswarn_msgr:   fnr,   s       r   innerz0skipDeviceIf.<locals>.decorate_fn.<locals>.inner\   se    tX._Ht]3 $hhKK);;&("++C00$0000r   )	functoolswraps)rC   rD   r:   r,   s   ` r   decorate_fnz!skipDeviceIf.<locals>.decorate_fn[   s%    __R 1 !1 Lr   c                     | S Nr   )rC   s    r   rG   z!skipDeviceIf.<locals>.decorate_fnh   s    Ir   r   )condr,   r:   rG   s    `` r   skipDeviceIfrK   Y   s     	  	 r   namefilereturnc                    t         rt        rt        j                  j	                  |      j                  d      }t        j                  j                  d| d       | dk(  rt        j                  d       t        j                  d      y y )Nz.pyz4Windows CI does not have necessary dependencies for z tests yet
__main__r   z!requires sympy/functorch/filelock)r   r   ospathbasenamestripsysstderrwriteexitr>   r?   )rL   rM   modules      r   skip_windows_cirZ   m   sr    e!!$'--e4

B6(,W	
 :HHQK CDD zr   zrequires gpuzrequires tritonc                       fd}|S )Nc                     t         j                  j                         r+t         j                  j                         j                  k  r# t        j                  ddz  dd      |       S | S )Nz%Only if the CUDA device has at least g    eAz.3fzGB memory to be safe)r   cudar$   get_device_propertiestotal_memoryr>   skip)rC   min_mem_requireds    r   rD   z/requires_cuda_with_enough_memory.<locals>.inner|   s`    zz&&(EJJ,L,L,N,[,[^n,nz8==#HIY\_I_`cHddx!yz{}~~Ir   r   )ra   rD   s   ` r    requires_cuda_with_enough_memoryrb   {   s     Lr   r]   )r:   xpuc                  ,    t         xr t               dk(  S )Ni  HAS_CUDAr   r   r   r   <lambda>rg          H *6) r   c                  ,    t         xr t               dk(  S )Ni  re   r   r   r   rg   rg      rh   r   c                  &    t         xr
 t               S rI   )rf   r	   r   r   r   rg   rg      s    X6*, r   c                      t        d      D  cg c]  } t        j                  d       }}  t        t        j                  d      | }t        |      }t        ||      }|S c c} w )zc
    Create a graph. This is useful for unit testing code which accesses
    V.graph.sizevars.
    r"   
   fake)tracing_mode)	shape_env)ranger   randnr   addr   r   )_example_inputsgmro   graphs        r   dummy_graphrw      s`    
 05Qx8!ekk"o8N8	0	0.	AB%n5I
E
 L 9s   A$c                     | j                   dv r<dt        j                  vr*t        j                  j
                  j                  d      S t        j                         S )z
    For certain ops, there meta and eager implementation returns differents
    strides. This cause size/strides assert fail. Skip adding those
    asserts for now.
    )	fft_hfftnfft_hfft	fft_hfft2
fft_ihfftnfft_fftfft_fft2fft_fftnfft_ifft	fft_ifft2	fft_ifftn	fft_irfft
fft_irfft2
fft_irfftn	fft_ihfft
fft_ihfft2fft_rfft	fft_rfft2	fft_rfftn
linalg_eiglinalg_eigvalsTORCHINDUCTOR_SIZE_ASSERTSF)size_asserts)		aten_namerQ   environr   r   configpatch
contextlibnullcontext)ops    r   maybe_skip_size_assertsr      sP     	
	
. )

:%%+++??%%''r   c                    t        | t        j                        s| S t        j                  | | j	                         j                         | j                         z  fdd      }|s|j                         }n|j                  |d      }t        j                  || j                         | j                         | j                               }|S )N)   r   T)copy)
isinstancer   Tensor
as_strideduntyped_storagesizeelement_sizeclonetostridestorage_offset)xr:   bufferouts       r   clone_preserve_strides_offsetr      s    a&	A$$&!..*::<dAF 6-


61668QXXZ9I9I9K
LCJr   rI   )Hloggingr   r.   r>   rE   r   rQ   
subprocessr   rU   torch._inductor.async_compile"torch.fx.experimental.proxy_tensorr   torch._inductor.graphr   torch._inductor.compile_fxr   torch._inductor.codecacher   torch._inductor.utilsr   r	   r
   r   torch.utils._tritonr   $torch.testing._internal.common_utilsr   r   r   r   r   	getLogger__name__r   Logger__annotations__r   HAS_CPU
HAS_TRITONtritonbackendsTRITON_HAS_CPUr]   r$   rf   rc   HAS_XPUmpsHAS_MPSHAS_GPUGPU_TYPEanyHAS_MULTIGPUr6   rK   strrZ   partialskipIfrequires_gpurequires_tritonrb   
skipCUDAIf	skipXPUIf	skipCPUIfIS_A100IS_H100
IS_BIG_GPUrw   r   r   r   r   r   <module>r      s     	    	 ) 
 $ 6 / < 2 C 9 *  (g''1W^^ 1
 (
\
foo666NN ::""$3
))
 
 
"
1z
))
 
 
"

g>  
H
H&(E# ES ET E !y  w7I'2JN[#)##HOO^EVW Y|F;
Il59	Il59	
*
 *
 67
] "(Hr   