Skip to content

Commit 9068fe4

Browse files
committedAug 8, 2018
More updates for opencl
1 parent 7404263 commit 9068fe4

File tree

13 files changed

+352
-126
lines changed

13 files changed

+352
-126
lines changed
 

‎python/analysis/auto_generated/raster/qgsaspectfilter.sip.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Calculates output value from nine input values. The input values and the output
2929
nodata value if not present or outside of the border. Must be implemented by subclasses*
3030
%End
3131

32+
33+
34+
3235
};
3336

3437
/************************************************************************

‎python/analysis/auto_generated/raster/qgsninecellfilter.sip.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212

13+
1314
class QgsNineCellFilter
1415
{
1516
%Docstring
@@ -34,7 +35,8 @@ Starts the calculation, reads from mInputFile and stores the result in mOutputFi
3435

3536
:param feedback: feedback object that receives update and that is checked for cancelation.
3637

37-
:return: 0 in case of success*
38+
:return: 0 in case of success
39+
TODO: return an enum
3840
%End
3941

4042
double cellSizeX() const;

‎python/analysis/auto_generated/raster/qgsslopefilter.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Calculates slope values in a window of 3x3 cells based on first order derivative
2828
Calculates output value from nine input values. The input values and the output value can be equal to the
2929
nodata value if not present or outside of the border. Must be implemented by subclasses*
3030
%End
31+
3132
};
3233

3334
/************************************************************************

‎src/analysis/raster/qgsaspectfilter.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ class ANALYSIS_EXPORT QgsAspectFilter: public QgsDerivativeFilter
3636
float *x12, float *x22, float *x32,
3737
float *x13, float *x23, float *x33 ) override;
3838

39+
40+
41+
42+
// QgsNineCellFilter interface
43+
private:
44+
const QString openClProgramBaseName() const override
45+
{
46+
return QStringLiteral( "aspect" );
47+
}
3948
};
4049

4150
#endif // QGSASPECTFILTER_H

‎src/analysis/raster/qgshillshadefilter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ANALYSIS_EXPORT QgsHillshadeFilter: public QgsDerivativeFilter
4646
private:
4747
float mLightAzimuth;
4848
float mLightAngle;
49+
4950
};
5051

5152
#endif // QGSHILLSHADEFILTER_H

‎src/analysis/raster/qgsninecellfilter.cpp

Lines changed: 255 additions & 116 deletions
Large diffs are not rendered by default.

‎src/analysis/raster/qgsninecellfilter.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "gdal.h"
2323
#include "qgis_analysis.h"
2424
#include "qgsogrutils.h"
25+
#include "qgsopenclutils.h"
26+
2527
class QgsFeedback;
2628

2729
/**
@@ -40,7 +42,9 @@ class ANALYSIS_EXPORT QgsNineCellFilter
4042
/**
4143
* Starts the calculation, reads from mInputFile and stores the result in mOutputFile
4244
\param feedback feedback object that receives update and that is checked for cancelation.
43-
\returns 0 in case of success*/
45+
\returns 0 in case of success
46+
TODO: return an enum
47+
*/
4448
int processRaster( QgsFeedback *feedback = nullptr );
4549

4650
double cellSizeX() const { return mCellSizeX; }
@@ -80,6 +84,36 @@ class ANALYSIS_EXPORT QgsNineCellFilter
8084
\returns the output dataset or nullptr in case of error*/
8185
gdal::dataset_unique_ptr openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
8286

87+
/**
88+
* \brief processRasterCPU executes the computation on the CPU
89+
* \param feedback
90+
* \return an opaque integer for error codes: 0 in case of success
91+
* TODO: return an enum
92+
*/
93+
int processRasterCPU( QgsFeedback *feedback = nullptr );
94+
95+
#ifdef HAVE_OPENCL
96+
97+
/**
98+
* \brief processRasterGPU executes the computation on the GPU
99+
* \param feedback
100+
* \return an opaque integer for error codes: 0 in case of success
101+
* TODO: return an enum
102+
*/
103+
int processRasterGPU( const QString &source, QgsFeedback *feedback = nullptr );
104+
105+
virtual void addExtraRasterParams( std::vector<float> &params )
106+
{
107+
Q_UNUSED( params );
108+
}
109+
110+
virtual const QString openClProgramBaseName() const
111+
{
112+
return QString();
113+
}
114+
115+
#endif
116+
83117
protected:
84118

85119
QString mInputFile;

‎src/analysis/raster/qgsruggednessfilter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class ANALYSIS_EXPORT QgsRuggednessFilter: public QgsNineCellFilter
4141

4242
private:
4343
QgsRuggednessFilter();
44+
45+
//virtual QString _openClProgramBaseName() override { return QStringLiteral( "ruggedness" ); }
46+
4447
};
4548

4649
#endif // QGSRUGGEDNESSFILTER_H

‎src/analysis/raster/qgsslopefilter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ QgsSlopeFilter::QgsSlopeFilter( const QString &inputFile, const QString &outputF
2424

2525
}
2626

27-
float QgsSlopeFilter::processNineCellWindow( float *x11, float *x21, float *x31,
28-
float *x12, float *x22, float *x32, float *x13, float *x23, float *x33 )
27+
float QgsSlopeFilter::processNineCellWindow(
28+
float *x11, float *x21, float *x31,
29+
float *x12, float *x22, float *x32,
30+
float *x13, float *x23, float *x33 )
2931
{
3032
float derX = calcFirstDerX( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
3133
float derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33 );

‎src/analysis/raster/qgsslopefilter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ class ANALYSIS_EXPORT QgsSlopeFilter: public QgsDerivativeFilter
3535
float processNineCellWindow( float *x11, float *x21, float *x31,
3636
float *x12, float *x22, float *x32,
3737
float *x13, float *x23, float *x33 ) override;
38+
39+
private:
40+
41+
virtual const QString openClProgramBaseName() const override
42+
{
43+
return QStringLiteral( "slope" );
44+
}
45+
3846
};
3947

4048
#endif // QGSSLOPEFILTER_H

‎src/analysis/raster/slope.cl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
22

33
float calcFirstDer( float x11, float x21, float x31, float x12, float x22, float x32, float x13, float x23, float x33,
4-
double mInputNodataValue, double mOutputNodataValue, double mZFactor, double mCellSize )
4+
float mInputNodataValue, float mOutputNodataValue, float mZFactor, float mCellSize )
55
{
66
//the basic formula would be simple, but we need to test for nodata values...
77
//X: return (( (x31 - x11) + 2 * (x32 - x12) + (x33 - x13) ) / (8 * mCellSizeX));
88
//Y: return (((x11 - x13) + 2 * (x21 - x23) + (x31 - x33)) / ( 8 * mCellSizeY));
99

1010
int weight = 0;
11-
double sum = 0;
11+
float sum = 0;
1212

1313

1414
//first row
@@ -75,7 +75,7 @@ __kernel void processNineCellWindow( __global float *scanLine1,
7575
__global float *scanLine2,
7676
__global float *scanLine3,
7777
__global float *resultLine,
78-
__global double *rasterParams
78+
__global float *rasterParams
7979
) {
8080

8181
// Get the index of the current element
@@ -102,8 +102,8 @@ __kernel void processNineCellWindow( __global float *scanLine1,
102102
}
103103
else
104104
{
105-
double res = sqrt( derX * derX + derY * derY );
105+
float res = sqrt( derX * derX + derY * derY );
106106
res = atanpi( res );
107-
resultLine[i] = (float)res * 180.0;
107+
resultLine[i] = res * 180.0;
108108
}
109109
}

‎src/core/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ SET(QGIS_CORE_SRCS
521521
qgsuserprofilemanager.cpp
522522
)
523523

524-
525524
FILE(GLOB JSON_HELP_FILES "${CMAKE_SOURCE_DIR}/resources/function_help/json/*")
526525
IF(NOT USING_NINJA)
527526
STRING(REPLACE "$" "$$" JSON_HELP_FILES "${JSON_HELP_FILES}")
@@ -1210,6 +1209,17 @@ INCLUDE_DIRECTORIES(SYSTEM
12101209
)
12111210

12121211

1212+
IF (HAVE_OPENCL)
1213+
SET(QGIS_CORE_SRCS ${QGIS_CORE_SRCS}
1214+
qgsopenclutils.cpp
1215+
)
1216+
SET(QGIS_CORE_HDRS ${QGIS_CORE_HDRS}
1217+
qgsopenclutils.h
1218+
)
1219+
INCLUDE_DIRECTORIES(${OpenCL_INCLUDE_DIR})
1220+
ENDIF (HAVE_OPENCL)
1221+
1222+
12131223
IF (APPLE)
12141224
# Libtasn1 is for DER-encoded PKI ASN.1 parsing/extracting workarounds
12151225
INCLUDE_DIRECTORIES(SYSTEM
@@ -1245,6 +1255,12 @@ IF(ENABLE_MODELTEST)
12451255
TARGET_LINK_LIBRARIES(qgis_core ${Qt5Test_LIBRARIES})
12461256
ENDIF(ENABLE_MODELTEST)
12471257

1258+
1259+
IF(HAVE_OPENCL)
1260+
TARGET_LINK_LIBRARIES(qgis_core ${OpenCL_LIBRARY})
1261+
ENDIF(HAVE_OPENCL)
1262+
1263+
12481264
IF(NOT APPLE)
12491265
INSTALL(FILES ${QGIS_CORE_HDRS} ${QGIS_CORE_MOC_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
12501266
ELSE(NOT APPLE)

‎tests/src/core/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ IF(WITH_QTWEBKIT)
205205
)
206206
ENDIF(WITH_QTWEBKIT)
207207

208+
209+
IF(HAVE_OPENCL)
210+
SET(TESTS ${TESTS}
211+
testqgsopenclutils.cpp
212+
)
213+
ENDIF(HAVE_OPENCL)
214+
215+
208216
FOREACH(TESTSRC ${TESTS})
209217
ADD_QGIS_TEST(${TESTSRC})
210218
ENDFOREACH(TESTSRC)

0 commit comments

Comments
 (0)
Please sign in to comment.