Skip to content

Commit 57d9b80

Browse files
authored
[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
1 parent fbe8982 commit 57d9b80

File tree

11 files changed

+32
-39
lines changed

11 files changed

+32
-39
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ option(WITH_IPU "Compile PaddlePaddle with Graphcore IPU" OFF)
6262
option(WITH_ONNXRUNTIME "Compile PaddlePaddle with ONNXRUNTIME" OFF)
6363
option(WITH_CUSPARSELT "Compile PaddlePaddle with CUSPARSELT" OFF)
6464
option(WITH_SETUP_INSTALL "Compile PaddlePaddle with setup.py" OFF)
65+
option(WITH_SHARED_PHI "Compile PaddlePaddle with SHARED LIB of PHI" OFF)
6566
# Note(zhouwei): It use option above, so put here
6667
include(init)
6768
include(generic) # simplify cmake module
@@ -111,7 +112,7 @@ endif()
111112

112113
if(WIN32)
113114
option(MSVC_STATIC_CRT "use static C Runtime library by default" ON)
114-
115+
message("Build static library of PHI")
115116
set(CMAKE_SUPPRESS_REGENERATION ON)
116117
set(CMAKE_STATIC_LIBRARY_PREFIX lib)
117118

cmake/configure.cmake

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,6 @@ if(WITH_CUDNN_FRONTEND)
236236
add_definitions(-DPADDLE_WITH_CUDNN_FRONTEND)
237237
endif()
238238

239-
set(WITH_PHI_SHARED
240-
ON
241-
CACHE BOOL "" FORCE)
242-
if(WIN32
243-
OR WITH_ROCM
244-
OR WITH_XPU_KP
245-
OR ON_INFER)
246-
set(WITH_PHI_SHARED
247-
OFF
248-
CACHE BOOL "" FORCE)
249-
endif()
250-
251-
if(WITH_PHI_SHARED)
239+
if(WITH_SHARED_PHI)
252240
add_definitions(-DPHI_SHARED)
253241
endif()

cmake/inference_lib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ else()
269269
SRCS ${src_dir}/inference/api/paddle_*.h ${paddle_inference_lib}
270270
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/include
271271
${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib)
272-
if(WITH_PHI_SHARED)
272+
if(WITH_SHARED_PHI)
273273
set(paddle_phi_lib ${PADDLE_BINARY_DIR}/paddle/phi/libphi.*)
274274
copy(
275275
inference_lib_dist

paddle/fluid/eager/auto_code_generator/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if(WIN32)
5252
set(eager_generator_path "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
5353
endif()
5454

55-
if(WITH_PHI_SHARED)
55+
if(WITH_SHARED_PHI)
5656
message("Copied phi.dll for Eager AutoCodeGen")
5757
add_custom_command(
5858
OUTPUT ${eager_generator_path}/phi.dll

paddle/fluid/pybind/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ if(WITH_PYTHON)
330330
")\n"
331331
"exit /b 0")
332332

333-
if(WITH_PHI_SHARED)
333+
if(WITH_SHARED_PHI)
334334
add_custom_command(
335335
OUTPUT ${op_impl_path}/phi.dll
336336
COMMAND ${CMAKE_COMMAND} -E copy ${PHI_LIB} ${op_impl_path}

paddle/phi/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ set(PHI_SRCS
9797
${infermeta_srcs}
9898
${capi_srcs})
9999

100-
if(WITH_PHI_SHARED)
100+
if(WITH_SHARED_PHI)
101101
set(PHI_BUILD_TYPE
102102
SHARED
103103
CACHE INTERNAL "" FORCE)
@@ -136,7 +136,7 @@ if(WIN32)
136136
endif()
137137

138138
if(WIN32)
139-
if(WITH_PHI_SHARED)
139+
if(WITH_SHARED_PHI)
140140
set_property(TARGET phi PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
141141
set(PHI_NAME
142142
phi.dll
@@ -147,7 +147,7 @@ if(WIN32)
147147
CACHE INTERNAL "" FORCE)
148148
endif()
149149
elseif(APPLE)
150-
if(WITH_PHI_SHARED)
150+
if(WITH_SHARED_PHI)
151151
set(PHI_NAME
152152
libphi.dylib
153153
CACHE INTERNAL "" FORCE)
@@ -157,7 +157,7 @@ elseif(APPLE)
157157
CACHE INTERNAL "" FORCE)
158158
endif()
159159
else()
160-
if(WITH_PHI_SHARED)
160+
if(WITH_SHARED_PHI)
161161
set(PHI_NAME
162162
libphi.so
163163
CACHE INTERNAL "" FORCE)
@@ -187,7 +187,7 @@ if(WITH_FLASHATTN)
187187
endif()
188188

189189
# for inference static library
190-
if(NOT WITH_PHI_SHARED)
190+
if(NOT WITH_SHARED_PHI)
191191
get_property(phi_modules GLOBAL PROPERTY PHI_MODULES)
192192
set(phi_modules ${phi_modules} ${INFERENCE_DEPS} phi)
193193
set_property(GLOBAL PROPERTY PHI_MODULES "${phi_modules}")

paddle/scripts/paddle_build.sh

Lines changed: 11 additions & 9 deletions
Large diffs are not rendered by default.

python/env_dict.py.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env_dict={
1212
'FLUID_CORE_NAME':'@FLUID_CORE_NAME@',
1313
'PHI_LIB':'@PHI_LIB@',
1414
'PHI_NAME':'@PHI_NAME@',
15-
'WITH_PHI_SHARED':'@WITH_PHI_SHARED@',
15+
'WITH_SHARED_PHI':'@WITH_SHARED_PHI@',
1616
'WARPCTC_LIBRARIES':'@WARPCTC_LIBRARIES@',
1717
'WARPRNNT_LIBRARIES':'@WARPRNNT_LIBRARIES@',
1818
'FLASHATTN_LIBRARIES':'@FLASHATTN_LIBRARIES@',

python/setup.py.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ package_dir={
563563
libs_path='${PADDLE_BINARY_DIR}/python/paddle/libs'
564564

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

@@ -728,12 +728,12 @@ if '${CMAKE_BUILD_TYPE}' == 'Release':
728728
if "@APPLE@" == "1":
729729
commands = ["install_name_tool -id '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so']
730730
commands.append("install_name_tool -add_rpath '@loader_path/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so')
731-
if('${WITH_PHI_SHARED}' == 'ON'):
731+
if('${WITH_SHARED_PHI}' == 'ON'):
732732
# change rpath of phi.ext for loading 3rd party libb
733733
commands.append("install_name_tool -add_rpath '@loader_path' ${PADDLE_BINARY_DIR}/python/paddle/libs/${PHI_NAME}")
734734
else:
735735
commands = ["patchelf --set-rpath '$ORIGIN/../libs/' ${PADDLE_BINARY_DIR}/python/paddle/fluid/${FLUID_CORE_NAME}" + '.so']
736-
if('${WITH_PHI_SHARED}' == 'ON'):
736+
if('${WITH_SHARED_PHI}' == 'ON'):
737737
# change rpath of phi.ext for loading 3rd party lib
738738
commands.append("patchelf --set-rpath '$ORIGIN' ${PADDLE_BINARY_DIR}/python/paddle/libs/${PHI_NAME}")
739739
# The sw_64 not suppot patchelf, so we just disable that.

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ def get_package_data_and_package_dir():
967967
libs_path = paddle_binary_dir + '/python/paddle/libs'
968968
package_data['paddle.libs'] = []
969969

970-
if env_dict.get("WITH_PHI_SHARED") == "ON":
970+
if env_dict.get("WITH_SHARED_PHI") == "ON":
971971
package_data['paddle.libs'] = [
972972
('libphi' if os.name != 'nt' else 'phi') + ext_suffix
973973
]
@@ -1211,7 +1211,7 @@ def get_package_data_and_package_dir():
12111211
+ env_dict.get("FLUID_CORE_NAME")
12121212
+ '.so'
12131213
)
1214-
if env_dict.get("WITH_PHI_SHARED") == "ON":
1214+
if env_dict.get("WITH_SHARED_PHI") == "ON":
12151215
commands.append(
12161216
"install_name_tool -add_rpath '@loader_path' "
12171217
+ env_dict.get("PADDLE_BINARY_DIR")
@@ -1226,7 +1226,7 @@ def get_package_data_and_package_dir():
12261226
+ env_dict.get("FLUID_CORE_NAME")
12271227
+ '.so'
12281228
]
1229-
if env_dict.get("WITH_PHI_SHARED") == "ON":
1229+
if env_dict.get("WITH_SHARED_PHI") == "ON":
12301230
commands.append(
12311231
"patchelf --set-rpath '$ORIGIN' "
12321232
+ env_dict.get("PADDLE_BINARY_DIR")

0 commit comments

Comments
 (0)