
    {-j                       d dl m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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 n# e$ r  eej        d          ZY nw xY wddlmZ ddlmZ dd	lmZmZ  ej        d
          Z e !                    ej"                    ej#        d          Z$ ej%                    Z&e&'                    e$           e (                    e&           ej)        Z*e*+                    d          Z,g dZ-g dZ.g dZ/dgZ0 ej1                    rg dZ2nddgZ3dZ4dZ5dZ6dZ7ej8        9                                ej8        :                                ej8        ;                                ej8        <                                ej8        =                                ej8        >                                gZ?d`dZ@d ZA ejB        dd d!g          ZC G d" d#          ZD ejB        d$g d%          ZE G d& d'          ZFd( ZGd) ZHd* ZId+ ZJdad-ZKd. ZLd/ ZMd0 ZNd1 ZOd2 ZPd3 ZQd4 ZRd5 ZSdad6ZTd7 ZUd8 ZVd9 ZWd: ZXd; ZYd< ZZdbd?Z[dad@Z\dA Z]dB Z^dcdDZ_dE Z`dF ZadadGZbdH ZcdI ZddJ ZedadddMZfdedPZgdadQZh	 dadRZidS ZjdT ZkdadUZldV Zm	 dadWZndX ZodadYZpdZ Zqdad[Zrdad\Zsd] Ztdfd_ZudS )g    )annotationsN)	machinery)DEVNULLwb   )core)OpProtoHolder)get_includeget_libzutils.cpp_extensionz)%(asctime)s - %(levelname)s - %(message)s)fmtwin)z/MTz/wd4819z/wd4251z/wd4244z/wd4267z/wd4275z/wd4018z/wd4190z/EHscz/wz/DGOOGLE_GLOG_DLL_DECLz/DBOOST_HAS_STATIC_ASSERTz/DNDEBUGz/DPADDLE_USE_DSO)
z-fno-commonz-dynamicz-DNDEBUGz-gz-fwrapvz-O3-archx86_64r   arm64)z-dynamiclibz
-undefineddynamic_lookupr   r   r   r   z/MACHINE:X64)z-DPADDLE_WITH_HIP-DEIGEN_USE_GPUz-DEIGEN_USE_HIPz-DPADDLE_WITH_CUDAr   )      r   )   r   i^  a  
                        *************************************
                        *  Compiler Compatibility WARNING   *
                        *************************************

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Found that your compiler ({user_compiler}) is not compatible with the compiler
built Paddle for this platform, which is {paddle_compiler} on {platform}. Please
use {paddle_compiler} to compile your custom op. Or you may compile Paddle from
source using {user_compiler}, and then also use it compile your custom op.

See https://www.paddlepaddle.org.cn/documentation/docs/zh/install/compile/fromsource.html
for help with compiling Paddle from source.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ax  
                            **********************************
                            *    ABI Compatibility WARNING   *
                            **********************************

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Found that your compiler ({user_compiler} == {version}) may be ABI-incompatible with pre-installed Paddle!
Please use compiler that is ABI-compatible with GCC >= 5.4 (Recommended 8.2).

See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html for ABI Compatibility
information

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
lib_filenamestrreturn	list[str]c                z    t          j        |           }t          j                                        |          }|S N)r   !load_op_meta_info_and_register_opr	   instanceupdate_op_proto)r   new_listproto_sync_opss      j/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/utils/cpp_extension/extension_utils.pyr   r      s4    5lCCH"+--==hGGN    c           	     <   t          j        d                                          }t          j                            |           \  }}|dz   |z   } g }t                                                                          rt          d           nt                                          
                                \  }}|j        }t          |          }	|	D ]$}
|                    t          |
                     %t          dt          |	           d           t!          |d          5 }|                    |                    t          j                            |           d                    |                               d	d	d	           d	S # 1 swxY w Y   d	S )
zs
    Customized write_stub function to allow us to inject generated python
    api codes into egg python file.
    a  
        {custom_api}

        import os
        import sys
        import types
        import paddle
        import importlib.abc
        import importlib.util

        cur_dir = os.path.dirname(os.path.abspath(__file__))
        so_path = os.path.join(cur_dir, "{resource}")

        def __bootstrap__():
            assert os.path.exists(so_path)
            # load custom op shared library with abs path
            custom_ops = paddle.utils.cpp_extension.load_op_meta_info_and_register_op(so_path)

            if os.name == 'nt' or sys.platform.startswith('darwin'):
                # Cpp Extension only support Linux now
                mod = types.ModuleType(__name__)
            else:
                try:
                    spec = importlib.util.spec_from_file_location(__name__, so_path)
                    assert spec is not None
                    mod = importlib.util.module_from_spec(spec)
                    assert isinstance(spec.loader, importlib.abc.Loader)
                    spec.loader.exec_module(mod)
                except ImportError:
                    mod = types.ModuleType(__name__)

            for custom_op in custom_ops:
                setattr(mod, custom_op, eval(custom_op))

        __bootstrap__()

        _pd_z6Received len(custom_op) =  0, using cpp extension onlyzReceived len(custom_op) = z, using custom operatorw

)resource
custom_apiN)textwrapdedentlstripospathsplitextCustomOpInfor   emptyprintlastso_pathr   append_custom_api_contentlenopenwriteformatbasenamejoin)r'   pyfile_stub_templatefilenameextapi_content_op_infor3   new_custom_opsop_namefs               r!   custom_write_stubrF      s   
 _$	& &L fhhM T G$$X..MHc& 3&HK$$&& 
FGGGG "**,,1133
7/:7CC% 	= 	=G27;;<<<<U^)<)<UUU	
 	
 	
 
fc		 
a	!!))(33!;;{33 "  	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   )AFFFOpInfoso_namer3   c                  B    e Zd ZdZed             Zd ZddZd Zd Z	dS )	r/   zO
    A global Singleton map to record all compiled custom ops information.
    c                N    t          | d          s |             | _        | j        S )N	_instance)hasattrrK   )clss    r!   r   zCustomOpInfo.instance   s)    sK(( 	"CEECM}r"   c                t    t          | j        d          r
J d            t          j                    | _        d S )NrK   z3Please use `instance()` to get CustomOpInfo object!)rL   	__class__collectionsOrderedDictop_info_mapselfs    r!   __init__zCustomOpInfo.__init__   sD    4>;77 	
 	
A	
 	
7 '244r"   Nc                6    t          ||          | j        |<   d S r   )rG   rR   )rT   rD   rH   r3   s       r!   addzCustomOpInfo.add   s    $*7G$<$<!!!r"   c                    t          | j                  dk    sJ t          t          | j                                                            S )z:
        Return the last inserted custom op info.
        r   )r6   rR   nextreverseditemsrS   s    r!   r2   zCustomOpInfo.last   sE     4#$$q((((HT-335566777r"   c                    | j         rdS dS )NFT)rR   rS   s    r!   r0   zCustomOpInfo.empty  s     	5tr"   r   )
__name__
__module____qualname____doc__classmethodr   rU   rW   r2   r0    r"   r!   r/   r/      sz            [
5 5 5= = = =8 8 8    r"   r/   VersionFields)sourcesextra_compile_argsextra_link_argslibrary_dirsruntime_library_dirsinclude_dirsdefine_macrosundef_macrosc                  0    e Zd Zd Zd Zed             ZdS )VersionManagerc                H    || _         |                     |          | _        d S r   )version_fieldhasherversion)rT   ro   s     r!   rU   zVersionManager.__init__  s!    *{{=11r"   c                p   ddl m} t          j                    }|j        D ]}t          ||          }|st          |t          t          t          f          r) ||          }t          |t          |                    }`t          dt          |           d| d          |                                S )Nr   )flattenz6Support types with list, tuple and dict, but received z with .)paddle.utilsrs   hashlibmd5_fieldsgetattr
isinstancelisttupledictcombine_hashRuntimeErrortype	hexdigest)rT   ro   rs   rw   fieldelem	flat_elems          r!   rp   zVersionManager.hasher   s    ((((((kmm"* 
	 
	E=%00D $ud 344 #GDMM	"3i(8(899"fTRVZZff_cfff   }}r"   c                4    | j                                         S r   )ro   _asdictrS   s    r!   detailszVersionManager.details2  s    !))+++r"   N)r]   r^   r_   rU   rp   propertyr   rb   r"   r!   rm   rm     sM        2 2 2  $ , , X, , ,r"   rm   c                n    |                      t          |                                                     | S )z
    Return new hash value.
    DO NOT use `hash()` because it doesn't generate stable value between different process.
    See https://stackoverflow.com/questions/27522626/hash-function-in-python-3-3-returns-different-results-between-sessions
    )updatereprencode)rw   values     r!   r~   r~   7  s-     JJtE{{!!##$$$Jr"   c           	     x   d }d }d}t           j                            |           }t           j                            |           }t           j                            ||          }fdt
          j        D             }t
                              |          }	t          |	          }
t           j        	                    |           rt           j        	                    |          r ||          }|
                    |d          }|\||
j        k    rSt          d| d|
j         d| d	           t          j        |            |
j        }|
j        ||<    |||           dS dS dS t           j        	                    |          st          j        |           |
j        }|
j        ||<    |||           dS )
z
    If already compiling source before, we should check whether cflags
    have changed and delete the built object to re-compile the source
    even though source file content keeps unchanged.
    c                    t          |t                    sJ t          | d          5 }|                    t	          j        |dd                     d d d            d S # 1 swxY w Y   d S )Nr%   r   T)indent	sort_keys)rz   r}   r7   r8   jsondumps)r-   version_inforE   s      r!   	serializez0clean_object_if_change_cflags.<locals>.serializeH  s    ,-----$__ 	HGGDJ|AFFFGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   +A  A$'A$c                    t           j                            |           sJ t          | d          5 }|                                }t          j        |          cd d d            S # 1 swxY w Y   d S )Nr)r,   r-   existsr7   readr   loads)r-   rE   contents      r!   deserializez2clean_object_if_change_cflags.<locals>.deserializeM  s    w~~d#####$__ 	'ffhhG:g&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   (A''A+.A+zversion.txtc                2    g | ]}t          |d           S r   )ry   ).0r   	extensions     r!   
<listcomp>z1clean_object_if_change_cflags.<locals>.<listcomp>Z  s%    OOOGIud++OOOr"   NzRe-Compiling z<, because specified cflags have been changed. New signature z has been saved into rt   )r,   r-   dirnamer:   r;   rc   rx   _makerm   r   getrq   log_vremover   makedirs)r3   r   r   r   VERSION_FILEbase_dirrH   version_fileargsro   	versionerold_version_info
so_versionnew_version_infor   s    `             r!   clean_object_if_change_cflagsr   A  s    H H H
' ' ' !Lww''Hgw''G7<<,77L POOO9NOOOD!''--M}--I	w~~g )27>>,#?#? )&;|44%))'488
!jI4E&E&E ]  ]  ]enev  ]  ]  NZ  ]  ]  ]   Ig(0(1(9W%Il$455555 "!&E&E w~~h'' 	"K!!!#$,	,(((((r"   c                    t          j                    rg t          dd| t          |           } nJt          j        d          rg t
          dd| } n&g t
          dddddd| t          |           } | S )	M
    Prepare all necessary compiled flags for nvcc compiling CUDA files.
    z
-Xcompilerz-fPICiluvatar_gpuz-DPADDLE_WITH_COREXz-ccbinccz--expt-relaxed-constexprz-DNVCC)r   is_compiled_with_rocmCOMMON_HIPCC_FLAGSget_rocm_arch_flagsis_compiled_with_custom_deviceCOMMON_NVCC_FLAGSget_cuda_arch_flagscflagss    r!   prepare_unix_cudaflagsr   t  s     !## 



 
 	

 !((
 
	,^	<	< 
N$NgN/DNvN





 

 	


 

 '

 

 

 !((

 Mr"   c                >    g t           d| t          |           } | S )r   -w)r   r   r   s    r!   prepare_win_cudaflagsr     s-     O N$NN2Ef2M2MNFMr"   Fc                    |dk    rdndt          fd| D                       s"|rdnd}|z   }|                     |           dS dS )zG
    Append -std=c++14/17 in cflags if without specific it before.
    msvcz/std:z-std=c              3      K   | ]}|v V  	d S r   rb   )r   flagcpp_flag_prefixs     r!   	<genexpr>z)add_std_without_repeat.<locals>.<genexpr>  s(      ::4$&::::::r"   zc++17zc++14N)anyr4   )r   compiler_type	use_std17suffixcpp_flagr   s        @r!   add_std_without_repeatr     sw     "/&!8!8gggO::::6:::::  %27"V+h   r"   c                    g S )z
    For an arch, say "6.1", the added compile flag will be
    ``-gencode=arch=compute_61,code=sm_61``.
    For an added "+PTX", an additional
    ``-gencode=arch=compute_xx,code=compute_xx`` is added.
    rb   r   s    r!   r   r     s	     Ir"   c                    g | dddd} | S )zE
    For ROCm platform, amdgpu target should be added for HIPCC.
    z-fno-gpu-rdcz-amdgpu-target=gfx906z-amdgpu-target=gfx926z-amdgpu-target=gfx928rb   r   s    r!   r   r     s>    	 	  	 	
 	 F Mr"   c                     ddl } t          j                            t          j                            | j                  d          S )z)
    Return installed base dir path.
    r   Nbase)paddler,   r-   r;   r   __file__)r   s    r!   _get_base_pathr     s3     MMM7<<88&AAAr"   c                 "    t           rdnd} d| z   S )z(
    Return pybind DSO module name.
    .pyd.so	libpaddle)
IS_WINDOWS)ext_names    r!   _get_core_namer     s     $.vvH!!r"   c                     t                      } d| dd          d}t          j                            t	                      |          S )z=
    Return real path of libcore_(no)avx.dylib on MacOS.
    libN.dylib)r   r,   r-   r;   r   )raw_core_namelib_core_names     r!   _get_lib_core_pathr     sD     #$$M4-,444M7<<((-888r"   c                 Z    t           j                            t                      d          S )z3
    Return real path of libpaddle on Windows.
    zlibpaddle.dll)r,   r-   r;   r   rb   r"   r!   _get_dll_core_pathr     s      7<<((/:::r"   c                    t           j                            |           sJ t                              d          r/d}dt                       }d| d| d|  }t          |           dS dS )a  
    NOTE(Aurelius84): Runtime path of libpaddle.so is modified into `@loader_path/../libs`
    in setup.py.in. While loading custom op, `@loader_path` is the dirname of custom op
    instead of `paddle/base`. So we modify `@loader_path` from custom dylib into `@rpath`
    to ensure dynamic loader find it correctly.

    Moreover, we will add `-rpath site-packages/paddle/base` while linking the dylib so
    that we don't need to set `LD_LIBRARY_PATH` any more.
    darwinz@loader_path/../libs/z@rpath/zinstall_name_tool -change  N)r,   r-   r   OS_NAME
startswithr   run_cmd)r3   origin_runtime_pathrpathcmds       r!   _reset_so_rpathr     s     7>>'"""""(## 5,.**,,P)<PPuPPwPP 	 	 r"   c                |   d}t           j                            |           }t           j                            ||          }t           j                            |          sJ d| d            t          |d          5 }d |D             }ddd           n# 1 swxY w Y   dg}t          |          }|D ][}|D ]V}t           j                            ||          }	t           j                            |	          r|                    |	           W\|                    |           |	                                 |S )zV
    Get all include directories when compiling the PaddlePaddle
    source code.
    zincludes.txtzFile z does not existr   c                ^    g | ]*}|                                 |                                 +S rb   strip)r   lines     r!   r   z4_get_include_dirs_when_compiling.<locals>.<listcomp>  s-    CCCdjjllC

CCCr"   Nzpaddle/base/platform)
r,   r-   abspathr;   isfiler7   r{   isdirr4   sort)
compile_dirinclude_dirs_filer-   rE   ri   
extra_dirsall_include_dirs	extra_dirinclude_dirds
             r!    _get_include_dirs_when_compilingr     s   
 '7??;''DT+<==7>>+,,  2!222 , 
	%	% DCCCCCD D D D D D D D D D D D D D D ))JL)) + +	' 	+ 	+K[)44Aw}}Q + ''***	+ D!!!s   ?BBBc                 	   t          | t                    sJ g }|                     dd          }|rt          |          }t	          |                     dg                     }d |D             }|                    |           |                    t                                 |                    t          |                     |                    t                                 || d<   |                     dg           }|                    t          |                     || d<   |                     dg           }t          |t                    rdD ]}||vrg ||<   t          rt|                     dg           }|                    t                     t                      }	|                    |	            |r|                    d	d
g           || d<   n5|                     dg           }t                              d          r(|                    ddt!                       dg           nJ|                    dt#                                  t                      }	|                    d|	            t%          |dg           |r>t'          j                    r|                    d           n|                    d           || d<   |                     dg           }
|
                    t          |                     |
| d<   |t%          |dg           t'          j                    r9t-          j        d          }|r"d t1          j        d|          D             }t	          |                    dg                     }g }|D ]}d |                    d          D             }t5          |          dv sJ d|             t5          |          dk    r|d         d z  |d!         z   }n|d         }|                    |           t7          t9          |                    }|D ]}|                    d"d#| d$| g            t;          j        |          }||d<   || d<   d%| d&<   | S )'zM
    Normalize include_dirs, library_dir and other attributes in kwargs.
    _compile_dirNri   c                6    g | ]}t          j        |          S rb   )r,   fsdecode)r   r   s     r!   r   z.normalize_extension_kwargs.<locals>.<listcomp>  s"    MMMBK,,MMMr"   rg   re   )cxxnvccrf   zcudadevrt.libzcudart_static.liblinuxz-Wl,--no-as-neededz-l:z-Wl,--as-neededz-Wl,-rpath,z-lr   z
-lamdhip64z-lcudartrh   z-DPADDLE_WITH_CUSTOM_KERNELPADDLE_CUDA_ARCH_LISTc                ^    g | ]*}|                                 |                                 +S rb   r   )r   ss     r!   r   z.normalize_extension_kwargs.<locals>.<listcomp>j  s=       aggii		  r"   z;|\s|\,r  c                0    g | ]}|t          |          S rb   )int)r   sss     r!   r   z.normalize_extension_kwargs.<locals>.<listcomp>p  s#    ;;;";c"gg;;;r"   rt   )      zinvalid sm format: r  r   
   r  z-gencodezarch=compute_z	,code=sm_zc++language)rz   r}   r   r   r{   extend"find_paddle_custom_device_includesfind_paddle_includesfind_python_includesfind_paddle_librariesr   MSVC_LINK_FLAGScreate_sym_link_if_not_existr4   r   r   r   r   add_compile_flagr   r   is_compiled_with_cudar,   getenvresplitr6   sortedsetcopydeepcopy)kwargsuse_cudacompile_include_dirsr   ri   rg   re   compilerrf   r   rh   	arch_listnvcc_optionssmsr  sms                   r!   normalize_extension_kwargsr'    s    fd##### **^T22K M?LL 

>26677LMMMMML,---:<<===,X66777,..///)F> ::nb11L-h77888)F>  $8"==$d++ 2' 	2 	2H111/1"8, 0> **%6;;///466-1222 	K""O5H#IJJJ$3 !! !**%6;; g&& 	9 ""(,.**,,%    ""#C1A1A#C#CDDD 9::M""#7#7#7888 	+dV444 	3)++ 3&&|4444&&z222$3 !  &zz*@"EE##$9($C$CDDD)=%&+.K-LMMM!## 6I566	 	6 #%8J	#B#B  I   2 6 6vr B BCCLC  ;;;;;2ww&(((*C*C*C(((r77a<<Abe+BBAB

2S""C  ##!B!B!Bb!B!BC    "&/A!B!B)5v&#5F F:Mr"   c                 f   t                               d          s	t          sJ t                      } t          j                            t                      |           }t          rt                      }t          j        	                    |          s]	 t	          j
        ||           nF# t          $ r9 t          j        d|  d| d| d|  d	           t          d| d|            Y nw xY wt          j        	                    |          sJ | dd	         d
z   S t                      }t          j        	                    |          s_	 t	          j
        ||           t          j        	                    |          sJ n'# t          $ r t!          d|  d| d| d          w xY w| dd         S )z3
    Create soft symbol link of `libpaddle.so`
    r   z&Failed to create soft symbol link for z[.
 You can run prompt as administrator and execute the following command manually: `mklink r   z$`. Now it will create hard link for z	 trickly.z
mklink /H Nz.libz9.
 Please execute the following command manually: `ln -s `r   )r   r   r   r   r,   r-   r;   r   r   r   symlink	Exceptionwarningswarnr   r   r   )r   	core_pathnew_dll_core_pathnew_lib_core_paths       r!   r  r    sA    h''5:555"$$M^--}==I ".00w~~/00 	FF
9&78888 F F FW] W W;LW WOXW W LW W W   D%6DDDDEEEEEF w~~/00000SbS!F** /00w~~/00 	
9&7888w~~&7888888   " g]  g  g  GP  g  g  Sd  g  g  g   SbS!!s   B) )A C,+C,6F $F&c                    d} t           j                            dd                              t           j                  }|D ]E}t           j                            |d          }t           j                            |          r|}  nF| Yt           j        dk    rdnd}	 t          j
        |dg                                                                          } n	#  d} Y nxY w| d}|d	z  }t          j        |           | S )
z2
    Use heuristic method to find ccache path
    NPATH ccachentwherewhichzTNo ccache found. Please be aware that recompiling all source files may be required. zeYou can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md)r,   environr   r  pathsepr-   r;   r   name
subprocesscheck_outputdecoder   r-  r.  )ccache_pathpathsr-   ccache_candidate	which_cmdwarning_messages         r!   find_ccache_homerD    s    KJNN62&&,,RZ88E  7<<h777>>*++ 	*KE	
 !w$GGG		'H(=>>EEGGMMOO K	KKKp  C  	Co&&&s   :C C c                    t           j                            d          pt           j                            d          } | t          rdnd}	 t	          t           j        d          5 }t          j        |dg|          }|                                }|	                    d	          d
         }t           j
                            t           j
                            |                    } ddd           n# 1 swxY w Y   n@#  t          r0t          j        d          }t          |          d
k    r|d
         } nd} Y nxY w| r4t           j
                            |           st          j                    rd} | S )z0
    Use heuristic method to find cuda path
    	CUDA_HOME	CUDA_PATHNr7  r8  r%   r  stderr
r   z7C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v*.*z/usr/local/cuda)r,   r9  r   r   r7   devnullr<  r=  r>  r  r-   r   globr6   r   r   r  )	cuda_homerB  rK  	nvcc_pathcandidate_pathss        r!   find_cuda_homerP    s   
 
{++Jrz~~k/J/JI )6GGw		.bj#&& 	H'&3'  	 &,,..	%OOF33A6	 GOOBGOOI,F,FGG		H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H		. ."&)Q# # ''!++ / 2I-	 	y)) &((
 	s1   D (BC8,D 8C<<D ?C< D ;Ec                 |   t           j                            d          pt           j                            d          } | t          rdnd}	 t	          t           j        d          5 }t          j        |dg|          }|                                }|	                    d	          }t           j
                            t           j
                            |                    } ddd           n# 1 swxY w Y   n	#  d
} Y nxY w| r4t           j
                            |           st          j                    rd} | S )z0
    Use heuristic method to find rocm path
    	ROCM_HOME	ROCM_PATHNr7  r8  r%   hipccrH  rJ  z	/opt/rocm)r,   r9  r   r   r7   rK  r<  r=  r>  rstripr-   r   r   r   r   )	rocm_homerB  rK  
hipcc_paths       r!   find_rocm_homerX    sv   
 
{++Jrz~~k/J/JI )6GGw		$bj#&& I''4(  
 (..00
'..v66
 GOOBGOOJ,G,GHH	I I I I I I I I I I I I I I I	$#III 	y)) &((
 	s1   C= 'A>C1%C= 1C55C= 8C59C= =Dc                     t                      } | t          d          t          j                            | d          g d}fd|D             }d |D             S )z8
    Use heuristic method to find cuda include path
    NINot found CUDA runtime, please use `export CUDA_HOME=XXX` to specific it.include)r4  ccclnvtx3c                P    g | ]"}t           j                            |          #S rb   )r,   r-   r;   )r   subbase_includes     r!   r   z&find_cuda_includes.<locals>.<listcomp>%  s)    AAARW\\,,,AAAr"   c                P    g | ]#}t           j                            |          !|$S rb   )r,   r-   r   r   ps     r!   r   z&find_cuda_includes.<locals>.<listcomp>&  s+    222!q 1 12A222r"   )rP  
ValueErrorr,   r-   r;   )rM  sub_dirsr@  r`  s      @r!   find_cuda_includesrf    sz       IW
 
 	
 7<<	955L$$$HAAAAAAAE22u2222r"   c                     t                      } | t          d          t          j                            | d          gS )z8
    Use heuristic method to find rocm include path
    NzJNot found ROCM runtime, please use `export ROCM_PATH= XXX` to specific it.r[  rX  rd  r,   r-   r;   )rV  s    r!   find_rocm_includesri  )  sE       IX
 
 	
 GLLI..//r"   include_rootos.PathLike[str] | strc                
   t           j                            | d          }| |g}t          sWt           j                            | d          }t           j                            | d          }|                    ||g           |S )zR
    Get all paddle include directories from include root (packaged in wheel)
    third_partyzpaddle/phi/api/include/compatz4paddle/phi/api/include/compat/torch/csrc/api/include)r,   r-   r;   r   r  )rj  third_party_dirri   compat_dir_rootcompat_dir_api_includes        r!   *_get_all_paddle_includes_from_include_rootrq  6  s     gll<??O /2L G',,9
 
 "$B"
 "
 	_.DEFFFr"   c                   t                      }t          |          }| rZt          j                    r$t	                      }|                    |           n#t                      }|                    |           t                              d          rDt                      }|4t          j                            |          r|                    |           |S )z3
    Return Paddle necessary include dir path.
    r   )r
   rq  r   r   ri  r  rf  r   r   find_clang_cpp_includer,   r-   r   r4   )r   paddle_include_dirri   rocm_include_dircuda_include_dirstd_v1_includess         r!   r  r  J  s    
 %= L  2%'' 	2133 01111133 0111(## 1022&27>>/+J+J&000r"   c                 h   g } t          j                    }|s| S |d         }t          j        |          r|t          j        d          }|rUt          j                            |d          }t          j                            |          r|                     |           nt          d          | S | S )zA
    Return Paddle Custom Device necessary include dir path.
    CUSTOM_DEVICE_ROOTr[  zXNot found CUSTOM_DEVICE_ROOT, please use `export CUSTOM_DEVICE_ROOT=XXX` to specific it.)
r   get_all_device_typer   r,   r  r-   r;   r   r4   rd  )ri   devicesdevicecustom_device_rootr   s        r!   r  r  e  s     L&((G R[F*622 
Y';<< 	',,'99EEKw~~k** 1##K000j   r"   c                 |    t          j        dt          rdnd          } | t          | t                    sJ | gS g S )z8
    Return necessary include dir path of Python.h.
    r[  r6  posix_prefix)scheme)	sysconfigget_pathr   rz   r   )python_include_paths    r!   r  r  ~  sW     $,*@$$.   &-s33333#$$Ir"   clangc                   d }	 t          j        | dg          }|                                }|                    d          }|D ]}d|v r|                    d          d                                         }|r\t
          j                            |          r=t
          j                            t
          j        	                    |          d          }n$# t          $ r t          j        d           Y nw xY w|S )Nz	--version
InstalledDir:ry  zinclude/c++/v1zWFailed to search `include/c++/v1/` include dirs. Don't worry because it's not required.)r<  r=  r>  r  r   r,   r-   r   r;   r   r,  r-  r.  )r"  rw  compiler_versioninfosinfov1_paths         r!   rs  rs    s   O
%2Hk3JKK+2244 &&t,, 	 	D%%**S//"-3355 rw~~g66 &(gll002B' 'O		  
 
 
e	
 	
 	
 	
 	


 s   CC C98C9c                     t                      } | t          d          t          r#t          j                            | dd          g}n!t          j                            | d          g}|S )z;
    Use heuristic method to find cuda static lib path
    NrZ  r   x64lib64)rP  rd  r   r,   r-   r;   )rM  cuda_lib_dirs     r!   find_cuda_librariesr    sn       IW
 
 	
  :Yu==>Y889r"   c                     t                      } | t          d          t          j                            | d          g}|S )z<
    Use heuristic method to find rocm dynamic lib path
    NzINot found ROCM runtime, please use `export ROCM_PATH=XXX` to specific it.r   rh  )rV  rocm_lib_dirs     r!   find_rocm_librariesr    sJ       IW
 
 	
 GLLE223Lr"   c                   t                      g}| rZt          j                    r$t                      }|                    |           n#t                      }|                    |           |                    t                                 |S )z3
    Return Paddle necessary library dir path.
    )r   r   r   r  r  r  r4   r   )r   paddle_lib_dirsr  r  s       r!   r  r    s    
 yykO 1%'' 	1.00L""<0000.00L""<000 >++,,,r"   c                    t          |t                    sJ t          | t                    r.|                                 D ]}|                    |           d S |                     |           d S r   )rz   r{   r}   valuesr  )re   flagsr   s      r!   r  r    s    eT"""""$d++ )&--// 	 	DKK	 	 	!!%(((((r"   c                    | j                             d          }|d         }d| }t          | j        |g           d S )Nrt   ry  z-DPADDLE_EXTENSION_NAME=)r;  r  r  re   )r   namesr;  defines       r!   define_paddle_extension_namer    sH    N  %%E9D...FY1F8<<<<<r"   c                    dh}t           j                            |           }t          |          dk    sJ |d         |v S )Nz.cur  ry  )r,   r-   r.   r6   )r-   cuda_suffixr[   s      r!   is_cuda_filer    s@    'KGT""Eu::>>>>9##r"   verboseboolc                   t           j                            d          }|yd}t           j                            t           j                            d          |          }t          rt           j                            |          }t          d| d|            t           j        	                    |          st          j
        |           |S )a  
    Return paddle extension root directory to put shared library. It could be specified by
    ``export PADDLE_EXTENSION_DIR=XXX`` . If not set, ``~/.cache/paddle_extension`` will be used
    by default.

    Returns:
        The root directory of compiling customized operators.

    Examples:

    .. code-block:: python

        >>> from paddle.utils.cpp_extension import get_build_directory

        >>> build_dir = get_build_directory()
        >>> print(build_dir)

    PADDLE_EXTENSION_DIRNpaddle_extensionsz~/.cachez.$PADDLE_EXTENSION_DIR is not set, using path: z by default.)r,   r9  r   r-   r;   
expanduserr   normpathr   r   r   )r  root_extensions_directorydir_names      r!   get_build_directoryr    s    & !#
/E F F (&$&GLLGz**H%
 %
!  	(*(8(8)) )% 	d=Vddd	
 	
 	

 7>>344 /
-...$$r"   rD   &tuple[list[str], list[str], list[str]]c                   | t          j                    j        vrt          d|  d          t          j                                        |           }d |j        D             }d |j        D             }d |j        D             }|||fS )zh
    Parse input names and outputs detail information from registered custom op
    from OpInfoMap.
    zPlease load zc shared library file firstly by `paddle.utils.cpp_extension.load_op_meta_info_and_register_op(...)`c                    g | ]	}|j         
S rb   r;  r   xs     r!   r   z!parse_op_info.<locals>.<listcomp>#  s    0001000r"   c                8    g | ]}|j         t          v|j         S rb   )r;  DEFAULT_OP_ATTR_NAMESr  s     r!   r   z!parse_op_info.<locals>.<listcomp>$  s.       !&8M*M*M*M*M*Mr"   c                    g | ]	}|j         
S rb   r  r  s     r!   r   z!parse_op_info.<locals>.<listcomp>'  s    222A222r"   )r	   r   op_proto_maprd  get_op_protoinputsattrsoutputs)rD   op_protoin_names
attr_names	out_namess        r!   parse_op_infor    s    
 m,..;;; H7  H  H  H
 
 	
 %''44W==H00000H    J 32!1222IZ**r"   c           	        t           rd}nt                              d          rd}nd}t          j                            || |z             }t          j                            |          st          d| d          t          d| |           t          |          }t          j
        dk    st          j                            d          rt          | |||          S 	 t          j                            | |          }|J t          j                            |          }t%          |j        t          j        j                  sJ |j                            |           n1# t.          $ r$ t          d
           t          | |||          cY S w xY wt          | |||          }|D ]!}	t1          ||	t3          ||	                     "|S )zF
    Load shared library and import it as callable python module.
    r   r   r   r   zExtension path:  does not exist.zloading shared library from: r6  Nzusing custom operator only)r   r   r   r,   r-   r;   r   FileNotFoundErrorr   r   r;  sysplatform_generate_python_module	importlibutilspec_from_file_locationmodule_from_specrz   loaderabcLoaderexec_moduleImportErrorsetattrry   )
module_namebuild_directoryr  dynamic_suffixext_pathop_namesspecmodule	op_modulerD   s
             r!   _import_module_from_libraryr  ,  s     			H	%	% !w||O[>-IJJH7>>(## O M8 M M MNNN 

4(
4
4g>>>0::H	w$#,11(;;&?G
 
 	


~55k8LL0066$+y}';<<<<<'''' 
 
 
*+++&?G
 
 	
 	
 	

 (X I  > >G!<!<====Ms   #BE' '+FFc                  	 d 	t          t          j                    j                  }t          j                            || dz   |z   dz             t          d |           t          j	        	fd           d |D             }t          d          5 }|                    d                    |                     d	d	d	           n# 1 swxY w Y   t          | |          }|S )
zS
    Automatically generate python file to allow import or load into as module
    c                p    t           j                            |           rt          j        |            d S d S r   )r,   r-   r   r   )filepaths    r!   remove_if_exitz/_generate_python_module.<locals>.remove_if_exita  s8    7>>(## 	 Ih	  	 r"   rA   z.pyzgenerate api file: c                                 S r   rb   )api_filer  s   r!   <lambda>z)_generate_python_module.<locals>.<lambda>n  s    NN844 r"   c                ,    g | ]}t          |          S rb   )r5   )r   rD   s     r!   r   z+_generate_python_module.<locals>.<listcomp>q  s!    HHHG&w//HHHr"   r%   r&   N)r   	threadingcurrent_threadidentr,   r-   r;   r   atexitregisterr7   r8   _load_module_from_file)
r  r  r  r  	thread_idr@   rE   custom_moduler  r  s
           @@r!   r  r  Z  s@         I,..455Iw||s*Y6> H 

*
*
*G444 O44444555 IHxHHHK	h		 *	K(()))* * * * * * * * * * * * * * * +8['JJMs   )CCCc                   d}d| d}d| d| d| d| d| d| d	| d
| d| d| d|  d}	t          |          D ]\  }
}d}|
|v r||
         }|dk    rd||         v rd||         v r||                             d          d                                         }|d| d| d| d| d| d| d| d| d| dz  }t          r|	d| d| d| d| d| dz  }	|	d| d| d| d| d | 
z  }	|dk    rwd||         v rm||                             d          d                                         }|d| d!| d| d"| d#	z  }t          r|	d| d$| d| dz  }	!|	d| d$| d | z  }	1|dk    rd||         v r|||                             d          d                                         }|d| d| d| d%| d| d| d&z  }t          r|	d| d| d| d| d'	z  }	|	d| d| d| d| d | 
z  }	|dk    r=t          s6||                                         }|d| d(| d&z  }|	d| d$| d | z  }	 |d| d(| d&z  }|	d| d$| d'z  }	|d| d)z  }|	d| d*|  d+| d| d,| d)z  }	||	fS )-Nz        z	res = []
zstart_idx = 0z	ins = {}
z
ins_map = r  z
outs = {}
zouts_list = z#for key, value in ins_map.items():
z    # handle optional inputs
z    if value is not None:
z        ins[key] = value
zhelper = LayerHelper("z", **locals())
ry  z@VECTORz	@OPTIONAL@r   zif z is not None:
z/    res.append(outs[start_idx: start_idx + len(z)])
z    start_idx += len(z)
zelse:
z    res.append(None)
z    start_idx += 1z
    outs['zA'] = [helper.create_variable(dtype='float32') for _ in range(len(z))]z'] = z+res.append(outs[start_idx: start_idx + len(zstart_idx += len()zouts['z     res.append(outs[start_idx])
zstart_idx += 1z,'] = helper.create_variable(dtype='float32')zres.append(outs[start_idx])
z%return res[0] if len(res)==1 else reszhelper.append_op(type="z#", inputs=ins, outputs=outs, attrs=zVres = [outs[out_name] if out_name in outs.keys() else None for out_name in outs_list]
)	enumerater  lowerr   )rD   r  r  ins_map	attrs_map	outs_listinplace_reverse_idxr   dynamic_contentstatic_contentout_idxout_namein_idxlower_in_namess                 r!   _gen_output_contentr  z  s    F  O		 		 		 	 	 	 	 	 		 	
 	 	 	 	 	 	 	 	  '	 	 	N 'y11 HH HH)))(1FbLLXf---x/// &f-33C88;AACCN           8F        -    	   
           O  5 #t#t #t#t #t#t #t#t #t^l#t #t #t t  #5#5 #5#5 #5#5 #5#5 #5"0#5 #5 5
 bLLY(6*:::%f-33C88;AACCN  . .  .4B .  . .  .( .  .  . .O  1 #p#p #p#p #pZh#p #p #p p  #1#1 #1#1 #1,#1 #1 1 bLL[HV,<<<%f-33C88;AACCN                	   
       O  5 #L#L #L#L #L#L #L#L #L #L L  #5#5 #5#5 #5#5 #5#5 #5"0#5 #5 5 bLLL%f-3355N           O  11 11 1,1 1 1NN            O  HH HH H H HNN  11 1 1 1O  11 1 '1 1LU1 11 1 1 1 1 1N
 N**r"   c           	         t          |           \  }}}}}}}}t          | ||||||          \  }	}
t          j        d                                          }|                    | ||	|
          }|S )Nak  
        from paddle import _C_ops
        from paddle.framework import in_dynamic_or_pir_mode
        from paddle.base.layer_helper import LayerHelper
        from paddle.jit.marker import unified

        @unified
        def {op_name}({params_list}):
            # The output variable's dtype use default value 'float32',
            # and the actual dtype of output variable will be inferred in runtime.
            if in_dynamic_or_pir_mode():
                outs = _C_ops._run_custom_op("{op_name}", {params_list})
                {dynamic_content}
            else:
                {static_content}
            )rD   params_listr  r  )_get_api_inputs_strr  r)   r*   r+   r9   )rD   r  r  r  r  r  r  r  r  r  r  API_TEMPLATEr@   s                r!   r5   r5     s     	G$$	&9' '#O^ ?	 " fhh# ( %%'%	 &  K r"   c                v   t           j                            |           st          d|  d          t	          d|  |           d|z   }t          j        ||           }t          j        	                    |j
        |          }t          j                            |          }|                    |           |S )z'
    Load module from python file.
    zFile : r  zimport module from file: _paddle_cpp_extension_)r,   r-   r   r  r   r   SourceFileLoaderr  r  spec_from_loaderr;  r  r  )api_file_pathr  r  r   r  r  r  s          r!   r  r    s     7>>-(( K I- I I IJJJ 

5m
5
5w???'+5H '-@@F>**6;??D^,,T22F
vMr"   c                   t          |           \  }}}||z   }d                    d |D                       }d                    d                    d |D                                 }d                    d                    d |D                                 }d                    d                    d |D                                 }t          j                            |           }	||||||||	fS )z;
    Returns string of api parameters and inputs dict.
    ,c                h    g | ]/}|                     d           d                                         0S )r  r   )r  r  rb  s     r!   r   z'_get_api_inputs_str.<locals>.<listcomp>6  s2    IIIAGGCLLO1133IIIr"   z{{{}}}c                    g | ]C}d                      ||                    d          d                                                   DS z	'{}' : {}r  r   r9   r  r  )r   in_names     r!   r   z'_get_api_inputs_str.<locals>.<listcomp>:  sU        ""7GMM#,>,>q,A,G,G,I,IJJ  r"   c                    g | ]C}d                      ||                    d          d                                                   DS r  r  )r   	attr_names     r!   r   z'_get_api_inputs_str.<locals>.<listcomp>C  sU        ""9iooc.B.B1.E.K.K.M.MNN  r"   z[{}]c                    g | ]}d | d 	S )'rb   r   r;  s     r!   r   z'_get_api_inputs_str.<locals>.<listcomp>J  s     'J'J'JD'J'J'Jr"   )r  r;   r9   r   eager _get_custom_operator_inplace_map)
rD   r  r  r  param_namesr  r  r  r  r  s
             r!   r  r  ,  s.    '4G&<&<#Hj)Z'K ((II[IIIJJKoo '  	
 	
 G  !+  	
 	
 I chh'J'J	'J'J'JKKLLI*EEgNN 		 	r"   c
                4   t          j        d                                          }
d}t          d |D                       rd}t	          d| |	           |
                    | |rdndt          |          t          |          t          |          t          |          t          |          t          |          |	  	        }t	          d	| |	           t          |d
          5 }|                    |           ddd           dS # 1 swxY w Y   dS )zL
    Automatically generate setup.py and write it into build directory.
    a  
    import os
    from paddle.utils.cpp_extension import CppExtension, CUDAExtension, BuildExtension, setup
    from paddle.utils.cpp_extension import get_build_directory


    setup(
        name='{name}',
        ext_modules=[
            {prefix}Extension(
                sources={sources},
                include_dirs={include_dirs},
                library_dirs={library_dirs},
                extra_compile_args={{'cxx':{extra_cxx_cflags}, 'nvcc':{extra_cuda_cflags}}},
                extra_link_args={extra_link_args})],
        cmdclass={{"build_ext" : BuildExtension.with_options(
            output_dir=r'{build_dir}',
            no_python_abi_suffix=True)
        }})Fc              3  4   K   | ]}t          |          V  d S r   )r  )r   sources     r!   r   z$_write_setup_file.<locals>.<genexpr>  s*      
6
6F<
6
6
6
6
6
6r"   Tzwith_cuda: CUDACpp)	r;  prefixrd   ri   rg   extra_cxx_cflagsextra_cuda_cflagsrf   	build_dirzwrite setup.py into r%   N)	r)   r*   r+   r   r   r9   list2strr7   r8   )r;  rd   	file_pathr  ri   rg   r  r  	link_argsr  template	with_cudar   rE   s                 r!   _write_setup_filer  Z  sx    	 ( fhh) , I

6
6g
6
6
666 		
#	
#
#W---oo"-vv!!l++l++!"233"#455 ++  
 
G 

,
,
,g666	i		 	                 s   *DDDc                |    | dS t          | t          t          f          sJ d | D             } t          |           S )zP
    Convert list[str] into string. For example: ['x', 'y'] -> "['x', 'y']"
    Nz[]c                    g | ]}| S rb   rb   )r   args     r!   r   zlist2str.<locals>.<listcomp>  s    %%%sH%%%r"   )rz   r{   r|   r   )r   s    r!   r  r    sG     |tdT5M*****%%%%%D::r"   c                v   t           j                            |           sJ t           j                            |           }t           j                            |           }t
          j        }	 t          j        |dg          }|	                                }t          d| d|                                 |           n:# t          $ r- t          j                    \  }}}t          d| d|           w xY wt          rd| d| d| d	}nd
| d| d| d	}t!          d           t#          ||           dS )z,
    Build shared library in subprocess
    z-VzUsing Python interpreter: z, version: z)Failed to check Python interpreter with `z`, errors: zcd /d z && r   z buildzcd z9Compiling user custom op, it will cost a few seconds.....N)r,   r-   r   r   r:   r  
executabler<  r=  r>  r   r   r,  exc_infor   r   r1   r   )	r  r  ext_dir
setup_fileinterpreter
py_versionrA   errorcompile_cmds	            r!   _jit_compiler+    sy    7>>)$$$$$gooi((G!!),,J .K
,k4-@AA
&&((
UUUAQAQASASUU	
 	
 	
 	
  
 
 
lnn5!WWWPUWW
 
 	

  JLwLLKLL*LLLIGIIIIzIII	
EFFFK!!!!!s   -AC   7C7c                    d }t                      }| D ]L}t          |d          5 }|                                }| ||          z  }ddd           n# 1 swxY w Y   Mt          |          S )z8
    Parse registering custom op name from sources.
    c                    t          j        d          }t          j        dd|           } |                    |           }d |D             }|S )NzPD_BUILD_OP\(([^,\)]+)\)z\s|\t|\nr4  c                :    h | ]}t          j        d d|          S )_gradr4  )r  r_  r  s     r!   	<setcomp>z4parse_op_name_from.<locals>.regex.<locals>.<setcomp>  s&    AAA26'2t,,AAAr"   )r  compiler_  findall)r   patternrD   s      r!   regexz!parse_op_name_from.<locals>.regex  sN    *899&b'22//'**AAAAAr"   r   N)r  r7   r   r{   )rd   r4  r  r  rE   r   s         r!   parse_op_name_fromr5    s    
   uuH ' '&# 	'!ffhhGg&H	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' >>s   #AA	A	c                &   t          d|  |           	 |r!t          j        | dt          j                  S t          j        | dt                    S # t
          $ r2 t          j                    \  }}}t          dt           d|           w xY w)z*
    Execute command with subprocess.
    zexecute command: T)shellrI  )r7  stdoutzFailed to run command: z
, errors: )
r   r<  
check_callSTDOUTr   r,  r  r$  r   r1  )commandr  rA   r)  s       r!   r   r     s    
 

'g
'
'111	Q 	N(tJ,=    (WMMMM Q Q Qlnn5!OWOOOOPPPQs   "A A <Bc                  
 t           j                            d          dv rdS t          st	          j        d| gt          j                  }t           j                            |	                                          
                                
t          
fdt                      D                       sHt          j        t                              | t                      d         t"                               d	S d
}t"                              d          rdS 	 t"                              d          rZt&          }t	          j        | ddg          }|	                                }|
                                                    d          }nt          rt*          }t	          j        | t          j                  }	 |	                    d          }n%# t,          $ r |	                    d          }Y nw xY wt/          j        d|
                                          }||                                }nB# t4          $ r5 t7          j                    \  }}	}t          j        d|  d|	            Y d	S w xY wt;          |          dk    sJ t=          t?          t@          |                    |k    rdS t          j        tB                              | d"                    |                               d	S )zi
    Check whether GCC version on user local machine is compatible with Paddle in
    site-packages.
    PADDLE_SKIP_CHECK_ABI)Truetrue1Tr8  rH  c              3      K   | ]}|v V  	d S r   rb   )r   r;  compiler_paths     r!   r   z*check_abi_compatibility.<locals>.<genexpr>  s<       
 
 M!
 
 
 
 
 
r"   r   )user_compilerpaddle_compilerr  F)r   r   r   r   r  z-dumpfullversionz-dumpversionrt   zUTF-8gbkz(\d+)\.(\d+)\.(\d+)Nz%Failed to check compiler version for z: r   )rC  rq   )#r,   r9  r   r   r<  r=  r:  r-   realpathr>  r   r   #_expected_compiler_current_platformr-  r.  WRONG_COMPILER_WARNINGr9   r   r   GCC_MINI_VERSIONr  MSVC_MINI_VERSIONUnicodeDecodeErrorr  searchgroupsr,  r  r$  r6   r|   mapr	  ABI_INCOMPATIBILITY_WARNINGr;   )r"  r  cmd_outrq   mini_required_versionr   compiler_infomatchrA   r)  rB  s             @r!   check_abi_compatibilityrT    s   
 
z~~-..2GGGt )h
(9
 
 
 (()9)9::@@BB 
 
 
 
;==
 
 
 
 
 	 M&--"*$G$I$I!$L$ .     5G(## tg&& 	)$4!%2-~> L (..00L"((**0055GG 	)$5!&3!2  M< - 4 4W = =% < < < - 4 4U ; ;<I4m6I6I6K6KLLE ,,..   lnn5!GHGGGG	
 	
 	
 uu w<<1Sg#888tM#**"CHHW,=,= 	+ 	
 	
  
 5s8   B"H; G H; G:7H; 9G::A H; ;;I:9I:c                     t                               d          rddg} n)t                               d          rg d} n
t          rdg} | S )z?
    Returns supported compiler string on current platform
    r   r  zclang++r  )gcczg++zgnu-c++zgnu-cccl)r   r   r   )expect_compilerss    r!   rG  rG  2  sc     (## "#Y/			G	$	$ ">>>	 " 6r"   Tc                B    |rt                               |            dS dS )z*
    Print log information on stdout.
    N)loggerr  )r  r  s     r!   r   r   ?  s.      D r"   )r   r   r   r   )F)rj  rk  r   r   )r  )r  r  r   r   )rD   r   r   r  )T)v
__future__r   r  rP   r  rL  rv   importlib.abcr  importlib.utilr   loggingr,   r  r<  r  r  r)   r  r-  r   r   r  r7   rK  r   r   base.frameworkr	   r
   r   	getLoggerrZ  setLevelINFO	Formatter	formatterStreamHandlerchsetFormatter
addHandlerr  r   r   r   MSVC_COMPILE_FLAGSCLANG_COMPILE_FLAGSCLANG_LINK_FLAGSr  r   r   r   rI  rJ  rH  rO  op_proto_and_checker_makerkOpRoleAttrNamekOpRoleVarAttrNamekOpNameScopeAttrNamekOpCreationCallstackAttrNamekOpDeviceAttrNamekOpWithQuantAttrNamer  r   rF   
namedtuplerG   r/   rc   rm   r~   r   r   r   r   r   r   r   r   r   r   r   r   r'  r  rD  rP  rX  rf  ri  rq  r  r  r  rs  r  r  r  r  r  r  r  r  r  r  r  r5   r  r  r  r  r+  r5  r   rT  rG  r   rb   r"   r!   <module>rt     s   # " " " " "                   				 				     



                %""""""" % % %d2:t$$GGG%       + + + + + + - - - - - - - -		0	1	1    G"MNNN	W 	      "   
,&&
           ""4 B   ./@A "  $ " 	#3355#6688#88::#@@BB#5577#88::    G
 G
 G
T 
 	9i*@	A	A       D '&	 	 	 , , , , , , , ,8  0) 0) 0)f  <             B B B" " "9 9 9; ; ;  *  4t t t tn%" %" %"P  >' ' 'T  B3 3 3"
0 
0 
0   (   6  2      *  "     *) ) )= = =$ $ $&% &% &% &% &%R+ + + +(+ + + +^ 5:   @i+ i+ i+X/ / /d   (+ + +p 8 8 8 8v  " " " "B  ,Q Q Q Q(D D D DN
 
 
     s   A A21A2