From 041ea14cf711b441f6a49d3fb5edf2c7f9031714 Mon Sep 17 00:00:00 2001 From: Yuanle Liu Date: Fri, 24 Feb 2023 14:41:27 +0800 Subject: [PATCH] Fix libpaddle_inference.so symbol conflicts with other .so (gflags) (#50787) --- paddle/fluid/inference/CMakeLists.txt | 10 +-- .../inference/api/details/zero_copy_tensor.cc | 40 ++++----- paddle/fluid/inference/paddle_inference.map | 1 + .../paddle_inference_custom_device.map | 81 ------------------- paddle/phi/core/enforce.cc | 5 +- paddle/phi/core/enforce.h | 11 ++- 6 files changed, 32 insertions(+), 116 deletions(-) delete mode 100644 paddle/fluid/inference/paddle_inference_custom_device.map diff --git a/paddle/fluid/inference/CMakeLists.txt b/paddle/fluid/inference/CMakeLists.txt index b8f60d25213..de23d3e477e 100644 --- a/paddle/fluid/inference/CMakeLists.txt +++ b/paddle/fluid/inference/CMakeLists.txt @@ -154,14 +154,8 @@ set_target_properties(paddle_inference_shared PROPERTIES OUTPUT_NAME paddle_inference) if(NOT APPLE AND NOT WIN32) # TODO(liuyiqun): Temporarily disable the link flag because it is not support on Mac. - if(WITH_CUSTOM_DEVICE) - set(LINK_FLAGS - "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/paddle_inference_custom_device.map" - ) - else() - set(LINK_FLAGS - "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/paddle_inference.map") - endif() + set(LINK_FLAGS + "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/paddle_inference.map") set_target_properties(paddle_inference_shared PROPERTIES LINK_FLAGS "${LINK_FLAGS}") # check symbol hidden diff --git a/paddle/fluid/inference/api/details/zero_copy_tensor.cc b/paddle/fluid/inference/api/details/zero_copy_tensor.cc index 59b44769ddd..80bde735363 100644 --- a/paddle/fluid/inference/api/details/zero_copy_tensor.cc +++ b/paddle/fluid/inference/api/details/zero_copy_tensor.cc @@ -378,17 +378,16 @@ void Tensor::CopyToCpuImpl(T *data, auto *t_data = tensor->data(); auto t_place = tensor->place(); - phi::DenseTensor out; - auto mem_allocation = - std::make_shared( - static_cast(data), - ele_num * sizeof(T), - paddle::platform::CPUPlace()); - out.ResetHolder(mem_allocation); - if (paddle::platform::is_cpu_place(t_place)) { #ifdef PADDLE_WITH_MKLDNN - if (tensor->layout() == phi::DataLayout::ONEDNN) + if (tensor->layout() == phi::DataLayout::ONEDNN) { + phi::DenseTensor out; + auto mem_allocation = + std::make_shared( + static_cast(data), + ele_num * sizeof(T), + paddle::platform::CPUPlace()); + out.ResetHolder(mem_allocation); phi::funcs::TransDataLayoutFromOneDNN( tensor->layout(), phi::OneDNNContext::tls().get_cur_paddle_data_layout(), @@ -396,8 +395,9 @@ void Tensor::CopyToCpuImpl(T *data, &out, paddle::platform::CPUPlace(), true); - else + } else { std::memcpy(static_cast(data), t_data, ele_num * sizeof(T)); + } #else std::memcpy(static_cast(data), t_data, ele_num * sizeof(T)); #endif @@ -871,17 +871,16 @@ void InternalUtils::CopyToCpuWithIoStream(paddle_infer::Tensor *t, auto *t_data = tensor->data(); auto t_place = tensor->place(); - phi::DenseTensor out; - auto mem_allocation = - std::make_shared( - static_cast(data), - ele_num * sizeof(T), - paddle::platform::CPUPlace()); - out.ResetHolder(mem_allocation); - if (paddle::platform::is_cpu_place(t_place)) { #ifdef PADDLE_WITH_MKLDNN - if (tensor->layout() == phi::DataLayout::ONEDNN) + if (tensor->layout() == phi::DataLayout::ONEDNN) { + phi::DenseTensor out; + auto mem_allocation = + std::make_shared( + static_cast(data), + ele_num * sizeof(T), + paddle::platform::CPUPlace()); + out.ResetHolder(mem_allocation); phi::funcs::TransDataLayoutFromOneDNN( tensor->layout(), phi::OneDNNContext::tls().get_cur_paddle_data_layout(), @@ -889,8 +888,9 @@ void InternalUtils::CopyToCpuWithIoStream(paddle_infer::Tensor *t, &out, paddle::platform::CPUPlace(), true); - else + } else { std::memcpy(static_cast(data), t_data, ele_num * sizeof(T)); + } #else std::memcpy(static_cast(data), t_data, ele_num * sizeof(T)); #endif diff --git a/paddle/fluid/inference/paddle_inference.map b/paddle/fluid/inference/paddle_inference.map index b29235b5d3e..a928401490b 100644 --- a/paddle/fluid/inference/paddle_inference.map +++ b/paddle/fluid/inference/paddle_inference.map @@ -73,6 +73,7 @@ *Pass*; *profile*; *phi*; + PD_*; *cinn*; local: *; diff --git a/paddle/fluid/inference/paddle_inference_custom_device.map b/paddle/fluid/inference/paddle_inference_custom_device.map deleted file mode 100644 index 06fdeaac838..00000000000 --- a/paddle/fluid/inference/paddle_inference_custom_device.map +++ /dev/null @@ -1,81 +0,0 @@ -{ - global: - extern "C++" { - *paddle_infer::GetVersion*; - *paddle_infer::UpdateDllFlag*; - *paddle_infer::experimental::InternalUtils*; - *paddle_infer::Tensor*; - *paddle_infer::Predictor*; - *paddle_infer::CreatePredictor*; - *paddle_infer::GetTrtCompileVersion*; - *paddle_infer::GetTrtRuntimeVersion*; - *paddle_infer::GetNumBytesOfDataType*; - *paddle_infer::ConvertToMixedPrecision*; - *paddle_infer::contrib::TensorUtils*; - *paddle_infer::contrib::Status*; - *paddle_infer::services::PredictorPool*; - *paddle_infer::LayoutConvert*; - - *paddle::experimental*; - *paddle::internal*; - *paddle::get_version*; - *paddle::LiteNNAdapterConfig*; - *paddle::AnalysisConfig::*; - *paddle::PaddlePredictor::*; - *paddle::CreatePaddlePredictor*; - *paddle::NativePaddlePredictor*; - *paddle::AnalysisPredictor*; - *paddle::PaddleDtypeSize*; - *paddle::ZeroCopyTensor*; - *paddle::*Strategy*; - *paddle::NativeConfig*; - *paddle::PaddleBuf*; - *paddle::PaddleTensor*; - *paddle::UpdateDllFlag*; - *paddle::MakeCipher*; - *paddle::DistConfig*; - *paddle::DefaultGPUPlace*; - *paddle::ResourceManager*; - *paddle::GPUContextResource*; - *paddle::CPUContextResource*; - *paddle::OpMetaInfoBuilder*; - *paddle::CustomOpKernelContext*; - - /* ut needs the following symbol, we need to modify all the ut to hidden such symbols */ - - /* Another question: the ut size will grow from 50M to 80M, why? */ - - *paddle::detail*; - *paddle::imperative*; - *paddle::detailv3*; - *paddle::memory*; - *paddle::string*; - *paddle::operators*; - - *paddle::distributed*; - /* *paddle::distributed::FleetWrapper*; */ - /* *paddle::distributed::TensorTable*; */ - /* *paddle::distributed::TableManager*; */ - - /* *paddle::inference*; */ - *paddle::inference::ReadBinaryFile*; - - *paddle::platform*; - /* *paddle::platform::GetExportedFlagInfoMap*; */ - - /* *paddle::framework*; */ - *paddle::framework::InterpreterCore*; - *paddle::framework::Executor*; - *paddle::framework::proto*; - }; - - /* The following symbols need to reconsider. */ - *Pass*; - *profile*; - *phi*; - *FLAGS_*; - PD_*; - *cinn*; - local: - *; -}; diff --git a/paddle/phi/core/enforce.cc b/paddle/phi/core/enforce.cc index 7d4efead494..dc309a3185c 100644 --- a/paddle/phi/core/enforce.cc +++ b/paddle/phi/core/enforce.cc @@ -20,7 +20,8 @@ limitations under the License. */ #include #include "paddle/utils/blank.h" -#include "paddle/utils/variant.h" + +DECLARE_int32(call_stack_level); namespace egr { class EagerVariable; @@ -88,6 +89,8 @@ using NameTensorMap = NameVarMap; namespace phi { namespace enforce { +int GetCallStackLevel() { return FLAGS_call_stack_level; } + template static std::string ReplaceComplexTypeStr(std::string str, const std::string& type_name) { diff --git a/paddle/phi/core/enforce.h b/paddle/phi/core/enforce.h index e0dd918cef4..31147356a54 100644 --- a/paddle/phi/core/enforce.h +++ b/paddle/phi/core/enforce.h @@ -101,8 +101,6 @@ limitations under the License. */ #include "paddle/utils/variant.h" -DECLARE_int32(call_stack_level); - namespace phi { class ErrorSummary; } // namespace phi @@ -235,6 +233,7 @@ struct BinaryCompareMessageConverter { }; } // namespace details +int GetCallStackLevel(); std::string GetCurrentTraceBackString(bool for_signal = false); std::string SimplifyErrorTypeFormat(const std::string& str); @@ -243,7 +242,7 @@ static std::string GetErrorSumaryString(StrType&& what, const char* file, int line) { std::ostringstream sout; - if (FLAGS_call_stack_level > 1) { + if (GetCallStackLevel() > 1) { sout << "\n----------------------\nError Message " "Summary:\n----------------------\n"; } @@ -270,7 +269,7 @@ template static std::string GetTraceBackString(StrType&& what, const char* file, int line) { - if (FLAGS_call_stack_level > 1) { + if (GetCallStackLevel() > 1) { // FLAGS_call_stack_level>1 means showing c++ call stack return GetCurrentTraceBackString() + GetErrorSumaryString(what, file, line); } else { @@ -317,7 +316,7 @@ struct EnforceNotMet : public std::exception { } const char* what() const noexcept override { - if (FLAGS_call_stack_level > 1) { + if (GetCallStackLevel() > 1) { return err_str_.c_str(); } else { return simple_err_str_.c_str(); @@ -331,7 +330,7 @@ struct EnforceNotMet : public std::exception { const std::string& simple_error_str() const { return simple_err_str_; } void set_error_str(std::string str) { - if (FLAGS_call_stack_level > 1) { + if (GetCallStackLevel() > 1) { err_str_ = str; } else { simple_err_str_ = str; -- GitLab