summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorXukai Liu <xukai@multicorewareinc.com>2013-10-31 20:20:37 -0500
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-10-31 20:24:48 -0500
commit7abfae3622fc952ecac8ebacb1d70650ef773619 (patch)
tree4b7172e421f712782d0b011b1ad180085c6f14ce /sc
parent2ee41f402fdea5bed8076295ae3e94c79f92bd64 (diff)
GPU Calc: refactor code generation for inlined library routines
Refactored two library functions: Round and approxEqual. Generate them only when corresponding Calc spreadsheet functions are used. Change-Id: Ibf532d551ba0d99a117cedd4a0f3397acb5e017d Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx21
-rw-r--r--sc/source/core/opencl/formulagroupcl_finacial.hxx31
-rw-r--r--sc/source/core/opencl/op_financial.cxx9
-rw-r--r--sc/source/core/opencl/op_financial.hxx1
-rw-r--r--sc/source/core/opencl/opbase.hxx6
-rw-r--r--sc/source/core/opencl/opinlinefun_finacial.cxx53
6 files changed, 89 insertions, 32 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index c40c2894fd39..2dfc0cf65b59 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -823,6 +823,13 @@ public:
t = t + mvSubArguments[i]->DumpOpName();
return t;
}
+ virtual void DumpInlineFun(std::set<std::string>& decls,
+ std::set<std::string>& funs) const
+ {
+ mpCodeGen->BinInlineFun(decls,funs);
+ for (unsigned i = 0; i < mvSubArguments.size(); i++)
+ mvSubArguments[i]->DumpInlineFun(decls,funs);
+ }
private:
SubArgumentsType mvSubArguments;
boost::scoped_ptr<SlidingFunctionBase> mpCodeGen;
@@ -1181,6 +1188,18 @@ public:
// preambles
decl << publicFunc;
decl << finacialFunc;
+ DK->DumpInlineFun(inlineDecl,inlineFun);
+ for(std::set<std::string>::iterator set_iter=inlineDecl.begin();
+ set_iter!=inlineDecl.end();set_iter++)
+ {
+ decl<<*set_iter;
+ }
+
+ for(std::set<std::string>::iterator set_iter=inlineFun.begin();
+ set_iter!=inlineFun.end();set_iter++)
+ {
+ decl<<*set_iter;
+ }
mSyms.DumpSlidingWindowFunctions(decl);
mKernelSignature = DK->DumpOpName();
decl << "__kernel void DynamicKernel" << mKernelSignature;
@@ -1255,6 +1274,8 @@ private:
cl_program mpProgram;
cl_kernel mpKernel;
cl_mem mpResClmem; // Results
+ std::set<std::string> inlineDecl;
+ std::set<std::string> inlineFun;
};
DynamicKernel::~DynamicKernel()
diff --git a/sc/source/core/opencl/formulagroupcl_finacial.hxx b/sc/source/core/opencl/formulagroupcl_finacial.hxx
index a8db8e94ed61..da09168ff7f1 100644
--- a/sc/source/core/opencl/formulagroupcl_finacial.hxx
+++ b/sc/source/core/opencl/formulagroupcl_finacial.hxx
@@ -9,38 +9,7 @@
#ifndef SC_OPENCL_FORMULAGROUPCL_FINACIAL_HXX
#define SC_OPENCL_FORMULAGROUPCL_FINACIAL_HXX
-
const char* finacialFunc =
-"bool approxEqual(double a, double b)\n"
-"{\n"
- "\tif (a == b)\n"
- "\t\treturn true;\n"
- "\tdouble x = a - b;\n"
- "\treturn (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 *"
- "16777216.0)));\n"
-"}\n"
-"double constant nKorrVal[] = {0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, "
-"9e-8,9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15};\n"
-"constant double SCdEpsilon = 1.0E-7;\n"
-"double Round(double fValue)\n"
-"{\n"
- "\tif (fValue == 0.0)\n"
- "\t\treturn fValue;\n"
- "\tdouble fFac = 0;\n"
- "\tint nExp;\n"
- "\tif (fValue > 0.0)\n"
- "\t\tnExp = (floor(log10(fValue)));\n"
- "\telse\n"
- "\t\tnExp = 0;\n"
- "\tint nIndex = 15 - nExp;\n"
- "\tif (nIndex > 15)\n"
- "\t\tnIndex = 15;\n"
- "\telse if (nIndex <= 1)\n"
- "\t\tnIndex = 0;\n"
- "\tfValue = floor(fValue + 0.5 + nKorrVal[nIndex]);\n"
- "\treturn fValue;\n"
-"}\n"
-"void RateIteration(){\n\tdouble tmp = Round(3.0);\n\treturn;\n}\n"
"double GetRmz( double fZins, double fZzr, double fBw, double fZw, int nF )\n"
"{\n"
"\tdouble fRmz;\n"
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 5ae04ff3d625..da4845ca1cc0 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -21,6 +21,8 @@
using namespace formula;
namespace sc { namespace opencl {
+// Definitions of inline functions
+#include "opinlinefun_finacial.cxx"
void RRI::GenSlidingWindowFunction(
std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
@@ -2513,6 +2515,13 @@ void OpTbillprice::GenSlidingWindowFunction(
ss << "return tmp;\n";
ss << "}\n";
}
+ void RATE::BinInlineFun(std::set<std::string>& decls,
+ std::set<std::string>& funs)
+{
+ decls.insert(approxEqualDecl);decls.insert(nKorrValDecl);
+ decls.insert(SCdEpsilonDecl);decls.insert(RoundDecl);
+ funs.insert(approxEqual);funs.insert(Round);
+}
void RATE::GenSlidingWindowFunction(
std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index bb85b865e390..544d757c023f 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -309,6 +309,7 @@ class RATE: public Normal
public:
virtual void GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments);
+ virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& );
};
class OpIntrate: public RATE {
public:
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index c4200752f0a6..11f0c7fc4706 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -16,7 +16,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/noncopyable.hpp>
-
+#include <set>
#define ISNAN
namespace sc { namespace opencl {
@@ -101,6 +101,8 @@ public:
formula::FormulaToken *GetFormulaToken(void) const;
virtual size_t GetWindowSize(void) const;
virtual std::string DumpOpName(void) const { return std::string(""); }
+ virtual void DumpInlineFun(std::set<std::string>& ,
+ std::set<std::string>& ) const {}
const std::string& GetName(void) const { return mSymName; }
protected:
const std::string mSymName;
@@ -121,6 +123,8 @@ public:
const std::string &/*rhs*/) const {return "";}
virtual std::string Gen(ArgVector& /*argVector*/){return "";};
virtual std::string BinFuncName(void)const {return "";};
+ virtual void BinInlineFun(std::set<std::string>& ,
+ std::set<std::string>& ) {}
virtual bool takeString() const = 0;
virtual bool takeNumeric() const = 0;
virtual ~OpBase() {}
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
new file mode 100644
index 000000000000..bb5d3f2fccf6
--- /dev/null
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef SC_OPENCL_OPINLINFUN_finacial
+#define SC_OPENCL_OPINLINFUN_finacial
+std::string approxEqualDecl="bool approxEqual(double a, double b);\n";
+std::string approxEqual =
+"bool approxEqual(double a, double b)\n"
+"{\n"
+ "\tif (a == b)\n"
+ "\t\treturn true;\n"
+ "\tdouble x = a - b;\n"
+ "\treturn (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 *"
+ "16777216.0)));\n"
+"}\n";
+
+std::string nKorrValDecl ="double constant nKorrVal[]"
+"= {0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, "
+"9e-8,9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15};\n";
+
+std::string SCdEpsilonDecl =
+"constant double SCdEpsilon = 1.0E-7;\n";
+
+std::string RoundDecl = "double Round(double fValue);\n";
+
+std::string Round =
+"double Round(double fValue)\n"
+"{\n"
+ "\tif (fValue == 0.0)\n"
+ "\t\treturn fValue;\n"
+ "\tdouble fFac = 0;\n"
+ "\tint nExp;\n"
+ "\tif (fValue > 0.0)\n"
+ "\t\tnExp = (floor(log10(fValue)));\n"
+ "\telse\n"
+ "\t\tnExp = 0;\n"
+ "\tint nIndex = 15 - nExp;\n"
+ "\tif (nIndex > 15)\n"
+ "\t\tnIndex = 15;\n"
+ "\telse if (nIndex <= 1)\n"
+ "\t\tnIndex = 0;\n"
+ "\tfValue = floor(fValue + 0.5 + nKorrVal[nIndex]);\n"
+ "\treturn fValue;\n"
+"}\n";
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */