summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormulei <mulei@multicorewareinc.com>2013-11-06 09:39:08 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-13 14:39:14 -0600
commitea17d1ec016f84e37cf9368a1ef4e3319c748a95 (patch)
tree78a725febec0794f0101a6bdcb0c1d1fe0fbb104
parent85be1bb6cadb6be0d369a8cb8430a931dd985f80 (diff)
GPU Calc: implemented for NPV
AMLOEXT-120 FIX Change-Id: Ieb1411a8d7d479c11c63d7f658a3a17b4ce249fb 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.cxx4
-rw-r--r--sc/source/core/opencl/op_financial.cxx118
-rw-r--r--sc/source/core/opencl/op_financial.hxx8
3 files changed, 130 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 81ac09d5bda6..ded4977670f0 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1096,6 +1096,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpArcCosHyp));
break;
+ case ocNPV:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpNPV));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 58b0a87cca00..24d7981bace2 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -2320,6 +2320,124 @@ void OpPMT::GenSlidingWindowFunction(std::stringstream &ss,
ss << "return tmp;\n";
ss << "}";
}
+ void OpNPV::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 << " int nCount = 1;\n";
+ size_t nItems = 0;
+ ss << " double arg0=";
+ ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+ //while (i-- > 1)
+ for (size_t i = 1; 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
+ ss << "nCount += 1;\n";
+#endif
+ nItems += 1;
+ }
+#ifdef ISNAN
+ if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+ {
+ ss << " if (isNan(";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << ")){\n";
+ ss << " tmp += 0;}\n";
+ ss << " else{\n";
+ ss << " tmp +="<<vSubArguments[i]
+ ->GenSlidingWindowDeclRef();
+ ss <<" / pow(1.0f+ arg0 ,";
+ ss <<" (double)nCount );\n";
+ ss << " nCount += 1;\n";
+ ss << " }\n";
+ ss << " }\n";
+ }
+ else
+ {
+ ss << " tmp +="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss <<" / pow(1.0f+ arg0 ,";
+ ss <<" (double)nCount );\n";
+ ss << " nCount += 1;\n";
+ }
+#else
+ ss << "tmp +="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss <<" / pow(1.0f+ arg0 ,";
+ ss <<" (double)nCount );\n";
+ ss << " nCount += 1;\n";
+#endif
+ }
+ ss << " return tmp;\n";
+ ss << "}";
+ }
void OpPrice::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 68f291590250..4283dd917f31 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -304,6 +304,14 @@ public:
const std::string sSymName, SubArguments &vSubArguments);
virtual std::string BinFuncName(void) const { return "PMT"; }
};
+class OpNPV: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "NPV"; }
+};
+
class OpPrice: public Normal
{
public: