[Libreoffice-commits] core.git: 2 commits - sc/Library_scopencl.mk sc/qa sc/source

minwang min at multicorewareinc.com
Sat Nov 16 23:04:36 PST 2013


 sc/Library_scopencl.mk                     |    1 
 sc/qa/unit/data/xls/opencl/logical/and.xls |binary
 sc/qa/unit/opencl-test.cxx                 |   30 +++++++
 sc/source/core/opencl/formulagroupcl.cxx   |    5 +
 sc/source/core/opencl/op_logical.cxx       |  109 +++++++++++++++++++++++++++++
 sc/source/core/opencl/op_logical.hxx       |   29 +++++++
 sc/source/core/tool/token.cxx              |    1 
 7 files changed, 175 insertions(+)

New commits:
commit 1c8701f8b7b5fe287a0d9a1c433504f3f8f88ec3
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 0782883..238cefd 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -239,6 +239,7 @@ public:
     void testArrayFormulaSumXMY2();
     void testStatisticalFormulaStDevP();
     void testStatisticalFormulaCovar();
+    void testLogicalFormulaAnd();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -409,6 +410,7 @@ public:
     CPPUNIT_TEST(testArrayFormulaSumXMY2);
     CPPUNIT_TEST(testStatisticalFormulaStDevP);
     CPPUNIT_TEST(testStatisticalFormulaCovar);
+    CPPUNIT_TEST(testLogicalFormulaAnd);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -4712,6 +4714,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 b8a5095..5dc92e6 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1470,6 +1470,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocSumXMY2:
             case ocStDevP:
             case ocCovar:
+            case ocAnd:
             // Don't change the state.
             break;
             default:
commit 26c759b7dfcbceb295acbb1f895847bcc4dd6cce
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 134afb8..2c0ac16 100644
--- a/sc/Library_scopencl.mk
+++ b/sc/Library_scopencl.mk
@@ -43,6 +43,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 36415e5..85ebdf0 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