summaryrefslogtreecommitdiff
path: root/sc/source/core/opencl/op_financial.cxx
diff options
context:
space:
mode:
authorxinjiang <xinjiang@multicorewareinc.com>2013-12-12 11:56:36 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-12-19 17:53:51 -0600
commit49be3173e5b9ad955654eddf0f61f0e188fff2c6 (patch)
tree8cfa41e93a8d77847cb171bf2346bc1f6e104f39 /sc/source/core/opencl/op_financial.cxx
parent7dbb68e296a7b8b4b6d72df4fe0f4f961594d87c (diff)
GPU Calc: Fix Bug of DISC
AMLOEXT-233 Change-Id: I1bea3ad03f300b95772ffc0a94b73ae35f69e445 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/core/opencl/op_financial.cxx')
-rw-r--r--sc/source/core/opencl/op_financial.cxx139
1 files changed, 52 insertions, 87 deletions
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index d2322ecd5523..878d4e169686 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -290,19 +290,19 @@ void OpDollarfr::GenSlidingWindowFunction(std::stringstream &ss,
void OpDISC::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs)
{
- decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
+ decls.insert(GetYearFrac_newDecl);decls.insert(DaysToDate_newDecl);
decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
- funs.insert(GetYearFrac);funs.insert(DaysToDate);
+ funs.insert(GetYearFrac_new);funs.insert(DaysToDate_new);
funs.insert(GetNullDate);funs.insert(DateToDays);
funs.insert(DaysInMonth);funs.insert(IsLeapYear);
}
-void OpDISC::GenSlidingWindowFunction(
- std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+void OpDISC::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)
@@ -310,97 +310,62 @@ void OpDISC::GenSlidingWindowFunction(
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 << " 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 = 1.0 - price / redemp;\n\t";
- ss << "tmp /= GetYearFrac( nNullDate , settle , maturity , mode );\n\t";
- ss << "return tmp;\n";
+ }
+ ss << " int nNullDate = GetNullDate();\n";
+ ss << " tmp = 1.0 - arg2 / arg3;\n";
+ ss << " tmp /= ";
+ ss << "GetYearFrac_new(nNullDate, (int)arg0, (int)arg1, (int)arg4);\n";
+ ss << " return tmp;\n";
ss << "}";
}
+
void OpINTRATE::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs)
{