Kaydet (Commit) 08f16d5a authored tarafından Kohei Yoshida's avatar Kohei Yoshida Kaydeden (comit) Markus Mohrhard

Avoid having build-time dependency on scopencl.

Change-Id: I32918599dca0556a61b85d868dffbb5e72541e69
üst 3be59e38
...@@ -227,6 +227,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ ...@@ -227,6 +227,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/tool/optutil \ sc/source/core/tool/optutil \
sc/source/core/tool/orcusxml \ sc/source/core/tool/orcusxml \
sc/source/core/tool/parclass \ sc/source/core/tool/parclass \
sc/source/core/tool/platforminfo \
sc/source/core/tool/printopt \ sc/source/core/tool/printopt \
sc/source/core/tool/prnsave \ sc/source/core/tool/prnsave \
sc/source/core/tool/progress \ sc/source/core/tool/progress \
......
...@@ -35,7 +35,6 @@ $(eval $(call gb_Library_use_libraries,scopencl,\ ...@@ -35,7 +35,6 @@ $(eval $(call gb_Library_use_libraries,scopencl,\
$(eval $(call gb_Library_add_exception_objects,scopencl,\ $(eval $(call gb_Library_add_exception_objects,scopencl,\
sc/source/core/opencl/formulagroupcl \ sc/source/core/opencl/formulagroupcl \
sc/source/core/opencl/platforminfo \
sc/source/core/opencl/openclwrapper \ sc/source/core/opencl/openclwrapper \
sc/source/core/opencl/clcc/clew \ sc/source/core/opencl/clcc/clew \
)) ))
......
...@@ -35,7 +35,6 @@ $(eval $(call gb_Library_use_libraries,scui,\ ...@@ -35,7 +35,6 @@ $(eval $(call gb_Library_use_libraries,scui,\
i18nlangtag \ i18nlangtag \
sal \ sal \
sc \ sc \
scopencl \
sfx \ sfx \
sot \ sot \
svl \ svl \
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#include "address.hxx" #include "address.hxx"
#include "types.hxx" #include "types.hxx"
#include "platforminfo.hxx"
#include <vector>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp> #include <boost/ptr_container/ptr_vector.hpp>
#include <boost/unordered_set.hpp> #include <boost/unordered_set.hpp>
...@@ -52,6 +54,7 @@ class SC_DLLPUBLIC FormulaGroupInterpreter ...@@ -52,6 +54,7 @@ class SC_DLLPUBLIC FormulaGroupInterpreter
public: public:
static FormulaGroupInterpreter *getStatic(); static FormulaGroupInterpreter *getStatic();
static void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms);
virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0; virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0;
virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, const ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) = 0; virtual bool interpret(ScDocument& rDoc, const ScAddress& rTopPos, const ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode) = 0;
......
...@@ -26,6 +26,8 @@ struct SC_DLLPUBLIC OpenclDeviceInfo ...@@ -26,6 +26,8 @@ struct SC_DLLPUBLIC OpenclDeviceInfo
size_t mnMemory; size_t mnMemory;
size_t mnComputeUnits; size_t mnComputeUnits;
size_t mnFrequency; size_t mnFrequency;
OpenclDeviceInfo();
}; };
struct SC_DLLPUBLIC OpenclPlatformInfo struct SC_DLLPUBLIC OpenclPlatformInfo
...@@ -34,9 +36,9 @@ struct SC_DLLPUBLIC OpenclPlatformInfo ...@@ -34,9 +36,9 @@ struct SC_DLLPUBLIC OpenclPlatformInfo
OUString maVendor; OUString maVendor;
OUString maName; OUString maName;
std::vector<OpenclDeviceInfo> maDevices; std::vector<OpenclDeviceInfo> maDevices;
};
SC_DLLPUBLIC std::vector<OpenclPlatformInfo> listAllOpenclPlatforms(); OpenclPlatformInfo();
};
} }
......
...@@ -1080,6 +1080,20 @@ SAL_DLLPUBLIC_EXPORT sc::FormulaGroupInterpreter* SAL_CALL createFormulaGroupOpe ...@@ -1080,6 +1080,20 @@ SAL_DLLPUBLIC_EXPORT sc::FormulaGroupInterpreter* SAL_CALL createFormulaGroupOpe
return new sc::opencl::FormulaGroupInterpreterOpenCL(); 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -2718,6 +2718,21 @@ bool createPlatformInfo(cl_platform_id nPlatformId, OpenclPlatformInfo& rPlatfor ...@@ -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) void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms)
{ {
int status = clewInit(OPENCL_DLL_NAME); int status = clewInit(OPENCL_DLL_NAME);
......
...@@ -280,6 +280,7 @@ public: ...@@ -280,6 +280,7 @@ public:
friend class agency; friend class agency;
}; };
size_t getOpenCLPlatformCount();
void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms); void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms);
}} }}
......
...@@ -334,12 +334,29 @@ public: ...@@ -334,12 +334,29 @@ public:
static void SAL_CALL thisModule() {} 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 #endif
FormulaGroupInterpreter *FormulaGroupInterpreter::msInstance = NULL; 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 /// load and/or configure the correct formula group interpreter
FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic()
{ {
...@@ -376,18 +393,12 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() ...@@ -376,18 +393,12 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic()
msInstance = createFormulaGroupOpenCLInterpreter(); msInstance = createFormulaGroupOpenCLInterpreter();
#else #else
// Dynamically load scopencl shared object, and instantiate the opencl interpreter. // Dynamically load scopencl shared object, and instantiate the opencl interpreter.
osl::Module* pModule = getOpenCLModule();
OUString aLibName(SVLIBRARY("scopencl")); if (pModule)
static osl::Module aModule;
bool bLoaded = aModule.loadRelative(&thisModule, aLibName);
if (!bLoaded)
bLoaded = aModule.load(aLibName);
if (bLoaded)
{ {
oslGenericFunction fn = aModule.getFunctionSymbol("createFormulaGroupOpenCLInterpreter"); oslGenericFunction fn = pModule->getFunctionSymbol("createFormulaGroupOpenCLInterpreter");
if (fn) if (fn)
msInstance = reinterpret_cast<LoaderFn>(fn)(); msInstance = reinterpret_cast<__createFormulaGroupOpenCLInterpreter>(fn)();
} }
if (!msInstance) if (!msInstance)
...@@ -405,6 +416,29 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() ...@@ -405,6 +416,29 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic()
return msInstance; 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) void FormulaGroupInterpreter::generateRPNCode(ScDocument& rDoc, const ScAddress& rPos, ScTokenArray& rCode)
{ {
// First, generate an RPN (reverse polish notation) token array. // First, generate an RPN (reverse polish notation) token array.
......
...@@ -8,16 +8,13 @@ ...@@ -8,16 +8,13 @@
*/ */
#include "platforminfo.hxx" #include "platforminfo.hxx"
#include "openclwrapper.hxx" #include "formulagroup.hxx"
namespace sc { namespace sc {
std::vector<OpenclPlatformInfo> listAllOpenclPlatforms() OpenclDeviceInfo::OpenclDeviceInfo() {}
{
std::vector<OpenclPlatformInfo> aPlatforms; OpenclPlatformInfo::OpenclPlatformInfo() {}
opencl::fillOpenCLInfo(aPlatforms);
return aPlatforms;
}
} }
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include "svtools/svlbitm.hxx" #include "svtools/svlbitm.hxx"
#include "svtools/treelistentry.hxx" #include "svtools/treelistentry.hxx"
#if HAVE_FEATURE_OPENCL
#include "formulagroup.hxx"
#endif
namespace { namespace {
typedef enum { typedef enum {
...@@ -195,7 +199,7 @@ void ScCalcOptionsDialog::fillOpenclList() ...@@ -195,7 +199,7 @@ void ScCalcOptionsDialog::fillOpenclList()
{ {
mpOpenclInfoList->SetUpdateMode(false); mpOpenclInfoList->SetUpdateMode(false);
mpOpenclInfoList->Clear(); mpOpenclInfoList->Clear();
maPlatformInfo = sc::listAllOpenclPlatforms(); sc::FormulaGroupInterpreter::fillOpenCLInfo(maPlatformInfo);
for(std::vector<sc::OpenclPlatformInfo>::iterator it = maPlatformInfo.begin(), for(std::vector<sc::OpenclPlatformInfo>::iterator it = maPlatformInfo.begin(),
itEnd = maPlatformInfo.end(); it != itEnd; ++it) itEnd = maPlatformInfo.end(); it != itEnd; ++it)
{ {
......
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