diff options
author | mingli <mingli@multicorewareinc.com> | 2013-12-24 13:41:55 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-12-30 15:05:26 -0600 |
commit | fb68fb3c64ae1b1a9811b7fed434dfc31015940d (patch) | |
tree | f97e02647fbcd91b30f4ca8376d9a87fd2b27fb5 | |
parent | 60ae598d537c14283109e1c6de22ec43a0147bcf (diff) |
GPU Calc: implemented AVEDEV
AMLOEXT-379 FIX
Change-Id: I31fadbc5e96759d988d096c93429cdc22923a0a7
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>
-rw-r--r-- | sc/source/core/opencl/formulagroupcl.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/opencl/op_statistical.cxx | 123 | ||||
-rw-r--r-- | sc/source/core/opencl/op_statistical.hxx | 8 |
3 files changed, 134 insertions, 1 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 6045b251c032..4ae6fef41d0e 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -2612,6 +2612,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpNegSub)); break; + case ocAveDev: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i], new OpAveDev)); + 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 a98a08e5adba..858de87ff361 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -11326,7 +11326,128 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss, ss << " return sqrt(vSum * pow(fCount,-1.0));\n"; ss << "}\n"; } - +void OpAveDev:: 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 <<"{\n"; + ss << " int gid0 = get_global_id(0);\n"; + ss << " double sum=0.0;\n"; + ss << " double length;\n"; + ss << " double totallength=0;\n"; + ss << " double tmp = 0;\n"; + for (unsigned i = 0; 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 << " length="<<nCurWindowSize; + ss << ";\n"; + ss << " for (int i = "; + ss << "0; i < "<< nCurWindowSize << "; i++)\n"; + ss << " {\n"; + ss << " double arg"<<i<<" = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if(isNan(arg"<<i<<")||((gid0+i)>="; + ss << pDVR->GetArrayLength(); + ss << "))\n"; + ss << " {\n"; + ss << " length-=1.0;\n"; + ss << " continue;\n"; + ss << " }\n"; +#endif + ss << " sum += arg"<<i<<";\n"; + ss << " }\n"; + ss << " totallength +=length;\n"; + } + else if (pCur->GetType() == formula::svSingleVectorRef) + { + ss << " tmp = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if(!isNan(tmp))\n"; + ss << " {\n"; + ss << " sum += tmp;\n"; + ss << " totallength +=1;\n"; + ss << " }\n"; +#endif + } + else if (pCur->GetType() == formula::svDouble) + { + ss << " tmp = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; + ss << " sum += tmp;\n"; + ss << " totallength +=1;\n"; + } + } + ss << " double mean = sum * pow(totallength,-1);\n"; + ss << " sum = 0.0;\n"; + for (unsigned i = 0; 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 = "; + ss << "0; i < "<< nCurWindowSize << "; i++)\n"; + ss << " {\n"; + ss << " double arg"<<i<<" = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if(isNan(arg"<<i<<")||((gid0+i)>="; + ss << pDVR->GetArrayLength(); + ss << "))\n"; + ss << " {\n"; + ss << " continue;\n"; + ss << " }\n"; +#endif + ss << " sum += fabs(arg"<<i<<"-mean);\n"; + ss << " }\n"; + } + else if (pCur->GetType() == formula::svSingleVectorRef) + { + ss << " tmp = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if(!isNan(tmp))\n"; + ss << " {\n"; + ss << " sum += fabs(tmp-mean);\n"; + ss << " }\n"; +#endif + } + else if (pCur->GetType() == formula::svDouble) + { + ss << " tmp = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; + ss << " sum += fabs(tmp-mean);\n"; + } + } + ss << " tmp=sum*pow(totallength,-1);\n"; + ss << " return tmp;\n"; + ss << "}"; +} }} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx index cdbc86678f76..19b33eb1c63a 100644 --- a/sc/source/core/opencl/op_statistical.hxx +++ b/sc/source/core/opencl/op_statistical.hxx @@ -533,6 +533,14 @@ public: virtual bool takeString() const { return true; } virtual bool takeNumeric() const { return true; } }; +class OpAveDev: public Normal +{ +public: + virtual void GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments); + virtual std::string BinFuncName(void) const { return "AveDev"; } +}; + }} #endif |