From 45125ba538f7f647cff99aed34d9e18b4d7584f5 Mon Sep 17 00:00:00 2001 From: peizhilin Date: Thu, 8 Nov 2018 18:02:44 +0800 Subject: [PATCH] fix share library issue --- CMakeLists.txt | 2 +- cmake/generic.cmake | 17 ++++++----------- paddle/fluid/inference/CMakeLists.txt | 1 + paddle/fluid/inference/api/api_impl.cc | 4 ---- paddle/fluid/platform/device_context.h | 2 +- paddle/fluid/platform/init.cc | 8 ++++++++ 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eabacbf7cc..cd8c54e24e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,7 @@ option(WITH_INFERENCE_API_TEST "Test fluid inference high-level api interface" option(WITH_SYSTEM_BLAS "Use system blas library" OFF) option(PY_VERSION "Compile PaddlePaddle with python3 support" ${PY_VERSION}) option(WITH_FAST_MATH "Make use of fast math library, might affect the precision to some extent" ON) -option(WITH_PREBUILD_OPENBLAS "Make use of the pre-built openblas library" ON) +option(WITH_PREBUILD_OPENBLAS "Make use of the pre-built openblas library" ${WIN32}) # PY_VERSION if(NOT PY_VERSION) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 174e5b2d17..e21f89c7c5 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -304,12 +304,6 @@ function(sep_library TARGET_NAME) set(options STATIC static SHARED shared) set(oneValueArgs "") set(multiValueArgs SRCS DEPS) - set(${TARGET_NAME}_dummy_flag "") - if(${sep_library_STATIC}) - set(${TARGET_NAME}_dummy_flag "STATIC") - elseif(${sep_library_SHARED}) - set(${TARGET_NAME}_dummy_flag "SHARED") - endif() cmake_parse_arguments(sep_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(dummy_index 1) set(dummy_offset 1) @@ -321,10 +315,7 @@ function(sep_library TARGET_NAME) list(LENGTH dummy_list listlen ) if ((${listlen} GREATER ${dummy_limit}) OR (${dummy_offset} EQUAL ${sep_all_len})) message("create dummy library ${TARGET_NAME}_dummy_lib_${dummy_index} for ${TARGET_NAME}") - # set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_dummy_${dummy_index}.c) - # file(WRITE ${dummyfile} "const char *dummy_${TARGET_NAME}_${dummy_index} = \"${dummyfile}\";") - # cc_library(${TARGET_NAME}_dummy_lib_${dummy_index} ${${TARGET_NAME}_dummy_flag} SRCS ${dummyfile} DEPS ${dummy_list}) - cc_library(${TARGET_NAME}_dummy_lib_${dummy_index} ${${TARGET_NAME}_dummy_flag} DEPS ${dummy_list}) + cc_library(${TARGET_NAME}_dummy_lib_${dummy_index} STATIC DEPS ${dummy_list}) foreach(i ${dummy_list}) list(REMOVE_AT dummy_list 0) endforeach() @@ -333,7 +324,11 @@ function(sep_library TARGET_NAME) endif() MATH(EXPR dummy_offset "${dummy_offset}+1") endforeach() - cc_library(${TARGET_NAME} ${${TARGET_NAME}_dummy_flag} SRCS ${sep_library_SRCS} DEPS ${${TARGET_NAME}_dummy_list}) + if(${sep_library_SHARED}) + cc_library(${TARGET_NAME} SHARED SRCS ${sep_library_SRCS} DEPS ${${TARGET_NAME}_dummy_list}) + else(${sep_library_SHARED}) + cc_library(${TARGET_NAME} STATIC SRCS ${sep_library_SRCS} DEPS ${${TARGET_NAME}_dummy_list}) + endif(${sep_library_SHARED}) endfunction(sep_library) function(cc_binary TARGET_NAME) diff --git a/paddle/fluid/inference/CMakeLists.txt b/paddle/fluid/inference/CMakeLists.txt index da1711fc18..f09a434950 100644 --- a/paddle/fluid/inference/CMakeLists.txt +++ b/paddle/fluid/inference/CMakeLists.txt @@ -60,6 +60,7 @@ endif() if(WIN32) sep_library(paddle_fluid_shared SHARED SRCS ${SHARED_INFERENCE_SRCS} DEPS ${fluid_modules} paddle_fluid_api reset_tensor_array) + target_link_libraries(paddle_fluid_shared shlwapi) if(WITH_GPU AND NOT WITH_DSO) target_link_libraries(paddle_fluid_origin ${cuda_modules}) endif(WITH_GPU AND NOT WITH_DSO) diff --git a/paddle/fluid/inference/api/api_impl.cc b/paddle/fluid/inference/api/api_impl.cc index a576ab13df..d06ab8f8c8 100644 --- a/paddle/fluid/inference/api/api_impl.cc +++ b/paddle/fluid/inference/api/api_impl.cc @@ -75,10 +75,6 @@ bool NativePaddlePredictor::Init( } #endif - // windows has no support for openblas multi-thread -#ifdef _WIN32 - FLAGS_paddle_num_threads = 1; -#endif // no matter with or without MKLDNN paddle::platform::SetNumThreads(FLAGS_paddle_num_threads); diff --git a/paddle/fluid/platform/device_context.h b/paddle/fluid/platform/device_context.h index df248f9bb1..892984dc3e 100644 --- a/paddle/fluid/platform/device_context.h +++ b/paddle/fluid/platform/device_context.h @@ -32,7 +32,7 @@ limitations under the License. */ #include "glog/logging.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/place.h" -#ifdef PADDLE_WITH_CUDA +#ifdef PADDLE_WITH_CUDA && !defined(_WIN32) #include "paddle/fluid/platform/stream_callback_manager.h" #endif #include "unsupported/Eigen/CXX11/Tensor" diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index f61abfc43d..092585ed2a 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -112,6 +112,14 @@ void InitDevices(bool init_p2p, const std::vector devices) { } places.emplace_back(platform::CPUPlace()); platform::DeviceContextPool::Init(places); + +// windows has no support for openblas multi-thread +#ifdef _WIN32 + if (FLAGS_paddle_num_threads > 1) { + FLAGS_paddle_num_threads = 1; + } +#endif + #ifndef PADDLE_WITH_MKLDNN platform::SetNumThreads(FLAGS_paddle_num_threads); #endif -- GitLab