16 #ifndef QGSOPENCLUTILS_H
17 #define QGSOPENCLUTILS_H
21 #define CL_HPP_ENABLE_EXCEPTIONS
25 #define CL_HPP_MINIMUM_OPENCL_VERSION 120
26 #define CL_HPP_TARGET_OPENCL_VERSION 120
27 #define CL_TARGET_OPENCL_VERSION 120
29 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
30 #define CL_HPP_TARGET_OPENCL_VERSION 200
31 #define CL_TARGET_OPENCL_VERSION 200
34 #include "qgsconfig.h"
36 #ifdef OPENCL_USE_NEW_HEADER
37 #include <CL/opencl.hpp>
42 #include "qgis_core.h"
104 Q_ENUM( HardwareType )
113 Name = CL_DEVICE_NAME,
114 Vendor = CL_DEVICE_VENDOR,
115 Version = CL_DEVICE_VERSION,
116 Profile = CL_DEVICE_PROFILE,
117 ImageSupport = CL_DEVICE_IMAGE_SUPPORT,
118 Image2dMaxWidth = CL_DEVICE_IMAGE2D_MAX_WIDTH,
119 Image2dMaxHeight = CL_DEVICE_IMAGE2D_MAX_HEIGHT,
120 MaxMemAllocSize = CL_DEVICE_MAX_MEM_ALLOC_SIZE,
121 Type = CL_DEVICE_TYPE
133 static bool available();
136 static bool enabled();
139 static const std::vector<cl::Device> devices();
148 static cl::Device activeDevice( );
155 static QString activePlatformVersion( );
158 static void storePreferredDevice(
const QString deviceId );
161 static QString preferredDevice( );
164 static QString deviceId(
const cl::Device device );
169 static QString deviceDescription(
const cl::Device device );
174 static QString deviceDescription(
const QString deviceId );
177 static void setEnabled(
bool enabled );
180 static QString buildLog( cl::BuildError &error );
183 static QString sourceFromPath(
const QString &path );
186 static QString sourceFromBaseName(
const QString &baseName );
192 static QString errorText(
const int errorCode );
200 static cl::CommandQueue commandQueue();
208 Q_DECL_DEPRECATED
static cl::Program buildProgram(
const cl::Context &context,
const QString &source,
ExceptionBehavior exceptionBehavior = Catch );
214 static cl::Program buildProgram(
const QString &source,
ExceptionBehavior exceptionBehavior = Catch );
224 static cl::Context context();
227 static QString sourcePath();
230 static void setSourcePath(
const QString &value );
233 static QString activeDeviceInfo(
const Info infoType = Info::Name );
236 static QString deviceInfo(
const Info infoType, cl::Device device );
242 template <
typename T>
248 explicit CPLAllocator(
unsigned long size ): mMem( static_cast<T *>( CPLMalloc( sizeof( T ) * size ) ) ) { }
252 CPLFree(
static_cast<void *
>( mMem ) );
258 CPLFree(
static_cast<void *
>( mMem ) );
264 reset(
static_cast<T *
>( CPLMalloc(
sizeof( T ) *size ) ) );
312 static bool activate(
const QString &preferredDeviceId = QString() );
319 static bool sAvailable;
320 static QLatin1String SETTINGS_GLOBAL_ENABLED_KEY;
321 static QLatin1String SETTINGS_DEFAULT_DEVICE_KEY;
The QgsOpenClUtils class is responsible for common OpenCL operations such as.
HardwareType
The Type enum represent OpenCL device type.
ExceptionBehavior
The ExceptionBehavior enum define how exceptions generated by OpenCL should be treated.
@ 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...
Tiny smart-pointer-like wrapper around CPLMalloc and CPLFree: this is needed because OpenCL C++ API m...
T & operator[](const int index)
void reset(unsigned long size)
CPLAllocator(unsigned long size)