[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter-4' - 4 commits - sc/Library_scopencl.mk sc/qa sc/source
yiming ju
yiming at multicorewareinc.com
Sun Nov 17 11:04:29 PST 2013
sc/Library_scopencl.mk | 1
sc/qa/unit/data/xls/opencl/logical/and.xls |binary
sc/qa/unit/data/xls/opencl/math/sumproduct_mixSliding.xls |binary
sc/qa/unit/opencl-test.cxx | 68 ++++++++
sc/source/core/opencl/formulagroupcl.cxx | 62 ++++++-
sc/source/core/opencl/op_logical.cxx | 109 ++++++++++++++
sc/source/core/opencl/op_logical.hxx | 29 +++
sc/source/core/tool/token.cxx | 1
8 files changed, 261 insertions(+), 9 deletions(-)
New commits:
commit 2c64547663697834ca9fb2359109edfd924b9f97
Author: yiming ju <yiming at multicorewareinc.com>
Date: Sun Nov 17 18:29:16 2013 +0800
GPU Calc: unit test cases for SUMPRODUCT WITH FIXED WINDOWS
AMLOEXT-214 BUG
Change-Id: Ib5adff235593b3a38f6aa7e63edf0196d31b8e82
Signed-off-by: haochen <haochen at multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
diff --git a/sc/qa/unit/data/xls/opencl/math/sumproduct_mixSliding.xls b/sc/qa/unit/data/xls/opencl/math/sumproduct_mixSliding.xls
new file mode 100644
index 0000000..09ff33e
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/math/sumproduct_mixSliding.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 437602a..f810121 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -242,6 +242,7 @@ public:
void testStatisticalFormulaStDevP();
void testStatisticalFormulaCovar();
void testLogicalFormulaAnd();
+ void testMathFormulaSumProduct();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -413,6 +414,7 @@ public:
CPPUNIT_TEST(testStatisticalFormulaStDevP);
CPPUNIT_TEST(testStatisticalFormulaCovar);
CPPUNIT_TEST(testLogicalFormulaAnd);
+ CPPUNIT_TEST(testMathFormulaSumProduct);
CPPUNIT_TEST_SUITE_END();
private:
@@ -4716,6 +4718,42 @@ void ScOpenclTest:: testArrayFormulaSumXMY2()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-214]
+void ScOpenclTest::testMathFormulaSumProduct()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/math/sumproduct_mixSliding.", XLS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/math/sumproduct_mixSliding.", XLS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ // Check the results of formula cells in the shared formula range.
+ for (SCROW i = 0; i <= 9; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(2,i,0));
+ double fExcel = pDocRes->GetValue(ScAddress(2,i,0));
+ if ( i == 1 )
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(82, fLibre, fabs(0.0001*fExcel));
+ else if ( i == 2 )
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(113, fLibre, fabs(0.0001*fExcel));
+ else if ( i == 4 )
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(175, fLibre, fabs(0.0001*fExcel));
+ else if ( i == 5 )
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(206, fLibre, fabs(0.0001*fExcel));
+ else if ( i == 6 )
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(237, fLibre, fabs(0.0001*fExcel));
+ else if ( i == 7 )
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(268, fLibre, fabs(0.0001*fExcel));
+ else
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ xDocSh->DoClose();
+ xDocShRes->DoClose();
+}
//[AMLOEXT-217]
void ScOpenclTest:: testLogicalFormulaAnd()
{
commit e7c752b9903c4e056ebbd9ee0ac5035aeeeb1637
Author: yiming ju <yiming at multicorewareinc.com>
Date: Sun Nov 17 18:58:23 2013 +0800
GPU Calc: implemented SUMPRODUCT WITH FIXED WINDOWS
AMLOEXT-214 FIX
Change-Id: Ifb2797899ec30f998a2387ce9c5752c8e8a03b79
Signed-off-by: haochen <haochen at multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 8c63199..dfb2037 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -808,6 +808,8 @@ public:
const std::string sSymName, SubArguments &vSubArguments)
{
size_t nCurWindowSize = 0;
+ FormulaToken *tmpCur = NULL;
+ const formula::DoubleVectorRefToken *pCurDVR = NULL;
ss << "\ndouble " << sSymName;
ss << "_"<< BinFuncName() <<"(";
for (unsigned i = 0; i < vSubArguments.size(); i++)
@@ -816,15 +818,50 @@ public:
ss << ",";
vSubArguments[i]->GenSlidingWindowDecl(ss);
size_t nCurChildWindowSize = vSubArguments[i]->GetWindowSize();
- nCurWindowSize = (nCurWindowSize < nCurChildWindowSize) ?
+ nCurWindowSize = (nCurWindowSize < nCurChildWindowSize)?
nCurChildWindowSize:nCurWindowSize;
+ tmpCur = vSubArguments[i]->GetFormulaToken();
+ if ( ocPush==tmpCur->GetOpCode() )
+ {
+
+ pCurDVR = dynamic_cast<
+ const formula::DoubleVectorRefToken*>(tmpCur);
+ if ( !
+ ( (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ || (pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) )
+ )
+ throw Unhandled();
+ }
+
}
- ss << ") {\n\t";
- ss << "double tmp = 0.0;\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- ss << "for (int i = 0; i <" << nCurWindowSize << "; i++){\n\t\t";
- ss << "int currentCount = i+gid0+1;\n";
- ss << "tmp += ";
+ ss << ") {\n";
+ ss << " double tmp = 0.0;\n";
+ ss << " int gid0 = get_global_id(0);\n";
+ ss << " int i ;\n";
+ ss << " for (i = 0; i < "<< nCurWindowSize <<"; i++)\n";
+ ss << " {\n";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ tmpCur = vSubArguments[i]->GetFormulaToken();
+ if(ocPush==tmpCur->GetOpCode())
+ {
+ pCurDVR= dynamic_cast<
+ const formula::DoubleVectorRefToken *>(tmpCur);
+ if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss << " int currentCount";
+ ss << i;
+ ss <<" =i+gid0+1;\n";
+ }
+ else
+ {
+ ss << " int currentCount";
+ ss << i;
+ ss << " =i+1;\n";
+ }
+ }
+ }
+ ss << " tmp += ";
for (unsigned i = 0; i < vSubArguments.size(); i++)
{
if (i)
@@ -833,7 +870,9 @@ public:
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss <<"(";
- ss <<"(currentCount>";
+ ss <<"(currentCount";
+ ss << i;
+ ss<< ">";
if(vSubArguments[i]->GetFormulaToken()->GetType() ==
formula::svSingleVectorRef)
{
@@ -850,7 +889,7 @@ public:
(vSubArguments[i]->GetFormulaToken());
ss<<pSVR->GetArrayLength();
}
- ss << ")&&isNan("<<vSubArguments[i]
+ ss << ")||isNan("<<vSubArguments[i]
->GenSlidingWindowDeclRef(true);
ss << ")?0:";
ss << vSubArguments[i]->GenSlidingWindowDeclRef(true);
commit 7f723c49b1f64253c8e43f5d5093e5f9700ec5de
Author: minwang <min at multicorewareinc.com>
Date: Sun Nov 17 14:26:52 2013 +0800
GPU Calc: unit test cases for AND
Turn NO_FALLBACK_TO_SWINTERP on in formulagroupcl.cxx for test
AMLOEXT-217 BUG
Change-Id: I768e3b58e37d56c527f364aab54b88ecfe8c0907
Signed-off-by: haochen <haochen at multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
diff --git a/sc/qa/unit/data/xls/opencl/logical/and.xls b/sc/qa/unit/data/xls/opencl/logical/and.xls
new file mode 100644
index 0000000..19ae64b
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/logical/and.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index c81b50d..437602a 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -241,6 +241,7 @@ public:
void testArrayFormulaSumXMY2();
void testStatisticalFormulaStDevP();
void testStatisticalFormulaCovar();
+ void testLogicalFormulaAnd();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -411,6 +412,7 @@ public:
CPPUNIT_TEST(testArrayFormulaSumXMY2);
CPPUNIT_TEST(testStatisticalFormulaStDevP);
CPPUNIT_TEST(testStatisticalFormulaCovar);
+ CPPUNIT_TEST(testLogicalFormulaAnd);
CPPUNIT_TEST_SUITE_END();
private:
@@ -4714,6 +4716,34 @@ void ScOpenclTest:: testArrayFormulaSumXMY2()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-217]
+void ScOpenclTest:: testLogicalFormulaAnd()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/logical/and.", XLS);
+ ScDocument *pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/logical/and.", XLS);
+ ScDocument *pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ for (SCROW i = 1; i <= 20; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(2, i, 0));
+ double fExcel = pDocRes->GetValue(ScAddress(2, i, 0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ for (SCROW i = 1; i <= 20; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(3, i, 0));
+ double fExcel = pDocRes->GetValue(ScAddress(3, 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/tool/token.cxx b/sc/source/core/tool/token.cxx
index 28c0721..46af6e9 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1469,6 +1469,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocSumXMY2:
case ocStDevP:
case ocCovar:
+ case ocAnd:
// Don't change the state.
break;
default:
commit a36bdd6b62202a7f9e8bf606c9aefffadd9fad50
Author: minwang <min at multicorewareinc.com>
Date: Sun Nov 17 14:38:12 2013 +0800
GPU Calc: implemented for AND
AMLOEXT-217 FIX
Change-Id: I95454c6e390ddc856b9a08d1db5a7a696a3928aa
Signed-off-by: haochen <haochen at multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk
index d82da7d..8cd590e 100644
--- a/sc/Library_scopencl.mk
+++ b/sc/Library_scopencl.mk
@@ -44,6 +44,7 @@ $(eval $(call gb_Library_add_exception_objects,scopencl,\
sc/source/core/opencl/op_math \
sc/source/core/opencl/op_statistical \
sc/source/core/opencl/op_array \
+ sc/source/core/opencl/op_logical \
sc/source/core/opencl/clcc/clew \
))
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index d08c35a..8c63199 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -21,6 +21,7 @@
#include "op_financial.hxx"
#include "op_database.hxx"
#include "op_math.hxx"
+#include "op_logical.hxx"
#include "op_statistical.hxx"
#include "op_array.hxx"
#include "formulagroupcl_public.hxx"
@@ -1792,6 +1793,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpCovar));
break;
+ case ocAnd:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpAnd));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_logical.cxx b/sc/source/core/opencl/op_logical.cxx
new file mode 100644
index 0000000..dd455ec
--- /dev/null
+++ b/sc/source/core/opencl/op_logical.cxx
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "op_logical.hxx"
+
+#include "formulagroup.hxx"
+#include "document.hxx"
+#include "formulacell.hxx"
+#include "tokenarray.hxx"
+#include "compiler.hxx"
+#include "interpre.hxx"
+#include "formula/vectortoken.hxx"
+#include <sstream>
+
+
+using namespace formula;
+
+namespace sc { namespace opencl {
+void OpAnd::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 t = 1,tmp=0;\n";
+ for(unsigned int j = 0; j< vSubArguments.size(); j++)
+ {
+ ss << " double tmp"<<j<<" = 1;\n";
+ FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
+ if(tmpCur0->GetType() == formula::svSingleVectorRef)
+ {
+#ifdef ISNAN
+ const formula::SingleVectorRefToken*pCurDVR= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ ss<< " int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
+ ss<< ";\n";
+ ss <<" if(gid0 >= buffer_len"<<j<<" || isNan(";
+ ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" tmp = 1;\n else\n";
+#endif
+ ss <<" tmp = ";
+ ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+ ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
+ }
+ else if(tmpCur0->GetType() == formula::svDouble)
+ {
+ ss <<" tmp = ";
+ ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+ ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
+ }
+ else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
+ {
+ const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(tmpCur0);
+ size_t nCurWindowSize = pCurDVR->GetArrayLength() <
+ pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
+ pCurDVR->GetRefRowSize() ;
+ ss << " for(int i = ";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+ ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
+ }
+ else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
+ ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
+ }
+ else{
+ ss << "0; i < " << nCurWindowSize << "; i++) {\n";
+ }
+#ifdef ISNAN
+ if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
+ ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
+ ss <<")\n";
+ ss <<" tmp = 1;\n else\n";
+ }
+ else
+ {
+ ss <<" if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
+ ss <<")||i>="<<pCurDVR->GetArrayLength();
+ ss <<")\n";
+ ss <<" tmp = 1;\n else\n";
+ }
+#endif
+ ss <<" tmp = ";
+ ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+ ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
+ ss <<" }\n";
+ }
+ ss <<" t = t && tmp"<<j<<";\n";
+ }
+ ss << " return t;\n";
+ ss << "}\n";
+}
+}}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_logical.hxx b/sc/source/core/opencl/op_logical.hxx
new file mode 100644
index 0000000..3015830a5
--- /dev/null
+++ b/sc/source/core/opencl/op_logical.hxx
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef SC_OPENCL_OP_LOGICAL_HXX
+#define SC_OPENCL_OP_LOGICAL_HXX
+
+#include "opbase.hxx"
+
+
+namespace sc { namespace opencl {
+
+class OpAnd: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "And"; }
+};
+}}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list