sc/inc/formulacell.hxx              |    7 ++++-
 sc/source/core/data/formulacell.cxx |   28 ++++++++++++++++++---
 sc/source/core/tool/token.cxx       |   48 ++++++++++--------------------------
 3 files changed, 45 insertions(+), 38 deletions(-)

New commits:
commit e0e21f2747c19dae13332f4e59949c717aa114f3
Author: Luboš Luňák <l.lu...@collabora.com>
Date:   Fri Jun 15 18:22:12 2018 +0200

    clean up calc'c choosing between threading and OpenCL
    
    Now there's just one place to decide what is used first,
    in InterpretFormulaGroup(). Place in other places now checks both threading
    and OpenCL, which should be cheap, but it also allows e.g. falling
    back from OpenCL to threading if it doesn't work out for a specific
    formula group.
    
    Change-Id: I0cac55197c5278174d303691c20f77b842995c84
    Reviewed-on: https://gerrit.libreoffice.org/55885
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Tested-by: Jenkins

diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index cee9fec13fc2..78eb1f6265b8 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -27,6 +27,7 @@
 
 #include "types.hxx"
 #include "interpretercontext.hxx"
+#include "formulalogger.hxx"
 #include "formularesult.hxx"
 
 namespace sc {
@@ -140,6 +141,11 @@ private:
         const sc::RefUpdateContext& rCxt, ScDocument* pUndoDoc, const 
ScAddress* pUndoCellPos );
 
     ScFormulaCell( const ScFormulaCell& ) = delete;
+
+    bool InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope& aScope);
+    bool InterpretFormulaGroupOpenCL(sc::FormulaLogger::GroupScope& aScope);
+    bool InterpretInvariantFormulaGroup();
+
 public:
 
 
@@ -417,7 +423,6 @@ public:
     CompareState CompareByTokenArray( const ScFormulaCell& rOther ) const;
 
     bool InterpretFormulaGroup();
-    bool InterpretInvariantFormulaGroup();
 
     // nOnlyNames may be one or more of SC_LISTENING_NAMES_*
     void StartListeningTo( ScDocument* pDoc );
diff --git a/sc/source/core/data/formulacell.cxx 
b/sc/source/core/data/formulacell.cxx
index 6dda20b6a3b5..5378d0084c31 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -4385,8 +4385,6 @@ bool ScFormulaCell::InterpretFormulaGroup()
         return false;
     }
 
-    static const bool bThreadingProhibited = 
std::getenv("SC_NO_THREADED_CALCULATION");
-
     // To temporarily use threading for sc unit tests regardless of the size 
of the formula group,
     // add the condition !std::getenv("LO_TESTNAME") below (with &&)
     if (GetWeight() < 
ScInterpreter::GetGlobalConfig().mnOpenCLMinimumFormulaGroupSize)
@@ -4409,7 +4407,25 @@ bool ScFormulaCell::InterpretFormulaGroup()
     // ScFormulaCell::InterpretTail()
     RecursionCounter aRecursionCounter( pDocument->GetRecursionHelper(), this);
 
-    if (!bThreadingProhibited && !ScCalcConfig::isOpenCLEnabled() &&
+    // Preference order:
+    // First try OpenCL, but only if actual OpenCL is available (i.e. no 
SwInterpreter).
+    // Then try threading and as the last one try SwInterpreter.
+    if( ScCalcConfig::isOpenCLEnabled())
+        if( InterpretFormulaGroupOpenCL(aScope))
+            return true;
+
+    if( InterpretFormulaGroupThreading(aScope))
+        return true;
+
+    return InterpretFormulaGroupOpenCL(aScope);
+}
+
+
+// To be called only from InterpretFormulaGroup().
+bool 
ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope& 
aScope)
+{
+    static const bool bThreadingProhibited = 
std::getenv("SC_NO_THREADED_CALCULATION");
+    if (!bThreadingProhibited &&
         pCode->IsEnabledForThreading() &&
         ScCalcConfig::isThreadingEnabled())
     {
@@ -4519,6 +4535,12 @@ bool ScFormulaCell::InterpretFormulaGroup()
         return true;
     }
 
+    return false;
+}
+
+// To be called only from InterpretFormulaGroup().
+bool ScFormulaCell::InterpretFormulaGroupOpenCL(sc::FormulaLogger::GroupScope& 
aScope)
+{
     bool bCanVectorize = pCode->IsEnabledForOpenCL();
     switch (pCode->GetVectorState())
     {
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 08989651f278..89cd1d4cc086 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1325,9 +1325,6 @@ void ScTokenArray::CheckForThreading( OpCode eOp  )
         ocExternal
     });
 
-    // We only call this if it was already disabled
-    assert(IsFormulaVectorDisabled());
-
     // Don't enable threading once we decided to disable it.
     if (!mbThreadingEnabled)
         return;
@@ -1342,9 +1339,6 @@ void ScTokenArray::CheckForThreading( OpCode eOp  )
                 << "(" << int(eOp) << ") disables threaded calculation of 
formula group");
             mbThreadingEnabled = false;
         }
-        else
-            SAL_INFO("sc.core.formulagroup", "but enabling for threading 
instead");
-
     }
     else
         mbThreadingEnabled = false;
@@ -1352,16 +1346,14 @@ void ScTokenArray::CheckForThreading( OpCode eOp  )
 
 void ScTokenArray::CheckToken( const FormulaToken& r )
 {
-    if (IsFormulaVectorDisabled())
-    {
-        if (mbThreadingEnabled)
-            CheckForThreading(r.GetOpCode());
-        // It's already disabled.  No more checking needed.
-        return;
-    }
-
     OpCode eOp = r.GetOpCode();
 
+    if (mbThreadingEnabled)
+        CheckForThreading(eOp);
+
+    if (IsFormulaVectorDisabled())
+        return; // It's already disabled.  No more checking needed.
+
     if (SC_OPCODE_START_FUNCTION <= eOp && eOp < SC_OPCODE_STOP_FUNCTION)
     {
         if (ScInterpreter::GetGlobalConfig().mbOpenCLSubsetOnly &&
@@ -1371,7 +1363,6 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                 << "(" << int(eOp) << ") disables vectorisation for formula 
group");
             meVectorState = FormulaVectorDisabledNotInSubSet;
             mbOpenCLEnabled = false;
-            CheckForThreading(eOp);
             return;
         }
 
@@ -1385,7 +1376,6 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                 << "(" << int(eOp) << ") disables S/W interpreter for formula 
group");
             meVectorState = FormulaVectorDisabledNotInSoftwareSubset;
             mbOpenCLEnabled = false;
-            CheckForThreading(eOp);
             return;
         }
 
@@ -1571,6 +1561,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                     << "(" << int(eOp) << ") disables vectorisation for 
formula group");
                 meVectorState = FormulaVectorDisabledByOpCode;
                 mbOpenCLEnabled = false;
+                return;
         }
     }
     else if (eOp == ocPush)
@@ -1611,8 +1602,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                 SAL_INFO("sc.opencl", "opcode ocPush: variable type " << 
StackVarEnumToString(r.GetType()) << " disables vectorisation for formula 
group");
                 meVectorState = FormulaVectorDisabledByStackVariable;
                 mbOpenCLEnabled = false;
-                CheckForThreading(eOp);
-            break;
+                return;
             default:
                 ;
         }
@@ -1626,7 +1616,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                 << "(" << int(eOp) << ") disables vectorisation for formula 
group");
             meVectorState = FormulaVectorDisabledNotInSubSet;
             mbOpenCLEnabled = false;
-            CheckForThreading(eOp);
+            return;
         }
         // only when openCL interpreter is not enabled - the assumption is that
         // the S/W interpreter blacklist is more strict
@@ -1638,7 +1628,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                 << "(" << int(eOp) << ") disables S/W interpreter for formula 
group");
             meVectorState = FormulaVectorDisabledNotInSoftwareSubset;
             mbOpenCLEnabled = false;
-            CheckForThreading(eOp);
+            return;
         }
     }
     else
@@ -1674,8 +1664,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
                     << "(" << int(eOp) << ") disables vectorisation for 
formula group");
                 meVectorState = FormulaVectorDisabledByOpCode;
                 mbOpenCLEnabled = false;
-                CheckForThreading(eOp);
-            break;
+                return;
 
             // Known good, don't change state.
             case ocStop:
@@ -1827,18 +1816,9 @@ void ScTokenArray::GenHash()
 
 void ScTokenArray::ResetVectorState()
 {
-    if(ScCalcConfig::isOpenCLEnabled())
-    {
-        meVectorState = FormulaVectorEnabled;
-        mbOpenCLEnabled = true;
-        mbThreadingEnabled = false;
-    }
-    else
-    {
-        meVectorState = FormulaVectorDisabled;
-        mbOpenCLEnabled = false;
-        mbThreadingEnabled = ScCalcConfig::isThreadingEnabled();
-    }
+    mbOpenCLEnabled = ScCalcConfig::isOpenCLEnabled() || 
ScCalcConfig::isSwInterpreterEnabled();
+    meVectorState = mbOpenCLEnabled ? FormulaVectorEnabled : 
FormulaVectorDisabled;
+    mbThreadingEnabled = ScCalcConfig::isThreadingEnabled();
 }
 
 bool ScTokenArray::IsFormulaVectorDisabled() const
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to