diff options
author | yiming ju <yiming@multicorewareinc.com> | 2013-11-05 15:20:52 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-11-13 00:45:01 -0600 |
commit | dfcf4a80bd15ebf5e740a16b5a00994d6ff5f414 (patch) | |
tree | 37f991f10166dc42f1b92684d8aabd3ea9e2854e | |
parent | 29d038548c5c507e16483296d860b8f8beaa8082 (diff) |
GPU Calc: implemented for VDB
AMLOEXT-133 FIX
Change-Id: I8147c2626131800d9c0075fee8dfdfd70b5bef5c
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.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/opencl/op_financial.cxx | 50 | ||||
-rw-r--r-- | sc/source/core/opencl/op_financial.hxx | 9 | ||||
-rw-r--r-- | sc/source/core/opencl/opinlinefun_finacial.cxx | 136 |
4 files changed, 199 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 166d02b4262b..b56ea0f0d378 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1068,6 +1068,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],new OpSumIfs)); break; + case ocVBD: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i],new OpVDB)); + 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 30d4c85d4d7a..ccebf0366dd4 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -4135,7 +4135,57 @@ tmpCur4); ss << " return -result;\n"; ss << "}"; } + void OpVDB::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(ScGetGDADecl);decls.insert(DblMinDecl); + decls.insert(ScInterVDBDecl);decls.insert(VDBImplementDecl); + funs.insert(ScGetGDA);funs.insert(DblMin); + funs.insert(ScInterVDB);funs.insert(VDBImplement); +} + +void OpVDB::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 << " int singleIndex = gid0;\n"; + ss << " double result = 0;\n"; + if(vSubArguments.size()<5) + { + ss << " result = -DBL_MAX;\n"; + ss << " return result;\n"; + }else + { + GenTmpVariables(ss,vSubArguments); + CheckAllSubArgumentIsNan(ss,vSubArguments); + if(vSubArguments.size() <= 6) + { + ss << " int tmp6 = 0;\n"; + } + if(vSubArguments.size() == 5) + { + ss << " double tmp5= 2.0;\n"; + } + ss << " if(tmp3 < 0 || tmp4<tmp3 || tmp4>tmp2 || tmp0<0 ||tmp1>tmp0"; + ss << "|| tmp5 <=0)\n"; + ss << " result = -DBL_MAX;\n"; + ss << " else\n"; + ss << " result ="; + ss << "VDBImplement(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n"; + ss << " return result;\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 3a1350aa5611..a24db10769c1 100644 --- a/sc/source/core/opencl/op_financial.hxx +++ b/sc/source/core/opencl/op_financial.hxx @@ -465,6 +465,15 @@ public: virtual std::string BinFuncName(void) const { return "PV"; } }; +class OpVDB: public CheckVariables +{ +public: + virtual void GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments); + + virtual std::string BinFuncName(void) const { return "VDB"; } + virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& ); +}; }} #endif diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx index 86f93eb5bde9..7770458c0d61 100644 --- a/sc/source/core/opencl/opinlinefun_finacial.cxx +++ b/sc/source/core/opencl/opinlinefun_finacial.cxx @@ -995,6 +995,142 @@ std::string GetDuration= " fDur /= nFreq;\n" " return fDur;\n""}\n"; +std::string ScGetGDADecl= +"double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode," +"double fFaktor);\n"; + +std::string ScGetGDA= +"double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode," +"double fFaktor)\n" +"{\n" +" double fGda, fZins, fAlterWert, fNeuerWert;\n" +" fZins = fFaktor / fDauer;\n" +" if (fZins >= 1.0)\n" +" {\n" +" fZins = 1.0;\n" +" if (fPeriode == 1.0)\n" +" fAlterWert = fWert;\n" +" else\n" +" fAlterWert = 0.0;\n" +" }\n" +" else\n" +" fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1.0);\n" +" fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n" + +" if (fNeuerWert < fRest)\n" +" fGda = fAlterWert - fRest;\n" +" else\n" +" fGda = fAlterWert - fNeuerWert;\n" +" if (fGda < 0.0)\n" +" fGda = 0.0;\n" +" return fGda;\n" +"}\n"; + +std::string DblMinDecl= +"inline double DblMin( double a, double b );\n"; + +std::string DblMin= +"inline double DblMin( double a, double b )\n" +"{\n" +" return (a < b) ? a : b;\n" +"}\n"; + +std::string ScInterVDBDecl= +"double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1," +"double fPeriode,double fFaktor);\n"; + +std::string ScInterVDB= +"double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1," +"double fPeriode,double fFaktor)\n" +"{\n" +" double fVdb=0;\n" +" double fIntEnd = ceil(fPeriode);\n" +" int nLoopEnd = fIntEnd;\n" + +" double fTerm, fLia;\n" +" double fRestwert = fWert - fRest;\n" +" int bNowLia = 0;\n" +" double fGda;\n" +" int i;\n" +" fLia=0;\n" +" for ( i = 1; i <= nLoopEnd; i++)\n" +" {\n" +" if(!bNowLia)\n" +" {\n" +" fGda = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor);\n" +" fLia = fRestwert/ (fDauer1 - (double) (i-1));\n" +" if (fLia > fGda)\n" +" {\n" +" fTerm = fLia;\n" +" bNowLia = 1;\n" +" }\n" +" else\n" +" {\n" +" fTerm = fGda;\n" +" fRestwert =fRestwert- fGda;\n" +" }\n" +" }\n" +" else\n" +" {\n" +" fTerm = fLia;\n" +" }\n" + +" if ( i == nLoopEnd)\n" +" fTerm *= ( fPeriode + 1.0 - fIntEnd );\n" + +" fVdb += fTerm;\n" +" }\n" +" return fVdb;\n" +"}\n"; + +std::string VDBImplementDecl= +"double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang" +", double fEnde, double fFaktor,int bFlag);\n"; + +std::string VDBImplement= +"double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang" +", double fEnde, double fFaktor,int bFlag)\n" +"{\n" +" double result=0;\n" +" double fIntStart = floor(fAnfang);\n" +" double fIntEnd = ceil(fEnde);\n" +" int nLoopStart = (int) fIntStart;\n" +" int nLoopEnd = (int) fIntEnd;\n" +" if (bFlag)\n" +" {\n" +" for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n" +" {\n" +" double fTerm = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor" +");\n" +" if ( i == nLoopStart+1 )\n" +" fTerm *= ( DblMin( fEnde, fIntStart + 1.0 ) - fAnfang );\n" +" else if ( i == nLoopEnd )\n" +" fTerm *= ( fEnde + 1.0 - fIntEnd );\n" +" result += fTerm;\n" +" }\n" +" }\n" +" else\n" +" {\n" +" double fDauer1=fDauer;\n" +" if(!isequal(fAnfang,floor(fAnfang)))\n" +" {\n" +" if(fFaktor>1)\n" +" {\n" +" if(fAnfang>fDauer/2 || isequal(fAnfang,fDauer/2))\n" +" {\n" +" double fPart=fAnfang-fDauer/2;\n" +" fAnfang=fDauer/2;\n" +" fEnde-=fPart;\n" +" fDauer1+=1;\n" +" }\n" +" }\n" +" }\n" +" fWert-=ScInterVDB(fWert,fRest,fDauer,fDauer1,fAnfang,fFaktor);\n" +" result=ScInterVDB(fWert,fRest,fDauer,fDauer-fAnfang,fEnde-fAnfang," +"fFaktor);\n" +" }\n" +" return result;\n" +"}\n"; #endif |