[Libreoffice-commits] core.git: Branch 'private/kohei/calc-group-interpreter-4-dynamic-kernels-reviewed' - 5 commits - sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Oct 29 05:15:51 CET 2013


 sc/source/core/opencl/OPBase.hxx                  |   11 +++
 sc/source/core/opencl/OP_Statistical.cxx          |   13 ++-
 sc/source/core/opencl/OP_database.cxx             |   13 +++
 sc/source/core/opencl/OP_finacial.cxx             |   11 +++
 sc/source/core/opencl/OP_math.cxx                 |   13 +++
 sc/source/core/opencl/formulagroupcl.cxx          |   80 ++++++++++++----------
 sc/source/core/opencl/formulagroupcl_finacial.hxx |   25 +++++-
 sc/source/core/opencl/formulagroupcl_public.hxx   |   18 ++++
 8 files changed, 139 insertions(+), 45 deletions(-)

New commits:
commit 1a92083144a704fd2214671c4083373f57bec7aa
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Oct 29 00:01:05 2013 -0400

    Add missing boilerplates.
    
    Change-Id: Iec0e62d650c81e5c8382b8db8946ac5f982fefe5

diff --git a/sc/source/core/opencl/OPBase.hxx b/sc/source/core/opencl/OPBase.hxx
index 119fe76..42ca8e6 100644
--- a/sc/source/core/opencl/OPBase.hxx
+++ b/sc/source/core/opencl/OPBase.hxx
@@ -1,3 +1,12 @@
+/* -*- 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 OPBASE
 #define OPBASE
 #include "formulagroup.hxx"
@@ -184,3 +193,5 @@ public:
 }}
 
 #endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/OP_Statistical.cxx b/sc/source/core/opencl/OP_Statistical.cxx
index 729b0a7..9dc233b 100644
--- a/sc/source/core/opencl/OP_Statistical.cxx
+++ b/sc/source/core/opencl/OP_Statistical.cxx
@@ -1,3 +1,12 @@
+/* -*- 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 OP_STATISTICAL
 #define OP_STATISTICAL
 #include "formulagroup.hxx"
@@ -726,3 +735,4 @@ class OpRsq:public Normal{
 }}
 #endif
 
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/OP_database.cxx b/sc/source/core/opencl/OP_database.cxx
index d7f6309..e553933 100644
--- a/sc/source/core/opencl/OP_database.cxx
+++ b/sc/source/core/opencl/OP_database.cxx
@@ -1,3 +1,12 @@
+/* -*- 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 OP_DATABASE
 #define OP_DATABASE
 #include "formulagroup.hxx"
@@ -18,4 +27,6 @@ using namespace formula;
 namespace sc { namespace opencl {
 
 }}
-#endif
\ No newline at end of file
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/OP_finacial.cxx b/sc/source/core/opencl/OP_finacial.cxx
index a5ec76d..e752528 100644
--- a/sc/source/core/opencl/OP_finacial.cxx
+++ b/sc/source/core/opencl/OP_finacial.cxx
@@ -1,3 +1,12 @@
+/* -*- 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 OP_FINACIAL
 #define OP_FINACIAL
 #include "formulagroup.hxx"
@@ -2903,3 +2912,5 @@ class OpMIRR: public MIRR{
 }
 }
 #endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/OP_math.cxx b/sc/source/core/opencl/OP_math.cxx
index 486df5a..c22a838 100644
--- a/sc/source/core/opencl/OP_math.cxx
+++ b/sc/source/core/opencl/OP_math.cxx
@@ -1,3 +1,12 @@
+/* -*- 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 OP_MATH
 #define OP_MATH
 #include "formulagroup.hxx"
@@ -84,4 +93,6 @@ public:
  virtual std::string BinFuncName(void) const { return "Csc"; }
 };
 }}
-#endif
\ No newline at end of file
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/formulagroupcl_finacial.hxx b/sc/source/core/opencl/formulagroupcl_finacial.hxx
index 338a38d..a8db8e9 100644
--- a/sc/source/core/opencl/formulagroupcl_finacial.hxx
+++ b/sc/source/core/opencl/formulagroupcl_finacial.hxx
@@ -1,3 +1,15 @@
+/* -*- 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_FORMULAGROUPCL_FINACIAL_HXX
+#define SC_OPENCL_FORMULAGROUPCL_FINACIAL_HXX
+
 const char* finacialFunc =
 "bool approxEqual(double a, double b)\n"
 "{\n"
@@ -741,3 +753,6 @@ const char* finacialFunc =
 "    return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), nDay2, nMonth2, nYear2, bUSAMethod );\n"
 "}\n";
 
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/formulagroupcl_public.hxx b/sc/source/core/opencl/formulagroupcl_public.hxx
index b0dc13c..996c898 100644
--- a/sc/source/core/opencl/formulagroupcl_public.hxx
+++ b/sc/source/core/opencl/formulagroupcl_public.hxx
@@ -1,3 +1,15 @@
+/* -*- 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_FORMULAGROUPCL_PUBLIC_HXX
+#define SC_OPENCL_FORMULAGROUPCL_PUBLIC_HXX
+
 const char* publicFunc =
  "int isNan(double a) { return a != a; }\n"
  "double fsum(double a, double b) { return isNan(a)?b:a+b; }\n"
@@ -5,3 +17,7 @@ const char* publicFunc =
  "double fdiv(double a, double b) { return a/b; }\n"
  "double strequal(unsigned a, unsigned b) { return (a==b)?1.0:0; }\n"
  ;
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f7038bfcfb53093a266bab38818c3d883f263775
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Oct 28 23:59:02 2013 -0400

    Fix compiler warnings for unused variables and non-const char* declaration.
    
    Change-Id: I52d9285d5f42d2001be4464a192bf8f4481b56fd

diff --git a/sc/source/core/opencl/OP_Statistical.cxx b/sc/source/core/opencl/OP_Statistical.cxx
index cece203..729b0a7 100644
--- a/sc/source/core/opencl/OP_Statistical.cxx
+++ b/sc/source/core/opencl/OP_Statistical.cxx
@@ -88,9 +88,6 @@ class OpGamma:public Normal{
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
     {
-        FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
-        const formula::SingleVectorRefToken*tmpCurDVR= dynamic_cast<const
-              formula::SingleVectorRefToken *>(tmpCur);
         ss << "\ndouble " << sSymName;
         ss << "_"<< BinFuncName() <<"(";
         for (unsigned i = 0; i < vSubArguments.size(); i++)
diff --git a/sc/source/core/opencl/formulagroupcl_finacial.hxx b/sc/source/core/opencl/formulagroupcl_finacial.hxx
index 64a65bb..338a38d 100644
--- a/sc/source/core/opencl/formulagroupcl_finacial.hxx
+++ b/sc/source/core/opencl/formulagroupcl_finacial.hxx
@@ -1,4 +1,4 @@
-char* finacialFunc =
+const char* finacialFunc =
 "bool approxEqual(double a, double b)\n"
 "{\n"
     "\tif (a == b)\n"
diff --git a/sc/source/core/opencl/formulagroupcl_public.hxx b/sc/source/core/opencl/formulagroupcl_public.hxx
index 5599aab..b0dc13c 100644
--- a/sc/source/core/opencl/formulagroupcl_public.hxx
+++ b/sc/source/core/opencl/formulagroupcl_public.hxx
@@ -1,4 +1,4 @@
-char* publicFunc = 
+const char* publicFunc =
  "int isNan(double a) { return a != a; }\n"
  "double fsum(double a, double b) { return isNan(a)?b:a+b; }\n"
  "double fsub(double a, double b) { return a-b; }\n"
commit 488d1eb36093ce86dfe9b4608213c8a42931e582
Author: haochen <haochen at multicorewareinc.com>
Date:   Sat Oct 26 19:20:18 2013 +0800

    Fix compilation problems on AMD OCL of finaancial functions
    
    In AMD(HSA/NHSA) GPU compiler not support expressions like -double/double,
    must generate as -1*(double/double). Changed functions: COUPDAYS,
    COUPDAYBS, YIELD.
    
    Change-Id: I8aeedd62073283375c46e97d60db36a1aad85170
    
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/formulagroupcl_finacial.hxx b/sc/source/core/opencl/formulagroupcl_finacial.hxx
index 7d83dc1..64a65bb 100644
--- a/sc/source/core/opencl/formulagroupcl_finacial.hxx
+++ b/sc/source/core/opencl/formulagroupcl_finacial.hxx
@@ -316,7 +316,7 @@ char* finacialFunc =
     "}\n"
     "while(aDate > nSettle )\n"
     "{\n"
-        "addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-12/nFreq,&rYear);\n"
+        "addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear);\n"
         "aDate=DateToDays( rDay,rMonth,rYear );\n"
     "}\n"
     "return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, rbLastDay, rb30Days, rbUSMode, rnDay,\n"
@@ -341,7 +341,7 @@ char* finacialFunc =
     "}\n"
     "while(aDate > nSettle )\n"
     "{\n"
-        "addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-12/nFreq,&rYear);\n"
+        "addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear);\n"
         "aDate=DateToDays( rDay,rMonth,rYear );\n"
     "}\n"
     "int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
@@ -364,7 +364,7 @@ char* finacialFunc =
     "if( aDate < nSettle )\n"
         "rYear+= 1;\n"
     "int d=DateToDays( rDay,rMonth,rYear );\n"
-    "int nMonthCount=-12 / nFreq;\n"
+    "int nMonthCount=-1*(12 / nFreq);\n"
     "while(d > nSettle )\n"
     "{\n"
         "int nNewMonth = nMonthCount + rMonth;\n"
@@ -419,7 +419,7 @@ char* finacialFunc =
         "aDate=DateToDays( rDay,rMonth,rYear );\n"
         "if( aDate > nSettle )\n"
         "{\n"  
-        "rYear+= -1;\n"
+        "rYear-= 1;\n"
         "aDate=DateToDays( rDay,rMonth,rYear );\n"
 "}\n"
 "while(aDate <= nSettle )\n"
commit 934927eb8e662cc3af2df988439988a086db97cf
Author: I-Jui (Ray) Sung <ray at multicorewareinc.com>
Date:   Mon Oct 28 20:19:02 2013 -0500

    Cache compiled kernels in GPU Calc dynamic kernel compiler
    
    Change-Id: I21cd3d22998c814152272b1f7c865c03d17a2cec

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index d11adc8..741850d 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1170,19 +1170,20 @@ public:
     std::string GetMD5(void)
     {
 #ifdef MD5_KERNEL
-        if(mKernelSignature.empty()) {
+        if (mKernelHash.empty()) {
             std::stringstream md5s;
             // Compute MD5SUM of kernel body to obtain the name
             sal_uInt8 result[RTL_DIGEST_LENGTH_MD5];
-            rtlDigestError err = rtl_digest_MD5(
-                mKernelSrc.str().c_str(), mKernelSrc.str().length(), result,
+            rtl_digest_MD5(
+                mFullProgramSrc.c_str(),
+                mFullProgramSrc.length(), result,
                 RTL_DIGEST_LENGTH_MD5);
             for(int i=0; i < RTL_DIGEST_LENGTH_MD5; i++) {
                 md5s << std::hex << (int)result[i];
             }
-            mKernelSignature = md5s.str();
+            mKernelHash = md5s.str();
         }
-        return mKernelSignature;
+        return mKernelHash;
 #else
         return "";
 #endif
@@ -1190,7 +1191,7 @@ public:
     /// Create program, build, and create kerenl
     /// TODO cache results based on kernel body hash
     /// TODO: abstract OpenCL part out into OpenCL wrapper.
-    bool CreateKernel(void);
+    void CreateKernel(void);
     /// Prepare buffers, marshal them to GPU, and launch the kernel
     /// TODO: abstract OpenCL part out into OpenCL wrapper.
     void Launch(size_t nr)
@@ -1222,8 +1223,7 @@ private:
     void TraverseAST(std::shared_ptr<FormulaTreeNode>);
     std::shared_ptr<FormulaTreeNode> mpRoot;
     SymbolTable mSyms;
-    std::stringstream mKernelSrc;
-    std::string mKernelSignature;
+    std::string mKernelSignature, mKernelHash;
     std::string mFullProgramSrc;
     cl_program mpProgram;
     cl_kernel mpKernel;
@@ -1246,7 +1246,7 @@ DynamicKernel::~DynamicKernel()
     }
 }
 /// Build code
-bool DynamicKernel::CreateKernel(void)
+void DynamicKernel::CreateKernel(void)
 {
     cl_int err;
     std::string kname = "DynamicKernel"+mKernelSignature;
@@ -1255,16 +1255,27 @@ bool DynamicKernel::CreateKernel(void)
     KernelEnv kEnv;
     OclCalc::setKernelEnv(&kEnv);
     const char *src = mFullProgramSrc.c_str();
-    mpProgram = clCreateProgramWithSource(kEnv.mpkContext, 1,
-            &src, NULL, &err);
-    if (err != CL_SUCCESS)
-        return true;
-    err = clBuildProgram(mpProgram, 1,
-            OpenclDevice::gpuEnv.mpArryDevsID, "", NULL, NULL);
-    if (err != CL_SUCCESS)
-        return true;
+    if (OpenclDevice::buildProgramFromBinary("",
+        &OpenclDevice::gpuEnv,
+        (mKernelSignature+GetMD5()).c_str(), 0)) {
+        mpProgram = OpenclDevice::gpuEnv.mpArryPrograms[0];
+        OpenclDevice::gpuEnv.mpArryPrograms[0] = NULL;
+    } else {
+        mpProgram = clCreateProgramWithSource(kEnv.mpkContext, 1,
+                &src, NULL, &err);
+        if (err != CL_SUCCESS)
+            throw OpenCLError(err);
+        err = clBuildProgram(mpProgram, 1,
+                OpenclDevice::gpuEnv.mpArryDevsID, "", NULL, NULL);
+        if (err != CL_SUCCESS)
+            throw OpenCLError(err);
+        // Generate binary out of compiled kernel.
+        OpenclDevice::generatBinFromKernelSource(mpProgram,
+                (mKernelSignature+GetMD5()).c_str());
+    }
     mpKernel = clCreateKernel(mpProgram, kname.c_str(), &err);
-    return (err != CL_SUCCESS);
+    if (err != CL_SUCCESS)
+        throw OpenCLError(err);
 }
 // Symbol lookup. If there is no such symbol created, allocate one
 // kernel with argument with unique name and return so.
@@ -1379,9 +1390,7 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc,
         KernelEnv kEnv;
         OclCalc::setKernelEnv(&kEnv);
         // Compile kernel here!!!
-        if (mpKernel->CreateKernel()) {
-            std::cerr << "Cannot create kernel\n";
-        }
+        mpKernel->CreateKernel();
         // Run the kernel.
         mpKernel->Launch(xGroup->mnLength);
         // Map results back
commit c2b0254ac3a0809cff83a515dbe9c4b750083452
Author: I-Jui (Ray) Sung <ray at multicorewareinc.com>
Date:   Mon Oct 28 14:34:46 2013 -0500

    Use MD5 in RTL instead of the one from OpenSSL.
    
    Change-Id: I120961da4fd9eb8ddd99e347ed4c266fcb2c7ec6

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 0886980..d11adc8 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -30,8 +30,9 @@
 #include <iostream>
 #include <sstream>
 #include <algorithm>
+#define MD5_KERNEL 1
 #ifdef MD5_KERNEL
-#include <openssl/md5.h>
+#include <rtl/digest.h>
 #endif
 #include <memory>
 using namespace formula;
@@ -1172,10 +1173,11 @@ public:
         if(mKernelSignature.empty()) {
             std::stringstream md5s;
             // Compute MD5SUM of kernel body to obtain the name
-            unsigned char result[MD5_DIGEST_LENGTH];
-             MD5(reinterpret_cast<const unsigned char *>
-                (mKernelSrc.str().c_str()), mKernelSrc.str().length(), result);
-            for(int i=0; i < MD5_DIGEST_LENGTH; i++) {
+            sal_uInt8 result[RTL_DIGEST_LENGTH_MD5];
+            rtlDigestError err = rtl_digest_MD5(
+                mKernelSrc.str().c_str(), mKernelSrc.str().length(), result,
+                RTL_DIGEST_LENGTH_MD5);
+            for(int i=0; i < RTL_DIGEST_LENGTH_MD5; i++) {
                 md5s << std::hex << (int)result[i];
             }
             mKernelSignature = md5s.str();
@@ -1188,26 +1190,7 @@ public:
     /// Create program, build, and create kerenl
     /// TODO cache results based on kernel body hash
     /// TODO: abstract OpenCL part out into OpenCL wrapper.
-    bool CreateKernel(void)
-    {
-        cl_int err;
-        std::string kname = "DynamicKernel"+mKernelSignature;
-        // Compile kernel here!!!
-        // Obtain cl context
-        KernelEnv kEnv;
-        OclCalc::setKernelEnv(&kEnv);
-        const char *src = mFullProgramSrc.c_str();
-        mpProgram = clCreateProgramWithSource(kEnv.mpkContext, 1,
-                &src, NULL, &err);
-        if (err != CL_SUCCESS)
-            return true;
-        err = clBuildProgram(mpProgram, 1,
-                OpenclDevice::gpuEnv.mpArryDevsID, "", NULL, NULL);
-        if (err != CL_SUCCESS)
-            return true;
-        mpKernel = clCreateKernel(mpProgram, kname.c_str(), &err);
-        return (err != CL_SUCCESS);
-    }
+    bool CreateKernel(void);
     /// Prepare buffers, marshal them to GPU, and launch the kernel
     /// TODO: abstract OpenCL part out into OpenCL wrapper.
     void Launch(size_t nr)
@@ -1262,7 +1245,27 @@ DynamicKernel::~DynamicKernel()
         clReleaseProgram(mpProgram);
     }
 }
-
+/// Build code
+bool DynamicKernel::CreateKernel(void)
+{
+    cl_int err;
+    std::string kname = "DynamicKernel"+mKernelSignature;
+    // Compile kernel here!!!
+    // Obtain cl context
+    KernelEnv kEnv;
+    OclCalc::setKernelEnv(&kEnv);
+    const char *src = mFullProgramSrc.c_str();
+    mpProgram = clCreateProgramWithSource(kEnv.mpkContext, 1,
+            &src, NULL, &err);
+    if (err != CL_SUCCESS)
+        return true;
+    err = clBuildProgram(mpProgram, 1,
+            OpenclDevice::gpuEnv.mpArryDevsID, "", NULL, NULL);
+    if (err != CL_SUCCESS)
+        return true;
+    mpKernel = clCreateKernel(mpProgram, kname.c_str(), &err);
+    return (err != CL_SUCCESS);
+}
 // Symbol lookup. If there is no such symbol created, allocate one
 // kernel with argument with unique name and return so.
 // The template argument T must be a subclass of DynamicKernelArgument


More information about the Libreoffice-commits mailing list