summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-09-13 18:59:41 -0400
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-09-19 17:03:19 +0200
commit08f16d5ae44cb0e92debf5b67b56a7605a07e65e (patch)
tree77b0f3ac4ebf8285315592cb43db577846dce4d3
parentstore the platform and device id for later look-up (diff)
downloadcore-08f16d5ae44cb0e92debf5b67b56a7605a07e65e.tar.gz
core-08f16d5ae44cb0e92debf5b67b56a7605a07e65e.zip
Avoid having build-time dependency on scopencl.
Change-Id: I32918599dca0556a61b85d868dffbb5e72541e69
-rw-r--r--sc/Library_sc.mk1
-rw-r--r--sc/Library_scopencl.mk1
-rw-r--r--sc/Library_scui.mk1
-rw-r--r--sc/inc/formulagroup.hxx3
-rw-r--r--sc/inc/platforminfo.hxx6
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx14
-rw-r--r--sc/source/core/opencl/openclwrapper.cxx15
-rw-r--r--sc/source/core/opencl/openclwrapper.hxx1
-rw-r--r--sc/source/core/tool/formulagroup.cxx56
-rw-r--r--sc/source/core/tool/platforminfo.cxx (renamed from sc/source/core/opencl/platforminfo.cxx)11
-rw-r--r--sc/source/ui/optdlg/calcoptionsdlg.cxx6
11 files changed, 92 insertions, 23 deletions
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 <vector>
#include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/unordered_set.hpp>
@@ -52,6 +54,7 @@ class SC_DLLPUBLIC FormulaGroupInterpreter
public:
static FormulaGroupInterpreter *getStatic();
+ static void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& 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<OpenclDeviceInfo> maDevices;
-};
-SC_DLLPUBLIC std::vector<OpenclPlatformInfo> 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<sc::OpenclPlatformInfo> 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<OpenclPlatformInfo>& 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<OpenclPlatformInfo>& rPlatforms);
}}
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<LoaderFn>(fn)();
+ msInstance = reinterpret_cast<__createFormulaGroupOpenCLInterpreter>(fn)();
}
if (!msInstance)
@@ -405,6 +416,29 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic()
return msInstance;
}
+void FormulaGroupInterpreter::fillOpenCLInfo(std::vector<OpenclPlatformInfo>& 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<OpenclPlatformInfo> 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/opencl/platforminfo.cxx b/sc/source/core/tool/platforminfo.cxx
index e5700d657fca..74f5136e755a 100644
--- a/sc/source/core/opencl/platforminfo.cxx
+++ b/sc/source/core/tool/platforminfo.cxx
@@ -8,16 +8,13 @@
*/
#include "platforminfo.hxx"
-#include "openclwrapper.hxx"
+#include "formulagroup.hxx"
namespace sc {
-std::vector<OpenclPlatformInfo> listAllOpenclPlatforms()
-{
- std::vector<OpenclPlatformInfo> aPlatforms;
- opencl::fillOpenCLInfo(aPlatforms);
- return aPlatforms;
-}
+OpenclDeviceInfo::OpenclDeviceInfo() {}
+
+OpenclPlatformInfo::OpenclPlatformInfo() {}
}
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<sc::OpenclPlatformInfo>::iterator it = maPlatformInfo.begin(),
itEnd = maPlatformInfo.end(); it != itEnd; ++it)
{