From 57d9b800b0045861781550b791a0790801520fea Mon Sep 17 00:00:00 2001 From: YuanRisheng Date: Thu, 15 Jun 2023 10:31:05 +0800 Subject: [PATCH] [Cherry-Pick]Add PHI option in cmake (#54462) (#54576) * Add PHI option in cmake (#54462) * add phi option in cmake * modify default option * fix windows bugs * perfect log * change default mode * change phi so on for py3 * fix mac bugs * fix mac bugs * delete code --- CMakeLists.txt | 3 ++- cmake/configure.cmake | 14 +------------ cmake/inference_lib.cmake | 2 +- .../eager/auto_code_generator/CMakeLists.txt | 2 +- paddle/fluid/pybind/CMakeLists.txt | 2 +- paddle/phi/CMakeLists.txt | 10 +++++----- paddle/scripts/paddle_build.sh | 20 ++++++++++--------- python/env_dict.py.in | 2 +- python/setup.py.in | 6 +++--- setup.py | 6 +++--- test/CMakeLists.txt | 4 +++- 11 files changed, 32 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d62ae24020a12..a2e933c838a29 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,7 @@ option(WITH_IPU "Compile PaddlePaddle with Graphcore IPU" OFF) option(WITH_ONNXRUNTIME "Compile PaddlePaddle with ONNXRUNTIME" OFF) option(WITH_CUSPARSELT "Compile PaddlePaddle with CUSPARSELT" OFF) option(WITH_SETUP_INSTALL "Compile PaddlePaddle with setup.py" OFF) +option(WITH_SHARED_PHI "Compile PaddlePaddle with SHARED LIB of PHI" OFF) # Note(zhouwei): It use option above, so put here include(init) include(generic) # simplify cmake module @@ -111,7 +112,7 @@ endif() if(WIN32) option(MSVC_STATIC_CRT "use static C Runtime library by default" ON) - + message("Build static library of PHI") set(CMAKE_SUPPRESS_REGENERATION ON) set(CMAKE_STATIC_LIBRARY_PREFIX lib) diff --git a/cmake/configure.cmake b/cmake/configure.cmake index f092607f9ad93..dc661fce388fe 100644 --- a/cmake/configure.cmake +++ b/cmake/configure.cmake @@ -236,18 +236,6 @@ if(WITH_CUDNN_FRONTEND) add_definitions(-DPADDLE_WITH_CUDNN_FRONTEND) endif() -set(WITH_PHI_SHARED - ON - CACHE BOOL "" FORCE) -if(WIN32 - OR WITH_ROCM - OR WITH_XPU_KP - OR ON_INFER) - set(WITH_PHI_SHARED - OFF - CACHE BOOL "" FORCE) -endif() - -if(WITH_PHI_SHARED) +if(WITH_SHARED_PHI) add_definitions(-DPHI_SHARED) endif() diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index 0e6ba8c497efe..34d1fb7dd46fc 100755 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -269,7 +269,7 @@ else() SRCS ${src_dir}/inference/api/paddle_*.h ${paddle_inference_lib} DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib) - if(WITH_PHI_SHARED) + if(WITH_SHARED_PHI) set(paddle_phi_lib ${PADDLE_BINARY_DIR}/paddle/phi/libphi.*) copy( inference_lib_dist diff --git a/paddle/fluid/eager/auto_code_generator/CMakeLists.txt b/paddle/fluid/eager/auto_code_generator/CMakeLists.txt index d187b1abb11cc..51ab946f4f0f2 100644 --- a/paddle/fluid/eager/auto_code_generator/CMakeLists.txt +++ b/paddle/fluid/eager/auto_code_generator/CMakeLists.txt @@ -52,7 +52,7 @@ if(WIN32) set(eager_generator_path "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}") endif() - if(WITH_PHI_SHARED) + if(WITH_SHARED_PHI) message("Copied phi.dll for Eager AutoCodeGen") add_custom_command( OUTPUT ${eager_generator_path}/phi.dll diff --git a/paddle/fluid/pybind/CMakeLists.txt b/paddle/fluid/pybind/CMakeLists.txt index e25a0a7a85ecf..7bce2ba2144b9 100755 --- a/paddle/fluid/pybind/CMakeLists.txt +++ b/paddle/fluid/pybind/CMakeLists.txt @@ -330,7 +330,7 @@ if(WITH_PYTHON) ")\n" "exit /b 0") - if(WITH_PHI_SHARED) + if(WITH_SHARED_PHI) add_custom_command( OUTPUT ${op_impl_path}/phi.dll COMMAND ${CMAKE_COMMAND} -E copy ${PHI_LIB} ${op_impl_path} diff --git a/paddle/phi/CMakeLists.txt b/paddle/phi/CMakeLists.txt index bd9702f73d3e0..40e44bae076cc 100644 --- a/paddle/phi/CMakeLists.txt +++ b/paddle/phi/CMakeLists.txt @@ -97,7 +97,7 @@ set(PHI_SRCS ${infermeta_srcs} ${capi_srcs}) -if(WITH_PHI_SHARED) +if(WITH_SHARED_PHI) set(PHI_BUILD_TYPE SHARED CACHE INTERNAL "" FORCE) @@ -136,7 +136,7 @@ if(WIN32) endif() if(WIN32) - if(WITH_PHI_SHARED) + if(WITH_SHARED_PHI) set_property(TARGET phi PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) set(PHI_NAME phi.dll @@ -147,7 +147,7 @@ if(WIN32) CACHE INTERNAL "" FORCE) endif() elseif(APPLE) - if(WITH_PHI_SHARED) + if(WITH_SHARED_PHI) set(PHI_NAME libphi.dylib CACHE INTERNAL "" FORCE) @@ -157,7 +157,7 @@ elseif(APPLE) CACHE INTERNAL "" FORCE) endif() else() - if(WITH_PHI_SHARED) + if(WITH_SHARED_PHI) set(PHI_NAME libphi.so CACHE INTERNAL "" FORCE) @@ -187,7 +187,7 @@ if(WITH_FLASHATTN) endif() # for inference static library -if(NOT WITH_PHI_SHARED) +if(NOT WITH_SHARED_PHI) get_property(phi_modules GLOBAL PROPERTY PHI_MODULES) set(phi_modules ${phi_modules} ${INFERENCE_DEPS} phi) set_property(GLOBAL PROPERTY PHI_MODULES "${phi_modules}") diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 7c3b1d1f1c2ce..928b6850e3d93 100644 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -2958,17 +2958,17 @@ EOF startTime_s=`date +%s` set +e export MAX_JOBS=${parallel_number} - export WITH_DISTRIBUTE=OFF ON_INFER=ON WITH_TENSORRT=ON CUDA_ARCH_NAME=${CUDA_ARCH_NAME:-Auto} WITH_PYTHON=${WITH_PYTHON:-ON} WITH_ONNXRUNTIME=${WITH_ONNXRUNTIME:-OFF} + export WITH_DISTRIBUTE=OFF ON_INFER=ON WITH_TENSORRT=ON CUDA_ARCH_NAME=${CUDA_ARCH_NAME:-Auto} WITH_PYTHON=${WITH_PYTHON:-ON} WITH_ONNXRUNTIME=${WITH_ONNXRUNTIME:-OFF} WITH_SHARED_PHI=${WITH_SHARED_PHI:-OFF} echo "if you use setup.py to compile,please export envs as following in /paddle ..." cat << EOF ======================================== - export CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} WITH_GPU=${WITH_GPU:-OFF} WITH_CUDNN_DSO=${WITH_CUDNN_DSO:-OFF} WITH_TENSORRT=${WITH_TENSORRT:-ON} WITH_ROCM=${WITH_ROCM:-OFF} WITH_CINN=${WITH_CINN:-OFF} WITH_DISTRIBUTE=${distibuted_flag} WITH_MKL=${WITH_MKL:-ON} WITH_AVX=${WITH_AVX:-OFF} CUDA_ARCH_NAME=${CUDA_ARCH_NAME:-All} NEW_RELEASE_PYPI=${NEW_RELEASE_PYPI:-OFF} NEW_RELEASE_ALL=${NEW_RELEASE_ALL:-OFF} NEW_RELEASE_JIT=${NEW_RELEASE_JIT:-OFF} WITH_PYTHON=${WITH_PYTHON:-ON} CUDNN_ROOT=/usr/ WITH_TESTING=${WITH_TESTING:-ON} WITH_COVERAGE=${WITH_COVERAGE:-OFF} WITH_INCREMENTAL_COVERAGE=${WITH_INCREMENTAL_COVERAGE:-OFF} CMAKE_MODULE_PATH=/opt/rocm/hip/cmake CMAKE_EXPORT_COMPILE_COMMANDS=ON WITH_INFERENCE_API_TEST=${WITH_INFERENCE_API_TEST:-ON} INFERENCE_DEMO_INSTALL_DIR=${INFERENCE_DEMO_INSTALL_DIR} PY_VERSION=${PY_VERSION:-3.7} CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX:-/paddle/build} WITH_PSCORE=${pscore_flag} WITH_PSLIB=${pslib_flag} WITH_GLOO=${gloo_flag} LITE_GIT_TAG=release/v2.10 WITH_XPU=${WITH_XPU:-OFF} WITH_IPU=${WITH_IPU:-OFF} XPU_SDK_ROOT=${XPU_SDK_ROOT:-""} WITH_LITE=${WITH_LITE:-OFF} WITH_XPU_BKCL=${WITH_XPU_BKCL:-OFF} WITH_ARM=${WITH_ARM:-OFF} WITH_STRIP=${WITH_STRIP:-ON} ON_INFER=${ON_INFER:-OFF} WITH_HETERPS=${WITH_HETERPS:-OFF} WITH_GPU_GRAPH=${WITH_GPU_GRAPH:-OFF} CUDA_ARCH_BIN=${CUDA_ARCH_BIN} WITH_RECORD_BUILDTIME=${WITH_RECORD_BUILDTIME:-OFF} WITH_UNITY_BUILD=${WITH_UNITY_BUILD:-OFF} WITH_ONNXRUNTIME=${WITH_ONNXRUNTIME:-OFF} WITH_CUDNN_FRONTEND=${WITH_CUDNN_FRONTEND:-OFF} + export CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release} WITH_GPU=${WITH_GPU:-OFF} WITH_SHARED_PHI=${WITH_SHARED_PHI:-OFF} WITH_CUDNN_DSO=${WITH_CUDNN_DSO:-OFF} WITH_TENSORRT=${WITH_TENSORRT:-ON} WITH_ROCM=${WITH_ROCM:-OFF} WITH_CINN=${WITH_CINN:-OFF} WITH_DISTRIBUTE=${distibuted_flag} WITH_MKL=${WITH_MKL:-ON} WITH_AVX=${WITH_AVX:-OFF} CUDA_ARCH_NAME=${CUDA_ARCH_NAME:-All} NEW_RELEASE_PYPI=${NEW_RELEASE_PYPI:-OFF} NEW_RELEASE_ALL=${NEW_RELEASE_ALL:-OFF} NEW_RELEASE_JIT=${NEW_RELEASE_JIT:-OFF} WITH_PYTHON=${WITH_PYTHON:-ON} CUDNN_ROOT=/usr/ WITH_TESTING=${WITH_TESTING:-ON} WITH_COVERAGE=${WITH_COVERAGE:-OFF} WITH_INCREMENTAL_COVERAGE=${WITH_INCREMENTAL_COVERAGE:-OFF} CMAKE_MODULE_PATH=/opt/rocm/hip/cmake CMAKE_EXPORT_COMPILE_COMMANDS=ON WITH_INFERENCE_API_TEST=${WITH_INFERENCE_API_TEST:-ON} INFERENCE_DEMO_INSTALL_DIR=${INFERENCE_DEMO_INSTALL_DIR} PY_VERSION=${PY_VERSION:-3.7} CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX:-/paddle/build} WITH_PSCORE=${pscore_flag} WITH_PSLIB=${pslib_flag} WITH_GLOO=${gloo_flag} LITE_GIT_TAG=release/v2.10 WITH_XPU=${WITH_XPU:-OFF} WITH_IPU=${WITH_IPU:-OFF} XPU_SDK_ROOT=${XPU_SDK_ROOT:-""} WITH_LITE=${WITH_LITE:-OFF} WITH_XPU_BKCL=${WITH_XPU_BKCL:-OFF} WITH_ARM=${WITH_ARM:-OFF} WITH_STRIP=${WITH_STRIP:-ON} ON_INFER=${ON_INFER:-OFF} WITH_HETERPS=${WITH_HETERPS:-OFF} WITH_GPU_GRAPH=${WITH_GPU_GRAPH:-OFF} CUDA_ARCH_BIN=${CUDA_ARCH_BIN} WITH_RECORD_BUILDTIME=${WITH_RECORD_BUILDTIME:-OFF} WITH_UNITY_BUILD=${WITH_UNITY_BUILD:-OFF} WITH_ONNXRUNTIME=${WITH_ONNXRUNTIME:-OFF} WITH_CUDNN_FRONTEND=${WITH_CUDNN_FRONTEND:-OFF} ======================================== EOF echo "if you use cmake to compile,please Configuring cmake in /paddle/build ..." cat <) - target_link_libraries(${test_name} $) + if(WITH_SHARED_PHI) + target_link_libraries(${test_name} $) + endif() add_dependencies(${test_name} ${paddle_lib} paddle_gtest_main_new) if(WITH_GPU) target_link_libraries(${test_name} ${CUDA_CUDART_LIBRARY}