public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/auto-numerical-bench:unstable commit in: accuracy/, /, accuracy/lapack/, btl/libs/BLAS/, btl/generic_bench/utils/, ...
@ 2011-08-05  1:28 Andrea Arteaga
  0 siblings, 0 replies; only message in thread
From: Andrea Arteaga @ 2011-08-05  1:28 UTC (permalink / raw
  To: gentoo-commits

commit:     87da764f8191a31b77b85c7780226bc01f97bb55
Author:     Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
AuthorDate: Fri Aug  5 01:28:00 2011 +0000
Commit:     Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
CommitDate: Fri Aug  5 01:28:00 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=87da764f

Added lapack_accuracy module.

---
 accuracy/lapack/diff.hh                       |   30 +++++
 accuracy/lapack/lapack_LU.hh                  |   57 ++++++++++
 accuracy/lapack/lapack_QR.hh                  |   57 ++++++++++
 accuracy/lapack/lapack_SVD.hh                 |   40 +++++++
 accuracy/lapack/lapack_cholesky.hh            |   37 ++++++
 accuracy/lapack/main_lapack.cpp               |   89 +++++++++++++++
 accuracy/lapack/timer.hh                      |   50 ++++++++
 accuracy/sizes.hh                             |   42 +++++++
 basemodule.py                                 |    6 +-
 benchconfig.py                                |   25 ++---
 btl/generic_bench/utils/LinearCongruential.hh |    2 +-
 btl/libs/BLAS/blas.h                          |    8 +-
 btl/libs/LAPACK/lapack.hh                     |   16 +++
 btl/libs/LAPACK/lapack_.hh                    |   19 +++
 btl/libs/LAPACK/lapack_interface.hh           |    1 +
 lapack_accuracy.py                            |  149 +++++++++++++++++++++++++
 testdescr.py                                  |    2 +
 17 files changed, 607 insertions(+), 23 deletions(-)

diff --git a/accuracy/lapack/diff.hh b/accuracy/lapack/diff.hh
new file mode 100644
index 0000000..f807d30
--- /dev/null
+++ b/accuracy/lapack/diff.hh
@@ -0,0 +1,30 @@
+#ifndef DIFF_HH
+#define DIFF_HH
+
+#include <vector>
+
+double diff(const int& N, const double* x, const double* test)
+{
+  std::vector<double> d(x, x+N);
+  const int iONE = 1;
+  const double alpha = -1.;
+  daxpy_(&N, &alpha, test, &iONE, &d[0], &iONE);
+  return dnrm2_(&N, &d[0], &iONE)/dnrm2_(&N, x, &iONE);
+}
+
+template<typename T>
+T diff(const std::vector<T> x, const std::vector<T> test)
+{
+  return diff(static_cast<const int&>(x.size()), &x[0], &test[0]);
+}
+
+//float diff(const int& N, const float* x, const float* test)
+//{
+//  std::vector<float> d(x, x+N);
+//  const int iONE = 1;
+//  const float alpha = -1.;
+//  saxpy_(&N, &alpha, test, &iONE, &d[0], &iONE);
+//  return snrm2_(&N, &d[0], &iONE)/snrm2_(&N, x, &iONE);
+//}
+
+#endif /* DIFF_HH */

diff --git a/accuracy/lapack/lapack_LU.hh b/accuracy/lapack/lapack_LU.hh
new file mode 100644
index 0000000..8111f7b
--- /dev/null
+++ b/accuracy/lapack/lapack_LU.hh
@@ -0,0 +1,57 @@
+#ifndef LAPACK_LU_HH
+#define LAPACK_LU_HH
+
+#include "LinearCongruential.hh"
+#include "diff.hh"
+
+vector<int> get_piv(const vector<int>& ipiv)
+{
+  const int size = ipiv.size();
+  vector<int> ret(size);
+  for (int i = 0; i < size; ++i)
+    ret[i] = i;
+
+  int ii, jj, tmp;
+  for (int i = 1; i <= size; ++i) {
+      ii = i-1;
+      jj = ipiv[ii]-1;
+      tmp = ret[ii];
+      ret[ii] = ret[jj];
+      ret[jj] = tmp;
+  }
+
+  return ret;
+}
+
+double test_LU(const int& N, const unsigned& seed = 0)
+{
+  LinearCongruential lc(seed);
+
+  vector<double> A(N*N), Acopy, P(N*N);
+
+  /* Fill A and Acopy */
+  for (int i = 0; i < N*N; ++i)
+    A[i] = lc.get_01();
+  Acopy = A;
+
+  /* Compute decomposition */
+  vector<int> ipiv(N);
+  int info;
+  dgetrf_(&N, &N, &A[0], &N, &ipiv[0], &info);
+  vector<int> piv = get_piv(ipiv);
+
+  /* Construct P */
+  for (int r = 0; r < N; ++r) {
+    int c = piv[r];
+    P[c+N*r] = 1;
+  }
+
+  /* Test */
+  const double alpha = 1.;
+  dtrmm_("R", "L", "N", "U", &N, &N, &alpha, &A[0], &N, &P[0], &N);
+  dtrmm_("R", "U", "N", "N", &N, &N, &alpha, &A[0], &N, &P[0], &N);
+
+  return diff(Acopy, P);
+}
+
+#endif /* LAPACK_LU_HH */

diff --git a/accuracy/lapack/lapack_QR.hh b/accuracy/lapack/lapack_QR.hh
new file mode 100644
index 0000000..f5a93c8
--- /dev/null
+++ b/accuracy/lapack/lapack_QR.hh
@@ -0,0 +1,57 @@
+#ifndef LAPACK_QR_HH
+#define LAPACK_QR_HH
+
+#include "LinearCongruential.hh"
+#include "diff.hh"
+
+double test_QR(const int& N, const unsigned& seed = 0)
+{
+  LinearCongruential lc(seed);
+  vector<double> A(N*N), Acopy, tau(N), work(1), Q(N*N), H(N*N), tmp;
+
+  /* Fill A and Acopy */
+  for (int i = 0; i < N*N; ++i)
+    A[i] = lc.get_01();
+  Acopy = A;
+
+  /* Retrieve lwork */
+  int lwork = -1, info;
+  dgeqrf_(&N, &N, &A[0], &N, &tau[0], &work[0], &lwork, &info);
+  lwork = work[0];
+  work.resize(lwork);
+
+  /* Compute decomposition */
+  dgeqrf_(&N, &N, &A[0], &N, &tau[0], &work[0], &lwork, &info);
+
+  /* Compute Q */
+  for (int i = 0; i < N; ++i)
+    Q[i+i*N] = 1.;
+
+  double alpha, t;
+  const double dZERO = 0., dONE = 1.;
+  const int iONE = 1, N2 = N*N;
+  work.resize(N2);
+  for (int i = 0; i < N; ++i) {
+      /* Generate H_i */
+      for (int r = 0; r < N; ++r)
+        for (int c = 0; c < N; ++c)
+          H[r+c*N] = (r == c);
+      dcopy_(&N, &A[i*N], &iONE, &work[0], &iONE);
+      for (int j = 0; j < i; ++j)
+        work[j] = 0.;
+      work[i] = 1.;
+      t = -tau[i];
+      dger_(&N, &N, &t, &work[0], &iONE, &work[0], &iONE, &H[0], &N);
+
+      /* Multiply Q = Q*H_i */
+      dsymm_("R", "U", &N, &N, &dONE, &H[0], &N, &Q[0], &N, &dZERO, &work[0], &N);
+      dcopy_(&N2, &work[0], &iONE, &Q[0], &iONE);
+  }
+
+  /* Multiply */
+  dtrmm_("R", "U", "N", "N", &N, &N, &dONE, &A[0], &N, &Q[0], &N);
+
+  return diff(Acopy, Q);
+}
+
+#endif /* LAPACK_QR_HH */

diff --git a/accuracy/lapack/lapack_SVD.hh b/accuracy/lapack/lapack_SVD.hh
new file mode 100644
index 0000000..a0a7aae
--- /dev/null
+++ b/accuracy/lapack/lapack_SVD.hh
@@ -0,0 +1,40 @@
+#ifndef LAPACK_SVD_HH
+#define LAPACK_SVD_HH
+
+#include "LinearCongruential.hh"
+#include "diff.hh"
+
+double test_SVD(const int& N, const unsigned& seed = 0)
+{
+  LinearCongruential lc(seed);
+
+  vector<double> A(N*N), Acopy, U(N*N), VT(N*N), S_(N), S(N*N);
+  vector<double> work(1);
+
+  /* Fill A and Acopy */
+  for (int i = 0; i < N*N; ++i)
+    A[i] = lc.get_01();
+  Acopy = A;
+
+  /* Retrieve lwork */
+  int lwork = -1, info;
+  dgesvd_("A", "A", &N, &N, &A[0], &N, &S_[0], &U[0], &N, &VT[0], &N, &work[0], &lwork, &info);
+  lwork = work[0];
+  work.resize(lwork);
+
+  /* Compute decomposition */
+  dgesvd_("A", "A", &N, &N, &A[0], &N, &S_[0], &U[0], &N, &VT[0], &N, &work[0], &lwork, &info);
+
+  /* Construct S */
+  for (int r = 0; r < N; ++r)
+    S[r+r*N] = S_[r];
+
+  /* Test */
+  const double dONE = 1., dZERO = 0.;
+  dgemm_("N", "N", &N, &N, &N, &dONE, &U[0], &N,  &S[0], &N, &dZERO, &A[0], &N);
+  dgemm_("N", "N", &N, &N, &N, &dONE, &A[0], &N, &VT[0], &N, &dZERO, &S[0], &N);
+
+  return diff(Acopy, S);
+}
+
+#endif /* LAPACK_SVD_HH */

diff --git a/accuracy/lapack/lapack_cholesky.hh b/accuracy/lapack/lapack_cholesky.hh
new file mode 100644
index 0000000..daee54e
--- /dev/null
+++ b/accuracy/lapack/lapack_cholesky.hh
@@ -0,0 +1,37 @@
+#ifndef LAPACK_CHOLESKY_HH
+#define LAPACK_CHOLESKY_HH
+
+#include "LinearCongruential.hh"
+#include "diff.hh"
+
+double test_cholesky(const int& N, const unsigned& seed = 0)
+{
+  LinearCongruential lc(seed);
+
+  vector<double> A(N*N), Acopy, test(N*N);
+
+  /* Fill A (SPD), Acopy and test (identity) */
+  for (int r = 0; r < N; ++r) {
+      A[r+r*N] = N;
+      test[r+r*N] = 1.;
+      for (int c = r; c < N; ++c) {
+        A[r+c*N] += lc.get_01();
+        A[c+r*N] = A[r+c*N];
+      }
+  }
+  Acopy = A;
+
+  /* Compute decomposition */
+  int info;
+  dpotrf_("L", &N, &A[0], &N, &info);
+
+  /* Test */
+  const double alpha = 1.;
+  dtrmm_("L", "L", "N", "N", &N, &N, &alpha, &A[0], &N, &test[0], &N);
+  dtrmm_("R", "L", "T", "N", &N, &N, &alpha, &A[0], &N, &test[0], &N);
+
+  return diff(Acopy, test);
+
+}
+
+#endif /* LAPACK_CHOLESKY_HH */

diff --git a/accuracy/lapack/main_lapack.cpp b/accuracy/lapack/main_lapack.cpp
new file mode 100644
index 0000000..ca4fa67
--- /dev/null
+++ b/accuracy/lapack/main_lapack.cpp
@@ -0,0 +1,89 @@
+#include "lapack.hh"
+#include "LinearCongruential.hh"
+#include "timer.hh"
+#include "sizes.hh"
+
+#include <iostream>
+#include <iomanip>
+#include <vector>
+#include <fstream>
+#include <sstream>
+#include <string>
+
+using namespace std;
+
+extern "C" {
+  void daxpy_(const int*, const double*, const double*, const int*, double*, const int*);
+  void dcopy_(const int*, const double*, const int*, double*, const int*);
+  double dnrm2_(const int*, const double*, const int*);
+  void dger_(const int*, const int*, const double*, const double*, const int*, const double*, const int*, double*, const int*);
+  void dgemm_(const char*, const char*, const int*, const int*, const int*, const double*, const double*, const int*, const double*, const int*, const double*, double*, const int*);
+  void dsymm_(const char*, const char*, const int*, const int*, const double*, const double*, const int*, const double*, const int*, const double*, double*, const int*);
+  void dtrmm_(const char*, const char*, const char*, const char*, const int*, const int*, const double*, const double*, const int*, double*, const int*);
+}
+#include "lapack_LU.hh"
+#include "lapack_cholesky.hh"
+#include "lapack_SVD.hh"
+#include "lapack_QR.hh"
+
+template<typename exec_t>
+void test(exec_t exec, const std::string& testname, const int& max = 3000, const int& N = 100)
+{
+  static vector<int> sizes = logsizes(1, max, N);
+  Timer timer;
+
+  ostringstream fname;
+  fname << "accuracy_" << testname << "_lapack.dat";
+  cout << "Testing " << testname << " --> " << fname.str() << endl;
+  ofstream fs(fname.str().c_str());
+
+  for (vector<int>::const_iterator i = sizes.begin(), end = sizes.end(); i != end; ++i) {
+      const int size = *i;
+      double error = 0;
+      timer.start();
+      int times = 0;
+      do
+        error += exec(size, times++);
+      while (timer.elapsed() < 1.);
+      cout << " " << setw(4) << right << size;
+      cout << setw(15) << right << error/times << "    ";
+      cout << "[" << setw(6) << times << " samples]  ";
+      cout << "(" << setw(3) << right << (i-sizes.begin()+1) << "/" << N << ")" << endl;
+      fs << size << " " << error/times << "\n";
+  }
+
+  fs.close();
+}
+
+int main(int argc, char **argv)
+{
+  bool
+  lu_decomp=false, cholesky = false, svd_decomp=false, qr_decomp=false
+  ;
+
+  for (int i = 1; i < argc; ++i) {
+          std::string arg = argv[i];
+          if (arg == "lu_decomp") lu_decomp = true;
+          else if (arg == "cholesky") cholesky = true;
+          else if (arg == "svd_decomp") svd_decomp = true;
+          else if (arg == "qr_decomp") qr_decomp = true;
+  }
+
+  if (lu_decomp) {
+      test(test_LU, "lu_decomp", 3000, 100);
+  }
+
+  if (cholesky) {
+      test(test_cholesky, "cholesky", 3000, 100);
+  }
+
+  if (svd_decomp) {
+      test(test_SVD, "svd_decomp", 1500, 90);
+  }
+
+  if (qr_decomp) {
+      test(test_QR, "qr_decomp", 600, 75);
+  }
+
+  return 0;
+}

diff --git a/accuracy/lapack/timer.hh b/accuracy/lapack/timer.hh
new file mode 100644
index 0000000..7b448fd
--- /dev/null
+++ b/accuracy/lapack/timer.hh
@@ -0,0 +1,50 @@
+#ifndef TIMER_HH
+#define TIMER_HH
+
+#include <sys/time.h>
+
+class Timer
+{
+public:
+  Timer() : ZERO(0.)
+  { }
+
+  void start()
+  {
+    t = walltime(&ZERO);
+  }
+
+  double elapsed()
+  {
+    return walltime(&t);
+  }
+
+private:
+  double t;
+
+  const double ZERO;
+
+  static double walltime(const double *t0)
+  {
+    double mic;
+    double time;
+    double mega = 0.000001;
+    struct timeval tp;
+    struct timezone tzp;
+    static long base_sec = 0;
+    static long base_usec = 0;
+
+    (void) gettimeofday(&tp, &tzp);
+    if (base_sec == 0) {
+      base_sec = tp.tv_sec;
+      base_usec = tp.tv_usec;
+    }
+
+    time = (double) (tp.tv_sec - base_sec);
+    mic = (double) (tp.tv_usec - base_usec);
+    time = (time + mic * mega) - *t0;
+    return (time);
+  }
+};
+
+#endif /* TIMER_HH */

diff --git a/accuracy/sizes.hh b/accuracy/sizes.hh
new file mode 100644
index 0000000..79c9b15
--- /dev/null
+++ b/accuracy/sizes.hh
@@ -0,0 +1,42 @@
+#ifndef SIZES_HH
+#define SIZES_HH
+
+#include <vector>
+#include <cmath>
+
+template<typename T>
+std::vector<T> logspace(const T& min, const T& max, const unsigned& N)
+{
+        std::vector<T> result;
+        result.reserve(N);
+
+        const double emin = std::log(static_cast<double>(min)),
+                     emax = std::log(static_cast<double>(max));
+        double e, r = (emax-emin)/(N-1);
+        for (unsigned i = 0; i < N; ++i) {
+                e = emin + i*r;
+                result.push_back(static_cast<T>(exp(e)));
+        }
+
+        return result;
+}
+
+template<typename T>
+std::vector<T> logsizes(const T& min, const T& max, const unsigned& N)
+{
+        if (N <= 10)
+                return logspace(min, max, N);
+
+        std::vector<T> result;
+        result.reserve(N);
+
+        for (unsigned i = 0; i < 9; ++i)
+                result.push_back(i+1);
+        std::vector<T> lres = logspace(10, max, N-9);
+        for (unsigned i = 9; i < N; ++i)
+                result.push_back(lres[i-9]);
+
+        return result;
+}
+
+#endif /* SIZES_HH */

diff --git a/basemodule.py b/basemodule.py
index 71e2bea..8a1d180 100644
--- a/basemodule.py
+++ b/basemodule.py
@@ -65,7 +65,7 @@ class BaseModule:
         t.files = self.files
         return t
     
-    def save_results(self, results, plottype='plot'):
+    def save_results(self, results, plottype='plot', ylabel="MFlops"):
         if not with_images:
             Print("Report generation skipped - missing libraries")
             return
@@ -119,7 +119,7 @@ class BaseModule:
                 if self.summary_only:
                     plt.legend(loc='best')
                 plt.xlabel('size')
-                plt.ylabel('MFlops')
+                plt.ylabel(ylabel)
                 plt.grid(True)
             fname = pjoin(cfg.reportdir, 'summary.png')
             plt.savefig(fname, format='png', bbox_inches='tight', \
@@ -136,7 +136,7 @@ class BaseModule:
                     plotf(x,y, label=impl, hold=True)
                 plt.legend(loc='best')
                 plt.xlabel('size')
-                plt.ylabel('MFlops')
+                plt.ylabel(ylabel)
                 plt.grid(True)
                 fname = pjoin(cfg.reportdir, test+".png")
                 plt.savefig(fname, format='png', bbox_inches='tight', \

diff --git a/benchconfig.py b/benchconfig.py
index 9ae4ed1..08b404b 100644
--- a/benchconfig.py
+++ b/benchconfig.py
@@ -19,27 +19,27 @@ if needsinitialization:
     scriptdir = os.path.dirname(os.path.realpath(__file__))
     btldir = 'btl'
     
-    # Invariant directories:
-    # roots, tests
-    rootsdir = "/var/tmp/benchmarks/roots/"
-    testsdir = "/var/tmp/benchmarks/tests/"
-    
     # Library directory (lib32 vs. lib64)
     libdir = sp.Popen \
       ('ABI=$(portageq envvar ABI); echo /usr/`portageq envvar LIBDIR_$ABI`/', \
       stdout=sp.PIPE, shell=True).communicate()[0].strip()
     
-    # Packages directory
+    # roots, tests, packages directories -- report, logs base directories
     if isroot:
+        testsdir = "/var/tmp/benchmarks/tests/"
+        rootsdir = "/var/tmp/benchmarks/roots/"
         pkgsdir = "/var/cache/benchmarks/packages/"
+        reportdirb = "/var/cache/benchmarks/reports/"
+        logdirb = "/var/log/benchmarks/"+modname+"_"+time.strftime('%Y-%m-%d')
     else:
+        testsdir = os.environ['HOME'] + "/.benchmarks/tests/"
+        rootsdir = os.environ['HOME'] + "/.benchmarks/roots/"
         pkgsdir = os.environ['HOME'] + "/.benchmarks/packages/"
+        reportdirb = os.environ['HOME'] + "/.benchmarks/reports/"
+        logdirb = pjoin(os.environ['HOME'], ".benchmarks/log",
+                        modname + "_" + time.strftime('%Y-%m-%d'))
     
     # Report directory
-    if isroot:
-        reportdirb = "/var/cache/benchmarks/reports/"
-    else:
-        reportdirb = os.environ['HOME'] + "/.benchmarks/reports/"
     reportdirb += modname + "_" + time.strftime('%Y-%m-%d')
     if os.path.exists(reportdirb):
         n = 1
@@ -53,11 +53,6 @@ if needsinitialization:
     del reportdirb
     
     # Logs directory
-    if isroot:
-        logdirb = "/var/log/benchmarks/"+modname+"_"+time.strftime('%Y-%m-%d')
-    else:
-        logdirb = pjoin(os.environ['HOME'], ".benchmarks/log",
-                        modname + "_" + time.strftime('%Y-%m-%d'))
     if os.path.exists(logdirb):
         n = 1
         while True:

diff --git a/btl/generic_bench/utils/LinearCongruential.hh b/btl/generic_bench/utils/LinearCongruential.hh
index 49b9d12..2ab21ae 100644
--- a/btl/generic_bench/utils/LinearCongruential.hh
+++ b/btl/generic_bench/utils/LinearCongruential.hh
@@ -12,7 +12,7 @@ public:
   LinearCongruential(const int_t& seed) :
     a_(1664525u), c_(1013904223u), m_(getM()), i_(0)
   {
-    buffer_.resize(100);
+    buffer_.resize(4096/sizeof(unsigned));
     fillBuffer(seed);
   }
 

diff --git a/btl/libs/BLAS/blas.h b/btl/libs/BLAS/blas.h
index 67e02e4..25607a5 100644
--- a/btl/libs/BLAS/blas.h
+++ b/btl/libs/BLAS/blas.h
@@ -599,8 +599,8 @@ int BLASFUNC(cgetf2)(int *, int *, float  *, int *, int *, int *);
 int BLASFUNC(zgetf2)(int *, int *, double *, int *, int *, int *);
 int BLASFUNC(xgetf2)(int *, int *, double *, int *, int *, int *);
 
-int BLASFUNC(sgetrf)(int *, int *, float  *, int *, int *, int *);
-int BLASFUNC(dgetrf)(int *, int *, double *, int *, int *, int *);
+//int BLASFUNC(sgetrf)(int *, int *, float  *, int *, int *, int *);
+//int BLASFUNC(dgetrf)(int *, int *, double *, int *, int *, int *);
 int BLASFUNC(qgetrf)(int *, int *, double *, int *, int *, int *);
 int BLASFUNC(cgetrf)(int *, int *, float  *, int *, int *, int *);
 int BLASFUNC(zgetrf)(int *, int *, double *, int *, int *, int *);
@@ -634,8 +634,8 @@ int BLASFUNC(cpotf2)(char *, int *, float  *, int *, int *);
 int BLASFUNC(zpotf2)(char *, int *, double *, int *, int *);
 int BLASFUNC(xpotf2)(char *, int *, double *, int *, int *);
 
-int BLASFUNC(spotrf)(char *, int *, float  *, int *, int *);
-int BLASFUNC(dpotrf)(char *, int *, double *, int *, int *);
+//int BLASFUNC(spotrf)(char *, int *, float  *, int *, int *);
+//int BLASFUNC(dpotrf)(char *, int *, double *, int *, int *);
 int BLASFUNC(qpotrf)(char *, int *, double *, int *, int *);
 int BLASFUNC(cpotrf)(char *, int *, float  *, int *, int *);
 int BLASFUNC(zpotrf)(char *, int *, double *, int *, int *);

diff --git a/btl/libs/LAPACK/lapack.hh b/btl/libs/LAPACK/lapack.hh
new file mode 100644
index 0000000..6b797fb
--- /dev/null
+++ b/btl/libs/LAPACK/lapack.hh
@@ -0,0 +1,16 @@
+#ifndef LAPACK_HH
+#define LAPACK_HH
+
+#define SCALAR        float
+#define SCALAR_PREFIX s
+#include "lapack_.hh"
+#undef SCALAR
+#undef SCALAR_PREFIX
+
+#define SCALAR        double
+#define SCALAR_PREFIX d
+#include "lapack_.hh"
+#undef SCALAR
+#undef SCALAR_PREFIX
+
+#endif /* LAPACK_HH */

diff --git a/btl/libs/LAPACK/lapack_.hh b/btl/libs/LAPACK/lapack_.hh
new file mode 100644
index 0000000..c9d664c
--- /dev/null
+++ b/btl/libs/LAPACK/lapack_.hh
@@ -0,0 +1,19 @@
+#ifndef CAT
+#  define CAT2(A,B) A##B
+#  define CAT(A,B) CAT2(A,B)
+#endif
+#define LAPACKFUNC(NAME) CAT(CAT(SCALAR_PREFIX,NAME),_)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void LAPACKFUNC(getrf)(const int*, const int*, SCALAR*, const int*, int*, int*);
+void LAPACKFUNC(potrf)(const char*, const int*, SCALAR*, const int*, int*);
+void LAPACKFUNC(geqrf)(const int*, const int*, SCALAR*, const int*, SCALAR*, SCALAR*, const int*, int*);
+void LAPACKFUNC(gesvd)(const char*, const char*, const int*, const int*, SCALAR*, const int*, SCALAR*, SCALAR*, const int*, SCALAR*, const int*, SCALAR*, const int*, int*);
+
+#ifdef __cplusplus
+}
+#endif
+

diff --git a/btl/libs/LAPACK/lapack_interface.hh b/btl/libs/LAPACK/lapack_interface.hh
index 1840741..87c45bd 100644
--- a/btl/libs/LAPACK/lapack_interface.hh
+++ b/btl/libs/LAPACK/lapack_interface.hh
@@ -3,6 +3,7 @@
 
 #include <../BLAS/c_interface_base.h>
 #include <complex>
+#include "lapack.hh"
 
 extern "C" {
 #include "../BLAS/blas.h"

diff --git a/lapack_accuracy.py b/lapack_accuracy.py
new file mode 100644
index 0000000..1f062fa
--- /dev/null
+++ b/lapack_accuracy.py
@@ -0,0 +1,149 @@
+import subprocess as sp
+import shlex, os
+from os.path import join as pjoin
+
+from benchutils import mkdir, run_cmd
+from benchprint import Print
+from htmlreport import HTMLreport
+import basemodule
+import benchconfig as cfg
+
+class Module(basemodule.BaseModule):
+    
+    def _initialize(self):
+        self.libname = 'lapack'
+        self.avail=['lu_decomp', 'cholesky', 'svd_decomp', 'qr_decomp']
+    
+    def _parse_args(self, args):     
+        # Parse arguments
+        tests = []
+        for i in args:
+            if i in self.avail:
+                tests.append(i)
+                continue
+            raise Exception("Argument not recognized: " + i)
+        
+        # Sort tests
+        self.tests = [i for i in self.avail if i in tests]
+        
+        # If no test is specified, then do everything
+        if len(self.tests) == 0:
+            self.tests = self.avail
+         
+        # Generate list of dat (result) files, relative to the testdir
+        self.files = [pjoin('accuracy_%s_%s.dat' % (op, self.libname)) \
+          for op in self.tests]
+        
+    @staticmethod
+    def _testClass():
+        return LAPACK_accuracyTest
+
+    
+    def save_results(self, results):
+        basemodule.BaseModule.save_results(self, results, 'plot', \
+          'Relative error')
+            
+class LAPACK_accuracyTest(basemodule.BaseTest):
+    
+    compileenv = {}
+    runenv = {}
+        
+    def _compileTest(self):
+        self.compileenv = {}
+        
+        # Flags and envvars lists
+        includes = [pjoin(self.root, 'usr/include'),
+                    pjoin(cfg.curdir, 'accuracy'),
+                    pjoin(cfg.btldir, 'libs', 'LAPACK'),
+                    pjoin(cfg.btldir, 'generic_bench', 'utils')]
+        libraries = []
+        libdirs = [self.libdir]
+        defines = ['NDEBUG']
+        flags = []
+        
+        ## Interpret flags        
+        for flag in self._get_flags() + \
+          shlex.split(run_cmd(['portageq', 'envvar', 'CXXFLAGS']).strip()):
+            flag = flag.strip()
+            if flag[:2] == '-l':
+                libraries.append(flag[2:])
+            elif flag[:2] == '-L':
+                libdirs.append(flag[2:])
+            elif flag[:2] == '-I':
+                includes.append(flag[2:])
+            else:
+                flags.append(flag)
+        
+        # Set compile environment
+        self.compileenv['INCLUDE_PATH'] = ':'.join(includes)
+        self.compileenv['LIBRARY_PATH'] = ':'.join(libdirs)
+        self.compileenv['LD_LIBRARY_PATH'] = ':'.join(libdirs)
+        self.runenv['LD_LIBRARY_PATH'] = ':'.join(libdirs)
+        
+        exe = pjoin(self.testdir, "test")
+        source = "accuracy/lapack/main_lapack.cpp"
+    
+        # Retrieve compiler
+        cxx = 'g++'
+        cxx_portage = run_cmd(['portageq', 'envvar', 'CXX']).strip()
+        if cxx_portage != '':
+            cxx = cxx_portage
+        if os.environ.has_key('CXX'):
+            cxx = os.environ['CXX']
+        
+        # Form command line arguments
+        args = [cxx, source, '-o', exe]
+        args += ['-I'+I for I in includes]
+        args += ['-l'+l for l in libraries]
+        args += ['-L'+L for L in libdirs]
+        args += ['-D'+D for D in defines]
+        args += flags
+    
+        # Open logfile or redirect to PIPE
+        logfile = file(pjoin(self.logdir, "compile.log"), 'w')
+        logfile.write(' '.join([n+'='+v for n,v in self.compileenv.items()]))
+        logfile.write(' ' + ' '.join(args) + '\n' + 80*'-' + '\n')
+        logfile.flush()
+        
+        # Execute
+        proc=sp.Popen(args,stdout=logfile,stderr=sp.STDOUT,env=self.compileenv)
+        proc.wait()
+        
+        # Close, return
+        logfile.close()
+        return proc.returncode, exe, logfile.name
+    
+    
+    def _executeTest(self, exe):
+        # Log dynamic link
+        lddlogfile = file(pjoin(self.logdir, 'ldd.log'), 'w')
+        sp.Popen(['ldd', '-v', exe], stdout=lddlogfile, env=self.runenv).wait()
+        
+        # Open pipe
+        logfile = file(pjoin(self.logdir, 'run.log'), 'w')
+        args = [exe] + self.tests
+        logfile.write(' '.join([n+'='+v for n,v in self.runenv.items()]) + ' ')
+        logfile.write(' '.join(args) + '\n')
+        logfile.write(80*'-' + '\n')
+        proc = sp.Popen(args, bufsize=1, stdout=sp.PIPE, stderr=sp.PIPE, 
+          env=self.runenv, cwd=self.testdir)
+        
+        # Interpret output
+        Print.down()
+        while True:
+            line = proc.stdout.readline()
+            if not line:
+                break
+            logfile.write(line)
+            if len(line.strip()) == 0:
+                continue
+            if line[0] != ' ':
+                Print.up()
+                Print(line.strip())
+                Print.down()
+            else:
+                Print(line[1:-1])
+        Print.up()          
+        logfile.close()      
+        proc.wait()
+        return proc.returncode

diff --git a/testdescr.py b/testdescr.py
index ae63578..a6f0fe4 100644
--- a/testdescr.py
+++ b/testdescr.py
@@ -19,6 +19,8 @@ testdescr = {
 'least_squares': 'Least squares solution',
 'lu_decomp': 'LU-decomposition',
 'cholesky': 'Cholesky decomposition',
+'svd_decomp': 'SVD-decomposition',
+'qr_decomp': 'QR-decomposition',
 'symm_ev': 'Symmetric Eigenvalue computation',
 
 # FFTW



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-05  1:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-05  1:28 [gentoo-commits] proj/auto-numerical-bench:unstable commit in: accuracy/, /, accuracy/lapack/, btl/libs/BLAS/, btl/generic_bench/utils/, Andrea Arteaga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox