summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Arteaga <andyspiros@gmail.com>2012-09-27 13:36:42 +0200
committerAndrea Arteaga <andyspiros@gmail.com>2012-09-27 13:36:42 +0200
commitc021ab0695f7511c4079a55f2eb1f1d828adabdc (patch)
treef0e8b7ee6efdd0d8283512bf618f78434e1380d1
parentAdded initial support for copying the reports at the end (working for (diff)
downloadauto-numerical-bench-c021ab0695f7511c4079a55f2eb1f1d828adabdc.tar.gz
auto-numerical-bench-c021ab0695f7511c4079a55f2eb1f1d828adabdc.tar.bz2
auto-numerical-bench-c021ab0695f7511c4079a55f2eb1f1d828adabdc.zip
Initial import of the new interfaces.
-rw-r--r--NumericInterface/NI_internal/CDeclarations.hpp52
-rw-r--r--NumericInterface/NI_internal/CInterface.hpp50
-rw-r--r--NumericInterface/NI_internal/FortranDeclarations.hpp60
-rw-r--r--NumericInterface/NI_internal/FortranInterface.hpp112
-rw-r--r--NumericInterface/NI_internal/utils.hpp29
-rw-r--r--NumericInterface/NumericInterface.hpp64
6 files changed, 367 insertions, 0 deletions
diff --git a/NumericInterface/NI_internal/CDeclarations.hpp b/NumericInterface/NI_internal/CDeclarations.hpp
new file mode 100644
index 0000000..0109559
--- /dev/null
+++ b/NumericInterface/NI_internal/CDeclarations.hpp
@@ -0,0 +1,52 @@
+//=====================================================
+// Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com>
+//=====================================================
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+#ifndef CDECLARATIONS_HPP_
+#define CDECLARATIONS_HPP_
+
+
+// Cblas constants
+const int CblasRowMajor = 101;
+const int CblasColMajor = 102;
+
+const int CblasNoTrans = 111;
+const int CblasTrans = 112;
+const int CblasConjTrans = 113;
+const int AtlasConj = 114;
+
+const int CblasUpper = 121;
+const int CblasLower = 122;
+
+const int CblasNonUnit = 131;
+const int CblasUnit = 132;
+
+const int CblasLeft = 141;
+const int CblasRight = 142;
+
+
+// Cblas functions
+extern "C" {
+ void cblas_sgemv(int, int, int, int, float, const float*, int,
+ const float*, int, float, float*, int);
+
+ void cblas_dgemv(int, int, int, int, double, const double*, int,
+ const double*, int, double, double*, int);
+
+}
+
+
+#endif /* CDECLARATIONS_HPP_ */
diff --git a/NumericInterface/NI_internal/CInterface.hpp b/NumericInterface/NI_internal/CInterface.hpp
new file mode 100644
index 0000000..a067144
--- /dev/null
+++ b/NumericInterface/NI_internal/CInterface.hpp
@@ -0,0 +1,50 @@
+//=====================================================
+// Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com>
+//=====================================================
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+/* Check whether we are included by NumeriInterface.hpp or not */
+#ifndef NI_INCLUDE_OK
+# error CInterface.hpp should never be included directly: include NumericInterface.hpp instead!
+#endif
+
+#define CBLASFUNC(F) CAT(cblas_, CAT(NI_SCALARPREFIX, F))
+
+template<>
+class NumericInterface<NI_SCALAR>
+{
+public:
+ typedef NI_SCALAR Scalar;
+
+public:
+ static std::string name()
+ {
+ std::string name = "CInterface<";
+ name += MAKE_STRING(NI_SCALAR);
+ name += ">";
+ return name;
+ }
+
+
+ static void matrixVector(
+ const int& M, const int& N, const Scalar& alpha, const Scalar* A,
+ const Scalar* x, const Scalar& beta, Scalar* y
+ )
+ {
+ CBLASFUNC(gemv)(CblasColMajor, CblasNoTrans, M, N, alpha, A, M,
+ x, 1, beta, y, 1);
+ }
+};
diff --git a/NumericInterface/NI_internal/FortranDeclarations.hpp b/NumericInterface/NI_internal/FortranDeclarations.hpp
new file mode 100644
index 0000000..fce99d2
--- /dev/null
+++ b/NumericInterface/NI_internal/FortranDeclarations.hpp
@@ -0,0 +1,60 @@
+//=====================================================
+// Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com>
+//=====================================================
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+#ifndef FORTRANDECLARATIONS_HPP_
+#define FORTRANDECLARATIONS_HPP_
+
+extern "C" {
+
+
+
+ /****************
+ * LEVEL 1 BLAS *
+ ****************/
+
+ void srot_(const int*, float*, const int*, float*, const int*, const float*, const float*);
+ void drot_(const int*, double*, const int*, double*, const int*, const double*, const double*);
+
+ void saxpy_(const int*, const float*, const float*, const int*, float*, const int*);
+ void daxpy_(const int*, const double*, const double*, const int*, double*, const int*);
+
+ float sdot_(const int*, const float*, const int*, const float*, const int*);
+ double ddot_(const int*, const double*, const int*, const double*, const int*);
+
+ float snrm2_(const int*, const float*, const int*);
+ double dnrm2_(const int*, const double*, const int*);
+
+
+
+
+ /****************
+ * LEVEL 2 BLAS *
+ ****************/
+
+ void sgemv_(const char*, const int*, const int*, const float*, const float*, const int*, const float*, const int*, const float*, const float*, const int*);
+ void dgemv_(const char*, const int*, const int*, const double*, const double*, const int*, const double*, const int*, const double*, const double*, const int*);
+
+ void strsv_(const char*, const char*, const char*, const int*, const float*, const int*, float*, const int*);
+ void dtrsv_(const char*, const char*, const char*, const int*, const double*, const int*, double*, const int*);
+
+ void sger_(const int*, const int*, const float*, const float*, const int*, const float*, const int*, const float*, const int*);
+ void dger_(const int*, const int*, const double*, const double*, const int*, const double*, const int*, const double*, const int*);
+}
+
+
+#endif /* FORTRANDECLARATIONS_HPP_ */
+
diff --git a/NumericInterface/NI_internal/FortranInterface.hpp b/NumericInterface/NI_internal/FortranInterface.hpp
new file mode 100644
index 0000000..0bdcf89
--- /dev/null
+++ b/NumericInterface/NI_internal/FortranInterface.hpp
@@ -0,0 +1,112 @@
+//=====================================================
+// Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com>
+//=====================================================
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+
+/* Check whether we are included by NumeriInterface.hpp or not */
+#ifndef NI_INCLUDE_OK
+# error FortranInterface.hpp should never be included directly: include NumericInterface.hpp instead!
+#endif
+
+
+#define FORTFUNC(F) CAT(CAT(NI_SCALARPREFIX, F), _)
+
+
+template<>
+class NumericInterface<NI_SCALAR>
+{
+public:
+ typedef NI_SCALAR Scalar;
+
+ static const int ZERO;
+ static const int ONE;
+
+public:
+ static std::string name()
+ {
+ std::string name = "FortranInterface<";
+ name += MAKE_STRING(NI_SCALAR);
+ name += ">";
+ return name;
+ }
+
+
+
+ /****************
+ * LEVEL 1 BLAS *
+ ****************/
+
+ static void rot(const int& N, Scalar* x, Scalar* y,
+ const Scalar& cosine, const Scalar& sine)
+ {
+ FORTFUNC(rot)(&N, x, &ONE, y, &ONE, &cosine, &sine);
+ }
+
+
+ static void axpy(const int& N, const Scalar& alpha,
+ const Scalar* x, Scalar* y)
+ {
+ FORTFUNC(axpy)(&N, &alpha, x, &ONE, y, &ONE);
+ }
+
+ static Scalar dot(const int& N, const Scalar* x, const Scalar* y)
+ {
+ return FORTFUNC(dot)(&N, x, &ONE, y, &ONE);
+ }
+
+ static Scalar norm(const int& N, const Scalar* x)
+ {
+ return FORTFUNC(nrm2)(&N, x, &ONE);
+ }
+
+
+
+ /****************
+ * LEVEL 2 BLAS *
+ ****************/
+
+ static void matrixVector(const char& trans, const int& M, const int& N,
+ const Scalar& alpha, const Scalar* A, const Scalar* x,
+ const Scalar& beta, Scalar* y)
+ {
+ FORTFUNC(gemv)(&trans, &M, &N, &alpha, A, &M, x, &ONE, &beta, y, &ONE);
+ }
+
+ static void triangularSolveVector(const char& uplo, const char& diag,
+ const int& N, const Scalar* A, Scalar* x)
+ {
+ FORTFUNC(trsv)(&uplo, "N", &diag, &N, A, &N, x, &ONE);
+ }
+
+ static void rank1update(const int& M, const int& N, const Scalar& alpha,
+ const Scalar* x, const Scalar* y, Scalar* A)
+ {
+ FORTFUNC(ger)(&M, &N, &alpha, x, &ONE, y, &ONE, A, &M);
+ }
+};
+
+const int NumericInterface<NI_SCALAR>::ZERO = 0;
+const int NumericInterface<NI_SCALAR>::ONE = 1;
+
+
+
+
+
+
+
+
+
+
diff --git a/NumericInterface/NI_internal/utils.hpp b/NumericInterface/NI_internal/utils.hpp
new file mode 100644
index 0000000..56e8177
--- /dev/null
+++ b/NumericInterface/NI_internal/utils.hpp
@@ -0,0 +1,29 @@
+//=====================================================
+// Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com>
+//=====================================================
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+#ifndef UTILS_HPP_
+#define UTILS_HPP_
+
+#define MAKE_STRING2(S) #S
+#define MAKE_STRING(S) MAKE_STRING2(S)
+
+#define CAT2(A,B) A##B
+#define CAT(A,B) CAT2(A,B)
+
+
+
+#endif /* UTILS_HPP_ */
diff --git a/NumericInterface/NumericInterface.hpp b/NumericInterface/NumericInterface.hpp
new file mode 100644
index 0000000..73df532
--- /dev/null
+++ b/NumericInterface/NumericInterface.hpp
@@ -0,0 +1,64 @@
+//=====================================================
+// Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com>
+//=====================================================
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+#ifndef NUMERICINTERFACE_HPP_
+#define NUMERICINTERFACE_HPP_
+
+#include "NI_internal/utils.hpp"
+#include <string>
+
+template<class Scalar> class NumericInterface;
+
+#define NI_INCLUDE_OK
+
+#ifdef NI_FORTRAN
+#
+# include "NI_internal/FortranDeclarations.hpp"
+#
+# define NI_SCALAR double
+# define NI_SCALARPREFIX d
+# include "NI_internal/FortranInterface.hpp"
+# undef NI_SCALAR
+# undef NI_SCALARPREFIX
+#
+# define NI_SCALAR float
+# define NI_SCALARPREFIX s
+# include "NI_internal/FortranInterface.hpp"
+# undef NI_SCALAR
+# undef NI_SCALARPREFIX
+#
+#else
+# include "NI_internal/CDeclarations.hpp"
+#
+# define NI_SCALAR double
+# define NI_SCALARPREFIX d
+# include "NI_internal/CInterface.hpp"
+# undef NI_SCALAR
+# undef NI_SCALARPREFIX
+#
+# define NI_SCALAR float
+# define NI_SCALARPREFIX s
+# include "NI_internal/CInterface.hpp"
+# undef NI_SCALAR
+# undef NI_SCALARPREFIX
+#
+#endif
+
+#undef NI_INCLUDE_OK
+
+
+#endif /* NUMERICINTERFACE_HPP_ */