From e4228f4bfd49f81bc1e9abe544af607a65c3160b Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Fri, 6 Jul 2018 09:28:39 +0200 Subject: [PATCH] [opencl] Add performance test --- tests/src/core/testqgsopenclutils.cpp | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/src/core/testqgsopenclutils.cpp b/tests/src/core/testqgsopenclutils.cpp index e897196ce80..a773d903de3 100644 --- a/tests/src/core/testqgsopenclutils.cpp +++ b/tests/src/core/testqgsopenclutils.cpp @@ -19,10 +19,12 @@ #include #include #include +#include //header for class being tested #include - +#include +#include class TestQgsOpenClUtils: public QObject { @@ -46,7 +48,11 @@ class TestQgsOpenClUtils: public QObject private: + // For performance testing + void testHillshade(); + void _testMakeRunProgram(); + void _testMakeHillshade( const QString title, const int loops ); cl::Program buildProgram( const cl::Context &context, const QString &source ) { @@ -67,11 +73,15 @@ class TestQgsOpenClUtils: public QObject return pgm; } + + QgsRasterLayer *mFloat32RasterLayer = nullptr; }; void TestQgsOpenClUtils::init() { + // Reset to default in case some tests mess it up + QgsOpenClUtils::setSourcePath( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/opencl_programs" ) ) ); } void TestQgsOpenClUtils::cleanup() @@ -89,6 +99,11 @@ void TestQgsOpenClUtils::initTestCase() QgsApplication::init(); QgsApplication::initQgis(); + + QString float32FileName = QStringLiteral( TEST_DATA_DIR ) + '/' + "/raster/band1_float32_noct_epsg4326.tif"; + QFileInfo float32RasterFileInfo( float32FileName ); + mFloat32RasterLayer = new QgsRasterLayer( float32RasterFileInfo.filePath(), + float32RasterFileInfo.completeBaseName() ); } @@ -183,6 +198,27 @@ void TestQgsOpenClUtils::testContext() QVERIFY( QgsOpenClUtils::context()() != nullptr ); } +void TestQgsOpenClUtils::_testMakeHillshade( const QString title, const int loops ) +{ + std::chrono::time_point startTime( std::chrono::system_clock::now() ); + for ( int i = 0 ; i < loops; i++ ) + { + QgsHillshadeRenderer renderer( mFloat32RasterLayer->dataProvider(), 1, 35.0, 5000.0 ); + QgsRasterBlock *block = renderer.block( 0, mFloat32RasterLayer->extent(), 401, 401 ); + } + qDebug() << QStringLiteral( "%1 average for %2 loops: %3 ms" ) + .arg( title ) + .arg( loops ) + .arg( std::chrono::duration_cast( std::chrono::system_clock::now() - startTime ).count() / loops ) ; +} + +void TestQgsOpenClUtils::testHillshade() +{ + QgsOpenClUtils::setEnabled( true ); + _testMakeHillshade( QStringLiteral( "OpenCL" ), 5 ); + QgsOpenClUtils::setEnabled( false ); + _testMakeHillshade( QStringLiteral( "CPU" ), 5 ); +} QGSTEST_MAIN( TestQgsOpenClUtils ) #include "testqgsopenclutils.moc"