[Libreoffice-commits] core.git: Branch 'private/tml/opencl-background-compilation' - sc/inc sc/source
Tor Lillqvist
tml at collabora.com
Wed Nov 13 08:10:49 PST 2013
sc/inc/formulacell.hxx | 15 ++++++++++-----
sc/inc/types.hxx | 1 +
sc/source/core/data/formulacell.cxx | 3 +++
sc/source/core/opencl/formulagroupcl.cxx | 18 ++++++++++++++++--
sc/source/core/tool/clkernelthread.cxx | 9 +++++++++
5 files changed, 39 insertions(+), 7 deletions(-)
New commits:
commit bec94973e236a464dbeef853ba157aead8637799
Author: Tor Lillqvist <tml at collabora.com>
Date: Wed Nov 13 18:06:32 2013 +0200
WIP: Background ahead-of-time OpenCL compilation
Change-Id: I6e9906fb68a22eb0adab753726ec0d62dd05fe9b
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 68648fc..656eebb 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -20,15 +20,19 @@
#ifndef SC_FORMULACELL_HXX
#define SC_FORMULACELL_HXX
-#include "formularesult.hxx"
+#include <set>
+
+#include <boost/noncopyable.hpp>
-#include "formula/tokenarray.hxx"
+#include <formula/tokenarray.hxx>
+#include <osl/conditn.hxx>
+#include <osl/mutex.hxx>
#include <rtl/ref.hxx>
-#include "svl/listener.hxx"
+#include <svl/listener.hxx>
+
#include "types.hxx"
-#include <set>
-#include <boost/noncopyable.hpp>
+#include "formularesult.hxx"
namespace sc {
@@ -54,6 +58,7 @@ struct SC_DLLPUBLIC ScFormulaCellGroup : boost::noncopyable
ScTokenArray* mpCode;
osl::Mutex maMutex;
+ osl::Condition maCompilationDone;
sc::CompiledFormula* mpCompiledFormula;
ScFormulaCell *mpTopCell;
SCROW mnLength; // How many of these do we have ?
diff --git a/sc/inc/types.hxx b/sc/inc/types.hxx
index 1704341..fc0e0e8 100644
--- a/sc/inc/types.hxx
+++ b/sc/inc/types.hxx
@@ -59,6 +59,7 @@ const sal_uInt16 MatrixEdgeOpen = 32;
enum GroupCalcState
{
GroupCalcEnabled,
+ GroupCalcOpenCLKernelCompilationScheduled,
GroupCalcOpenCLKernelBinaryCreated,
GroupCalcRunning,
GroupCalcDisabled
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index f1ed90b..724922b 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -445,9 +445,12 @@ ScFormulaCellGroup::~ScFormulaCellGroup()
void ScFormulaCellGroup::scheduleCompilation()
{
+ osl::ResettableMutexGuard aGuard(maMutex);
+ meCalcState = sc::GroupCalcOpenCLKernelCompilationScheduled;
sc::CLBuildKernelWorkItem aWorkItem;
aWorkItem.meWhatToDo = sc::CLBuildKernelWorkItem::COMPILE;
aWorkItem.mxGroup = this;
+ aGuard.clear();
mxCLKernelThread->push(aWorkItem);
}
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 895bdc4..a1b902e 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1540,8 +1540,22 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc,
const ScAddress& rTopPos, const ScFormulaCellGroupRef& xGroup,
ScTokenArray& rCode )
{
- // printf("Vector width = %d\n", xGroup->mnLength);
- DynamicKernel *pKernel = DynamicKernel::create(rDoc, rTopPos, rCode);
+ DynamicKernel *pKernel;
+
+ osl::ResettableMutexGuard aGuard(xGroup->maMutex);
+ if (xGroup->meCalcState == sc::GroupCalcOpenCLKernelCompilationScheduled)
+ {
+ aGuard.clear();
+ xGroup->maCompilationDone.wait();
+ xGroup->maCompilationDone.reset();
+ pKernel = static_cast<DynamicKernel*>(xGroup->mpCompiledFormula);
+ }
+ else
+ {
+ aGuard.clear();
+ pKernel = DynamicKernel::create(rDoc, rTopPos, rCode);
+ }
+
if (!pKernel)
return false;
diff --git a/sc/source/core/tool/clkernelthread.cxx b/sc/source/core/tool/clkernelthread.cxx
index b89312b..7404a80 100644
--- a/sc/source/core/tool/clkernelthread.cxx
+++ b/sc/source/core/tool/clkernelthread.cxx
@@ -9,6 +9,8 @@
#include <sal/log.hxx>
+#include "formulagroupinterpreter.hxx"
+
#include "clkernelthread.hxx"
using namespace std;
@@ -46,6 +48,13 @@ void CLBuildKernelThread::execute()
{
case CLBuildKernelWorkItem::COMPILE:
SAL_INFO("sc.opencl.thread", "told to compile group " << aWorkItem.mxGroup << " to binary");
+ assert(aWorkItem.mxGroup->meCalcState == sc::GroupCalcOpenCLKernelCompilationScheduled);
+ aWorkItem.mxGroup->mpCompiledFormula =
+ sc::FormulaGroupInterpreter::getStatic()->createCompiledFormula(*aWorkItem.mxGroup->mpTopCell->GetDocument(),
+ aWorkItem.mxGroup->mpTopCell->aPos,
+ *aWorkItem.mxGroup->mpCode);
+ aWorkItem.mxGroup->meCalcState = sc::GroupCalcOpenCLKernelBinaryCreated;
+ aWorkItem.mxGroup->maCompilationDone.set();
break;
case CLBuildKernelWorkItem::FINISH:
SAL_INFO("sc.opencl.thread", "told to finish");
More information about the Libreoffice-commits
mailing list