Commit 127ed5e0 authored by steinbac's avatar steinbac

created minimal working version on Linux and Mac

parent 0211b011
# Check if SSE instructions are available on the machine where
# the project is compiled.
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
EXEC_PROGRAM(cat ARGS "/proc/cpuinfo" OUTPUT_VARIABLE CPUINFO)
STRING(REGEX REPLACE "^.*(sse2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "sse2" "${SSE_THERE}" SSE2_TRUE)
IF (SSE2_TRUE)
set(SSE2_FOUND true CACHE BOOL "SSE2 available on host")
ELSE (SSE2_TRUE)
set(SSE2_FOUND false CACHE BOOL "SSE2 available on host")
ENDIF (SSE2_TRUE)
# /proc/cpuinfo apparently omits sse3 :(
STRING(REGEX REPLACE "^.*[^s](sse3).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "sse3" "${SSE_THERE}" SSE3_TRUE)
IF (NOT SSE3_TRUE)
STRING(REGEX REPLACE "^.*(T2300).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "T2300" "${SSE_THERE}" SSE3_TRUE)
ENDIF (NOT SSE3_TRUE)
STRING(REGEX REPLACE "^.*(ssse3).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "ssse3" "${SSE_THERE}" SSSE3_TRUE)
IF (SSE3_TRUE OR SSSE3_TRUE)
set(SSE3_FOUND true CACHE BOOL "SSE3 available on host")
ELSE (SSE3_TRUE OR SSSE3_TRUE)
set(SSE3_FOUND false CACHE BOOL "SSE3 available on host")
ENDIF (SSE3_TRUE OR SSSE3_TRUE)
IF (SSSE3_TRUE)
set(SSSE3_FOUND true CACHE BOOL "SSSE3 available on host")
ELSE (SSSE3_TRUE)
set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host")
ENDIF (SSSE3_TRUE)
STRING(REGEX REPLACE "^.*(sse4_1).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "sse4_1" "${SSE_THERE}" SSE41_TRUE)
IF (SSE41_TRUE)
set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host")
ELSE (SSE41_TRUE)
set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host")
ENDIF (SSE41_TRUE)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin")
EXEC_PROGRAM("/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE
CPUINFO)
STRING(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSE2" "${SSE_THERE}" SSE2_TRUE)
IF (SSE2_TRUE)
set(SSE2_FOUND true CACHE BOOL "SSE2 available on host")
ELSE (SSE2_TRUE)
set(SSE2_FOUND false CACHE BOOL "SSE2 available on host")
ENDIF (SSE2_TRUE)
STRING(REGEX REPLACE "^.*[^S](SSE3).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSE3" "${SSE_THERE}" SSE3_TRUE)
IF (SSE3_TRUE)
set(SSE3_FOUND true CACHE BOOL "SSE3 available on host")
ELSE (SSE3_TRUE)
set(SSE3_FOUND false CACHE BOOL "SSE3 available on host")
ENDIF (SSE3_TRUE)
STRING(REGEX REPLACE "^.*(SSSE3).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSSE3" "${SSE_THERE}" SSSE3_TRUE)
IF (SSSE3_TRUE)
set(SSSE3_FOUND true CACHE BOOL "SSSE3 available on host")
ELSE (SSSE3_TRUE)
set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host")
ENDIF (SSSE3_TRUE)
STRING(REGEX REPLACE "^.*(SSE4.1).*$" "\\1" SSE_THERE ${CPUINFO})
STRING(COMPARE EQUAL "SSE4.1" "${SSE_THERE}" SSE41_TRUE)
IF (SSE41_TRUE)
set(SSE4_1_FOUND true CACHE BOOL "SSE4.1 available on host")
ELSE (SSE41_TRUE)
set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host")
ENDIF (SSE41_TRUE)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Windows")
# TODO
set(SSE2_FOUND true CACHE BOOL "SSE2 available on host")
set(SSE3_FOUND false CACHE BOOL "SSE3 available on host")
set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host")
set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host")
ELSE(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(SSE2_FOUND true CACHE BOOL "SSE2 available on host")
set(SSE3_FOUND false CACHE BOOL "SSE3 available on host")
set(SSSE3_FOUND false CACHE BOOL "SSSE3 available on host")
set(SSE4_1_FOUND false CACHE BOOL "SSE4.1 available on host")
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(NOT SSE2_FOUND)
MESSAGE(STATUS "Could not find hardware support for SSE2 on this machine.")
endif(NOT SSE2_FOUND)
if(NOT SSE3_FOUND)
MESSAGE(STATUS "Could not find hardware support for SSE3 on this machine.")
endif(NOT SSE3_FOUND)
if(NOT SSSE3_FOUND)
MESSAGE(STATUS "Could not find hardware support for SSSE3 on this machine.")
endif(NOT SSSE3_FOUND)
if(NOT SSE4_1_FOUND)
MESSAGE(STATUS "Could not find hardware support for SSE4.1 on this machine.")
endif(NOT SSE4_1_FOUND)
mark_as_advanced(SSE2_FOUND SSE3_FOUND SSSE3_FOUND SSE4_1_FOUND)
......@@ -77,3 +77,13 @@ if(${CURRENT_HOSTNAME} MATCHES ".*(falcon2|talisker|schorle|scicomp-pc-3|recover
endif()
endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(SSE)
message(STATUS "${PROJECT_SOURCE_DIR}/tests/build_machine.hpp.in --> ${CMAKE_CURRENT_BINARY_DIR}/build_machine.hpp")
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>
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 (0),
expected_nphyscores (0)
{
expected_vendor = "intel";
expected_brand = "Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz";
expected_device_name = "i7-3520M";
expected_has_sse2= @SSE2_FOUND@ ;
if(expected_has_sse2)
expected_has_sse = true ;
expected_has_sse3= @SSE3_FOUND@ ;
expected_has_sse4= @SSE4_1_FOUND@ ;
expected_has_avx = false ;
expected_has_avx2= false ;
//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= 256;
expected_L3_size_kB= 4096 ;
expected_ncores = 4;
expected_nphyscores = 2;
}
};
#endif /* _COMPASS_FIXTURES_H_ */
#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);
}
}
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