test_SIMDFlags.cpp 2.0 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 21

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

TEST(SIMDFlags, normalPrint) {
L
liaogang 已提交
36 37 38 39 40 41 42 43 44 45
  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;
L
liaogang 已提交
46
}