diff options
author | xinjiang <xinjiang@multicorewareinc.com> | 2013-12-12 12:12:30 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-12-19 17:53:51 -0600 |
commit | 2eb504cca2b507cad77a99d37857d0f4312ef560 (patch) | |
tree | be76ad5af31661f7a0d41175d8203563ff879078 /sc/source | |
parent | 49be3173e5b9ad955654eddf0f61f0e188fff2c6 (diff) |
GPU Calc: Optimized INTRATE
AMLOEXT-355
Change-Id: I7ceb5760f83e75e69c0d0dd5f7db6b2680747262
Signed-off-by: haochen <haochen@multicorewareinc.com>
Signed-off-by: Wei Wei <weiwei@multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/opencl/op_financial.cxx | 144 | ||||
-rw-r--r-- | sc/source/core/opencl/opinlinefun_finacial.cxx | 76 |
2 files changed, 131 insertions, 89 deletions
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index 878d4e169686..94af72873d58 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -369,117 +369,83 @@ void OpDISC::GenSlidingWindowFunction(std::stringstream& ss, void OpINTRATE::BinInlineFun(std::set<std::string>& decls, std::set<std::string>& funs) { - decls.insert(GetYearDiffDecl);decls.insert(GetDiffDateDecl); - decls.insert(DaysToDateDecl);decls.insert(GetNullDateDecl); + decls.insert(GetYearDiff_newDecl);decls.insert(GetDiffDate_newDecl); + decls.insert(DaysToDate_newDecl);decls.insert(GetNullDateDecl); decls.insert(DateToDaysDecl);decls.insert(DaysInMonthDecl); decls.insert(IsLeapYearDecl); - funs.insert(GetYearDiff);funs.insert(GetDiffDate); - funs.insert(DaysToDate);funs.insert(GetNullDate); + funs.insert(GetYearDiff_new);funs.insert(GetDiffDate_new); + funs.insert(DaysToDate_new);funs.insert(GetNullDate); funs.insert(DateToDays);funs.insert(DaysInMonth); funs.insert(IsLeapYear); } -void OpINTRATE::GenSlidingWindowFunction( - std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments) +void OpINTRATE::GenSlidingWindowFunction(std::stringstream& ss, + const std::string sSymName, SubArguments& vSubArguments) { ss << "\ndouble " << sSymName; - ss << "_"<< BinFuncName() <<"("; + ss << "_" << BinFuncName() << "("; for (unsigned i = 0; i < vSubArguments.size(); i++) { if (i) ss << ","; vSubArguments[i]->GenSlidingWindowDecl(ss); } - ss << ") {\n\t"; - ss << "double tmp = " << GetBottom() <<";\n\t"; - ss << "int gid0 = get_global_id(0);\n\t"; - ss << "double settle = " << GetBottom() <<";\n\t"; - ss << "double maturity = " << GetBottom() <<";\n\t"; - ss << "double price = " << GetBottom() <<";\n\t"; - ss << "double redemp = " << GetBottom() <<";\n\t"; - ss << "int mode = " << GetBottom() <<";\n\t"; -#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_settle_len = "; - ss << tmpCurDVR0->GetArrayLength(); - ss << ";\n\t"; - ss << "int buffer_maturity_len = "; - ss << tmpCurDVR1->GetArrayLength(); - ss << ";\n\t"; - ss << "int buffer_price_len = "; - ss << tmpCurDVR2->GetArrayLength(); - ss << ";\n\t"; - ss << "int buffer_redemp_len = "; - ss << tmpCurDVR3->GetArrayLength(); - ss << ";\n\t"; - ss << "int buffer_mode_len = "; - ss << tmpCurDVR4->GetArrayLength(); - ss << ";\n\t"; -#endif -#ifdef ISNAN - ss << "if((gid0)>=buffer_settle_len || isNan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << "))\n\t\t"; - ss << "settle = 0;\n\telse \n\t\t"; -#endif - ss << "settle = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; -#ifdef ISNAN - ss << "if((gid0)>=buffer_maturity_len || isNan("; - ss << vSubArguments[1]->GenSlidingWindowDeclRef(); - ss << "))\n\t\t"; - ss << "maturity = 0;\n\telse \n\t\t"; -#endif - ss << "maturity = "; - ss << vSubArguments[1]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; + 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"; + for (unsigned i = 0; i < vSubArguments.size(); i++) + { + FormulaToken* pCur = vSubArguments[i]->GetFormulaToken(); + assert(pCur); + if (pCur->GetType() == formula::svSingleVectorRef) + { #ifdef ISNAN - ss << "if((gid0)>=buffer_price_len || isNan("; - ss << vSubArguments[2]->GenSlidingWindowDeclRef(); - ss << "))\n\t\t"; - ss << "price = 0;\n\telse \n\t\t"; + const formula::SingleVectorRefToken* pSVR = + dynamic_cast< const formula::SingleVectorRefToken* >(pCur); + ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n"; #endif - ss << "price = "; - ss << vSubArguments[2]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; + } + else if (pCur->GetType() == formula::svDouble) + { #ifdef ISNAN - ss << "if((gid0)>=buffer_redemp_len || isNan("; - ss << vSubArguments[3]->GenSlidingWindowDeclRef(); - ss << "))\n\t\t"; - ss << "redemp = 0;\n\telse \n\t\t"; + ss << " {\n"; #endif - ss << "redemp = "; - ss << vSubArguments[3]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; + } #ifdef ISNAN - ss << "if((gid0)>=buffer_mode_len || isNan("; - ss << vSubArguments[4]->GenSlidingWindowDeclRef(); - ss << "))\n\t\t"; - ss << "mode = 0;\n\telse \n\t\t"; + if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) + { + ss << " if (isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " arg" << i << " = 0;\n"; + ss << " else\n"; + ss << " arg" << i << " = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + ss << " }\n"; + } + else + { + ss << " arg" << i << " = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + } +#else + ss << " arg" << i; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; #endif - ss << "mode = "; - ss << vSubArguments[4]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; - ss << "int nNullDate = GetNullDate();\n\t"; - ss << "tmp = (redemp / price - 1.0) / GetYearDiff(nNullDate, settle, maturity, mode);\n\t"; - ss << "return tmp;\n"; + } + ss << " int nNullDate = GetNullDate();\n"; + ss << " tmp = arg3 * pow(arg2,-1) - 1.0;\n"; + ss << " tmp = tmp * pow(GetYearDiff_new(nNullDate, (int)arg0,"; + ss << " (int)arg1,(int)arg4),-1);\n"; + ss << " return tmp;\n"; ss << "}"; } + void OpFV::BinInlineFun(std::set<std::string>& decls, std::set<std::string>& funs) { diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx index 66d722c68f1b..27ed0c9f55ea 100644 --- a/sc/source/core/opencl/opinlinefun_finacial.cxx +++ b/sc/source/core/opencl/opinlinefun_finacial.cxx @@ -1488,6 +1488,82 @@ std::string DaysToDate_new = " }\n" "}\n"; +std::string GetYearDiff_newDecl= +"double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate," +"int nMode);\n"; + +std::string GetYearDiff_new= +"double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate," +"int nMode )\n" +"{\n" +" int nDays1stYear;\n" +" int nTotalDays = GetDiffDate_new( nNullDate, nStartDate, nEndDate," +"nMode, &" +"nDays1stYear );\n" +" return (double)(nTotalDays)* pow((double)nDays1stYear,-1);\n" +"}\n"; + +std::string GetDiffDate_newDecl= +"int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode," +" int* pOptDaysIn1stYear );\n"; + +std::string GetDiffDate_new= +"int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode," +" int* pOptDaysIn1stYear )\n" +"{\n" +" bool bNeg = nStartDate > nEndDate;\n" +" if( bNeg )\n" +" {\n" +" int n = nEndDate;\n" +" nEndDate = nStartDate;\n" +" nStartDate = n;\n" +" }\n" +" int nRet;\n" +" switch( nMode )\n" +" {\n" +" case 0: \n" +" case 4: \n" +" {\n" +" int nD1, nM1, nY1, nD2, nM2, nY2;\n" +" nStartDate += nNullDate;\n" +" nEndDate += nNullDate;\n" +" DaysToDate_new( nStartDate, &nD1, &nM1, &nY1 );\n" +" DaysToDate_new( nEndDate, &nD2, &nM2, &nY2 );\n" +" bool bLeap = IsLeapYear( nY1 );\n" +" int nDays, nMonths;\n" +" nMonths = nM2 - nM1;\n" +" nDays = nD2 - nD1;\n" +" nMonths += ( nY2 - nY1 ) * 12;\n" +" nRet = nMonths * 30 + nDays;\n" +" if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n" +" nRet -= bLeap? 1 : 2;\n" +" if( pOptDaysIn1stYear )\n" +" *pOptDaysIn1stYear = 360;\n" +" }\n" +" break;\n" +" case 1: \n" +" if( pOptDaysIn1stYear )\n" +" {\n" +" int nD, nM, nY;\n" +" DaysToDate_new( nStartDate + nNullDate, &nD, &nM, &nY );\n" +" *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n" +" }\n" +" nRet = nEndDate - nStartDate;\n" +" break;\n" +" case 2: \n" +" nRet = nEndDate - nStartDate;\n" +" if( pOptDaysIn1stYear )\n" +" *pOptDaysIn1stYear = 360;\n" +" break;\n" +" case 3: \n" +" nRet = nEndDate - nStartDate;\n" +" if( pOptDaysIn1stYear )\n" +" *pOptDaysIn1stYear = 365;\n" +" break;\n" +" }\n" +" return bNeg? -nRet : nRet;\n" +"}\n"; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |