未验证 提交 9d801855 编写于 作者: L Leo Chen 提交者: GitHub

fix dynamic link of xpu library (#47434)

* refine comments,test=kunlun

* link xpu lib, test=kunlun

* add sleep for test, test=kunlun

* merge develop, fix compile, test=kunlun

* remove debug code, test=kunlun

* add dependency to avoid potential concurrency error, test=kunlun
上级 f9134045
...@@ -49,18 +49,15 @@ endif() ...@@ -49,18 +49,15 @@ endif()
list(LENGTH test_names len) list(LENGTH test_names len)
if(${len} GREATER_EQUAL 1) if(${len} GREATER_EQUAL 1)
message("Total tests: ${len}") message("Total cpp tests using dynamic link: ${len}")
math(EXPR stop "${len} - 1") math(EXPR stop "${len} - 1")
foreach(idx RANGE ${stop}) foreach(idx RANGE ${stop})
if(WITH_TESTING) if(WITH_TESTING)
list(GET test_srcs ${idx} test_src) list(GET test_srcs ${idx} test_src)
list(GET test_names ${idx} test_name) list(GET test_names ${idx} test_name)
get_property(test_arg GLOBAL PROPERTY "${test_name}_ARGS") get_property(test_arg GLOBAL PROPERTY "${test_name}_ARGS")
message("add test ${test_name}") # message("add test ${test_name}")
add_executable(${test_name} ${test_src}) add_executable(${test_name} ${test_src})
# target_link_libraries(
# ${test_name}
# ${CMAKE_BINARY_DIR}/paddle/fluid/pybind/libpaddle${POSTFIX})
target_link_libraries(${test_name} $<TARGET_LINKER_FILE:${paddle_lib}>) target_link_libraries(${test_name} $<TARGET_LINKER_FILE:${paddle_lib}>)
target_link_libraries(${test_name} paddle_gtest_main_new) target_link_libraries(${test_name} paddle_gtest_main_new)
add_dependencies(${test_name} ${paddle_lib} paddle_gtest_main_new) add_dependencies(${test_name} ${paddle_lib} paddle_gtest_main_new)
...@@ -75,6 +72,9 @@ if(${len} GREATER_EQUAL 1) ...@@ -75,6 +72,9 @@ if(${len} GREATER_EQUAL 1)
target_link_libraries(${test_name} target_link_libraries(${test_name}
"-Wl,-rpath,$<TARGET_FILE_DIR:${paddle_lib}>") "-Wl,-rpath,$<TARGET_FILE_DIR:${paddle_lib}>")
endif() endif()
if(WITH_XPU)
target_link_libraries(${test_name} xpulib)
endif()
if(NOT if(NOT
("${test_name}" STREQUAL "c_broadcast_op_npu_test" ("${test_name}" STREQUAL "c_broadcast_op_npu_test"
OR "${test_name}" STREQUAL "c_allreduce_sum_op_npu_test" OR "${test_name}" STREQUAL "c_allreduce_sum_op_npu_test"
......
...@@ -57,11 +57,9 @@ class CCommInitOp : public framework::OperatorBase { ...@@ -57,11 +57,9 @@ class CCommInitOp : public framework::OperatorBase {
using CommContext = platform::NCCLCommContext; using CommContext = platform::NCCLCommContext;
#elif defined(PADDLE_WITH_XPU_BKCL) #elif defined(PADDLE_WITH_XPU_BKCL)
using UniqueId = BKCLUniqueId; using UniqueId = BKCLUniqueId;
using Place = platform::XPUPlace;
using CommContext = platform::BKCLCommContext; using CommContext = platform::BKCLCommContext;
#elif defined(PADDLE_WITH_CNCL) #elif defined(PADDLE_WITH_CNCL)
using UniqueId = cnclCliqueId; using UniqueId = cnclCliqueId;
using Place = platform::MLUPlace;
using CommContext = platform::CNCLCommContext; using CommContext = platform::CNCLCommContext;
#else #else
PADDLE_THROW(platform::errors::PreconditionNotMet( PADDLE_THROW(platform::errors::PreconditionNotMet(
......
...@@ -48,6 +48,16 @@ set(FLUID_CORE_DEPS ${FLUID_CORE}) ...@@ -48,6 +48,16 @@ set(FLUID_CORE_DEPS ${FLUID_CORE})
add_custom_target(copy_libpaddle ALL DEPENDS ${FLUID_CORE_DEPS}) add_custom_target(copy_libpaddle ALL DEPENDS ${FLUID_CORE_DEPS})
# NOTE(zhiqiu): WHY?
# In `setup.py.in`, some dynamic libraries (eg, libxpuapi.so) are modified using
# patchelf. In rare cases, if the a linker is linking that dynamic library for
# some executables at the same time, a `file not recognized, file truncated`
# error may occur, result in the compilation error.
# So, add dependency to force the cpp tests built before running `setup.py.in`.
if(WITH_TESTING)
add_dependencies(copy_libpaddle build_tests)
endif()
if(WIN32) if(WIN32)
add_custom_command( add_custom_command(
OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册