test_SIMDFlags.cpp 2.2 KB
Newer Older
L
liaogang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* 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"

using namespace paddle; // NOLINT

TEST(SIMDFlags, gccTest) {
#if (defined(__GNUC__) || defined(__GNUG__)) && !(defined(__clang__))
L
liaogang 已提交
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);
L
liaogang 已提交
27 28
    CHECK(__builtin_cpu_supports("sse4.1")== HAS_SSE41);
    CHECK(__builtin_cpu_supports("sse4.2")== HAS_SSE42);
L
liaogang 已提交
29 30
    CHECK(__builtin_cpu_supports("avx")   == HAS_AVX);
    CHECK(__builtin_cpu_supports("avx2")  == HAS_AVX2);
L
liaogang 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#endif
}

TEST(SIMDFlags, normalPrint) {
    auto simd = SIMDFlags::instance();
    LOG(INFO) << "Has SSE2:    " << std::boolalpha << simd->isSSE2();
    LOG(INFO) << "Has SSE3:    " << std::boolalpha << simd->isSSE3();
    LOG(INFO) << "Has SSSE3:   " << std::boolalpha << simd->isSSSE3();
    LOG(INFO) << "Has SSE4.1:  " << std::boolalpha << simd->isSSE41();
    LOG(INFO) << "Has SSE4.2:  " << std::boolalpha << simd->isSSE42();
    LOG(INFO) << "Has FMA3:    " << std::boolalpha << simd->isFMA3();
    LOG(INFO) << "Has FMA4:    " << std::boolalpha << simd->isFMA4();
    LOG(INFO) << "Has AVX:     " << std::boolalpha << simd->isAVX();
    LOG(INFO) << "Has AVX2:    " << std::boolalpha << simd->isAVX2();
    LOG(INFO) << "Has AVX512:  " << std::boolalpha << simd->isAVX512();
}

int main(int argc, char** argv) {
  testing::InitGoogleTest(&argc, argv);
  paddle::initMain(argc, argv);
  return RUN_ALL_TESTS();
}