summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-06-18 17:11:21 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-06-18 17:18:59 +1000
commit4186d0f149b64ec71190b5a04264d84cb6837409 (patch)
tree0e550ac9a5f7471cb98d39667b0b071b6d80ddf6
parentc8ff876789a6dc1721706036de837dd8bea2ca39 (diff)
Add versionFlags() to QCLDevice and QCLPlatform
-rw-r--r--src/opencl/qcldevice.cpp51
-rw-r--r--src/opencl/qcldevice.h7
-rw-r--r--src/opencl/qclplatform.cpp33
-rw-r--r--src/opencl/qclplatform.h16
4 files changed, 102 insertions, 5 deletions
diff --git a/src/opencl/qcldevice.cpp b/src/opencl/qcldevice.cpp
index 4ba2976..a1fc427 100644
--- a/src/opencl/qcldevice.cpp
+++ b/src/opencl/qcldevice.cpp
@@ -796,7 +796,10 @@ QString QCLDevice::profile() const
Returns the OpenCL version that is implemented by this OpenCL device,
usually something like \c{OpenCL 1.0}.
- \sa driverVersion()
+ The versionFlags() function parses the version into flag bits
+ that are easier to test than the string returned by version().
+
+ \sa versionFlags(), driverVersion()
*/
QString QCLDevice::version() const
{
@@ -886,6 +889,52 @@ bool QCLDevice::hasExtension(const char *name) const
return qt_cl_has_extension(buf.constData(), size, name);
}
+int qt_cl_version_flags(const QString &version)
+{
+ if (!version.startsWith(QLatin1String("OpenCL ")))
+ return 0;
+ int index = 7;
+ int major = 0;
+ int minor = 0;
+ while (index < version.length()) {
+ int ch = version[index].unicode();
+ if (ch < '0' || ch > '9')
+ break;
+ major = major * 10 + (ch - '0');
+ ++index;
+ }
+ if (index < version.length() && version[index] == QChar('.')) {
+ ++index;
+ while (index < version.length()) {
+ int ch = version[index].unicode();
+ if (ch < '0' || ch > '9')
+ break;
+ minor = minor * 10 + (ch - '0');
+ ++index;
+ }
+ }
+ int flags = 0;
+ if (major >= 1)
+ flags |= QCLPlatform::Version_1_0;
+ if ((major == 1 && minor >= 1) || major >= 2)
+ flags |= QCLPlatform::Version_1_1;
+ return flags;
+}
+
+/*!
+ Returns the OpenCL versions supported by this device.
+
+ \sa version(), QCLPlatform::versionFlags()
+*/
+QCLPlatform::VersionFlags QCLDevice::versionFlags() const
+{
+ if (!m_flags) {
+ m_flags = qt_cl_version_flags
+ (qt_cl_paramString(m_id, CL_DEVICE_VERSION));
+ }
+ return QCLPlatform::VersionFlags(m_flags);
+}
+
/*!
\fn cl_device_id QCLDevice::deviceId() const
diff --git a/src/opencl/qcldevice.h b/src/opencl/qcldevice.h
index 36c792c..638dcbc 100644
--- a/src/opencl/qcldevice.h
+++ b/src/opencl/qcldevice.h
@@ -54,8 +54,8 @@ QT_MODULE(CL)
class Q_CL_EXPORT QCLDevice
{
public:
- QCLDevice() : m_id(0) {}
- QCLDevice(cl_device_id id) : m_id(id) {}
+ QCLDevice() : m_id(0), m_flags(0) {}
+ QCLDevice(cl_device_id id) : m_id(id), m_flags(0) {}
enum DeviceType
{
@@ -156,6 +156,8 @@ public:
bool hasExtension(const char *name) const;
+ QCLPlatform::VersionFlags versionFlags() const;
+
cl_device_id deviceId() const { return m_id; }
static QList<QCLDevice> allDevices();
@@ -168,6 +170,7 @@ public:
private:
cl_device_id m_id;
+ mutable int m_flags;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QCLDevice::DeviceTypes)
diff --git a/src/opencl/qclplatform.cpp b/src/opencl/qclplatform.cpp
index 4664576..b5cfee7 100644
--- a/src/opencl/qclplatform.cpp
+++ b/src/opencl/qclplatform.cpp
@@ -70,6 +70,9 @@ QT_BEGIN_NAMESPACE
functions can be used to check for specific profile strings.
\o version() - version of OpenCL supported by the platform;
usually something like \c{OpenCL 1.0}.
+ \o versionFlags() - flag bits indicating which versions of
+ OpenCL are supported by this platform, in an easier to
+ use form than the string from version().
\o name() - name of the platform.
\o vendor() - name of the vendor that created the platform.
\o extensionSuffix() - the vendor extension suffix if the \c{cl_khr_icd}
@@ -165,6 +168,11 @@ QString QCLPlatform::profile() const
/*!
Returns the OpenCL version that is implemented by this OpenCL platform,
usually something like \c{OpenCL 1.0}.
+
+ The versionFlags() function parses the version into flag bits
+ that are easier to test than the string returned by version().
+
+ \sa versionFlags()
*/
QString QCLPlatform::version() const
{
@@ -235,6 +243,31 @@ bool QCLPlatform::hasExtension(const char *name) const
}
/*!
+ \enum QCLPlatform::VersionFlag
+ This enum defines flag bits corresponding to OpenCL versions.
+
+ \value Version_1_0 OpenCL 1.0 is supported.
+ \value Version_1_1 OpenCL 1.1 is supported.
+*/
+
+// Defined in qcldevice.cpp.
+int qt_cl_version_flags(const QString &version);
+
+/*!
+ Returns the OpenCL versions supported by this platform.
+
+ \sa version(), QCLDevice::versionFlags()
+*/
+QCLPlatform::VersionFlags QCLPlatform::versionFlags() const
+{
+ if (!m_flags) {
+ m_flags = qt_cl_version_flags
+ (qt_cl_platform_string(m_id, CL_PLATFORM_VERSION));
+ }
+ return QCLPlatform::VersionFlags(m_flags);
+}
+
+/*!
\fn cl_platform_id QCLPlatform::platformId() const
Returns the native OpenCL platform identifier for this object.
diff --git a/src/opencl/qclplatform.h b/src/opencl/qclplatform.h
index 7fda1a5..1de70c0 100644
--- a/src/opencl/qclplatform.h
+++ b/src/opencl/qclplatform.h
@@ -56,8 +56,8 @@ QT_MODULE(CL)
class Q_CL_EXPORT QCLPlatform
{
public:
- QCLPlatform() : m_id(0) {}
- QCLPlatform(cl_platform_id id) : m_id(id) {}
+ QCLPlatform() : m_id(0), m_flags(0) {}
+ QCLPlatform(cl_platform_id id) : m_id(id), m_flags(0) {}
bool isNull() const { return m_id == 0; }
@@ -73,6 +73,15 @@ public:
bool hasExtension(const char *name) const;
+ enum VersionFlag
+ {
+ Version_1_0 = 0x0001,
+ Version_1_1 = 0x0002
+ };
+ Q_DECLARE_FLAGS(VersionFlags, VersionFlag)
+
+ QCLPlatform::VersionFlags versionFlags() const;
+
cl_platform_id platformId() const { return m_id; }
static QList<QCLPlatform> platforms();
@@ -82,8 +91,11 @@ public:
private:
cl_platform_id m_id;
+ mutable int m_flags;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QCLPlatform::VersionFlags)
+
inline bool QCLPlatform::operator==(const QCLPlatform &other) const
{
return m_id == other.m_id;