16#ifndef QGSOPENCLUTILS_H
17#define QGSOPENCLUTILS_H
20#define CL_HPP_ENABLE_EXCEPTIONS
27using namespace Qt::StringLiterals;
30#define CL_HPP_MINIMUM_OPENCL_VERSION 120
31#define CL_HPP_TARGET_OPENCL_VERSION 120
32#define CL_TARGET_OPENCL_VERSION 120
34#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
35#define CL_HPP_TARGET_OPENCL_VERSION 200
36#define CL_TARGET_OPENCL_VERSION 200
41#ifdef OPENCL_USE_NEW_HEADER
42#include <CL/opencl.hpp>
89class CORE_EXPORT QgsOpenClUtils
115 Q_ENUM( HardwareType )
144 static bool available();
147 static bool enabled();
150 static const std::vector<cl::Device> devices();
159 static cl::Device activeDevice();
166 static QString activePlatformVersion();
169 static void storePreferredDevice(
const QString deviceId );
172 static QString preferredDevice();
175 static QString deviceId(
const cl::Device device );
180 static QString deviceDescription(
const cl::Device device );
185 static QString deviceDescription(
const QString deviceId );
188 static void setEnabled(
bool enabled );
191 static QString buildLog( cl::BuildError &error );
194 static QString sourceFromPath(
const QString &path );
197 static QString sourceFromBaseName(
const QString &baseName );
203 static QString
errorText(
const int errorCode );
247 static QString
deviceInfo(
const Info infoType, cl::Device device );
257 : mMem( static_cast<T *>( CPLMalloc( sizeof( T ) * size ) ) )
265 CPLFree(
static_cast<void *
>( mMem ) );
269 void reset(
unsigned long size ) {
reset(
static_cast<T *
>( CPLMalloc(
sizeof( T ) * size ) ) ); }
309 static bool activate(
const QString &preferredDeviceId = QString() );
311 static bool activateInternal(
const QString &preferredDeviceId );
318 static bool sAvailable;
Utilities responsible for common OpenCL operations.
static Q_DECL_DEPRECATED cl::Program buildProgram(const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior=Catch)
Build the program from source in the given context and depending on exceptionBehavior can throw or ca...
static void setSourcePath(const QString &value)
Set the base path to OpenCL program directory.
static QString sourcePath()
Returns the base path to OpenCL program directory.
static cl::Context context()
Context factory.
HardwareType
The Type enum represent OpenCL device type.
static QString activeDeviceInfo(const Info infoType=Info::Name)
Returns infoType information about the active (default) device.
static QString deviceInfo(const Info infoType, cl::Device device)
Returns infoType information about the device.
static QString errorText(const int errorCode)
Returns a string representation from an OpenCL errorCode.
static cl::CommandQueue commandQueue()
Create an OpenCL command queue from the default context.
static const QgsSettingsEntryBool * settingsOpenClEnabled
static const QgsSettingsEntryString * settingsOpenClDefaultDevice
ExceptionBehavior
The ExceptionBehavior enum define how exceptions generated by OpenCL should be treated.
@ Throw
Write errors in the message log and re-throw exceptions.
@ Catch
Write errors in the message log and silently fail.
Info
The Info enum maps to OpenCL info constants.
static QLatin1String LOGMESSAGE_TAG
OpenCL string for message logs.
A boolean settings entry.
T & operator[](const int index)
void reset(unsigned long size)
CPLAllocator(unsigned long size)