summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormulei <mulei@multicorewareinc.com>2013-11-07 15:59:23 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-14 14:09:41 -0600
commit8aa6ad0ae7b55b3fb456dd7780869e76da68d31c (patch)
tree95df59d34ca3bc1cf255985bcb64dc3655c38eff
parenta26f0830913cc0acf2649b8134d383cc00b86694 (diff)
GPU Calc: Add support for nested argument to NPER
AMLOEXT-146 FIX Change-Id: I737df1d3266e7bf5833e446515135de6db02a072 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.cxx2
-rw-r--r--sc/source/core/opencl/op_financial.cxx147
-rw-r--r--sc/source/core/opencl/op_financial.hxx2
3 files changed, 101 insertions, 50 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index ae1deb1d0220..ddd7ca8bdc04 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1078,7 +1078,7 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
break;
case ocZZR:
mvSubArguments.push_back(SoPHelper(ts,
- ft->Children[i], new OpNPER));
+ ft->Children[i], new OpNper));
break;
case ocNormDist:
mvSubArguments.push_back(SoPHelper(ts,
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 3b226c5b00fb..3d93721a9d30 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3179,63 +3179,114 @@ void OpPriceDisc::GenSlidingWindowFunction(std::stringstream &ss,
ss <<" return tmp;\n";
ss <<"}";
}
-void OpNPER::GenSlidingWindowFunction(std::stringstream &ss,
- const std::string sSymName, SubArguments &vSubArguments)
-{
+void OpNper::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);
+ if (i)
+ ss << ", ";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
}
ss << ") {\n";
ss << " double tmp = 0;\n";
ss << " int gid0 = get_global_id(0);\n";
- for (unsigned n = 0; n < vSubArguments.size(); 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";
+ size_t nItems = 0;
+ for (size_t i = 0; i < vSubArguments.size(); i++)
{
- ss<<" double tmp"<<n<<"=";
- ss<<vSubArguments[n]->GenSlidingWindowDeclRef();
- ss<<";\n";
- }
-#ifdef ISNAN
- FormulaToken *tmpCur0 = vSubArguments[0]
- ->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- ss<<" if("<<tmpCurDVR0->GetArrayLength()<<"<=gid0||";
- ss <<"isNan(tmp0))\n";
- ss<<" tmp0= 0;\n";
- FormulaToken *tmpCur1 = vSubArguments[1]
- ->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur1);
- ss<<" if("<<tmpCurDVR1->GetArrayLength()<<"<=gid0||";
- ss <<"isNan(tmp1))\n";
- ss<<" tmp1= 0;\n";
- FormulaToken *tmpCur2 = vSubArguments[2]
- ->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur2);
- ss<<" if("<<tmpCurDVR2->GetArrayLength()<<"<=gid0||";
- ss <<"isNan(tmp2))\n";
- ss<<" tmp2= 0;\n";
- FormulaToken *tmpCur3 = vSubArguments[3]
- ->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur3);
- ss<<" if("<<tmpCurDVR3->GetArrayLength()<<"<=gid0||";
- ss <<"isNan(tmp3))\n";
- ss<<" tmp3= 0;\n";
- FormulaToken *tmpCur4 = vSubArguments[4]
- ->GetFormulaToken();
- const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
- formula::SingleVectorRefToken *>(tmpCur4);
- ss<<" if("<<tmpCurDVR4->GetArrayLength()<<"<=gid0||";
- ss <<"isNan(tmp4))\n";
- ss<<" tmp4= 0;\n";
+ 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 <<" if (tmp0 == 0.0)\n";
ss <<" tmp=(-(tmp2 + tmp3)/tmp1);\n";
ss <<" else if (tmp4 > 0.0)\n";
@@ -3246,7 +3297,7 @@ void OpNPER::GenSlidingWindowFunction(std::stringstream &ss,
ss <<"/log(1.0+tmp0);\n";
ss <<" return tmp;\n";
ss <<"}";
-}
+ }
void OpPPMT::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs)
{
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index e63f8723656b..11d5fcd6df64 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -343,7 +343,7 @@ public:
virtual std::string BinFuncName(void) const { return "Price"; }
};
-class OpNPER: public Normal
+class OpNper: public Normal
{
public:
virtual void GenSlidingWindowFunction(std::stringstream &ss,