From 3ae96450846b87c58924e44360ac7ac4ebac47ba Mon Sep 17 00:00:00 2001 From: wanghaoshuang Date: Sun, 14 Oct 2018 23:08:44 +0800 Subject: [PATCH] compile in linux --- cmake/cuda.cmake | 5 ++++- cmake/external/warpctc.cmake | 7 ++++--- cmake/flags.cmake | 10 +++++++--- cmake/generic.cmake | 1 - paddle/fluid/framework/CMakeLists.txt | 4 ++-- paddle/fluid/framework/ir/node.cc | 2 +- paddle/fluid/framework/ir/node.h | 2 +- paddle/fluid/inference/CMakeLists.txt | 2 ++ paddle/fluid/operators/elementwise_op_function.h | 4 ++-- paddle/fluid/platform/port.h | 1 + 10 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cmake/cuda.cmake b/cmake/cuda.cmake index ec14615244d..5e6522dd7d1 100644 --- a/cmake/cuda.cmake +++ b/cmake/cuda.cmake @@ -172,6 +172,9 @@ set(CUDA_PROPAGATE_HOST_FLAGS OFF) if (NOT WIN32) # windows msvc2015 support c++11 natively. # -std=c++11 -fPIC not recoginize by msvc +list(APPEND CUDA_NVCC_FLAGS "-std=c++11") +list(APPEND CUDA_NVCC_FLAGS "-w" "-Xcompiler -fPIC") +else(NOT WIN32) list(APPEND CUDA_NVCC_FLAGS "-w" "-Xcompiler -fPIC" "-Xcompiler /w") endif(NOT WIN32) @@ -201,4 +204,4 @@ endif() endif(NOT WIN32) mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_VERBOSE_BUILD) -mark_as_advanced(CUDA_SDK_ROOT_DIR CUDA_SEPARABLE_COMPILATION) \ No newline at end of file +mark_as_advanced(CUDA_SDK_ROOT_DIR CUDA_SEPARABLE_COMPILATION) diff --git a/cmake/external/warpctc.cmake b/cmake/external/warpctc.cmake index 07e1137e16a..63dbee9c400 100644 --- a/cmake/external/warpctc.cmake +++ b/cmake/external/warpctc.cmake @@ -34,7 +34,9 @@ IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "App ELSE() SET(USE_OMP ON) ENDIF() - +message("warpctc") +message(${CMAKE_CXX_COMPILER}) +message(${CMAKE_CXX_FLAGS}) ExternalProject_Add( extern_warpctc ${EXTERNAL_PROJECT_LOG_ARGS} @@ -43,8 +45,7 @@ ExternalProject_Add( UPDATE_COMMAND "" CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} + -DCMAKE_CXX_FLAGS="" -DCMAKE_INSTALL_PREFIX=${WARPCTC_INSTALL_DIR} -DWITH_GPU=${WITH_GPU} -DWITH_OMP=${USE_OMP} diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 30757c95977..5ffa549aa1c 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -26,6 +26,7 @@ function(CheckCompilerCXX11Flag) endfunction() CheckCompilerCXX11Flag() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # safe_set_flag # @@ -116,10 +117,8 @@ if (NOT WIN32) set(COMMON_FLAGS -fPIC -fno-omit-frame-pointer - -Werror -Wall -Wextra - -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wno-unused-parameter -Wno-unused-function @@ -144,6 +143,12 @@ set(GPU_COMMON_FLAGS -Wno-error=unused-function # Warnings in Numpy Header. -Wno-error=array-bounds # Warnings in Eigen::array ) +set(COMMON_FLAGS + -fPIC + -fno-omit-frame-pointer) +set(GPU_COMMON_FLAGS + -fPIC + -fno-omit-frame-pointer) else(NOT WIN32) set(COMMON_FLAGS @@ -165,7 +170,6 @@ if(LINUX) set(GPU_COMMON_FLAGS -Wall -Wextra - -Werror ${GPU_COMMON_FLAGS}) endif(LINUX) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 0bb01a61b91..3464464281b 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -243,7 +243,6 @@ function(cc_library TARGET_NAME) # add libxxx.lib prefix in windows set(${TARGET_NAME}_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${TARGET_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE STRING "output library name for target ${TARGET_NAME}") endif(WIN32) - message("flags" ${CMAKE_CXX_FLAGS}) if(cc_library_SRCS) if(cc_library_SHARED OR cc_library_shared) # build *.so add_library(${TARGET_NAME} SHARED ${cc_library_SRCS}) diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index 1e36114c670..59e4d814027 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -48,7 +48,7 @@ if(WITH_GPU) nv_library(tensor SRCS tensor.cc .tensor_util.cu DEPS place memory data_type device_context) add_dependencies(tensor tensor_util) else() - nv_library(tensor SRCS tensor.cc tensor_util.cu DEPS place memory data_type device_context) + nv_library(tensor SRCS tensor.cc tensor_util.cc DEPS place memory data_type device_context) endif(WIN32) else() cc_library(tensor SRCS tensor.cc tensor_util.cc DEPS place memory data_type device_context) @@ -100,7 +100,7 @@ if(WITH_GPU) nv_library(data_type_transform SRCS .data_type_transform.cu DEPS tensor) add_dependencies(data_type_transform hidden_file) else() - nv_library(data_type_transform SRCS data_type_transform.cu DEPS tensor) + nv_library(data_type_transform SRCS data_type_transform.cc DEPS tensor) endif(WIN32) nv_test(data_type_transform_test SRCS data_type_transform_test.cc data_type_transform_test.cu DEPS data_type_transform) else() diff --git a/paddle/fluid/framework/ir/node.cc b/paddle/fluid/framework/ir/node.cc index cc7fd23be79..03ed6da1046 100644 --- a/paddle/fluid/framework/ir/node.cc +++ b/paddle/fluid/framework/ir/node.cc @@ -18,7 +18,7 @@ namespace paddle { namespace framework { namespace ir { -char Node::kControlDepVarName[]; +constexpr char Node::kControlDepVarName[]; int Node::count_ = 0; } // namespace ir } // namespace framework diff --git a/paddle/fluid/framework/ir/node.h b/paddle/fluid/framework/ir/node.h index e053478f898..d53d789d3ad 100644 --- a/paddle/fluid/framework/ir/node.h +++ b/paddle/fluid/framework/ir/node.h @@ -27,7 +27,7 @@ namespace ir { class Node { public: enum class Type { kOperation, kVariable }; - static char kControlDepVarName[]; + static constexpr char kControlDepVarName[] = "__control_var"; explicit Node(const std::string& name, Type type) : name_(name), diff --git a/paddle/fluid/inference/CMakeLists.txt b/paddle/fluid/inference/CMakeLists.txt index f275af55095..45a36982c69 100644 --- a/paddle/fluid/inference/CMakeLists.txt +++ b/paddle/fluid/inference/CMakeLists.txt @@ -28,6 +28,8 @@ cc_library(paddle_fluid_origin DEPS ${fluid_modules} paddle_fluid_api) # Create static library if (WIN32) cc_library(paddle_fluid DEPS ${fluid_modules} ${fluid_third_partys} paddle_fluid_api paddle_inference_api) +else(WIND32) +cc_library(paddle_fluid DEPS ${fluid_modules} paddle_fluid_api paddle_inference_api) endif(WIN32) if(NOT APPLE) # TODO(liuyiqu: Temporarily disable the link flag because it is not support on Mac. diff --git a/paddle/fluid/operators/elementwise_op_function.h b/paddle/fluid/operators/elementwise_op_function.h index 57bb20dfd37..b089ae81027 100644 --- a/paddle/fluid/operators/elementwise_op_function.h +++ b/paddle/fluid/operators/elementwise_op_function.h @@ -97,8 +97,8 @@ class MidWiseTransformIterator; // NOTE(dzhwinter): ptrdiff_t in iterator is deperecated in c++17 template class RowwiseTransformIterator - : public std::iterator { + : public std::iterator { public: RowwiseTransformIterator(const T *ptr, int n) : ptr_(ptr), i_(0), n_(n) {} diff --git a/paddle/fluid/platform/port.h b/paddle/fluid/platform/port.h index ec681f8b2ad..e6a112e19df 100644 --- a/paddle/fluid/platform/port.h +++ b/paddle/fluid/platform/port.h @@ -18,6 +18,7 @@ #include #include +#include // NOLINT #define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h #define GOOGLE_GLOG_DLL_DECL -- GitLab