Skip to content

Commit 16a49cd

Browse files
committedAug 8, 2018
Wrap make program in OpenCL utils
1 parent 79f0ead commit 16a49cd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
 

‎src/core/qgsopenclutils.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,35 @@ cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QStr
528528
}
529529
return program;
530530
}
531+
532+
cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior )
533+
{
534+
cl::Program program;
535+
try
536+
{
537+
program = cl::Program( context, source.toStdString( ) );
538+
program.build( "-cl-std=CL1.1" );
539+
}
540+
catch ( cl::BuildError &e )
541+
{
542+
cl::BuildLogType build_logs = e.getBuildLog();
543+
QString build_log;
544+
if ( build_logs.size() > 0 )
545+
build_log = QString::fromStdString( build_logs[0].second );
546+
else
547+
build_log = QObject::tr( "Build logs not available!" );
548+
QString err = QObject::tr( "Error building OpenCL program: %1" )
549+
.arg( build_log );
550+
QgsMessageLog::logMessage( err, LOGMESSAGE_TAG, Qgis::Critical );
551+
if ( exceptionBehavior == Throw )
552+
throw e;
553+
}
554+
catch ( cl::Error &e )
555+
{
556+
QString err = QObject::tr( "Error %1 running OpenCL program in %2" )
557+
.arg( errorText( e.err() ), QString::fromStdString( e.what() ) );
558+
QgsMessageLog::logMessage( err, LOGMESSAGE_TAG, Qgis::Critical );
559+
throw e;
560+
}
561+
return program;
562+
}

‎src/core/qgsopenclutils.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class CORE_EXPORT QgsOpenClUtils
6565

6666
public:
6767

68+
<<<<<<< 79f0eadb05fe4d845ab29045c40c34e1e08b4710
6869
/**
6970
* The ExceptionBehavior enum define how exceptions generated by OpenCL should be treated
7071
*/
@@ -113,6 +114,15 @@ class CORE_EXPORT QgsOpenClUtils
113114
*
114115
* This function must always be called before using QGIS OpenCL utils
115116
*/
117+
=======
118+
enum ExceptionBehavior
119+
{
120+
Catch,
121+
Throw
122+
};
123+
124+
static bool enabled();
125+
>>>>>>> Wrap make program in OpenCL utils
116126
static bool available();
117127

118128
//! Returns true if OpenCL is enabled in the user settings
@@ -166,6 +176,7 @@ class CORE_EXPORT QgsOpenClUtils
166176

167177
//! Returns a string representation from an OpenCL \a errorCode
168178
static QString errorText( const int errorCode );
179+
<<<<<<< 79f0eadb05fe4d845ab29045c40c34e1e08b4710
169180

170181
/**
171182
* Build the program from \a source in the given \a context and depending on \a exceptionBehavior
@@ -181,6 +192,9 @@ class CORE_EXPORT QgsOpenClUtils
181192
* no device were identified or OpenCL support is not available
182193
* and enabled
183194
*/
195+
=======
196+
static cl::Program buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior = Catch );
197+
>>>>>>> Wrap make program in OpenCL utils
184198
static cl::Context context();
185199

186200
//! Returns the base path to OpenCL program directory

0 commit comments

Comments
 (0)
Please sign in to comment.