Skip to content

Commit

Permalink
add cuDNN dynamic-link libraries into wheel package (PaddlePaddle#47552)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pangyoki authored Nov 3, 2022
1 parent aa342a2 commit 1a40465
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions paddle/scripts/paddle_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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}
Expand Down Expand Up @@ -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} \
Expand Down
14 changes: 14 additions & 0 deletions python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import sys
import fnmatch
import errno
import platform
import glob

from contextlib import contextmanager
from setuptools import Command
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1a40465

Please sign in to comment.