update BTL (better timer, eigen2 => eigen3, etc)

This commit is contained in:
Gael Guennebaud 2010-02-23 18:23:12 +01:00
parent 801440c519
commit 68eaefa5d4
6 changed files with 88 additions and 81 deletions

View File

@ -70,7 +70,7 @@ MACRO(BTL_ADD_BENCH targetname)
IF(BUILD_${targetname}) IF(BUILD_${targetname})
ADD_EXECUTABLE(${targetname} ${_sources}) ADD_EXECUTABLE(${targetname} ${_sources})
ADD_TEST(${targetname} "${targetname}") ADD_TEST(${targetname} "${targetname}")
target_link_libraries(${targetname} ${DEFAULT_LIBRARIES}) target_link_libraries(${targetname} ${DEFAULT_LIBRARIES} rt)
ENDIF(BUILD_${targetname}) ENDIF(BUILD_${targetname})
ENDMACRO(BTL_ADD_BENCH) ENDMACRO(BTL_ADD_BENCH)

View File

@ -1,6 +1,6 @@
eigen2 ; with lines lw 4 lt 1 lc rgbcolor "black" eigen3 ; with lines lw 4 lt 1 lc rgbcolor "black"
eigen2_novec ; with lines lw 2 lt 1 lc rgbcolor "#999999" eigen3_novec ; with lines lw 2 lt 1 lc rgbcolor "#999999"
eigen2_nogccvec ; with lines lw 2 lt 2 lc rgbcolor "#991010" eigen3_nogccvec ; with lines lw 2 lt 2 lc rgbcolor "#991010"
INTEL_MKL ; with lines lw 3 lt 2 lc rgbcolor "#00b7ff" INTEL_MKL ; with lines lw 3 lt 2 lc rgbcolor "#00b7ff"
ATLAS ; with lines lw 3 lt 1 lc rgbcolor "#52e657" ATLAS ; with lines lw 3 lt 1 lc rgbcolor "#52e657"
gmm ; with lines lw 3 lt 1 lc rgbcolor "#0000ff" gmm ; with lines lw 3 lt 1 lc rgbcolor "#0000ff"

View File

@ -23,7 +23,7 @@
// minimal time for each measurement // minimal time for each measurement
#define REAL_TYPE float #define REAL_TYPE float
// minimal time for each measurement // minimal time for each measurement
#define MIN_TIME 0.5 #define MIN_TIME 0.2
// nb of point on bench curves // nb of point on bench curves
#define NB_POINT 100 #define NB_POINT 100
// min vector size for axpy bench // min vector size for axpy bench
@ -48,6 +48,6 @@
#define DEFAULT_NB_SAMPLE 1000 #define DEFAULT_NB_SAMPLE 1000
// how many times we run a single bench (keep the best perf) // how many times we run a single bench (keep the best perf)
#define NB_TRIES 5 #define NB_TRIES 3
#endif #endif

View File

@ -27,41 +27,41 @@
template <class Action> template <class Action>
class Portable_Perf_Analyzer{ class Portable_Perf_Analyzer{
public: public:
Portable_Perf_Analyzer( void ):_nb_calc(1),_chronos(){ Portable_Perf_Analyzer( ):_nb_calc(0), m_time_action(0), _chronos(){
MESSAGE("Portable_Perf_Analyzer Ctor"); MESSAGE("Portable_Perf_Analyzer Ctor");
}; };
Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){ Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){
INFOS("Copy Ctor not implemented"); INFOS("Copy Ctor not implemented");
exit(0); exit(0);
}; };
~Portable_Perf_Analyzer( void ){ ~Portable_Perf_Analyzer(){
MESSAGE("Portable_Perf_Analyzer Dtor"); MESSAGE("Portable_Perf_Analyzer Dtor");
}; };
BTL_DONT_INLINE double eval_mflops(int size) BTL_DONT_INLINE double eval_mflops(int size)
{ {
Action action(size); Action action(size);
double time_action = 0; // action.initialize();
action.initialize(); // time_action = time_calculate(action);
time_action = time_calculate(action); while (m_time_action < MIN_TIME)
while (time_action < MIN_TIME)
{ {
_nb_calc *= 2; if(_nb_calc==0) _nb_calc = 1;
else _nb_calc *= 2;
action.initialize(); action.initialize();
time_action = time_calculate(action); m_time_action = time_calculate(action);
} }
// optimize // optimize
for (int i=1; i<NB_TRIES; ++i) for (int i=1; i<NB_TRIES; ++i)
{ {
Action _action(size); Action _action(size);
std::cout << " " << _action.nb_op_base()*_nb_calc/(time_action*1e6) << " "; std::cout << " " << _action.nb_op_base()*_nb_calc/(m_time_action*1e6) << " ";
_action.initialize(); _action.initialize();
time_action = std::min(time_action, time_calculate(_action)); m_time_action = std::min(m_time_action, time_calculate(_action));
} }
time_action = time_action / (double(_nb_calc)); double time_action = m_time_action / (double(_nb_calc));
// check // check
if (BtlConfig::Instance.checkResults && size<128) if (BtlConfig::Instance.checkResults && size<128)
@ -70,7 +70,7 @@ public:
action.calculate(); action.calculate();
action.check_result(); action.check_result();
} }
return action.nb_op_base()/(time_action*1000000.0); return action.nb_op_base()/(time_action*1e6);
} }
BTL_DONT_INLINE double time_calculate(Action & action) BTL_DONT_INLINE double time_calculate(Action & action)
@ -86,7 +86,7 @@ public:
return _chronos.user_time(); return _chronos.user_time();
} }
unsigned long long get_nb_calc( void ) unsigned long long get_nb_calc()
{ {
return _nb_calc; return _nb_calc;
} }
@ -94,6 +94,7 @@ public:
private: private:
unsigned long long _nb_calc; unsigned long long _nb_calc;
double m_time_action;
Portable_Timer _chronos; Portable_Timer _chronos;
}; };

View File

@ -75,7 +75,7 @@
private: private:
double LIToSecs(LARGE_INTEGER& L) { double LIToSecs(LARGE_INTEGER& L) {
return ((double)L.QuadPart /(double)frequency.QuadPart) ; return ((double)L.QuadPart /(double)frequency.QuadPart) ;
} }
@ -98,34 +98,37 @@ class Portable_Timer
{ {
public: public:
Portable_Timer( void ):_utime_sec_start(-1), Portable_Timer( void )
_utime_usec_start(-1), // :_utime_sec_start(-1),
_utime_sec_stop(-1), // _utime_usec_start(-1),
_utime_usec_stop(-1)/*, // _utime_sec_stop(-1),
m_prev_cs(-1)*/ // _utime_usec_stop(-1)/*,
// m_prev_cs(-1)*/
{ {
} }
void start() void start()
{ {
int status=getrusage(RUSAGE_SELF, &resourcesUsage) ; // int status=getrusage(RUSAGE_SELF, &resourcesUsage) ;
// _start_time = std::clock(); // _utime_sec_start = resourcesUsage.ru_utime.tv_sec ;
_utime_sec_start = resourcesUsage.ru_utime.tv_sec ; // _utime_usec_start = resourcesUsage.ru_utime.tv_usec ;
_utime_usec_start = resourcesUsage.ru_utime.tv_usec ;
// m_prev_cs = resourcesUsage.ru_nivcsw; timespec ts;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
m_start_time = double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
} }
void stop() void stop()
{ {
int status=getrusage(RUSAGE_SELF, &resourcesUsage) ; // int status=getrusage(RUSAGE_SELF, &resourcesUsage) ;
// _stop_time = std::clock(); // _utime_sec_stop = resourcesUsage.ru_utime.tv_sec ;
_utime_sec_stop = resourcesUsage.ru_utime.tv_sec ; // _utime_usec_stop = resourcesUsage.ru_utime.tv_usec ;
_utime_usec_stop = resourcesUsage.ru_utime.tv_usec ;
// m_prev_cs = resourcesUsage.ru_nivcsw - m_prev_cs; timespec ts;
// std::cerr << resourcesUsage.ru_nvcsw << " + " << resourcesUsage.ru_nivcsw << "\n"; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
m_stop_time = double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
} }
@ -137,26 +140,29 @@ class Portable_Timer
double user_time() double user_time()
{ {
// std::cout << m_prev_cs << "\n"; // std::cout << m_prev_cs << "\n";
long tot_utime_sec=_utime_sec_stop-_utime_sec_start; // long tot_utime_sec=_utime_sec_stop-_utime_sec_start;
long tot_utime_usec=_utime_usec_stop-_utime_usec_start; // long tot_utime_usec=_utime_usec_stop-_utime_usec_start;
return double(tot_utime_sec)+ double(tot_utime_usec)/double(USEC_IN_SEC) ; // return double(tot_utime_sec)+ double(tot_utime_usec)/double(USEC_IN_SEC) ;
return m_stop_time - m_start_time;
} }
private: private:
struct rusage resourcesUsage ; // struct rusage resourcesUsage ;
long _utime_sec_start ; // long _utime_sec_start ;
long _utime_usec_start ; // long _utime_usec_start ;
long _utime_sec_stop ; // long _utime_sec_stop ;
long _utime_usec_stop ; // long _utime_usec_stop ;
// long m_prev_cs; // long m_prev_cs;
std::clock_t _start_time; // std::clock_t _start_time;
std::clock_t _stop_time; // std::clock_t _stop_time;
double m_stop_time, m_start_time;
}; // Portable_Timer }; // Portable_Timer

View File

@ -1,57 +1,57 @@
# find_package(MKL)
find_package(Eigen2) find_package(Eigen2)
if (EIGEN2_FOUND) if (EIGEN2_FOUND)
include_directories(${EIGEN2_INCLUDE_DIR}) include_directories(${EIGEN2_INCLUDE_DIR})
btl_add_bench(btl_eigen2_linear main_linear.cpp) btl_add_bench(btl_eigen3_linear main_linear.cpp)
btl_add_bench(btl_eigen2_vecmat main_vecmat.cpp) btl_add_bench(btl_eigen3_vecmat main_vecmat.cpp)
btl_add_bench(btl_eigen2_matmat main_matmat.cpp) btl_add_bench(btl_eigen3_matmat main_matmat.cpp)
btl_add_bench(btl_eigen2_adv main_adv.cpp ) btl_add_bench(btl_eigen3_adv main_adv.cpp )
btl_add_target_property(btl_eigen2_linear COMPILE_FLAGS "-DBTL_PREFIX=eigen2") btl_add_target_property(btl_eigen3_linear COMPILE_FLAGS "-fno-exceptions -DBTL_PREFIX=eigen3")
btl_add_target_property(btl_eigen2_vecmat COMPILE_FLAGS "-DBTL_PREFIX=eigen2") btl_add_target_property(btl_eigen3_vecmat COMPILE_FLAGS "-fno-exceptions -DBTL_PREFIX=eigen3")
btl_add_target_property(btl_eigen2_matmat COMPILE_FLAGS "-DBTL_PREFIX=eigen2") btl_add_target_property(btl_eigen3_matmat COMPILE_FLAGS "-fno-exceptions -DBTL_PREFIX=eigen3")
btl_add_target_property(btl_eigen2_adv COMPILE_FLAGS "-DBTL_PREFIX=eigen2") btl_add_target_property(btl_eigen3_adv COMPILE_FLAGS "-fno-exceptions -DBTL_PREFIX=eigen3")
option(BTL_BENCH_NOGCCVEC "also bench Eigen explicit vec without GCC's auto vec" OFF) option(BTL_BENCH_NOGCCVEC "also bench Eigen explicit vec without GCC's auto vec" OFF)
if(CMAKE_COMPILER_IS_GNUCXX AND BTL_BENCH_NOGCCVEC) if(CMAKE_COMPILER_IS_GNUCXX AND BTL_BENCH_NOGCCVEC)
btl_add_bench(btl_eigen2_nogccvec_linear main_linear.cpp) btl_add_bench(btl_eigen3_nogccvec_linear main_linear.cpp)
btl_add_bench(btl_eigen2_nogccvec_vecmat main_vecmat.cpp) btl_add_bench(btl_eigen3_nogccvec_vecmat main_vecmat.cpp)
btl_add_bench(btl_eigen2_nogccvec_matmat main_matmat.cpp) btl_add_bench(btl_eigen3_nogccvec_matmat main_matmat.cpp)
btl_add_bench(btl_eigen2_nogccvec_adv main_adv.cpp ) btl_add_bench(btl_eigen3_nogccvec_adv main_adv.cpp )
btl_add_target_property(btl_eigen2_nogccvec_linear COMPILE_FLAGS "-fno-tree-vectorize -DBTL_PREFIX=eigen2_nogccvec") btl_add_target_property(btl_eigen3_nogccvec_linear COMPILE_FLAGS "-fno-exceptions -fno-tree-vectorize -DBTL_PREFIX=eigen3_nogccvec")
btl_add_target_property(btl_eigen2_nogccvec_vecmat COMPILE_FLAGS "-fno-tree-vectorize -DBTL_PREFIX=eigen2_nogccvec") btl_add_target_property(btl_eigen3_nogccvec_vecmat COMPILE_FLAGS "-fno-exceptions -fno-tree-vectorize -DBTL_PREFIX=eigen3_nogccvec")
btl_add_target_property(btl_eigen2_nogccvec_matmat COMPILE_FLAGS "-fno-tree-vectorize -DBTL_PREFIX=eigen2_nogccvec") btl_add_target_property(btl_eigen3_nogccvec_matmat COMPILE_FLAGS "-fno-exceptions -fno-tree-vectorize -DBTL_PREFIX=eigen3_nogccvec")
btl_add_target_property(btl_eigen2_nogccvec_adv COMPILE_FLAGS "-fno-tree-vectorize -DBTL_PREFIX=eigen2_nogccvec") btl_add_target_property(btl_eigen3_nogccvec_adv COMPILE_FLAGS "-fno-exceptions -fno-tree-vectorize -DBTL_PREFIX=eigen3_nogccvec")
endif() endif()
if(NOT BTL_NOVEC) if(NOT BTL_NOVEC)
btl_add_bench(btl_eigen2_novec_linear main_linear.cpp) btl_add_bench(btl_eigen3_novec_linear main_linear.cpp)
btl_add_bench(btl_eigen2_novec_vecmat main_vecmat.cpp) btl_add_bench(btl_eigen3_novec_vecmat main_vecmat.cpp)
btl_add_bench(btl_eigen2_novec_matmat main_matmat.cpp) btl_add_bench(btl_eigen3_novec_matmat main_matmat.cpp)
btl_add_bench(btl_eigen2_novec_adv main_adv.cpp ) btl_add_bench(btl_eigen3_novec_adv main_adv.cpp )
btl_add_target_property(btl_eigen2_novec_linear COMPILE_FLAGS "-DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen2_novec") btl_add_target_property(btl_eigen3_novec_linear COMPILE_FLAGS "-fno-exceptions -DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen3_novec")
btl_add_target_property(btl_eigen2_novec_vecmat COMPILE_FLAGS "-DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen2_novec") btl_add_target_property(btl_eigen3_novec_vecmat COMPILE_FLAGS "-fno-exceptions -DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen3_novec")
btl_add_target_property(btl_eigen2_novec_matmat COMPILE_FLAGS "-DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen2_novec") btl_add_target_property(btl_eigen3_novec_matmat COMPILE_FLAGS "-fno-exceptions -DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen3_novec")
btl_add_target_property(btl_eigen2_novec_adv COMPILE_FLAGS "-DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen2_novec") btl_add_target_property(btl_eigen3_novec_adv COMPILE_FLAGS "-fno-exceptions -DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen3_novec")
# if(BUILD_btl_eigen2_adv) # if(BUILD_btl_eigen3_adv)
# target_link_libraries(btl_eigen2_adv ${MKL_LIBRARIES}) # target_link_libraries(btl_eigen3_adv ${MKL_LIBRARIES})
# endif(BUILD_btl_eigen2_adv) # endif(BUILD_btl_eigen3_adv)
endif(NOT BTL_NOVEC) endif(NOT BTL_NOVEC)
btl_add_bench(btl_tiny_eigen2 btl_tiny_eigen2.cpp OFF) btl_add_bench(btl_tiny_eigen3 btl_tiny_eigen3.cpp OFF)
if(NOT BTL_NOVEC) if(NOT BTL_NOVEC)
btl_add_bench(btl_tiny_eigen2_novec btl_tiny_eigen2.cpp OFF) btl_add_bench(btl_tiny_eigen3_novec btl_tiny_eigen3.cpp OFF)
btl_add_target_property(btl_tiny_eigen2_novec COMPILE_FLAGS "-DBTL_PREFIX=eigen2_tiny") btl_add_target_property(btl_tiny_eigen3_novec COMPILE_FLAGS "-DBTL_PREFIX=eigen3_tiny")
if(BUILD_btl_tiny_eigen2_novec) if(BUILD_btl_tiny_eigen3_novec)
btl_add_target_property(btl_tiny_eigen2_novec COMPILE_FLAGS "-DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen2_tiny_novec") btl_add_target_property(btl_tiny_eigen3_novec COMPILE_FLAGS "-DEIGEN_DONT_VECTORIZE -DBTL_PREFIX=eigen3_tiny_novec")
endif(BUILD_btl_tiny_eigen2_novec) endif(BUILD_btl_tiny_eigen3_novec)
endif(NOT BTL_NOVEC) endif(NOT BTL_NOVEC)
endif (EIGEN2_FOUND) endif (EIGEN2_FOUND)