Skip to content

Commit

Permalink
Wrap make program in OpenCL utils
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Aug 8, 2018
1 parent 79f0ead commit 16a49cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/core/qgsopenclutils.cpp
Expand Up @@ -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;
}
14 changes: 14 additions & 0 deletions src/core/qgsopenclutils.h
Expand Up @@ -65,6 +65,7 @@ class CORE_EXPORT QgsOpenClUtils

public:

<<<<<<< 79f0eadb05fe4d845ab29045c40c34e1e08b4710
/**
* The ExceptionBehavior enum define how exceptions generated by OpenCL should be treated
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 16a49cd

Please sign in to comment.