test_SIMDFlags.cpp 2.1 KB
Newer Older
L
liaogang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* Copyright (c) 2016 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. */

#include <gtest/gtest.h>

#include "paddle/utils/CpuId.h"
#include "paddle/utils/Logging.h"
#include "paddle/utils/Util.h"

Y
Yu Yang 已提交
18
using namespace paddle;  // NOLINT
L
liaogang 已提交
19 20

TEST(SIMDFlags, gccTest) {
21 22
#if (defined(__GNUC__) || defined(__GNUG__)) && !(defined(__clang__)) && \
    !defined(__arm__)
L
liaogang 已提交
23
  // clang-format off
24 25 26 27
  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);
Y
Yu Yang 已提交
28 29
  CHECK(!__builtin_cpu_supports("sse4.1") != HAS_SSE41);
  CHECK(!__builtin_cpu_supports("sse4.2") != HAS_SSE42);
30 31 32
  CHECK(!__builtin_cpu_supports("avx")    != HAS_AVX);
  CHECK(!__builtin_cpu_supports("avx2")   != HAS_AVX2);
// clang-format on
L
liaogang 已提交
33 34 35 36
#endif
}

TEST(SIMDFlags, normalPrint) {
L
liaogang 已提交
37 38 39 40 41 42 43 44 45 46
  LOG(INFO) << "Has SSE:     " << std::boolalpha << HAS_SSE;
  LOG(INFO) << "Has SSE2:    " << std::boolalpha << HAS_SSE2;
  LOG(INFO) << "Has SSE3:    " << std::boolalpha << HAS_SSE3;
  LOG(INFO) << "Has SSSE3:   " << std::boolalpha << HAS_SSSE3;
  LOG(INFO) << "Has SSE4:    " << std::boolalpha << HAS_SSE41 || HAS_SSE42;
  LOG(INFO) << "Has FMA3:    " << std::boolalpha << HAS_FMA3;
  LOG(INFO) << "Has FMA4:    " << std::boolalpha << HAS_FMA4;
  LOG(INFO) << "Has AVX:     " << std::boolalpha << HAS_AVX;
  LOG(INFO) << "Has AVX2:    " << std::boolalpha << HAS_AVX2;
  LOG(INFO) << "Has AVX512:  " << std::boolalpha << HAS_AVX512;
47
  LOG(INFO) << "Has NEON:    " << std::boolalpha << HAS_NEON;
L
liaogang 已提交
48
}