16#ifndef QGSOPENCLUTILS_H
17#define QGSOPENCLUTILS_H
21#define CL_HPP_ENABLE_EXCEPTIONS
26using namespace Qt::StringLiterals;
29#define CL_HPP_MINIMUM_OPENCL_VERSION 120
30#define CL_HPP_TARGET_OPENCL_VERSION 120
31#define CL_TARGET_OPENCL_VERSION 120
33#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
34#define CL_HPP_TARGET_OPENCL_VERSION 200
35#define CL_TARGET_OPENCL_VERSION 200
40#ifdef OPENCL_USE_NEW_HEADER
41#include <CL/opencl.hpp>
85class CORE_EXPORT QgsOpenClUtils
110 Q_ENUM( HardwareType )
139 static bool available();
142 static bool enabled();
145 static const std::vector<cl::Device> devices();
154 static cl::Device activeDevice( );
161 static QString activePlatformVersion( );
164 static void storePreferredDevice(
const QString deviceId );
167 static QString preferredDevice( );
170 static QString deviceId(
const cl::Device device );
175 static QString deviceDescription(
const cl::Device device );
180 static QString deviceDescription(
const QString deviceId );
183 static void setEnabled(
bool enabled );
186 static QString buildLog( cl::BuildError &error );
189 static QString sourceFromPath(
const QString &path );
192 static QString sourceFromBaseName(
const QString &baseName );
198 static QString
errorText(
const int errorCode );
242 static QString
deviceInfo(
const Info infoType, cl::Device device );
248 template <
typename T>
254 explicit CPLAllocator(
unsigned long size ): mMem( static_cast<T *>( CPLMalloc( sizeof( T ) * size ) ) ) { }
258 CPLFree(
static_cast<void *
>( mMem ) );
264 CPLFree(
static_cast<void *
>( mMem ) );
270 reset(
static_cast<T *
>( CPLMalloc(
sizeof( T ) *size ) ) );
319 static bool activate(
const QString &preferredDeviceId = QString() );
321 static bool activateInternal(
const QString &preferredDeviceId );
328 static bool sAvailable;
329 static QLatin1String SETTINGS_GLOBAL_ENABLED_KEY;
330 static QLatin1String SETTINGS_DEFAULT_DEVICE_KEY;
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.
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.
QgsMargins operator*(const QgsMargins &margins, double factor)
Returns a QgsMargins object that is formed by multiplying each component of the given margins by fact...
T & operator[](const int index)
void reset(unsigned long size)
CPLAllocator(unsigned long size)