sc/Library_scopencl.mk | 1 sc/Library_scui.mk | 1 sc/inc/platforminfo.hxx | 40 +++++++ sc/source/core/opencl/openclwrapper.cxx | 89 +++++++++++++++++ sc/source/core/opencl/openclwrapper.hxx | 3 sc/source/core/opencl/platforminfo.cxx | 24 ++++ sc/source/ui/optdlg/calcoptionsdlg.cxx | 52 +++++++++- sc/source/ui/optdlg/calcoptionsdlg.hxx | 10 + sc/uiconfig/scalc/ui/formulacalculationoptions.ui | 111 ++++++++++++++++++++-- 9 files changed, 322 insertions(+), 9 deletions(-)
New commits: commit 3f41ef4c5fe059628c17a560df7e0ec697871903 Author: Markus Mohrhard <markus.mohrh...@googlemail.com> Date: Fri Sep 13 14:11:43 2013 +0200 inital work on showing available opencl platforms/devices Change-Id: I7e9beb3abeee42b19788980d43fb1ab5140e3e65 diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk index 2942e47..44137826 100644 --- a/sc/Library_scopencl.mk +++ b/sc/Library_scopencl.mk @@ -35,6 +35,7 @@ $(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 f553dde..85028ee 100644 --- a/sc/Library_scui.mk +++ b/sc/Library_scui.mk @@ -35,6 +35,7 @@ $(eval $(call gb_Library_use_libraries,scui,\ i18nlangtag \ sal \ sc \ + scopencl \ sfx \ sot \ svl \ diff --git a/sc/inc/platforminfo.hxx b/sc/inc/platforminfo.hxx new file mode 100644 index 0000000..bae6e41 --- /dev/null +++ b/sc/inc/platforminfo.hxx @@ -0,0 +1,40 @@ +/* -*- 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/. + */ + +#ifndef SC_PLATFORM_INFO_HXX +#define SC_PLATFORM_INFO_HXX + +#include <vector> + +#include <rtl/ustring.hxx> + +#include "scdllapi.h" + +namespace sc { + +struct SC_DLLPUBLIC OpenclDeviceInfo +{ + size_t mnId; + OUString maName; + OUString maVendor; +}; + +struct SC_DLLPUBLIC OpenclPlatformInfo +{ + void* mnId; + OUString maVendor; + OUString maName; + std::vector<OpenclDeviceInfo> maDevices; +}; + +SC_DLLPUBLIC std::vector<OpenclPlatformInfo> listAllOpenclPlatforms(); + +} + +#endif diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx index c1791f9..a45241c 100644 --- a/sc/source/core/opencl/openclwrapper.cxx +++ b/sc/source/core/opencl/openclwrapper.cxx @@ -9,6 +9,9 @@ #include "openclwrapper.hxx" +#include <rtl/ustring.hxx> +#include <boost/scoped_array.hpp> + #include "sal/config.h" #include "oclkernels.hxx" @@ -2628,6 +2631,92 @@ int OclCalc::oclHostMatrixInverse32Bits( const char* aKernelName, float *fpOclMa return 0; } +namespace { + +void createDeviceInfo(cl_device_id aDeviceId, OpenclPlatformInfo& rPlatformInfo) +{ + OpenclDeviceInfo aDeviceInfo; + char pName[64]; + cl_int nState = clGetDeviceInfo(aDeviceId, CL_DEVICE_NAME, 64, pName, NULL); + if(nState != CL_SUCCESS) + return; + + aDeviceInfo.maName = OUString::createFromAscii(pName); + + char pVendor[64]; + nState = clGetDeviceInfo(aDeviceId, CL_DEVICE_VENDOR, 64, pName, NULL); + if(nState != CL_SUCCESS) + return; + + aDeviceInfo.maVendor = OUString::createFromAscii(pVendor); + + rPlatformInfo.maDevices.push_back(aDeviceInfo); +} + +bool createPlatformInfo(cl_platform_id nPlatformId, OpenclPlatformInfo& rPlatformInfo) +{ + rPlatformInfo.mnId = nPlatformId; + char pName[64]; + cl_int nState = clGetPlatformInfo(nPlatformId, CL_PLATFORM_NAME, 64, + pName, NULL); + if(nState != CL_SUCCESS) + return false; + rPlatformInfo.maName = OUString::createFromAscii(pName); + + char pVendor[64]; + nState = clGetPlatformInfo(nPlatformId, CL_PLATFORM_VENDOR, 64, + pVendor, NULL); + if(nState != CL_SUCCESS) + return false; + + rPlatformInfo.maVendor = OUString::createFromAscii(pName); + + cl_uint nDevices; + nState = clGetDeviceIDs(nPlatformId, CL_DEVICE_TYPE_ALL, 0, NULL, &nDevices); + if(nState != CL_SUCCESS) + return false; + + boost::scoped_array<cl_device_id> pDevices(new cl_device_id[nDevices]); + nState = clGetDeviceIDs(nPlatformId, CL_DEVICE_TYPE_ALL, nDevices, pDevices.get(), NULL); + if(nState != CL_SUCCESS) + return false; + + for(size_t i = 0; i < nDevices; ++i) + { + createDeviceInfo(pDevices[i], rPlatformInfo); + } + + return true; +} + +} + +void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms) +{ + int status = clewInit("libOpenCL.so"); + if (status < 0) + return; + + cl_uint nPlatforms; + cl_int nState = clGetPlatformIDs(0, NULL, &nPlatforms); + + if(nState != CL_SUCCESS) + return; + + boost::scoped_array<cl_platform_id> pPlatforms(new cl_platform_id[nPlatforms]); + nState = clGetPlatformIDs(nPlatforms, pPlatforms.get(), NULL); + + if(nState != CL_SUCCESS) + return; + + for(size_t i = 0; i < nPlatforms; ++i) + { + OpenclPlatformInfo aPlatformInfo; + if(createPlatformInfo(pPlatforms[i], aPlatformInfo)) + rPlatforms.push_back(aPlatformInfo); + } +} + }} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx index 431a771..adaa98e 100644 --- a/sc/source/core/opencl/openclwrapper.hxx +++ b/sc/source/core/opencl/openclwrapper.hxx @@ -14,6 +14,7 @@ #include <formula/opcode.hxx> #include <sal/detail/log.h> #include <cassert> +#include "platforminfo.hxx" #include "clcc/clew.h" @@ -279,6 +280,8 @@ public: friend class agency; }; +void fillOpenCLInfo(std::vector<OpenclPlatformInfo>& rPlatforms); + }} #endif diff --git a/sc/source/core/opencl/platforminfo.cxx b/sc/source/core/opencl/platforminfo.cxx new file mode 100644 index 0000000..e5700d6 --- /dev/null +++ b/sc/source/core/opencl/platforminfo.cxx @@ -0,0 +1,24 @@ +/* -*- 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<OpenclPlatformInfo> listAllOpenclPlatforms() +{ + std::vector<OpenclPlatformInfo> aPlatforms; + opencl::fillOpenCLInfo(aPlatforms); + return aPlatforms; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/optdlg/calcoptionsdlg.cxx b/sc/source/ui/optdlg/calcoptionsdlg.cxx index dd6003c..8167736 100644 --- a/sc/source/ui/optdlg/calcoptionsdlg.cxx +++ b/sc/source/ui/optdlg/calcoptionsdlg.cxx @@ -7,8 +7,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <config_features.h> - #include "calcoptionsdlg.hxx" #include "sc.hrc" #include "scresid.hxx" @@ -16,6 +14,10 @@ #include "svtools/svlbitm.hxx" #include "svtools/treelistentry.hxx" +#if HAVE_FEATURE_OPENCL +#include "platforminfo.hxx" +#endif + namespace { typedef enum { @@ -113,6 +115,14 @@ ScCalcOptionsDialog::ScCalcOptionsDialog(Window* pParent, const ScCalcConfig& rC get(mpFtAnnotation, "annotation"); get(mpBtnTrue, "true"); get(mpBtnFalse, "false"); + get(mpOpenclInfoList, "opencl_list"); + get(mpBtnAutomaticSelectionTrue, "automatic_select_true"); + get(mpBtnAutomaticSelectionFalse, "automatic_select_false"); + + mpOpenclInfoList->set_height_request(4* mpOpenclInfoList->GetTextHeight()); + mpOpenclInfoList->SetStyle(mpOpenclInfoList->GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE); + mpOpenclInfoList->SetHighlightRange(); + mpOpenclInfoList->GetParent()->Hide(); maCaptionStringRefSyntax = get<Window>("ref_syntax_caption")->GetText(); maDescStringRefSyntax = get<Window>("ref_syntax_desc")->GetText(); @@ -177,6 +187,36 @@ void ScCalcOptionsDialog::setValueAt(size_t nPos, const OUString &rValue) pModel->InvalidateEntry(pEntry); } +#if HAVE_FEATURE_OPENCL + +void ScCalcOptionsDialog::fillOpenclList() +{ + mpOpenclInfoList->SetUpdateMode(false); + mpOpenclInfoList->Clear(); + std::vector<sc::OpenclPlatformInfo> aPlatformInfo = sc::listAllOpenclPlatforms(); + for(std::vector<sc::OpenclPlatformInfo>::const_iterator it = aPlatformInfo.begin(), + itEnd = aPlatformInfo.end(); it != itEnd; ++it) + { + SvTreeListEntry* pEntry = new SvTreeListEntry; + pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0)); + pEntry->AddItem(new SvLBoxString(pEntry, 0, it->maVendor)); + mpOpenclInfoList->GetModel()->Insert(pEntry); + + for(std::vector<sc::OpenclDeviceInfo>::const_iterator + itr = it->maDevices.begin(), itrEnd = it->maDevices.end(); itr != itrEnd; ++itr) + { + SvTreeListEntry* pDeviceEntry = new SvTreeListEntry; +pDeviceEntry->AddItem(new SvLBoxContextBmp(pDeviceEntry, 0, Image(), Image(), 0)); +pDeviceEntry->AddItem(new SvLBoxString(pDeviceEntry, 0, itr->maName)); +mpOpenclInfoList->GetModel()->Insert(pDeviceEntry, pEntry); + } + } + + mpOpenclInfoList->SetUpdateMode(true); +} + +#endif + void ScCalcOptionsDialog::FillOptionsList() { mpLbSettings->SetUpdateMode(false); @@ -198,6 +238,7 @@ void ScCalcOptionsDialog::FillOptionsList() pModel->Insert(createBoolItem(maCaptionEmptyStringAsZero,maConfig.mbEmptyStringAsZero)); #if HAVE_FEATURE_OPENCL pModel->Insert(createBoolItem(maCaptionOpenCLEnabled,maConfig.mbOpenCLEnabled)); + fillOpenclList(); #endif mpLbSettings->SetUpdateMode(true); @@ -214,6 +255,7 @@ void ScCalcOptionsDialog::SelectionChanged() mpBtnTrue->Hide(); mpBtnFalse->Hide(); mpLbOptionEdit->Show(); + mpOpenclInfoList->GetParent()->Hide(); mpLbOptionEdit->Clear(); mpLbOptionEdit->InsertEntry(maUseFormulaSyntax); @@ -253,11 +295,17 @@ void ScCalcOptionsDialog::SelectionChanged() { bValue = maConfig.mbEmptyStringAsZero; mpFtAnnotation->SetText(maDescEmptyStringAsZero); + mpOpenclInfoList->GetParent()->Hide(); } else { bValue = maConfig.mbOpenCLEnabled; mpFtAnnotation->SetText(maDescOpenCLEnabled); + mpOpenclInfoList->GetParent()->Show(); + if(bValue) + mpOpenclInfoList->GetParent()->Enable(); + else + mpOpenclInfoList->GetParent()->Disable(); } if ( bValue ) diff --git a/sc/source/ui/optdlg/calcoptionsdlg.hxx b/sc/source/ui/optdlg/calcoptionsdlg.hxx index 3badc9a..b52b46f 100644 --- a/sc/source/ui/optdlg/calcoptionsdlg.hxx +++ b/sc/source/ui/optdlg/calcoptionsdlg.hxx @@ -10,10 +10,13 @@ #ifndef __SC_OPTDLG_CALCOPTIONSDLG_HXX__ #define __SC_OPTDLG_CALCOPTIONSDLG_HXX__ +#include <config_features.h> + #include "vcl/dialog.hxx" #include "vcl/button.hxx" #include "vcl/fixed.hxx" #include "svx/checklbx.hxx" +#include "svtools/treelistbox.hxx" #include "calcconfig.hxx" @@ -33,6 +36,9 @@ private: void SelectionChanged(); void ListOptionValueChanged(); void RadioValueChanged(); +#if HAVE_FEATURE_OPENCL + void fillOpenclList(); +#endif OUString toString(formula::FormulaGrammar::AddressConvention eConv) const; OUString toString(bool bVal) const; @@ -48,6 +54,10 @@ private: FixedText* mpFtAnnotation; + SvTreeListBox* mpOpenclInfoList; + RadioButton* mpBtnAutomaticSelectionTrue; + RadioButton* mpBtnAutomaticSelectionFalse; + OUString maTrue; OUString maFalse; diff --git a/sc/uiconfig/scalc/ui/formulacalculationoptions.ui b/sc/uiconfig/scalc/ui/formulacalculationoptions.ui index 0f00fa3..a848051 100644 --- a/sc/uiconfig/scalc/ui/formulacalculationoptions.ui +++ b/sc/uiconfig/scalc/ui/formulacalculationoptions.ui @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <interface> <!-- interface-requires gtk+ 3.6 --> + <!-- interface-requires LibreOffice 1.0 --> <object class="GtkDialog" id="FormulaCalculationOptions"> <property name="can_focus">False</property> <property name="border_width">6</property> @@ -66,6 +67,9 @@ <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> + <child internal-child="selection"> + <object class="GtkTreeSelection" id="Check List Box-selection1"/> + </child> </object> <packing> <property name="left_attach">0</property> @@ -173,6 +177,7 @@ <property name="xalign">0</property> <property name="yalign">0</property> <property name="wrap">True</property> + <property name="ellipsize">end</property> <property name="max_width_chars">56</property> </object> <packing> @@ -190,7 +195,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">3</property> + <property name="top_attach">4</property> <property name="width">1</property> <property name="height">1</property> </packing> @@ -205,7 +210,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">4</property> + <property name="top_attach">5</property> <property name="width">1</property> <property name="height">1</property> </packing> @@ -218,7 +223,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">5</property> + <property name="top_attach">6</property> <property name="width">1</property> <property name="height">1</property> </packing> @@ -231,7 +236,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">6</property> + <property name="top_attach">7</property> <property name="width">1</property> <property name="height">1</property> </packing> @@ -246,7 +251,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">7</property> + <property name="top_attach">8</property> <property name="width">1</property> <property name="height">1</property> </packing> @@ -259,7 +264,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">8</property> + <property name="top_attach">9</property> <property name="width">1</property> <property name="height">1</property> </packing> @@ -274,7 +279,99 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">9</property> + <property name="top_attach">10</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="grid6"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="row_spacing">2</property> + <child> + <object class="svtlo-SvTreeListBox" id="opencl_list"> + <property name="visible">True</property> + <property name="app_paintable">True</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <child internal-child="selection"> + <object class="GtkTreeSelection" id="Tree List-selection1"/> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="grid3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Automatic Selection of Platform/Device:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="automatic_select_true"> + <property name="label" translatable="yes">True</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + <property name="group">automatic_select_false</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="automatic_select_false"> + <property name="label" translatable="yes">False</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="xalign">0</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + <property name="group">automatic_select_true</property> + </object> + <packing> + <property name="left_attach">2</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">1</property> + <property name="height">1</property> + </packing> + </child> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> <property name="width">1</property> <property name="height">1</property> </packing> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits