Commit b8f97f3f authored by steinbac's avatar steinbac

added cacheline retrieval, cache size started

parent 5dd4ce5a
......@@ -10,6 +10,7 @@ cmake_host_system_information(RESULT CURRENT_HOSTNAME QUERY HOSTNAME)
if(${CURRENT_HOSTNAME} MATCHES ".*(falcon2|schorle|scicomp-pc-3|recovery-station).*")
message(">> hostname (${CURRENT_HOSTNAME}): added compass test ")
add_test(NAME compass_impl COMMAND test_compass_impl)
add_test(NAME compass_sizes COMMAND test_compass_sizes)
else()
message(">> unknown host (${CURRENT_HOSTNAME}): no tests were written for your host ")
endif()
......
......@@ -69,6 +69,17 @@ namespace compass {
}
};
struct cache{
static std::uint32_t level(int _lvl){
using current_arch_t = ct::arch::type;
return compass::runtime::detail::size::cache::level(_lvl,current_arch_t());
}
};
};//size
};//namespace runtime
......
......@@ -184,7 +184,7 @@ namespace compass {
static bool has(feature::avx2 , ct::x86_tag){
auto regs = rt::cpuid(7,7,0,0,0);
auto regs = rt::cpuid(7,0,0,0);
bool value = bitview(regs[ct::ebx]).test(5);
......
......@@ -24,17 +24,46 @@ namespace compass {
namespace size{
struct cacheline{
struct cacheline
{
static std::uint32_t level(int _lvl, ct::x86_tag){
auto regs = cpuid(0,0x4);
auto regs = cpuid(4,0,_lvl - 1);
if(!bitview(regs[ct::eax]).test(0))
return 0;//bitview(regs[ct::eax]).test(0) set if cache level does not exist
return regs[ct::ebx];
std::uint32_t value = bitview(regs[ct::ebx]).range(0,11);
return value + 1;
}
};
struct cache
{
static std::uint32_t level(int _lvl, ct::x86_tag){
auto regs = cpuid(4,0,_lvl - 1);
if(!bitview(regs[ct::eax]).test(0))
return 0;//bitview(regs[ct::eax]).test(0) set if cache level does not exist
std::uint32_t ways = 1 + bitview(regs[ct::ebx]).range(22,31);
std::uint32_t partitions = 1 + bitview(regs[ct::ebx]).range(12,21);
std::uint32_t line_size = 1 + bitview(regs[ct::ebx]).range(0,11);
std::uint32_t sets = 1 + regs[ct::ecx];
std::uint32_t value = ways*partitions*line_size*sets;
return value;
}
};
};
};//detail
......
......@@ -26,6 +26,9 @@ add_dependencies(catcho catch2)
if(${CURRENT_HOSTNAME} MATCHES ".*(falcon2|schorle|scicomp-pc-3|recovery-station).*")
add_executable(test_compass_impl test_compass_impl.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_compass_impl PRIVATE ${PROJECT_SOURCE_DIR}/include ${CATCH2_HEADER_PATH})
add_executable(test_compass_sizes test_compass_sizes.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_compass_sizes PRIVATE ${PROJECT_SOURCE_DIR}/include ${CATCH2_HEADER_PATH})
endif()
#idea for generating test fixture at cmake-invocation
......
......@@ -21,7 +21,15 @@ struct host_reference
bool expected_has_avx ;
bool expected_has_avx2 ;
int expected_ncores ;
int expected_L1d_linesize ;
int expected_L2_linesize ;
int expected_L3_linesize ;
int expected_L1d_size_kB ;
int expected_L2_size_kB ;
int expected_L3_size_kB ;
host_reference():
hostname(compass::tests::hostname()),
......@@ -34,6 +42,12 @@ struct host_reference
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 (-1)
{
......@@ -47,7 +61,12 @@ struct host_reference
expected_has_sse4= true ;
expected_has_avx = true ;
expected_has_avx2= false ;
expected_L1d_linesize= 42 ;
expected_L1d_linesize= 64 ;
expected_L2_linesize= 64 ;
expected_L3_linesize= 64 ;
expected_L1d_size_kB= 64 ;
expected_L2_size_kB= 0 ;
expected_L3_size_kB= 0 ;
expected_ncores = 4;
}
......
......@@ -121,12 +121,5 @@ TEST_CASE_METHOD( host_reference, "machine_specific" ){
}
SECTION( "L1d_cacheline_size" ){
auto value = compass::runtime::size::cacheline::level(1);
REQUIRE(value==expected_L1d_linesize);
}
}
#include "catch.hpp"
#include "compass_fixture.hpp"
#include "compass.hpp"
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
TEST_CASE_METHOD( host_reference, "machine_specific" ){
SECTION( "L1d_cacheline_size" ){
auto value = compass::runtime::size::cacheline::level(1);
REQUIRE(value==expected_L1d_linesize);
}
SECTION( "L1d_cache_size" ){
auto value = compass::runtime::size::cache::level(1);
REQUIRE(value==expected_L1d_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