From bf5342702f566703a67289682b38682b95533a7a Mon Sep 17 00:00:00 2001 From: liaogang Date: Fri, 9 Dec 2016 15:47:44 +0800 Subject: [PATCH] Fix bugs on SIMD flags and unit test --- paddle/utils/CpuId.cpp | 4 ---- paddle/utils/CpuId.h | 22 +++++++++++----------- paddle/utils/tests/test_SIMDFlags.cpp | 16 ++++++++-------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/paddle/utils/CpuId.cpp b/paddle/utils/CpuId.cpp index 909c347945b..734b2e09246 100644 --- a/paddle/utils/CpuId.cpp +++ b/paddle/utils/CpuId.cpp @@ -28,10 +28,6 @@ limitations under the License. */ namespace paddle { -/// init simd instance -static InitFunction __init_simd_flags( - []{ SIMDFlags::instance(); }, std::numeric_limits::max()); - SIMDFlags::SIMDFlags() { unsigned int cpuInfo[4]; // CPUID: https://en.wikipedia.org/wiki/CPUID diff --git a/paddle/utils/CpuId.h b/paddle/utils/CpuId.h index 59a917c8578..d15e58d1ddd 100644 --- a/paddle/utils/CpuId.h +++ b/paddle/utils/CpuId.h @@ -24,17 +24,17 @@ public: static SIMDFlags* instance(); - inline bool isSSE() { return simd_flags_ & SIMD_SSE; } - inline bool isSSE2() { return simd_flags_ & SIMD_SSE2; } - inline bool isSSE3() { return simd_flags_ & SIMD_SSE3; } - inline bool isSSSE3() { return simd_flags_ & SIMD_SSSE3; } - inline bool isSSE41() { return simd_flags_ & SIMD_SSE41; } - inline bool isSSE42() { return simd_flags_ & SIMD_SSE42; } - inline bool isFMA3() { return simd_flags_ & SIMD_FMA3; } - inline bool isFMA4() { return simd_flags_ & SIMD_FMA4; } - inline bool isAVX() { return simd_flags_ & SIMD_AVX; } - inline bool isAVX2() { return simd_flags_ & SIMD_AVX2; } - inline bool isAVX512() { return simd_flags_ & SIMD_AVX512;} + inline bool isSSE() const { return simd_flags_ & SIMD_SSE; } + inline bool isSSE2() const { return simd_flags_ & SIMD_SSE2; } + inline bool isSSE3() const { return simd_flags_ & SIMD_SSE3; } + inline bool isSSSE3() const { return simd_flags_ & SIMD_SSSE3; } + inline bool isSSE41() const { return simd_flags_ & SIMD_SSE41; } + inline bool isSSE42() const { return simd_flags_ & SIMD_SSE42; } + inline bool isFMA3() const { return simd_flags_ & SIMD_FMA3; } + inline bool isFMA4() const { return simd_flags_ & SIMD_FMA4; } + inline bool isAVX() const { return simd_flags_ & SIMD_AVX; } + inline bool isAVX2() const { return simd_flags_ & SIMD_AVX2; } + inline bool isAVX512()const { return simd_flags_ & SIMD_AVX512;} private: enum simd_t { diff --git a/paddle/utils/tests/test_SIMDFlags.cpp b/paddle/utils/tests/test_SIMDFlags.cpp index 382d69a4a60..a544901aa38 100644 --- a/paddle/utils/tests/test_SIMDFlags.cpp +++ b/paddle/utils/tests/test_SIMDFlags.cpp @@ -20,14 +20,14 @@ using namespace paddle; // NOLINT TEST(SIMDFlags, gccTest) { #if (defined(__GNUC__) || defined(__GNUG__)) && !(defined(__clang__)) - CHECK(__builtin_cpu_supports("sse") == HAS_SSE); - CHECK(__builtin_cpu_supports("sse2") == HAS_SSE2); - CHECK(__builtin_cpu_supports("sse3") == HAS_SSE3); - CHECK(__builtin_cpu_supports("ssse3") == HAS_SSSE3); - CHECK(__builtin_cpu_supports("sse4.1")== HAS_SSE41); - CHECK(__builtin_cpu_supports("sse4.2")== HAS_SSE42); - CHECK(__builtin_cpu_supports("avx") == HAS_AVX); - CHECK(__builtin_cpu_supports("avx2") == HAS_AVX2); + CHECK(!__builtin_cpu_supports("sse") != HAS_SSE); + CHECK(!__builtin_cpu_supports("sse2") != HAS_SSE2); + CHECK(!__builtin_cpu_supports("sse3") != HAS_SSE3); + CHECK(!__builtin_cpu_supports("ssse3") != HAS_SSSE3); + CHECK(!__builtin_cpu_supports("sse4.1")!= HAS_SSE41); + CHECK(!__builtin_cpu_supports("sse4.2")!= HAS_SSE42); + CHECK(!__builtin_cpu_supports("avx") != HAS_AVX); + CHECK(!__builtin_cpu_supports("avx2") != HAS_AVX2); #endif } -- GitLab