summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshiming zhang <shiming@multicorewareinc.com>2013-11-12 14:07:00 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-15 11:54:27 -0600
commitcfbdb1e40030c58f7674cb293b8984d1d129a2cb (patch)
treee5d454dca9ad4a936f97dc410c56304edf55d6a0
parent5d02ff1e4534f201772c467b60f71903894a431b (diff)
GPU Calc: implemented SLOPE
AMLOEXT-186 FIX Change-Id: Iff85c08948adf75e6e4d443906b601219155ba80 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_statistical.cxx147
-rw-r--r--sc/source/core/opencl/op_statistical.hxx7
3 files changed, 158 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 7171e8006bd0..b31dae5b5350 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1365,6 +1365,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpStDev));
break;
+ case ocSlope:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpSlope));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 3a9b0b5c8e10..00d44d779459 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -1812,6 +1812,153 @@ void OpStDev::GenSlidingWindowFunction(std::stringstream &ss,
ss << " return sqrt(vSum / (fCount - 1.0));\n";
ss << "}\n";
}
+void OpSlope::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 << " int gid0 = get_global_id(0);\n";
+ ss << " double fSumX=0.0;\n";
+ ss << " double fSumY=0.0;\n";
+ ss << " double fMeanX=0.0;\n";
+ ss << " double fMeanY=0.0;\n";
+ ss << " double fSumDeltaXDeltaY=0.0;\n";
+ ss << " double fSumSqrDeltaX=0.0;\n";
+ ss << " double fCount=0.0;\n";
+ ss << " double argX=0.0;\n";
+ ss << " double argY=0.0;\n";
+ if(vSubArguments.size() != 2)
+ {
+ ss << " return DBL_MAX;\n";
+ ss << "}\n";
+ return ;
+ }
+ FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
+ FormulaToken *pCur1 = vSubArguments[0]->GetFormulaToken();
+ assert(pCur);
+ assert(pCur1);
+ if (pCur->GetType() == formula::svDoubleVectorRef&&
+ pCur1->GetType() == formula::svDoubleVectorRef)
+ {
+ const formula::DoubleVectorRefToken* pDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+ const formula::DoubleVectorRefToken* pDVR1 =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur1);
+
+ size_t nCurWindowSize = pDVR->GetRefRowSize();
+ size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
+ if(nCurWindowSize != nCurWindowSize1)
+ {
+ ss << " return DBL_MAX;\n}";
+ ss << "}\n";
+ return ;
+ }
+ ss << " for (int i = ";
+ if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
+ {
+#ifdef ISNAN
+ ss << "gid0; i < " << pDVR->GetArrayLength();
+ ss << " && i < " << nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#else
+ ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#endif
+ }
+ else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+ {
+#ifdef ISNAN
+ ss << "0; i < " << pDVR->GetArrayLength();
+ ss << " && i < gid0+"<< nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#else
+ ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#endif
+ }
+ else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+ {
+#ifdef ISNAN
+ ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+ ss << " && i < "<< nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#else
+ ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#endif
+ }
+ else
+ {
+#ifdef ISNAN
+ ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#else
+ ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#endif
+ }
+
+ ss << " argX = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+ ss << " argY = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+#ifdef ISNAN
+ ss << " if (isNan(argX)||isNan(argY))\n";
+ ss << " continue;\n";
+#endif
+ ss << " fSumX += argX;\n";
+ ss << " fSumY += argY;\n";
+ ss << " fCount += 1;\n";
+ ss << " }\n";
+
+ ss << " if (fCount<1.0)\n";
+ ss << " return DBL_MAX;\n";
+ ss << " else\n";
+ ss << " {\n";
+ ss << " fMeanX=fSumX/fCount;\n";
+ ss << " fMeanY=fSumY/fCount;\n";
+
+#ifdef ISNAN
+ ss << " for (int i = 0; i + gid0 < " << pDVR->GetArrayLength();
+ ss << " && i < " << nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#else
+ ss << " for (int i = 0; i < " << nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+#endif
+ ss << " argX = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+ ss << " argY = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+#ifdef ISNAN
+ ss << " if (isNan(argX)||isNan(argY))\n";
+ ss << " continue;\n";
+#endif
+ ss << " fSumDeltaXDeltaY +=(argX-fMeanX)*(argY-fMeanY);\n";
+ ss << " fSumSqrDeltaX +=(argX-fMeanX)*(argX-fMeanX);\n";
+ ss << " }\n";
+ ss << " if(fSumSqrDeltaX==0)\n";
+ ss << " return DBL_MAX;\n";
+ ss << " else\n";
+ ss << " {\n";
+ ss << " return fSumDeltaXDeltaY/fSumSqrDeltaX;\n";
+ ss << " }\n";
+ ss << " }\n";
+ ss << "}\n";
+ }
+ else
+ {
+ ss << " return DBL_MAX;\n";
+ ss << "}\n";
+ }
+}
void OpFisher::GenSlidingWindowFunction(
std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx
index 48fd7d6c6a3d..dc6a7b466e11 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -56,6 +56,13 @@ public:
const std::string sSymName, SubArguments &vSubArguments);
virtual std::string BinFuncName(void) const { return "Skewp"; }
};
+class OpSlope: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "Slope"; }
+};
class OpWeibull: public Normal
{
public: