summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryiming ju <yiming@multicorewareinc.com>2013-11-05 15:03:14 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-13 00:44:55 -0600
commitf9f1737ab0dbe9b03e130ff39e66608417a4df16 (patch)
tree610008eb4302543991ee822679a88a28e63475f9
parentGPU Calc: unit test cases for MDURATION (diff)
downloadcore-f9f1737ab0dbe9b03e130ff39e66608417a4df16.tar.gz
core-f9f1737ab0dbe9b03e130ff39e66608417a4df16.zip
GPU Calc: implemented for SUMIFS
AMLOEXT-128 FIX Change-Id: I9addf29388eb9dbf6c48382ba5aa940719f7c430 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_math.cxx66
-rw-r--r--sc/source/core/opencl/op_math.hxx8
-rw-r--r--sc/source/core/opencl/opbase.cxx61
-rw-r--r--sc/source/core/opencl/opbase.hxx10
5 files changed, 147 insertions, 2 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 6d589fda1fe2..166d02b4262b 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1064,6 +1064,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpFV));
break;
+ case ocSumIfs:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i],new OpSumIfs));
+ 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 9d10fce340a1..a24872e4cff1 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -79,7 +79,71 @@ void OpCsc::GenSlidingWindowFunction(
ss << "return tmp;\n";
ss << "}";
}
-
+void OpSumIfs::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
+ const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(tmpCur);
+ size_t nCurWindowSize = pCurDVR->GetArrayLength() <
+ pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
+ pCurDVR->GetRefRowSize() ;
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ")\n {\n";
+ ss <<" int gid0=get_global_id(0);\n";
+ ss << " double tmp =0;\n";
+ ss << " int i ;\n";
+ GenTmpVariables(ss,vSubArguments);
+ ss << " for (i = ";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+ ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
+ } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
+ ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
+ } else {
+ ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
+ }
+ ss << " {\n";
+ if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss<< " int doubleIndex =i+gid0;\n";
+ }else
+ {
+ ss<< " int doubleIndex =i;\n";
+ }
+ ss<< " int singleIndex =gid0;\n";
+ int m=0;
+ for(unsigned j=1;j<vSubArguments.size();j+=2,m++)
+ {
+ CheckSubArgumentIsNan(ss,vSubArguments,j);
+ CheckSubArgumentIsNan(ss,vSubArguments,j+1);
+ ss <<" if(isequal(";
+ ss <<"tmp";
+ ss <<j;
+ ss <<" , ";
+ ss << "tmp";
+ ss << j+1;
+ ss << ")){\n";
+ }
+ CheckSubArgumentIsNan(ss,vSubArguments,0);
+ ss << " tmp += tmp0;\n";
+ for(unsigned j=1;j<=vSubArguments.size();j+=2,m--)
+ {
+ for(int n = 0;n<m+1;n++)
+ {
+ ss << " ";
+ }
+ ss<< "}\n";
+ }
+ ss << "return tmp;\n";
+ ss << "}";
+}
void OpSinh::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 d7ce226ef956..d6dda45a4549 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -30,7 +30,13 @@ public:
const std::string sSymName, SubArguments &vSubArguments);
virtual std::string BinFuncName(void) const { return "Csc"; }
};
-
+class OpSumIfs: public CheckVariables
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "SumIfs"; }
+};
class OpSinh: public Normal
{
public:
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index 1ce3e5c7b67f..fe5aedee5eca 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -104,6 +104,67 @@ void Normal::GenSlidingWindowFunction(
ss << "}";
}
+void CheckVariables::GenTmpVariables(
+ std::stringstream & ss, SubArguments & vSubArguments)
+{
+ for(unsigned i=0;i<vSubArguments.size();i++)
+ {
+ ss << " double tmp";
+ ss << i;
+ ss <<";\n";
+ }
+}
+
+void CheckVariables::CheckSubArgumentIsNan( std::stringstream & ss,
+ SubArguments &vSubArguments, int argumentNum)
+{
+ int i = argumentNum;
+#ifdef ISNAN
+ if(vSubArguments[i]->GetFormulaToken()->GetType() ==
+ formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*pTmpDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(vSubArguments[i]->GetFormulaToken());
+ ss<< " if(singleIndex>=";
+ ss<< pTmpDVR1->GetArrayLength();
+ ss<<" ||";
+ }
+ if(vSubArguments[i]->GetFormulaToken()->GetType() ==
+ formula::svDoubleVectorRef)
+ {
+ const formula::DoubleVectorRefToken*pTmpDVR2= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(vSubArguments[i]->GetFormulaToken());
+ ss<< " if(doubleIndex>=";
+ ss<< pTmpDVR2->GetArrayLength();
+ ss<<" ||";
+ }
+ if(vSubArguments[i]->GetFormulaToken()->GetType() == formula::svDouble)
+ {
+ ss<< " if(";
+ }
+ ss<< "isNan(";
+ ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<< " tmp";
+ ss<< i;
+ ss <<"=0;\n else \n";
+#endif
+ ss <<" tmp";
+ ss <<i;
+ ss << "=";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+}
+void CheckVariables::CheckAllSubArgumentIsNan(
+ std::stringstream & ss, SubArguments & vSubArguments)
+{
+ ss<<" int k = gid0;\n";
+ for(unsigned i=0;i<vSubArguments.size();i++)
+ {
+ CheckSubArgumentIsNan(ss,vSubArguments,i);
+ }
+}
+
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index 11f0c7fc4706..4898962979eb 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -149,6 +149,16 @@ public:
virtual bool takeNumeric() const { return true; }
};
+class CheckVariables:public Normal
+{
+public:
+ void GenTmpVariables(std::stringstream &ss, SubArguments &vSubArguments);
+ void CheckSubArgumentIsNan(std::stringstream &ss,
+ SubArguments &vSubArguments, int argumentNum);
+ void CheckAllSubArgumentIsNan(std::stringstream &ss,
+ SubArguments &vSubArguments);
+};
+
}}
#endif