summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorfengzeng <fengzeng@multicorewareinc.com>2013-12-13 13:16:06 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-12-19 17:53:55 -0600
commite25d9b6cbe032f9d0a47279056c4a8554967cff4 (patch)
tree8fb9c9e50f53ae09475a4b6ee4624347692d3bf7 /sc
parent2766704b7f0141ba0bc9b020ff56ec4308d896d2 (diff)
GPU Calc: implemented COUNTIF
AMLOEXT-360 FIX Change-Id: I01034aba7f94c9ae704d54b29b9ac0b04a6fba70 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')
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx4
-rw-r--r--sc/source/core/opencl/op_math.cxx131
-rw-r--r--sc/source/core/opencl/op_math.hxx7
3 files changed, 142 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 52ef6ccc51f5..211d7aa52eef 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2440,6 +2440,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpRadians));
break;
+ case ocCountIf:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpCountIf));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 99b42e301f40..8849a0c50b41 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -1610,6 +1610,137 @@ void OpOdd::GenSlidingWindowFunction(
ss << " return tmp;\n";
ss << "}";
}
+void OpCountIf::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < 2; i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ")\n";
+ ss << "{\n";
+ ss << " int gid0=get_global_id(0);\n";
+ ss << " double vara, varb;\n";
+ ss << " int varc = 0;\n";
+ FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
+ assert(tmpCur);
+ if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
+ {
+ if(tmpCur->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken* tmpCurDVR=
+ dynamic_cast<
+ const formula::SingleVectorRefToken *>(tmpCur);
+ ss << " varb = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss << " if(isNan(varb)||(gid0>=";
+ ss << tmpCurDVR->GetArrayLength();
+ ss << "))\n";
+ ss << " varb = 0;\n";
+#endif
+ }
+ else if(tmpCur->GetType() == formula::svDouble)
+ {
+ ss << " varb = ";
+ ss << tmpCur->GetDouble() << ";\n";
+ }
+ }
+ else
+ {
+ ss << " varb = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+ }
+ tmpCur = vSubArguments[0]->GetFormulaToken();
+ assert(tmpCur);
+ if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
+ {
+ //TODO DoubleVector
+ if (tmpCur->GetType() == formula::svDoubleVectorRef)
+ {
+ const formula::DoubleVectorRefToken* pDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(tmpCur);
+ 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";
+ 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 << " vara = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss << " if (isNan(vara))\n";
+ ss << " continue;\n";
+#endif
+ ss << " (vara == varb) && varc++;\n";
+ ss << " }\n";
+ }
+ else if(tmpCur->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken* tmpCurDVR=
+ dynamic_cast<
+ const formula::SingleVectorRefToken *>(tmpCur);
+ ss << " vara = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss << " if(isNan(vara)||(gid0>=";
+ ss << tmpCurDVR->GetArrayLength();
+ ss << "))\n";
+ ss << " return 0;\n";
+ ss << " (vara == varb) && varc++;\n";
+#endif
+ }
+ }
+ ss << " return varc;\n";
+ ss << "}";
+}
void OpTrunc::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments)
{
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index e64f7e4bbc97..5fe20a88b769 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -408,6 +408,13 @@ public:
const std::string sSymName, SubArguments &vSubArguments);
virtual std::string BinFuncName(void) const { return "Degrees"; }
};
+class OpCountIf: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "Countif"; }
+};
}}
#endif