summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorminwang <min@multicorewareinc.com>2013-11-06 14:39:25 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-13 14:39:23 -0600
commit570aa2e905ea421d6be6232ae6ba89a8d0127bbf (patch)
treeb29701b9821cc8b8640b5b75d44886041d8aed60 /sc
parent76451b69743b0c50ed0f7ab4cc64bd51656aa30d (diff)
GPU Calc: implemented for DB
AMLOEXT-132 FIX Change-Id: Ia468999f2d182fab62a8229362dfe2ebbe949654 Signed-off-by: haochen <haochen@multicorewareinc.com> Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx4
-rw-r--r--sc/source/core/opencl/op_financial.cxx115
-rw-r--r--sc/source/core/opencl/op_financial.hxx7
3 files changed, 125 insertions, 1 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index bf4b234c7a9f..d5e296534484 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1136,6 +1136,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpIntercept));
break;
+ case ocGDA2:
+ mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
+ new OpDB));
+ 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 7643c0dc8225..829ad49ae3a5 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -4966,7 +4966,120 @@ void OpXirr::GenSlidingWindowFunction(std::stringstream &ss,
}
}
-
+void OpDB::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 << " int gid0 = get_global_id(0);\n";
+ ss << " double nWert,nRest,nDauer,nPeriode;\n";
+ ss << " int nMonate;\n";
+ ss << " double tmp = 0;\n";
+#ifdef ISNAN
+ FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+ FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+ FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur4);
+ ss<< " int buffer_wert_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n";
+ ss<< " int buffer_rest_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n";
+ ss<< " int buffer_dauer_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n";
+ ss<< " int buffer_periode_len = ";
+ ss<< tmpCurDVR3->GetArrayLength();
+ ss << ";\n";
+ ss<< " int buffer_nMonate_len = ";
+ ss<< tmpCurDVR4->GetArrayLength();
+ ss << ";\n";
+#endif
+#ifdef ISNAN
+ ss <<" if(gid0 >= buffer_wert_len || isNan(";
+ ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" nWert = 0;\n else\n";
+#endif
+ ss <<" nWert = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+#ifdef ISNAN
+ ss <<" if(gid0 >= buffer_rest_len || isNan(";
+ ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" nRest = 0;\n else\n";
+#endif
+ ss <<" nRest = ";
+ ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+#ifdef ISNAN
+ ss <<" if(gid0 >= buffer_dauer_len || isNan(";
+ ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" nDauer = 0;\n else\n";
+#endif
+ ss <<" nDauer = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+#ifdef ISNAN
+ ss <<" if(gid0 >= buffer_periode_len || isNan(";
+ ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" nPeriode = 0;\n else\n";
+#endif
+ ss <<" nPeriode = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+#ifdef ISNAN
+ ss <<" if(gid0 >= buffer_nMonate_len || isNan(";
+ ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" nMonate = 0;\n else\n";
+#endif
+ ss <<" nMonate = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+ ss <<" double nAbRate = 1.0 - pow(nRest / nWert, 1.0 / nDauer);\n";
+ ss <<" nAbRate = ((int)(nAbRate * 1000.0 + 0.5)) / 1000.0;\n";
+ ss <<" double nErsteAbRate = nWert * nAbRate * nMonate / 12.0;\n";
+ ss <<" double nGda2 = 0.0;\n";
+ ss <<" if ((int)(nPeriode) == 1)\n";
+ ss <<" nGda2 = nErsteAbRate;\n";
+ ss <<" else\n";
+ ss <<" {\n";
+ ss <<" double nSummAbRate = nErsteAbRate;\n";
+ ss <<" double nMin = nDauer;\n";
+ ss <<" if (nMin > nPeriode) nMin = nPeriode;\n";
+ ss <<" int iMax = (int)nMin;\n";
+ ss <<" for (int i = 2; i <= iMax; i++)\n";
+ ss <<" {\n";
+ ss <<" nGda2 = (nWert - nSummAbRate) * nAbRate;\n";
+ ss <<" nSummAbRate += nGda2;\n";
+ ss <<" }\n";
+ ss <<" if (nPeriode > nDauer)\n";
+ ss <<" nGda2 = ((nWert - nSummAbRate)";
+ ss <<"* nAbRate * (12.0 - nMonate)) / 12.0;\n";
+ ss <<" }\n";
+ ss <<" tmp = nGda2;\n";
+ ss <<" return tmp;\n";
+ ss <<"}";
+}
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index 1843fcf00226..411823667d45 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -428,7 +428,14 @@ public:
virtual std::string BinFuncName(void) const { return "DDB"; }
};
+class OpDB:public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "DB"; }
+};
class OpAmordegrc:public Normal
{
public: