From ac425090f389e34f9aee71b5957cca529ac74a38 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 26 Feb 2010 14:57:49 +0100 Subject: [PATCH] BTL: allow to bench real time --- bench/bench_gemm.cpp | 5 +- bench/bench_gemm_blas.cpp | 109 ++++++++++++++++++ bench/btl/generic_bench/bench_parameter.hh | 2 +- bench/btl/generic_bench/btl.hh | 21 +++- .../timers/portable_perf_analyzer.hh | 2 +- .../generic_bench/timers/portable_timer.hh | 44 ++----- 6 files changed, 142 insertions(+), 41 deletions(-) create mode 100644 bench/bench_gemm_blas.cpp diff --git a/bench/bench_gemm.cpp b/bench/bench_gemm.cpp index d958cc1bf..c7a3db619 100644 --- a/bench/bench_gemm.cpp +++ b/bench/bench_gemm.cpp @@ -3,6 +3,7 @@ // icpc bench_gemm.cpp -I .. -O3 -DNDEBUG -lrt -openmp && OMP_NUM_THREADS=2 ./a.out #include + #include using namespace std; @@ -68,10 +69,10 @@ void gemm(const M& a, const M& b, M& c) int main(int argc, char ** argv) { - int rep = 1; // number of repetitions per try + int rep = 2048; // number of repetitions per try int tries = 5; // number of tries, we keep the best - int s = 2048; + int s = 512; int m = s; int n = s; int p = s; diff --git a/bench/bench_gemm_blas.cpp b/bench/bench_gemm_blas.cpp new file mode 100644 index 000000000..254302312 --- /dev/null +++ b/bench/bench_gemm_blas.cpp @@ -0,0 +1,109 @@ + +#include +#include + +extern "C" +{ + #include + #include + + void sgemm_kernel(int actual_mc, int cols, int actual_kc, float alpha, + float* blockA, float* blockB, float* res, int resStride); + + void sgemm_otcopy(int actual_kc, int cols, const float* rhs, int rhsStride, float* blockB); + void sgemm_oncopy(int actual_kc, int cols, const float* rhs, int rhsStride, float* blockB); + void sgemm_itcopy(int actual_kc, int cols, const float* rhs, int rhsStride, float* blockB); + void sgemm_incopy(int actual_kc, int cols, const float* rhs, int rhsStride, float* blockB); +} + +using namespace std; +using namespace Eigen; + +#ifndef SCALAR +#define SCALAR float +#endif + +typedef SCALAR Scalar; +typedef Matrix M; + +static float fone = 1; +static float fzero = 0; +static double done = 1; +static double szero = 0; +static char notrans = 'N'; +static char trans = 'T'; +static char nonunit = 'N'; +static char lower = 'L'; +static char right = 'R'; +static int intone = 1; + +void blas_gemm(const MatrixXf& a, const MatrixXf& b, MatrixXf& c) +{ + int M = c.rows(); + int N = c.cols(); + int K = a.cols(); + + int lda = a.rows(); + int ldb = b.rows(); + int ldc = c.rows(); + +// c.noalias() += a * b; + sgemm_(¬rans,¬rans,&M,&N,&K,&fone, + const_cast(a.data()),&lda, + const_cast(b.data()),&ldb,&fone, + c.data(),&ldc); +} + +void blas_gemm(const MatrixXd& a, const MatrixXd& b, MatrixXd& c) +{ + int M = c.rows(); + int N = c.cols(); + int K = a.cols(); + + int lda = a.rows(); + int ldb = b.rows(); + int ldc = c.rows(); + +// c.noalias() += a * b; + + dgemm_(¬rans,¬rans,&M,&N,&K,&done, + const_cast(a.data()),&lda, + const_cast(b.data()),&ldb,&done, + c.data(),&ldc); +} + +int main(int argc, char **argv) +{ + int rep = 1; + int s = 2048; + int m = s; + int n = s; + int p = s; + const int N = 1; + M a[N]; + M b[N]; + M c[N]; + + for (int k=0; k m_selectedActionNames; diff --git a/bench/btl/generic_bench/timers/portable_perf_analyzer.hh b/bench/btl/generic_bench/timers/portable_perf_analyzer.hh index 6b1f8e7d7..5c337471e 100644 --- a/bench/btl/generic_bench/timers/portable_perf_analyzer.hh +++ b/bench/btl/generic_bench/timers/portable_perf_analyzer.hh @@ -53,7 +53,7 @@ public: } // optimize - for (int i=1; i