From 9d801855afccf4a71fca42808eb7b21ade6c9c09 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 1 Nov 2022 21:48:04 +0800 Subject: [PATCH] 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 --- paddle/CMakeLists.txt | 10 +++++----- paddle/fluid/operators/collective/c_comm_init_op.cc | 2 -- python/CMakeLists.txt | 10 ++++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/paddle/CMakeLists.txt b/paddle/CMakeLists.txt index 895bd9db9c..80f4c6bb54 100644 --- a/paddle/CMakeLists.txt +++ b/paddle/CMakeLists.txt @@ -49,18 +49,15 @@ endif() list(LENGTH test_names len) if(${len} GREATER_EQUAL 1) - message("Total tests: ${len}") + message("Total cpp tests using dynamic link: ${len}") math(EXPR stop "${len} - 1") foreach(idx RANGE ${stop}) if(WITH_TESTING) list(GET test_srcs ${idx} test_src) list(GET test_names ${idx} test_name) 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}) - # target_link_libraries( - # ${test_name} - # ${CMAKE_BINARY_DIR}/paddle/fluid/pybind/libpaddle${POSTFIX}) target_link_libraries(${test_name} $) target_link_libraries(${test_name} paddle_gtest_main_new) add_dependencies(${test_name} ${paddle_lib} paddle_gtest_main_new) @@ -75,6 +72,9 @@ if(${len} GREATER_EQUAL 1) target_link_libraries(${test_name} "-Wl,-rpath,$") endif() + if(WITH_XPU) + target_link_libraries(${test_name} xpulib) + endif() if(NOT ("${test_name}" STREQUAL "c_broadcast_op_npu_test" OR "${test_name}" STREQUAL "c_allreduce_sum_op_npu_test" diff --git a/paddle/fluid/operators/collective/c_comm_init_op.cc b/paddle/fluid/operators/collective/c_comm_init_op.cc index 59fbd02b5c..26e700262f 100644 --- a/paddle/fluid/operators/collective/c_comm_init_op.cc +++ b/paddle/fluid/operators/collective/c_comm_init_op.cc @@ -57,11 +57,9 @@ class CCommInitOp : public framework::OperatorBase { using CommContext = platform::NCCLCommContext; #elif defined(PADDLE_WITH_XPU_BKCL) using UniqueId = BKCLUniqueId; - using Place = platform::XPUPlace; using CommContext = platform::BKCLCommContext; #elif defined(PADDLE_WITH_CNCL) using UniqueId = cnclCliqueId; - using Place = platform::MLUPlace; using CommContext = platform::CNCLCommContext; #else PADDLE_THROW(platform::errors::PreconditionNotMet( diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index b7d8eb1dcb..3a3c98a9e9 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -48,6 +48,16 @@ set(FLUID_CORE_DEPS ${FLUID_CORE}) 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) add_custom_command( OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp -- GitLab