diff options
author | mulei <mulei@multicorewareinc.com> | 2013-11-06 13:45:39 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-11-13 14:39:21 -0600 |
commit | d6c0c2151053601bc9430e9e17b5e6b284ba5f65 (patch) | |
tree | 0ef339527d10161e1cf9afeb8fe8e46f7dca6926 /sc | |
parent | 0487d67571ef7845a55d45a504dc265140493ca5 (diff) |
GPU Calc: implemented for ODDLYIELD
AMLOEXT-68 FIX
Change-Id: I5a955a7488829621cf4ad905239f915784b1f374
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.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/opencl/op_financial.cxx | 132 | ||||
-rw-r--r-- | sc/source/core/opencl/op_financial.hxx | 9 | ||||
-rw-r--r-- | sc/source/core/opencl/opinlinefun_finacial.cxx | 18 |
4 files changed, 165 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index a9a47a87fc90..02ff50920b00 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1295,6 +1295,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpOddlprice)); } + else if ( !(pChild->GetExternal().compareTo(OUString( + "com.sun.star.sheet.addin.Analysis.getOddlyield")))) + { + mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], + new OpOddlyield)); + } break; default: throw UnhandledToken(pChild, "unhandled opcode"); diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index bc3485424175..aaa79a83a976 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -2786,6 +2786,138 @@ void OpOddlprice::GenSlidingWindowFunction(std::stringstream &ss, ss <<" return tmp;\n"; ss <<"}"; } +void OpOddlyield::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(GetDiffDateDecl);decls.insert(DaysToDateDecl); + decls.insert(GetYearDiffDecl);decls.insert(IsLeapYearDecl); + decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl); + decls.insert(DaysInMonthDecl); + decls.insert(GetYearFracDecl);decls.insert(GetOddlyieldDecl); + funs.insert(GetDiffDate);funs.insert(DaysToDate); + funs.insert(GetYearDiff);funs.insert(IsLeapYear); + funs.insert(GetNullDate);funs.insert(DaysInMonth); + funs.insert(DateToDays); + funs.insert(GetYearFrac);funs.insert(GetOddlyield); +} +void OpOddlyield::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 = 0;\n"; + ss <<" int gid0 = get_global_id(0);\n"; + ss <<" double tmp0=0;\n"; + ss <<" double tmp1=0;\n"; + ss <<" double tmp2=0;\n"; + ss <<" double tmp3=0;\n"; + ss <<" double tmp4=0;\n"; + ss <<" double tmp5=0;\n"; + ss <<" double tmp6=0;\n"; + ss <<" double tmp7=0;\n"; + size_t nItems = 0; + ss <<" \n"; + for (size_t i = 0; i < vSubArguments.size(); i++) + { + FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); + assert(pCur); + if (pCur->GetType() == formula::svDoubleVectorRef) + { + const formula::DoubleVectorRefToken* pDVR = + dynamic_cast<const formula::DoubleVectorRefToken *>(pCur); + size_t nCurWindowSize = pDVR->GetRefRowSize(); + ss << " for (int i = "; + if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) { +#ifdef ISNAN + ss << "gid0; i < " << pDVR->GetArrayLength(); + ss << " && i < " << nCurWindowSize << "; i++){\n"; +#else + ss << "gid0; i < "<< nCurWindowSize << "; i++)\n"; +#endif + } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) { +#ifdef ISNAN + ss << "0; i < " << pDVR->GetArrayLength(); + ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n"; +#else + ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n"; +#endif + } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){ +#ifdef ISNAN + ss << "0; i + gid0 < " << pDVR->GetArrayLength(); + ss << " && i < "<< nCurWindowSize << "; i++){\n"; +#else + ss << "0; i < "<< nCurWindowSize << "; i++)\n"; +#endif + } + else { +#ifdef ISNAN + ss << "0; i < "<< nCurWindowSize << "; i++){\n"; +#else + ss << "0; i < "<< nCurWindowSize << "; i++)\n"; +#endif + } + nItems += nCurWindowSize; + } + else if (pCur->GetType() == formula::svSingleVectorRef) + { +#ifdef ISNAN + const formula::SingleVectorRefToken* pSVR = + dynamic_cast< const formula::SingleVectorRefToken* >(pCur); + ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n"; +#else + nItems += 1; +#endif + } + else if (pCur->GetType() == formula::svDouble) + { +#ifdef ISNAN + ss << "{\n"; +#endif + nItems += 1; + } + else + { +#ifdef ISNAN +#endif + nItems += 1; + } +#ifdef ISNAN + if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) + { + ss << " if (isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " tmp"<<i<<"= 0;\n"; + ss << " else\n"; + ss << " tmp"<<i<<"="; + ss <<vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; + ss <<" }\n"; + } + else + { + ss << " tmp"<<i<<"="; + ss <<vSubArguments[i]->GenSlidingWindowDeclRef(); + ss <<";\n"; + } +#else + ss << " tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#endif + } + ss <<" int nNullDate = GetNullDate();\n"; + ss <<" tmp = GetOddlyield(nNullDate,tmp0,tmp1"; + ss <<",tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n"; + ss <<" return tmp;\n"; + ss <<"}"; +} void OpNPER::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 6c886f914a15..4efd1e3cc4e3 100644 --- a/sc/source/core/opencl/op_financial.hxx +++ b/sc/source/core/opencl/op_financial.hxx @@ -351,6 +351,15 @@ public: std::set<std::string>& ); virtual std::string BinFuncName(void) const { return "Oddlprice"; } }; +class OpOddlyield: 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>& ); + virtual std::string BinFuncName(void) const { return "Oddlyield"; } +}; class OpPPMT: public Normal { public: diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx index 5e514707468d..fab1db877d05 100644 --- a/sc/source/core/opencl/opinlinefun_finacial.cxx +++ b/sc/source/core/opencl/opinlinefun_finacial.cxx @@ -1153,6 +1153,24 @@ std::string GetOddlprice= " return p;\n" "}\n"; +std::string GetOddlyieldDecl= +"double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" +" double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n"; + +std::string GetOddlyield= +"double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" +" double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n" +"{\n" +" double fFreq = nFreq ;\n" +" double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n" +" double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n" +" double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n" +" double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n" +" y /= fPrice + fAi * 100.0 * fRate / fFreq;\n" +" y -= 1.0;\n" +" y *= fFreq / fDSCi;\n" +" return y;\n" +"}\n"; #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |