From 0d46f518aef8d8893f5f438475e6bc53b6f2b8bd Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Thu, 23 Aug 2018 14:32:46 +0800 Subject: [PATCH] refine avx condition and warning --- cmake/configure.cmake | 22 ++++++++++++++-------- paddle/fluid/platform/CMakeLists.txt | 2 +- paddle/fluid/platform/cpu_info.h | 2 +- paddle/fluid/platform/init.cc | 17 +++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cmake/configure.cmake b/cmake/configure.cmake index e03e15bfc01..7e5d8a76217 100644 --- a/cmake/configure.cmake +++ b/cmake/configure.cmake @@ -50,14 +50,20 @@ if(NOT WITH_PROFILER) endif(NOT WITH_PROFILER) if(NOT CMAKE_CROSSCOMPILING) - if(WITH_AVX AND AVX512F_FOUND) - set(SIMD_FLAG ${AVX512F_FLAG}) - elseif(WITH_AVX AND AVX2_FOUND) - set(SIMD_FLAG ${AVX2_FLAG}) - elseif(WITH_AVX AND AVX_FOUND) - set(SIMD_FLAG ${AVX_FLAG}) - elseif(SSE3_FOUND) - set(SIMD_FLAG ${SSE3_FLAG}) + set(SIMD_FLAG) + if(WITH_AVX) + if (AVX512F_FOUND) + set(SIMD_FLAG "${SIMD_FLAG} ${AVX512F_FLAG}") + endif() + if (AVX2_FOUND) + set(SIMD_FLAG "${SIMD_FLAG} ${AVX2_FLAG}") + endif() + if (AVX_FOUND) + set(SIMD_FLAG "${SIMD_FLAG} ${AVX_FLAG}") + endif() + if (SSE3_FOUND) + set(SIMD_FLAG "${SIMD_FLAG} ${SSE3_FLAG}") + endif() endif() endif() diff --git a/paddle/fluid/platform/CMakeLists.txt b/paddle/fluid/platform/CMakeLists.txt index f08c0e8e345..75d3856d0dd 100644 --- a/paddle/fluid/platform/CMakeLists.txt +++ b/paddle/fluid/platform/CMakeLists.txt @@ -50,7 +50,7 @@ ENDIF() # memcpy depends on device_context, here add deps individually for # avoiding cycle dependencies cc_library(device_context SRCS device_context.cc init.cc DEPS malloc - place eigen3 stringpiece cpu_helper framework_proto ${GPU_CTX_DEPS} ${MKLDNN_CTX_DEPS}) + place eigen3 stringpiece cpu_helper cpu_info framework_proto ${GPU_CTX_DEPS} ${MKLDNN_CTX_DEPS}) nv_test(device_context_test SRCS device_context_test.cu DEPS device_context gpu_info) cc_test(init_test SRCS init_test.cc DEPS device_context) diff --git a/paddle/fluid/platform/cpu_info.h b/paddle/fluid/platform/cpu_info.h index 5d17978dd79..30c8fbcfce9 100644 --- a/paddle/fluid/platform/cpu_info.h +++ b/paddle/fluid/platform/cpu_info.h @@ -51,7 +51,7 @@ typedef enum { } cpu_isa_t; // Instruction set architecture // May I use some instruction -inline bool MayIUse(const cpu_isa_t cpu_isa); +bool MayIUse(const cpu_isa_t cpu_isa); } // namespace jit diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index 6f1f0c4796f..020ce4d6f59 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -18,6 +18,7 @@ limitations under the License. */ #include "paddle/fluid/framework/operator.h" #include "paddle/fluid/platform/cpu_helper.h" +#include "paddle/fluid/platform/cpu_info.h" #include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/init.h" #include "paddle/fluid/platform/place.h" @@ -120,6 +121,22 @@ void InitDevices(bool init_p2p, const std::vector devices) { #ifndef PADDLE_WITH_MKLDNN platform::SetNumThreads(FLAGS_paddle_num_threads); #endif + + if (platform::jit::MayIUse(platform::jit::avx512_common)) { +#ifndef __AVX512F__ + LOG(WARNING) << "AVX512F is available, Please re-compile on local machine"; +#endif + } + if (platform::jit::MayIUse(platform::jit::avx2)) { +#ifndef __AVX2__ + LOG(WARNING) << "AVX2 is available, Please re-compile on local machine"; +#endif + } + if (platform::jit::MayIUse(platform::jit::avx)) { +#ifndef __AVX__ + LOG(WARNING) << "AVX is available, Please re-compile on local machine"; +#endif + } } void InitGLOG(const std::string &prog_name) { -- GitLab