diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-11-22 20:27:48 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-11-25 20:44:58 +0100 |
commit | 7524119f965c54b863c9a67a19ff0a212c77879f (patch) | |
tree | 9f4b8bff25ea684f524a7ea8ddb9a9eead921a4a | |
parent | eff099b9083ed5a5f83b45162d45c55e5c6d714a (diff) |
provide UNO API for OpenCL selection
Change-Id: If5eb71e9298cefdac3dda98cb1ff67fe913ad3c3
-rwxr-xr-x | offapi/UnoApi_offapi.mk | 5 | ||||
-rw-r--r-- | offapi/com/sun/star/sheet/opencl/XOpenCLSelection.idl | 45 | ||||
-rw-r--r-- | sc/inc/docuno.hxx | 20 | ||||
-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 | 35 | ||||
-rw-r--r-- | sc/source/core/opencl/openclwrapper.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/formulagroup.cxx | 33 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 56 |
9 files changed, 201 insertions, 1 deletions
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index f75da6851f3a..e7c52f2e63f2 100755 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -3325,6 +3325,11 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/security,\ XSanExtension \ XSerialNumberAdapter \ )) + +$(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/sheet/opencl,\ + XOpenCLSelection \ +)) + $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/sheet,\ ActivationEvent \ AddressConvention \ diff --git a/offapi/com/sun/star/sheet/opencl/XOpenCLSelection.idl b/offapi/com/sun/star/sheet/opencl/XOpenCLSelection.idl new file mode 100644 index 000000000000..c6e18cf30e27 --- /dev/null +++ b/offapi/com/sun/star/sheet/opencl/XOpenCLSelection.idl @@ -0,0 +1,45 @@ +/* -*- 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/. + */ + +module com { module sun { module star { module sheet { module opencl { + +interface XOpenCLSelection : com::sun::star::uno::XInterface +{ + + /** + * Returns true if calculation with OpenCL is enabled + */ + boolean isOpenCLEnabled(); + + /** + * Enables or disables OpenCL + */ + void enableOpenCL( [in] boolean enable ); + + /** + * Set the OpenCL device with the platform ID and device ID + * Uses the ID of the platform and the device + */ + void selectOpenCLDevice( [in] long platform, [in] long device ); + + /** + * returns the platform id of the currently selected device + */ + long getPlatformID(); + + /** + * returns the device id of the currently selected device + */ + long getDeviceID(); + +}; + +}; }; }; }; }; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index 9be1ee22e7b3..a3b7680f7142 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -45,6 +45,7 @@ #include <com/sun/star/sheet/XSheetAnnotations.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/sheet/XCellRangesAccess.hpp> +#include <com/sun/star/sheet/opencl/XOpenCLSelection.hpp> #include <com/sun/star/util/XChangesNotifier.hpp> #include <cppuhelper/implbase2.hxx> #include <cppuhelper/implbase3.hxx> @@ -81,7 +82,8 @@ class SC_DLLPUBLIC ScModelObj : public SfxBaseModel, public com::sun::star::beans::XPropertySet, public SvxFmMSFactory, ///< derived from XMultiServiceFactory public com::sun::star::lang::XServiceInfo, - public ::com::sun::star::util::XChangesNotifier + public ::com::sun::star::util::XChangesNotifier, + public com::sun::star::sheet::opencl::XOpenCLSelection { private: SfxItemPropertySet aPropSet; @@ -315,6 +317,22 @@ public: virtual void SAL_CALL removeChangesListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XChangesListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); + + // XOpenCLSelection + virtual sal_Bool SAL_CALL isOpenCLEnabled() + throw(::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL enableOpenCL(sal_Bool bEnable) + throw(::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL selectOpenCLDevice( sal_Int32 platform, sal_Int32 device ) + throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getPlatformID() + throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getDeviceID() + throw(::com::sun::star::uno::RuntimeException); }; diff --git a/sc/inc/formulagroup.hxx b/sc/inc/formulagroup.hxx index 9f8d09c3206d..17f00d1708bb 100644 --- a/sc/inc/formulagroup.hxx +++ b/sc/inc/formulagroup.hxx @@ -97,6 +97,7 @@ class SC_DLLPUBLIC FormulaGroupInterpreter static void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms); static bool switchOpenCLDevice(const OUString& rDeviceId, bool bAutoSelect); static void enableOpenCL(bool bEnable); + static void getOpenCLDeviceInfo(sal_Int32& rDeviceId, sal_Int32& rPlatformId); virtual ScMatrixRef inverseMatrix(const ScMatrix& rMat) = 0; virtual CompiledFormula* createCompiledFormula(ScDocument& rDoc, diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index bee159bf3adc..8e4c5be4f2f3 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -2894,6 +2894,11 @@ SAL_DLLPUBLIC_EXPORT bool SAL_CALL switchOpenClDevice( return sc::opencl::switchOpenclDevice(pDeviceId, bAutoSelect); } +SAL_DLLPUBLIC_EXPORT void SAL_CALL getOpenCLDeviceInfo(size_t* pDeviceId, size_t* pPlatformId) +{ + sc::opencl::getOpenCLDeviceInfo(*pDeviceId, *pPlatformId); +} + } // extern "C" /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx index 8127b7493e88..24459c627780 100644 --- a/sc/source/core/opencl/openclwrapper.cxx +++ b/sc/source/core/opencl/openclwrapper.cxx @@ -889,6 +889,35 @@ cl_device_id findDeviceIdByDeviceString(const OUString& rString, const std::vect return NULL; } +void findDeviceInfoFromDeviceId(cl_device_id aDeviceId, size_t& rDeviceId, size_t& rPlatformId) +{ + cl_platform_id platformId; + cl_int nState = clGetDeviceInfo(aDeviceId, CL_DEVICE_PLATFORM, + sizeof(platformId), &platformId, NULL); + + if(nState != CL_SUCCESS) + return; + + const std::vector<OpenclPlatformInfo>& rPlatforms = fillOpenCLInfo(); + for(size_t i = 0; i < rPlatforms.size(); ++i) + { + cl_platform_id platId = static_cast<cl_platform_id>(rPlatforms[i].platform); + if(platId != platformId) + continue; + + for(size_t j = 0; j < rPlatforms[i].maDevices.size(); ++j) + { + cl_device_id id = static_cast<cl_device_id>(rPlatforms[i].maDevices[j].device); + if(id == aDeviceId) + { + rDeviceId = j; + rPlatformId = i; + return; + } + } + } +} + } bool switchOpenclDevice(const OUString* pDevice, bool bAutoSelect) @@ -966,6 +995,12 @@ bool switchOpenclDevice(const OUString* pDevice, bool bAutoSelect) return !OpenclDevice::initOpenclRunEnv(0); } +void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId) +{ + cl_device_id id = OpenclDevice::gpuEnv.mpDevID; + findDeviceInfoFromDeviceId(id, rDeviceId, rPlatformId); +} + }} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx index 0dfe24c63873..073ce1aa3548 100644 --- a/sc/source/core/opencl/openclwrapper.hxx +++ b/sc/source/core/opencl/openclwrapper.hxx @@ -185,6 +185,8 @@ const std::vector<OpenclPlatformInfo>& fillOpenCLInfo(); */ bool switchOpenclDevice(const OUString* pDeviceId, bool bAutoSelect); +void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId); + }} #endif diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index f3ec3e08d5eb..372e8fca1cc3 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -33,6 +33,7 @@ extern "C" size_t getOpenCLPlatformCount(void); extern "C" void fillOpenCLInfo(sc::OpenclPlatformInfo*, size_t); extern "C" bool switchOpenClDevice(const OUString*, bool); extern "C" sc::FormulaGroupInterpreter* createFormulaGroupOpenCLInterpreter(); +extern "C" void getOpenCLDeviceInfo(size_t*, size_t*); #endif @@ -504,6 +505,7 @@ typedef FormulaGroupInterpreter* (*__createFormulaGroupOpenCLInterpreter)(void); typedef size_t (*__getOpenCLPlatformCount)(void); typedef void (*__fillOpenCLInfo)(OpenclPlatformInfo*, size_t); typedef bool (*__switchOpenClDevice)(const OUString*, bool); +typedef void (*__getOpenCLDeviceInfo)(size_t*, size_t*); #endif @@ -653,6 +655,37 @@ bool FormulaGroupInterpreter::switchOpenCLDevice(const OUString& rDeviceId, bool return false; } +void FormulaGroupInterpreter::getOpenCLDeviceInfo(sal_Int32& rDeviceId, sal_Int32& rPlatformId) +{ + rDeviceId = -1; + rPlatformId = -1; + bool bOpenCLEnabled = ScInterpreter::GetGlobalConfig().mbOpenCLEnabled; + if(bOpenCLEnabled) + return; + +#if HAVE_FEATURE_OPENCL + + size_t aDeviceId = -1; + size_t aPlatformId = -1; + +#ifndef DISABLE_DYNLOADING + osl::Module* pModule = getOpenCLModule(); + if (!pModule) + return; + + oslGenericFunction fn = pModule->getFunctionSymbol("getOpenCLDeviceInfo"); + if (!fn) + return; + + reinterpret_cast<__getOpenCLDeviceInfo>(fn)(&aDeviceId, &aPlatformId); +#else + getOpenCLDeviceInfo(&aDeviceId, &aPlatformId); +#endif + rDeviceId = aDeviceId; + rPlatformId = aPlatformId; +#endif +} + void FormulaGroupInterpreter::enableOpenCL(bool bEnable) { ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig(); diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index a1312aaa2045..c1671c6389e2 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -92,6 +92,9 @@ #include "sheetevents.hxx" #include "sc.hrc" #include "scresid.hxx" +#include "platforminfo.hxx" +#include "interpre.hxx" +#include "formulagroup.hxx" using namespace com::sun::star; @@ -2286,6 +2289,59 @@ void ScModelObj::HandleCalculateEvents() } } +// XOpenCLSelection + +sal_Bool ScModelObj::isOpenCLEnabled() + throw (uno::RuntimeException) +{ + return ScInterpreter::GetGlobalConfig().mbOpenCLEnabled; +} + +void ScModelObj::enableOpenCL(sal_Bool bEnable) + throw (uno::RuntimeException) +{ + ScCalcConfig aConfig = ScInterpreter::GetGlobalConfig(); + aConfig.mbOpenCLEnabled = bEnable; + ScInterpreter::SetGlobalConfig(aConfig); +} + +void ScModelObj::selectOpenCLDevice( sal_Int32 nPlatform, sal_Int32 nDevice ) + throw (uno::RuntimeException) +{ + if(nPlatform < 0 || nDevice < 0) + throw uno::RuntimeException(); + + std::vector<sc::OpenclPlatformInfo> aPlatformInfo; + sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo); + if(size_t(nPlatform) >= aPlatformInfo.size()) + throw uno::RuntimeException(); + + if(size_t(nDevice) >= aPlatformInfo[nPlatform].maDevices.size()) + throw uno::RuntimeException(); + + OUString aDeviceString = aPlatformInfo[nPlatform].maVendor + " " + aPlatformInfo[nPlatform].maDevices[nDevice].maName; + sc::FormulaGroupInterpreter::switchOpenCLDevice(aDeviceString, false); +} + +sal_Int32 ScModelObj::getPlatformID() + throw (uno::RuntimeException) +{ + sal_Int32 nPlatformId; + sal_Int32 nDeviceId; + sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId); + return nPlatformId; +} + +sal_Int32 ScModelObj::getDeviceID() + throw (uno::RuntimeException) +{ + sal_Int32 nPlatformId; + sal_Int32 nDeviceId; + sc::FormulaGroupInterpreter::getOpenCLDeviceInfo(nDeviceId, nPlatformId); + return nDeviceId; +} + + //------------------------------------------------------------------------ ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) : |