Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-pick] Fix libpaddle soname mismatch error (#46344) #46576

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions paddle/fluid/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -572,25 +572,33 @@ if(WITH_PYTHON)
list(APPEND PYBIND_DEPS custom_operator_node)
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(
libpaddle SHARED
${SHARD_LIB_NAME} SHARED
SRCS ${PYBIND_SRCS}
DEPS ${PYBIND_DEPS} ${GLOB_OP_LIB} ${GLOB_OPERATOR_DEPS})

if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
add_dependencies(libpaddle legacy_eager_codegen)
add_dependencies(libpaddle eager_legacy_op_function_generator_cmd)
add_dependencies(${SHARD_LIB_NAME} legacy_eager_codegen)
add_dependencies(${SHARD_LIB_NAME} eager_legacy_op_function_generator_cmd)
endif()

if(NOT APPLE AND NOT WIN32)
target_link_libraries(libpaddle rt)
target_link_libraries(${SHARD_LIB_NAME} rt)
endif()

if(WITH_ROCM)
target_link_libraries(libpaddle ${ROCM_HIPRTC_LIB})
target_link_libraries(${SHARD_LIB_NAME} ${ROCM_HIPRTC_LIB})
endif()

get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
target_link_libraries(libpaddle ${os_dependency_modules})
add_dependencies(libpaddle op_function_generator_cmd)
target_link_libraries(${SHARD_LIB_NAME} ${os_dependency_modules})
add_dependencies(${SHARD_LIB_NAME} op_function_generator_cmd)
endif()
5 changes: 2 additions & 3 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ if(WIN32)
# Python would use the .pyd by default under Windows series platform
set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.pyd)
set(FLUID_CORE_LIB ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.lib)

add_custom_command(
OUTPUT ${FLUID_CORE}
COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE}
Expand All @@ -41,8 +40,8 @@ else()
set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so)
add_custom_command(
OUTPUT ${FLUID_CORE}
COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE}
DEPENDS libpaddle)
COMMAND cmake -E copy $<TARGET_FILE:paddle> ${FLUID_CORE}
DEPENDS paddle)
endif()

set(FLUID_CORE_DEPS ${FLUID_CORE})
Expand Down
20 changes: 11 additions & 9 deletions python/paddle/fluid/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
import warnings
import platform

core_suffix = 'so'
has_paddle_dy_lib = False

dy_lib_name = 'libpaddle'
dy_lib_suffix = 'so'
if os.name == 'nt':
core_suffix = 'pyd'
dy_lib_suffix = 'pyd'

has_libpaddle_so = False
current_path = os.path.abspath(os.path.dirname(__file__))
if os.path.exists(current_path + os.sep + 'libpaddle.' + core_suffix):
has_libpaddle_so = True
if os.path.exists(current_path + os.sep + dy_lib_name + '.' + dy_lib_suffix):
has_paddle_dy_lib = True

try:
if os.name == 'nt':
Expand Down Expand Up @@ -193,8 +195,8 @@ def load_dso(dso_absolute_path):


def pre_load(dso_name):
if has_libpaddle_so:
core_so = current_path + os.sep + 'libpaddle.' + core_suffix
if has_paddle_dy_lib:
core_so = current_path + os.sep + dy_lib_name + '.' + dy_lib_suffix
else:
core_so = None
dso_path = get_dso_path(core_so, dso_name)
Expand Down Expand Up @@ -290,10 +292,10 @@ def to_list(s):
from .libpaddle import _cleanup_mmap_fds
from .libpaddle import _remove_tensor_list_mmap_fds
except Exception as e:
if has_libpaddle_so:
if has_paddle_dy_lib:
sys.stderr.write(
'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():
sys.stderr.write(
"Error: Your machine doesn't support AVX, but the installed PaddlePaddle is avx core, "
Expand Down