Skip to content

Commit

Permalink
[opencl] Add options widget
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Aug 8, 2018
1 parent 3054da0 commit 1decb48
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 4 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -699,6 +699,7 @@
<file>themes/default/mIndicatorEmbedded.svg</file>
<file>themes/default/mIconHistory.svg</file>
<file>themes/default/mIndicatorMemory.svg</file>
<file>themes/default/mIconGPU.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
14 changes: 14 additions & 0 deletions images/themes/default/mIconGPU.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -51,6 +51,10 @@
#include "qgslocatorwidget.h"
#include "qgslocatoroptionswidget.h"

#ifdef HAVE_OPENCL
#include "qgsopenclutils.h"
#endif

#include <QInputDialog>
#include <QFileDialog>
#include <QColorDialog>
Expand Down Expand Up @@ -1076,6 +1080,43 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mOptionsStackedWidget->addWidget( page );
}

#ifdef HAVE_OPENCL

// Setup OpenCL (GPU) widget
mGPUEnableCheckBox->setChecked( QgsOpenClUtils::enabled( ) );
if ( QgsOpenClUtils::available( ) )
{
mGPUEnableCheckBox->setEnabled( true );
mGPUInfoLabel->setText( QStringLiteral( "OpenCL compatible GPU found on your system:<br>"
"Name: <b>%1</b><br>"
"Vendor: <b>%2</b><br>"
"Profile: <b>%3</b><br>"
"Version: <b>%4</b><br>"
).arg( QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Name ),
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Vendor ),
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Profile ),
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Version ) )
);
connect( mGPUEnableCheckBox, &QCheckBox::toggled, this, []( bool status )
{
QgsOpenClUtils::setEnabled( status );
}, Qt::UniqueConnection );
}
else
{
mGPUEnableCheckBox->setEnabled( false );
mGPUInfoLabel->setText( QStringLiteral( "OpenCL compatible GPU was not found on your system. You may need to install additional libraries in order to enable OpenCL." ) );
}


#else

mOptionsListWidget->removeItemWidget( mOptionsListWidget->findItems( QStringLiteral( "GPU" ), Qt::MatchExactly ).first() );
mOptionsStackedWidget->removeWidget( mOptionsPageGPU );


#endif

connect( pbnEditCreateOptions, &QAbstractButton::pressed, this, &QgsOptions::editCreateOptions );
connect( pbnEditPyramidsOptions, &QAbstractButton::pressed, this, &QgsOptions::editPyramidsOptions );

Expand Down
22 changes: 21 additions & 1 deletion src/core/qgsopenclutils.cpp
Expand Up @@ -114,10 +114,30 @@ void QgsOpenClUtils::setSourcePath( const QString &value )
sSourcePath = value;
}

QString QgsOpenClUtils::deviceInfo( const Info infoType )
{
if ( available( ) )
{
switch ( infoType )
{
case Info::Vendor:
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_VENDOR>() );
case Info::Profile:
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_PROFILE>() );
case Info::Version:
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_VERSION>() );
case Info::Name:
default:
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_NAME>() );
}
}
return QString();
}


bool QgsOpenClUtils::enabled()
{
return QgsSettings().value( SETTINGS_KEY, true, QgsSettings::Section::Core ).toBool();
return QgsSettings().value( SETTINGS_KEY, false, QgsSettings::Section::Core ).toBool();
}

bool QgsOpenClUtils::available()
Expand Down
10 changes: 9 additions & 1 deletion src/core/qgsopenclutils.h
Expand Up @@ -23,7 +23,6 @@
#define CL_HPP_TARGET_OPENCL_VERSION 110
#include <CL/cl2.hpp>


#include "qgis_core.h"
#include "qgis.h"

Expand Down Expand Up @@ -51,6 +50,14 @@ class CORE_EXPORT QgsOpenClUtils
Throw // Write errors in the message log and re-throw exceptions
};

enum Info
{
Name = CL_DEVICE_NAME,
Vendor = CL_DEVICE_VENDOR,
Version = CL_DEVICE_VERSION,
Profile = CL_DEVICE_PROFILE
};

static bool enabled();
static bool available();
static void setEnabled( bool enabled );
Expand All @@ -63,6 +70,7 @@ class CORE_EXPORT QgsOpenClUtils
static cl::Context context();
static QString sourcePath();
static void setSourcePath( const QString &value );
static QString deviceInfo( const Info infoType = Info::Name );

/**
* Tiny smart-pointer-like wrapper around CPLMalloc and CPLFree: this is needed because
Expand Down
57 changes: 55 additions & 2 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -287,6 +287,18 @@
<normaloff>:/images/themes/default/mIconWarning.svg</normaloff>:/images/themes/default/mIconWarning.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>GPU</string>
</property>
<property name="toolTip">
<string>Configure GPU for processing algorithms</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mIconGPU.svg</normaloff>:/images/themes/default/mIconGPU.svg</iconset>
</property>
</item>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -320,7 +332,7 @@
<item>
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="currentIndex">
<number>0</number>
<number>16</number>
</property>
<widget class="QWidget" name="mOptionsPageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -1070,7 +1082,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>544</width>
<width>843</width>
<height>1094</height>
</rect>
</property>
Expand Down Expand Up @@ -5307,6 +5319,47 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="mOptionsPageGPU">
<layout class="QVBoxLayout" name="verticalLayout_29">
<item>
<widget class="QLabel" name="label_53">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Some of the internal C++ processing core algorithms can take advantage of an OpenCL compatible GPU to increase the performances.&lt;br/&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;QGIS support is highly experimental and can crash QGIS because of bugs in the underlying libraries, enable at your own risk!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="mGPUInfoLabel">
<property name="text">
<string>Placemark for OpenCL information results (mGPUInfoLabel)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mGPUEnableCheckBox">
<property name="text">
<string>Enable OpenCL GPU acceleration</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 1decb48

Please sign in to comment.