Skip to content

Commit

Permalink
[Cherry-Pick]Add PHI option in cmake (#54462) (#54576)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
YuanRisheng authored Jun 15, 2023
1 parent fbe8982 commit 57d9b80
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 39 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 1 addition & 13 deletions cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion cmake/inference_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/eager/auto_code_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
10 changes: 5 additions & 5 deletions paddle/phi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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}")
Expand Down
20 changes: 11 additions & 9 deletions paddle/scripts/paddle_build.sh

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion python/env_dict.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env_dict={
'FLUID_CORE_NAME':'@FLUID_CORE_NAME@',
'PHI_LIB':'@PHI_LIB@',
'PHI_NAME':'@PHI_NAME@',
'WITH_PHI_SHARED':'@WITH_PHI_SHARED@',
'WITH_SHARED_PHI':'@WITH_SHARED_PHI@',
'WARPCTC_LIBRARIES':'@WARPCTC_LIBRARIES@',
'WARPRNNT_LIBRARIES':'@WARPRNNT_LIBRARIES@',
'FLASHATTN_LIBRARIES':'@FLASHATTN_LIBRARIES@',
Expand Down
6 changes: 3 additions & 3 deletions python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ package_dir={
libs_path='${PADDLE_BINARY_DIR}/python/paddle/libs'

package_data['paddle.libs']= []
if('${WITH_PHI_SHARED}' == 'ON'):
if('${WITH_SHARED_PHI}' == 'ON'):
package_data['paddle.libs'] = [('libphi' if os.name != 'nt' else 'phi') + ext_name]
shutil.copy('${PHI_LIB}', libs_path)

Expand Down Expand Up @@ -728,12 +728,12 @@ if '${CMAKE_BUILD_TYPE}' == 'Release':
if "@APPLE@" == "1":
commands = ["install_name_tool -id '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so']
commands.append("install_name_tool -add_rpath '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so')
if('${WITH_PHI_SHARED}' == 'ON'):
if('${WITH_SHARED_PHI}' == 'ON'):
# 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}")
else:
commands = ["patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so']
if('${WITH_PHI_SHARED}' == 'ON'):
if('${WITH_SHARED_PHI}' == 'ON'):
# change rpath of phi.ext for loading 3rd party lib
commands.append("patchelf --set-rpath '$ORIGIN' ${PADDLE_BINARY_DIR}/python/paddle/libs/${PHI_NAME}")
# The sw_64 not suppot patchelf, so we just disable that.
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ def get_package_data_and_package_dir():
libs_path = paddle_binary_dir + '/python/paddle/libs'
package_data['paddle.libs'] = []

if env_dict.get("WITH_PHI_SHARED") == "ON":
if env_dict.get("WITH_SHARED_PHI") == "ON":
package_data['paddle.libs'] = [
('libphi' if os.name != 'nt' else 'phi') + ext_suffix
]
Expand Down Expand Up @@ -1211,7 +1211,7 @@ def get_package_data_and_package_dir():
+ env_dict.get("FLUID_CORE_NAME")
+ '.so'
)
if env_dict.get("WITH_PHI_SHARED") == "ON":
if env_dict.get("WITH_SHARED_PHI") == "ON":
commands.append(
"install_name_tool -add_rpath '@loader_path' "
+ env_dict.get("PADDLE_BINARY_DIR")
Expand All @@ -1226,7 +1226,7 @@ def get_package_data_and_package_dir():
+ env_dict.get("FLUID_CORE_NAME")
+ '.so'
]
if env_dict.get("WITH_PHI_SHARED") == "ON":
if env_dict.get("WITH_SHARED_PHI") == "ON":
commands.append(
"patchelf --set-rpath '$ORIGIN' "
+ env_dict.get("PADDLE_BINARY_DIR")
Expand Down
4 changes: 3 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ if(${len} GREATER_EQUAL 1)
add_executable(${test_name} ${test_src})
target_link_libraries(${test_name} paddle_gtest_main_new)
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:${paddle_lib}>)
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:phi>)
if(WITH_SHARED_PHI)
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:phi>)
endif()
add_dependencies(${test_name} ${paddle_lib} paddle_gtest_main_new)
if(WITH_GPU)
target_link_libraries(${test_name} ${CUDA_CUDART_LIBRARY}
Expand Down

0 comments on commit 57d9b80

Please sign in to comment.