Kaydet (Commit) 25fb3d74 authored tarafından Tor Lillqvist's avatar Tor Lillqvist Kaydeden (comit) Michael Meeks

WIP: Background ahead-of-time OpenCL compilation

Change-Id: I6e9906fb68a22eb0adab753726ec0d62dd05fe9b
üst 3e8df9eb
......@@ -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 ?
......
......@@ -59,6 +59,7 @@ const sal_uInt16 MatrixEdgeOpen = 32;
enum GroupCalcState
{
GroupCalcEnabled,
GroupCalcOpenCLKernelCompilationScheduled,
GroupCalcOpenCLKernelBinaryCreated,
GroupCalcRunning,
GroupCalcDisabled
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment