From 570aa2e905ea421d6be6232ae6ba89a8d0127bbf Mon Sep 17 00:00:00 2001 From: minwang Date: Wed, 6 Nov 2013 14:39:25 +0800 Subject: GPU Calc: implemented for DB AMLOEXT-132 FIX Change-Id: Ia468999f2d182fab62a8229362dfe2ebbe949654 Signed-off-by: haochen Signed-off-by: I-Jui (Ray) Sung --- sc/source/core/opencl/formulagroupcl.cxx | 4 ++ sc/source/core/opencl/op_financial.cxx | 115 ++++++++++++++++++++++++++++++- sc/source/core/opencl/op_financial.hxx | 7 ++ 3 files changed, 125 insertions(+), 1 deletion(-) (limited to 'sc') 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(tmpCur0); + FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken(); + const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast(tmpCur1); + FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken(); + const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast(tmpCur2); + FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken(); + const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast(tmpCur3); + FormulaToken* tmpCur4 = vSubArguments[4]->GetFormulaToken(); + const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast(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 <GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nWert = 0;\n else\n"; +#endif + ss <<" nWert = "<GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_rest_len || isNan("; + ss <GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nRest = 0;\n else\n"; +#endif + ss <<" nRest = "; + ss <GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_dauer_len || isNan("; + ss <GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nDauer = 0;\n else\n"; +#endif + ss <<" nDauer = "<GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_periode_len || isNan("; + ss <GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nPeriode = 0;\n else\n"; +#endif + ss <<" nPeriode = "<GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_nMonate_len || isNan("; + ss <GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nMonate = 0;\n else\n"; +#endif + ss <<" nMonate = (int)"<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: -- cgit