From 77a622f2bb3356ee005a9413f6436373ec06efc2 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 8 Jul 2008 17:20:17 +0000 Subject: add Cholesky and eigensolver benchmark --- bench/BenchSparseUtil.h | 2 - bench/BenchUtil.h | 40 +++++++++ bench/basicbenchmark.cpp | 14 +-- bench/benchCholesky.cpp | 132 ++++++++++++++++++++++++++++ bench/benchEigenSolver.cpp | 210 +++++++++++++++++++++++++++++++++++++++++++++ bench/bench_unrolling | 2 +- bench/ompbench.cxxlist | 7 -- bench/ompbenchmark.cpp | 81 ----------------- 8 files changed, 384 insertions(+), 104 deletions(-) create mode 100644 bench/benchCholesky.cpp create mode 100644 bench/benchEigenSolver.cpp delete mode 100644 bench/ompbench.cxxlist delete mode 100644 bench/ompbenchmark.cpp (limited to 'bench') diff --git a/bench/BenchSparseUtil.h b/bench/BenchSparseUtil.h index 9d88148d0..2c24c29e6 100644 --- a/bench/BenchSparseUtil.h +++ b/bench/BenchSparseUtil.h @@ -3,8 +3,6 @@ #include #include - - using namespace std; using namespace Eigen; USING_PART_OF_NAMESPACE_EIGEN diff --git a/bench/BenchUtil.h b/bench/BenchUtil.h index bb3c4611c..4afe61980 100644 --- a/bench/BenchUtil.h +++ b/bench/BenchUtil.h @@ -26,3 +26,43 @@ template void initMatrix_identity(MatrixType& mat) { mat.setIdentity(); } + +#ifndef __INTEL_COMPILER +#define DISABLE_SSE_EXCEPTIONS() { \ + int aux; \ + asm( \ + "stmxcsr %[aux] \n\t" \ + "orl $32832, %[aux] \n\t" \ + "ldmxcsr %[aux] \n\t" \ + : : [aux] "m" (aux)); \ +} +#else +#define DISABLE_SSE_EXCEPTIONS() +#endif + +#ifdef BENCH_GMM +#include +template +void eiToGmm(const EigenMatrixType& src, GmmMatrixType& dst) +{ + dst.resize(src.rows(),src.cols()); + for (int j=0; j +#include +#include +template +void eiToGsl(const EigenMatrixType& src, gsl_matrix** dst) +{ + for (int j=0; j +#include +#include +using namespace Eigen; + +#ifndef REPEAT +#define REPEAT 10000 +#endif + +#ifndef TRIES +#define TRIES 4 +#endif + +typedef float Scalar; + +template +__attribute__ ((noinline)) void benchCholesky(const MatrixType& m) +{ + int rows = m.rows(); + int cols = m.cols(); + + int repeats = (REPEAT*1000)/(rows*rows); + + typedef typename MatrixType::Scalar Scalar; + typedef Matrix SquareMatrixType; + + MatrixType a = MatrixType::random(rows,cols); + SquareMatrixType covMat = a * a.adjoint(); + + BenchTimer timerNoSqrt, timerSqrt; + + Scalar acc = 0; + int r = ei_random(0,covMat.rows()-1); + int c = ei_random(0,covMat.cols()-1); + for (int t=0; t cholnosqrt(covMat); + acc += cholnosqrt.matrixL().coeff(r,c); + } + timerNoSqrt.stop(); + } + + for (int t=0; t chol(covMat); + acc += chol.matrixL().coeff(r,c); + } + timerSqrt.stop(); + } + + if (MatrixType::RowsAtCompileTime==Dynamic) + std::cout << "dyn "; + else + std::cout << "fixed "; + std::cout << covMat.rows() << " \t" + << (timerNoSqrt.value() * REPEAT) / repeats << "s \t" + << (timerSqrt.value() * REPEAT) / repeats << "s"; + + + #ifdef BENCH_GSL + if (MatrixType::RowsAtCompileTime==Dynamic) + { + timerSqrt.reset(); + + gsl_matrix* gslCovMat = gsl_matrix_alloc(covMat.rows(),covMat.cols()); + gsl_matrix* gslCopy = gsl_matrix_alloc(covMat.rows(),covMat.cols()); + + eiToGsl(covMat, &gslCovMat); + for (int t=0; t0; ++i) + benchCholesky(Matrix(dynsizes[i],dynsizes[i])); + + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + benchCholesky(Matrix()); + return 0; +} + diff --git a/bench/benchEigenSolver.cpp b/bench/benchEigenSolver.cpp new file mode 100644 index 000000000..a62ee41f4 --- /dev/null +++ b/bench/benchEigenSolver.cpp @@ -0,0 +1,210 @@ + +// g++ -DNDEBUG -O3 -I.. benchEigenSolver.cpp -o benchEigenSolver && ./benchEigenSolver +// options: +// -DBENCH_GMM +// -DBENCH_GSL -lgsl /usr/lib/libcblas.so.3 +// -DEIGEN_DONT_VECTORIZE +// -msse2 +// -DREPEAT=100 +// -DTRIES=10 +// -DSCALAR=double + +#include +#include +#include +using namespace Eigen; + +#ifndef REPEAT +#define REPEAT 1000 +#endif + +#ifndef TRIES +#define TRIES 4 +#endif + +#ifndef SCALAR +#define SCALAR float +#endif + +typedef SCALAR Scalar; + +template +__attribute__ ((noinline)) void benchEigenSolver(const MatrixType& m) +{ + int rows = m.rows(); + int cols = m.cols(); + + int stdRepeats = std::max(1,int((REPEAT*1000)/(rows*rows*sqrt(rows)))); + int saRepeats = stdRepeats * 4; + + typedef typename MatrixType::Scalar Scalar; + typedef Matrix SquareMatrixType; + + MatrixType a = MatrixType::random(rows,cols); + SquareMatrixType covMat = a * a.adjoint(); + + BenchTimer timerSa, timerStd; + + Scalar acc = 0; + int r = ei_random(0,covMat.rows()-1); + int c = ei_random(0,covMat.cols()-1); + { + SelfAdjointEigenSolver ei(covMat); + for (int t=0; t ei(covMat); + for (int t=0; t gmmCovMat(covMat.rows(),covMat.cols()); + gmm::dense_matrix eigvect(covMat.rows(),covMat.cols()); + std::vector eigval(covMat.rows()); + eiToGmm(covMat, gmmCovMat); + for (int t=0; t0; ++i) + benchEigenSolver(Matrix(dynsizes[i],dynsizes[i])); + + benchEigenSolver(Matrix()); + benchEigenSolver(Matrix()); + benchEigenSolver(Matrix()); + benchEigenSolver(Matrix()); + benchEigenSolver(Matrix()); + benchEigenSolver(Matrix()); + benchEigenSolver(Matrix()); + return 0; +} + diff --git a/bench/bench_unrolling b/bench/bench_unrolling index 7934031a8..bf01cce7d 100755 --- a/bench/bench_unrolling +++ b/bench/bench_unrolling @@ -5,7 +5,7 @@ for ((i=1; i<16; ++i)); do echo "Matrix size: $i x $i :" - $CXX -O3 -I.. -DNDEBUG benchmark.cpp -DMATSIZE=$i -DEIGEN_UNROLLING_LIMIT=1024 -DEIGEN_UNROLLING_LIMIT=25 -o benchmark && time ./benchmark >/dev/null + $CXX -O3 -I.. -DNDEBUG benchmark.cpp -DMATSIZE=$i -DEIGEN_UNROLLING_LIMIT=1024 -DEIGEN_UNROLLING_LIMIT=400 -o benchmark && time ./benchmark >/dev/null $CXX -O3 -I.. -DNDEBUG -finline-limit=10000 benchmark.cpp -DMATSIZE=$i -DEIGEN_DONT_USE_UNROLLED_LOOPS=1 -o benchmark && time ./benchmark >/dev/null echo " " done diff --git a/bench/ompbench.cxxlist b/bench/ompbench.cxxlist deleted file mode 100644 index fc6681d33..000000000 --- a/bench/ompbench.cxxlist +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -CLIST[((g++))]="g++-4.2 -O3 -DNDEBUG -finline-limit=10000 -fopenmp" - -# CLIST[((g++))]="g++-4.3 -O3 -DNDEBUG -finline-limit=10000 -fopenmp" - -CLIST[((g++))]="icpc -fast -DNDEBUG -fno-exceptions -no-inline-max-size -openmp" \ No newline at end of file diff --git a/bench/ompbenchmark.cpp b/bench/ompbenchmark.cpp deleted file mode 100644 index ac5155cb8..000000000 --- a/bench/ompbenchmark.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// g++ -O3 -DNDEBUG -I.. -fopenmp benchOpenMP.cpp -o benchOpenMP && ./benchOpenMP 2> /dev/null -// icpc -fast -fno-exceptions -DNDEBUG -I.. -openmp benchOpenMP.cpp -o benchOpenMP && ./benchOpenMP 2> /dev/null - -#include -#include "BenchUtil.h" -#include "basicbenchmark.h" - -// #include -// #include "BenchTimer.h" -// -// using namespace std; -// USING_PART_OF_NAMESPACE_EIGEN -// -// enum {LazyEval, EarlyEval, OmpEval}; -// -// template -// double benchSingleProc(const MatrixType& mat, int iterations, int tries) __attribute__((noinline)); -// -// template -// double benchBasic(const MatrixType& mat, int iterations, int tries) -// { -// const int rows = mat.rows(); -// const int cols = mat.cols(); -// -// Eigen::BenchTimer timer; -// for(uint t=0; t(Matrix4d(), 10000, 10) << "s " - << benchBasic(Matrix4d(), 10000, 10) << "s \n"; - - #define BENCH_MATRIX(TYPE, SIZE, ITERATIONS, TRIES) {\ - double single = benchBasic(Matrix(SIZE,SIZE), ITERATIONS, TRIES); \ - double omp = benchBasic (Matrix(SIZE,SIZE), ITERATIONS, TRIES); \ - std::cout << #TYPE << ", " << #SIZE << "x" << #SIZE << ": " << single << "s " << omp << "s " \ - << " => x" << single/omp << " (" << omp_get_num_procs() << ")" << std::endl; \ - } - - BENCH_MATRIX(double, 32, 1000, 10); - BENCH_MATRIX(double, 128, 10, 10); - BENCH_MATRIX(double, 512, 1, 6); - BENCH_MATRIX(double, 1024, 1, 4); - - return 0; -} - -- cgit v1.2.3