2024-09-06 12:00:33 +08:00
from __future__ import annotations
2017-12-06 19:15:43 +08:00
import subprocess
2018-07-05 22:24:32 +08:00
import os
2019-11-03 12:46:08 +08:00
import os . path
2020-07-30 11:46:12 +08:00
import errno
2018-06-29 11:29:26 +08:00
import re
2018-07-06 10:50:58 +08:00
import shutil
2019-08-05 19:06:14 +08:00
import sys
2019-09-28 23:35:03 +08:00
import fnmatch
2020-04-14 19:56:22 +08:00
import errno
2020-06-29 11:54:30 +08:00
import platform
2022-11-03 11:22:23 +08:00
import glob
2023-11-14 12:47:30 +08:00
import shlex
2024-08-22 10:52:42 +08:00
import ctypes
2019-09-28 23:35:03 +08:00
2019-11-03 12:46:08 +08:00
from contextlib import contextmanager
2024-09-05 11:10:08 +08:00
from pathlib import Path
2019-09-28 23:35:03 +08:00
from setuptools import Command
from setuptools import setup , Distribution , Extension
from setuptools . command . install import install as InstallCommandBase
2022-04-25 10:43:36 +08:00
from setuptools . command . egg_info import egg_info
2019-09-28 23:35:03 +08:00
2017-08-07 19:31:10 +08:00
class BinaryDistribution ( Distribution ) :
def has_ext_modules ( foo ) :
return True
2016-08-29 14:32:53 +00:00
2017-12-06 19:15:43 +08:00
RC = 0
2019-08-05 19:06:14 +08:00
ext_name = ' .dll ' if os . name == ' nt ' else ( ' .dylib ' if sys . platform == ' darwin ' else ' .so ' )
2017-12-06 19:15:43 +08:00
2024-09-06 12:00:33 +08:00
def git_commit ( ) - > str :
2017-12-06 19:15:43 +08:00
try :
cmd = [ ' git ' , ' rev-parse ' , ' HEAD ' ]
2018-11-07 17:25:54 +08:00
git_commit = subprocess . Popen ( cmd , stdout = subprocess . PIPE ,
cwd = " @PADDLE_SOURCE_DIR@ " ) . communicate ( ) [ 0 ] . strip ( )
2017-12-06 19:15:43 +08:00
except :
git_commit = ' Unknown '
2018-07-12 20:15:26 +08:00
git_commit = git_commit . decode ( )
2018-07-12 19:45:45 +08:00
return str ( git_commit )
2017-12-06 19:15:43 +08:00
2018-06-29 11:29:26 +08:00
def _get_version_detail ( idx ) :
[CodeStyle][Typos][V-[1-11],W-1] Fix typos (`vaccum`,`valud`,`validat`,`VAILD`,`valus`,`valuse`,`Varible`,`varaible`,`vecotr`,`vesion`,`verson`,`Vetical`,`vunerability`,`varn`) (#70680)
* fix
* fix
2025-01-13 14:15:56 +08:00
assert idx < 3 , " version info consists of %(major)d . %(minor)d . %(patch)d , \
2018-07-03 14:20:05 +08:00
so detail index must less than 3 "
2018-06-29 11:29:26 +08:00
2024-09-09 12:37:58 +08:00
if re . match ( r ' @TAG_VERSION_REGEX@ ' , ' @PADDLE_VERSION@ ' ) :
2018-07-06 13:57:16 +08:00
version_details = ' @PADDLE_VERSION@ ' . split ( ' . ' )
2018-06-29 11:29:26 +08:00
2018-11-01 15:09:48 +08:00
if len ( version_details ) > = 3 :
2018-07-06 13:57:16 +08:00
return version_details [ idx ]
2018-06-29 11:29:26 +08:00
2018-07-06 15:03:39 +08:00
return 0
2018-06-29 11:29:26 +08:00
2024-09-06 12:00:33 +08:00
def get_major ( ) - > int :
2018-07-06 15:59:29 +08:00
return int ( _get_version_detail ( 0 ) )
2018-06-29 14:36:29 +08:00
2024-09-06 12:00:33 +08:00
def get_minor ( ) - > int :
2018-07-06 15:59:29 +08:00
return int ( _get_version_detail ( 1 ) )
2018-06-29 14:36:29 +08:00
2024-09-06 12:00:33 +08:00
def get_nccl_version ( ) - > int :
2024-03-05 14:57:14 +08:00
if ' @WITH_NCCL@ ' == ' ON ' :
return @NCCL_VERSION @
return 0
2024-09-06 12:00:33 +08:00
def get_patch ( ) - > str :
2018-07-06 15:59:29 +08:00
return str ( _get_version_detail ( 2 ) )
2018-06-29 11:29:26 +08:00
2024-09-06 12:00:33 +08:00
def get_cuda_version ( ) - > str :
2021-10-27 19:56:32 +08:00
if ' @WITH_GPU@ ' == ' ON ' :
return ' @CUDA_VERSION@ '
else :
return ' False '
2025-10-30 13:06:59 +08:00
def get_hip_version ( ) - > str | None :
with_hip = ' @WITH_ROCM@ '
if with_hip == ' ON ' :
return str ( ' @HIP_VERSION@ ' )
else :
return None
2024-09-06 12:00:33 +08:00
def get_cudnn_version ( ) - > str :
2021-10-27 19:56:32 +08:00
if ' @WITH_GPU@ ' == ' ON ' :
temp_cudnn_version = ' '
if ' @CUDNN_MAJOR_VERSION@ ' :
temp_cudnn_version + = ' @CUDNN_MAJOR_VERSION@ '
if ' @CUDNN_MINOR_VERSION@ ' :
temp_cudnn_version + = ' .@CUDNN_MINOR_VERSION@ '
if ' @CUDNN_PATCHLEVEL_VERSION@ ' :
temp_cudnn_version + = ' .@CUDNN_PATCHLEVEL_VERSION@ '
return temp_cudnn_version
else :
return ' False '
2024-09-06 12:00:33 +08:00
def get_xpu_xre_version ( ) - > str :
2023-01-29 13:05:45 +08:00
if ' @WITH_XPU@ ' == ' ON ' :
2024-06-11 10:54:11 +08:00
return ' @XPU_XRE_BASE_VERSION@ '
2023-01-29 13:05:45 +08:00
else :
return ' False '
2024-09-06 12:00:33 +08:00
def get_xpu_xccl_version ( ) - > str :
2023-01-29 13:05:45 +08:00
if ' @WITH_XPU_BKCL@ ' == ' ON ' :
return ' @XPU_XCCL_BASE_VERSION@ '
else :
return ' False '
2024-09-06 12:00:33 +08:00
def get_xpu_xhpc_version ( ) - > str :
2023-12-26 20:19:51 +08:00
if ' @WITH_XPU@ ' == ' ON ' :
2023-12-14 13:06:40 +08:00
return ' @XPU_XHPC_BASE_DATE@ '
else :
return ' False '
2024-09-06 12:00:33 +08:00
def is_tagged ( ) - > bool :
2018-06-29 12:48:30 +08:00
try :
2018-07-11 21:51:05 +08:00
cmd = [ ' git ' , ' describe ' , ' --exact-match ' , ' --tags ' , ' HEAD ' , ' 2>/dev/null ' ]
2018-11-07 17:25:54 +08:00
git_tag = subprocess . Popen ( cmd , stdout = subprocess . PIPE , cwd = " @PADDLE_SOURCE_DIR@ " ) . communicate ( ) [ 0 ] . strip ( )
2018-07-12 20:15:26 +08:00
git_tag = git_tag . decode ( )
2018-06-29 12:48:30 +08:00
except :
2018-06-29 14:33:26 +08:00
return False
2018-07-11 21:51:05 +08:00
if str ( git_tag ) . replace ( ' v ' , ' ' ) == ' @PADDLE_VERSION@ ' :
2018-06-29 14:33:26 +08:00
return True
else :
2018-06-29 14:39:11 +08:00
return False
2018-06-29 11:29:26 +08:00
2024-09-06 12:00:33 +08:00
def get_cinn_version ( ) - > str :
2023-04-12 14:56:42 +08:00
if ' @WITH_CINN@ ' != ' ON ' :
return " False "
2023-06-27 10:35:02 +08:00
return " 0.3.0 "
2023-04-12 14:56:42 +08:00
2024-09-06 12:00:33 +08:00
def get_cuda_archs ( ) - > list [ int ] :
compiled_cuda_archs = ' @COMPILED_CUDA_ARCHS@ '
if isinstance ( compiled_cuda_archs , str ) :
2024-09-13 14:19:33 +08:00
compiled_cuda_archs = re . findall ( r ' \ d+ ' , compiled_cuda_archs )
return [ int ( arch ) for arch in compiled_cuda_archs ]
2024-09-06 12:00:33 +08:00
else :
return [ ]
def get_tensorrt_version ( ) - > str :
def find_libnvinfer ( ) :
""" Search for libnvinfer.so file in LD_LIBRARY_PATH. """
tensorrt_library_path = ' @TENSORRT_LIBRARY_DIR@ '
trt_infer_rt_path = ' @TR_INFER_RT@ '
libnvinfer_file = os . path . join ( tensorrt_library_path , trt_infer_rt_path )
if os . path . exists ( libnvinfer_file ) :
return libnvinfer_file
else :
print ( f " { libnvinfer_file } not found. " )
return None
try :
libnvinfer_path = find_libnvinfer ( )
if not libnvinfer_path :
return None
trt = ctypes . CDLL ( libnvinfer_path )
get_version = trt . getInferLibVersion
get_version . restype = ctypes . c_int
version = get_version ( )
version_str = str ( version )
major = version_str [ : 1 ] if len ( version_str ) > 1 else version_str
minor = version_str [ 1 : 2 ] if len ( version_str ) > 3 else version_str [ 1 : ]
patch = version_str [ 3 : ] if len ( version_str ) > 3 else ' '
minor = minor if minor else ' 0 '
patch = patch if patch else ' 0 '
version_str = f " { major } . { minor } . { patch } "
return version_str
except Exception as e :
print ( f " Error while getting TensorRT version: { e } " )
return None
2025-11-09 11:49:33 +08:00
def get_paddle_version ( ) - > str :
return ' @PADDLE_VERSION@ '
2021-10-27 19:56:32 +08:00
def write_version_py ( filename = ' paddle/version/__init__.py ' ) :
2018-11-07 17:25:54 +08:00
cnt = ''' # THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
2017-12-06 19:15:43 +08:00
#
2025-10-30 13:06:59 +08:00
import inspect
2025-11-09 11:49:33 +08:00
full_version = ' %(paddle_version)s '
2023-01-29 13:05:45 +08:00
major = ' %(major)d '
minor = ' %(minor)d '
patch = ' %(patch)s '
2024-03-05 14:57:14 +08:00
nccl_version = ' %(nccl)d '
2023-01-29 13:05:45 +08:00
rc = ' %(rc)d '
cuda_version = ' %(cuda)s '
cudnn_version = ' %(cudnn)s '
2025-10-30 13:06:59 +08:00
hip_version = %(hip)s
2024-06-11 10:54:11 +08:00
xpu_xre_version = ' %(xpu_xre)s '
2023-01-29 13:05:45 +08:00
xpu_xccl_version = ' %(xpu_xccl)s '
2023-12-14 13:06:40 +08:00
xpu_xhpc_version = ' %(xpu_xhpc)s '
2024-09-06 12:00:33 +08:00
is_tagged = %(is_tagged)s
2023-01-29 13:05:45 +08:00
commit = ' %(commit)s '
with_mkl = ' %(with_mkl)s '
2025-11-27 17:34:27 +08:00
with_hml = ' %(with_hml)s '
2024-09-06 12:00:33 +08:00
cinn_version = ' %(cinn)s '
tensorrt_version = ' %(tensorrt)s '
with_pip_cuda_libraries = ' %(with_pip_cuda_libraries)s '
with_pip_tensorrt = ' %(with_pip_tensorrt)s '
compiled_cuda_archs = %(compiled_cuda_archs)s
2023-01-29 13:05:45 +08:00
2025-10-30 13:06:59 +08:00
__all__ = [ ' cuda ' , ' cudnn ' , ' nccl ' , ' show ' , ' xpu ' , ' xpu_xre ' , ' xpu_xccl ' , ' xpu_xhpc ' , ' tensorrt ' , ' cuda_archs ' , ' hip ' ]
2021-10-27 19:56:32 +08:00
2024-06-19 13:58:03 +08:00
def show() -> None:
2021-10-28 17:55:53 +08:00
" " " Get the version of paddle if `paddle` package if tagged. Otherwise, output the corresponding commit id.
2022-12-29 18:55:39 +08:00
2021-10-28 17:55:53 +08:00
Returns:
If paddle package is not tagged, the commit-id of paddle will be output.
Otherwise, the following information will be output.
full_version: version of paddle
major: the major version of paddle
minor: the minor version of paddle
patch: the patch level version of paddle
2022-12-29 18:55:39 +08:00
2021-10-28 17:55:53 +08:00
rc: whether it ' s rc version
cuda: the cuda version of package. It will return `False` if CPU version paddle package is installed
cudnn: the cudnn version of package. It will return `False` if CPU version paddle package is installed
2022-12-29 18:55:39 +08:00
2024-06-11 10:54:11 +08:00
xpu_xre: the xpu xre version of package. It will return `False` if non-XPU version paddle package is installed
2023-01-29 13:05:45 +08:00
xpu_xccl: the xpu xccl version of package. It will return `False` if non-XPU version paddle package is installed
2023-12-14 13:06:40 +08:00
xpu_xhpc: the xpu xhpc version of package. It will return `False` if non-XPU version paddle package is installed
2023-04-12 14:56:42 +08:00
cinn: the cinn version of package. It will return `False` if paddle package is not compiled with CINN
2021-10-28 17:55:53 +08:00
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2021-10-28 17:55:53 +08:00
2023-09-19 17:15:58 +08:00
>>> import paddle
>>> # Case 1: paddle is tagged with 2.2.0
>>> paddle.version.show()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
full_version: 2.2.0
major: 2
minor: 2
patch: 0
rc: 0
cuda: ' 10.2 '
cudnn: ' 7.6.5 '
2024-06-11 10:54:11 +08:00
xpu_xre: ' 4.32.0.1 '
2023-09-19 17:15:58 +08:00
xpu_xccl: ' 1.0.7 '
2023-12-14 13:06:40 +08:00
xpu_xhpc: ' 20231208 '
2023-09-19 17:15:58 +08:00
cinn: False
>>> # doctest: -SKIP
>>> # Case 2: paddle is not tagged
>>> paddle.version.show()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
commit: cfa357e984bfd2ffa16820e354020529df434f7d
cuda: ' 10.2 '
cudnn: ' 7.6.5 '
2024-06-11 10:54:11 +08:00
xpu_xre: ' 4.32.0.1 '
2023-09-19 17:15:58 +08:00
xpu_xccl: ' 1.0.7 '
2023-12-14 13:06:40 +08:00
xpu_xhpc: ' 20231208 '
2023-09-19 17:15:58 +08:00
cinn: False
>>> # doctest: -SKIP
2021-10-28 17:55:53 +08:00
" " "
2024-02-26 10:43:40 +08:00
if is_tagged:
2018-07-12 19:45:45 +08:00
print( ' full_version: ' , full_version)
print( ' major: ' , major)
print( ' minor: ' , minor)
print( ' patch: ' , patch)
print( ' rc: ' , rc)
2017-12-06 19:15:43 +08:00
else:
2018-07-12 19:45:45 +08:00
print( ' commit: ' , commit)
2021-10-28 17:55:53 +08:00
print( ' cuda: ' , cuda_version)
print( ' cudnn: ' , cudnn_version)
2025-10-30 13:06:59 +08:00
print( ' hip: ' , hip_version)
2024-03-05 14:57:14 +08:00
print( ' nccl: ' , nccl_version)
2024-06-11 10:54:11 +08:00
print( ' xpu_xre: ' , xpu_xre_version)
2023-01-29 13:05:45 +08:00
print( ' xpu_xccl: ' , xpu_xccl_version)
2023-12-14 13:06:40 +08:00
print( ' xpu_xhpc: ' , xpu_xhpc_version)
2023-04-12 14:56:42 +08:00
print( ' cinn: ' , cinn_version)
2024-09-06 12:00:33 +08:00
print( ' tensorrt: ' , tensorrt_version)
print( ' cuda_archs: ' , compiled_cuda_archs)
2018-01-10 16:39:07 +08:00
2024-06-19 13:58:03 +08:00
def mkl() -> str:
2018-01-10 16:39:07 +08:00
return with_mkl
2021-10-27 19:56:32 +08:00
2025-11-27 17:34:27 +08:00
def hml() -> str:
return with_hml
2024-06-19 13:58:03 +08:00
def nccl() -> str:
2024-03-13 11:08:07 +08:00
" " " Get nccl version of paddle package.
Returns:
string: Return the version information of cuda nccl. If paddle package is CPU version, it will return False.
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2024-03-13 11:08:07 +08:00
>>> import paddle
>>> paddle.version.nccl()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
' 2804 '
" " "
2024-05-13 11:33:38 +08:00
return nccl_version
2024-03-05 14:57:14 +08:00
2025-09-08 16:32:53 +08:00
import inspect
CUDA_FUNC_DOC = " " " Get cuda version of paddle package.
2021-10-27 19:56:32 +08:00
Returns:
string: Return the version information of cuda. If paddle package is CPU version, it will return False.
2023-01-29 13:05:45 +08:00
2021-10-27 19:56:32 +08:00
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2021-10-27 19:56:32 +08:00
2023-09-19 17:15:58 +08:00
>>> import paddle
2021-10-27 19:56:32 +08:00
2023-09-19 17:15:58 +08:00
>>> paddle.version.cuda()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
' 10.2 '
2021-10-27 19:56:32 +08:00
" " "
2025-09-08 16:32:53 +08:00
class CudaVersion(str):
def __new__(cls, version: str):
return super().__new__(cls, version)
def __call__(self) -> str:
# When users check for GPU devices using paddle.version.cuda is None, we cannot align this behavior with other frameworks .
# Note: This discrepancy arises because the is operator checks for object identity (memory address equality) rather than value equality.
return str(self)
def __repr__(self) -> str:
return f " CudaVersion( ' {self} ' ) "
@property
def __doc__(self):
return CUDA_FUNC_DOC
@property
def __signature__(self):
return inspect.Signature(
parameters=[],
return_annotation=str
)
cuda = CudaVersion(cuda_version)
2021-10-27 19:56:32 +08:00
2024-06-19 13:58:03 +08:00
def cudnn() -> str:
2021-10-27 19:56:32 +08:00
" " " Get cudnn version of paddle package.
Returns:
string: Return the version information of cudnn. If paddle package is CPU version, it will return False.
2023-01-29 13:05:45 +08:00
2021-10-27 19:56:32 +08:00
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2021-10-27 19:56:32 +08:00
2023-09-19 17:15:58 +08:00
>>> import paddle
2021-10-27 19:56:32 +08:00
2023-09-19 17:15:58 +08:00
>>> paddle.version.cudnn()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
' 7.6.5 '
2021-10-27 19:56:32 +08:00
" " "
return cudnn_version
2023-01-29 13:05:45 +08:00
2024-06-19 13:58:03 +08:00
def xpu() -> str:
2024-06-11 10:54:11 +08:00
" " " Get xpu version of paddle package. The API is deprecated now, please use xpu_xhpc() instead.
Returns:
string: Return the version information of xpu. If paddle package is non-XPU version, it will return False.
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2026-01-05 13:45:45 +08:00
2024-06-11 10:54:11 +08:00
>>> import paddle
2026-01-05 13:45:45 +08:00
2024-06-11 10:54:11 +08:00
>>> paddle.version.xpu()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
' 20230114 '
" " "
return xpu_xhpc_version
2024-06-19 13:58:03 +08:00
def xpu_xre() -> str:
2024-06-11 10:54:11 +08:00
" " " Get xpu xre version of paddle package.
2023-01-29 13:05:45 +08:00
Returns:
string: Return the version information of xpu. If paddle package is non-XPU version, it will return False.
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2023-01-29 13:05:45 +08:00
2023-09-19 17:15:58 +08:00
>>> import paddle
2023-01-29 13:05:45 +08:00
2024-06-11 10:54:11 +08:00
>>> paddle.version.xpu_xre()
2023-09-19 17:15:58 +08:00
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
2024-06-11 10:54:11 +08:00
' 4.32.0.1 '
2023-01-29 13:05:45 +08:00
" " "
2024-06-11 10:54:11 +08:00
return xpu_xre_version
2023-01-29 13:05:45 +08:00
2024-06-19 13:58:03 +08:00
def xpu_xccl() -> str:
2023-01-29 13:05:45 +08:00
" " " Get xpu xccl version of paddle package.
Returns:
string: Return the version information of xpu xccl. If paddle package is non-XPU version, it will return False.
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2023-01-29 13:05:45 +08:00
2023-09-19 17:15:58 +08:00
>>> import paddle
2023-01-29 13:05:45 +08:00
2023-09-19 17:15:58 +08:00
>>> paddle.version.xpu_xccl()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
' 1.0.7 '
2023-01-29 13:05:45 +08:00
" " "
return xpu_xccl_version
2023-04-12 14:56:42 +08:00
2024-06-19 13:58:03 +08:00
def xpu_xhpc() -> str:
2023-12-14 13:06:40 +08:00
" " " Get xpu xhpc version of paddle package.
Returns:
string: Return the version information of xpu xhpc. If paddle package is non-XPU version, it will return False.
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2023-12-14 13:06:40 +08:00
>>> import paddle
>>> paddle.version.xpu_xhpc()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
' 20231208 '
" " "
return xpu_xhpc_version
2024-06-19 13:58:03 +08:00
def cinn() -> str:
2023-04-12 14:56:42 +08:00
" " " Get CINN version of paddle package.
Returns:
string: Return the version information of CINN. If paddle package is not compiled with CINN, it will return False.
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2023-04-12 14:56:42 +08:00
2023-09-19 17:15:58 +08:00
>>> import paddle
2023-04-12 14:56:42 +08:00
2023-09-19 17:15:58 +08:00
>>> paddle.version.cinn()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
False
2023-04-12 14:56:42 +08:00
" " "
return cinn_version
2024-09-06 12:00:33 +08:00
def tensorrt() -> str:
" " " Get TensorRT version of paddle package.
Returns:
string: Return the version information of TensorRT. If paddle package is not compiled with TensorRT, it will return False.
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2024-09-06 12:00:33 +08:00
>>> import paddle
>>> paddle.version.tensorrt()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
False
" " "
return tensorrt_version
2025-10-30 13:06:59 +08:00
hip = hip_version
2024-09-06 12:00:33 +08:00
def cuda_archs():
" " " Get compiled cuda archs of paddle package.
Returns:
list[int]: Return the compiled cuda archs if with gpu. If paddle package is not compiled with gpu, it will return " " .
Examples:
2026-02-03 14:19:51 +08:00
.. code-block:: pycon
2024-09-06 12:00:33 +08:00
>>> import paddle
>>> paddle.version.cuda_archs()
>>> # doctest: +SKIP( ' Different environments yield different output. ' )
[86]
" " "
return compiled_cuda_archs
2017-12-06 19:15:43 +08:00
'''
commit = git_commit ( )
2021-10-27 19:56:32 +08:00
dirname = os . path . dirname ( filename )
try :
os . makedirs ( dirname )
except OSError as e :
if e . errno != errno . EEXIST :
raise
2017-12-06 19:15:43 +08:00
with open ( filename , ' w ' ) as f :
f . write ( cnt % {
2025-11-09 11:49:33 +08:00
' paddle_version ' : get_paddle_version ( ) ,
2018-06-29 11:29:26 +08:00
' major ' : get_major ( ) ,
' minor ' : get_minor ( ) ,
' patch ' : get_patch ( ) ,
2024-03-05 14:57:14 +08:00
' nccl ' : get_nccl_version ( ) ,
2017-12-06 19:15:43 +08:00
' rc ' : RC ,
' version ' : ' $ {PADDLE_VERSION} ' ,
2021-10-27 19:56:32 +08:00
' cuda ' : get_cuda_version ( ) ,
' cudnn ' : get_cudnn_version ( ) ,
2025-10-30 13:06:59 +08:00
' hip ' : get_hip_version ( ) ,
2024-06-11 10:54:11 +08:00
' xpu_xre ' : get_xpu_xre_version ( ) ,
2023-01-29 13:05:45 +08:00
' xpu_xccl ' : get_xpu_xccl_version ( ) ,
2023-12-14 13:06:40 +08:00
' xpu_xhpc ' : get_xpu_xhpc_version ( ) ,
2017-12-06 19:15:43 +08:00
' commit ' : commit ,
2024-02-26 10:43:40 +08:00
' is_tagged ' : is_tagged ( ) ,
2023-04-12 14:56:42 +08:00
' with_mkl ' : ' @WITH_MKL@ ' ,
2025-11-27 17:34:27 +08:00
' with_hml ' : ' @WITH_HML@ ' ,
2024-03-07 10:30:17 +08:00
' cinn ' : get_cinn_version ( ) ,
2024-09-06 12:00:33 +08:00
' tensorrt ' : get_tensorrt_version ( ) ,
' with_pip_tensorrt ' : ' @WITH_PIP_TENSORRT@ ' ,
' compiled_cuda_archs ' : get_cuda_archs ( ) ,
2024-03-07 10:30:17 +08:00
' with_pip_cuda_libraries ' : ' @WITH_PIP_CUDA_LIBRARIES@ ' } )
2024-08-26 14:29:45 +08:00
def get_cinn_config_jsons ( ) :
from pathlib import Path
src_cinn_config_path = ' $ {PADDLE_SOURCE_DIR} /python/paddle/cinn_config '
prefix_len = len ( src_cinn_config_path ) + 1
p = Path ( src_cinn_config_path )
json_list = list ( p . glob ( ' **/*.json ' ) )
json_path_list = [ ]
for json in json_list :
json = str ( json )
json = json [ prefix_len : ]
json_path_list + = [ json ]
return json_path_list
2025-05-22 10:44:48 +08:00
def get_apy_files ( ) :
from pathlib import Path
apy_path = ' $ {PADDLE_BINARY_DIR} /python/paddle/apy/ '
prefix_len = len ( apy_path )
p = Path ( apy_path )
file_list = [ ]
for path in p . rglob ( ' * ' ) :
if path . is_file ( ) :
relative_path = str ( path ) [ prefix_len : ]
file_list . append ( relative_path )
return file_list
2021-10-27 19:56:32 +08:00
write_version_py ( filename = ' @PADDLE_BINARY_DIR@/python/paddle/version/__init__.py ' )
2017-12-06 19:15:43 +08:00
New whl release strategy with pruned nv_fatbin (#35239)
[Background]
Expansion in code size can be irreversible in the long run, leading to huge release packages which
not only hampers user experience but also exceeds a hard limit of pypi.
In such, NV_FATBIN section takes up 86% of the compiled dylib size, owing to the vast number of GPU
arches supported.
This PR aims to prune this NV_FATBIN.
[Solution]
In the new release strategy, two types of whl packages will be involved:
Cubin PIP package:
PIP package maintains a smaller window for GPU arches support, containing
sm_60, sm_70, sm_75, sm_80 cubins, covering Pascal - Ampere arches
JIT release package:
This is a backup for Cubin PIP package, containing compute_35, compute_50, compute_60,
compute_70, compute_75, compute_80, with best performance and GPU arches coverage.
However, it takes around 10 min to install due to the JIT compilation.
[How to use]
The new release strategy is disabled by default.
To compile for Cubin PIP package, add this to cmake: -DCUBIN_RELEASE_PIP
To compile for JIT release package, add this to cmake: -DJIT_RELEASE_WHL
2021-08-31 18:09:18 +08:00
def write_cuda_env_config_py ( filename = ' paddle/cuda_env.py ' ) :
cnt = " "
if ' $ {JIT_RELEASE_WHL} ' == ' ON ' :
cnt = ''' # THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
#
import os
os.environ[ ' CUDA_CACHE_MAXSIZE ' ] = ' 805306368 '
'''
with open ( filename , ' w ' ) as f :
f . write ( cnt )
write_cuda_env_config_py ( filename = ' @PADDLE_BINARY_DIR@/python/paddle/cuda_env.py ' )
2023-02-27 10:13:02 +08:00
def write_distributed_training_mode_py ( filename = ' paddle/incubate/distributed/fleet/parameter_server/version.py ' ) :
2022-10-10 17:53:57 +08:00
cnt = '''
2020-04-14 19:56:22 +08:00
# THIS FILE IS GENERATED FROM PADDLEPADDLE SETUP.PY
2023-02-22 21:11:59 +08:00
from paddle.incubate.distributed.fleet.base import Mode
2020-04-14 19:56:22 +08:00
BUILD_MODE=Mode. %(mode)s
def is_transpiler():
return Mode.TRANSPILER == BUILD_MODE
'''
dirname = os . path . dirname ( filename )
try :
os . makedirs ( dirname )
except OSError as e :
if e . errno != errno . EEXIST :
raise
with open ( filename , ' w ' ) as f :
f . write ( cnt % {
2025-07-23 20:20:51 +08:00
' mode ' : ' TRANSPILER '
2020-04-14 19:56:22 +08:00
} )
2023-02-27 10:13:02 +08:00
write_distributed_training_mode_py ( filename = ' @PADDLE_BINARY_DIR@/python/paddle/incubate/distributed/fleet/parameter_server/version.py ' )
2017-12-06 19:15:43 +08:00
2020-07-30 11:46:12 +08:00
2024-01-28 19:18:57 +08:00
def get_paddle_extra_install_requirements ( ) :
2024-08-22 10:52:42 +08:00
#(Note risemeup1): Paddle will install the pypi cuda package provided by Nvidia, which includes the cuda runtime, cudnn, and cublas. Additionally, it now supports the installation of TensorRT, further enhancing its functionality. This integration simplifies the process as the operation of 'pip install paddle' is no longer dependent on the separate installation of cuda, cudnn, or TensorRT.
paddle_cuda_requires = [ ]
paddle_tensorrt_requires = [ ]
2024-03-06 13:23:00 +08:00
if ' @WITH_PIP_CUDA_LIBRARIES@ ' == ' ON ' :
2024-05-29 19:13:00 +08:00
if platform . system ( ) == ' Linux ' :
PADDLE_CUDA_INSTALL_REQUIREMENTS = {
2025-02-26 09:43:54 +08:00
" 11.8 " : (
2024-01-28 19:18:57 +08:00
" nvidia-cuda-runtime-cu11==11.8.89; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-cupti-cu11==11.8.87; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2024-10-23 11:28:15 +08:00
" nvidia-cudnn-cu11==8.9.6.50; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2024-01-28 19:18:57 +08:00
" nvidia-cublas-cu11==11.11.3.6; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufft-cu11==10.9.0.58; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-curand-cu11==10.3.0.86; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusolver-cu11==11.4.1.48; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparse-cu11==11.7.5.86; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2024-05-20 17:08:36 +08:00
" nvidia-nccl-cu11==2.19.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nvtx-cu11==11.8.86; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-nvrtc-cu11==11.8.89; platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
2024-01-28 19:18:57 +08:00
) ,
2025-02-26 09:43:54 +08:00
" 12.3 " : (
2024-05-20 17:08:36 +08:00
" nvidia-cuda-runtime-cu12==12.3.101; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-cupti-cu12==12.3.101; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2024-11-14 16:18:35 +08:00
" nvidia-cudnn-cu12==9.1.1.17; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2024-05-20 17:08:36 +08:00
" nvidia-cublas-cu12==12.3.4.1; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufft-cu12==11.2.1.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-curand-cu12==10.3.5.147; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusolver-cu12==11.6.1.9; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparse-cu12==12.3.1.170; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2026-01-22 16:33:38 +08:00
" nvidia-nccl-cu12==2.28.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2024-05-20 17:08:36 +08:00
" nvidia-nvtx-cu12==12.4.127; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-nvrtc-cu12==12.3.107; platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
2024-01-28 19:18:57 +08:00
) ,
2025-02-26 09:43:54 +08:00
" 12.4 " : (
" nvidia-cuda-nvrtc-cu12==12.4.127; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-runtime-cu12==12.4.127; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-cupti-cu12==12.4.127; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cudnn-cu12==9.1.0.70; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cublas-cu12==12.4.5.8; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufft-cu12==11.2.1.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-curand-cu12==10.3.5.147; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusolver-cu12==11.6.1.9; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparse-cu12==12.3.1.170; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparselt-cu12==0.6.2; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2026-01-22 16:33:38 +08:00
" nvidia-nccl-cu12==2.28.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2025-02-26 09:43:54 +08:00
" nvidia-nvtx-cu12==12.4.127; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nvjitlink-cu12==12.4.127; platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
) ,
" 12.6 " : (
" nvidia-cuda-nvrtc-cu12==12.6.77; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-runtime-cu12==12.6.77; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-cupti-cu12==12.6.80; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cudnn-cu12==9.5.1.17; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cublas-cu12==12.6.4.1; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufft-cu12==11.3.0.4; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-curand-cu12==10.3.7.77; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusolver-cu12==11.7.1.2; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparse-cu12==12.5.4.2; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparselt-cu12==0.6.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2026-03-06 14:26:37 +08:00
" nvidia-nccl-cu12==2.25.1; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2025-02-26 09:43:54 +08:00
" nvidia-nvtx-cu12==12.6.77; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nvjitlink-cu12==12.6.85; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufile-cu12==1.11.1.6; platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
) ,
" 12.8 " : (
" nvidia-cuda-nvrtc-cu12==12.8.61; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-runtime-cu12==12.8.57; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-cupti-cu12==12.8.57; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cudnn-cu12==9.7.1.26; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cublas-cu12==12.8.3.14; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufft-cu12==11.3.3.41; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-curand-cu12==10.3.9.55; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusolver-cu12==11.7.2.55; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparse-cu12==12.5.7.53; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparselt-cu12==0.6.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2026-01-22 16:33:38 +08:00
" nvidia-nccl-cu12==2.28.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2025-02-26 09:43:54 +08:00
" nvidia-nvtx-cu12==12.8.55; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nvjitlink-cu12==12.8.61; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufile-cu12==1.13.0.11; platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
) ,
2025-05-19 20:19:00 -07:00
" 12.9 " : (
" nvidia-cuda-nvrtc-cu12==12.9.41; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-runtime-cu12==12.9.37; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-cupti-cu12==12.9.19; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cudnn-cu12==9.9.0.52; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cublas-cu12==12.9.0.13; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufft-cu12==11.4.0.6; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-curand-cu12==10.3.10.19; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusolver-cu12==11.7.4.40; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparse-cu12==12.5.9.5; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparselt-cu12==0.7.1; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2026-01-22 16:33:38 +08:00
" nvidia-nccl-cu12==2.28.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2025-05-19 20:19:00 -07:00
" nvidia-nvtx-cu12==12.9.19; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nvjitlink-cu12==12.9.41; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2025-12-01 20:57:13 +08:00
" nvidia-cufile-cu12==1.14.0.30; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" cuda-python==12.9.4; platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
2025-05-19 20:19:00 -07:00
) ,
2025-09-22 15:56:18 +08:00
" 13.0 " : (
" nvidia-cuda-nvrtc==13.0.88; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-runtime==13.0.88; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cuda-cupti==13.0.85; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cudnn-cu13==9.13.0.50; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cublas==13.0.2.14; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cufft==12.0.0.61; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-curand==10.4.0.35; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusolver==12.0.4.66; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparse==12.6.3.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-cusparselt-cu13==0.8.1; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nccl-cu13==2.28.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nvtx==13.0.85; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" nvidia-nvjitlink==13.0.88; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
2025-12-01 20:57:13 +08:00
" nvidia-cufile==1.15.1.6; platform_system == ' Linux ' and platform_machine == ' x86_64 ' | "
" cuda-python==13.0.3; platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
2025-09-22 15:56:18 +08:00
) ,
2024-01-28 19:18:57 +08:00
}
2025-06-16 21:04:27 +08:00
if ' @WITH_CINN@ ' == ' ON ' :
PADDLE_CUDA_INSTALL_REQUIREMENTS [ " 12.3 " ] + = (
" | nvidia-cuda-cccl-cu12==12.3.52;platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
)
PADDLE_CUDA_INSTALL_REQUIREMENTS [ " 12.4 " ] + = (
" | nvidia-cuda-cccl-cu12==12.4.99;platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
)
PADDLE_CUDA_INSTALL_REQUIREMENTS [ " 12.6 " ] + = (
" | nvidia-cuda-cccl-cu12==12.6.77;platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
)
PADDLE_CUDA_INSTALL_REQUIREMENTS [ " 12.8 " ] + = (
" | nvidia-cuda-cccl-cu12==12.8.90;platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
)
PADDLE_CUDA_INSTALL_REQUIREMENTS [ " 12.9 " ] + = (
" | nvidia-cuda-cccl-cu12==12.9.27;platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
)
2025-09-22 15:56:18 +08:00
PADDLE_CUDA_INSTALL_REQUIREMENTS [ " 13.0 " ] + = (
" | nvidia-cuda-cccl==13.0.85;platform_system == ' Linux ' and platform_machine == ' x86_64 ' "
)
2024-05-29 19:13:00 +08:00
elif platform . system ( ) == ' Windows ' :
PADDLE_CUDA_INSTALL_REQUIREMENTS = {
2025-02-26 09:43:54 +08:00
" 11.8 " : (
2024-05-29 19:13:00 +08:00
" nvidia-cuda-runtime-cu11==11.8.89 | "
" nvidia-cudnn-cu11==8.9.4.19 | "
" nvidia-cublas-cu11==11.11.3.6 | "
" nvidia-cufft-cu11==10.9.0.58 | "
" nvidia-curand-cu11==10.3.0.86 | "
" nvidia-cusolver-cu11==11.4.1.48 | "
" nvidia-cusparse-cu11==11.7.5.86 "
) ,
2025-02-26 09:43:54 +08:00
" 12.3 " : (
2024-05-29 19:13:00 +08:00
" nvidia-cuda-runtime-cu12==12.3.101 | "
2024-11-14 16:18:35 +08:00
" nvidia-cudnn-cu12==9.1.1.17 | "
2024-05-29 19:13:00 +08:00
" nvidia-cublas-cu12==12.3.4.1 | "
" nvidia-cufft-cu12==11.2.1.3 | "
" nvidia-curand-cu12==10.3.5.147 | "
" nvidia-cusolver-cu12==11.6.1.9 | "
" nvidia-cusparse-cu12==12.3.1.170 "
) ,
2025-03-12 22:17:06 +08:00
" 12.6 " : (
" nvidia-cuda-runtime-cu12==12.6.77 | "
" nvidia-cudnn-cu12==9.5.1.17 | "
" nvidia-cublas-cu12==12.6.4.1 | "
" nvidia-cufft-cu12==11.3.0.4 | "
" nvidia-curand-cu12==10.3.7.77 | "
" nvidia-cusolver-cu12==11.7.1.2 | "
" nvidia-cusparse-cu12==12.5.4.2 "
) ,
2025-04-28 10:53:59 +08:00
" 12.8 " : (
" nvidia-cuda-runtime-cu12==12.8.57 | "
" nvidia-cudnn-cu12==9.7.1.26 | "
" nvidia-cublas-cu12==12.8.3.14 | "
" nvidia-cufft-cu12==11.3.3.41 | "
" nvidia-curand-cu12==10.3.9.55 | "
" nvidia-cusolver-cu12==11.7.2.55 | "
" nvidia-cusparse-cu12==12.5.7.53 "
) ,
2025-05-19 20:19:00 -07:00
" 12.9 " : (
" nvidia-cuda-runtime-cu12==12.9.37 | "
" nvidia-cudnn-cu12==9.9.0.52 | "
" nvidia-cublas-cu12==12.9.0.13 | "
" nvidia-cufft-cu12==11.4.0.6 | "
" nvidia-curand-cu12==10.3.10.19 | "
" nvidia-cusolver-cu12==11.7.4.40 | "
" nvidia-cusparse-cu12==12.5.9.5 "
) ,
2025-10-30 18:29:52 +08:00
" 13.0 " : (
" nvidia-cuda-runtime==13.0.88 | "
2025-12-11 12:06:45 +08:00
" nvidia-cudnn-cu13==9.13.0.50 | "
" nvidia-cublas==13.0.2.14 | "
2025-10-30 18:29:52 +08:00
" nvidia-cufft==12.0.0.61 | "
" nvidia-curand==10.4.0.35 | "
" nvidia-cusolver==12.0.4.66 | "
" nvidia-cusparse==12.6.3.3 "
)
2024-05-29 19:13:00 +08:00
}
2024-08-22 10:52:42 +08:00
2024-01-28 19:18:57 +08:00
try :
output = subprocess . check_output ( [ ' nvcc ' , ' --version ' ] ) . decode ( ' utf-8 ' )
version_line = [ line for line in output . split ( ' \n ' ) if ' release ' in line ] [ 0 ]
2025-02-26 09:43:54 +08:00
match = re . search ( r ' release ([ \ d \ .]+) ' , version_line )
cuda_major_version = match . group ( 1 )
2024-01-28 19:18:57 +08:00
except Exception as e :
raise ValueError ( " CUDA not found " )
2025-05-26 14:16:39 +08:00
if cuda_major_version in PADDLE_CUDA_INSTALL_REQUIREMENTS :
paddle_cuda_requires = PADDLE_CUDA_INSTALL_REQUIREMENTS [ cuda_major_version ] . split ( " | " )
2024-05-13 11:33:38 +08:00
2024-08-26 19:26:03 +08:00
if ' @WITH_PIP_TENSORRT@ ' == ' ON ' :
2024-08-22 10:52:42 +08:00
version_str = get_tensorrt_version ( )
version_default = int ( version_str . split ( " . " ) [ 0 ] )
if platform . system ( ) == ' Linux ' or ( platform . system ( ) == ' Windows ' and version_default > = 10 ) :
PADDLE_TENSORRT_INSTALL_REQUIREMENTS = [
" tensorrt==8.5.3.1 " ,
" tensorrt==8.6.0 " ,
" tensorrt==8.6.1.post1 " ,
" tensorrt==10.3.0 " ,
]
if not version_str :
return paddle_cuda_requires , [ ]
version_main = " . " . join ( version_str . split ( " . " ) [ : 3 ] )
matched_package = None
for paddle_tensorrt_requires in PADDLE_TENSORRT_INSTALL_REQUIREMENTS :
paddle_tensorrt_version = paddle_tensorrt_requires . split ( " == " ) [ 1 ]
paddle_tensorrt_main = " . " . join ( paddle_tensorrt_version . split ( " . " ) [ : 3 ] )
if version_main == paddle_tensorrt_main :
matched_package = paddle_tensorrt_requires
break
if matched_package :
paddle_tensorrt_requires = [ matched_package ]
else :
print (
f " No exact match found for TensorRT Version: { version_str } . We currently support TensorRT versions 8.5.3.1, 8.6.0, and 8.6.1. "
)
return paddle_cuda_requires , [ ]
2024-08-26 19:26:03 +08:00
return paddle_cuda_requires , paddle_tensorrt_requires
2024-08-22 10:52:42 +08:00
2025-05-22 10:44:48 +08:00
def build_cutlass3_src_code ( ) :
target_path = " $ {PADDLE_BINARY_DIR} /python/paddle/apy/matmul_pass/matmul/cutlass-3.7.0 "
if not os . path . exists ( target_path ) :
os . mkdir ( target_path )
try :
cmd = [ ' git ' , ' rev-parse ' , ' HEAD ' ]
git_commit = subprocess . Popen ( cmd , stdout = subprocess . PIPE ,
cwd = " $ {PADDLE_SOURCE_DIR} /third_party/cutlass " ) . communicate ( ) [ 0 ] . strip ( )
except :
git_commit = ' Unknown '
raise Exception ( " obtain commit id of third_party cutlass failed " )
commit_id = str ( git_commit . decode ( ) )
command = (
' cd '
+ ' $ {PADDLE_SOURCE_DIR} /third_party/cutlass && '
+ ' git checkout v3.7.0 && '
+ ' cp '
+ ' $ {PADDLE_SOURCE_DIR} /third_party/cutlass/tools -r '
+ f ' { target_path } && '
+ ' cp '
+ ' $ {PADDLE_SOURCE_DIR} /third_party/cutlass/include -r '
+ f ' { target_path } && '
+ f ' git checkout { commit_id } '
)
if os . system ( command ) != 0 :
raise Exception ( f " copy cutlass-3.7.0 failed, command: { command } " )
2024-08-22 10:52:42 +08:00
2024-01-28 19:18:57 +08:00
2016-08-29 14:32:53 +00:00
packages = [ ' paddle ' ,
2018-07-05 22:24:32 +08:00
' paddle.libs ' ,
2017-01-23 18:44:51 +08:00
' paddle.utils ' ,
2026-02-05 10:52:22 +08:00
' paddle.utils.data ' ,
2026-03-10 18:01:26 +08:00
' paddle.utils.data._utils ' ,
2021-08-05 17:36:48 +08:00
' paddle.utils.gast ' ,
2021-02-03 14:13:07 +08:00
' paddle.utils.cpp_extension ' ,
2018-03-29 15:21:47 -07:00
' paddle.dataset ' ,
' paddle.reader ' ,
2019-02-12 15:48:06 +08:00
' paddle.distributed ' ,
2025-08-19 20:22:41 +08:00
' paddle.distributed.flex_checkpoint ' ,
' paddle.distributed.flex_checkpoint.aoa ' ,
' paddle.distributed.flex_checkpoint.dcp ' ,
2022-08-31 10:45:50 +08:00
' paddle.distributed.communication ' ,
' paddle.distributed.communication.stream ' ,
2022-01-28 11:53:47 +08:00
' paddle.distributed.metric ' ,
2022-02-08 17:22:06 +08:00
' paddle.distributed.ps ' ,
' paddle.distributed.ps.utils ' ,
2020-04-30 16:21:27 +08:00
' paddle.incubate ' ,
2024-07-25 10:48:41 +08:00
' paddle.incubate.jit ' ,
2022-04-02 06:51:55 +08:00
' paddle.incubate.autograd ' ,
2021-01-07 00:40:53 +08:00
' paddle.incubate.optimizer ' ,
2021-04-21 08:40:01 +08:00
' paddle.incubate.checkpoint ' ,
2021-07-12 11:08:47 +08:00
' paddle.incubate.operators ' ,
2021-09-16 20:36:22 +08:00
' paddle.incubate.tensor ' ,
2022-04-04 21:14:23 +08:00
' paddle.incubate.multiprocessing ' ,
2021-10-27 14:27:22 +08:00
' paddle.incubate.nn ' ,
2022-05-25 10:17:27 +08:00
' paddle.incubate.asp ' ,
2021-11-19 17:43:55 +08:00
' paddle.incubate.passes ' ,
2024-01-05 16:07:28 +08:00
' paddle.incubate.framework ' ,
2021-12-23 19:29:44 +08:00
' paddle.distribution ' ,
2022-09-20 22:00:26 +08:00
' paddle.distributed.utils ' ,
2022-03-09 19:04:50 +08:00
' paddle.distributed.sharding ' ,
2025-12-20 06:04:37 +08:00
' paddle.distributed.fsdp ' ,
2020-08-13 11:08:43 +08:00
' paddle.distributed.fleet ' ,
2022-03-21 15:14:36 +08:00
' paddle.distributed.launch ' ,
2023-09-07 08:26:45 +08:00
' paddle.distributed.auto_tuner ' ,
2022-03-21 15:14:36 +08:00
' paddle.distributed.launch.context ' ,
' paddle.distributed.launch.controllers ' ,
' paddle.distributed.launch.job ' ,
' paddle.distributed.launch.plugins ' ,
' paddle.distributed.launch.utils ' ,
2020-08-13 11:08:43 +08:00
' paddle.distributed.fleet.base ' ,
2022-09-19 14:08:49 +08:00
' paddle.distributed.fleet.recompute ' ,
2021-08-04 15:38:40 +08:00
' paddle.distributed.fleet.elastic ' ,
2020-08-13 11:08:43 +08:00
' paddle.distributed.fleet.meta_optimizers ' ,
2020-10-26 10:08:10 +08:00
' paddle.distributed.fleet.meta_optimizers.sharding ' ,
2021-04-19 15:07:02 +08:00
' paddle.distributed.fleet.meta_optimizers.dygraph_optimizer ' ,
2020-08-13 11:08:43 +08:00
' paddle.distributed.fleet.runtime ' ,
2022-10-13 11:13:28 +08:00
' paddle.distributed.rpc ' ,
2020-08-13 11:08:43 +08:00
' paddle.distributed.fleet.dataset ' ,
2020-09-28 16:56:33 +08:00
' paddle.distributed.fleet.data_generator ' ,
2020-08-13 11:08:43 +08:00
' paddle.distributed.fleet.metrics ' ,
' paddle.distributed.fleet.proto ' ,
' paddle.distributed.fleet.utils ' ,
2022-09-16 10:53:58 +08:00
' paddle.distributed.fleet.layers ' ,
' paddle.distributed.fleet.layers.mpu ' ,
2021-04-17 01:07:40 +08:00
' paddle.distributed.fleet.meta_parallel ' ,
2021-04-25 22:45:32 +08:00
' paddle.distributed.fleet.meta_parallel.pp_utils ' ,
2021-11-29 11:22:17 +08:00
' paddle.distributed.fleet.meta_parallel.sharding ' ,
2021-04-25 11:31:04 +08:00
' paddle.distributed.fleet.meta_parallel.parallel_layers ' ,
2021-08-11 15:20:25 +08:00
' paddle.distributed.auto_parallel ' ,
2024-11-01 15:04:06 +08:00
' paddle.distributed.auto_parallel.intermediate ' ,
2025-06-04 22:56:28 +08:00
' paddle.distributed.auto_parallel.pipelining ' ,
2023-05-30 14:07:49 +08:00
' paddle.distributed.auto_parallel.dygraph ' ,
' paddle.distributed.auto_parallel.static ' ,
' paddle.distributed.auto_parallel.static.operators ' ,
' paddle.distributed.auto_parallel.static.tuner ' ,
' paddle.distributed.auto_parallel.static.cost ' ,
2024-04-18 19:39:32 +08:00
' paddle.distributed.auto_parallel.static.reshard_funcs ' ,
2021-11-15 11:13:52 +08:00
' paddle.distributed.passes ' ,
2024-04-12 19:09:36 +08:00
' paddle.distributed.passes.pipeline_scheduler_pass ' ,
2022-04-27 11:19:52 +08:00
' paddle.distributed.models ' ,
' paddle.distributed.models.moe ' ,
2023-02-20 11:52:44 +08:00
' paddle.distributed.transpiler ' ,
' paddle.distributed.transpiler.details ' ,
2020-04-20 10:47:23 +08:00
' paddle.framework ' ,
2020-08-10 23:18:32 -05:00
' paddle.jit ' ,
2020-09-29 13:01:23 +08:00
' paddle.jit.dy2static ' ,
2023-12-25 10:03:29 +08:00
' paddle.jit.dy2static.transformers ' ,
2023-10-13 21:57:33 +08:00
' paddle.jit.sot ' ,
' paddle.jit.sot.opcode_translator ' ,
' paddle.jit.sot.opcode_translator.executor ' ,
' paddle.jit.sot.opcode_translator.executor.variables ' ,
' paddle.jit.sot.opcode_translator.instruction_utils ' ,
2024-08-28 19:17:28 +08:00
' paddle.jit.sot.profiler ' ,
2023-10-13 21:57:33 +08:00
' paddle.jit.sot.symbolic ' ,
2025-04-15 11:04:01 +08:00
' paddle.jit.sot.symbolic_shape ' ,
2023-10-13 21:57:33 +08:00
' paddle.jit.sot.utils ' ,
2020-09-23 10:31:49 +08:00
' paddle.inference ' ,
2021-09-16 09:27:09 +08:00
' paddle.inference.contrib ' ,
' paddle.inference.contrib.utils ' ,
2023-09-07 17:26:19 +08:00
' paddle.base ' ,
' paddle.base.dygraph ' ,
' paddle.base.proto ' ,
' paddle.base.proto.profiler ' ,
' paddle.base.layers ' ,
' paddle.base.incubate ' ,
2023-02-22 21:11:59 +08:00
' paddle.incubate.distributed.fleet ' ,
2023-09-07 17:26:19 +08:00
' paddle.base.incubate.checkpoint ' ,
2020-09-30 18:04:11 +08:00
' paddle.amp ' ,
2021-11-04 10:57:34 +08:00
' paddle.cost_model ' ,
2024-08-26 14:29:45 +08:00
' paddle.cinn_config ' ,
2020-08-31 12:39:43 +08:00
' paddle.hapi ' ,
' paddle.vision ' ,
' paddle.vision.models ' ,
' paddle.vision.transforms ' ,
' paddle.vision.datasets ' ,
2022-09-09 00:15:04 +08:00
' paddle.audio ' ,
2025-05-22 11:32:52 +08:00
' paddle.audio.functional ' ,
' paddle.audio.features ' ,
' paddle.audio.datasets ' ,
' paddle.audio.backends ' ,
2020-08-31 12:39:43 +08:00
' paddle.text ' ,
' paddle.text.datasets ' ,
2020-05-15 02:04:46 +08:00
' paddle.incubate ' ,
2025-04-25 10:50:56 +08:00
' paddle.incubate.cc ' ,
2025-05-08 20:49:38 +08:00
' paddle.incubate.cc.ap ' ,
2025-05-22 10:44:48 +08:00
' paddle.incubate.cc.tools ' ,
' paddle.apy ' ,
2024-07-25 10:48:41 +08:00
' paddle.incubate.jit ' ,
2021-10-27 14:27:22 +08:00
' paddle.incubate.nn ' ,
' paddle.incubate.nn.functional ' ,
' paddle.incubate.nn.layer ' ,
2022-03-31 14:23:36 +08:00
' paddle.incubate.optimizer.functional ' ,
Add support for forward and reverse high-order automatic differentiation mechanism (#41919)
* Updated triple_grad_check func
* add todo for gradient checker and refine some comments
* remove additional code
* add test for warnging in backward.py
* format python code
* support multi input in triple gradient checker
* Add matmul triple grad kernel
* Updated comments of TODO
* Supported some special tests
* Change code-format to follow CI std
* Updated gradient_checker.py
* Fix conflicts
* Removed unnecessary printing log
* Change code style to follow CI std
* merge upstream
* add priops.py
* add_p
* rm useless files
* add sub_p mul_p div_p
* add sqrt_p and tanh_p
* add reshape_p
* add broadcast_p
* Add python primitive wrappers.
* Jvp rules updated.
* JVP rules done for all the 17 primops.
* quick check and fixes.
* add jvp(op, *args)
* add broadcast_p fill_constant_p matmul_p reduce_p reshape_p transpose_p
* add split_p and concat_p
* add gather_p and scatter_add_p
* add slice_select_p and slice_assign_p
* Add transpose rules.
* add multi input check for add_p, sub_p, mul_p, div_p
* update concat_p
* Linearize and transpose in progress..
* refine gather_p and scatter_add_p
* updated.
* update transpose.
* refine slice_assign_p and slice_select_p
* init commit for lower
* Merged with primitive ops.
* small update
* add rules for orig2prim and prim2orig
* add 9 test for prim ops
* add more test and fix some bug
* add more test
* register proto
* Adding primops test.
* add shape valid check for broadcast_p op, and add keepdim attr into reduce_p op proto
* support multi input and multi output for split_p and concat_p
* Test updated.
* update
* fix slice bug for slice_select_p and slice_assign_p
* updated.
* Ops updated.
* Refactor and bug fixes.
* updated.
* finish orig2prim and prim2orig rules
* dtype for axis attr should be long int
* update dtype for axis attr int64_t
* update for iscan CI
* Update primx.
* Refactor vars in primx.
* update for lower transform
* add more shape and dtype check
* update primx.py
* change IndexTensor into int32 dtype
* update
* Fix linearize and transpose.
* Update is_dot
* Update is_dot
* Update is_dot
* add gradient aggregation, fix add_transpose.
* pass first linearize+transpose test.
* update test
* refactor op registration and primx.
* update rule for slice_assign
* try test lower
* update orig2prim and prim2orig
* pass simple lower pass
* update
* Update input types in the unit test.
* orig2prim segfault.
* 50% for adam.minimize
* test updated.
* temp fix erros in removing vars.
* primx updated.
* update for matmul_v2 and reshape2 orig2prim
* update for minimize
* Refine primrules
* Remove some code
* supporting unused and unreachable vars.
* update for use prim2orig in minimize
* fix gather and scatter_add transpose.
* Add rules UT
* update scatter_add
* Refine UT code
* fix nonetype check in topo
* Update gather_p pywrapper.
* remove useless print
* Merge tongxin PR and refine code
* readd some test
* rm useless print
* polish code.
* fix bug in minimize
* add get_input_var_list and get_output_var_list and use it in lower
* Fix scatter_add_p prim2orig
* Update code and fix orig2prim/prim2orig UT
* delete vars after block.desc._remove
* Improve ops and vars clean up logics.
* fix some bug in linearize and lower
* update tanh transpose.
* use set instead of list for var2remove
* test updated.
* polish code.
* fix dot2bar delete.
* merge tx/ad
* add indextensor_dot for gather and scatter_add
* add sorted for set
* Fix scale_orig2prim params
* fix some syntax bug
* add golbal_lower_update list
* Better handling of unused vars.
* update tests.
* Fix elementwise_sub orig2prim
* support none for transpose rule
* Merge and add transform UT
* fix a bug in transpose
* Fix transpose and UT
* a hacky fix for cancat op
* Fix exector place
* Refine variable name
* Add elementwise_mul orig2prim and support p_norm when p=1
* Add sqrt orig2prim rule and UT
* merge wz test
* rename files, add enable_prim, disable_prim, prim_enabled, delete global_lower_update
* fix a bug in test_ad_transform_trans
* revert modify in framework.py
* add paddle.fluid.incubate.ad_transform to python/setup.py.in
* Fix remove vars error
* Fix p_norm_orig2prim
* merge wz
* Modify the code directory
* Add utils.py and remove get_input/output_vars functions
* Update maolin code
* Rename UT and refine test_ad_transform_primops
* Fix div_p jvp rule
* Add higher derivatives UT
* Remove UT to autograd dir
* Fix comments
* import paddle in primops.py
* Add some error message for assert
* Refine UT class name and refine some comments in primreg.py
* update minimize of paddle/optimizer for supporting new autograd
* resolve cicular importing between backward.py and optimizer.py
* fill gradients and minimize unittest
* Replace `assert isinstance` with `raise TypeError`
* Add some assert message for primx.py
* Polish variable name
* Add some assert message
* add some docstring
* refine some name
* update the format of english documents
* Split test_transform.py to two files to avoid ci error
* fix the document format of enable_prim/disable_prim/prim2orig/prim_enabled
* polish test_gradients_and_minimize
* add default value for prim_enabled api doc
* Remove some UT to avoid windows ci error
* Enlarge test_gradients_and_minimize limit time
* Fix ut limit time
Co-authored-by: veyron95 <veyron_wu@163.com>
Co-authored-by: Jiabin Yang <360788950@qq.com>
Co-authored-by: levi131 <limaolin01@baidu.com>
Co-authored-by: Tongxin Bai <waffle.bai@gmail.com>
Co-authored-by: Xiaoxu Chen <chenxx_id@163.com>
Co-authored-by: levi131 <83750468+levi131@users.noreply.github.com>
2022-05-18 16:03:04 +08:00
' paddle.incubate.autograd ' ,
2022-04-27 11:19:52 +08:00
' paddle.incubate.distributed ' ,
2022-10-29 22:58:04 +08:00
' paddle.incubate.distributed.utils ' ,
' paddle.incubate.distributed.utils.io ' ,
2022-09-19 14:08:49 +08:00
' paddle.incubate.distributed.fleet ' ,
2022-04-27 11:19:52 +08:00
' paddle.incubate.distributed.models ' ,
' paddle.incubate.distributed.models.moe ' ,
' paddle.incubate.distributed.models.moe.gate ' ,
2023-02-27 10:13:02 +08:00
' paddle.incubate.distributed.fleet.parameter_server ' ,
' paddle.incubate.distributed.fleet.parameter_server.distribute_transpiler ' ,
' paddle.incubate.distributed.fleet.parameter_server.pslib ' ,
' paddle.incubate.distributed.fleet.parameter_server.ir ' ,
2023-04-23 10:56:37 +08:00
' paddle.incubate.layers ' ,
2022-12-23 14:56:11 +08:00
' paddle.quantization ' ,
' paddle.quantization.quanters ' ,
2023-02-16 14:57:20 +08:00
' paddle.quantization.observers ' ,
2022-10-21 00:30:31 +08:00
' paddle.sparse ' ,
' paddle.sparse.nn ' ,
' paddle.sparse.nn.layer ' ,
' paddle.sparse.nn.functional ' ,
2022-07-13 19:44:32 +08:00
' paddle.incubate.xpu ' ,
2020-04-21 10:37:47 +08:00
' paddle.io ' ,
2023-05-11 17:38:02 +08:00
' paddle.io.dataloader ' ,
2020-05-15 02:04:46 +08:00
' paddle.optimizer ' ,
2020-04-04 03:04:07 +08:00
' paddle.nn ' ,
2025-09-20 23:07:55 +08:00
' paddle.nn.attention ' ,
2020-04-04 03:04:07 +08:00
' paddle.nn.functional ' ,
2020-04-14 20:53:18 +08:00
' paddle.nn.layer ' ,
2025-11-15 14:45:36 +08:00
' paddle.nn.modules ' ,
2021-06-09 10:23:34 +08:00
' paddle.nn.quant ' ,
2023-01-11 19:55:47 +08:00
' paddle.nn.quant.qat ' ,
2020-05-15 02:04:46 +08:00
' paddle.nn.initializer ' ,
2020-08-20 19:10:48 +08:00
' paddle.nn.utils ' ,
2020-05-15 02:04:46 +08:00
' paddle.metric ' ,
2020-08-10 23:18:32 -05:00
' paddle.static ' ,
' paddle.static.nn ' ,
2020-12-16 16:52:01 +08:00
' paddle.static.amp ' ,
2023-01-12 19:37:36 +08:00
' paddle.static.amp.bf16 ' ,
2022-12-30 11:03:39 +08:00
' paddle.static.quantization ' ,
' paddle.quantization ' ,
' paddle.quantization.imperative ' ,
2020-04-23 21:01:22 +08:00
' paddle.tensor ' ,
2025-10-30 20:04:58 +08:00
' paddle.compat ' ,
' paddle.compat.nn ' ,
' paddle.compat.nn.functional ' ,
2020-11-13 13:20:30 +08:00
' paddle.onnx ' ,
2021-04-01 14:55:48 +08:00
' paddle.autograd ' ,
2025-09-18 11:16:41 +08:00
' paddle.cuda ' ,
2021-07-19 17:44:21 +08:00
' paddle.device ' ,
' paddle.device.cuda ' ,
2022-11-10 14:39:56 +08:00
' paddle.device.xpu ' ,
2021-10-27 19:56:32 +08:00
' paddle.version ' ,
2022-04-06 14:19:59 +08:00
' paddle.profiler ' ,
2022-08-09 17:14:06 +08:00
' paddle.geometric ' ,
' paddle.geometric.message_passing ' ,
2022-08-29 12:47:03 +08:00
' paddle.geometric.sampling ' ,
2023-09-22 11:56:17 +08:00
' paddle.pir ' ,
2023-08-08 14:07:59 +08:00
' paddle.decomposition ' ,
2024-05-13 11:33:38 +08:00
' paddle._typing ' ,
2024-09-05 11:10:08 +08:00
' paddle._typing.libs ' ,
2025-01-20 11:15:05 +08:00
' paddle.api_tracer ' ,
2025-12-20 20:59:30 +08:00
' paddle.testing ' ,
2024-09-05 11:10:08 +08:00
]
2018-03-14 17:05:44 +08:00
2025-03-06 13:43:21 +08:00
if (
' @WITH_GPU@ ' == ' ON '
and ' @CUDA_ARCH_BIN@ '
and ' @CUDA_ARCH_BIN@ ' . find ( " 90 " ) != - 1
) :
packages . extend ( [ ' paddle.distributed.communication.deep_ep ' ] )
2025-11-10 20:26:57 +08:00
if (
' @WITH_XPU@ ' == ' ON '
and ' @WITH_XPU_XRE5@ ' == ' ON '
) :
packages . extend ( [ ' paddle.distributed.communication.deep_ep ' ] )
2025-06-05 19:26:23 +08:00
if (
' @WITH_GPU@ ' == ' ON '
and tuple ( map ( int , ' @CUDA_VERSION@ ' . split ( ' . ' ) ) ) > = ( 12 , 9 )
and ' @COMPILED_CUDA_ARCHS@ ' . find ( " 90 " ) != - 1
) :
packages . extend ( [ ' paddle.incubate.fp8.deep_gemm ' ] )
packages . extend ( [ ' paddle.incubate.fp8.deep_gemm.jit ' ] )
packages . extend ( [ ' paddle.incubate.fp8.deep_gemm.jit_kernels ' ] )
2025-01-20 15:00:58 +08:00
if ' @WITH_TENSORRT@ ' == ' ON ' :
2025-01-13 15:44:05 +08:00
packages . extend ( [
' paddle.tensorrt ' ,
' paddle.tensorrt.impls ' ,
] )
2017-08-11 16:14:24 +08:00
with open ( ' @PADDLE_SOURCE_DIR@/python/requirements.txt ' ) as f :
setup_requires = f . read ( ) . splitlines ( )
2017-06-06 03:22:11 -07:00
2025-05-22 11:32:52 +08:00
if sys . version_info < ( 3 , 9 ) :
raise RuntimeError ( " Paddle only support Python version>=3.9 now " )
2022-09-27 09:49:08 +08:00
2025-05-22 11:32:52 +08:00
if sys . version_info > = ( 3 , 9 ) :
2020-04-12 22:47:55 +08:00
setup_requires_tmp = [ ]
for setup_requires_i in setup_requires :
2023-12-12 20:07:39 +08:00
if (
" < \" 3.6 \" " in setup_requires_i
or " <= \" 3.6 \" " in setup_requires_i
or " < \" 3.5 \" " in setup_requires_i
or " <= \" 3.5 \" " in setup_requires_i
or " < \" 3.7 \" " in setup_requires_i
or " <= \" 3.7 \" " in setup_requires_i
or " < \" 3.8 \" " in setup_requires_i
2025-05-22 11:32:52 +08:00
or ' <= " 3.8 " ' in setup_requires_i
or ' < " 3.9 " ' in setup_requires_i
2024-09-05 11:10:08 +08:00
or setup_requires_i . strip ( ) . endswith (
' [build] '
) # remove `[build]` requirements
2023-12-12 20:07:39 +08:00
) :
2020-04-12 22:47:55 +08:00
continue
setup_requires_tmp + = [ setup_requires_i ]
setup_requires = setup_requires_tmp
2024-05-29 19:13:00 +08:00
if ' @WITH_GPU@ ' == ' ON ' and platform . system ( ) in ( ' Linux ' , ' Windows ' ) and platform . machine ( ) in ( ' x86_64 ' , ' AMD64 ' ) :
2024-08-26 19:26:03 +08:00
paddle_cuda_requires , paddle_tensorrt_requires = get_paddle_extra_install_requirements ( )
2024-01-28 19:18:57 +08:00
setup_requires + = paddle_cuda_requires
2024-08-26 19:26:03 +08:00
setup_requires + = paddle_tensorrt_requires
2024-05-13 11:33:38 +08:00
2020-04-12 22:47:55 +08:00
2017-08-14 15:12:16 +08:00
# the prefix is sys.prefix which should always be usr
2018-03-14 17:05:44 +08:00
paddle_bins = ' '
2020-04-20 19:06:50 +08:00
2019-01-18 22:02:04 +08:00
if not ' $ {WIN32} ' :
paddle_bins = [ ' $ {PADDLE_BINARY_DIR} /paddle/scripts/paddle ' ]
2021-05-07 11:00:45 +08:00
if os . name != ' nt ' :
2023-09-07 17:26:19 +08:00
package_data = { ' paddle.base ' : [ ' $ {FLUID_CORE_NAME} ' + ' .so ' ] }
2021-05-07 11:00:45 +08:00
else :
2023-09-07 17:26:19 +08:00
package_data = { ' paddle.base ' : [ ' $ {FLUID_CORE_NAME} ' + ' .pyd ' , ' $ {FLUID_CORE_NAME} ' + ' .lib ' ] }
2021-05-07 11:00:45 +08:00
2026-03-02 20:07:17 +08:00
custom_device_dir = ' $ {PADDLE_BINARY_DIR} /python/paddle/paddle_custom_device '
if os . path . isdir ( custom_device_dir ) :
packages . append ( ' paddle.paddle_custom_device ' )
package_data [ ' paddle.paddle_custom_device ' ] = [ ' *.so ' , ' include/** ' ]
2023-09-07 17:26:19 +08:00
package_data [ ' paddle.base ' ] + = [ ' $ {PADDLE_BINARY_DIR} /python/paddle/cost_model/static_op_benchmark.json ' ]
2018-11-05 15:13:53 +08:00
2024-08-26 14:29:45 +08:00
whl_cinn_config_path = ' $ {PADDLE_BINARY_DIR} /python/paddle/cinn_config '
src_cinn_config_path = ' $ {PADDLE_SOURCE_DIR} /python/paddle/cinn_config '
package_data [ ' paddle.cinn_config ' ] = [ ]
if os . path . exists ( whl_cinn_config_path ) :
shutil . rmtree ( whl_cinn_config_path )
shutil . copytree ( src_cinn_config_path , whl_cinn_config_path )
json_path_list = get_cinn_config_jsons ( )
for json in json_path_list :
package_data [ ' paddle.cinn_config ' ] + = [ json ]
2025-05-28 09:33:29 +08:00
# if '${WITH_CINN}' == 'ON':
# build_cutlass3_src_code()
2025-05-22 10:44:48 +08:00
package_data [ ' paddle.apy ' ] = [ ]
file_path_list = get_apy_files ( )
for file in file_path_list :
package_data [ ' paddle.apy ' ] + = [ file ]
2018-03-14 17:05:44 +08:00
package_dir = {
2018-04-10 10:21:37 +08:00
' ' : ' $ {PADDLE_BINARY_DIR} /python ' ,
2023-09-07 17:26:19 +08:00
# The paddle.base.proto will be generated while compiling.
2018-03-14 17:05:44 +08:00
# So that package points to other directory.
2023-09-07 17:26:19 +08:00
' paddle.base.proto.profiler ' : ' $ {PADDLE_BINARY_DIR} /paddle/fluid/platform ' ,
' paddle.base.proto ' : ' $ {PADDLE_BINARY_DIR} /paddle/fluid/framework ' ,
' paddle.base ' : ' $ {PADDLE_BINARY_DIR} /python/paddle/base ' ,
2026-03-02 20:07:17 +08:00
* * ( { ' paddle.paddle_custom_device ' : custom_device_dir }
if os . path . isdir ( custom_device_dir ) else { } ) ,
2018-03-14 17:05:44 +08:00
}
2017-08-14 15:12:16 +08:00
2018-07-05 22:24:32 +08:00
# put all thirdparty libraries in paddle.libs
libs_path = ' $ {PADDLE_BINARY_DIR} /python/paddle/libs '
2018-12-18 20:20:19 +08:00
2018-12-19 10:31:40 +08:00
package_data [ ' paddle.libs ' ] = [ ]
2025-03-31 11:56:20 +08:00
if ( ' $ {WITH_FLAGCX} ' == ' ON ' ) :
package_data [ ' paddle.libs ' ] + = [ ( ' libflagcx ' if os . name != ' nt ' else ' flagcx ' ) + ext_name ]
shutil . copy ( ' $ {FLAGCX_LIB} ' , libs_path )
2023-06-12 14:10:18 +08:00
if ( ' $ {WITH_SHARED_PHI} ' == ' ON ' ) :
2023-06-20 12:59:54 +08:00
package_data [ ' paddle.libs ' ] + = [ ( ' libphi ' if os . name != ' nt ' else ' phi ' ) + ext_name ]
2023-05-26 17:12:32 +08:00
shutil . copy ( ' $ {PHI_LIB} ' , libs_path )
2025-08-30 10:30:13 +08:00
if os . name != ' nt ' :
package_data [ ' paddle.libs ' ] + = [ ( ' libphi_core ' if os . name != ' nt ' else ' phi_core ' ) + ext_name ]
shutil . copy ( ' $ {PHI_CORE_LIB} ' , libs_path )
if ( ' $ {WITH_GPU} ' == ' ON ' or ' $ {WITH_ROCM} ' == ' ON ' ) :
package_data [ ' paddle.libs ' ] + = [ ( ' libphi_gpu ' if os . name != ' nt ' else ' phi_gpu ' ) + ext_name ]
shutil . copy ( ' $ {PHI_GPU_LIB} ' , libs_path )
2026-02-10 11:27:18 +08:00
if os . name == ' nt ' :
package_data [ ' paddle.libs ' ] + = [ ' phi.lib ' ]
shutil . copy ( ' $ {PHI_LINK} ' , libs_path )
2023-05-26 17:12:32 +08:00
2023-06-20 12:59:54 +08:00
if ( ' $ {WITH_SHARED_IR} ' == ' ON ' ) :
2023-09-09 20:17:57 +08:00
package_data [ ' paddle.libs ' ] + = [ ( ' libpir ' if os . name != ' nt ' else ' pir ' ) + ext_name ]
2023-06-20 12:59:54 +08:00
shutil . copy ( ' $ {IR_LIB} ' , libs_path )
2023-05-26 17:12:32 +08:00
package_data [ ' paddle.libs ' ] + = [
2022-12-23 14:14:01 +08:00
( ' libwarpctc ' if os . name != ' nt ' else ' warpctc ' ) + ext_name ,
( ' libwarprnnt ' if os . name != ' nt ' else ' warprnnt ' ) + ext_name ,
]
2023-11-15 16:22:28 +08:00
package_data [ ' paddle.libs ' ] + = [
( ' libcommon ' if os . name != ' nt ' else ' common ' ) + ext_name ,
]
2025-04-26 17:17:11 +08:00
if os . name == ' nt ' :
package_data [ ' paddle.libs ' ] + = [ ' common.lib ' ]
shutil . copy ( ' $ {COMMON_LINK} ' , libs_path )
2023-11-15 16:22:28 +08:00
shutil . copy ( ' $ {COMMON_LIB} ' , libs_path )
2018-12-18 20:20:19 +08:00
shutil . copy ( ' $ {WARPCTC_LIBRARIES} ' , libs_path )
2022-12-23 14:14:01 +08:00
shutil . copy ( ' $ {WARPRNNT_LIBRARIES} ' , libs_path )
2018-12-18 17:04:48 +08:00
2021-09-22 11:01:36 +08:00
package_data [ ' paddle.libs ' ] + = [
2023-01-29 13:05:45 +08:00
os . path . basename ( ' $ {LAPACK_LIB} ' ) ,
2021-09-22 11:01:36 +08:00
os . path . basename ( ' $ {BLAS_LIB} ' ) ,
os . path . basename ( ' $ {GFORTRAN_LIB} ' ) ,
os . path . basename ( ' $ {GNU_RT_LIB_1} ' ) ]
shutil . copy ( ' $ {BLAS_LIB} ' , libs_path )
shutil . copy ( ' $ {LAPACK_LIB} ' , libs_path )
shutil . copy ( ' $ {GFORTRAN_LIB} ' , libs_path )
shutil . copy ( ' $ {GNU_RT_LIB_1} ' , libs_path )
2025-12-01 14:28:40 +08:00
if ( ' $ {WITH_MAGMA} ' == ' ON ' ) :
package_data [ ' paddle.libs ' ] + = [
os . path . basename ( ' $ {MAGMA_LIB} ' ) ]
shutil . copy ( ' $ {MAGMA_LIB} ' , libs_path )
2022-11-03 11:22:23 +08:00
2021-09-22 11:01:36 +08:00
if not sys . platform . startswith ( " linux " ) :
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( ' $ {GNU_RT_LIB_2} ' ) ]
shutil . copy ( ' $ {GNU_RT_LIB_2} ' , libs_path )
2024-07-03 20:29:01 +08:00
if ' $ {WITH_GPU} ' == ' ON ' or ' $ {WITH_ROCM} ' == ' ON ' :
2024-02-23 14:28:34 +08:00
if len ( ' $ {FLASHATTN_LIBRARIES} ' ) > 1 :
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( ' $ {FLASHATTN_LIBRARIES} ' ) ]
shutil . copy ( ' $ {FLASHATTN_LIBRARIES} ' , libs_path )
2024-11-14 15:09:42 +08:00
if len ( ' $ {FLASHATTN_V3_LIBRARIES} ' ) > 1 :
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( ' $ {FLASHATTN_V3_LIBRARIES} ' ) ]
shutil . copy ( ' $ {FLASHATTN_V3_LIBRARIES} ' , libs_path )
2025-08-27 10:54:26 +08:00
if len ( ' $ {FLASHMASK_V2_LIBRARIES} ' ) > 1 :
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( ' $ {FLASHMASK_V2_LIBRARIES} ' ) ]
shutil . copy ( ' $ {FLASHMASK_V2_LIBRARIES} ' , libs_path )
2023-03-01 23:03:33 +08:00
2025-03-10 10:52:19 +08:00
if ' $ {WITH_DISTRIBUTE} ' == ' ON ' and ' $ {WITH_NVSHMEM} ' == ' ON ' :
2025-03-11 11:25:14 +08:00
package_data [ ' paddle.libs ' ] + = [
os . path . basename ( ' $ {NVSHMEM_BOOTSTRAP_UID_LIB} ' ) ,
os . path . basename ( ' $ {NVSHMEM_BOOTSTRAP_PMI_LIB} ' ) ,
os . path . basename ( ' $ {NVSHMEM_BOOTSTRAP_PMI2_LIB} ' ) ,
os . path . basename ( ' $ {NVSHMEM_TRANSPORT_IBRC_LIB} ' ) ,
os . path . basename ( ' $ {NVSHMEM_TRANSPORT_IBGDA_LIB} ' ) ,
]
2025-03-10 10:52:19 +08:00
shutil . copy ( ' $ {NVSHMEM_BOOTSTRAP_UID_LIB} ' , libs_path )
shutil . copy ( ' $ {NVSHMEM_BOOTSTRAP_PMI_LIB} ' , libs_path )
shutil . copy ( ' $ {NVSHMEM_BOOTSTRAP_PMI2_LIB} ' , libs_path )
shutil . copy ( ' $ {NVSHMEM_TRANSPORT_IBRC_LIB} ' , libs_path )
shutil . copy ( ' $ {NVSHMEM_TRANSPORT_IBGDA_LIB} ' , libs_path )
2018-07-05 22:24:32 +08:00
if ' $ {WITH_MKL} ' == ' ON ' :
2018-12-18 11:36:42 +08:00
shutil . copy ( ' $ {MKLML_SHARED_LIB} ' , libs_path )
shutil . copy ( ' $ {MKLML_SHARED_IOMP_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ( ' libmklml_intel ' if os . name != ' nt ' else ' mklml ' ) + ext_name , ( ' libiomp5 ' if os . name != ' nt ' else ' libiomp5md ' ) + ext_name ]
2025-11-27 17:34:27 +08:00
elif ' $ {WITH_HML} ' == ' ON ' :
shutil . copy ( ' $ {HML_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' libhml_rt ' + ext_name ]
2018-12-18 15:38:33 +08:00
else :
if os . name == ' nt ' :
2018-12-18 17:04:48 +08:00
# copy the openblas.dll
2019-12-26 11:42:52 +08:00
shutil . copy ( ' $ {OPENBLAS_SHARED_LIB} ' , libs_path )
2018-12-19 10:31:40 +08:00
package_data [ ' paddle.libs ' ] + = [ ' openblas ' + ext_name ]
2021-01-14 10:54:59 +08:00
elif os . name == ' posix ' and platform . machine ( ) == ' aarch64 ' and ' $ {OPENBLAS_LIB} ' . endswith ( ' so ' ) :
2021-01-12 20:21:29 +08:00
# copy the libopenblas.so on linux+aarch64
2022-09-16 13:33:11 +08:00
# special: libpaddle.so without avx depends on 'libopenblas.so.0', not 'libopenblas.so'
2021-01-14 10:54:59 +08:00
if os . path . exists ( ' $ {OPENBLAS_LIB} ' + ' .0 ' ) :
shutil . copy ( ' $ {OPENBLAS_LIB} ' + ' .0 ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' libopenblas.so.0 ' ]
2018-12-18 15:38:33 +08:00
2021-11-10 16:19:11 +08:00
if ' $ {WITH_CINN} ' == ' ON ' :
shutil . copy ( ' $ {CINN_LIB_LOCATION} /$ {CINN_LIB_NAME} ' , libs_path )
2023-06-27 10:35:02 +08:00
shutil . copy ( ' $ {CINN_INCLUDE_DIR} /paddle/cinn/runtime/cuda/cinn_cuda_runtime_source.cuh ' , libs_path )
2024-08-09 12:29:59 +08:00
shutil . copy ( ' $ {CINN_INCLUDE_DIR} /paddle/cinn/runtime/hip/cinn_hip_runtime_source.h ' , libs_path )
2025-03-28 14:17:17 +08:00
shutil . copy ( ' $ {CINN_INCLUDE_DIR} /paddle/cinn/runtime/sycl/cinn_sycl_runtime_source.h ' , libs_path )
2021-11-10 16:19:11 +08:00
package_data [ ' paddle.libs ' ] + = [ ' libcinnapi.so ' ]
2021-12-07 14:16:08 +08:00
package_data [ ' paddle.libs ' ] + = [ ' cinn_cuda_runtime_source.cuh ' ]
2024-08-09 12:29:59 +08:00
package_data [ ' paddle.libs ' ] + = [ ' cinn_hip_runtime_source.h ' ]
2025-03-28 14:17:17 +08:00
package_data [ ' paddle.libs ' ] + = [ ' cinn_sycl_runtime_source.h ' ]
2022-12-27 19:57:36 +08:00
2023-06-27 10:35:02 +08:00
cinn_fp16_file = ' $ {CINN_INCLUDE_DIR} /paddle/cinn/runtime/cuda/float16.h '
2025-09-01 10:39:35 +08:00
if ' $ {WITH_ROCM} ' == ' ON ' :
cinn_fp16_file = ' $ {CINN_INCLUDE_DIR} /paddle/cinn/runtime/hip/float16.h '
2022-12-27 19:57:36 +08:00
if os . path . exists ( cinn_fp16_file ) :
shutil . copy ( cinn_fp16_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' float16.h ' ]
2023-06-27 10:35:02 +08:00
cinn_bf16_file = ' $ {CINN_INCLUDE_DIR} /paddle/cinn/runtime/cuda/bfloat16.h '
2023-05-11 20:53:17 +08:00
if os . path . exists ( cinn_bf16_file ) :
shutil . copy ( cinn_bf16_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' bfloat16.h ' ]
2025-07-29 19:47:35 +08:00
cinn_fp8_file = ' $ {CINN_INCLUDE_DIR} /paddle/cinn/runtime/cuda/float8e4m3.h '
if os . path . exists ( cinn_fp8_file ) :
shutil . copy ( cinn_fp8_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' float8e4m3.h ' ]
2022-06-21 16:31:56 +08:00
if ' $ {CMAKE_BUILD_TYPE} ' == ' Release ' and os . name != ' nt ' :
2025-12-03 14:23:00 +08:00
if ( ' @WITH_GPU@ ' == ' ON ' and tuple ( map ( int , ' @CUDA_VERSION@ ' . split ( ' . ' ) ) ) > = ( 13 , 0 ) and tuple ( map ( int , ' @CUDA_VERSION@ ' . split ( ' . ' ) ) ) < ( 14 , 0 ) ) :
2026-03-17 10:34:51 +08:00
command = " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cu13/lib/:$ORIGIN/../../nvidia/cudnn/lib/:$ORIGIN/ ' %s /$ {CINN_LIB_NAME} " % libs_path
2025-12-03 14:23:00 +08:00
if os . system ( command ) != 0 :
raise Exception ( " patch %s /$ {CINN_LIB_NAME} failed, command: %s " % ( libs_path , command ) )
else :
2026-03-17 10:34:51 +08:00
command = " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_nvrtc/lib/:$ORIGIN/../../nvidia/cuda_runtime/lib/:$ORIGIN/../../nvidia/cublas/lib/:$ORIGIN/../../nvidia/cudnn/lib/:$ORIGIN/../../nvidia/curand/lib/:$ORIGIN/../../nvidia/cusolver/lib/:$ORIGIN/../../nvidia/nvtx/lib/:$ORIGIN/ ' %s /$ {CINN_LIB_NAME} " % libs_path
2025-12-03 14:23:00 +08:00
if os . system ( command ) != 0 :
raise Exception ( " patch %s /$ {CINN_LIB_NAME} failed, command: %s " % ( libs_path , command ) )
2021-11-10 16:19:11 +08:00
2019-09-17 15:11:39 +08:00
2024-04-10 11:14:24 +08:00
if ' $ {WITH_ONEDNN} ' == ' ON ' :
2018-12-21 10:25:37 +08:00
if ' $ {CMAKE_BUILD_TYPE} ' == ' Release ' and os . name != ' nt ' :
2018-12-20 19:29:51 +08:00
# only change rpath in Release mode.
# TODO(typhoonzero): use install_name_tool to patch mkl libs once
# we can support mkl on mac.
#
2020-01-04 05:43:06 +01:00
# change rpath of libdnnl.so.1, add $ORIGIN/ to it.
2018-12-20 19:29:51 +08:00
# The reason is that all thirdparty libraries in the same directory,
2020-01-04 05:43:06 +01:00
# thus, libdnnl.so.1 will find libmklml_intel.so and libiomp5.so.
2026-03-17 10:34:51 +08:00
command = " patchelf --force-rpath --set-rpath ' $ORIGIN/ ' $ {ONEDNN_SHARED_LIB} "
2018-12-20 19:29:51 +08:00
if os . system ( command ) != 0 :
2020-01-04 05:43:06 +01:00
raise Exception ( " patch libdnnl.so failed, command: %s " % command )
2024-04-19 10:22:58 +08:00
shutil . copy ( ' $ {ONEDNN_SHARED_LIB} ' , libs_path )
2019-12-10 09:37:26 +01:00
if os . name != ' nt ' :
2023-07-12 10:46:33 +08:00
package_data [ ' paddle.libs ' ] + = [ ' libdnnl.so.3 ' ]
2020-01-04 05:43:06 +01:00
else :
package_data [ ' paddle.libs ' ] + = [ ' mkldnn.dll ' ]
2022-03-10 20:50:24 +08:00
if ' $ {WITH_ONNXRUNTIME} ' == ' ON ' :
shutil . copy ( ' $ {ONNXRUNTIME_SHARED_LIB} ' , libs_path )
2022-06-06 06:59:27 -05:00
shutil . copy ( ' $ {PADDLE2ONNX_LIB} ' , libs_path )
2022-03-10 20:50:24 +08:00
if os . name == ' nt ' :
package_data [ ' paddle.libs ' ] + = [ ' paddle2onnx.dll ' , ' onnxruntime.dll ' ]
else :
2022-06-22 01:17:50 -05:00
package_data [ ' paddle.libs ' ] + = [ ' $ {PADDLE2ONNX_LIB_NAME} ' , ' $ {ONNXRUNTIME_LIB_NAME} ' ]
2022-03-10 20:50:24 +08:00
2024-12-13 17:03:15 +08:00
if ' $ {WITH_OPENVINO} ' == ' ON ' :
shutil . copy ( ' $ {OPENVINO_LIB} ' , libs_path )
shutil . copy ( ' $ {TBB_LIB} ' , libs_path )
shutil . copy ( ' $ {OPENVINO_PADDLE_LIB} ' , libs_path )
shutil . copy ( ' $ {OPENVINO_CPU_PLUGIN_LIB} ' , libs_path )
if os . name != ' nt ' :
package_data [ ' paddle.libs ' ] + = [ ' libopenvino.so.2500 ' , ' libtbb.so.12 ' , ' libopenvino_paddle_frontend.so.2500 ' , ' libopenvino_intel_cpu_plugin.so ' ]
else :
package_data [ ' paddle.libs ' ] + = [ ' openvino.dll ' , ' tbb.dll ' , ' openvino_paddle_frontend.dll ' , ' openvino_intel_cpu_plugin.dll ' ]
2020-08-21 15:21:49 +08:00
if ' $ {WITH_XPU} ' == ' ON ' :
shutil . copy ( ' $ {XPU_API_LIB} ' , libs_path )
2022-11-04 15:28:58 +08:00
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_API_LIB_NAME} ' ]
xpu_rt_lib_list = glob . glob ( ' $ {XPU_RT_LIB} * ' )
for xpu_rt_lib_file in xpu_rt_lib_list :
shutil . copy ( xpu_rt_lib_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( xpu_rt_lib_file ) ]
2024-06-11 10:54:11 +08:00
xpu_cuda_lib_list = glob . glob ( ' $ {XPU_CUDA_LIB} * ' )
for xpu_cuda_lib_file in xpu_cuda_lib_list :
shutil . copy ( xpu_cuda_lib_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( xpu_cuda_lib_file ) ]
2024-11-13 19:26:01 +08:00
if ' $ {WITH_XPU_XRE5} ' == ' ON ' :
xpu_cuda_rt_lib_list = glob . glob ( ' $ {XPU_CUDA_RT_LIB} * ' )
for xpu_cuda_rt_lib_file in xpu_cuda_rt_lib_list :
shutil . copy ( xpu_cuda_rt_lib_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( xpu_cuda_rt_lib_file ) ]
2024-11-28 15:17:49 +08:00
xpu_ml_lib_list = glob . glob ( ' $ {XPU_ML_LIB} * ' )
for xpu_ml_lib_file in xpu_ml_lib_list :
shutil . copy ( xpu_ml_lib_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( xpu_ml_lib_file ) ]
2024-11-13 19:26:01 +08:00
shutil . copy ( ' $ {XPU_XBLAS_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XBLAS_LIB_NAME} ' ]
2026-01-05 13:45:45 +08:00
shutil . copy ( ' $ {XPU_XBLAS_JITC_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XBLAS_JITC_LIB_NAME} ' ]
shutil . copy ( ' $ {XPU_XBLAS_LLVM_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XBLAS_LLVM_LIB_NAME} ' ]
shutil . copy ( ' $ {XPU_XBLAS_CLANG_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XBLAS_CLANG_LIB_NAME} ' ]
2024-11-13 19:26:01 +08:00
shutil . copy ( ' $ {XPU_XFA_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XFA_LIB_NAME} ' ]
shutil . copy ( ' $ {XPU_XPUDNN_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XPUDNN_LIB_NAME} ' ]
2025-08-05 15:45:02 +08:00
shutil . copy ( ' $ {XPU_XPUDNN_OMP_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XPUDNN_OMP_LIB_NAME} ' ]
2025-11-18 10:39:11 +08:00
shutil . copy ( ' $ {XPU_XPUTX_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XPUTX_LIB_NAME} ' ]
2025-11-21 17:11:21 +08:00
shutil . copy ( ' $ {XPU_CUPTI_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_CUPTI_LIB_NAME} ' ]
2020-08-21 15:21:49 +08:00
2020-12-28 17:57:29 +08:00
if ' $ {WITH_XPU_BKCL} ' == ' ON ' :
shutil . copy ( ' $ {XPU_BKCL_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_BKCL_LIB_NAME} ' ]
2025-05-07 16:18:42 +08:00
if ' $ {WITH_XPU_FFT} ' == ' ON ' :
xpu_fft_lib_list = glob . glob ( ' $ {XPU_FFT_LIB} * ' )
for xpu_fft_lib_file in xpu_fft_lib_list :
shutil . copy ( xpu_fft_lib_file , libs_path )
package_data [ ' paddle.libs ' ] + = [ os . path . basename ( xpu_fft_lib_file ) ]
2023-03-06 15:08:14 +08:00
if ' $ {WITH_XPU_XFT} ' == ' ON ' :
shutil . copy ( ' $ {XPU_XFT_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XFT_LIB_NAME} ' ]
2023-06-26 11:50:41 +08:00
if ' $ {WITH_XPTI} ' == ' ON ' :
shutil . copy ( ' $ {XPU_XPTI_LIB} ' , libs_path )
package_data [ ' paddle.libs ' ] + = [ ' $ {XPU_XPTI_LIB_NAME} ' ]
2018-07-05 22:24:32 +08:00
# remove unused paddle/libs/__init__.py
2018-11-06 14:38:54 +08:00
if os . path . isfile ( libs_path + ' /__init__.py ' ) :
os . remove ( libs_path + ' /__init__.py ' )
2018-07-05 22:24:32 +08:00
package_dir [ ' paddle.libs ' ] = libs_path
2019-09-28 23:35:03 +08:00
2019-06-12 18:07:26 +08:00
# change rpath of ${FLUID_CORE_NAME}.ext, add $ORIGIN/../libs/ to it.
2018-11-09 10:40:45 +08:00
# The reason is that libwarpctc.ext, libiomp5.ext etc are in paddle.libs, and
2023-09-07 17:26:19 +08:00
# ${FLUID_CORE_NAME}.ext is in paddle.base, thus paddle/fluid/../libs will pointer to above libraries.
2018-07-05 22:24:32 +08:00
# This operation will fix https://github.com/PaddlePaddle/Paddle/issues/3213
2018-08-21 11:01:22 +08:00
if ' $ {CMAKE_BUILD_TYPE} ' == ' Release ' :
2018-11-05 15:13:53 +08:00
if os . name != ' nt ' :
2019-06-12 18:07:26 +08:00
# only change rpath in Release mode, since in Debug mode, ${FLUID_CORE_NAME}.xx is too large to be changed.
2018-08-21 11:01:22 +08:00
if " @APPLE@ " == " 1 " :
2023-09-07 17:26:19 +08:00
commands = [ " install_name_tool -id ' @loader_path/../libs/ ' $ {PADDLE_BINARY_DIR} /python/paddle/base/$ {FLUID_CORE_NAME} " + ' .so ' ]
commands . append ( " install_name_tool -add_rpath ' @loader_path/../libs/ ' $ {PADDLE_BINARY_DIR} /python/paddle/base/$ {FLUID_CORE_NAME} " + ' .so ' )
2023-12-04 17:00:41 +08:00
commands . append ( " install_name_tool -add_rpath ' @loader_path/../libs/ ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {COMMON_NAME} " )
2023-06-12 14:10:18 +08:00
if ( ' $ {WITH_SHARED_PHI} ' == ' ON ' ) :
2023-05-26 17:12:32 +08:00
# change rpath of phi.ext for loading 3rd party libb
commands . append ( " install_name_tool -add_rpath ' @loader_path ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_NAME} " )
2024-06-17 11:06:39 +08:00
commands . append ( " install_name_tool -add_rpath ' @loader_path ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_CORE_NAME} " )
if ( ' $ {WITH_GPU} ' == ' ON ' or ' $ {WITH_ROCM} ' == ' ON ' ) :
commands . append ( " install_name_tool -add_rpath ' @loader_path ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_GPU_NAME} " )
2023-06-20 12:59:54 +08:00
if ( ' $ {WITH_SHARED_IR} ' == ' ON ' ) :
2023-09-22 11:56:17 +08:00
# change rpath of pir.ext for loading 3rd party libb
2023-06-20 12:59:54 +08:00
commands . append ( " install_name_tool -add_rpath ' @loader_path ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {IR_NAME} " )
2018-08-21 11:01:22 +08:00
else :
2025-12-03 14:23:00 +08:00
if ( ' @WITH_GPU@ ' == ' ON ' and tuple ( map ( int , ' @CUDA_VERSION@ ' . split ( ' . ' ) ) ) > = ( 13 , 0 ) and tuple ( map ( int , ' @CUDA_VERSION@ ' . split ( ' . ' ) ) ) < ( 14 , 0 ) ) :
2026-03-17 10:34:51 +08:00
commands = [ " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cu13/lib:$ORIGIN/../../nvidia/cudnn/lib:$ORIGIN/../../nvidia/nccl/lib:$ORIGIN/../../cusparselt/lib:$ORIGIN/../libs/ ' $ {PADDLE_BINARY_DIR} /python/paddle/base/$ {FLUID_CORE_NAME} " + ' .so ' ]
2025-12-03 14:23:00 +08:00
if ( ' $ {WITH_SHARED_PHI} ' == ' ON ' ) :
# change rpath of phi.ext for loading 3rd party lib
2026-03-17 10:34:51 +08:00
commands . append ( " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_runtime/lib/:$ORIGIN/../../nvidia/cu13/lib:$ORIGIN:$ORIGIN/../libs ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_NAME} " )
commands . append ( " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_runtime/lib/:$ORIGIN/../../nvidia/cu13/lib:$ORIGIN:$ORIGIN/../libs ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_CORE_NAME} " )
2025-12-03 14:23:00 +08:00
if ( ' $ {WITH_GPU} ' == ' ON ' or ' $ {WITH_ROCM} ' == ' ON ' ) :
2026-03-17 10:34:51 +08:00
commands . append ( " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_runtime/lib/:$ORIGIN/../../nvidia/cu13/lib:$ORIGIN:$ORIGIN/../libs ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_GPU_NAME} " )
2025-12-03 14:23:00 +08:00
else :
2026-03-17 10:34:51 +08:00
commands = [ " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_runtime/lib:$ORIGIN/../../nvidia/cuda_nvrtc/lib:$ORIGIN/../../nvidia/cublas/lib:$ORIGIN/../../nvidia/cudnn/lib:$ORIGIN/../../nvidia/curand/lib:$ORIGIN/../../nvidia/cusparse/lib:$ORIGIN/../../nvidia/nvjitlink/lib:$ORIGIN/../../nvidia/cuda_cupti/lib:$ORIGIN/../../nvidia/cuda_runtime/lib:$ORIGIN/../../nvidia/cufft/lib:$ORIGIN/../../nvidia/cufft/lib:$ORIGIN/../../nvidia/cusolver/lib:$ORIGIN/../../nvidia/nccl/lib:$ORIGIN/../../nvidia/nvtx/lib:$ORIGIN/../libs/ ' $ {PADDLE_BINARY_DIR} /python/paddle/base/$ {FLUID_CORE_NAME} " + ' .so ' ]
2025-12-03 14:23:00 +08:00
if ( ' $ {WITH_SHARED_PHI} ' == ' ON ' ) :
# change rpath of phi.ext for loading 3rd party lib
2026-03-17 10:34:51 +08:00
commands . append ( " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_runtime/lib:$ORIGIN:$ORIGIN/../libs ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_NAME} " )
commands . append ( " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_runtime/lib:$ORIGIN:$ORIGIN/../libs ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_CORE_NAME} " )
2025-12-03 14:23:00 +08:00
if ( ' $ {WITH_GPU} ' == ' ON ' or ' $ {WITH_ROCM} ' == ' ON ' ) :
2026-03-17 10:34:51 +08:00
commands . append ( " patchelf --force-rpath --set-rpath ' $ORIGIN/../../nvidia/cuda_runtime/lib:$ORIGIN:$ORIGIN/../libs ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {PHI_GPU_NAME} " )
2023-06-20 12:59:54 +08:00
if ( ' $ {WITH_SHARED_IR} ' == ' ON ' ) :
2023-09-22 11:56:17 +08:00
# change rpath of pir.ext for loading 3rd party lib
2026-03-17 10:34:51 +08:00
commands . append ( " patchelf --force-rpath --set-rpath ' $ORIGIN:$ORIGIN/../libs ' $ {PADDLE_BINARY_DIR} /python/paddle/libs/$ {IR_NAME} " )
2024-02-26 10:43:40 +08:00
# The sw_64 not support patchelf, so we just disable that.
2021-01-12 20:21:29 +08:00
if platform . machine ( ) != ' sw_64 ' and platform . machine ( ) != ' mips64 ' :
2021-09-22 11:01:36 +08:00
for command in commands :
if os . system ( command ) != 0 :
raise Exception ( " patch $ {FLUID_CORE_NAME} . %s failed, command: %s " % ( ext_name , command ) )
2018-11-05 15:13:53 +08:00
2018-11-05 21:06:57 +08:00
ext_modules = [ Extension ( ' _foo ' , [ ' stub.cc ' ] ) ]
2018-11-05 15:13:53 +08:00
if os . name == ' nt ' :
# fix the path separator under windows
fix_package_dir = { }
for k , v in package_dir . items ( ) :
fix_package_dir [ k ] = v . replace ( ' / ' , ' \\ ' )
package_dir = fix_package_dir
2018-11-05 21:06:57 +08:00
ext_modules = [ ]
2019-08-05 19:06:14 +08:00
elif sys . platform == ' darwin ' :
ext_modules = [ ]
2017-08-13 21:52:16 +08:00
2021-04-23 21:21:54 +08:00
def find_files ( pattern , root , recursive = False ) :
2019-09-28 23:35:03 +08:00
for dirpath , _ , files in os . walk ( root ) :
2021-04-23 21:21:54 +08:00
for filename in fnmatch . filter ( files , pattern ) :
yield os . path . join ( dirpath , filename )
if not recursive :
break
2019-09-28 23:35:03 +08:00
headers = (
2023-03-21 14:45:31 +08:00
# paddle level api headers (high level api, for both training and inference)
New custom operator extension mechanism (#30690)
* initial commit: simple demo
* polish copyright format
* add grap op simple demo
* adapt uncertain number of argument
* change trait marco name
* add place & dtype support for add kernel
* add dispath and infershape func
* poish code & add notes
* add dynamic_loader dep for paddle_framework
* add new custom op test dir
* polish impl details
* add unittest for new custom op
* fix failed unittest
* Costum op (#1)
* fix compile error
* wrap framework tensor with LoDTensor
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* add CustomTensor default constructor
* add size() for CustomTensor
* make size const for CustomTensor
* refactor place related api to circle the concept
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* make place const
* make Tensor copy
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* remove additional head of framework
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* add gpu test
* merge latest cwh code in
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* Remove ShareData from user && Change CustomTensor to Tensor && Support more data type (#2)
* fix compile error
* wrap framework tensor with LoDTensor
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* add CustomTensor default constructor
* add size() for CustomTensor
* make size const for CustomTensor
* refactor place related api to circle the concept
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* make place const
* make Tensor copy
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* remove additional head of framework
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* add gpu test
* merge latest cwh code in
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* hid share data from and to
* rename CustomTensor to Tensor
* refactor register design & add test
* change op_funtion to op_meta_info
* split op meta info into .h and .cc
* move get methods into friend class
* move OpMetaInfoHelper into framework space
* move CustomTensorUtils into framework space
* change pybind api name
* move PD C API into op meta info
* add register custom op api
* remove inference cmake change
* refactor copy to api && change Reshape to lowercase && support more dtype && add more test (#3)
* fix compile error
* wrap framework tensor with LoDTensor
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* add CustomTensor default constructor
* add size() for CustomTensor
* make size const for CustomTensor
* refactor place related api to circle the concept
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* make place const
* make Tensor copy
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* remove additional head of framework
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* add gpu test
* merge latest cwh code in
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* hid share data from and to
* rename CustomTensor to Tensor
* support multi dtype
* remove lod, make reshape lowercase, add copy test and refactor copy api
* remove lod, make reshape lowercase, add copy test and refactor copy api
* remove lod, make reshape lowercase, add copy test and refactor copy api
* remove lod, make reshape lowercase, add copy test and refactor copy api
* fix copy to error
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* polish detail & error message
* polish test details
* Add cast api && Change copy related api to copy_to && add more test (#4)
* fix compile error
* wrap framework tensor with LoDTensor
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* add CustomTensor default constructor
* add size() for CustomTensor
* make size const for CustomTensor
* refactor place related api to circle the concept
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* fix compile error
* make place const
* make Tensor copy
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* debug CustomTensor core
* remove additional head of framework
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* use back to shared ptr for custom tensor
* add gpu test
* merge latest cwh code in
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* adjust ut code of custom op
* hid share data from and to
* rename CustomTensor to Tensor
* support multi dtype
* remove lod, make reshape lowercase, add copy test and refactor copy api
* remove lod, make reshape lowercase, add copy test and refactor copy api
* remove lod, make reshape lowercase, add copy test and refactor copy api
* remove lod, make reshape lowercase, add copy test and refactor copy api
* fix copy to error
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add more test
* add type cast
* add cast and make copy to api
* add cast and make copy to api
* add cast and make copy to api
* add cast and make copy to api
* merge cwh code
* merge cwh code
* merge cwh code
* merge cwh code
* merge cwh code
* add more error log
* add more error log
* polish code
* used for test
* remove test comment
* remove test comment
* fix uint8 type error
* fix lost uint8 type error
* add test for coverage
* polish details by reviewer comments
* add prefix for DISABLE_COPY_AND_ASSIGN
Co-authored-by: Jiabin Yang <360788950@qq.com>
2021-02-09 21:04:39 -06:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle ' ) ) +
2023-12-04 17:00:41 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/common ' ) ) + # paddle common headers
2022-02-28 12:45:03 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/api ' ) ) + # phi unify api header
2022-02-20 22:16:56 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/api/ext ' ) ) + # custom op api
2022-02-28 12:45:03 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/api/include ' ) ) + # phi api
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/common ' ) ) + # phi common headers
2025-08-31 09:09:30 +08:00
# torch compatible apis
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/api/include/compat ' , recursive = True ) ) +
2023-03-21 14:45:31 +08:00
# phi level api headers (low level api, for training only)
2022-03-04 13:28:48 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi ' ) ) + # phi extension header
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/include ' , recursive = True ) ) + # phi include headers
2025-12-22 10:56:15 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends ' ) ) + # phi backends headers
2022-03-04 13:28:48 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/core ' , recursive = True ) ) + # phi core headers
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/infermeta ' , recursive = True ) ) + # phi infermeta headers
2023-03-21 14:45:31 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/kernels ' , recursive = True ) ) + # phi kernels headers
2022-06-16 21:42:39 +08:00
# capi headers
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/capi ' , recursive = True ) ) + # phi capi headers
2023-03-20 17:32:18 +08:00
# phi profiler headers
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/api/profiler ' ) ) +
2022-07-27 14:03:17 +08:00
# utils api headers
2023-03-20 17:32:18 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/utils ' , recursive = True ) ) + # paddle utils headers
# init headers
2024-02-29 14:23:57 +08:00
list ( find_files ( ' init_phi.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/platform ' ) ) + # phi init headers
# init headers
2024-03-02 04:32:36 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/pir/include ' , recursive = True ) ) + # pir init headers
2024-02-29 14:23:57 +08:00
# init headers
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/drr/include ' ) ) + # drr init headers
2024-10-15 16:44:42 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape ' ) ) +
2024-08-21 10:34:05 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/ir ' ) ) + # operator init headers
2025-01-07 10:34:18 +08:00
list ( find_files ( ' sub_graph_detector.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/transforms/ ' ) ) +
2025-12-04 16:24:27 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/distributed/collective/ ' ) ) +
2024-07-31 20:53:12 +08:00
list ( find_files ( ' general_functions.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/utils ' ) ) +
2024-08-21 10:34:05 +08:00
list ( find_files ( ' interface.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/serialize_deserialize/include ' ) ) +
list ( find_files ( ' dense_tensor.inl ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/core ' ) ) +
list ( find_files ( ' op_yaml_info.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/interface ' ) ) +
2024-09-25 15:07:30 +08:00
list ( find_files ( ' op_yaml_info_util.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/utils/ ' ) ) +
2024-09-27 10:44:49 +08:00
list ( find_files ( ' op_yaml_info_parser.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/utils/ ' ) ) +
list ( find_files ( ' utils.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/utils/ ' ) ) +
2024-10-10 10:16:18 +08:00
list ( find_files ( ' op_compat_info.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/ir_adaptor/translator/ ' ) ) +
list ( find_files ( ' op_yaml_info_parser.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/utils/ ' ) ) +
2024-10-15 16:44:42 +08:00
list ( find_files ( ' vjp.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/interface/ ' ) ) +
2024-10-10 10:16:18 +08:00
list ( find_files ( ' infer_symbolic_shape.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/ ' ) ) +
#pir headers
list ( find_files ( ' lexer.h ' , ' @PADDLE_SOURCE_DIR@/paddle/pir/src/core/parser/ ' ) ) +
2025-01-02 10:33:22 +08:00
list ( find_files ( ' token.h ' , ' @PADDLE_SOURCE_DIR@/paddle/pir/src/core/parser/ ' ) ) +
2025-02-06 19:39:44 +08:00
#pir ops and dependency
list ( find_files ( ' pd_op.h ' , ' @PADDLE_BINARY_DIR@/paddle/fluid/pir/dialect/operator/ir/ ' ) ) +
2025-02-12 15:04:18 +08:00
list ( find_files ( ' pd_op_sig.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/ir_adaptor/translator/ ' ) ) +
2025-02-06 19:39:44 +08:00
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/interface/ ' ) ) +
list ( find_files ( ' *.hpp ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/interface/ ' ) ) +
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/trait/ ' ) ) +
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/operator/utils/ ' ) ) +
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/dialect/kernel/ir/ ' ) ) +
list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/pir/include/core/ ' ) ) +
2025-02-12 15:04:18 +08:00
list ( find_files ( ' pd_op_to_kernel_pass.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/pir/transforms/ ' ) ) +
2025-01-07 10:34:18 +08:00
#custom_engine
list ( find_files ( ' custom_engine_ext.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/custom_engine/ ' ) ) +
2025-01-02 10:33:22 +08:00
#new_executor headers
list ( find_files ( ' pir_adaptor_util.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/framework/new_executor/pir_adaptor/ ' ) ) +
2025-02-06 19:39:44 +08:00
list ( find_files ( ' custom_engine_instruction.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/framework/new_executor/instruction/ ' ) ) +
2025-02-12 15:04:18 +08:00
list ( find_files ( ' instruction_defs.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/framework/new_executor/instruction/ ' ) ) +
2025-02-06 19:39:44 +08:00
list ( find_files ( ' instruction_base.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/framework/new_executor/instruction/ ' ) ) )
2022-08-08 14:24:19 +08:00
jit_layer_headers = [ ' layer.h ' , ' serializer.h ' , ' serializer_utils.h ' , ' all.h ' , ' function.h ' ]
2022-07-27 14:03:17 +08:00
for f in jit_layer_headers :
2022-08-04 10:57:08 +08:00
headers + = list ( find_files ( f , ' @PADDLE_SOURCE_DIR@/paddle/fluid/jit ' , recursive = True ) )
2019-09-28 23:35:03 +08:00
2024-04-10 11:14:24 +08:00
if ' $ {WITH_ONEDNN} ' == ' ON ' :
2026-03-30 14:51:25 +08:00
headers + = list ( find_files ( ' * ' , ' $ {ONEDNN_INSTALL_DIR} /include ' , recursive = True ) ) # mkldnn
2019-11-21 15:18:26 +08:00
2024-12-13 17:03:15 +08:00
if ' $ {WITH_OPENVINO} ' == ' ON ' :
headers + = list (
find_files ( ' * ' , ' $ {OPENVINO_INC_DIR} ' )
) # openvino
headers + = list (
find_files ( ' * ' , ' $ {TBB_INC_DIR} ' )
) # tbb
2021-01-21 19:24:14 +08:00
if ' $ {WITH_GPU} ' == ' ON ' or ' $ {WITH_ROCM} ' == ' ON ' :
2021-05-27 10:07:13 +08:00
# externalErrorMsg.pb for External Error message
headers + = list ( find_files ( ' *.pb ' , ' $ {externalError_INCLUDE_DIR} ' ) )
2025-12-22 10:56:15 +08:00
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends ' , recursive = True )
)
2025-06-05 19:26:23 +08:00
2023-03-23 10:02:05 +08:00
if ' $ {WITH_XPU} ' == ' ON ' :
2025-11-27 19:17:13 +08:00
headers + = [
h for h in find_files ( ' *.h ' , ' @PADDLE_BINARY_DIR@/third_party/xpu/src/extern_xpu/xpu ' , recursive = True )
if ' /include/xpu/kernel/ ' not in h
] # xdnn api headers
2024-11-13 19:26:01 +08:00
headers + = list ( find_files ( ' *.hpp ' , ' @PADDLE_BINARY_DIR@/third_party/xpu/src/extern_xpu/xpu ' , recursive = True ) ) # xre headers with .hpp extension
2025-12-22 10:56:15 +08:00
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_BINARY_DIR@/paddle/phi/backends/cpu ' )
)
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/xpu ' )
)
headers + = list (
find_files (
' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload '
)
)
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/onednn ' )
)
2023-03-07 15:30:14 +08:00
2025-06-05 19:26:23 +08:00
if (
' @WITH_GPU@ ' == ' ON '
and tuple ( map ( int , ' @CUDA_VERSION@ ' . split ( ' . ' ) ) ) > = ( 12 , 9 )
and ' @COMPILED_CUDA_ARCHS@ ' . find ( " 90 " ) != - 1
) :
headers + = list ( find_files ( ' *.hpp ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/fp8/deep_gemm/include/cute/ ' , recursive = True ) )
headers + = list ( find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/fp8/deep_gemm/include/cutlass/ ' , recursive = True ) )
headers + = list ( find_files ( ' *.hpp ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/fp8/deep_gemm/include/cutlass/ ' , recursive = True ) )
headers + = list ( find_files ( ' *.cuh ' , ' @PADDLE_SOURCE_DIR@/paddle/fluid/fp8/deep_gemm/include/deep_gemm ' , recursive = True ) )
2025-12-22 10:56:15 +08:00
if (
' @WITH_GPU@ ' == ' OFF '
and ' @WITH_ROCM@ ' == ' OFF '
and ' @WITH_XPU@ ' == ' OFF '
) : # Custom Device
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/cpu ' )
)
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/custom ' )
)
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/gpu ' , recursive = True )
)
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/onednn ' )
)
headers + = [
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/afs_api.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/dynamic_loader.h ' ,
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/mklml.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/mklrt.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/lapack.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/hml.h '
) ,
]
else :
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/cpu ' )
)
headers + = list (
find_files ( ' *.h ' , ' @PADDLE_SOURCE_DIR@/paddle/phi/backends/onednn ' )
)
headers + = [
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/afs_api.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/dynamic_loader.h ' ,
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/mklml.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/mklrt.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/lapack.h '
) ,
os . path . join (
' @PADDLE_SOURCE_DIR@/paddle/phi/backends/dynload/hml.h '
) ,
]
2025-06-05 19:26:23 +08:00
[Cpp Extension] Support Cpp Extension (#49893)
* update include directory
* fully support C++ extension, pass unittest
* fix include directory
* support both extension and operator in one file
* polish testcase
* add jit unittest
* update third_party.cmake, pass CI test
* fix cmake
* fix setup
* fix inference, fix unittest precision
* fix unittest precision
* fix inference_lib cmake
* try fix setup, try fix inference_lib
* try fix inference_lib pybind
* fix mix_op_extension, fix inference_lib
* fix mix_op_extension, fix inference_lib
* change cmake
* change cmake
* add compile flags
* add Python.h headerfile
* add test_custom_plugin_creater cmake
* comment compile flag
* pass all CI
* pass all CI
* comment compile flag
* try solve test_custom_plugin_creater link error
* try solve test_custom_plugin_creater link error
* polish codes
* remove windows compile flag
* remove python_include_path
* update pybind11, 2.4.3->2.6.0
* update pybind11, 2.6.0->2.10.0
* update pybind11, 2.10.0->2.6.0b1
* update pybind11, 2.6.0b1->2.6.0, start fix unittest
* fix pybind11 2.6.0 VarBase print error
* fix pybind11 2.6.0 VarBase print error
* handle PADDLE_ON_INFERENCE
* modify according to reviewer
* fix cmake
* cmake decouple pybind_util when not ON_INFER
* cmake decouple pybind_util when not ON_INFER
* remove copy of inference_lib.cmake
* change pybind.cc headerfile fluid->phi
2023-02-20 14:25:16 +08:00
headers + = list ( find_files ( ' *.h ' , ' $ {PYBIND_INCLUDE_DIR} ' , True ) ) # pybind headers
2023-04-26 19:42:05 +08:00
def get_header_install_dir ( header ) :
if ' pb.h ' in header :
install_dir = re . sub ( ' $ {PADDLE_BINARY_DIR} / ' , ' ' , header )
elif ' third_party ' not in header :
# paddle headers
install_dir = re . sub ( ' @PADDLE_SOURCE_DIR@/ ' , ' ' , header )
if ' fluid/jit ' in install_dir :
install_dir = re . sub ( ' fluid/jit ' , ' jit ' , install_dir )
else :
# third_party
install_dir = re . sub ( ' $ {THIRD_PARTY_PATH} ' , ' third_party ' , header )
patterns = [ ' install/mkldnn/include ' , ' pybind/src/extern_pybind/include ' , ' third_party/xpu/src/extern_xpu/xpu/include/ ' ]
for pattern in patterns :
install_dir = re . sub ( pattern , ' ' , install_dir )
return install_dir
2019-09-28 23:35:03 +08:00
class InstallCommand ( InstallCommandBase ) :
def finalize_options ( self ) :
ret = InstallCommandBase . finalize_options ( self )
self . install_lib = self . install_platlib
New whl release strategy with pruned nv_fatbin (#35239)
[Background]
Expansion in code size can be irreversible in the long run, leading to huge release packages which
not only hampers user experience but also exceeds a hard limit of pypi.
In such, NV_FATBIN section takes up 86% of the compiled dylib size, owing to the vast number of GPU
arches supported.
This PR aims to prune this NV_FATBIN.
[Solution]
In the new release strategy, two types of whl packages will be involved:
Cubin PIP package:
PIP package maintains a smaller window for GPU arches support, containing
sm_60, sm_70, sm_75, sm_80 cubins, covering Pascal - Ampere arches
JIT release package:
This is a backup for Cubin PIP package, containing compute_35, compute_50, compute_60,
compute_70, compute_75, compute_80, with best performance and GPU arches coverage.
However, it takes around 10 min to install due to the JIT compilation.
[How to use]
The new release strategy is disabled by default.
To compile for Cubin PIP package, add this to cmake: -DCUBIN_RELEASE_PIP
To compile for JIT release package, add this to cmake: -DJIT_RELEASE_WHL
2021-08-31 18:09:18 +08:00
self . install_headers = os . path . join ( self . install_platlib , ' paddle ' , ' include ' )
2019-09-28 23:35:03 +08:00
return ret
2020-04-09 07:55:11 +02:00
2026-03-17 10:34:51 +08:00
2019-09-28 23:35:03 +08:00
class InstallHeaders ( Command ) :
""" Override how headers are copied.
"""
description = ' install C/C++ header files '
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
user_options = [ ( ' install-dir= ' , ' d ' ,
' directory to install header files to ' ) ,
( ' force ' , ' f ' ,
' force installation (overwrite existing files) ' ) ,
]
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
boolean_options = [ ' force ' ]
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
def initialize_options ( self ) :
self . install_dir = None
self . force = 0
self . outfiles = [ ]
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
def finalize_options ( self ) :
self . set_undefined_options ( ' install ' ,
( ' install_headers ' , ' install_dir ' ) ,
( ' force ' , ' force ' ) )
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
def mkdir_and_copy_file ( self , header ) :
2023-04-26 19:42:05 +08:00
install_dir = get_header_install_dir ( header )
2019-09-28 23:35:03 +08:00
install_dir = os . path . join ( self . install_dir , os . path . dirname ( install_dir ) )
if not os . path . exists ( install_dir ) :
self . mkpath ( install_dir )
return self . copy_file ( header , install_dir )
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
def run ( self ) :
hdrs = self . distribution . headers
if not hdrs :
return
self . mkpath ( self . install_dir )
for header in hdrs :
( out , _ ) = self . mkdir_and_copy_file ( header )
self . outfiles . append ( out )
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
def get_inputs ( self ) :
return self . distribution . headers or [ ]
2020-04-09 07:55:11 +02:00
2019-09-28 23:35:03 +08:00
def get_outputs ( self ) :
return self . outfiles
2022-04-25 10:43:36 +08:00
class EggInfo ( egg_info ) :
""" Copy license file into `.dist-info` folder. """
def run ( self ) :
# don't duplicate license into `.dist-info` when building a distribution
if not self . distribution . have_run . get ( ' install ' , True ) :
self . mkpath ( self . egg_info )
self . copy_file ( " @PADDLE_SOURCE_DIR@/LICENSE " , self . egg_info )
egg_info . run ( self )
2019-11-03 12:46:08 +08:00
# we redirect setuptools log for non-windows
if sys . platform != ' win32 ' :
@contextmanager
def redirect_stdout ( ) :
2019-12-09 16:03:25 +08:00
f_log = open ( ' $ {SETUP_LOG_FILE} ' , ' w ' )
origin_stdout = sys . stdout
sys . stdout = f_log
yield
f_log = sys . stdout
sys . stdout = origin_stdout
f_log . close ( )
2019-11-03 12:46:08 +08:00
else :
@contextmanager
def redirect_stdout ( ) :
yield
2021-01-28 19:15:13 +08:00
# Log for PYPI
2022-12-28 11:19:35 +08:00
with open ( " @PADDLE_BINARY_DIR@/python/paddle/README.md " , " r " , encoding = ' UTF-8 ' ) as f :
2022-10-11 12:06:33 +08:00
long_description = f . read ( )
2021-01-28 19:15:13 +08:00
2021-04-22 12:53:24 +08:00
# strip *.so to reduce package size
if ' $ {WITH_STRIP} ' == ' ON ' :
2023-11-14 12:47:30 +08:00
command = (
' find '
+ shlex . quote ( ' $ {PADDLE_BINARY_DIR} ' )
+ ' /python/paddle -name " *.so " | xargs -i strip {} '
)
2021-04-22 12:53:24 +08:00
if os . system ( command ) != 0 :
raise Exception ( " strip *.so failed, command: %s " % command )
2024-06-04 12:02:49 +08:00
def check_build_dependency ( ) :
missing_modules = ''' Missing build dependency: {dependency}
Please run ' pip install -r python/requirements.txt ' to make sure you have all the dependencies installed.
''' . strip ( )
with open ( ' $ {PADDLE_SOURCE_DIR} ' + ' /python/requirements.txt ' ) as f :
build_dependencies = (
f . read ( ) . splitlines ( )
) # Specify the dependencies to install
python_dependencies_module = [ ]
installed_packages = [ ]
2025-12-01 19:07:50 +08:00
def normalize_package_name ( package_name : str ) - > str :
return package_name . replace ( " _ " , " - " ) . lower ( )
2025-11-26 02:23:55 +08:00
def eval_marker ( marker_str ) :
""" Simple evaluation of PEP 508 environment markers. """
if not marker_str :
return True
marker_str = marker_str . strip ( )
# Build environment dict
env_markers = {
' python_version ' : ( sys . version_info . major , sys . version_info . minor ) ,
' python_full_version ' : (
sys . version_info . major ,
sys . version_info . minor ,
sys . version_info . micro ,
) ,
' platform_system ' : f ' " { platform . system ( ) } " ' ,
' platform_machine ' : f ' " { platform . machine ( ) } " ' ,
' sys_platform ' : f ' " { sys . platform } " ' ,
}
# Marker evaluation
try :
eval_str = marker_str
# Replace marker variables with their values
for key , value in env_markers . items ( ) :
eval_str = eval_str . replace ( key , str ( value ) )
def version_to_tuple ( match ) :
version_str = match . group ( 1 )
parts = version_str . split ( ' . ' )
return ' ( ' + ' , ' . join ( parts ) + ' ) '
eval_str = re . sub (
r ' [ " \' ]( \ d+(?: \ . \ d+)*)[ " \' ] ' , version_to_tuple , eval_str
)
return eval ( eval_str )
except Exception as e :
raise RuntimeError ( f " Failed to evaluate marker ' { marker_str } ' : { e } " )
2024-06-04 12:02:49 +08:00
for dependency in build_dependencies :
2025-11-26 02:23:55 +08:00
dependency = dependency . strip ( )
if not dependency or dependency . startswith ( ' # ' ) :
continue
# Split dependency spec and environment marker
if ' ; ' in dependency :
dependency_spec , marker = dependency . split ( ' ; ' , 1 )
dependency_spec = dependency_spec . strip ( )
marker = marker . strip ( )
# Evaluate marker - skip if not applicable to current environment
if not eval_marker ( marker ) :
continue
else :
dependency_spec = dependency
# Remove version specifiers from dependency spec
dependency_name = re . sub (
r " ==.*|>=.*|<=.*|~=.*|!=.* " , ' ' , dependency_spec
) . strip ( )
2025-12-01 19:07:50 +08:00
python_dependencies_module . append (
normalize_package_name ( dependency_name )
)
2025-11-26 02:23:55 +08:00
2024-06-04 12:02:49 +08:00
reqs = subprocess . check_output ( [ sys . executable , ' -m ' , ' pip ' , ' freeze ' ] )
for r in reqs . split ( ) :
installed_packages . append (
2025-12-01 19:07:50 +08:00
normalize_package_name ( r . decode ( ) . split ( ' == ' ) [ 0 ] )
2024-06-04 12:02:49 +08:00
)
for dependency in python_dependencies_module :
if dependency . lower ( ) not in installed_packages :
raise RuntimeError ( missing_modules . format ( dependency = dependency ) )
2023-04-26 19:42:05 +08:00
def install_cpp_dist_and_build_test ( paddle_install_dir , paddle_lib_test_dir ) :
""" install cpp distribution and build test target
2023-06-27 10:35:02 +08:00
TODO(huangjiyi):
[CodeStyle][Typos][S-[1-14],S-[16-18]] Fix typos(SMAE,satifies,sclar,sacle,sheduler,schduler,scheule,shedule,serach,seconde,Sel (#70772)
2025-01-14 10:16:19 +08:00
1. This function will be moved when separating C++ distribution
2023-04-26 19:42:05 +08:00
installation from python package installation.
2. Reduce the header and library files to be installed.
"""
if ' $ {CMAKE_BUILD_TYPE} ' != ' Release ' :
return
os . makedirs ( paddle_install_dir , exist_ok = True )
# install C++ header files
2023-06-27 10:35:02 +08:00
for header in headers :
2023-04-26 19:42:05 +08:00
install_dir = get_header_install_dir ( header )
install_dir = os . path . join (
paddle_install_dir , ' include ' , os . path . dirname ( install_dir )
)
os . makedirs ( install_dir , exist_ok = True )
shutil . copy ( header , install_dir )
# install C++ shared libraries
lib_install_dir = os . path . join ( paddle_install_dir , ' lib ' )
os . makedirs ( lib_install_dir , exist_ok = True )
# install libpaddle.ext
paddle_libs = glob . glob ( ' $ {PADDLE_BINARY_DIR} /paddle/fluid/pybind/$ {FLUID_CORE_NAME} .* ' )
for lib in paddle_libs :
shutil . copy ( lib , lib_install_dir )
# install dependent libraries
libs_path = package_dir [ ' paddle.libs ' ]
for lib in package_data [ ' paddle.libs ' ] :
lib_path = os . path . join ( libs_path , lib )
shutil . copy ( lib_path , lib_install_dir )
2023-06-27 10:35:02 +08:00
2023-04-26 19:42:05 +08:00
# build test target
cmake_args = [ " cmake " , paddle_lib_test_dir , " -B " , paddle_lib_test_dir ]
if os . getenv ( " GENERATOR " ) == " Ninja " :
cmake_args . append ( " -GNinja " )
subprocess . check_call ( cmake_args )
subprocess . check_call ( [ " cmake " , " --build " , paddle_lib_test_dir ] )
2024-06-04 12:02:49 +08:00
# check build dependency
check_build_dependency ( )
2023-04-26 19:42:05 +08:00
# install cpp distribution
if ' $ {WITH_CPP_DIST} ' == ' ON ' :
paddle_install_dir = ' $ {PADDLE_INSTALL_DIR} '
paddle_lib_test_dir = ' $ {PADDLE_LIB_TEST_DIR} '
install_cpp_dist_and_build_test ( paddle_install_dir , paddle_lib_test_dir )
2023-06-27 10:35:02 +08:00
2024-09-25 18:51:00 +08:00
2024-05-13 11:33:38 +08:00
# type hints
2024-09-25 18:51:00 +08:00
def get_typing_libs_packages ( paddle_binary_dir ) :
""" get all libpaddle sub modules from ' python/paddle/_typing/libs/libpaddle '
e.g.
' paddle._typing.libs.libpaddle.pir '
' paddle._typing.libs.libpaddle.eager '
' paddle._typing.libs.libpaddle.eager.ops '
"""
base_dir = Path ( paddle_binary_dir ) / ' python '
libs_dir = base_dir / ' paddle ' / ' _typing ' / ' libs ' / ' libpaddle '
return [
' . ' . join ( str ( Path ( root ) . relative_to ( base_dir ) ) . split ( os . sep ) )
for root , _ , _ in os . walk ( libs_dir )
]
def extend_type_hints_package_data ( packages , package_data , paddle_binary_dir ) :
typing_libs_packages = get_typing_libs_packages ( paddle_binary_dir )
# update packages
packages + = typing_libs_packages
# update package_data
2024-09-05 11:10:08 +08:00
type_hints_files = {
2024-09-25 18:51:00 +08:00
' paddle ' : [ ' py.typed ' , ' *.pyi ' ] ,
2024-09-05 11:10:08 +08:00
' paddle.framework ' : [ ' *.pyi ' ] ,
' paddle.base ' : [ ' *.pyi ' ] ,
' paddle.tensor ' : [ ' tensor.pyi ' ] ,
' paddle._typing ' : [ ' *.pyi ' ] ,
2024-09-25 18:51:00 +08:00
' paddle._typing.libs ' : [ ' *.pyi ' , ' *.md ' ] ,
2024-09-05 11:10:08 +08:00
}
2024-09-25 18:51:00 +08:00
for libpaddle_module in typing_libs_packages :
type_hints_files [ libpaddle_module ] = [ ' *.pyi ' ]
2024-09-05 11:10:08 +08:00
for pkg , files in type_hints_files . items ( ) :
if pkg not in package_data :
package_data [ pkg ] = [ ]
package_data [ pkg ] + = files
2024-09-25 18:51:00 +08:00
return packages , package_data
2024-09-05 11:10:08 +08:00
def generate_stub_files ( paddle_binary_dir , paddle_source_dir ) :
2024-06-04 12:02:49 +08:00
script_path = paddle_source_dir + ' /tools/ '
sys . path . append ( script_path )
2024-09-05 11:10:08 +08:00
print ( ' - ' * 2 , ' Generate stub file tensor.pyi ... ' )
2024-06-04 12:02:49 +08:00
import gen_tensor_stub
gen_tensor_stub . generate_stub_file (
input_file = paddle_source_dir
+ ' /python/paddle/tensor/tensor.prototype.pyi ' ,
output_file = paddle_binary_dir + ' /python/paddle/tensor/tensor.pyi ' ,
)
shutil . copy (
paddle_binary_dir + ' /python/paddle/tensor/tensor.pyi ' ,
paddle_source_dir + ' /python/paddle/tensor/tensor.pyi ' ,
)
2024-09-05 11:10:08 +08:00
print ( ' - ' * 2 , ' End Generate stub file tensor.pyi ... ' )
print ( ' - ' * 2 , ' Generate stub file for python binding APIs ... ' )
import gen_pybind11_stub
gen_pybind11_stub . generate_stub_file (
output_dir = str ( Path ( paddle_binary_dir ) / ' python/paddle/_typing/libs/ ' ) ,
module_name = ' paddle.base.libpaddle ' ,
ignore_all_errors = True ,
ops_yaml = [
paddle_source_dir
+ " /paddle/phi/ops/yaml/ops.yaml;paddle.base.libpaddle.eager.ops " ,
paddle_source_dir
+ " /paddle/phi/ops/yaml/ops.yaml;paddle.base.libpaddle.pir.ops " ,
paddle_source_dir
+ " /paddle/phi/ops/yaml/sparse_ops.yaml;paddle.base.libpaddle.eager.ops;sparse " ,
paddle_source_dir
+ " /paddle/phi/ops/yaml/sparse_ops.yaml;paddle.base.libpaddle.pir.ops;sparse " ,
paddle_source_dir
+ " /paddle/phi/ops/yaml/strings_ops.yaml;paddle.base.libpaddle.eager.ops;strings " ,
paddle_source_dir
+ " /paddle/phi/ops/yaml/strings_ops.yaml;paddle.base.libpaddle.pir.ops;strings " ,
] ,
2025-09-08 11:08:14 +08:00
python_api_info_yaml_path = paddle_source_dir
+ " /paddle/phi/ops/yaml/python_api_info.yaml " ,
2024-09-05 11:10:08 +08:00
)
libpaddle_dst = paddle_source_dir + ' /python/paddle/_typing/libs/libpaddle '
if Path ( libpaddle_dst ) . exists ( ) :
shutil . rmtree ( libpaddle_dst )
shutil . copytree (
paddle_binary_dir + ' /python/paddle/_typing/libs/libpaddle ' ,
libpaddle_dst ,
)
print ( ' - ' * 2 , ' End Generate stub for python binding APIs ... ' )
2024-06-04 12:02:49 +08:00
# generate stub file `tensor.pyi`
2024-07-05 14:08:09 +08:00
if os . getenv ( " SKIP_STUB_GEN " , ' ' ) . lower ( ) not in [
' y ' ,
' yes ' ,
' t ' ,
' true ' ,
' on ' ,
' 1 ' ,
] :
2024-09-05 11:10:08 +08:00
generate_stub_files ( ' $ {PADDLE_BINARY_DIR} ' , ' $ {PADDLE_SOURCE_DIR} ' )
2024-06-04 12:02:49 +08:00
2024-09-25 18:51:00 +08:00
packages , package_data = extend_type_hints_package_data ( packages , package_data , ' $ {PADDLE_BINARY_DIR} ' )
2024-06-04 12:02:49 +08:00
2019-11-03 12:46:08 +08:00
with redirect_stdout ( ) :
setup ( name = ' $ {PACKAGE_NAME} ' ,
version = ' $ {PADDLE_VERSION} ' ,
description = ' Parallel Distributed Deep Learning ' ,
2021-01-28 19:15:13 +08:00
long_description = long_description ,
long_description_content_type = " text/markdown " ,
author_email = " Paddle-better@baidu.com " ,
maintainer = " PaddlePaddle " ,
maintainer_email = " Paddle-better@baidu.com " ,
project_urls = {
' Homepage ' : ' https://www.paddlepaddle.org.cn/ ' ,
' Downloads ' : ' https://github.com/paddlepaddle/paddle '
2022-11-10 11:17:01 +08:00
} ,
2021-01-28 19:15:13 +08:00
license = ' Apache Software License ' ,
2019-11-03 12:46:08 +08:00
packages = packages ,
2021-01-28 19:15:13 +08:00
install_requires = setup_requires ,
2019-11-03 12:46:08 +08:00
ext_modules = ext_modules ,
package_data = package_data ,
package_dir = package_dir ,
scripts = paddle_bins ,
distclass = BinaryDistribution ,
headers = headers ,
cmdclass = {
' install_headers ' : InstallHeaders ,
' install ' : InstallCommand ,
2022-04-25 10:43:36 +08:00
' egg_info ' : EggInfo ,
2020-08-05 10:49:43 +08:00
} ,
entry_points = {
' console_scripts ' : [
2022-03-23 11:00:13 +08:00
' fleetrun = paddle.distributed.launch.main:launch '
2020-08-05 10:49:43 +08:00
]
2021-01-28 19:15:13 +08:00
} ,
classifiers = [
' Development Status :: 5 - Production/Stable ' ,
' Operating System :: OS Independent ' ,
' Intended Audience :: Developers ' ,
' Intended Audience :: Education ' ,
' Intended Audience :: Science/Research ' ,
' License :: OSI Approved :: Apache Software License ' ,
' Programming Language :: C++ ' ,
2023-01-04 14:43:20 +08:00
' Programming Language :: Python :: 3.9 ' ,
' Programming Language :: Python :: 3.10 ' ,
2023-12-06 18:21:07 +08:00
' Programming Language :: Python :: 3.11 ' ,
' Programming Language :: Python :: 3.12 ' ,
2024-11-08 19:04:09 +08:00
' Programming Language :: Python :: 3.13 ' ,
2024-05-13 11:33:38 +08:00
' Typing :: Typed ' ,
2021-01-28 19:15:13 +08:00
] ,
2019-11-03 12:46:08 +08:00
)
2019-10-16 11:14:53 +08:00
# As there are a lot of files in purelib which causes many logs,
2020-04-09 07:55:11 +02:00
# we don't print them on the screen, and you can open `setup.py.log`
2019-10-16 11:14:53 +08:00
# for the full logs.
2019-11-03 12:46:08 +08:00
if os . path . exists ( ' $ {SETUP_LOG_FILE} ' ) :
os . system ( ' grep -v " purelib " $ {SETUP_LOG_FILE} ' )