未验证 提交 1c22ed7f 编写于 作者: C Chen Weihang 提交者: GitHub

Fix libpaddle soname mismatch error (#46344) (#46576)

* fix libpaddle soname mismatch error

* fix windows failed

* polish linux and windows make impl

* unify winddows lib name

* fix windows error

* revert copy dst change

* revert naming change

* revert windows change

* fix gpups compile failed
上级 b2e4211d
...@@ -572,25 +572,33 @@ if(WITH_PYTHON) ...@@ -572,25 +572,33 @@ if(WITH_PYTHON)
list(APPEND PYBIND_DEPS custom_operator_node) list(APPEND PYBIND_DEPS custom_operator_node)
endif() endif()
# On Linux, cc_library(paddle SHARED ..) will generate the libpaddle.so,
# add a prefix `lib` by default, but on Windows, cc_library(paddle SHARED ..)
# will not add prefix, so it generate paddle.lib and paddle.pyd,
# we need to pay attention to the difference
set(SHARD_LIB_NAME paddle)
if(WIN32)
set(SHARD_LIB_NAME libpaddle)
endif()
cc_library( cc_library(
libpaddle SHARED ${SHARD_LIB_NAME} SHARED
SRCS ${PYBIND_SRCS} SRCS ${PYBIND_SRCS}
DEPS ${PYBIND_DEPS} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS}) DEPS ${PYBIND_DEPS} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})
if(NOT ((NOT WITH_PYTHON) AND ON_INFER)) if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
add_dependencies(libpaddle legacy_eager_codegen) add_dependencies(${SHARD_LIB_NAME} legacy_eager_codegen)
add_dependencies(libpaddle eager_legacy_op_function_generator_cmd) add_dependencies(${SHARD_LIB_NAME} eager_legacy_op_function_generator_cmd)
endif() endif()
if(NOT APPLE AND NOT WIN32) if(NOT APPLE AND NOT WIN32)
target_link_libraries(libpaddle rt) target_link_libraries(${SHARD_LIB_NAME} rt)
endif() endif()
if(WITH_ROCM) if(WITH_ROCM)
target_link_libraries(libpaddle ${ROCM_HIPRTC_LIB}) target_link_libraries(${SHARD_LIB_NAME} ${ROCM_HIPRTC_LIB})
endif() endif()
get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES) get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
target_link_libraries(libpaddle ${os_dependency_modules}) target_link_libraries(${SHARD_LIB_NAME} ${os_dependency_modules})
add_dependencies(libpaddle op_function_generator_cmd) add_dependencies(${SHARD_LIB_NAME} op_function_generator_cmd)
endif() endif()
...@@ -31,7 +31,6 @@ if(WIN32) ...@@ -31,7 +31,6 @@ if(WIN32)
# Python would use the .pyd by default under Windows series platform # Python would use the .pyd by default under Windows series platform
set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.pyd) set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.pyd)
set(FLUID_CORE_LIB ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.lib) set(FLUID_CORE_LIB ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.lib)
add_custom_command( add_custom_command(
OUTPUT ${FLUID_CORE} OUTPUT ${FLUID_CORE}
COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE} COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE}
...@@ -41,8 +40,8 @@ else() ...@@ -41,8 +40,8 @@ else()
set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so) set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so)
add_custom_command( add_custom_command(
OUTPUT ${FLUID_CORE} OUTPUT ${FLUID_CORE}
COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE} COMMAND cmake -E copy $<TARGET_FILE:paddle> ${FLUID_CORE}
DEPENDS libpaddle) DEPENDS paddle)
endif() endif()
set(FLUID_CORE_DEPS ${FLUID_CORE}) set(FLUID_CORE_DEPS ${FLUID_CORE})
......
...@@ -20,14 +20,16 @@ import os ...@@ -20,14 +20,16 @@ import os
import warnings import warnings
import platform import platform
core_suffix = 'so' has_paddle_dy_lib = False
dy_lib_name = 'libpaddle'
dy_lib_suffix = 'so'
if os.name == 'nt': if os.name == 'nt':
core_suffix = 'pyd' dy_lib_suffix = 'pyd'
has_libpaddle_so = False
current_path = os.path.abspath(os.path.dirname(__file__)) current_path = os.path.abspath(os.path.dirname(__file__))
if os.path.exists(current_path + os.sep + 'libpaddle.' + core_suffix): if os.path.exists(current_path + os.sep + dy_lib_name + '.' + dy_lib_suffix):
has_libpaddle_so = True has_paddle_dy_lib = True
try: try:
if os.name == 'nt': if os.name == 'nt':
...@@ -193,8 +195,8 @@ def load_dso(dso_absolute_path): ...@@ -193,8 +195,8 @@ def load_dso(dso_absolute_path):
def pre_load(dso_name): def pre_load(dso_name):
if has_libpaddle_so: if has_paddle_dy_lib:
core_so = current_path + os.sep + 'libpaddle.' + core_suffix core_so = current_path + os.sep + dy_lib_name + '.' + dy_lib_suffix
else: else:
core_so = None core_so = None
dso_path = get_dso_path(core_so, dso_name) dso_path = get_dso_path(core_so, dso_name)
...@@ -290,10 +292,10 @@ try: ...@@ -290,10 +292,10 @@ try:
from .libpaddle import _cleanup_mmap_fds from .libpaddle import _cleanup_mmap_fds
from .libpaddle import _remove_tensor_list_mmap_fds from .libpaddle import _remove_tensor_list_mmap_fds
except Exception as e: except Exception as e:
if has_libpaddle_so: if has_paddle_dy_lib:
sys.stderr.write( sys.stderr.write(
'Error: Can not import paddle core while this file exists: ' + 'Error: Can not import paddle core while this file exists: ' +
current_path + os.sep + 'libpaddle.' + core_suffix + '\n') current_path + os.sep + 'libpaddle.' + dy_lib_suffix + '\n')
if not avx_supported() and libpaddle.is_compiled_with_avx(): if not avx_supported() and libpaddle.is_compiled_with_avx():
sys.stderr.write( sys.stderr.write(
"Error: Your machine doesn't support AVX, but the installed PaddlePaddle is avx core, " "Error: Your machine doesn't support AVX, but the installed PaddlePaddle is avx core, "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册