From 1a404657e9e9669fc8f3b3286504dc779e5718d8 Mon Sep 17 00:00:00 2001 From: pangyoki Date: Thu, 3 Nov 2022 11:22:23 +0800 Subject: [PATCH] add cuDNN dynamic-link libraries into wheel package (#47552) * add cudnn into whl package * add cudnn dso into whl package * let WITH_CUDNN_DSO be consistent with WITH_GPU * fix WITH_CUDNN_DSO in paddle_build --- CMakeLists.txt | 12 ++++++++++++ paddle/scripts/paddle_build.sh | 4 ++++ python/setup.py.in | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 187162cffe7..bd35fcb26a6 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 e29fd6549ee..bcecab8ba35 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 76daa99e4b4..b58d7b052dc 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) -- GitLab