16#ifndef QGSOPENCLUTILS_H
17#define QGSOPENCLUTILS_H
21#define CL_HPP_ENABLE_EXCEPTIONS
26#define CL_HPP_MINIMUM_OPENCL_VERSION 120
27#define CL_HPP_TARGET_OPENCL_VERSION 120
28#define CL_TARGET_OPENCL_VERSION 120
30#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
31#define CL_HPP_TARGET_OPENCL_VERSION 200
32#define CL_TARGET_OPENCL_VERSION 200
37#ifdef OPENCL_USE_NEW_HEADER
38#include <CL/opencl.hpp>
82class CORE_EXPORT QgsOpenClUtils
107 Q_ENUM( HardwareType )
136 static bool available();
139 static bool enabled();
142 static const std::vector<cl::Device> devices();
151 static cl::Device activeDevice( );
158 static QString activePlatformVersion( );
161 static void storePreferredDevice(
const QString deviceId );
164 static QString preferredDevice( );
167 static QString deviceId(
const cl::Device device );
172 static QString deviceDescription(
const cl::Device device );
177 static QString deviceDescription(
const QString deviceId );
180 static void setEnabled(
bool enabled );
183 static QString buildLog( cl::BuildError &error );
186 static QString sourceFromPath(
const QString &path );
189 static QString sourceFromBaseName(
const QString &baseName );
195 static QString
errorText(
const int errorCode );
239 static QString
deviceInfo(
const Info infoType, cl::Device device );
245 template <
typename T>
251 explicit CPLAllocator(
unsigned long size ): mMem( static_cast<T *>( CPLMalloc( sizeof( T ) * size ) ) ) { }
255 CPLFree(
static_cast<void *
>( mMem ) );
261 CPLFree(
static_cast<void *
>( mMem ) );
267 reset(
static_cast<T *
>( CPLMalloc(
sizeof( T ) *size ) ) );
316 static bool activate(
const QString &preferredDeviceId = QString() );
318 static bool activateInternal(
const QString &preferredDeviceId );
325 static bool sAvailable;
326 static QLatin1String SETTINGS_GLOBAL_ENABLED_KEY;
327 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)