Skip to content

Commit 350829e

Browse files
committed
[opencl] Test with image2d
1 parent 1decb48 commit 350829e

File tree

6 files changed

+400
-147
lines changed

6 files changed

+400
-147
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "calcfirstder.cl"
2+
3+
__constant sampler_t sampler =
4+
CLK_NORMALIZED_COORDS_FALSE
5+
| CLK_ADDRESS_CLAMP_TO_EDGE
6+
| CLK_FILTER_NEAREST;
7+
8+
__kernel void processNineCellWindow(
9+
__read_only image2d_t inputImage,
10+
image2d_t outputImage,
11+
__global float *rasterParams
12+
) {
13+
14+
15+
// 0=width, 1=height
16+
int2 currentPosition = (int2)(get_global_id(0), get_global_id(1));
17+
float4 currentPixel = (ufloat4)(0.0f);
18+
float4 calculatedPixel = (float4)(1.0f);
19+
20+
currentPixel = read_imageuf(inputImage, sampler, currentPosition);
21+
calculatedPixel = currentPixel;
22+
write_imageuf(outputImage, currentPosition, calculatedPixel);
23+
}
24+
25+
26+
const sampler_t smp = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR;
27+
28+
void kernel copy(__read_only image2d_t in, image2d_t out)
29+
{
30+
int x = get_global_id(0);
31+
int y = get_global_id(1);
32+
int2 pos = (int2)(x, y);
33+
uint4 pixel = read_imageui(in, smp, pos);
34+
write_imageui(out, pos, pixel);
35+
}

src/analysis/raster/qgsninecellfilter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
220220

221221
cl_int errorCode = 0;
222222

223-
// Cast to float
223+
// Cast to float (because double just crashes on some GPUs)
224224
std::vector<float> rasterParams;
225225

226226
rasterParams.push_back( mInputNodataValue );
@@ -305,7 +305,7 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
305305
scanLine3[0] = scanLine3[xSize + 1] = mInputNodataValue;
306306

307307
// TODO: There is room for further optimization here: instead of replacing the buffers
308-
// we could just replace just hthe new one (the top row) and switch the order
308+
// we could just replace just the new one (the top row) and switch the order
309309
// of buffer arguments in the kernell call.
310310
errorCode = cl::enqueueWriteBuffer( scanLine1Buffer, CL_TRUE, 0,
311311
sizeof( float ) * ( xSize + 2 ), scanLine1.get() );

src/app/qgsoptions.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,20 +1092,25 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
10921092
"Vendor: <b>%2</b><br>"
10931093
"Profile: <b>%3</b><br>"
10941094
"Version: <b>%4</b><br>"
1095+
"Image support: <b>%5</b><br>"
1096+
"Max image2d width: <b>%6</b><br>"
1097+
"Max image2d height: <b>%7</b><br>"
10951098
).arg( QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Name ),
10961099
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Vendor ),
10971100
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Profile ),
1098-
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Version ) )
1101+
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Version ),
1102+
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::ImageSupport ),
1103+
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Image2dMaxWidth ),
1104+
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Image2dMaxHeight )
1105+
)
10991106
);
1100-
connect( mGPUEnableCheckBox, &QCheckBox::toggled, this, []( bool status )
1101-
{
1102-
QgsOpenClUtils::setEnabled( status );
1103-
}, Qt::UniqueConnection );
11041107
}
11051108
else
11061109
{
11071110
mGPUEnableCheckBox->setEnabled( false );
1108-
mGPUInfoLabel->setText( QStringLiteral( "OpenCL compatible GPU was not found on your system. You may need to install additional libraries in order to enable OpenCL." ) );
1111+
mGPUInfoLabel->setText( QStringLiteral( "OpenCL compatible GPU was not found on your system.<br>"
1112+
"You may need to install additional libraries in order to enable OpenCL.<br>"
1113+
"Please check your logs for further details." ) );
11091114
}
11101115

11111116

@@ -1658,6 +1663,12 @@ void QgsOptions::saveOptions()
16581663
// Number settings
16591664
mSettings->setValue( QStringLiteral( "locale/showGroupSeparator" ), cbShowGroupSeparator->isChecked( ) );
16601665

1666+
#ifdef HAVE_OPENCL
1667+
// OpenCL settings
1668+
QgsOpenClUtils::setEnabled( mGPUEnableCheckBox->isChecked() );
1669+
1670+
#endif
1671+
16611672
// Gdal skip driver list
16621673
if ( mLoadedGdalDriverList )
16631674
saveGdalDriverList();

src/core/qgsopenclutils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ QString QgsOpenClUtils::deviceInfo( const Info infoType )
126126
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_PROFILE>() );
127127
case Info::Version:
128128
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_VERSION>() );
129+
case Info::ImageSupport:
130+
return sDevice.getInfo<CL_DEVICE_IMAGE_SUPPORT>() ? QStringLiteral( "True" ) : QStringLiteral( "False" );
131+
case Info::Image2dMaxHeight:
132+
return QString::number( sDevice.getInfo<CL_DEVICE_IMAGE2D_MAX_HEIGHT>() );
133+
case Info::Image2dMaxWidth:
134+
return QString::number( sDevice.getInfo<CL_DEVICE_IMAGE2D_MAX_WIDTH>() );
129135
case Info::Name:
130136
default:
131137
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_NAME>() );
@@ -151,6 +157,8 @@ void QgsOpenClUtils::setEnabled( bool enabled )
151157
QgsSettings().setValue( SETTINGS_KEY, enabled, QgsSettings::Section::Core );
152158
}
153159

160+
161+
154162
QString QgsOpenClUtils::sourceFromPath( const QString &path )
155163
{
156164
// TODO: check for compatibility with current platform ( cl_khr_fp64 )

src/core/qgsopenclutils.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ class CORE_EXPORT QgsOpenClUtils
5555
Name = CL_DEVICE_NAME,
5656
Vendor = CL_DEVICE_VENDOR,
5757
Version = CL_DEVICE_VERSION,
58-
Profile = CL_DEVICE_PROFILE
58+
Profile = CL_DEVICE_PROFILE,
59+
ImageSupport = CL_DEVICE_IMAGE_SUPPORT,
60+
Image2dMaxWidth = CL_DEVICE_IMAGE2D_MAX_WIDTH,
61+
Image2dMaxHeight = CL_DEVICE_IMAGE2D_MAX_HEIGHT
5962
};
6063

6164
static bool enabled();
@@ -67,6 +70,14 @@ class CORE_EXPORT QgsOpenClUtils
6770
static QLatin1String LOGMESSAGE_TAG;
6871
static QString errorText( const int errorCode );
6972
static cl::Program buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior = Catch );
73+
74+
/**
75+
* Context factory
76+
*
77+
* \return a new context for the default device or an invalid context if
78+
* no device were identified or OpenCL support is not available
79+
* and enabled
80+
*/
7081
static cl::Context context();
7182
static QString sourcePath();
7283
static void setSourcePath( const QString &value );

0 commit comments

Comments
 (0)