Skip to content
Permalink
Browse files

Fix build warning and cl-std for 2.x builds

  • Loading branch information
elpaso committed Nov 30, 2018
1 parent e5b8645 commit a471934e56cab0cc3eed484d19efb5568872bee1
Showing with 26 additions and 17 deletions.
  1. +18 −9 src/core/qgsopenclutils.cpp
  2. +8 −1 src/core/qgsopenclutils.h
  3. +0 −7 tests/src/core/testqgsopenclutils.cpp
@@ -41,8 +41,7 @@ const std::vector<cl::Device> QgsOpenClUtils::devices()
{
std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
QgsDebugMsg( QStringLiteral( "Found OpenCL platform %1: %2" ).arg( QString::fromStdString( platver ), QString::fromStdString( p.getInfo<CL_PLATFORM_NAME>() ) ) );
// Check both versions 1 and 2
if ( platver.find( "OpenCL 1." ) != std::string::npos || platver.find( "OpenCL 2." ) != std::string::npos )
if ( platver.find( "OpenCL " ) != std::string::npos )
{
std::vector<cl::Device> _devices;
// Check for a device
@@ -219,8 +218,7 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
break;
std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
QgsDebugMsg( QStringLiteral( "Found OpenCL platform %1: %2" ).arg( QString::fromStdString( platver ), QString::fromStdString( p.getInfo<CL_PLATFORM_NAME>() ) ) );
// Checks both versions 1 and 2
if ( platver.find( "OpenCL 1." ) != std::string::npos || platver.find( "OpenCL 2." ) != std::string::npos )
if ( platver.find( "OpenCL " ) != std::string::npos )
{
std::vector<cl::Device> devices;
// Search for a device
@@ -262,7 +260,7 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
{
for ( const auto &_dev : devices )
{
if ( _dev.getInfo<CL_DEVICE_TYPE>() == CL_DEVICE_TYPE_GPU )
if ( _dev.getInfo<CL_DEVICE_TYPE>() == CL_DEVICE_TYPE_CPU )
{
// Got one!
plat = p;
@@ -548,10 +546,21 @@ cl::Program QgsOpenClUtils::buildProgram( const QString &source, QgsOpenClUtils:
try
{
program = cl::Program( QgsOpenClUtils::context(), source.toStdString( ) );
// OpenCL version for compatibility with older hardware
program.build( QStringLiteral( "-cl-std=CL%1 -I%2" )
.arg( QgsOpenClUtils::activePlatformVersion( ) )
.arg( sourcePath() ).toStdString().c_str() );
// OpenCL version for compatibility with older hardware, but it's up to
// llvm to support latest CL versions
bool ok;
float version( QgsOpenClUtils::activePlatformVersion().toFloat( &ok ) );
if ( ok && version < 2.0f )
{
program.build( QStringLiteral( "-cl-std=CL%1 -I%2" )
.arg( QgsOpenClUtils::activePlatformVersion( ) )
.arg( sourcePath() ).toStdString().c_str() );
}
else
{
program.build( QStringLiteral( "-I%1" )
.arg( sourcePath() ).toStdString().c_str() );
}
}
catch ( cl::BuildError &e )
{
@@ -21,7 +21,8 @@
#define CL_HPP_ENABLE_EXCEPTIONS
//#define CL_HPP_MINIMUM_OPENCL_VERSION 110
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#define CL_HPP_TARGET_OPENCL_VERSION 200
#define CL_HPP_TARGET_OPENCL_VERSION 220
#define CL_TARGET_OPENCL_VERSION 220
#include <CL/cl2.hpp>

#include "qgis_core.h"
@@ -175,6 +176,12 @@ class CORE_EXPORT QgsOpenClUtils
//! Returns a string representation from an OpenCL \a errorCode
static QString errorText( const int errorCode );

/**
* Create an OpenCL command queue from the default context.
*
* This wrapper is required in order to prevent a crash when
* running on OpenCL platforms < 2
*/
static cl::CommandQueue commandQueue();

/**
@@ -57,13 +57,6 @@ class TestQgsOpenClUtils: public QObject
void _testMakeRunProgram();
void _testMakeHillshade( const int loops );

cl::Program buildProgram( const cl::Context &context, const QString &source )
{
cl::Program program( context, source.toStdString( ) );
program.build( "-cl-std=CL1.1" );
return program;
}

std::string source()
{
std::string pgm = R"CL(

0 comments on commit a471934

Please sign in to comment.
You can’t perform that action at this time.