aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-07-02 16:05:33 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-07-02 16:05:33 +0000
commit8463b7d3f4ba6b94d79503d30b7822f064adbb08 (patch)
tree5d03ec7ad2a7722fd0bc9520fdb38477f50f2f0f /bench
parent9433df83a773d3ccfe0a481ae36e5e3a6e60fd50 (diff)
* fix compilation issue in Product
* added some tests for product and swap * overload .swap() for dynamic-sized matrix of same size
Diffstat (limited to 'bench')
-rw-r--r--bench/benchBlasGemm.cpp58
-rw-r--r--bench/benchmark.cpp13
2 files changed, 33 insertions, 38 deletions
diff --git a/bench/benchBlasGemm.cpp b/bench/benchBlasGemm.cpp
index d22af89da..02f067e1a 100644
--- a/bench/benchBlasGemm.cpp
+++ b/bench/benchBlasGemm.cpp
@@ -1,4 +1,8 @@
+// g++-4.2 -O3 -DNDEBUG -I.. benchBlasGemm.cpp /usr/lib/libcblas.so.3 - o benchBlasGemm
+// possible options:
+// -DEIGEN_DONT_VECTORIZE
+// -msse2
// #define EIGEN_DEFAULT_TO_ROW_MAJOR
#define _FLOAT
@@ -28,6 +32,8 @@ void check_product(void);
int main(int argc, char *argv[])
{
+ // disable SSE exceptions
+ #ifdef __GNUC__
{
int aux;
asm(
@@ -36,6 +42,7 @@ int main(int argc, char *argv[])
"ldmxcsr %[aux] \n\t"
: : [aux] "m" (aux));
}
+ #endif
int nbtries=1, nbloops=1, M, N, K;
@@ -70,8 +77,18 @@ int main(int argc, char *argv[])
}
else
{
+ std::cout << "Usage: " << argv[0] << " size \n";
+ std::cout << "Usage: " << argv[0] << " auto size\n";
std::cout << "Usage: " << argv[0] << " size nbloops nbtries\n";
std::cout << "Usage: " << argv[0] << " M N K nbloops nbtries\n";
+ std::cout << "Usage: " << argv[0] << " check\n";
+ std::cout << "Options:\n"
+ std::cout << " size unique size of the 2 matrices (integer)\n";
+ std::cout << " auto automatically set the number of repetitions and tries\n";
+ std::cout << " nbloops number of times the GEMM routines is executed\n"
+ std::cout << " nbtries number of times the loop is benched (return the best try)\n"
+ std::cout << " M N K sizes of the matrices: MxN = MxK * KxN (integers)\n"
+ std::cout << " check check eigen product using cblas as a reference\n";
exit(1);
}
@@ -119,7 +136,7 @@ int main(int argc, char *argv[])
mb = MyMatrix::random(K,N);
mc = MyMatrix::random(M,N);
- // eigen fast ?
+ // eigen
// if (!(std::string(argv[1])=="auto"))
{
timer.reset();
@@ -158,20 +175,10 @@ int main(int argc, char *argv[])
using namespace Eigen;
-
-
void bench_eigengemm(MyMatrix& mc, const MyMatrix& ma, const MyMatrix& mb, int nbloops)
{
for (uint j=0 ; j<nbloops ; ++j)
- #ifdef EIGEN_WIP_PRODUCT_DIRTY
- mc = ma * mb;
- #else
mc += (ma * mb).lazy();
- /*static_cast<MatrixBase<MyMatrix>& >*//*(mc).operator+=( (ma * mb).lazy() );*/
-
-// Flagged<Product<MyMatrix,MyMatrix,CacheFriendlyProduct>, 0, EvalBeforeNestingBit | EvalBeforeAssigningBit>(
-// Product<MyMatrix,MyMatrix,CacheFriendlyProduct>(ma, mb)));
- #endif
}
void bench_eigengemm_normal(MyMatrix& mc, const MyMatrix& ma, const MyMatrix& mb, int nbloops)
@@ -183,7 +190,6 @@ void bench_eigengemm_normal(MyMatrix& mc, const MyMatrix& ma, const MyMatrix& mb
#define MYVERIFY(A,M) if (!(A)) { \
std::cout << "FAIL: " << M << "\n"; \
}
-
void check_product(int M, int N, int K)
{
MyMatrix ma(M,K), mb(K,N), mc(M,N), maT(K,M), mbT(N,K), meigen(M,N), mref(M,N);
@@ -200,20 +206,20 @@ void check_product(int M, int N, int K)
meigen += ma * mb;
MYVERIFY(meigen.isApprox(mref, eps),". * .");
-// meigen = mref = mc;
-// CBLAS_GEMM(CblasColMajor, CblasTrans, CblasNoTrans, M, N, K, 1, maT.data(), K, mb.data(), K, 1, mref.data(), M);
-// meigen += maT.transpose() * mb;
-// MYVERIFY(meigen.isApprox(mref, eps),"T * .");
-//
-// meigen = mref = mc;
-// CBLAS_GEMM(CblasColMajor, CblasTrans, CblasTrans, M, N, K, 1, maT.data(), K, mbT.data(), N, 1, mref.data(), M);
-// meigen += (maT.transpose()) * (mbT.transpose());
-// MYVERIFY(meigen.isApprox(mref, eps),"T * T");
-//
-// meigen = mref = mc;
-// CBLAS_GEMM(CblasColMajor, CblasNoTrans, CblasTrans, M, N, K, 1, ma.data(), M, mbT.data(), N, 1, mref.data(), M);
-// meigen += ma * mbT.transpose();
-// MYVERIFY(meigen.isApprox(mref, eps),". * T");
+ meigen = mref = mc;
+ CBLAS_GEMM(CblasColMajor, CblasTrans, CblasNoTrans, M, N, K, 1, maT.data(), K, mb.data(), K, 1, mref.data(), M);
+ meigen += maT.transpose() * mb;
+ MYVERIFY(meigen.isApprox(mref, eps),"T * .");
+
+ meigen = mref = mc;
+ CBLAS_GEMM(CblasColMajor, CblasTrans, CblasTrans, M, N, K, 1, maT.data(), K, mbT.data(), N, 1, mref.data(), M);
+ meigen += (maT.transpose()) * (mbT.transpose());
+ MYVERIFY(meigen.isApprox(mref, eps),"T * T");
+
+ meigen = mref = mc;
+ CBLAS_GEMM(CblasColMajor, CblasNoTrans, CblasTrans, M, N, K, 1, ma.data(), M, mbT.data(), N, 1, mref.data(), M);
+ meigen += ma * mbT.transpose();
+ MYVERIFY(meigen.isApprox(mref, eps),". * T");
}
void check_product(void)
diff --git a/bench/benchmark.cpp b/bench/benchmark.cpp
index b48b21d68..5aeb2d315 100644
--- a/bench/benchmark.cpp
+++ b/bench/benchmark.cpp
@@ -18,17 +18,6 @@ USING_PART_OF_NAMESPACE_EIGEN
int main(int argc, char *argv[])
{
- Matrix4i m1, m2, m3;
- m1.setRandom();
- m2.setConstant(2);
- int s1 = 2;
- m3 = m1;
- std::cout << m1 << "\n\n";
- std::cout << m2 << "\n\n";
- m3 = m1.cwiseProduct(m2);
- std::cout << m3 << "\n==\n" << m1*s1 << "\n\n";
-// v(1,2,3,4);
-// std::cout << v * 2 << "\n";
Matrix<SCALAR,MATSIZE,MATSIZE> I = Matrix<SCALAR,MATSIZE,MATSIZE>::ones();
Matrix<SCALAR,MATSIZE,MATSIZE> m;
for(int i = 0; i < MATSIZE; i++)
@@ -39,7 +28,7 @@ int main(int argc, char *argv[])
asm("#begin");
for(int a = 0; a < REPEAT; a++)
{
- m = Matrix<SCALAR,MATSIZE,MATSIZE>::ones() + 0.00005 * (m + (m*m).eval());
+ m = Matrix<SCALAR,MATSIZE,MATSIZE>::ones() + 0.00005 * (m + (m*m));
}
asm("#end");
cout << m << endl;