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>
86class CORE_EXPORT QgsOpenClUtils
111 Q_ENUM( HardwareType )
140 static bool available();
143 static bool enabled();
146 static const std::vector<cl::Device> devices();
155 static cl::Device activeDevice( );
162 static QString activePlatformVersion( );
165 static void storePreferredDevice(
const QString deviceId );
168 static QString preferredDevice( );
171 static QString deviceId(
const cl::Device device );
176 static QString deviceDescription(
const cl::Device device );
181 static QString deviceDescription(
const QString deviceId );
184 static void setEnabled(
bool enabled );
187 static QString buildLog( cl::BuildError &error );
190 static QString sourceFromPath(
const QString &path );
193 static QString sourceFromBaseName(
const QString &baseName );
199 static QString
errorText(
const int errorCode );
243 static QString
deviceInfo(
const Info infoType, cl::Device device );
249 template <
typename T>
255 explicit CPLAllocator(
unsigned long size ): mMem( static_cast<T *>( CPLMalloc( sizeof( T ) * size ) ) ) { }
259 CPLFree(
static_cast<void *
>( mMem ) );
265 CPLFree(
static_cast<void *
>( mMem ) );
271 reset(
static_cast<T *
>( CPLMalloc(
sizeof( T ) *size ) ) );
320 static bool activate(
const QString &preferredDeviceId = QString() );
322 static bool activateInternal(
const QString &preferredDeviceId );
329 static bool sAvailable;
330 static QLatin1String SETTINGS_GLOBAL_ENABLED_KEY;
331 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)