diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-09-17 12:41:07 -0400 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-09-19 17:03:23 +0200 |
commit | deed1ca901896744a9cf859d390a5a592ba37041 (patch) | |
tree | 8a7ee9c804282d2dc7a44ddb6743841671079887 | |
parent | 82985b9bccbde3c697e73e1930c89634853c8d3c (diff) |
Set up a thread to compile OpenCL kernels during file load.
It's still a no-op & we need to have a smart mechanism to conditionally
trigger it rather than running it in all documents.
Change-Id: Ia875ebb9405b5de5c5d31418de84c5ca7a62f302
-rw-r--r-- | sc/Library_scfilt.mk | 2 | ||||
-rw-r--r-- | sc/inc/formulagroup.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/opencl/formulagroupcl.cxx | 5 | ||||
-rw-r--r-- | sc/source/core/opencl/openclwrapper.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/opencl/openclwrapper.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/formulagroup.cxx | 18 | ||||
-rw-r--r-- | sc/source/filter/excel/excform.cxx | 5 | ||||
-rw-r--r-- | sc/source/filter/excel/read.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/ftools/clkernelthread.cxx | 28 | ||||
-rw-r--r-- | sc/source/filter/inc/clkernelthread.hxx | 26 | ||||
-rw-r--r-- | sc/source/filter/inc/imp_op.hxx | 5 |
11 files changed, 102 insertions, 0 deletions
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk index ddd52a39680d..47172ce82521 100644 --- a/sc/Library_scfilt.mk +++ b/sc/Library_scfilt.mk @@ -45,6 +45,7 @@ $(eval $(call gb_Library_use_libraries,scfilt,\ msfilter \ oox \ sal \ + salhelper \ sax \ sb \ sc \ @@ -124,6 +125,7 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\ sc/source/filter/excel/xltools \ sc/source/filter/excel/xltracer \ sc/source/filter/excel/xlview \ + sc/source/filter/ftools/clkernelthread \ sc/source/filter/ftools/fapihelper \ sc/source/filter/ftools/fprogressbar \ sc/source/filter/ftools/ftools \ diff --git a/sc/inc/formulagroup.hxx b/sc/inc/formulagroup.hxx index bfd4bbc5e543..c6f32ace026b 100644 --- a/sc/inc/formulagroup.hxx +++ b/sc/inc/formulagroup.hxx @@ -56,6 +56,7 @@ class SC_DLLPUBLIC FormulaGroupInterpreter static FormulaGroupInterpreter *getStatic(); static void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms); static void switchOpenCLDevice(const OUString& rDeviceId, bool bAutoSelect); + static void compileKernels(); virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0; virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, const ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) = 0; diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 567d033b16b4..4c29223777e2 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1096,6 +1096,11 @@ SAL_DLLPUBLIC_EXPORT bool SAL_CALL switchOpenClDevice(const OUString* pDeviceId, return sc::opencl::switchOpenclDevice(pDeviceId, bAutoSelect); } +SAL_DLLPUBLIC_EXPORT void compileKernels() +{ + sc::opencl::compileKernels(); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx index 3994029bb687..a0c1e7a49fb7 100644 --- a/sc/source/core/opencl/openclwrapper.cxx +++ b/sc/source/core/opencl/openclwrapper.cxx @@ -2851,6 +2851,10 @@ bool switchOpenclDevice(const OUString* pDevice, bool bAutoSelect) return !OpenclDevice::initOpenclRunEnv(0); } +void compileKernels() +{ +} + }} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx index 057f02b81ca6..30e38386c771 100644 --- a/sc/source/core/opencl/openclwrapper.hxx +++ b/sc/source/core/opencl/openclwrapper.hxx @@ -266,6 +266,8 @@ const std::vector<OpenclPlatformInfo>& fillOpenCLInfo(); */ bool switchOpenclDevice(const OUString* pDeviceId, bool bAutoSelect); +void compileKernels(); + }} #endif diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index dd765a8eb235..c07d280c57a2 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -338,6 +338,7 @@ typedef FormulaGroupInterpreter* (*__createFormulaGroupOpenCLInterpreter)(void); typedef size_t (*__getOpenCLPlatformCount)(void); typedef void (*__fillOpenCLInfo)(OpenclPlatformInfo*, size_t); typedef bool (*__switchOpenClDevice)(const OUString*, bool); +typedef void (*__compileKernels)(void); #endif @@ -457,6 +458,23 @@ void FormulaGroupInterpreter::switchOpenCLDevice(const OUString& rDeviceId, bool #endif } +void FormulaGroupInterpreter::compileKernels() +{ + if (!ScInterpreter::GetGlobalConfig().mbOpenCLEnabled) + // OpenCL is not enabled. + return; + + osl::Module* pModule = getOpenCLModule(); + if (!pModule) + return; + + oslGenericFunction fn = pModule->getFunctionSymbol("compileKernels"); + if (!fn) + return; + + reinterpret_cast<__compileKernels>(fn)(); +} + void FormulaGroupInterpreter::generateRPNCode(ScDocument& rDoc, const ScAddress& rPos, ScTokenArray& rCode) { // First, generate an RPN (reverse polish notation) token array. diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx index c99f67abda70..49ca6ca39e9c 100644 --- a/sc/source/filter/excel/excform.cxx +++ b/sc/source/filter/excel/excform.cxx @@ -136,6 +136,11 @@ void ImportExcel::Formula( } } + if (!mxCLKernelThread.is()) + { + mxCLKernelThread.set(new sc::CLBuildKernelThread); + mxCLKernelThread->launch(); + } ConvErr eErr = pFormConv->Convert( pResult, maStrm, nFormLen, true, FT_CellFormula); ScFormulaCell* pCell = NULL; diff --git a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx index ae8924639d6e..14396f617eb2 100644 --- a/sc/source/filter/excel/read.cxx +++ b/sc/source/filter/excel/read.cxx @@ -763,6 +763,9 @@ FltError ImportExcel::Read( void ) eLastErr = SCWARN_IMPORT_COLUMN_OVERFLOW; } + if (mxCLKernelThread.is()) + mxCLKernelThread->join(); + return eLastErr; } @@ -1316,6 +1319,9 @@ FltError ImportExcel8::Read( void ) GetPivotTableManager().MaybeRefreshPivotTables(); } + if (mxCLKernelThread.is()) + mxCLKernelThread->join(); + return eLastErr; } diff --git a/sc/source/filter/ftools/clkernelthread.cxx b/sc/source/filter/ftools/clkernelthread.cxx new file mode 100644 index 000000000000..f6d8c63ad96e --- /dev/null +++ b/sc/source/filter/ftools/clkernelthread.cxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "clkernelthread.hxx" +#include "formulagroup.hxx" + +using namespace std; + +namespace sc { + +CLBuildKernelThread::CLBuildKernelThread() : salhelper::Thread("opencl-build-kernel-thread") {} + +CLBuildKernelThread::~CLBuildKernelThread() {} + +void CLBuildKernelThread::execute() +{ + sc::FormulaGroupInterpreter::compileKernels(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/inc/clkernelthread.hxx b/sc/source/filter/inc/clkernelthread.hxx new file mode 100644 index 000000000000..32586e731bd8 --- /dev/null +++ b/sc/source/filter/inc/clkernelthread.hxx @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "salhelper/thread.hxx" + +namespace sc { + +class CLBuildKernelThread : public salhelper::Thread +{ +public: + CLBuildKernelThread(); + virtual ~CLBuildKernelThread(); + +protected: + virtual void execute(); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/inc/imp_op.hxx b/sc/source/filter/inc/imp_op.hxx index 8e004f3e0f8a..613ae30a81d6 100644 --- a/sc/source/filter/inc/imp_op.hxx +++ b/sc/source/filter/inc/imp_op.hxx @@ -30,6 +30,9 @@ #include "otlnbuff.hxx" #include "colrowst.hxx" #include "excdefs.hxx" +#include "rtl/ref.hxx" +#include "clkernelthread.hxx" + #include <boost/shared_ptr.hpp> #include <boost/ptr_container/ptr_vector.hpp> @@ -79,6 +82,8 @@ private: class ImportExcel : public ImportTyp, protected XclImpRoot { protected: + rtl::Reference<sc::CLBuildKernelThread> mxCLKernelThread; + static const double fExcToTwips; // Umrechnung 1/256 Zeichen -> Twips RootData* pExcRoot; |