From 0d251fa34e2c98e95e5f5bbb0bcc10ded2a76168 Mon Sep 17 00:00:00 2001 From: fengzeng Date: Wed, 18 Dec 2013 15:36:12 +0800 Subject: GPU Calc: implemented SUMIF AMLOEXT-377 FIX Change-Id: I2e656e9d943179b4da1c1b104ac77f0edcb2f86e Signed-off-by: haochen Signed-off-by: I-Jui (Ray) Sung --- sc/source/core/opencl/formulagroupcl.cxx | 4 + sc/source/core/opencl/op_math.cxx | 151 +++++++++++++++++++++++++++++++ sc/source/core/opencl/op_math.hxx | 7 ++ 3 files changed, 162 insertions(+) diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index ddfb665df714..35f040d7e3cf 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -2585,6 +2585,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpSecH)); break; + case ocSumIf: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i], new OpSumIf)); + 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 d27476de29c0..0df3837dc81b 100644 --- a/sc/source/core/opencl/op_math.cxx +++ b/sc/source/core/opencl/op_math.cxx @@ -1905,6 +1905,157 @@ void OpCountIf::GenSlidingWindowFunction(std::stringstream &ss, ss << " return varc;\n"; ss << "}"; } +void OpSumIf::GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments) +{ + ss << "\ndouble " << sSymName; + ss << "_"<< BinFuncName() <<"("; + int flag = 0; + (3 == vSubArguments.size()) && (flag = 2); + for (unsigned i = 0; i < vSubArguments.size(); i++) + { + if (i) + ss << ","; + vSubArguments[i]->GenSlidingWindowDecl(ss); + } + ss << ")\n"; + ss << "{\n"; + ss << " int gid0=get_global_id(0);\n"; + ss << " double vara, varb, varc, sum = 0.0f;\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(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 << " varc = "; + ss << vSubArguments[flag]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if (isNan(varc))\n"; + ss << " varc = 0.0f;\n"; +#endif + ss << " (vara == varb)&&(sum = sum + 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"; +#endif + ss << " int i = 0;\n"; + ss << " varc = "; + ss << vSubArguments[flag]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if(isNan(varc)||(gid0>="; + ss << tmpCurDVR->GetArrayLength(); + ss << "))\n"; + ss << " varc = 0.0f;\n"; +#endif + + ss << " (vara == varb)&&(sum = sum + varc);\n"; + + } + } + ss << " return sum;\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 79a31d0d8c25..b0d79807bca8 100644 --- a/sc/source/core/opencl/op_math.hxx +++ b/sc/source/core/opencl/op_math.hxx @@ -468,6 +468,13 @@ public: const std::string sSymName, SubArguments &vSubArguments); virtual std::string BinFuncName(void) const { return "SeriesSum"; } }; +class OpSumIf: public Normal +{ +public: + virtual void GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments); + virtual std::string BinFuncName(void) const { return "SumIf"; } +}; class OpQuotient: public Normal { public: -- cgit