summaryrefslogtreecommitdiff
path: root/ufo/ufo-buffer.c
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2015-01-27 11:28:24 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2015-01-27 11:28:24 +0100
commita32b4fef87390ba0115e8748f5c08e585ba8fdd3 (patch)
treeb42148e2181618cf619fd3a993d81b3f5b6b5cfa /ufo/ufo-buffer.c
parent76ab642caf3286860d1f689fb06628fbc91c8718 (diff)
buffer: add functions to retrieve min/max
Diffstat (limited to 'ufo/ufo-buffer.c')
-rw-r--r--ufo/ufo-buffer.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/ufo/ufo-buffer.c b/ufo/ufo-buffer.c
index b751f41..b9ab8d6 100644
--- a/ufo/ufo-buffer.c
+++ b/ufo/ufo-buffer.c
@@ -332,6 +332,17 @@ ufo_buffer_get_size (UfoBuffer *buffer)
return buffer->priv->size;
}
+static gsize
+get_num_elements (UfoBufferPrivate *priv)
+{
+ gsize n = 1;
+
+ for (guint i = 0; i < priv->requisition.n_dims; i++)
+ n *= priv->requisition.dims[i];
+
+ return n;
+}
+
static void
set_region_from_requisition (size_t region[3],
UfoRequisition *requisition)
@@ -1201,6 +1212,78 @@ ufo_buffer_get_metadata_keys (UfoBuffer *buffer)
}
/**
+ * ufo_buffer_max:
+ * @buffer: A #UfoBuffer
+ * @cmd_queue: An OpenCL command queue or %NULL
+ *
+ * Return the maximum value of @buffer.
+ *
+ * Returns: The maximum found.
+ */
+gfloat
+ufo_buffer_max (UfoBuffer *buffer,
+ gpointer cmd_queue)
+{
+ UfoBufferPrivate *priv;
+ gsize n;
+ gfloat max = -G_MAXFLOAT;
+
+ g_return_val_if_fail (UFO_IS_BUFFER (buffer), 0.0f);
+
+ priv = buffer->priv;
+
+ if (priv->location != UFO_LOCATION_HOST) {
+ g_warning ("max() not supported for non-host buffers");
+ return 0.0f;
+ }
+
+ n = get_num_elements (priv);
+
+ for (gsize i = 0; i < n; i++) {
+ if (priv->host_array[i] > max)
+ max = priv->host_array[i];
+ }
+
+ return max;
+}
+
+/**
+ * ufo_buffer_min:
+ * @buffer: A #UfoBuffer
+ * @cmd_queue: An OpenCL command queue or %NULL
+ *
+ * Return the minimum value of @buffer.
+ *
+ * Returns: The minimum found.
+ */
+gfloat
+ufo_buffer_min (UfoBuffer *buffer,
+ gpointer cmd_queue)
+{
+ UfoBufferPrivate *priv;
+ gsize n;
+ gfloat min = G_MAXFLOAT;
+
+ g_return_val_if_fail (UFO_IS_BUFFER (buffer), 0.0f);
+
+ priv = buffer->priv;
+
+ if (priv->location != UFO_LOCATION_HOST) {
+ g_warning ("min() not supported for non-host buffers");
+ return 0.0f;
+ }
+
+ n = get_num_elements (priv);
+
+ for (gsize i = 0; i < n; i++) {
+ if (priv->host_array[i] < min)
+ min = priv->host_array[i];
+ }
+
+ return min;
+}
+
+/**
* ufo_buffer_param_spec:
* @name: canonical name of the property specified
* @nick: nick name for the property specified