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,\
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 \
......
......@@ -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 \
))
......
......@@ -35,7 +35,6 @@ $(eval $(call gb_Library_use_libraries,scui,\
i18nlangtag \
sal \
sc \
scopencl \
sfx \
sot \
svl \
......
......@@ -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;
......
......@@ -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();
};
}
......
......@@ -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: */
......@@ -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);
......
......@@ -280,6 +280,7 @@ public:
friend class agency;
};
size_t getOpenCLPlatformCount();
void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms);
}}
......
......@@ -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.
......
......@@ -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() {}
}
......
......@@ -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)
{
......
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