QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
qgsopenclutils.h
Go to the documentation of this file.
1
/***************************************************************************
2
qgsopenclutils.h - QgsOpenClUtils
3
4
---------------------
5
begin : 11.4.2018
6
copyright : (C) 2018 by Alessandro Pasotti
7
email : elpaso at itopen dot it
8
***************************************************************************
9
* *
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
14
* *
15
***************************************************************************/
16
#ifndef QGSOPENCLUTILS_H
17
#define QGSOPENCLUTILS_H
18
19
20
#define CL_HPP_ENABLE_EXCEPTIONS
21
22
#include <QString>
23
#include <QtGlobal>
24
25
#define SIP_NO_FILE
26
27
using namespace
Qt::StringLiterals;
28
29
#ifdef Q_OS_MAC
30
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
31
#define CL_HPP_TARGET_OPENCL_VERSION 120
32
#define CL_TARGET_OPENCL_VERSION 120
33
#else
34
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
35
#define CL_HPP_TARGET_OPENCL_VERSION 200
36
#define CL_TARGET_OPENCL_VERSION 200
37
#endif
38
39
#include "qgsconfig.h"
40
41
#ifdef OPENCL_USE_NEW_HEADER
42
#include <CL/opencl.hpp>
43
#else
44
#include <CL/cl2.hpp>
45
#endif
46
47
#include "qgis_core.h"
48
#include "
qgis.h
"
49
50
#include "cpl_conv.h"
51
52
class
QgsSettingsEntryBool
;
53
class
QgsSettingsEntryString
;
54
89
class
CORE_EXPORT QgsOpenClUtils
90
{
91
Q_GADGET
92
93
public
:
94
static
const
QgsSettingsEntryBool
*
settingsOpenClEnabled
;
95
static
const
QgsSettingsEntryString
*
settingsOpenClDefaultDevice
;
99
enum
ExceptionBehavior
100
{
101
Catch
,
102
Throw
103
};
104
108
enum
HardwareType
109
{
110
CPU
,
111
GPU
,
112
Other
113
};
114
115
Q_ENUM( HardwareType )
116
117
122
enum
Info
123
{
124
Name
= CL_DEVICE_NAME,
125
Vendor
= CL_DEVICE_VENDOR,
126
Version
= CL_DEVICE_VERSION,
127
Profile
= CL_DEVICE_PROFILE,
128
ImageSupport
= CL_DEVICE_IMAGE_SUPPORT,
129
Image2dMaxWidth
= CL_DEVICE_IMAGE2D_MAX_WIDTH,
130
Image2dMaxHeight
= CL_DEVICE_IMAGE2D_MAX_HEIGHT,
131
MaxMemAllocSize
= CL_DEVICE_MAX_MEM_ALLOC_SIZE,
132
Type
= CL_DEVICE_TYPE
// CPU/GPU etc.
133
};
134
144
static
bool
available();
145
147
static
bool
enabled();
148
150
static
const
std::vector<cl::Device> devices();
151
159
static
cl::Device activeDevice();
160
166
static
QString activePlatformVersion();
167
169
static
void
storePreferredDevice(
const
QString deviceId );
170
172
static
QString preferredDevice();
173
175
static
QString deviceId(
const
cl::Device device );
176
180
static
QString deviceDescription(
const
cl::Device device );
181
185
static
QString deviceDescription(
const
QString deviceId );
186
188
static
void
setEnabled(
bool
enabled );
189
191
static
QString buildLog( cl::BuildError &error );
192
194
static
QString sourceFromPath(
const
QString &path );
195
197
static
QString sourceFromBaseName(
const
QString &baseName );
198
200
static
QLatin1String
LOGMESSAGE_TAG
;
201
203
static
QString
errorText
(
const
int
errorCode );
204
211
static
cl::CommandQueue
commandQueue
();
212
219
Q_DECL_DEPRECATED
static
cl::Program
buildProgram
(
const
cl::Context &
context
,
const
QString &source,
ExceptionBehavior
exceptionBehavior =
Catch
);
220
225
static
cl::Program
buildProgram
(
const
QString &source,
ExceptionBehavior
exceptionBehavior =
Catch
);
226
227
235
static
cl::Context
context
();
236
238
static
QString
sourcePath
();
239
241
static
void
setSourcePath
(
const
QString &value );
242
244
static
QString
activeDeviceInfo
(
const
Info
infoType =
Info::Name
);
245
247
static
QString
deviceInfo
(
const
Info
infoType, cl::Device device );
248
253
template
<
typename
T>
struct
CPLAllocator
254
{
255
public
:
256
explicit
CPLAllocator
(
unsigned
long
size )
257
: mMem( static_cast<T *>( CPLMalloc( sizeof( T ) * size ) ) )
258
{}
259
260
~CPLAllocator
() { CPLFree(
static_cast<
void
*
>
( mMem ) ); }
261
262
void
reset
( T *newData )
263
{
264
if
( mMem )
265
CPLFree(
static_cast<
void
*
>
( mMem ) );
266
mMem = newData;
267
}
268
269
void
reset
(
unsigned
long
size ) {
reset
(
static_cast<
T *
>
( CPLMalloc(
sizeof
( T ) * size ) ) ); }
270
271
T &
operator*
()
272
{
273
// cppcheck-suppress returnTempReference
274
return
&mMem[0];
275
}
276
277
T *
release
()
278
{
279
T *tmpMem = mMem;
280
mMem =
nullptr
;
281
return
tmpMem;
282
}
283
284
T &
operator[]
(
const
int
index ) {
return
mMem[index]; }
285
286
T *
get
() {
return
mMem; }
287
288
private
:
289
T *mMem =
nullptr
;
290
};
291
292
293
private
:
294
QgsOpenClUtils
();
295
309
static
bool
activate(
const
QString &preferredDeviceId = QString() );
310
311
static
bool
activateInternal(
const
QString &preferredDeviceId );
312
316
static
void
init();
317
318
static
bool
sAvailable;
319
};
320
321
322
#endif
// QGSOPENCLUTILS_H
QgsOpenClUtils
Utilities responsible for common OpenCL operations.
Definition
qgsopenclutils.h:90
QgsOpenClUtils::buildProgram
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...
Definition
qgsopenclutils.cpp:790
QgsOpenClUtils::setSourcePath
static void setSourcePath(const QString &value)
Set the base path to OpenCL program directory.
Definition
qgsopenclutils.cpp:238
QgsOpenClUtils::sourcePath
static QString sourcePath()
Returns the base path to OpenCL program directory.
Definition
qgsopenclutils.cpp:233
QgsOpenClUtils::context
static cl::Context context()
Context factory.
Definition
qgsopenclutils.cpp:777
QgsOpenClUtils::HardwareType
HardwareType
The Type enum represent OpenCL device type.
Definition
qgsopenclutils.h:109
QgsOpenClUtils::GPU
@ GPU
Definition
qgsopenclutils.h:111
QgsOpenClUtils::Other
@ Other
Definition
qgsopenclutils.h:112
QgsOpenClUtils::CPU
@ CPU
Definition
qgsopenclutils.h:110
QgsOpenClUtils::activeDeviceInfo
static QString activeDeviceInfo(const Info infoType=Info::Name)
Returns infoType information about the active (default) device.
Definition
qgsopenclutils.cpp:243
QgsOpenClUtils::deviceInfo
static QString deviceInfo(const Info infoType, cl::Device device)
Returns infoType information about the device.
Definition
qgsopenclutils.cpp:248
QgsOpenClUtils::errorText
static QString errorText(const int errorCode)
Returns a string representation from an OpenCL errorCode.
Definition
qgsopenclutils.cpp:569
QgsOpenClUtils::commandQueue
static cl::CommandQueue commandQueue()
Create an OpenCL command queue from the default context.
Definition
qgsopenclutils.cpp:756
QgsOpenClUtils::settingsOpenClEnabled
static const QgsSettingsEntryBool * settingsOpenClEnabled
Definition
qgsopenclutils.h:94
QgsOpenClUtils::settingsOpenClDefaultDevice
static const QgsSettingsEntryString * settingsOpenClDefaultDevice
Definition
qgsopenclutils.h:95
QgsOpenClUtils::ExceptionBehavior
ExceptionBehavior
The ExceptionBehavior enum define how exceptions generated by OpenCL should be treated.
Definition
qgsopenclutils.h:100
QgsOpenClUtils::Throw
@ Throw
Write errors in the message log and re-throw exceptions.
Definition
qgsopenclutils.h:102
QgsOpenClUtils::Catch
@ Catch
Write errors in the message log and silently fail.
Definition
qgsopenclutils.h:101
QgsOpenClUtils::Info
Info
The Info enum maps to OpenCL info constants.
Definition
qgsopenclutils.h:123
QgsOpenClUtils::Name
@ Name
Definition
qgsopenclutils.h:124
QgsOpenClUtils::Type
@ Type
Definition
qgsopenclutils.h:132
QgsOpenClUtils::MaxMemAllocSize
@ MaxMemAllocSize
Definition
qgsopenclutils.h:131
QgsOpenClUtils::Version
@ Version
Definition
qgsopenclutils.h:126
QgsOpenClUtils::Image2dMaxWidth
@ Image2dMaxWidth
Definition
qgsopenclutils.h:129
QgsOpenClUtils::Profile
@ Profile
Definition
qgsopenclutils.h:127
QgsOpenClUtils::ImageSupport
@ ImageSupport
Definition
qgsopenclutils.h:128
QgsOpenClUtils::Vendor
@ Vendor
Definition
qgsopenclutils.h:125
QgsOpenClUtils::Image2dMaxHeight
@ Image2dMaxHeight
Definition
qgsopenclutils.h:130
QgsOpenClUtils::LOGMESSAGE_TAG
static QLatin1String LOGMESSAGE_TAG
OpenCL string for message logs.
Definition
qgsopenclutils.h:200
QgsSettingsEntryBool
A boolean settings entry.
Definition
qgssettingsentryimpl.h:298
QgsSettingsEntryString
A string settings entry.
Definition
qgssettingsentryimpl.h:123
qgis.h
QgsOpenClUtils::CPLAllocator::~CPLAllocator
~CPLAllocator()
Definition
qgsopenclutils.h:260
QgsOpenClUtils::CPLAllocator::release
T * release()
Definition
qgsopenclutils.h:277
QgsOpenClUtils::CPLAllocator::operator[]
T & operator[](const int index)
Definition
qgsopenclutils.h:284
QgsOpenClUtils::CPLAllocator::reset
void reset(unsigned long size)
Definition
qgsopenclutils.h:269
QgsOpenClUtils::CPLAllocator::get
T * get()
Definition
qgsopenclutils.h:286
QgsOpenClUtils::CPLAllocator::reset
void reset(T *newData)
Definition
qgsopenclutils.h:262
QgsOpenClUtils::CPLAllocator::CPLAllocator
CPLAllocator(unsigned long size)
Definition
qgsopenclutils.h:256
QgsOpenClUtils::CPLAllocator::operator*
T & operator*()
Definition
qgsopenclutils.h:271
Generated on
for QGIS API Documentation by
1.17.0