diff options
author | xinjiang <xinjiang@multicorewareinc.com> | 2013-11-06 17:19:09 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-11-13 17:44:09 -0600 |
commit | efc507cebc00051f7288fd0e017b4caec1c407b7 (patch) | |
tree | 628b2c159054892dc663f5f5feb537632df736d7 /sc | |
parent | cac80844c3d43fa8f7280be1a508875ca97a5aa6 (diff) |
GPU Calc: implemented CRITBINOM
AMLOEXT-142 FIX
Change-Id: Iec44d694c7ab520ca403efe7b6ccc2d6fbd84343
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 | 111 | ||||
-rw-r--r-- | sc/source/core/opencl/op_statistical.hxx | 12 | ||||
-rw-r--r-- | sc/source/core/opencl/opinlinefun_statistical.cxx | 2 |
4 files changed, 129 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index d1884697ec92..7e7d3de9202c 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1152,6 +1152,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpCosh)); break; + case ocKritBinom: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i], new OpCritBinom)); + 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 27b507c5ac85..6bc1f21f80ac 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -935,6 +935,117 @@ void OpConfidence::GenSlidingWindowFunction(std::stringstream& ss, ss << "}"; } +void OpCritBinom::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(MinDecl); +} + +void OpCritBinom::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 << " double tmp = " << GetBottom() <<";\n"; + ss << " int gid0 = get_global_id(0);\n"; + ss << " double n = " << GetBottom() <<";\n"; + ss << " double p = " << GetBottom() <<";\n"; + ss << " double alpha = " << GetBottom() <<";\n"; +#ifdef ISNAN + FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken(); + const formula::SingleVectorRefToken* tmpCurDVR0= dynamic_cast<const + formula::SingleVectorRefToken* >(tmpCur0); + FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken(); + const formula::SingleVectorRefToken* tmpCurDVR1= dynamic_cast<const + formula::SingleVectorRefToken* >(tmpCur1); + FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken(); + const formula::SingleVectorRefToken* tmpCurDVR2= dynamic_cast<const + formula::SingleVectorRefToken* >(tmpCur2); + ss << " int buffer_n_len = "; + ss << tmpCurDVR0->GetArrayLength(); + ss << ";\n"; + ss << " int buffer_p_len = "; + ss << tmpCurDVR1->GetArrayLength(); + ss << ";\n"; + ss << " int buffer_alpha_len = "; + ss << tmpCurDVR2->GetArrayLength(); + ss << ";\n"; +#endif +#ifdef ISNAN + ss << " if((gid0)>=buffer_n_len || isNan("; + ss << vSubArguments[0]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " n = 0;\n else\n"; +#endif + ss << " n = "; + ss << vSubArguments[0]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if((gid0)>=buffer_p_len || isNan("; + ss << vSubArguments[1]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " p = 0;\n else\n"; +#endif + ss << " p = "; + ss << vSubArguments[1]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss << " if((gid0)>=buffer_alpha_len || isNan("; + ss << vSubArguments[2]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " alpha = 0;\n else\n"; +#endif + ss << " alpha = "; + ss << vSubArguments[2]->GenSlidingWindowDeclRef(); + ss << ";\n"; + ss << " double rn = floor(n);\n"; + ss << " if (rn < 0.0 || alpha <= 0.0 || alpha >= 1.0 || p < 0.0"; + ss << " || p > 1.0)\n"; + ss << " tmp = -DBL_MAX;\n"; + ss << " else\n"; + ss << " {\n"; + ss << " double rq = (0.5 - p) + 0.5;\n"; + ss << " double fFactor = pow(rq, rn);\n"; + ss << " if (fFactor <= Min)\n"; + ss << " {\n"; + ss << " fFactor = pow(p, rn);\n"; + ss << " if (fFactor <= Min)\n"; + ss << " tmp = -DBL_MAX;\n"; + ss << " else\n"; + ss << " {\n"; + ss << " double fSum = 1.0 - fFactor;\n"; + ss << " uint max =(uint)(rn), i;\n"; + ss << " for (i = 0; i < max && fSum >= alpha; i++)\n"; + ss << " {\n"; + ss << " fFactor *= (rn - i) / (i + 1) * rq / p;\n"; + ss << " fSum -= fFactor;\n"; + ss << " }\n"; + ss << " tmp = (rn - i);\n"; + ss << " }\n"; + ss << " }\n"; + ss << " else\n"; + ss << " {\n"; + ss << " double fSum = fFactor;\n"; + ss << " uint max = (uint)(rn), i;\n"; + ss << " for (i = 0; i < max && fSum < alpha; i++)\n"; + ss << " {\n"; + ss << " fFactor *= (rn - i) / (i + 1) * p / rq;\n"; + ss << " fSum += fFactor;\n"; + ss << " }\n"; + ss << " tmp = (i);\n"; + ss << " }\n"; + ss << " }\n"; + ss << " return tmp;\n"; + ss << "}"; +} + void OpRsq::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 1b6e9cf87966..19ad6a596f8b 100644 --- a/sc/source/core/opencl/op_statistical.hxx +++ b/sc/source/core/opencl/op_statistical.hxx @@ -199,6 +199,18 @@ public: const std::string sSymName, SubArguments &vSubArguments); virtual std::string BinFuncName(void) const { return "LogInv"; } }; +class OpCritBinom: public Normal +{ +public: + virtual std::string GetBottom(void) { return "0"; } + + virtual void GenSlidingWindowFunction(std::stringstream& ss, + const std::string sSymName, SubArguments& vSubArguments); + virtual void BinInlineFun(std::set<std::string>& , + std::set<std::string>& ); + + virtual std::string BinFuncName(void) const { return "CritBinom"; } +}; }} #endif diff --git a/sc/source/core/opencl/opinlinefun_statistical.cxx b/sc/source/core/opencl/opinlinefun_statistical.cxx index f2ba0abbc8ba..31e9dc251206 100644 --- a/sc/source/core/opencl/opinlinefun_statistical.cxx +++ b/sc/source/core/opencl/opinlinefun_statistical.cxx @@ -12,6 +12,8 @@ std::string fBigInvDecl ="#define fBigInv 2.22045e-016\n"; std::string fLogDblMaxDecl ="#define fLogDblMax log(1.79769e+308)\n"; std::string fHalfMachEpsDecl ="#define fHalfMachEps 0.5*2.22045e-016\n"; +std::string MinDecl = "#define Min 2.22507e-308\n"; + std::string fMaxGammaArgumentDecl = "#define fMaxGammaArgument 171.624376956302\n"; |