Wrap make program in OpenCL utils

This commit is contained in:
Alessandro Pasotti 2018-04-19 09:40:06 +02:00
parent 79f0eadb05
commit 16a49cddaa
2 changed files with 46 additions and 0 deletions

View File

@ -528,3 +528,35 @@ cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QStr
}
return program;
}
cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior )
{
cl::Program program;
try
{
program = cl::Program( context, source.toStdString( ) );
program.build( "-cl-std=CL1.1" );
}
catch ( cl::BuildError &e )
{
cl::BuildLogType build_logs = e.getBuildLog();
QString build_log;
if ( build_logs.size() > 0 )
build_log = QString::fromStdString( build_logs[0].second );
else
build_log = QObject::tr( "Build logs not available!" );
QString err = QObject::tr( "Error building OpenCL program: %1" )
.arg( build_log );
QgsMessageLog::logMessage( err, LOGMESSAGE_TAG, Qgis::Critical );
if ( exceptionBehavior == Throw )
throw e;
}
catch ( cl::Error &e )
{
QString err = QObject::tr( "Error %1 running OpenCL program in %2" )
.arg( errorText( e.err() ), QString::fromStdString( e.what() ) );
QgsMessageLog::logMessage( err, LOGMESSAGE_TAG, Qgis::Critical );
throw e;
}
return program;
}

View File

@ -65,6 +65,7 @@ class CORE_EXPORT QgsOpenClUtils
public:
<<<<<<< 79f0eadb05fe4d845ab29045c40c34e1e08b4710
/**
* The ExceptionBehavior enum define how exceptions generated by OpenCL should be treated
*/
@ -113,6 +114,15 @@ class CORE_EXPORT QgsOpenClUtils
*
* This function must always be called before using QGIS OpenCL utils
*/
=======
enum ExceptionBehavior
{
Catch,
Throw
};
static bool enabled();
>>>>>>> Wrap make program in OpenCL utils
static bool available();
//! Returns true if OpenCL is enabled in the user settings
@ -166,6 +176,7 @@ class CORE_EXPORT QgsOpenClUtils
//! Returns a string representation from an OpenCL \a errorCode
static QString errorText( const int errorCode );
<<<<<<< 79f0eadb05fe4d845ab29045c40c34e1e08b4710
/**
* Build the program from \a source in the given \a context and depending on \a exceptionBehavior
@ -181,6 +192,9 @@ class CORE_EXPORT QgsOpenClUtils
* no device were identified or OpenCL support is not available
* and enabled
*/
=======
static cl::Program buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior = Catch );
>>>>>>> Wrap make program in OpenCL utils
static cl::Context context();
//! Returns the base path to OpenCL program directory