From 2b183e296940f19bb195ba967e09589d60f7cf40 Mon Sep 17 00:00:00 2001 From: mingli Date: Sat, 9 Nov 2013 11:32:43 +0800 Subject: GPU Calc: implemented B AMLOEXT-161 FIX Change-Id: Id383ee83028dac4e6d5a4341da8d80a1f46874ec Signed-off-by: haochen Signed-off-by: I-Jui (Ray) Sung --- sc/source/core/opencl/formulagroupcl.cxx | 4 + sc/source/core/opencl/op_statistical.cxx | 156 +++++++++++++++++++++++++++++++ sc/source/core/opencl/op_statistical.hxx | 9 ++ 3 files changed, 169 insertions(+) (limited to 'sc') diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 6fd4f22fff8e..d02b13707ced 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1249,6 +1249,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpFTest)); break; + case ocB: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i], new OpB)); + 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 e0af4c64c5c7..247d61c36b6a 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -3573,7 +3573,163 @@ void OpFTest::GenSlidingWindowFunction(std::stringstream &ss, ss << " return tmp;\n"; ss << "}"; } +void OpB::BinInlineFun(std::set& decls, + std::set& funs) +{ + //decls.insert(fBigInvDecl);decls.insert(fLogDblMaxDecl); + decls.insert(GetBinomDistPMFDecl);decls.insert(MinDecl); + decls.insert(fMachEpsDecl);decls.insert(fMaxGammaArgumentDecl); + decls.insert(GetBetaDistDecl);decls.insert(GetBetaDistPDFDecl); + decls.insert(lcl_GetBetaHelperContFracDecl);decls.insert(GetLogBetaDecl); + decls.insert(lcl_getLanczosSumDecl); decls.insert(GetBetaDecl); + funs.insert(GetBinomDistPMF);funs.insert(lcl_GetBinomDistRange); + funs.insert(GetBetaDist);funs.insert(GetBetaDistPDF); + funs.insert(lcl_GetBetaHelperContFrac);funs.insert(GetLogBeta); + funs.insert(lcl_getLanczosSum);funs.insert(GetBeta); +} +void OpB::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 min = 2.22507e-308;\n"; + ss << " double tmp;\n"; + ss << " double arg0,arg1,arg2,arg3;\n"; + size_t i = vSubArguments.size(); + size_t nItems = 0; + for (i = 0; i < vSubArguments.size(); i++) + { + FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); + assert(pCur); + if (pCur->GetType() == formula::svDoubleVectorRef) + { + const formula::DoubleVectorRefToken* pDVR = + dynamic_cast(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"; +#else + ss << "gid0; i < "<< nCurWindowSize << "; i++)\n"; +#endif + } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) { +#ifdef ISNAN + ss << "0; i < " << pDVR->GetArrayLength(); + ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n"; +#else + ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n "; +#endif + } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){ +#ifdef ISNAN + ss << "0; i + gid0 < " << pDVR->GetArrayLength(); + ss << " && i < "<< nCurWindowSize << "; i++){\n "; +#else + ss << "0; i < "<< nCurWindowSize << "; i++)\n"; +#endif + } + else { +#ifdef ISNAN + ss << "0; i < "<< nCurWindowSize << "; i++){\n"; +#else + ss << "0; i < "<< nCurWindowSize << "; i++)\n"; +#endif + } + nItems += nCurWindowSize; + } + else if (pCur->GetType() == formula::svSingleVectorRef) + { +#ifdef ISNAN + const formula::SingleVectorRefToken* pSVR = + dynamic_cast< const formula::SingleVectorRefToken* >(pCur); + ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n"; + ss << " {\n"; + ss << " if (isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " arg"<GetType() == formula::svDouble) + { +#ifdef ISNAN + ss << " if (isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " arg"< min)\n" + " tmp =" + " lcl_GetBinomDistRange(rn, rxs, rxe, fFactor, arg1, rq);\n" + " else\n" + " {\n" + " fFactor = pow(arg1, rn);\n" + " if (fFactor > min)\n" + " {\n" + " tmp =" + "lcl_GetBinomDistRange(rn, rn - rxe, rn - rxs, fFactor, rq, arg1);\n" + " }\n" + " else\n" + " tmp =" + "GetBetaDist(rq, rn - rxe, rxe + 1.0)" + "- GetBetaDist(rq, rn - rxs + 1, rxs);\n" + " }\n" + " }\n" + " }\n" + " else\n" + " {\n" + " if (bIsValidX)\n" + " {\n" + " if (arg1 == 0.0)\n" + " tmp = (rxs == 0.0 ? 1.0 : 0.0);\n" + " else if (arg1 == 1.0)\n" + " tmp = (rxe == rn ? 1.0 : 0.0);\n" + " else\n" + " {\n" + " tmp = DBL_MIN;\n" + " }\n" + " }\n" + " else\n" + " {\n" + " tmp = DBL_MIN;\n" + " }\n" + " }\n" + " return tmp;" + "}\n"; +} }} diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx index 63c6a7989fcf..fa2880d75aea 100644 --- a/sc/source/core/opencl/op_statistical.hxx +++ b/sc/source/core/opencl/op_statistical.hxx @@ -297,6 +297,15 @@ public: ); virtual std::string BinFuncName(void) const { return "FTest"; } }; +class OpB: public Normal +{ +public: + virtual void GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments); + void BinInlineFun(std::set& decls,std::set& funs +); + virtual std::string BinFuncName(void) const { return "B"; } +}; }} -- cgit