sc/qa/unit/data/xls/opencl/statistical/Betainv.xls |binary sc/qa/unit/opencl-test.cxx | 25 +++ sc/source/core/opencl/formulagroupcl.cxx | 10 + sc/source/core/opencl/op_statistical.cxx | 153 +++++++++++++++++++++ sc/source/core/opencl/op_statistical.hxx | 8 - sc/source/core/opencl/opbase.cxx | 4 sc/source/core/opencl/opinlinefun_statistical.cxx | 1 sc/source/core/tool/token.cxx | 1 8 files changed, 197 insertions(+), 5 deletions(-)
New commits: commit 811c671c7ff3229dab1ed9ae81fa9723c603fa80 Author: hongyu zhong <hon...@multicorewareinc.com> Date: Sat Nov 16 17:33:30 2013 +0800 GPU Calc: implemented BETAINV AMLOEXT-201 FIX Change-Id: I68a7277b7353ed5a6f4d2ea8d1a4f7fb894bf487 Signed-off-by: haochen <haoc...@multicorewareinc.com> diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 45ab642..d2a10c5 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1762,6 +1762,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],new OpSumX2PY2)); break; + case ocBetaInv: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i],new OpBetainv)); + 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 ddad803..48c015d 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -6198,6 +6198,159 @@ void OpBetaDist::GenSlidingWindowFunction(std::stringstream &ss, ss << " return tmp;\n"; ss << "}\n"; } +void OpBetainv::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(fMachEpsDecl); + funs.insert(""); + decls.insert(fMaxGammaArgumentDecl); + funs.insert(""); + decls.insert(lcl_IterateInverseBetaInvDecl); + funs.insert(lcl_IterateInverseBetaInv); + decls.insert(GetBetaDistDecl); + funs.insert(GetBetaDist); + decls.insert(lcl_HasChangeOfSignDecl); + funs.insert(lcl_HasChangeOfSign); + decls.insert(lcl_HasChangeOfSignDecl); + funs.insert(lcl_HasChangeOfSign); + decls.insert(lcl_HasChangeOfSignDecl); + funs.insert(lcl_HasChangeOfSign); + decls.insert(lcl_GetBetaHelperContFracDecl); + funs.insert(lcl_GetBetaHelperContFrac); + decls.insert(GetBetaDistPDFDecl); + funs.insert(GetBetaDistPDF); + decls.insert(GetLogBetaDecl); + funs.insert(GetLogBeta); + decls.insert(GetBetaDecl); + funs.insert(GetBeta); + decls.insert(lcl_getLanczosSumDecl); + funs.insert(lcl_getLanczosSum); +} +void OpBetainv::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 << " double tmp0,tmp1,tmp2,tmp3,tmp4;\n"; + ss << " int gid0=get_global_id(0);\n"; + size_t i = vSubArguments.size(); + size_t nItems = 0; + ss <<"\n "; + //while (i-- > 1) + 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<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"; +#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"; +#else + nItems += 1; +#endif + } + else if (pCur->GetType() == formula::svDouble) + { +#ifdef ISNAN + ss << "{\n"; +#endif + nItems += 1; + } + else + { +#ifdef ISNAN +#endif + nItems += 1; + } +#ifdef ISNAN + if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) + { + ss << " if (isNan("; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << "))\n"; + ss << " tmp"<<i<<"= 0;\n"; + ss << " else\n"; + ss << " tmp"<<i<<"=\n"; + ss << vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n}\n"; + } + else + { + ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); + ss <<";\n"; + } +#else + ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#endif + } + ss << " if (tmp0 < 0.0 || tmp0 >= 1.0 ||"; + ss << "tmp3 == tmp4 || tmp1 <= 0.0 || tmp2 <= 0.0)\n"; + ss << " {\n"; + ss << " return DBL_MIN;\n"; + ss << " }\n"; + ss << " if (tmp0 == 0.0)\n"; + ss << " return 0.0;\n"; + ss << " else\n"; + ss << " {"; + ss << " bool bConvError;"; + ss << " double fVal = lcl_IterateInverseBetaInv"; + ss << "(tmp0, tmp1, tmp2, 0.0, 1.0, &bConvError);\n"; + ss << " if(bConvError)\n"; + ss << " return DBL_MIN;\n"; + ss << " else\n"; + ss << " return (tmp3 + fVal*(tmp4 - tmp3));\n"; + ss << " }"; + ss << "}\n"; +} void OpDevSq::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 9f8f54a..43c829f 100644 --- a/sc/source/core/opencl/op_statistical.hxx +++ b/sc/source/core/opencl/op_statistical.hxx @@ -406,7 +406,13 @@ public: ); virtual std::string BinFuncName(void) const { return "BetaDist"; } }; - +class OpBetainv:public Normal{ + public: + 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 "OpBetainv"; } +}; }} #endif diff --git a/sc/source/core/opencl/opinlinefun_statistical.cxx b/sc/source/core/opencl/opinlinefun_statistical.cxx index b97dd11..8aaff82 100644 --- a/sc/source/core/opencl/opinlinefun_statistical.cxx +++ b/sc/source/core/opencl/opinlinefun_statistical.cxx @@ -432,6 +432,7 @@ std::string lcl_IterateInverseBetaInv = "{\n" " *rConvError = false;\n" " double fYEps = 1.0E-307;\n" +" double fXEps = fMachEps;\n" " if(!(fAx < fBx))\n" " {\n" " //print error\n" commit 95b610968c8cc3d44609f5d766276138b7048843 Author: hongyu zhong <hon...@multicorewareinc.com> Date: Sat Nov 16 17:00:14 2013 +0800 GPU Calc: unit test cases for BETAINV Turn NO_FALLBACK_TO_SWINTERP on in formulagroupcl.cxx for test resolve compile warning in opbase.cxx AMLOEXT-201 BUG Change-Id: I82917b13c43c1bcaa01928b89210c8eb7495a167 Signed-off-by: haochen <haoc...@multicorewareinc.com> Signed-off-by: I-Jui (Ray) Sung <r...@multicorewareinc.com> diff --git a/sc/qa/unit/data/xls/opencl/statistical/Betainv.xls b/sc/qa/unit/data/xls/opencl/statistical/Betainv.xls new file mode 100644 index 0000000..d06dfca Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Betainv.xls differ diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx index 81fa8eb..e69a071 100644 --- a/sc/qa/unit/opencl-test.cxx +++ b/sc/qa/unit/opencl-test.cxx @@ -232,6 +232,7 @@ public: void testStatisticalFormulaHypGeomDist(); void testArrayFormulaSumX2MY2(); void testArrayFormulaSumX2PY2(); + void testStatisticalFormulaBetainv(); CPPUNIT_TEST_SUITE(ScOpenclTest); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testFinacialFormula); @@ -395,6 +396,7 @@ public: CPPUNIT_TEST(testStatisticalFormulaHypGeomDist); CPPUNIT_TEST(testArrayFormulaSumX2MY2); CPPUNIT_TEST(testArrayFormulaSumX2PY2); + CPPUNIT_TEST(testStatisticalFormulaBetainv); CPPUNIT_TEST_SUITE_END(); private: @@ -4522,6 +4524,29 @@ void ScOpenclTest:: testArrayFormulaSumX2PY2() xDocSh->DoClose(); xDocShRes->DoClose(); } +//[AMLOEXT-201] +void ScOpenclTest::testStatisticalFormulaBetainv() +{ + if (!detectOpenCLDevice()) + return; + ScDocShellRef xDocSh = loadDoc("opencl/statistical/Betainv.", XLS); + ScDocument* pDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(pDoc); + enableOpenCL(); + pDoc->CalcAll(); + ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Betainv.", XLS); + ScDocument* pDocRes = xDocShRes->GetDocument(); + CPPUNIT_ASSERT(pDocRes); + // Check the results of formula cells in the shared formula range. + for (SCROW i = 1; i <= 19; ++i) + { + double fLibre = pDoc->GetValue(ScAddress(5,i,0)); + double fExcel = pDocRes->GetValue(ScAddress(5,i,0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel)); + } + xDocSh->DoClose(); + xDocShRes->DoClose(); +} ScOpenclTest::ScOpenclTest() : ScBootstrapFixture( "/sc/qa/unit/data" ) { diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 3af918d..45ab642 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -2280,7 +2280,6 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc, if (err != CL_SUCCESS) throw OpenCLError(err); delete mpKernel; - return true; } #undef NO_FALLBACK_TO_SWINTERP /* undef this for non-TDD runs */ catch (const UnhandledToken &ut) { @@ -2312,6 +2311,7 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc, return false; #endif } + return true; } // namespace opencl }} // namespace sc diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx index 07425df..7bcb429 100644 --- a/sc/source/core/opencl/opbase.cxx +++ b/sc/source/core/opencl/opbase.cxx @@ -183,8 +183,7 @@ void CheckVariables::CheckSubArgumentIsNan2( std::stringstream & ss, formula::svSingleVectorRef) ss<<"[get_group_id(1)]"; ss<<", 0);\n"; - return; -#endif +#else ss <<" tmp"; ss <<i; ss << "="; @@ -197,6 +196,7 @@ void CheckVariables::CheckSubArgumentIsNan2( std::stringstream & ss, ss<<"[get_group_id(1)]"; ss<<";\n"; +#endif } void CheckVariables::CheckAllSubArgumentIsNan( diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 4c84ca4..e4386ef 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1463,6 +1463,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r ) case ocHypGeomDist: case ocSumX2MY2: case ocSumX2DY2: + case ocBetaInv: // Don't change the state. break; default: commit 886c5551396d07e8372c9b90562487d1dc69e9b9 Author: I-Jui (Ray) Sung <r...@multicorewareinc.com> Date: Sat Nov 16 02:09:18 2013 -0600 GPU Calc: pass the right argument size for reduction kernels in SumIfs Change-Id: Ib8fab8eacddbeb37795ad45f026559bdde0d43f7 diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index c795a65..3af918d 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -192,6 +192,7 @@ public: throw OpenCLError(err); return 1; } + virtual cl_mem GetCLBuffer(void) const { return NULL; } }; class DynamicKernelPiArgument: public DynamicKernelArgument @@ -1060,7 +1061,8 @@ public: // set kernel arg of reduction kernel for (size_t j=0; j< vclmem.size(); j++){ - err = clSetKernelArg(redKernel, j, sizeof(cl_mem), + err = clSetKernelArg(redKernel, j, + vclmem[j]?sizeof(cl_mem):sizeof(double), (void *)&vclmem[j]); if (CL_SUCCESS != err) throw OpenCLError(err); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits