Skip to content

Commit

Permalink
[opencl] Remove all static members
Browse files Browse the repository at this point in the history
and rely on the default() mechanism, this prevents
random crashes on exit when dtor is called on the
statics

cherry-pick 868b04d
  • Loading branch information
elpaso committed Dec 5, 2018
1 parent c455bf6 commit bd36edb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 18 additions & 7 deletions src/core/qgsopenclutils.cpp
Expand Up @@ -27,8 +27,6 @@ QLatin1String QgsOpenClUtils::SETTINGS_GLOBAL_ENABLED_KEY = QLatin1Literal( "Ope
QLatin1String QgsOpenClUtils::SETTINGS_DEFAULT_DEVICE_KEY = QLatin1Literal( "OpenClDefaultDevice" );
QLatin1String QgsOpenClUtils::LOGMESSAGE_TAG = QLatin1Literal( "OpenCL" );
bool QgsOpenClUtils::sAvailable = false;
cl::Platform QgsOpenClUtils::sDefaultPlatform = cl::Platform();
cl::Device QgsOpenClUtils::sActiveDevice = cl::Device();
QString QgsOpenClUtils::sSourcePath = QString();


Expand Down Expand Up @@ -163,7 +161,21 @@ bool QgsOpenClUtils::enabled()

cl::Device QgsOpenClUtils::activeDevice()
{
return sActiveDevice;
return cl::Device::getDefault();
}

QString QgsOpenClUtils::activePlatformVersion()
{
QString version;
if ( cl::Platform::getDefault()() )
{
std::string platver = cl::Platform::getDefault().getInfo<CL_PLATFORM_VERSION>();
if ( platver.find( "OpenCL " ) != std::string::npos )
{
version = QString::fromStdString( platver.substr( 7 ) ).split( ' ' ).first();
}
}
return version;
}

void QgsOpenClUtils::storePreferredDevice( const QString deviceId )
Expand All @@ -189,6 +201,7 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
{
if ( deviceId( activeDevice() ) == preferredDeviceId )
{
sAvailable = true;
return false;
}
try
Expand Down Expand Up @@ -292,8 +305,6 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
.arg( QString::fromStdString( dev.getInfo<CL_DEVICE_NAME>() ) ),
LOGMESSAGE_TAG, Qgis::Success );
sAvailable = true;
sActiveDevice = dev;
sDefaultPlatform = plat;
}
}
}
Expand Down Expand Up @@ -491,9 +502,9 @@ cl::Context QgsOpenClUtils::context()
static std::once_flag contextCreated;
std::call_once( contextCreated, [ = ]()
{
if ( available() && sDefaultPlatform() && sActiveDevice() )
if ( available() && cl::Platform::getDefault()() && cl::Device::getDefault()() )
{
context = cl::Context( sActiveDevice );
context = cl::Context( cl::Device::getDefault() );
}
} );
return context;
Expand Down
2 changes: 0 additions & 2 deletions src/core/qgsopenclutils.h
Expand Up @@ -281,8 +281,6 @@ class CORE_EXPORT QgsOpenClUtils
static void init();

static bool sAvailable;
static cl::Device sActiveDevice;
static cl::Platform sDefaultPlatform;
static QLatin1String SETTINGS_GLOBAL_ENABLED_KEY;
static QLatin1String SETTINGS_DEFAULT_DEVICE_KEY;
static QString sSourcePath;
Expand Down

0 comments on commit bd36edb

Please sign in to comment.