summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordechuang <dechuang@multicorewareinc.com>2013-12-13 15:20:56 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-12-19 17:53:57 -0600
commit85605e15e90308c94aa510e42c45db740464021a (patch)
tree0057a127e362bf5bd7b46a569f2e6cf45712f2b1
parent0ed05f45f05f779edd1360140c030de17b2f5ed5 (diff)
GPU Calc: Optimized COUPDAYBS
AMLOEXT-238 Change-Id: Ib6d9401453214491b051d545301a2e57ca73dddc 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>
-rw-r--r--sc/source/core/opencl/op_financial.cxx130
-rw-r--r--sc/source/core/opencl/opinlinefun_finacial.cxx65
2 files changed, 122 insertions, 73 deletions
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index a7c0a7ea41ec..5515951b85f5 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3529,22 +3529,27 @@ void OpCoupdaybs::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs)
{
decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
- decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
- decls.insert(GetNullDateDecl); decls.insert(ScaDateDecl);
+ decls.insert(DaysToDateDecl); decls.insert(DateToDays_newDecl);
+ decls.insert(GetNullDate_newDecl); decls.insert(ScaDateDecl);
decls.insert(addMonthsDecl); decls.insert(getDaysInMonthRangeDecl);
decls.insert(GetDaysInYearsDecl);
decls.insert(getDaysInYearRangeDecl); decls.insert(getDiffDecl);
- decls.insert(lcl_GetcoupdaybsDecl);
+ decls.insert(setDayDecl);decls.insert(checklessthanDecl);
+ decls.insert(lcl_Getcoupdaybs_newDecl);
+ decls.insert(coupdaybs_newDecl);
funs.insert(IsLeapYear);funs.insert(DaysInMonth);
- funs.insert(DaysToDate);funs.insert(DateToDays);
- funs.insert(GetNullDate);funs.insert(ScaDate);
+ funs.insert(DaysToDate);funs.insert(DateToDays_new);
+ funs.insert(GetNullDate_new);funs.insert(ScaDate);
funs.insert(addMonths);funs.insert(getDaysInMonthRange);
funs.insert(GetDaysInYears);
funs.insert(getDaysInYearRange);funs.insert(getDiff);
- funs.insert(lcl_Getcoupdaybs);
+ funs.insert(setDay);funs.insert(checklessthan);
+ funs.insert(lcl_Getcoupdaybs_new);
+ funs.insert(coupdaybs_new);
}
void OpCoupdaybs::GenSlidingWindowFunction(
- std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+ std::stringstream &ss, const std::string sSymName, SubArguments &
+vSubArguments)
{
ss << "\ndouble " << sSymName;
ss << "_"<< BinFuncName() <<"(";
@@ -3554,78 +3559,73 @@ void OpCoupdaybs::GenSlidingWindowFunction(
ss << ",";
vSubArguments[i]->GenSlidingWindowDecl(ss);
}
- ss << ") {\n\t";
- ss << "double tmp = " << GetBottom() <<";\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "int nSettle,nMat,nFreq,nBase;\n\t";
+ ss << ") {\n";
+ ss << " double tmp = 0;\n";
+ ss << " int gid0 = get_global_id(0);\n";
+ ss << " int nSettle,nMat,nFreq,nBase;\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);
- ss<< "int buffer_nSettle_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_nMat_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_nFreq_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
- ss<< "int buffer_nBase_len = ";
- ss<< tmpCurDVR3->GetArrayLength();
- ss << ";\n\t";
+ FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
#endif
#ifdef ISNAN
- ss <<"if(gid0 >= buffer_nSettle_len || isNan(";
- ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nSettle = 0;\n\telse\n\t\t";
+ if(tmpCur0->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
+ ss <<" nSettle = 0;\n else\n";
+ }
#endif
- ss << "nSettle=(int)";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
+ ss <<" nSettle=(int)";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<";\n";
#ifdef ISNAN
- ss <<"if(gid0 >= buffer_nMat_len || isNan(";
- ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nMat = 0;\n\telse\n\t\t";
+ if(tmpCur1->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
+ ss <<" nMat = 0;\n else\n";
+ }
#endif
- ss << "nMat=(int)";
+ ss <<" nMat=(int)";
ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
+ ss <<";\n";
#ifdef ISNAN
- ss <<"if(gid0 >= buffer_nFreq_len || isNan(";
- ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nFreq = 0;\n\telse\n\t\t";
+ if(tmpCur2->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+ ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
+ ss <<" nFreq = 0;\n else\n";
+ }
#endif
- ss << "nFreq=(int)";
+ ss << " nFreq=(int)";
ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss <<";\n\t";
+ ss <<";\n";
#ifdef ISNAN
- ss <<"if(gid0 >= buffer_nBase_len || isNan(";
- ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
- ss <<"))\n\t\t";
- ss <<"nBase = 0;\n\telse\n\t\t";
+ if(tmpCur3->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+ ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
+ ss <<" nBase = 0;\n else\n";
+ }
#endif
- ss << "nBase=(int)";
+ ss << " nBase=(int)";
ss << vSubArguments[3]->GenSlidingWindowDeclRef();
- ss << ";\n\t";
- ss <<"int nNullDate=GetNullDate();\n\t";
- ss <<"tmp = lcl_Getcoupdaybs(nNullDate,";
- ss <<"nSettle, nMat,nFreq,nBase);\n\t";
- ss << "return tmp;\n";
- ss << "}";
+ ss << ";\n";
+ ss <<" tmp = coupdaybs_new(nSettle,nMat,nFreq,nBase);\n";
+ ss <<" return tmp;\n";
+ ss <<"}";
}
+
void OpCoupdays::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 1012f88e005d..bb20802992dd 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -197,14 +197,14 @@ std::string DaysToDate =
" }\n"
" }\n"
" while ( bCalc );\n"
-
-" *rMonth = 1;\n"
-" while ( (int)nTempDays > DaysInMonth( *rMonth, *rYear ) )\n"
-" {\n"
-" nTempDays -= DaysInMonth( *rMonth, *rYear );\n"
-" *rMonth+=1;\n"
-" }\n"
-" *rDay = (int)nTempDays;\n"
+" if(nTempDays!=0){\n"
+" for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
+"*rMonth+=1)\n"
+" {\n"
+" nTempDays -= DaysInMonth( *rMonth, *rYear );\n"
+" }\n"
+" *rDay = (int)nTempDays;\n"
+" }\n"
"}\n";
std::string DateToDaysDecl=
@@ -604,6 +604,45 @@ std::string lcl_Getcoupdaybs=
"sbLastDay, sb30Days, sbUSMode, snDay);\n"
"}\n";
+std::string lcl_Getcoupdaybs_newDecl=
+"int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
+"int nBase);\n";
+
+std::string lcl_Getcoupdaybs_new=
+"int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
+"int nBase)\n"
+"{\n"
+" int aDate = nMat;\n"
+" int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
+"rbUSMode=0,rnDay=0;\n"
+" int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
+"sbUSMode=0,snDay=0;\n"
+" ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
+"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
+" ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
+"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
+" rYear=sYear;\n"
+" setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
+" aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
+" if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
+"sbLastDay,rDay,sDay))\n"
+" {\n"
+" rYear+=1;\n"
+" setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
+" aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
+" }\n"
+" while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
+"rbLastDay,sDay,rDay))\n"
+" {\n"
+" double d = -1*(12/nFreq);\n"
+" addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
+" aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
+" }\n"
+" return getDiff( aDate,nSettle+nNullDate,rDay,rMonth,rYear,rbLastDayMode,"
+"rbLastDay,rb30Days,rbUSMode,rnDay,sDay,sMonth,sYear,sbLastDayMode,sbLastDay,"
+"sb30Days,sbUSMode, snDay);\n"
+"}\n";
+
std::string lcl_GetcoupdaysDecl=
"int lcl_Getcoupdays(int nNullDate,int nSettle, "
"int nMat,int nFreq,int nBase);\n";
@@ -787,6 +826,16 @@ std::string coupdaybs=
" return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
"}\n";
+std::string coupdaybs_newDecl=
+"double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase);\n";
+
+std::string coupdaybs_new=
+"double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase)\n"
+"{\n"
+" int nNullDate=GetNullDate_new();\n"
+" return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
+"}\n";
+
std::string coupdaysncDecl=
"double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n";