diff --git a/CMakeLists.txt b/CMakeLists.txt index 187162cffe7229af41c19e9a089894c30369fe46..bd35fcb26a60ab0c0e5b6f54e562299501b9ea34 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,6 +307,8 @@ option(WITH_FLPS "FL PS mode" OFF) option(WITH_RPC "Compile with rpc support" ${WITH_DISTRIBUTE}) option(WITH_CUDNN_FRONTEND "Compile with CUDNN Frontend API support (experimental)" OFF) +option(WITH_CUDNN_DSO "Compile PaddlePaddle with cuDNN dynamic-link libraries" + ${WITH_GPU}) if(WITH_RECORD_BUILDTIME) set_property( @@ -390,6 +392,16 @@ if(NOT WITH_GPU AND WITH_NCCL) CACHE STRING "Disable NCCL when compiling without GPU" FORCE) endif() +if(NOT WITH_GPU AND WITH_CUDNN_DSO) + message( + WARNING + "Can't compile with cuDNN libraries when compiling without GPU. Force WITH_CUDNN_DSO=OFF." + ) + set(WITH_CUDNN_DSO + OFF + CACHE STRING "Disable cuDNN libraries when compiling without GPU" FORCE) +endif() + # force WITH_XPU on when WITH_XPU_KP if(WITH_XPU_KP AND NOT WITH_XPU) message( diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index e29fd6549ee02ba627c0603ca2398095578bacca..bcecab8ba356fe854f9dc03ac608e3f478c66307 100755 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -197,6 +197,8 @@ function cmake_base() { INFERENCE_DEMO_INSTALL_DIR=${INFERENCE_DEMO_INSTALL_DIR:-/root/.cache/inference_demo} fi + WITH_CUDNN_DSO=${WITH_GPU:-OFF} + distibuted_flag=${WITH_DISTRIBUTE:-OFF} gloo_flag=${distibuted_flag} @@ -214,6 +216,7 @@ function cmake_base() { -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} ${PYTHON_FLAGS} -DWITH_GPU=${WITH_GPU:-OFF} + -DWITH_CUDNN_DSO=${WITH_CUDNN_DSO:-OFF} -DWITH_TENSORRT=${WITH_TENSORRT:-ON} -DWITH_ROCM=${WITH_ROCM:-OFF} -DWITH_CINN=${WITH_CINN:-OFF} @@ -269,6 +272,7 @@ EOF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} \ ${PYTHON_FLAGS} \ -DWITH_GPU=${WITH_GPU:-OFF} \ + -DWITH_CUDNN_DSO=${WITH_CUDNN_DSO:-OFF} \ -DWITH_TENSORRT=${WITH_TENSORRT:-ON} \ -DWITH_ROCM=${WITH_ROCM:-OFF} \ -DWITH_CINN=${WITH_CINN:-OFF} \ diff --git a/python/setup.py.in b/python/setup.py.in index 76daa99e4b44647770a581608de6927d26fb11d8..b58d7b052dcdd03d24f48bd27d2639eb19651f62 100755 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -8,6 +8,7 @@ import sys import fnmatch import errno import platform +import glob from contextlib import contextmanager from setuptools import Command @@ -471,6 +472,19 @@ 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) +if '${WITH_CUDNN_DSO}' == 'ON' and os.path.exists('${CUDNN_LIBRARY}'): + package_data['paddle.libs']+=[os.path.basename('${CUDNN_LIBRARY}')] + shutil.copy('${CUDNN_LIBRARY}', libs_path) + if sys.platform.startswith("linux") and '${CUDNN_MAJOR_VERSION}' == '8': + # libcudnn.so includes libcudnn_ops_infer.so, libcudnn_ops_train.so, + # libcudnn_cnn_infer.so, libcudnn_cnn_train.so, libcudnn_adv_infer.so, + # libcudnn_adv_train.so + cudnn_lib_files = glob.glob(os.path.dirname('${CUDNN_LIBRARY}') + '/libcudnn_*so.8') + for cudnn_lib in cudnn_lib_files: + if os.path.exists(cudnn_lib): + package_data['paddle.libs']+=[os.path.basename(cudnn_lib)] + shutil.copy(cudnn_lib, libs_path) + 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)