From 98798e904bd255de1d775f4f7b468614cc48eeb0 Mon Sep 17 00:00:00 2001 From: Jakob Schwendner Date: Sun, 16 Dec 2012 23:30:56 +0100 Subject: [PATCH 1/3] added benchmark for test vectorization in geometry package --- bench/benchGeometry.cpp | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 bench/benchGeometry.cpp diff --git a/bench/benchGeometry.cpp b/bench/benchGeometry.cpp new file mode 100644 index 000000000..270b67b65 --- /dev/null +++ b/bench/benchGeometry.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +using namespace Eigen; + +#ifndef REPEAT +#define REPEAT 1000000 +#endif + +enum func_opt +{ + TV, + TMATRIXV +}; + + +template +struct func; + +template +struct func +{ + static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) + { + asm (""); + return a1 * a2; + } +}; + +template +struct func +{ + static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) + { + asm (""); + return a1.matrix() * a2; + } +}; + + +template +struct test_transform +{ + static void run() + { + arg1 a1; + a1.setIdentity(); + arg2 a2; + a2.setIdentity(); + + BenchTimer timer; + timer.reset(); + for (int k=0; k<10; ++k) + { + timer.start(); + for (int k=0; k Trans;\ + typedef Matrix Vec;\ + typedef func Func;\ + test_transform< Func, Trans, Vec >::run();\ + } + +int main(int argc, char* argv[]) +{ + run_test(TV, float, Isometry, AutoAlign, 3); + run_test(TV, float, Isometry, DontAlign, 3); + run_test(TV, float, Isometry, AutoAlign, 4); + run_test(TV, float, Isometry, DontAlign, 4); + + run_test(TMATRIXV, float, Isometry, AutoAlign, 4); + run_test(TMATRIXV, float, Isometry, DontAlign, 4); +} From 22e6741da9a3c05637e9ffcfc78dc2476cd017db Mon Sep 17 00:00:00 2001 From: Jakob Schwendner Date: Mon, 17 Dec 2012 09:33:22 +0100 Subject: [PATCH 2/3] updated geometry benchmark to handle additional cases --- bench/benchGeometry.cpp | 72 ++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/bench/benchGeometry.cpp b/bench/benchGeometry.cpp index 270b67b65..7a532a846 100644 --- a/bench/benchGeometry.cpp +++ b/bench/benchGeometry.cpp @@ -1,8 +1,11 @@ #include +#include #include #include #include + using namespace Eigen; +using namespace std; #ifndef REPEAT #define REPEAT 1000000 @@ -11,7 +14,8 @@ using namespace Eigen; enum func_opt { TV, - TMATRIXV + TMATV, + TMATVMAT, }; @@ -29,7 +33,7 @@ struct func }; template -struct func +struct func { static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) { @@ -38,6 +42,15 @@ struct func } }; +template +struct func +{ + static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) + { + asm (""); + return res(a1.matrix() * a2.matrix()); + } +}; template struct test_transform @@ -58,13 +71,13 @@ struct test_transform a2 = func::run( a1, a2 ); timer.stop(); } - std::cout << timer.value() << "s " << (double(REPEAT)/timer.value())/(1024.*1024.*1024.) << " GFlops\n"; + cout << setprecision(4) << fixed << timer.value() << "s " << endl;; } }; -#define run_test( op, scalar, mode, option, vsize ) \ - std::cout << #op << " " << #scalar << " " << #mode << " " << #option << " " << #vsize " "; \ +#define run_vec( op, scalar, mode, option, vsize ) \ + std::cout << #scalar << "\t " << #mode << "\t " << #option << " " << #vsize " "; \ {\ typedef Transform Trans;\ typedef Matrix Vec;\ @@ -72,13 +85,50 @@ struct test_transform test_transform< Func, Trans, Vec >::run();\ } +#define run_trans( op, scalar, mode, option ) \ + std::cout << #scalar << "\t " << #mode << "\t " << #option << " "; \ + {\ + typedef Transform Trans;\ + typedef func Func;\ + test_transform< Func, Trans, Trans >::run();\ + } + int main(int argc, char* argv[]) { - run_test(TV, float, Isometry, AutoAlign, 3); - run_test(TV, float, Isometry, DontAlign, 3); - run_test(TV, float, Isometry, AutoAlign, 4); - run_test(TV, float, Isometry, DontAlign, 4); + cout << "vec = trans * vec" << endl; + run_vec(TV, float, Isometry, AutoAlign, 3); + run_vec(TV, float, Isometry, DontAlign, 3); + run_vec(TV, float, Isometry, AutoAlign, 4); + run_vec(TV, float, Isometry, DontAlign, 4); + run_vec(TV, float, Projective, AutoAlign, 4); + run_vec(TV, float, Projective, DontAlign, 4); + run_vec(TV, double, Isometry, AutoAlign, 3); + run_vec(TV, double, Isometry, DontAlign, 3); + run_vec(TV, double, Isometry, AutoAlign, 4); + run_vec(TV, double, Isometry, DontAlign, 4); + run_vec(TV, double, Projective, AutoAlign, 4); + run_vec(TV, double, Projective, DontAlign, 4); - run_test(TMATRIXV, float, Isometry, AutoAlign, 4); - run_test(TMATRIXV, float, Isometry, DontAlign, 4); + cout << "vec = trans.matrix() * vec" << endl; + run_vec(TMATV, float, Isometry, AutoAlign, 4); + run_vec(TMATV, float, Isometry, DontAlign, 4); + run_vec(TMATV, double, Isometry, AutoAlign, 4); + run_vec(TMATV, double, Isometry, DontAlign, 4); + + cout << "trans = trans1 * trans" << endl; + run_trans(TV, float, Isometry, AutoAlign); + run_trans(TV, float, Isometry, DontAlign); + run_trans(TV, double, Isometry, AutoAlign); + run_trans(TV, double, Isometry, DontAlign); + run_trans(TV, float, Projective, AutoAlign); + run_trans(TV, float, Projective, DontAlign); + run_trans(TV, double, Projective, AutoAlign); + run_trans(TV, double, Projective, DontAlign); + + cout << "trans = trans1.matrix() * trans.matrix()" << endl; + run_trans(TMATVMAT, float, Isometry, AutoAlign); + run_trans(TMATVMAT, float, Isometry, DontAlign); + run_trans(TMATVMAT, double, Isometry, AutoAlign); + run_trans(TMATVMAT, double, Isometry, DontAlign); } + From 6300e8ca0239ed4bfe8fbf37c5f72cb4ef3451a7 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Mon, 17 Dec 2012 16:55:14 +0100 Subject: [PATCH 3/3] replaced compiler specific __attribute__((noinline)) by EIGEN_DONT_INLINE --- bench/benchGeometry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bench/benchGeometry.cpp b/bench/benchGeometry.cpp index 7a532a846..6e16c0331 100644 --- a/bench/benchGeometry.cpp +++ b/bench/benchGeometry.cpp @@ -25,7 +25,7 @@ struct func; template struct func { - static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) + static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 ) { asm (""); return a1 * a2; @@ -35,7 +35,7 @@ struct func template struct func { - static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) + static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 ) { asm (""); return a1.matrix() * a2; @@ -45,7 +45,7 @@ struct func template struct func { - static __attribute__ ((noinline)) res run( arg1& a1, arg2& a2 ) + static EIGEN_DONT_INLINE res run( arg1& a1, arg2& a2 ) { asm (""); return res(a1.matrix() * a2.matrix());