diff options
author | Tor Lillqvist <tml@collabora.com> | 2013-11-13 18:06:32 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2013-11-20 18:23:05 +0000 |
commit | 25fb3d749c3184b96c79352be4990c9b4fa6c602 (patch) | |
tree | 21f776990e73bbbf140103b4c236478fd53665e6 /sc | |
parent | 3e8df9eb9535349b2bbb1394794cffcae4b067ac (diff) |
WIP: Background ahead-of-time OpenCL compilation
Change-Id: I6e9906fb68a22eb0adab753726ec0d62dd05fe9b
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/formulacell.hxx | 15 | ||||
-rw-r--r-- | sc/inc/types.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/opencl/formulagroupcl.cxx | 18 | ||||
-rw-r--r-- | sc/source/core/tool/clkernelthread.cxx | 9 |
5 files changed, 39 insertions, 7 deletions
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 68648fc1049a..656eebb49ac4 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 170434124163..fc0e0e85c07b 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 a864b1d7be9d..321c6af4ea3f 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 bf3c1d3f5567..d4862eaddbea 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -2659,8 +2659,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 b89312b26678..7404a803295f 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"); |