From 26dbe35c547bd3c5322d796c6fdbb3a95cc2b907 Mon Sep 17 00:00:00 2001 From: dzhwinter Date: Sun, 26 Aug 2018 18:46:01 +0800 Subject: [PATCH] add msvc flags and copy lib done --- cmake/flags.cmake | 23 +++++++++++------ cmake/inference_lib.cmake | 25 ++++++++++++++++++- paddle/fluid/operators/CMakeLists.txt | 2 +- paddle/fluid/operators/math/CMakeLists.txt | 2 ++ paddle/fluid/operators/math/matrix_bit_code.h | 18 ++++++------- 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index e0556a0babc..f92090284cb 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -97,9 +97,13 @@ SET(CMAKE_EXTRA_INCLUDE_FILES "") # Common flags. the compiler flag used for C/C++ sources whenever release or debug # Do not care if this flag is support for gcc. + +# https://github.com/PaddlePaddle/Paddle/issues/12773 +if (NOT WIN32) set(COMMON_FLAGS -fPIC -fno-omit-frame-pointer + -Werror -Wall -Wextra -Wnon-virtual-dtor @@ -114,11 +118,6 @@ set(COMMON_FLAGS -Wno-error=terminate # Warning in PADDLE_ENFORCE ) -# https://github.com/PaddlePaddle/Paddle/issues/12773 -if (NOT WIN32) -list(APPEND COMMON_FLAGS -Werror) -endif() - set(GPU_COMMON_FLAGS -fPIC -fno-omit-frame-pointer @@ -133,18 +132,28 @@ set(GPU_COMMON_FLAGS -Wno-error=array-bounds # Warnings in Eigen::array ) +else(NOT WIN32) +set(COMMON_FLAGS + "/w") #disable all warnings +set(GPU_COMMON_FLAGS + "/w") #disable all warnings + +endif(NOT WIN32) + if (APPLE) if(NOT CMAKE_CROSSCOMPILING) # On Mac OS X build fat binaries with x86_64 architectures by default. set (CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX" FORCE) endif() -else() +endif(APPLE) + +if(LINUX) set(GPU_COMMON_FLAGS -Wall -Wextra -Werror ${GPU_COMMON_FLAGS}) -endif() +endif(LINUX) if(UNIX AND NOT APPLE) # except apple from nix*Os family diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index f97da29a007..5e40e1df49a 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -31,10 +31,33 @@ function(copy TARGET) foreach(index RANGE ${len}) list(GET copy_lib_SRCS ${index} src) list(GET copy_lib_DSTS ${index} dst) + + if (WIN32) + # windows cmd shell will not expand wildcard automatically. + # below expand the files,libs and copy them by rules. + file(GLOB header_files ${src} "*.h") + file(GLOB static_lib_files ${src} "*.lib") + file(GLOB dll_lib_files ${src} "*.dll") + set(src_files ${header_files} ${static_lib_files} ${dll_lib_files}) + + if (NOT "${src_files}" STREQUAL "") + list(REMOVE_DUPLICATES src_files) + endif() + #string(REPLACE ";" " " src_files ${src_files}) add_custom_command(TARGET ${TARGET} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${dst}" - COMMAND ${CMAKE_COMMAND} -E copy_directory "${src}" "${dst}" + ) + foreach(src_file ${src_files}) + add_custom_command(TARGET ${TARGET} PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy "${src_file}" "${dst}" + COMMENT "copying ${src_file} -> ${dst}") + endforeach() + else() # not windows + add_custom_command(TARGET ${TARGET} PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${dst}" + COMMAND ${CMAKE_COMMAND} -E copy "${src_files}" "${dst}" COMMENT "copying ${src} -> ${dst}") + endif(WIN32) endforeach() endfunction() diff --git a/paddle/fluid/operators/CMakeLists.txt b/paddle/fluid/operators/CMakeLists.txt index 343aeaf13f8..5f7e27608c3 100644 --- a/paddle/fluid/operators/CMakeLists.txt +++ b/paddle/fluid/operators/CMakeLists.txt @@ -85,7 +85,7 @@ function(op_library TARGET) #remove windows unsupported op if (WIN32) - foreach(windows_unsupport_op "nccl_op" "gen_nccl_id_op" "warpctc_op") + foreach(windows_unsupport_op "nccl_op" "gen_nccl_id_op" "warpctc_op" "hierarchical_sigmoid_op") if ("${TARGET}" STREQUAL "${windows_unsupport_op}") return() endif() diff --git a/paddle/fluid/operators/math/CMakeLists.txt b/paddle/fluid/operators/math/CMakeLists.txt index d2b772d1137..09f3c6b54f4 100644 --- a/paddle/fluid/operators/math/CMakeLists.txt +++ b/paddle/fluid/operators/math/CMakeLists.txt @@ -51,7 +51,9 @@ math_library(sequence_padding) math_library(sequence_pooling DEPS math_function) math_library(sequence_scale) math_library(softmax DEPS math_function) +if (NOT WIN32) math_library(matrix_bit_code) +endif (NOT WIN32) math_library(unpooling) math_library(vol2col) diff --git a/paddle/fluid/operators/math/matrix_bit_code.h b/paddle/fluid/operators/math/matrix_bit_code.h index 7670dcbf7c2..525cd45cccb 100644 --- a/paddle/fluid/operators/math/matrix_bit_code.h +++ b/paddle/fluid/operators/math/matrix_bit_code.h @@ -67,31 +67,31 @@ inline constexpr size_t FindLastSet(size_t x) { : (std::is_same::value // NOLINT ? (x ? 8 * sizeof(x) - __builtin_clzl(x) : 0) : (x ? 8 * sizeof(x) - __builtin_clzll(x) : 0)); + #else // windows don't have built-in clz, ctz function template -unint32_t __inline ctz(const T& value) { +inline int ctz(const T& value) { DWORD trailing_zero = 0; if (_BitScanForward(&trailing_zero, value)) { - return static_cast(trailing_zero); + return static_cast(trailing_zero); } else { - return static_cast(0); + return static_cast(0); } } template -unint32_t __inline clz(const T& value) { +inline int clz(const T& value) { DWORD leadning_zero = 0; if (_BitScanReverse(&leadning_zero, value)) { - return sizeof(T) * 8 - leadning_zero; + return static_cast(sizeof(T) * 8 - leadning_zero); } else { - return static_cast(0); + return static_cast(0); } } -template -inline size_t FindLastSet(const T& x) { - return sizeof(T) * 8 - clz(x); +inline size_t FindLastSet(size_t x) { + return sizeof(size_t) * 8 - clz(x); } #endif // !_WIN32 } -- GitLab