summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/opencl/qclkernel.cpp29
-rw-r--r--src/opencl/qclkernel.h19
-rw-r--r--src/opencl/qclworksize.cpp27
-rw-r--r--src/opencl/qclworksize.h2
4 files changed, 76 insertions, 1 deletions
diff --git a/src/opencl/qclkernel.cpp b/src/opencl/qclkernel.cpp
index 58a0db8..e23d820 100644
--- a/src/opencl/qclkernel.cpp
+++ b/src/opencl/qclkernel.cpp
@@ -418,7 +418,7 @@ QCLWorkSize QCLKernel::globalWorkSize() const
/*!
Sets the global work size for this instance of the kernel to \a size.
- \sa globalWorkSize(), setLocalWorkSize()
+ \sa globalWorkSize(), setLocalWorkSize(), setRoundedGlobalWorkSize()
*/
void QCLKernel::setGlobalWorkSize(const QCLWorkSize &size)
{
@@ -443,6 +443,33 @@ void QCLKernel::setGlobalWorkSize(const QCLWorkSize &size)
*/
/*!
+ \fn void QCLKernel::setRoundedGlobalWorkSize(const QCLWorkSize &size)
+
+ Sets the global work size for this instance of the kernel to \a size,
+ after rounding it up to the next multiple of localWorkSize().
+
+ \sa globalWorkSize(), QCLWorkSize::roundTo()
+*/
+
+/*!
+ \fn void QCLKernel::setRoundedGlobalWorkSize(size_t width, size_t height)
+ \overload
+
+ Sets the global work size for this instance of the kernel to
+ \a width x \a height, after rounding it up to the next multiple
+ of localWorkSize().
+*/
+
+/*!
+ \fn void QCLKernel::setRoundedGlobalWorkSize(size_t width, size_t height, size_t depth)
+ \overload
+
+ Sets the global work size for this instance of the kernel to
+ \a width x \a height x \a depth, after rounding it up to the
+ next multiple of localWorkSize().
+*/
+
+/*!
\fn void QCLKernel::setLocalWorkSize(size_t width, size_t height)
\overload
diff --git a/src/opencl/qclkernel.h b/src/opencl/qclkernel.h
index b03676b..e886aa6 100644
--- a/src/opencl/qclkernel.h
+++ b/src/opencl/qclkernel.h
@@ -101,6 +101,10 @@ public:
void setGlobalWorkSize(size_t width, size_t height);
void setGlobalWorkSize(size_t width, size_t height, size_t depth);
+ void setRoundedGlobalWorkSize(const QCLWorkSize &size);
+ void setRoundedGlobalWorkSize(size_t width, size_t height);
+ void setRoundedGlobalWorkSize(size_t width, size_t height, size_t depth);
+
QCLWorkSize localWorkSize() const;
void setLocalWorkSize(const QCLWorkSize &size);
void setLocalWorkSize(size_t width, size_t height);
@@ -298,6 +302,21 @@ inline void QCLKernel::setGlobalWorkSize(size_t width, size_t height, size_t dep
setGlobalWorkSize(QCLWorkSize(width, height, depth));
}
+inline void QCLKernel::setRoundedGlobalWorkSize(const QCLWorkSize &size)
+{
+ setGlobalWorkSize(size.roundTo(localWorkSize()));
+}
+
+inline void QCLKernel::setRoundedGlobalWorkSize(size_t width, size_t height)
+{
+ setRoundedGlobalWorkSize(QCLWorkSize(width, height));
+}
+
+inline void QCLKernel::setRoundedGlobalWorkSize(size_t width, size_t height, size_t depth)
+{
+ setRoundedGlobalWorkSize(QCLWorkSize(width, height, depth));
+}
+
inline void QCLKernel::setLocalWorkSize(size_t width, size_t height)
{
setLocalWorkSize(QCLWorkSize(width, height));
diff --git a/src/opencl/qclworksize.cpp b/src/opencl/qclworksize.cpp
index 840dc39..eb47213 100644
--- a/src/opencl/qclworksize.cpp
+++ b/src/opencl/qclworksize.cpp
@@ -222,6 +222,33 @@ QCLWorkSize QCLWorkSize::toLocalWorkSize(const QCLDevice &device) const
device.maximumWorkItemsPerGroup());
}
+static inline size_t qt_cl_round_to(size_t value, size_t multiple)
+{
+ if (multiple <= 1)
+ return value;
+ size_t remainder = value % multiple;
+ if (!remainder)
+ return value;
+ else
+ return value + multiple - remainder;
+}
+
+/*!
+ Returns the result of rounding this work size up to a multiple of \a size.
+*/
+QCLWorkSize QCLWorkSize::roundTo(const QCLWorkSize &size) const
+{
+ if (m_dim == 1)
+ return QCLWorkSize(qt_cl_round_to(m_sizes[0], size.m_sizes[0]));
+ else if (m_dim == 2)
+ return QCLWorkSize(qt_cl_round_to(m_sizes[0], size.m_sizes[0]),
+ qt_cl_round_to(m_sizes[1], size.m_sizes[1]));
+ else
+ return QCLWorkSize(qt_cl_round_to(m_sizes[0], size.m_sizes[0]),
+ qt_cl_round_to(m_sizes[1], size.m_sizes[1]),
+ qt_cl_round_to(m_sizes[2], size.m_sizes[2]));
+}
+
/*!
Returns the string form of this work size, with components
separated by 'x'.
diff --git a/src/opencl/qclworksize.h b/src/opencl/qclworksize.h
index 290197c..d13bfd5 100644
--- a/src/opencl/qclworksize.h
+++ b/src/opencl/qclworksize.h
@@ -82,6 +82,8 @@ public:
(const QCLWorkSize &maxWorkItemSize, size_t maxItemsPerGroup) const;
QCLWorkSize toLocalWorkSize(const QCLDevice &device) const;
+ QCLWorkSize roundTo(const QCLWorkSize &size) const;
+
QString toString() const;
static QCLWorkSize fromString(const QString &str);