diff options
author | fengzeng <fengzeng@multicorewareinc.com> | 2013-11-10 09:03:29 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-11-14 20:30:40 -0600 |
commit | 8e2df9ac2bb14f05b8b59741526f6cfa3d1c97fe (patch) | |
tree | 431f5be73c408e222a2f5a41f4c5ebc6788fa70e /sc | |
parent | a9edef9c11cd5529f4995645d4649a2189be0a29 (diff) |
GPU Calc: implemented for SKEW
AMLOEXT-80 FIX
Change-Id: I22131ff7688237c7cb77335d6a8cadd4e40ff78d
Signed-off-by: haochen <haochen@multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/opencl/formulagroupcl.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/opencl/op_statistical.cxx | 339 | ||||
-rw-r--r-- | sc/source/core/opencl/op_statistical.hxx | 7 |
3 files changed, 350 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index ccdc01b6cd4c..ce53e74c490f 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1301,6 +1301,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpTrunc)); break; + case ocSchiefe: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i], new OpSkew)); + 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 a686e5dfe4d0..636afd0024eb 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -671,7 +671,346 @@ void OpWeibull::GenSlidingWindowFunction(std::stringstream &ss, ss << " return tmp;\n"; ss << "}\n"; } +void OpSkew::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 fSum = 0.0;\n"; + ss << " double fMean = 0.0;\n"; + ss << " double vSum = 0.0;\n"; + ss << " double fCount = 0.0;\n"; + ss << " double arg = 0.0;\n"; + unsigned i = vSubArguments.size(); + while (i--) + { + FormulaToken* pCur = vSubArguments[i]->GetFormulaToken(); + assert(pCur); + if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) + { + if (pCur->GetType() == formula::svDoubleVectorRef) + { + const formula::DoubleVectorRefToken* pDVR = + dynamic_cast<const formula::DoubleVectorRefToken *>(pCur); + 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 << " arg = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; +#ifdef ISNAN + ss << " if (isNan(arg))\n"; + ss << " continue;\n"; +#endif + ss << " fSum += arg;\n"; + ss << " fCount += 1;\n"; + ss << " }\n"; + } + else if (pCur->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken* pSVR = + dynamic_cast< const formula::SingleVectorRefToken* >(pCur); + assert(pSVR); +#ifdef ISNAN + ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n"; + ss << " {\n"; + ss << " if (!isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << "))\n"; + ss << " {\n"; +#endif + ss << " arg="; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + ss << " fSum += arg;\n"; + ss << " fCount += 1;\n"; +#ifdef ISNAN + ss << " }\n"; + ss << " }\n"; +#endif + } + else + { + ss << " arg=" << pCur->GetDouble() << ";\n"; + ss << " fSum += arg;\n"; + ss << " fCount += 1;\n"; + } + } + else + { + ss << " arg="; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + ss << " fSum += arg;\n"; + ss << " fCount += 1;\n"; + } + + if(i == 0) + { + ss << " if(fCount <= 2)\n"; + ss << " return 0;\n"; + ss << " else\n"; + ss << " fMean = fSum / " << "fCount" << ";\n"; + } + } + i = vSubArguments.size(); + while (i--) + { + FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); + assert(pCur); + if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) + { + if (pCur->GetType() == formula::svDoubleVectorRef) + { + const formula::DoubleVectorRefToken* pDVR = + dynamic_cast<const formula::DoubleVectorRefToken *>(pCur); + 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 << " arg = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; +#ifdef ISNAN + ss << " if (isNan(arg))\n"; + ss << " continue;\n"; +#endif + ss << " vSum += (arg - fMean) * (arg - fMean);\n"; + ss << " }\n"; + } + else if (pCur->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken* pSVR = + dynamic_cast< const formula::SingleVectorRefToken* >(pCur); + assert(pSVR); +#ifdef ISNAN + ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n"; + ss << " {\n"; + ss << " if (!isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << "))\n"; + ss << " {\n"; +#endif + ss << " arg="; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + ss << " vSum += (arg - fMean) * (arg - fMean);\n"; +#ifdef ISNAN + ss << " }\n"; + ss << " }\n"; +#endif + } + else + { + ss << " arg = " << pCur->GetDouble() << ";\n"; + ss << " vSum += (arg - fMean) * (arg - fMean);\n"; + } + } + else + { + ss << " arg="; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + ss << " vSum += (arg - fMean) * (arg - fMean);\n"; + } + } + ss << " double fStdDev = sqrt(vSum/(fCount-1.0));\n"; + ss << " double dx = 0.0;\n"; + ss << " double xcube = 0.0;\n"; + ss << " if(fStdDev == 0.0)\n"; + ss << " return DBL_MAX;\n"; + i = vSubArguments.size(); + while (i--) + { + FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); + assert(pCur); + if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) + { + if (pCur->GetType() == formula::svDoubleVectorRef) + { + const formula::DoubleVectorRefToken* pDVR = + dynamic_cast<const formula::DoubleVectorRefToken *>(pCur); + 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 << " arg = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; +#ifdef ISNAN + ss << " if (isNan(arg))\n"; + ss << " continue;\n"; +#endif + ss << " dx = (arg - fMean) / fStdDev;\n"; + ss << " xcube = xcube + (dx * dx * dx);\n"; + ss << " }\n"; + } + else if (pCur->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken* pSVR = + dynamic_cast< const formula::SingleVectorRefToken* >(pCur); + assert(pSVR); +#ifdef ISNAN + ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n"; + ss << " {\n"; + ss << " if (!isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << "))\n"; + ss << " {\n"; +#endif + ss << " arg = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + ss << " dx = (arg - fMean) / fStdDev;\n"; + ss << " xcube = xcube+(dx*dx*dx);\n"; +#ifdef ISNAN + ss << " }\n"; + ss << " }\n"; +#endif + } + else + { + ss << " arg = " << pCur->GetDouble() << ";\n"; + ss << " dx = (arg - fMean) / fStdDev;\n"; + ss << " xcube = xcube + (dx * dx * dx);\n"; + } + } + else + { + ss << " arg = "; + ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n"; + ss << " dx = (arg - fMean) / fStdDev;\n"; + ss << " xcube = xcube + (dx * dx * dx);\n"; + } + } + ss << " return ((xcube * fCount)/"; + ss << "(fCount - 1.0)) / (fCount - 2.0);\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 9566d30b4de4..e9ab0e63f351 100644 --- a/sc/source/core/opencl/op_statistical.hxx +++ b/sc/source/core/opencl/op_statistical.hxx @@ -50,6 +50,13 @@ public: virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>&); virtual std::string BinFuncName(void) const { return "Fdist"; } }; +class OpSkew: public Normal +{ +public: + virtual void GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments); + virtual std::string BinFuncName(void) const { return "Skew"; } +}; class OpFisher: public Normal { public: |