[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter' - sc/source

Michael Meeks michael.meeks at suse.com
Thu Jul 11 04:17:41 PDT 2013


 sc/source/core/opencl/formulagroupcl.cxx |   22 ++++++++++++++++------
 sc/source/core/opencl/openclwrapper.cxx  |   22 +++++++++++++++-------
 2 files changed, 31 insertions(+), 13 deletions(-)

New commits:
commit 638bc7daacc359de2c3699d52da392e22bbdee77
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Thu Jul 11 12:19:18 2013 +0100

    Prompt the user to delete cached kernels on failure
    
    also fallback to S/W group calculation if necessary.

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 8c2e236..0135c51 100755
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -299,6 +299,8 @@ public:
     }
 
     virtual ScMatrixRef inverseMatrix(const ScMatrix& /* rMat */) { return ScMatrixRef(); }
+    virtual bool interpretCL(ScDocument& rDoc, const ScAddress& rTopPos,
+                             const ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode);
     virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos,
                            const ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode);
 };
@@ -307,12 +309,9 @@ public:
 
 #include "compiler.hxx"
 
-// FIXME: really we should compile the formula and operate on the
-// RPN representation which -should- be more compact and have no Open / Close
-// or precedence issues; cf. rCode.FirstRPN() etc.
-bool FormulaGroupInterpreterGroundwater::interpret(ScDocument& rDoc, const ScAddress& rTopPos,
-                                                   const ScFormulaCellGroupRef& xGroup,
-                                                   ScTokenArray& rCode)
+bool FormulaGroupInterpreterGroundwater::interpretCL(ScDocument& rDoc, const ScAddress& rTopPos,
+                                                     const ScFormulaCellGroupRef& xGroup,
+                                                     ScTokenArray& rCode)
 {
     generateRPNCode(rDoc, rTopPos, rCode);
 
@@ -379,6 +378,17 @@ bool FormulaGroupInterpreterGroundwater::interpret(ScDocument& rDoc, const ScAdd
     return true;
 }
 
+bool FormulaGroupInterpreterGroundwater::interpret(ScDocument& rDoc, const ScAddress& rTopPos,
+                                                   const ScFormulaCellGroupRef& xGroup,
+                                                   ScTokenArray& rCode)
+{
+    bool bComplete = interpretCL(rDoc, rTopPos, xGroup, rCode);
+    if (!bComplete) // fallback to the (potentially) faster S/W formula group interpreter
+        return FormulaGroupInterpreterSoftware::interpret(rDoc, rTopPos, xGroup, rCode);
+    else
+        return true;
+}
+
 namespace opencl {
     sc::FormulaGroupInterpreter *createFormulaGroupInterpreter()
     {
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 781c838..7061f96 100755
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -480,6 +480,7 @@ int OpenclDevice::CompileKernelFile(GPUEnv *gpuInfo, const char *buildOption) {
                 sizeof(cl_device_id) * numDevices, mpArryDevsID, NULL);
         CHECK_OPENCL(status)
 
+        fprintf(stderr, "Create kernel from binary\n");
         gpuInfo->mpArryPrograms[idx] = clCreateProgramWithBinary(gpuInfo->mpContext,
                 numDevices, mpArryDevsID, &length, (const unsigned char**) &binary,
                 &binary_status, &status);
@@ -490,6 +491,7 @@ int OpenclDevice::CompileKernelFile(GPUEnv *gpuInfo, const char *buildOption) {
         mpArryDevsID = NULL;
     } else {
         // create a CL program using the kernel source
+        fprintf(stderr, "Create kernel from source\n");
         gpuEnv.mpArryPrograms[idx] = clCreateProgramWithSource(gpuEnv.mpContext,
                 1, &source, source_size, &status);
         CHECK_OPENCL(status);
@@ -504,21 +506,21 @@ int OpenclDevice::CompileKernelFile(GPUEnv *gpuInfo, const char *buildOption) {
     printf("BuildProgram.\n");
     if (!gpuInfo->mnIsUserCreated) {
         status = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, gpuInfo->mpArryDevsID,
-                buildOption, NULL, NULL);
+                                buildOption, NULL, NULL);
     } else {
         status = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &(gpuInfo->mpDevID),
-                buildOption, NULL, NULL);
+                                buildOption, NULL, NULL);
     }
 
     if (status != CL_SUCCESS) {
         printf ("BuildProgram error!\n");
         if (!gpuInfo->mnIsUserCreated) {
             status = clGetProgramBuildInfo(gpuInfo->mpArryPrograms[idx],
-                    gpuInfo->mpArryDevsID[0], CL_PROGRAM_BUILD_LOG, 0, NULL,
-                    &length);
+                                           gpuInfo->mpArryDevsID[0], CL_PROGRAM_BUILD_LOG, 0, NULL,
+                                           &length);
         } else {
             status = clGetProgramBuildInfo(gpuInfo->mpArryPrograms[idx],
-                    gpuInfo->mpDevID, CL_PROGRAM_BUILD_LOG, 0, NULL, &length);
+                                           gpuInfo->mpDevID, CL_PROGRAM_BUILD_LOG, 0, NULL, &length);
         }
         if (status != CL_SUCCESS) {
             printf("opencl create build log fail\n");
@@ -537,6 +539,10 @@ int OpenclDevice::CompileKernelFile(GPUEnv *gpuInfo, const char *buildOption) {
                     gpuInfo->mpDevID, CL_PROGRAM_BUILD_LOG, length, buildLog,
                     &length);
         }
+        if (status != CL_SUCCESS) {
+            printf("opencl program build info fail\n");
+            return 0;
+        }
 
         fd1 = fopen("kernel-build.log", "w+");
         if (fd1 != NULL) {
@@ -2145,12 +2151,14 @@ double *OclCalc::OclSimpleDeltaOperation(OpCode eOp, const double *pOpArray,
     size_t global_work_size[1];
 
     kEnv.mpkKernel = clCreateKernel(kEnv.mpkProgram, kernelName, &clStatus);
-    CHECK_OPENCL(clStatus);
     if (!kEnv.mpkKernel)
     {
-        fprintf(stderr, "could not clCreateKernel '%s'\n", kernelName);
+        fprintf(stderr, "\n\n*** Error: Could not clCreateKernel '%s' ***\n\n", kernelName);
+        fprintf(stderr, "\tprobably your binary cache is out of date\n"
+                "\tplease delete kernel-*.bin in your cwd\n\n\n");
         return NULL;
     }
+    CHECK_OPENCL(clStatus);
 
     // Ugh - horrible redundant copying ...
     cl_mem valuesCl   = allocateDoubleBuffer(kEnv, pOpArray, nElements, &clStatus);


More information about the Libreoffice-commits mailing list