Commit be79a839 authored by Peter Steinbach's avatar Peter Steinbach Committed by GitHub

Merge pull request #11 from psteinb/cmake-detect-feature

Cmake detect feature
parents 43b10f67 3be9d77c
*~
build
build/*
debug/*
*sln
*.vcxproj*
x64
x32
......@@ -50,7 +50,7 @@ matrix:
- os: osx
osx_image: xcode9
env:
- MATRIX_EVAL="CC=clang && CXX=clang"
- MATRIX_EVAL="CC=clang && CXX=clang++"
before_install:
- eval "${MATRIX_EVAL}"
......@@ -58,6 +58,7 @@ before_install:
script:
- mkdir -p build && cd build
- cmake ..
- cat tests/build_machine.hpp
- make VERBOSE=1
- ctest -V -j
- cd ..
\ No newline at end of file
......@@ -17,3 +17,4 @@ endif()
add_test(NAME compass_impl COMMAND test_compass_impl)
add_test(NAME bitview COMMAND test_bitview)
add_test(NAME build_machine COMMAND test_build_machine)
......@@ -15,6 +15,7 @@ install: []
build_script:
- IF "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" ( SET GEN="Visual Studio 14 2015") ELSE (SET GEN="Visual Studio 15 2017")
- wmic.exe cpu get
- cmake . -G%GEN% # -DCMAKE_CXX_FLAGS="%additional_flags%"
- cmake --build . --config Release
......
This diff is collapsed.
This diff is collapsed.
#ifndef COMPASS_DEFINITIONS_H
#define COMPASS_DEFINITIONS_H
#include "ct/preprocessor_impl.hpp"
namespace compass {
namespace compiletime {
......@@ -26,4 +24,6 @@ namespace compass {
};
//#include "ct/preprocessor_impl.hpp"
#endif /* DEFINITIONS_H */
......@@ -47,6 +47,8 @@ namespace compass {
};
#endif
namespace compass {
......@@ -261,6 +263,7 @@ namespace compass {
#ifndef COMPASS_X86_CPUID_COMMON_H
#define COMPASS_X86_CPUID_COMMON_H
#ifndef COMPASS_CT_COMP_MSVC
#include "cpuid.h"
namespace compass {
......@@ -299,7 +302,7 @@ namespace compass {
};
};
#endif
#endif
#ifndef COMPASS_RT_X86_LLVM_CPUID_H_
#define COMPASS_RT_X86_LLVM_CPUID_H_
......
......@@ -77,3 +77,12 @@ if(${CURRENT_HOSTNAME} MATCHES ".*(falcon2|talisker|schorle|scicomp-pc-3|recover
endif()
endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(CPU_FEATURES)
configure_file(${PROJECT_SOURCE_DIR}/tests/build_machine.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/build_machine.hpp)
add_executable(test_build_machine test_build_machine.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_build_machine PRIVATE ${CATCH2_HEADER_PATH} ${COMPASS_INCLUDE_BUILD_DIR} ${CMAKE_CURRENT_BINARY_DIR})
#ifndef _COMPASS_FIXTURES_H_
#define _COMPASS_FIXTURES_H_
#include <iostream>
#include <string>
#include <thread>
struct host_reference
{
std::string hostname ;
std::string expected_vendor ;
std::string expected_brand ;
std::string expected_device_name ;
bool expected_has_sse ;
bool expected_has_sse2 ;
bool expected_has_sse3 ;
bool expected_has_sse4 ;
bool expected_has_avx ;
bool expected_has_avx2 ;
std::uint32_t expected_L1d_linesize ;
std::uint32_t expected_L2_linesize ;
std::uint32_t expected_L3_linesize ;
std::uint32_t expected_L1d_size_kB ;
std::uint32_t expected_L2_size_kB ;
std::uint32_t expected_L3_size_kB ;
std::uint32_t expected_ncores ;
std::uint32_t expected_nphyscores ;
host_reference():
hostname(""),
expected_vendor (""),
expected_brand (""),
expected_device_name (""),
expected_has_sse (false),
expected_has_sse2(false),
expected_has_sse3(false),
expected_has_sse4(false),
expected_has_avx (false),
expected_has_avx2(false),
expected_L1d_linesize(0) ,
expected_L2_linesize(0) ,
expected_L3_linesize(0) ,
expected_L1d_size_kB(0) ,
expected_L2_size_kB(0),
expected_L3_size_kB(0),
expected_ncores (std::thread::hardware_concurrency()),
expected_nphyscores (0)
{
expected_vendor = "@CPU_VENDOR@";
expected_brand = "@CPU_MODEL_NAME@";
expected_device_name = "";
expected_has_sse= @SSE_FOUND@ ;
expected_has_sse2= @SSE2_FOUND@ ;
expected_has_sse3= @SSE3_FOUND@ ;
expected_has_sse4= @SSE4_1_FOUND@ ;
expected_has_avx = @AVX_FOUND@ ;
expected_has_avx2= @AVX2_FOUND@ ;
//check by `cat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size`
// expected_L1d_linesize= 64 ;
// expected_L2_linesize= 64 ;
// expected_L3_linesize= 64 ;
// //check by `cat /sys/devices/system/cpu/cpu0/cache/index0/size`
// expected_L1d_size_kB= 32 ;
expected_L2_size_kB= @CPU_L2_SIZE_KB@;
// expected_L3_size_kB= 4096 ; /sys/devices/system/cpu/cpu0/cache/index3/size
// expected_nphyscores = 2;
}
};
#endif /* _COMPASS_FIXTURES_H_ */
#include "catch.hpp"
#include "detail/bit_view.hpp"
#include "compass.hpp"
#include <bitset>
......
#include "catch.hpp"
#include "build_machine.hpp"
#include "compass.hpp"
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
TEST_CASE_METHOD( host_reference, "machine_specific" ){
SECTION( "vendor_right" ){
auto value = compass::runtime::vendor();
REQUIRE(value.size()!=0u);
// std::transform(value.begin(), value.end(),
// value.begin(),
// ::tolower);
REQUIRE(value.find(expected_vendor)!=std::string::npos);
}
SECTION( "brand_right" ){
auto value = compass::runtime::brand();
REQUIRE(value.empty()!=true);
REQUIRE_THAT(value, Catch::Matchers::Contains(expected_brand) );
}
SECTION( "device_name_right" ){
auto value = compass::runtime::device_name();
REQUIRE(value.empty()!=true);
REQUIRE_THAT(value, Catch::Matchers::Contains(expected_device_name) );
}
SECTION( "ncores_right" ){
auto value = compass::runtime::threads();
REQUIRE(value!=0);
REQUIRE(value==expected_ncores);
}
// SECTION( "physical_cores_right" ){
// auto value = compass::runtime::physical_threads();
// REQUIRE(value!=0);
// REQUIRE(value==expected_nphyscores);
// }
SECTION( "has_sse_right" ){
auto value = compass::runtime::has(compass::feature::sse());
REQUIRE(value==expected_has_sse);
}
SECTION( "has_sse2_right" ){
auto value = compass::runtime::has(compass::feature::sse2());
REQUIRE(value==expected_has_sse2);
}
SECTION( "has_sse3_right" ){
auto value = compass::runtime::has(compass::feature::sse3());
REQUIRE(value==expected_has_sse3);
}
SECTION( "has_sse4_right" ){
auto value = compass::runtime::has(compass::feature::sse4());
REQUIRE(value==expected_has_sse4);
}
SECTION( "has_avx_right" ){
auto value = compass::runtime::has(compass::feature::avx());
REQUIRE(value==expected_has_avx);
}
SECTION( "has_avx2_right" ){
auto value = compass::runtime::has(compass::feature::avx2());
REQUIRE(value==expected_has_avx2);
}
SECTION( "correct_l2_cache_size" ){
auto value = compass::runtime::size::cache::level(2);
REQUIRE(value > 0);
if(expected_L2_size_kB){
REQUIRE(value >> 10 ==expected_L2_size_kB);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment