From fd15477fe8602a72021866f2001cc36af0972005 Mon Sep 17 00:00:00 2001 From: Sing_chan <51314274+betterpig@users.noreply.github.com> Date: Tue, 9 Nov 2021 16:26:55 +0800 Subject: [PATCH] fix bugs when build in windows with_inference_api_test=on (#36973) --- cmake/external/dirent.cmake | 45 +++++++++++++++++++ cmake/third_party.cmake | 5 +++ .../fluid/inference/tests/api/tester_helper.h | 3 +- ...e_ernie_fp16_serialize_deserialize_test.cc | 8 +++- ..._shape_ernie_serialize_deserialize_test.cc | 8 +++- ...c_shape_ernie_serialize_deserialize_test.h | 5 +++ paddle/fluid/platform/complex.h | 8 ++-- paddle/fluid/platform/init.cc | 3 ++ paddle/fluid/platform/port.h | 3 ++ 9 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 cmake/external/dirent.cmake diff --git a/cmake/external/dirent.cmake b/cmake/external/dirent.cmake new file mode 100644 index 00000000000..45c9c7c2d68 --- /dev/null +++ b/cmake/external/dirent.cmake @@ -0,0 +1,45 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Note(chenxin33): dirent.h is only exist in Linux, so get it from github when build in windows. +# use dirent tag v1.23.2 on 09/05//2018 https://github.com/tronkko/dirent.git + +INCLUDE (ExternalProject) + +SET(DIRENT_PREFIX_DIR ${THIRD_PARTY_PATH}/dirent) +SET(DIRENT_SOURCE_DIR ${THIRD_PARTY_PATH}/dirent/src/extern_dirent) +SET(DIRENT_INCLUDE_DIR ${DIRENT_SOURCE_DIR}/include) + +include_directories(${DIRENT_INCLUDE_DIR}) + +set(DIRENT_REPOSITORY ${GIT_URL}/tronkko/dirent) +set(DIRENT_TAG 1.23.2) + +ExternalProject_Add( + extern_dirent + ${EXTERNAL_PROJECT_LOG_ARGS} + ${SHALLOW_CLONE} + GIT_REPOSITORY ${DIRENT_REPOSITORY} + GIT_TAG ${DIRENT_TAG} + PREFIX ${DIRENT_PREFIX_DIR} + UPDATE_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) + +add_library(dirent INTERFACE) + +add_dependencies(dirent extern_dirent) \ No newline at end of file diff --git a/cmake/third_party.cmake b/cmake/third_party.cmake index 7df70477682..8b3c17ae3db 100644 --- a/cmake/third_party.cmake +++ b/cmake/third_party.cmake @@ -378,4 +378,9 @@ if (WITH_POCKETFFT) add_definitions(-DPADDLE_WITH_POCKETFFT) endif (WITH_POCKETFFT) +if (WIN32) + include(external/dirent) + list(APPEND third_party_deps extern_dirent) +endif (WIN32) + add_custom_target(third_party ALL DEPENDS ${third_party_deps}) diff --git a/paddle/fluid/inference/tests/api/tester_helper.h b/paddle/fluid/inference/tests/api/tester_helper.h index 8e6b8b197d7..01953bd721f 100644 --- a/paddle/fluid/inference/tests/api/tester_helper.h +++ b/paddle/fluid/inference/tests/api/tester_helper.h @@ -465,7 +465,8 @@ void PredictionWarmUp(PaddlePredictor *predictor, } int iterations = 1; if (FLAGS_warmup_iters > 1) - iterations = std::min(FLAGS_warmup_iters, static_cast(inputs.size())); + iterations = + (std::min)(FLAGS_warmup_iters, static_cast(inputs.size())); outputs->resize(iterations); Timer warmup_timer; double elapsed_time = 0; diff --git a/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_fp16_serialize_deserialize_test.cc b/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_fp16_serialize_deserialize_test.cc index a5b9e6825c8..7e9f71c8b3c 100644 --- a/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_fp16_serialize_deserialize_test.cc +++ b/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_fp16_serialize_deserialize_test.cc @@ -13,9 +13,15 @@ See the License for the specific language governing permissions and limitations under the License. */ #include +#ifndef _WIN32 +#include +#else // headers below are substitute of unistd.h in windows +#include +#include +#endif +#define GLOG_NO_ABBREVIATED_SEVERITIES #include #include -#include #include "gflags/gflags.h" #include "paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.h" diff --git a/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.cc b/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.cc index 084169da340..209dd90c480 100644 --- a/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.cc +++ b/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.cc @@ -13,9 +13,15 @@ See the License for the specific language governing permissions and limitations under the License. */ #include +#ifndef _WIN32 +#include +#else // headers below are substitute of unistd.h in windows +#include +#include +#endif +#define GLOG_NO_ABBREVIATED_SEVERITIES #include #include -#include #include "gflags/gflags.h" #include "paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.h" diff --git a/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.h b/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.h index 86a5223cafe..5ae14576dfe 100644 --- a/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.h +++ b/paddle/fluid/inference/tests/api/trt_dynamic_shape_ernie_serialize_deserialize_test.h @@ -14,7 +14,12 @@ limitations under the License. */ #pragma once #include #include +#ifndef _WIN32 #include +#else // headers below are substitute of unistd.h in windows +#include +#include +#endif #include #include #include diff --git a/paddle/fluid/platform/complex.h b/paddle/fluid/platform/complex.h index 065ccd375c9..35de34086c5 100644 --- a/paddle/fluid/platform/complex.h +++ b/paddle/fluid/platform/complex.h @@ -352,12 +352,12 @@ HOSTDEVICE inline bool operator>=(const complex& a, const complex& b) { } template -HOSTDEVICE inline complex max(const complex& a, const complex& b) { +HOSTDEVICE inline complex(max)(const complex& a, const complex& b) { return (a.real >= b.real) ? a : b; } template -HOSTDEVICE inline complex min(const complex& a, const complex& b) { +HOSTDEVICE inline complex(min)(const complex& a, const complex& b) { return (a.real < b.real) ? a : b; } @@ -507,13 +507,13 @@ struct numeric_limits> { static const bool traps = false; static const bool tinyness_before = false; - static paddle::platform::complex min() { + static paddle::platform::complex(min)() { return paddle::platform::complex(0.0, 0.0); } static paddle::platform::complex lowest() { return paddle::platform::complex(0.0, 0.0); } - static paddle::platform::complex max() { + static paddle::platform::complex(max)() { return paddle::platform::complex(0.0, 0.0); } static paddle::platform::complex epsilon() { diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index 290b3353ae5..1109ecd5282 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -37,6 +37,9 @@ limitations under the License. */ #ifdef WITH_WIN_DUMP_DBG #include #include +#ifndef NOMINMAX +#define NOMINMAX // msvc max/min macro conflict with std::min/max +#endif #include #include "DbgHelp.h" diff --git a/paddle/fluid/platform/port.h b/paddle/fluid/platform/port.h index 453bea625b0..981e5f5af64 100644 --- a/paddle/fluid/platform/port.h +++ b/paddle/fluid/platform/port.h @@ -30,13 +30,16 @@ #include #include // std::accumulate #else +#ifndef NOMINMAX #define NOMINMAX // msvc max/min macro conflict with std::min/max +#endif // solve static linking error in windows // https://github.com/google/glog/issues/301 #define GOOGLE_GLOG_DLL_DECL #include // _popen, _pclose #include #include +#include #include // std::accumulate in msvc #ifndef S_ISDIR // windows port for sys/stat.h #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) -- GitLab