From 08f16d5ae44cb0e92debf5b67b56a7605a07e65e Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 13 Sep 2013 18:59:41 -0400 Subject: Avoid having build-time dependency on scopencl. Change-Id: I32918599dca0556a61b85d868dffbb5e72541e69 --- sc/Library_sc.mk | 1 + sc/Library_scopencl.mk | 1 - sc/Library_scui.mk | 1 - sc/inc/formulagroup.hxx | 3 ++ sc/inc/platforminfo.hxx | 6 ++-- sc/source/core/opencl/formulagroupcl.cxx | 14 ++++++++ sc/source/core/opencl/openclwrapper.cxx | 15 +++++++++ sc/source/core/opencl/openclwrapper.hxx | 1 + sc/source/core/opencl/platforminfo.cxx | 24 -------------- sc/source/core/tool/formulagroup.cxx | 56 +++++++++++++++++++++++++------- sc/source/core/tool/platforminfo.cxx | 21 ++++++++++++ sc/source/ui/optdlg/calcoptionsdlg.cxx | 6 +++- 12 files changed, 109 insertions(+), 40 deletions(-) delete mode 100644 sc/source/core/opencl/platforminfo.cxx create mode 100644 sc/source/core/tool/platforminfo.cxx diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index d1987371f327..b0ab893c8698 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -227,6 +227,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/core/tool/optutil \ sc/source/core/tool/orcusxml \ sc/source/core/tool/parclass \ + sc/source/core/tool/platforminfo \ sc/source/core/tool/printopt \ sc/source/core/tool/prnsave \ sc/source/core/tool/progress \ diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk index 44137826767d..2942e4709f68 100644 --- a/sc/Library_scopencl.mk +++ b/sc/Library_scopencl.mk @@ -35,7 +35,6 @@ $(eval $(call gb_Library_use_libraries,scopencl,\ $(eval $(call gb_Library_add_exception_objects,scopencl,\ sc/source/core/opencl/formulagroupcl \ - sc/source/core/opencl/platforminfo \ sc/source/core/opencl/openclwrapper \ sc/source/core/opencl/clcc/clew \ )) diff --git a/sc/Library_scui.mk b/sc/Library_scui.mk index 85028eebd783..f553dde96b1d 100644 --- a/sc/Library_scui.mk +++ b/sc/Library_scui.mk @@ -35,7 +35,6 @@ $(eval $(call gb_Library_use_libraries,scui,\ i18nlangtag \ sal \ sc \ - scopencl \ sfx \ sot \ svl \ diff --git a/sc/inc/formulagroup.hxx b/sc/inc/formulagroup.hxx index f4cbbdb06c70..ef9adbbf74ea 100644 --- a/sc/inc/formulagroup.hxx +++ b/sc/inc/formulagroup.hxx @@ -12,7 +12,9 @@ #include "address.hxx" #include "types.hxx" +#include "platforminfo.hxx" +#include #include #include #include @@ -52,6 +54,7 @@ class SC_DLLPUBLIC FormulaGroupInterpreter public: static FormulaGroupInterpreter *getStatic(); + static void fillOpenCLInfo(std::vector& rPlatforms); 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/inc/platforminfo.hxx b/sc/inc/platforminfo.hxx index 21c9aa9d731c..7a48e110a7c2 100644 --- a/sc/inc/platforminfo.hxx +++ b/sc/inc/platforminfo.hxx @@ -26,6 +26,8 @@ struct SC_DLLPUBLIC OpenclDeviceInfo size_t mnMemory; size_t mnComputeUnits; size_t mnFrequency; + + OpenclDeviceInfo(); }; struct SC_DLLPUBLIC OpenclPlatformInfo @@ -34,9 +36,9 @@ struct SC_DLLPUBLIC OpenclPlatformInfo OUString maVendor; OUString maName; std::vector maDevices; -}; -SC_DLLPUBLIC std::vector listAllOpenclPlatforms(); + OpenclPlatformInfo(); +}; } diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 61d9944a6f82..ce5f568b1378 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1080,6 +1080,20 @@ SAL_DLLPUBLIC_EXPORT sc::FormulaGroupInterpreter* SAL_CALL createFormulaGroupOpe return new sc::opencl::FormulaGroupInterpreterOpenCL(); } +SAL_DLLPUBLIC_EXPORT size_t getOpenCLPlatformCount() +{ + return sc::opencl::getOpenCLPlatformCount(); +} + +SAL_DLLPUBLIC_EXPORT void SAL_CALL fillOpenCLInfo(sc::OpenclPlatformInfo* pInfos, size_t nInfoSize) +{ + std::vector aPlatforms; + sc::opencl::fillOpenCLInfo(aPlatforms); + size_t n = std::min(aPlatforms.size(), nInfoSize); + for (size_t i = 0; i < n; ++i) + pInfos[i] = aPlatforms[i]; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx index f5178c20d225..f508758caf3c 100644 --- a/sc/source/core/opencl/openclwrapper.cxx +++ b/sc/source/core/opencl/openclwrapper.cxx @@ -2718,6 +2718,21 @@ bool createPlatformInfo(cl_platform_id nPlatformId, OpenclPlatformInfo& rPlatfor } +size_t getOpenCLPlatformCount() +{ + int status = clewInit(OPENCL_DLL_NAME); + if (status < 0) + return 0; + + cl_uint nPlatforms; + cl_int nState = clGetPlatformIDs(0, NULL, &nPlatforms); + + if (nState != CL_SUCCESS) + return 0; + + return nPlatforms; +} + void fillOpenCLInfo(std::vector& rPlatforms) { int status = clewInit(OPENCL_DLL_NAME); diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx index adaa98e65ea2..4d509c54c789 100644 --- a/sc/source/core/opencl/openclwrapper.hxx +++ b/sc/source/core/opencl/openclwrapper.hxx @@ -280,6 +280,7 @@ public: friend class agency; }; +size_t getOpenCLPlatformCount(); void fillOpenCLInfo(std::vector& rPlatforms); }} diff --git a/sc/source/core/opencl/platforminfo.cxx b/sc/source/core/opencl/platforminfo.cxx deleted file mode 100644 index e5700d657fca..000000000000 --- a/sc/source/core/opencl/platforminfo.cxx +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- 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 "platforminfo.hxx" -#include "openclwrapper.hxx" - -namespace sc { - -std::vector listAllOpenclPlatforms() -{ - std::vector aPlatforms; - opencl::fillOpenCLInfo(aPlatforms); - return aPlatforms; -} - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index 1a40b151b681..3b3001d93679 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -334,12 +334,29 @@ public: static void SAL_CALL thisModule() {} -typedef FormulaGroupInterpreter* (*LoaderFn)(void); +typedef FormulaGroupInterpreter* (*__createFormulaGroupOpenCLInterpreter)(void); +typedef size_t (*__getOpenCLPlatformCount)(void); +typedef void (*__fillOpenCLInfo)(OpenclPlatformInfo*, size_t); #endif FormulaGroupInterpreter *FormulaGroupInterpreter::msInstance = NULL; +osl::Module* getOpenCLModule() +{ + static osl::Module aModule; + if (aModule.is()) + // Already loaded. + return &aModule; + + OUString aLibName(SVLIBRARY("scopencl")); + bool bLoaded = aModule.loadRelative(&thisModule, aLibName); + if (!bLoaded) + bLoaded = aModule.load(aLibName); + + return bLoaded ? &aModule : NULL; +} + /// load and/or configure the correct formula group interpreter FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() { @@ -376,18 +393,12 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() msInstance = createFormulaGroupOpenCLInterpreter(); #else // Dynamically load scopencl shared object, and instantiate the opencl interpreter. - - OUString aLibName(SVLIBRARY("scopencl")); - static osl::Module aModule; - bool bLoaded = aModule.loadRelative(&thisModule, aLibName); - if (!bLoaded) - bLoaded = aModule.load(aLibName); - - if (bLoaded) + osl::Module* pModule = getOpenCLModule(); + if (pModule) { - oslGenericFunction fn = aModule.getFunctionSymbol("createFormulaGroupOpenCLInterpreter"); + oslGenericFunction fn = pModule->getFunctionSymbol("createFormulaGroupOpenCLInterpreter"); if (fn) - msInstance = reinterpret_cast(fn)(); + msInstance = reinterpret_cast<__createFormulaGroupOpenCLInterpreter>(fn)(); } if (!msInstance) @@ -405,6 +416,29 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() return msInstance; } +void FormulaGroupInterpreter::fillOpenCLInfo(std::vector& rPlatforms) +{ + osl::Module* pModule = getOpenCLModule(); + if (!pModule) + return; + + oslGenericFunction fn = pModule->getFunctionSymbol("getOpenCLPlatformCount"); + if (!fn) + return; + + size_t nPlatforms = reinterpret_cast<__getOpenCLPlatformCount>(fn)(); + if (!nPlatforms) + return; + + fn = pModule->getFunctionSymbol("fillOpenCLInfo"); + if (!fn) + return; + + std::vector aPlatforms(nPlatforms); + reinterpret_cast<__fillOpenCLInfo>(fn)(&aPlatforms[0], aPlatforms.size()); + rPlatforms.swap(aPlatforms); +} + void FormulaGroupInterpreter::generateRPNCode(ScDocument& rDoc, const ScAddress& rPos, ScTokenArray& rCode) { // First, generate an RPN (reverse polish notation) token array. diff --git a/sc/source/core/tool/platforminfo.cxx b/sc/source/core/tool/platforminfo.cxx new file mode 100644 index 000000000000..74f5136e755a --- /dev/null +++ b/sc/source/core/tool/platforminfo.cxx @@ -0,0 +1,21 @@ +/* -*- 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 "platforminfo.hxx" +#include "formulagroup.hxx" + +namespace sc { + +OpenclDeviceInfo::OpenclDeviceInfo() {} + +OpenclPlatformInfo::OpenclPlatformInfo() {} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx index 0b00a043b044..652090b36cb4 100644 --- a/sc/source/ui/optdlg/calcoptionsdlg.cxx +++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx @@ -14,6 +14,10 @@ #include "svtools/svlbitm.hxx" #include "svtools/treelistentry.hxx" +#if HAVE_FEATURE_OPENCL +#include "formulagroup.hxx" +#endif + namespace { typedef enum { @@ -195,7 +199,7 @@ void ScCalcOptionsDialog::fillOpenclList() { mpOpenclInfoList->SetUpdateMode(false); mpOpenclInfoList->Clear(); - maPlatformInfo = sc::listAllOpenclPlatforms(); + sc::FormulaGroupInterpreter::fillOpenCLInfo(maPlatformInfo); for(std::vector::iterator it = maPlatformInfo.begin(), itEnd = maPlatformInfo.end(); it != itEnd; ++it) { -- cgit