o
    #jz                     @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 ddl
mZmZmZmZ ddl
mZmZmZ ddl
mZmZmZ dd	l
mZmZmZmZ dd
l
mZmZ ddl
mZmZmZ ddl
mZmZm Z  ddl
m!Z!m"Z" ddl#m$Z$ erd dl%mZ& d dl'm(Z( e(dde&_)e Z*e$+ re Z,e,Z*dd Z-dd Z.dd Z/dd Z0G dd deZ1G dd deZ2G dd de	Z3							 d#d!d"Z4dS )$    N)easy_install)	build_ext)build   )add_compile_flagfind_cuda_homefind_rocm_homenormalize_extension_kwargs)is_cuda_fileprepare_unix_cudaflagsprepare_win_cudaflags)_import_module_from_library_write_setup_file_jit_compile)check_abi_compatibilitylog_vCustomOpInfoparse_op_name_from)_reset_so_rpathclean_object_if_change_cflags)bootstrap_contextget_build_directoryadd_std_without_repeat)
IS_WINDOWSOS_NAMEMSVC_COMPILE_FLAGS)CLANG_COMPILE_FLAGSCLANG_LINK_FLAGS   )core)Mock)return_valuec                  K   sB  |  di }t|tsJ d|vrtjdd|d< || d< d}d| vr't|| d dr2J d	 |  d	g }t|tsA|g}t|d
ksPJ d	t||D ]}| d |_
qR|| d	< d|vsdJ t|d< d|vsnJ tjd| d }tj|d|d< d| d< t  tjdi |  W d   dS 1 sw   Y  dS )a  
    The interface is used to config the process of compiling customized operators,
    mainly includes how to compile shared library, automatically generate python API
    and install it into site-package. It supports using customized operators directly with
    ``import`` statement.

    It encapsulates the python built-in ``setuptools.setup`` function and keeps arguments
    and usage same as the native interface. Meanwhile, it hides Paddle inner framework
    concepts, such as necessary compiling flags, included paths of head files, and linking
    flags. It also will automatically search and valid local environment and versions of
    ``cc(Linux)`` , ``cl.exe(Windows)`` and ``nvcc`` , then compiles customized operators
    supporting CPU or GPU device according to the specified Extension type.

    Moreover, `ABI compatibility <https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html>`_
    will be checked to ensure that compiler version from ``cc(Linux)`` , ``cl.exe(Windows)``
    on local machine is compatible with pre-installed Paddle whl in python site-packages.

    For Linux, GCC version will be checked . For example if Paddle with CUDA 10.1 is built with GCC 8.2,
    then the version of user's local machine should satisfy GCC >= 8.2.
    For Windows, Visual Studio version will be checked, and it should be greater than or equal to that of
    PaddlePaddle (Visual Studio 2017).
    If the above conditions are not met, the corresponding warning will be printed, and a fatal error may
    occur because of ABI compatibility.

    Note:

        1. Currently we support Linux, MacOS and Windows platform.
        2. On Linux platform, we recommend to use GCC 8.2 as soft linking candidate of ``/usr/bin/cc`` .
           Then, Use ``which cc`` to ensure location of ``cc`` and using ``cc --version`` to ensure linking
           GCC version.
        3. On Windows platform, we recommend to install `` Visual Studio`` (>=2017).


    Compared with Just-In-Time ``load`` interface, it only compiles once by executing
    ``python setup.py install`` . Then customized operators API will be available everywhere
    after importing it.

    A simple example of ``setup.py`` as followed:

    .. code-block:: text

        # setup.py

        # Case 1: Compiling customized operators supporting CPU and GPU devices
        from paddle.utils.cpp_extension import CUDAExtension, setup

        setup(
            name='custom_op',  # name of package used by "import"
            ext_modules=CUDAExtension(
                sources=['relu_op.cc', 'relu_op.cu', 'tanh_op.cc', 'tanh_op.cu']  # Support for compilation of multiple OPs
            )
        )

        # Case 2: Compiling customized operators supporting only CPU device
        from paddle.utils.cpp_extension import CppExtension, setup

        setup(
            name='custom_op',  # name of package used by "import"
            ext_modules=CppExtension(
                sources=['relu_op.cc', 'tanh_op.cc']  # Support for compilation of multiple OPs
            )
        )


    Applying compilation and installation by executing ``python setup.py install`` under source files directory.
    Then we can use the layer api as followed:

    .. code-block:: text

        import paddle
        from custom_op import relu, tanh

        x = paddle.randn([4, 10], dtype='float32')
        relu_out = relu(x)
        tanh_out = tanh(x)


    Args:
        name(str): Specify the name of shared library file and installed python package.
        ext_modules(Extension): Specify the Extension instance including customized operator source files, compiling flags et.al.
                                If only compile operator supporting CPU device, please use ``CppExtension`` ; If compile operator
                                supporting CPU and GPU devices, please use ``CUDAExtension`` .
        include_dirs(list[str], optional): Specify the extra include directories to search head files. The interface will automatically add
                                 ``site-package/paddle/include`` . Please add the corresponding directory path if including third-party
                                 head files. Default is None.
        extra_compile_args(list[str] | dict, optional): Specify the extra compiling flags such as ``-O3`` . If set ``list[str]`` , all these flags
                                will be applied for ``cc`` and ``nvcc`` compiler. It supports specify flags only applied ``cc`` or ``nvcc``
                                compiler using dict type with ``{'cxx': [...], 'nvcc': [...]}`` . Default is None.
        **attr(dict, optional): Specify other arguments same as ``setuptools.setup`` .

    Returns:
        None

    cmdclassr   T)no_python_abi_suffixa  
    Required to specific `name` argument in paddle.utils.cpp_extension.setup.
    It's used as `import XXX` when you want install and import your custom operators.

    For Example:
        # setup.py file
        from paddle.utils.cpp_extension import CUDAExtension, setup
        setup(name='custom_module',
              ext_modules=CUDAExtension(
              sources=['relu_op.cc', 'relu_op.cu'])

        # After running `python setup.py install`
        from custom_module import relu
    namemodulez8Please don't use 'module' as suffix in `name` argument, ext_modulesr   zRequired only one Extension, but received {}. If you want to compile multi operators, you can include all necessary source files in one Extension.r   r   )
build_baseFZzip_safeN )get
isinstancedictBuildExtensionwith_options
ValueErrorendswithlistlenformatr$   EasyInstallCommandospathjoinBuildCommandr   
setuptoolssetup)attrr"   	error_msgr&   Z
ext_moduler'   r(   r(   i/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/utils/cpp_extension/cpp_extension.pyr9   O   sH   _

"r9   c                 O   B   t |dd}|dd}|du rt| }tj|| g|R i |S )a  
    The interface is used to config source files of customized operators and complies
    Op Kernel only supporting CPU device. Please use ``CUDAExtension`` if you want to
    compile Op Kernel that supports both CPU and GPU devices.

    It further encapsulates python built-in ``setuptools.Extension`` .The arguments and
    usage are same as the native interface, except for no need to explicitly specify
    ``name`` .

    **A simple example:**

    .. code-block:: text

        # setup.py

        # Compiling customized operators supporting only CPU device
        from paddle.utils.cpp_extension import CppExtension, setup

        setup(
            name='custom_op',
            ext_modules=CppExtension(sources=['relu_op.cc'])
        )


    Note:
        It is mainly used in ``setup`` and the name of built shared library keeps same
        as ``name`` argument specified in ``setup`` interface.


    Args:
        sources(list[str]): Specify the C++/CUDA source files of customized operators.
        *args(list[options], optional): Specify other arguments same as ``setuptools.Extension`` .
        **kwargs(dict[option], optional): Specify other arguments same as ``setuptools.Extension`` .

    Returns:
        setuptools.Extension: An instance of ``setuptools.Extension``
    FZuse_cudar$   Nr	   r)   _generate_extension_namer8   Z	Extensionsourcesargskwargsr$   r(   r(   r<   CppExtension   s
   &rE   c                 O   r=   )aA  
    The interface is used to config source files of customized operators and complies
    Op Kernel supporting both CPU and GPU devices. Please use ``CppExtension`` if you want to
    compile Op Kernel that supports only CPU device.

    It further encapsulates python built-in ``setuptools.Extension`` .The arguments and
    usage are same as the native interface, except for no need to explicitly specify
    ``name`` .

    **A simple example:**

    .. code-block:: text

        # setup.py

        # Compiling customized operators supporting CPU and GPU devices
        from paddle.utils.cpp_extension import CUDAExtension, setup

        setup(
            name='custom_op',
            ext_modules=CUDAExtension(
                sources=['relu_op.cc', 'relu_op.cu']
            )
        )


    Note:
        It is mainly used in ``setup`` and the name of built shared library keeps same
        as ``name`` argument specified in ``setup`` interface.


    Args:
        sources(list[str]): Specify the C++/CUDA source files of customized operators.
        *args(list[options], optional): Specify other arguments same as ``setuptools.Extension`` .
        **kwargs(dict[option], optional): Specify other arguments same as ``setuptools.Extension`` .

    Returns:
        setuptools.Extension: An instance of setuptools.Extension.
    Tr>   r$   Nr?   rA   r(   r(   r<   CUDAExtension!  s
   (rF   c                 C   sZ   t | dks
J dg }| D ]}tj|}tj|\}}||vr'|| qd|S )z2
    Generate extension name by source files.
    r   zsource files is empty_)r1   r4   r5   basenamesplitextappendr6   )rB   Zfile_prefixsourcefilenamerG   r(   r(   r<   r@   U  s   

r@   c                       sp   e Zd ZdZedd Z fddZ fddZ fdd	Zd
d Z	 fddZ
dd Zdd Zdd Z  ZS )r,   z{
    Inherited from setuptools.command.build_ext to customize how to apply
    compilation process with share library.
    c                       G  fddd }|S )zS
        Returns a BuildExtension subclass containing use-defined options.
        c                          e Zd Z fddZdS )z5BuildExtension.with_options.<locals>.cls_with_optionsc                    &   |   j| g|R i | d S Nupdate__init__selfrC   rD   clsoptionsr(   r<   rS   r     
z>BuildExtension.with_options.<locals>.cls_with_options.__init__N__name__
__module____qualname__rS   r(   rV   r(   r<   cls_with_optionsq      r^   r(   rW   rX   r^   r(   rV   r<   r-   k     zBuildExtension.with_optionsc                    s8   t  j|i | |dd| _|dd| _d| _dS )a.  
        Attributes is initialized with following order:

            1. super().__init__()
            2. initialize_options(self)
            3. the reset of current __init__()
            4. finalize_options(self)

        So, it is recommended to set attribute value in `finalize_options`.
        r#   T
output_dirNF)superrS   r)   r#   rb   contain_cuda_filerT   	__class__r(   r<   rS   x  s   
zBuildExtension.__init__c                    s   t    d S rP   )rc   initialize_optionsrU   re   r(   r<   rg     s   z!BuildExtension.initialize_optionsc                    s$   t    | jd ur| j| _d S d S rP   )rc   finalize_optionsrb   	build_librh   re   r(   r<   ri     s   

zBuildExtension.finalize_optionsc                    s6  t dr	    jd j}ttj	
|jd  j jddg7  _jjdkrEj jddg7  _jj jjnjj  fdd}	 	 	 		 	 	 d fd	d
	}fdd}jjdkrq|j_n|j_|jjjj_  td t jd j}t| d S )Ndarwinr   z.cuz.cu.ccmsvcz.cuhc           
   
      st  t j|}t|}zjj}t|r^t	 r9t
dus J dt jt
dd}jd| t|tr8|d }n tdusAJ dt jtdd}	jd|	 t|trY|d }t|}n	t|trg|d }t	 rz|d	 |d
 |d t|dg t|sjrt	 r|d n|d t|jjdd  | ||||| W jd| dS jd| w )zv
            Monkey patch mechanism to replace inner compiler to custom compile process on Unix platform.
            NzeNot found ROCM runtime,                             please use `export ROCM_PATH= XXX` to specify it.binZhipcccompiler_sozeNot found CUDA runtime,                             please use `export CUDA_HOME= XXX` to specify it.nvcccxxz-D__HIP_PLATFORM_HCC__z-D__HIP_NO_HALF_CONVERSIONS__=1z/-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIPz-D_GLIBCXX_USE_CXX11_ABI=1z-DPADDLE_WITH_HIP-DPADDLE_WITH_CUDAT)Z	use_std14)r4   r5   abspathcopydeepcopycompilerrn   r
   r   is_compiled_with_rocm	ROCM_HOMEr6   Zset_executabler*   r+   	CUDA_HOMEr   rJ   r   rd   r   compiler_type)
objsrcextZcc_argsextra_postargsZpp_optscflagsZoriginal_compilerZ	hipcc_cmdnvcc_cmd)original_compilerU   r(   r<   unix_custom_single_compiler  sP   










"zDBuildExtension.build_extensions.<locals>.unix_custom_single_compilerc           	   	      sR   t |_d }fdd}z|j_ | |||||||W j_S j_w )Nc                    s  j j}tt| D ]}td| | d urd| |< td| | d ur(d| |< q
tddd fdd	| D D }td
dd fdd	| D D }td dd  fdd	| D D }t|dkrnt|dkspJ |d }|d }t|rtd usJ dt	j
tdd}tjtrjd }	ntjtrj}	ng }	t|	dg }	tD ]}
d|
g|	 }	q|d|d|g| |	 } n!tjtrtjd  }	| |	7 } ntjtrtj }	| |	7 } t|sjr| d | S )Nz/MDz/MTz/W[1-4]z/W0z/T(p|c)(.*)c                 S      g | ]	}|r| d qS )   group.0mr(   r(   r<   
<listcomp>
      zqBuildExtension.build_extensions.<locals>.win_custom_single_compiler.<locals>.win_custom_spawn.<locals>.<listcomp>c                 3       | ]}  |V  qd S rP   matchr   elem)	src_regexr(   r<   	<genexpr>      zpBuildExtension.build_extensions.<locals>.win_custom_single_compiler.<locals>.win_custom_spawn.<locals>.<genexpr>z/Fo(.*)c                 S   r   r   r   r   r(   r(   r<   r     r   c                 3   r   rP   r   r   )	obj_regexr(   r<   r     r   z((\-|\/)I.*)c                 S   r   r   r   r   r(   r(   r<   r     r   c                 3   r   rP   r   r   )include_regexr(   r<   r     r   r   r   zaNot found CUDA runtime,                         please use `export CUDA_HOME= XXX` to specify it.rm   ro   z--use-local-envz
-Xcompilerz-cz-orp   rq   )ru   compile_optionsranger1   researchcompiler
   rx   r4   r5   r6   r*   r~   r+   r0   r   r   rd   rJ   )cmdr   iZsrc_listZobj_listZinclude_listr{   rz   r   r~   flag)original_spawnrU   )r   r   r   r<   win_custom_spawn  s\   






z]BuildExtension.build_extensions.<locals>.win_custom_single_compiler.<locals>.win_custom_spawn)rs   rt   r~   ru   spawn)	rB   rb   macrosZinclude_dirsdebugZextra_preargsr}   Zdependsr   r   r   rU   r(   r<   win_custom_single_compiler  s    
BzCBuildExtension.build_extensions.<locals>.win_custom_single_compilerc                    s   d fdd	}|S )z
            Decorated the function to add customized naming mechanism.
            Originally, both .cc/.cu will have .o object output that will
            bring file override problem. Use .cu.o as CUDA object suffix.
            r    c                    s   zM| ||}t | D ]'\}}t|r2|| }jjdkr(|d d d ||< q|d d d ||< q d ur@ fdd|D }dd |D }W j_|S j_w )	Nrl   zcu.objzcu.oc                    s"   g | ]}t j t j|qS r(   )r4   r5   r6   rH   r   rz   )build_directoryr(   r<   r   f  s    zhBuildExtension.build_extensions.<locals>.object_filenames_with_cuda.<locals>.wrapper.<locals>.<listcomp>c                 S      g | ]}t j|qS r(   r4   r5   rr   r   r(   r(   r<   r   k      )	enumerater
   ru   ry   object_filenames)Zsource_filenamesZ	strip_dirrb   objectsr   rK   Zold_obj)r   origina_funcrU   r(   r<   wrapperW  s&   

zTBuildExtension.build_extensions.<locals>.object_filenames_with_cuda.<locals>.wrapperN)r   r   r(   )r   r   r   rh   )r   r   r<   object_filenames_with_cudaP  s   zCBuildExtension.build_extensions.<locals>.object_filenames_with_cudaz9Compiling user custom op, it will cost a few seconds.....)NNNr   NNN)r   
startswith_valid_clang_compiler
_check_abiZget_ext_fullpath
extensionsr$   r   r4   r5   rr   ru   Zsrc_extensionsry   Z_cpp_extensionsr   r   _compiler   rj   _record_op_infoprintr   build_extensionsZ
_full_namer   )rU   so_namer   r   r   so_pathr(   r   r<   r     sD   

H^$


zBuildExtension.build_extensionsc                    sr   t  |}d}||}| jr)t|dksJ dt| |d ||}tdr7d|d< ||}|S )N.r   z+Expected len(name_items) > 2, but received rk   Zdylibr   )	rc   get_ext_filenamesplitr#   r1   popr6   r   r   )rU   fullnameZext_nameZ	split_strZ
name_itemsre   r(   r<   r     s   




zBuildExtension.get_ext_filenamec                 C   s2   dgt  }dgt }| jj||dgdg|d dS )zD
        Make sure to use Clang as compiler on Mac platform
        Zclang)ru   rn   compiler_cxxZ
linker_exeZ	linker_soN)r   r   ru   Zset_executables)rU   Zcompiler_infosZlinker_infosr(   r(   r<   r     s   


z$BuildExtension._valid_clang_compilerc                 C   st   t | jdr| jjd }ntrtjdd}ntjdd}t| tr4dtjv r6dtjvr8d}t|d	S d	S d	S )
z*
        Check ABI Compatibility.
        r   r   CXXclzc++VSCMD_ARG_TGT_ARCHZDISTUTILS_USE_SDKzIt seems that the VC environment is activated but DISTUTILS_USE_SDK is not set.This may lead to multiple activations of the VC env.Please run `set DISTUTILS_USE_SDK=1` and try again.N)	hasattrru   r   r   r4   environr)   r   UserWarning)rU   ru   msgr(   r(   r<   r     s    

zBuildExtension._check_abic           	      C   s   |   }t|dksJ tj|d }tj|}t| jD ],\}}dd |jD }| j	s8t
dd |D | _	t|}|D ]}t j|||d q>qdS )	z/
        Record custom op information.
        r   r   c                 S   r   r(   r   r   sr(   r(   r<   r     r   z2BuildExtension._record_op_info.<locals>.<listcomp>c                 s   s    | ]}t |V  qd S rP   )r
   r   r(   r(   r<   r     s    z1BuildExtension._record_op_info.<locals>.<genexpr>)r   r   N)Zget_outputsr1   r4   r5   rr   rH   r   r   rB   rd   anyr   r   instanceadd)	rU   outputsr   r   r   	extensionrB   Zop_namesZop_namer(   r(   r<   r     s   zBuildExtension._record_op_info)r[   r\   r]   __doc__classmethodr-   rS   rg   ri   r   r   r   r   r   __classcell__r(   r(   re   r<   r,   e  s    
 rr,   c                       s,   e Zd ZdZ fddZ fddZ  ZS )r3   a  
    Extend easy_install Command to control the behavior of naming shared library
    file.

    NOTE(Aurelius84): This is a hook subclass inherited Command used to rename shared
                    library file after extracting egg-info into site-packages.
    c                    s   t  j|i | d S rP   )rc   rS   rT   re   r(   r<   rS     s   zEasyInstallCommand.__init__c                    s   t  j|i | | jD ]L}tj|\}}d}tdr$|dkr$d}ntdr0|dkr0d}ntr8|dkr8d}|rX|d | }tj	|sPt
d	| d	|  tj	|sXJ qd S )
NFlinuxz.soTrk   z.dylibz.pydZ_pd_z%s)rc   runr   r4   r5   rI   r   r   r   existsrename)rU   rC   rD   Zegg_filerL   r|   Zwill_renameZnew_so_pathre   r(   r<   r     s"   
zEasyInstallCommand.run)r[   r\   r]   r   rS   r   r   r(   r(   re   r<   r3     s    r3   c                       s8   e Zd ZdZedd Z fddZ fddZ  ZS )r7   z
    Extend build Command to control the behavior of specifying `build_base` root directory.

    NOTE(Aurelius84): This is a hook subclass inherited Command used to specify customized
                      build_base directory.
    c                    rM   )zQ
        Returns a BuildCommand subclass containing use-defined options.
        c                       rN   )z3BuildCommand.with_options.<locals>.cls_with_optionsc                    rO   rP   rQ   rT   rV   r(   r<   rS     rY   z<BuildCommand.with_options.<locals>.cls_with_options.__init__NrZ   r(   rV   r(   r<   r^     r_   r^   r(   r`   r(   rV   r<   r-      ra   zBuildCommand.with_optionsc                    s$   | dd | _t j|i | d S )Nr'   )r)   _specified_build_baserc   rS   rT   re   r(   r<   rS     s   zBuildCommand.__init__c                    s$   t    | jdur| j| _dS dS )z
        build_base is root directory for all sub-command, such as
        build_lib, build_temp. See `distutils.command.build` for details.
        N)rc   rg   r   r'   rh   re   r(   r<   rg     s   

zBuildCommand.initialize_options)	r[   r\   r]   r   r   r-   rS   rg   r   r(   r(   re   r<   r7     s    
r7   Fc	                 C   s   |du rt |}tj|}td| | tj||  d}	dd |D }|du r-g }|du r3g }t|ts?J d| t|tsKJ d|tdd	|d	|| tj|| }
t	| ||	|
||||||
 t
|	| t| |
|}|S )
a$  
    An Interface to automatically compile C++/CUDA source files Just-In-Time
    and return callable python function as other Paddle layers API. It will
    append user defined custom operators in background while building models.

    It will perform compiling, linking, Python API generation and module loading
    processes under a individual subprocess. It does not require CMake or Ninja
    environment. On Linux platform, it requires GCC compiler whose version is
    greater than 5.4 and it should be soft linked to ``/usr/bin/cc`` . On Windows
    platform, it requires Visual Studio whose version is greater than 2017.
    On MacOS, clang++ is requited. In addition, if compiling Operators supporting
    GPU device, please make sure ``nvcc`` compiler is installed in local environment.

    Moreover, `ABI compatibility <https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html>`_
    will be checked to ensure that compiler version from ``cc(Linux)`` , ``cl.exe(Windows)``
    on local machine is compatible with pre-installed Paddle whl in python site-packages.

    For Linux, GCC version will be checked . For example if Paddle with CUDA 10.1 is built with GCC 8.2,
    then the version of user's local machine should satisfy GCC >= 8.2.
    For Windows, Visual Studio version will be checked, and it should be greater than or equal to that of
    PaddlePaddle (Visual Studio 2017).
    If the above conditions are not met, the corresponding warning will be printed, and a fatal error may
    occur because of ABI compatibility.

    Compared with ``setup`` interface, it doesn't need extra ``setup.py`` and excute
    ``python setup.py install`` command. The interface contains all compiling and installing
    process underground.

    Note:

        1. Currently we support Linux, MacOS and Windows platform.
        2. On Linux platform, we recommend to use GCC 8.2 as soft linking candidate of ``/usr/bin/cc`` .
           Then, Use ``which cc`` to ensure location of ``cc`` and using ``cc --version`` to ensure linking
           GCC version.
        3. On Windows platform, we recommend to install `` Visual Studio`` (>=2017).


    **A simple example:**

    .. code-block:: text

        import paddle
        from paddle.utils.cpp_extension import load

        custom_op_module = load(
            name="op_shared_libary_name",                # name of shared library
            sources=['relu_op.cc', 'relu_op.cu'],        # source files of customized op
            extra_cxx_cflags=['-g', '-w'],               # optional, specify extra flags to compile .cc/.cpp file
            extra_cuda_cflags=['-O2'],                   # optional, specify extra flags to compile .cu file
            verbose=True                                 # optional, specify to output log information
        )

        x = paddle.randn([4, 10], dtype='float32')
        out = custom_op_module.relu(x)


    Args:
        name(str): Specify the name of generated shared library file name, not including ``.so`` and ``.dll`` suffix.
        sources(list[str]): Specify source files name of customized operators.  Supporting ``.cc`` , ``.cpp`` for CPP file
                            and ``.cu`` for CUDA file.
        extra_cxx_cflags(list[str], optional): Specify additional flags used to compile CPP files. By default
                               all basic and framework related flags have been included.
        extra_cuda_cflags(list[str], optional): Specify additional flags used to compile CUDA files. By default
                               all basic and framework related flags have been included.
                               See `Cuda Compiler Driver NVCC <https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html>`_
                               for details. Default is None.
        extra_ldflags(list[str], optional): Specify additional flags used to link shared library. See
                                `GCC Link Options <https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html>`_ for details.
                                Default is None.
        extra_include_paths(list[str], optional): Specify additional include path used to search header files. By default
                                all basic headers are included implicitly from ``site-package/paddle/include`` .
                                Default is None.
        extra_library_paths(list[str], optional): Specify additional library path used to search library files. By default
                                all basic libraries are included implicitly from ``site-packages/paddle/libs`` .
                                Default is None.
        build_directory(str, optional): Specify root directory path to put shared library file. If set None,
                            it will use ``PADDLE_EXTENSION_DIR`` from os.environ. Use
                            ``paddle.utils.cpp_extension.get_build_directory()`` to see the location. Default is None.
        verbose(bool, optional): whether to verbose compiled log information. Default is False.

    Returns:
        Module: A callable python module contains all CustomOp Layer APIs.

    Nzbuild_directory: z	_setup.pyc                 S   r   r(   r   )r   rK   r(   r(   r<   r     r   zload.<locals>.<listcomp>z;Required type(extra_cxx_cflags) == list[str], but received z>Required type(extra_cuda_cflags) == list[str], but received {}z:additional extra_cxx_cflags: [{}], extra_cuda_cflags: [{}] )r   r4   r5   rr   r   r6   r*   r0   r2   r   r   r   )r$   rB   Zextra_cxx_cflagsZextra_cuda_cflagsZextra_ldflagsZextra_include_pathsZextra_library_pathsr   verbose	file_pathZbuild_base_dirZcustom_op_apir(   r(   r<   load  sX   `
r   )NNNNNNF)5r4   rs   r   r8   Zsetuptools.command.easy_installr   Zsetuptools.command.build_extr   Zdistutils.command.buildr   Zextension_utilsr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   baser   Zdistutils.command.build_extZ_du_build_extZunittest.mockr    Zget_export_symbolsrx   rv   rw   r9   rE   rF   r@   r,   r3   r7   r   r(   r(   r(   r<   <module>   sT    !24  r#(