summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxinjiang <xinjiang@multicorewareinc.com>2013-11-06 12:35:21 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-13 14:39:19 -0600
commite2e1a878c6010820f4371dbb28198fa79cab74cc (patch)
treeba64ea88ec520db9f0fc98eade64a1d8e1bccf64
parentaff86baf272ffeaec901cb70f73df4592f341896 (diff)
GPU Calc: implemented for IPMT
AMLOEXT-134 FIX Change-Id: I5b5c9c484d7d1b585d0bd20f5a08ef033701e08e Signed-off-by: haochen <haochen@multicorewareinc.com> Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx4
-rw-r--r--sc/source/core/opencl/op_financial.cxx78
-rw-r--r--sc/source/core/opencl/op_financial.hxx14
3 files changed, 96 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 5feaecfd88a9..e8738a067bac 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1124,6 +1124,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpPhi));
break;
+ case ocZinsZ:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i],new OpIPMT));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 24d7981bace2..a1c82d21970e 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -537,6 +537,84 @@ void OpFV::GenSlidingWindowFunction(std::stringstream& ss,
ss << " return tmp;\n";
ss << "}";
}
+
+void OpIPMT::BinInlineFun(std::set<std::string>& decls,
+ std::set<std::string>& funs)
+{
+ decls.insert(GetZwDecl);
+ funs.insert(GetZw);
+}
+
+void OpIPMT::GenSlidingWindowFunction(std::stringstream& ss,
+ const std::string sSymName, SubArguments& vSubArguments)
+{
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ") {\n";
+ ss << " double tmp = " << GetBottom() << ";\n";
+ ss << " int gid0 = get_global_id(0);\n";
+ ss << " double arg0 = " << GetBottom() << ";\n";
+ ss << " double arg1 = " << GetBottom() << ";\n";
+ ss << " double arg2 = " << GetBottom() << ";\n";
+ ss << " double arg3 = " << GetBottom() << ";\n";
+ ss << " double arg4 = " << GetBottom() << ";\n";
+ ss << " double arg5 = " << GetBottom() << ";\n";
+ unsigned j = vSubArguments.size();
+ while (j--)
+ {
+ FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
+ assert(pCur);
+ if(pCur->GetType() == formula::svSingleVectorRef)
+ {
+#ifdef ISNAN
+ const formula::SingleVectorRefToken* pSVR =
+ dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+ ss << " if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
+ ss << vSubArguments[j]->GenSlidingWindowDeclRef();
+ ss << "))\n";
+ ss << " arg" << j << " = " <<GetBottom() << ";\n";
+ ss << " else\n";
+#endif
+ ss << " arg" << j << " = ";
+ ss << vSubArguments[j]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+ }
+ }
+ ss << " double pmt ;\n";
+ ss << " if(arg0 == 0.0)\n";
+ ss << " return 0;\n";
+ ss << " double temp1 = 0;\n";
+ ss << " double abl = pow(1.0 + arg0, arg2);\n";
+ ss << " temp1 -= arg4;\n";
+ ss << " temp1 -= arg3 * abl;\n";
+ ss << " pmt = temp1 / (1.0 + arg0 * arg5) /";
+ ss << " ( (abl - 1.0) / arg0);\n";
+ ss << " double temp = pow( 1 + arg0, arg1 - 2);\n";
+ ss << " if(arg1 == 1.0)\n";
+ ss << " {\n";
+ ss << " if(arg5 > 0.0)\n";
+ ss << " tmp = 0.0;\n";
+ ss << " else\n";
+ ss << " tmp = -arg3;\n";
+ ss << " }\n";
+ ss << " else\n";
+ ss << " {\n";
+ ss << " if(arg5 > 0.0)\n";
+ ss << " tmp = GetZw(arg0, arg1 - 2.0, pmt, arg3, 1.0)";
+ ss << " - pmt;\n";
+ ss << " else\n";
+ ss << " tmp = GetZw(arg0, arg1 - 1.0, pmt, arg3, 0.0);\n";
+ ss << " }\n";
+ ss << " tmp = tmp * arg0;\n";
+ ss << " return tmp;\n";
+ ss << "}";
+}
void OpISPMT::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 4283dd917f31..423eefd1b51c 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -100,6 +100,20 @@ public:
return "FV"; }
};
+class OpIPMT: public Normal
+{
+public:
+ virtual std::string GetBottom(void) { return "0"; }
+
+ virtual void GenSlidingWindowFunction(std::stringstream& ss,
+ const std::string sSymName, SubArguments& vSubArguments);
+ virtual void BinInlineFun(std::set<std::string>& ,
+ std::set<std::string>& );
+
+ virtual std::string BinFuncName(void) const {
+ return "IPMT"; }
+};
+
class OpISPMT: public Normal
{
public: