[gegl/gsoc2011-opencl: 10/10] Unit testing for OpenCL-related functions
- From: Victor Matheus de Araujo Oliveira <vmaolive src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/gsoc2011-opencl: 10/10] Unit testing for OpenCL-related functions
- Date: Sat, 2 Jul 2011 04:51:24 +0000 (UTC)
commit e4e2dc2dcdd27679752f2a0fabcffc95eb8c8fa9
Author: Victor Oliveira <victormatheus gmail com>
Date: Tue Jun 21 17:23:34 2011 -0300
Unit testing for OpenCL-related functions
This patch adds a opencl folder in gegl/tests where code
related to the OpenCL support is going to be tested.
Tests added so far:
- GeglClTexture
* clear
* copy
* dup
* set
* get
- GeglTile
* Locking mechanism beetween cpu memory
and OpenCL memory
In order to run the tests, type "make check" in the new folder.
configure.ac | 1 +
gegl/buffer/gegl-buffer-private.h | 2 +-
tests/opencl/Makefile.am | 38 +++++++
tests/opencl/test-gegl-cl-texture-clear.c | 103 ++++++++++++++++++
tests/opencl/test-gegl-cl-texture-copy.c | 109 +++++++++++++++++++
tests/opencl/test-gegl-cl-texture-dup.c | 104 ++++++++++++++++++
tests/opencl/test-gegl-cl-texture-set.c | 103 ++++++++++++++++++
...est-gegl-tile-lock-mode-cl-write-then-cl-read.c | 114 ++++++++++++++++++++
.../test-gegl-tile-lock-mode-cl-write-then-read.c | 113 +++++++++++++++++++
.../test-gegl-tile-lock-mode-write-then-cl-read.c | 113 +++++++++++++++++++
.../test-gegl-tile-lock-mode-write-then-read.c | 111 +++++++++++++++++++
11 files changed, 910 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 127e7e2..e63aeaa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1108,6 +1108,7 @@ tests/buffer/tests/Makefile
tests/compositions/Makefile
tests/compositions/data/Makefile
tests/simple/Makefile
+tests/opencl/Makefile
gegl.pc
gegl-uninstalled.pc
])
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index dea9bfd..12b8703 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -208,7 +208,7 @@ struct _GeglTile
#ifndef __GEGL_TILE_C
#define gegl_tile_get_data(tile) ((guchar*)((tile)->data))
-#define gegl_tile_get_cl_data(tile) ((tile)->cl_data))
+#define gegl_tile_get_cl_data(tile) ((tile)->cl_data)
#endif // __GEGL_TILE_C
diff --git a/tests/opencl/Makefile.am b/tests/opencl/Makefile.am
new file mode 100644
index 0000000..48432a6
--- /dev/null
+++ b/tests/opencl/Makefile.am
@@ -0,0 +1,38 @@
+# Make the tests run against the build and not the installation
+TESTS_ENVIRONMENT = \
+ GEGL_PATH=$(top_builddir)/operations/common:$(top_builddir)/operations/core:$(top_builddir)/operations/external:$(top_builddir)/operations/affine:$(top_builddir)/operations/generated \
+ ABS_TOP_BUILDDIR=$(top_builddir) \
+ ABS_TOP_SRCDIR=$(top_srcdir)
+
+# The tests
+noinst_PROGRAMS = \
+ test-gegl-cl-texture-dup \
+ test-gegl-cl-texture-copy \
+ test-gegl-cl-texture-set \
+ test-gegl-cl-texture-clear \
+ test-gegl-tile-lock-mode-write-then-read \
+ test-gegl-tile-lock-mode-cl-write-then-read \
+ test-gegl-tile-lock-mode-write-then-cl-read \
+ test-gegl-tile-lock-mode-cl-write-then-cl-read
+
+TESTS = $(noinst_PROGRAMS)
+
+# Common CPPFLAGS
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_builddir)/gegl \
+ -I$(top_srcdir)/gegl \
+ -I$(top_builddir)/gegl/buffer \
+ -I$(top_srcdir)/gegl/buffer \
+ -I$(top_builddir)/gegl/property-types \
+ -I$(top_srcdir)/gegl/property-types \
+ -I$(top_builddir)/gegl/operation \
+ -I$(top_srcdir)/gegl/operation \
+ -I$(top_builddir)/gegl/opencl \
+ -I$(top_srcdir)/gegl/opencl
+
+AM_CFLAGS = $(DEP_CFLAGS) $(BABL_CFLAGS)
+
+# Common libs
+LIBS = $(top_builddir)/gegl/libgegl-$(GEGL_API_VERSION).la \
+ $(DEP_LIBS) $(BABL_LIBS)
diff --git a/tests/opencl/test-gegl-cl-texture-clear.c b/tests/opencl/test-gegl-cl-texture-clear.c
new file mode 100644
index 0000000..741c7a8
--- /dev/null
+++ b/tests/opencl/test-gegl-cl-texture-clear.c
@@ -0,0 +1,103 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor M. de Araujo Oliveira <victormatheus gmail com>
+ */
+
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglClTexture *texture;
+ gfloat *components;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ texture = gegl_cl_texture_new (TEXTURE_SIZE_BYTES * 4);
+
+ components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+ gfloat color[4];
+
+ color[0] = g_random_double ();
+ color[1] = g_random_double ();
+ color[2] = g_random_double ();
+ color[3] = g_random_double ();
+
+ for (cnt = 0; cnt < TEXTURE_SIZE; cnt++)
+ {
+ gint index = cnt * 4;
+
+ components[index ] = color[0];
+ components[index + 1] = color[1];
+ components[index + 2] = color[2];
+ components[index + 3] = color[3];
+ }
+
+ /* set texture to some solid color to make sure that we aren't clearing
+ * an empty texture (note: this assumes that gegl_cl_texture_set()
+ * works as expected)
+ */
+ gegl_cl_texture_set (texture, components, TEXTURE_SIZE_BYTES * 4);
+
+ /* clear whole texture */
+ gegl_cl_texture_clear (texture, TEXTURE_SIZE_BYTES * 4);
+ gegl_cl_texture_get (texture, components, TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (components[cnt] > 1E-5f)
+ {
+ g_printerr ("The gegl_cl_texture_clear() test failed. "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ goto abort;
+ }
+ }
+
+abort:
+ g_free (components);
+ gegl_cl_texture_free (texture);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-cl-texture-copy.c b/tests/opencl/test-gegl-cl-texture-copy.c
new file mode 100644
index 0000000..3b2d70f
--- /dev/null
+++ b/tests/opencl/test-gegl-cl-texture-copy.c
@@ -0,0 +1,109 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor M. de Araujo Oliveira <victormatheus gmail com>
+ */
+
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+#define RANDOM_PIXEL_COUNT 1000
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglClTexture *texture1;
+ GeglClTexture *texture2;
+
+ gfloat *components1;
+ gfloat *components2;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ texture1 = gegl_cl_texture_new (TEXTURE_SIZE_BYTES * 4);
+ texture2 = gegl_cl_texture_new (TEXTURE_SIZE_BYTES * 4);
+
+ components1 = g_new (gfloat, TEXTURE_SIZE * 4);
+ components2 = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+
+ for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; cnt++)
+ {
+ gint i = g_random_int_range (0, TEXTURE_SIZE);
+
+ gfloat *pixel = &components1[i * 4];
+
+ pixel[0] = g_random_double ();
+ pixel[1] = g_random_double ();
+ pixel[2] = g_random_double ();
+ pixel[3] = g_random_double ();
+ }
+
+ /* set the texture to a random image (note: this test assumes that
+ * gegl_cl_texture_set() works as expected)
+ */
+ gegl_cl_texture_set (texture1, components1, TEXTURE_SIZE_BYTES * 4);
+
+ /* copy first texture to second texture */
+ gegl_cl_texture_copy (texture1, texture2, TEXTURE_SIZE_BYTES * 4);
+ gegl_cl_texture_get (texture2, components2, TEXTURE_SIZE_BYTES * 4);
+
+ /* compare the two textures */
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (components1[cnt], components2[cnt]))
+ {
+ g_printerr ("The gegl_cl_texture_copy() test failed. "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ goto abort;
+ }
+ }
+
+abort:
+ g_free (components2);
+ g_free (components1);
+
+ gegl_cl_texture_free (texture2);
+ gegl_cl_texture_free (texture1);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-cl-texture-dup.c b/tests/opencl/test-gegl-cl-texture-dup.c
new file mode 100644
index 0000000..9c40f0e
--- /dev/null
+++ b/tests/opencl/test-gegl-cl-texture-dup.c
@@ -0,0 +1,104 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor M. de Araujo Oliveira <victormatheus gmail com>
+ */
+
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+#define RANDOM_PIXEL_COUNT 1000
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglClTexture *texture1;
+ GeglClTexture *texture2;
+
+ gfloat *components1;
+ gfloat *components2;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ texture1 = gegl_cl_texture_new (TEXTURE_SIZE_BYTES * 4);
+
+ components1 = g_new (gfloat, TEXTURE_SIZE * 4);
+ components2 = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+
+ for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; cnt++)
+ {
+ gint i = g_random_int_range (0, TEXTURE_SIZE);
+
+ gfloat *pixel = &components1[i * 4];
+
+ pixel[0] = g_random_double ();
+ pixel[1] = g_random_double ();
+ pixel[2] = g_random_double ();
+ pixel[3] = g_random_double ();
+ }
+
+ /* set texture to a random image */
+ gegl_cl_texture_set (texture1, components1, TEXTURE_SIZE_BYTES * 4);
+
+ /* duplicate texture */
+ texture2 = gegl_cl_texture_dup (texture1, TEXTURE_SIZE_BYTES * 4);
+ gegl_cl_texture_get (texture2, components2, TEXTURE_SIZE_BYTES * 4);
+
+ /* compare the two images */
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (components1[cnt], components2[cnt]))
+ {
+ g_printerr ("The gegl_cl_texture_dup() test failed. Aborting.\n");
+ retval = FAILURE;
+ goto abort;
+ }
+ }
+
+abort:
+ g_free (components2);
+ g_free (components1);
+
+ gegl_cl_texture_free (texture2);
+ gegl_cl_texture_free (texture1);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-cl-texture-set.c b/tests/opencl/test-gegl-cl-texture-set.c
new file mode 100644
index 0000000..2f9b73c
--- /dev/null
+++ b/tests/opencl/test-gegl-cl-texture-set.c
@@ -0,0 +1,103 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor M. de Araujo Oliveira <victormatheus gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+#define RANDOM_PIXEL_COUNT 1000
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglClTexture *texture;
+
+ gfloat *components1;
+ gfloat *components2;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ texture = gegl_cl_texture_new (TEXTURE_SIZE_BYTES * 4);
+
+ components1 = g_new (gfloat, TEXTURE_SIZE * 4);
+ components2 = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+
+ for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; cnt++)
+ {
+ gint i = g_random_int_range (0, TEXTURE_SIZE);
+
+ gfloat *pixel = &components1[i * 4];
+
+ pixel[0] = g_random_double ();
+ pixel[1] = g_random_double ();
+ pixel[2] = g_random_double ();
+ pixel[3] = g_random_double ();
+ }
+
+ /* set the texture to a random image */
+ gegl_cl_texture_set (texture, components1, TEXTURE_SIZE_BYTES * 4);
+
+ /* get the texture and put it in a different buffer (actually, this test
+ * should also be considered as a test for gegl_cl_texture_get())
+ */
+ gegl_cl_texture_get (texture, components2, TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (components1[cnt], components2[cnt]))
+ {
+ g_printerr ("The gegl_cl_texture_set() test failed. Aborting.\n");
+ retval = FAILURE;
+ goto abort;
+ }
+ }
+
+abort:
+ g_free (components2);
+ g_free (components1);
+
+ gegl_cl_texture_free (texture);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-tile-lock-mode-cl-write-then-cl-read.c b/tests/opencl/test-gegl-tile-lock-mode-cl-write-then-cl-read.c
new file mode 100644
index 0000000..f2cc7d0
--- /dev/null
+++ b/tests/opencl/test-gegl-tile-lock-mode-cl-write-then-cl-read.c
@@ -0,0 +1,114 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor Matheus de Araujo Oliveira <victormatheus gmail com>
+ Based on work from Jerson Michael Perpetua <jersonperpetua gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#include "../../gegl/buffer/gegl-tile.h"
+#include "../../gegl/buffer/gegl-buffer-private.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+#define RANDOM_PIXEL_COUNT 1000
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglTile *tile;
+ gfloat *components;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ tile = gegl_tile_new (TEXTURE_SIZE_BYTES * 4);
+
+ components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+ gfloat *tile_components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ memset (gegl_tile_get_data(tile), 0, TEXTURE_SIZE_BYTES * 4);
+ gegl_cl_texture_clear (gegl_tile_get_cl_data(tile), TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; cnt++)
+ {
+ gint i = g_random_int_range (0, TEXTURE_SIZE);
+
+ gfloat *pixel = &components[i * 4];
+
+ pixel[0] = g_random_double ();
+ pixel[1] = g_random_double ();
+ pixel[2] = g_random_double ();
+ pixel[3] = g_random_double ();
+ }
+
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_CL_WRITE);
+
+ /* set tile to a random image */
+ gegl_cl_texture_set (gegl_tile_get_cl_data(tile), components, TEXTURE_SIZE_BYTES * 4);
+
+ gegl_tile_unlock (tile);
+
+ /* check contents of tile for consistency with previous write */
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_CL_READ);
+
+ gegl_cl_texture_get (gegl_tile_get_cl_data(tile), tile_components, TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
+ {
+ g_printerr ("Tile OpenCL texture inconsistent with original OpenCL texture "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ break;
+ }
+
+ gegl_tile_unlock (tile);
+ g_free (tile_components);
+ }
+
+ g_free (components);
+ gegl_tile_unref (tile);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-tile-lock-mode-cl-write-then-read.c b/tests/opencl/test-gegl-tile-lock-mode-cl-write-then-read.c
new file mode 100644
index 0000000..410be83
--- /dev/null
+++ b/tests/opencl/test-gegl-tile-lock-mode-cl-write-then-read.c
@@ -0,0 +1,113 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor Matheus de Araujo Oliveira <victormatheus gmail com>
+ Based on work from Jerson Michael Perpetua <jersonperpetua gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#include "../../gegl/buffer/gegl-tile.h"
+#include "../../gegl/buffer/gegl-buffer-private.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+#define RANDOM_PIXEL_COUNT 1000
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglTile *tile;
+ gfloat *components;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ tile = gegl_tile_new (TEXTURE_SIZE_BYTES * 4);
+
+ components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+ gfloat *tile_components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ memset (gegl_tile_get_data(tile), 0, TEXTURE_SIZE_BYTES * 4);
+ gegl_cl_texture_clear (gegl_tile_get_cl_data(tile), TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; cnt++)
+ {
+ gint i = g_random_int_range (0, TEXTURE_SIZE);
+
+ gfloat *pixel = &components[i * 4];
+
+ pixel[0] = g_random_double ();
+ pixel[1] = g_random_double ();
+ pixel[2] = g_random_double ();
+ pixel[3] = g_random_double ();
+ }
+
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_CL_WRITE);
+
+ /* set tile to a random image */
+ gegl_cl_texture_set (gegl_tile_get_cl_data(tile), components, TEXTURE_SIZE_BYTES * 4);
+
+ gegl_tile_unlock (tile);
+
+ /* check contents of tile for consistency with previous write */
+ /* when locking for reading in cpu, memory copying from the gpu should be done */
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_READ);
+ memcpy (tile_components, gegl_tile_get_data(tile), TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
+ {
+ g_printerr ("Tile data inconsistent with original OpenCL texture "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ break;
+ }
+
+ gegl_tile_unlock (tile);
+ }
+
+ g_free (components);
+ gegl_tile_unref (tile);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-tile-lock-mode-write-then-cl-read.c b/tests/opencl/test-gegl-tile-lock-mode-write-then-cl-read.c
new file mode 100644
index 0000000..7722883
--- /dev/null
+++ b/tests/opencl/test-gegl-tile-lock-mode-write-then-cl-read.c
@@ -0,0 +1,113 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor Matheus de Araujo Oliveira <victormatheus gmail com>
+ Based on work from Jerson Michael Perpetua <jersonperpetua gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#include "../../gegl/buffer/gegl-tile.h"
+#include "../../gegl/buffer/gegl-buffer-private.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+#define RANDOM_PIXEL_COUNT 1000
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglTile *tile;
+ gfloat *components;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ tile = gegl_tile_new (TEXTURE_SIZE_BYTES * 4);
+
+ components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+ gfloat *tile_components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ memset (gegl_tile_get_data(tile), 0, TEXTURE_SIZE_BYTES * 4);
+ gegl_cl_texture_clear (gegl_tile_get_cl_data(tile), TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; cnt++)
+ {
+ gint i = g_random_int_range (0, TEXTURE_SIZE);
+
+ gfloat *pixel = &components[i * 4];
+
+ pixel[0] = g_random_double ();
+ pixel[1] = g_random_double ();
+ pixel[2] = g_random_double ();
+ pixel[3] = g_random_double ();
+ }
+
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
+
+ /* set tile to a random image */
+ memcpy (gegl_tile_get_data(tile), components, TEXTURE_SIZE_BYTES * 4);
+
+ gegl_tile_unlock (tile);
+
+ /* check contents of tile for consistency with previous write */
+ /* when locking for reading in gpu, memory copying from the cpu should be done */
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_CL_READ);
+ gegl_cl_texture_get (gegl_tile_get_cl_data(tile), tile_components, TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
+ {
+ g_printerr ("Tile OpenCL texture inconsistent with original original data "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ break;
+ }
+
+ gegl_tile_unlock (tile);
+ }
+
+ g_free (components);
+ gegl_tile_unref (tile);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
diff --git a/tests/opencl/test-gegl-tile-lock-mode-write-then-read.c b/tests/opencl/test-gegl-tile-lock-mode-write-then-read.c
new file mode 100644
index 0000000..85a3f30
--- /dev/null
+++ b/tests/opencl/test-gegl-tile-lock-mode-write-then-read.c
@@ -0,0 +1,111 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2011 Victor Matheus de Araujo Oliveira <victormatheus gmail com>
+ Based on work from Jerson Michael Perpetua <jersonperpetua gmail com>
+ */
+
+#include <string.h>
+#include <babl/babl.h>
+
+#include "gegl.h"
+#include "gegl-utils.h"
+#include "gegl-cl-init.h"
+#include "gegl-cl-texture.h"
+
+#include "../../gegl/buffer/gegl-tile.h"
+#include "../../gegl/buffer/gegl-buffer-private.h"
+
+#define SUCCESS 0
+#define FAILURE (-1)
+
+#define TEXTURE_SIZE (1024)
+#define TEXTURE_SIZE_BYTES (TEXTURE_SIZE * sizeof(gfloat))
+
+#define RANDOM_PIXEL_COUNT 1000
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ gint retval = SUCCESS;
+
+ GeglTile *tile;
+ gfloat *components;
+
+ gegl_init (&argc, &argv);
+
+ gegl_cl_init (NULL);
+
+ if (!gegl_cl_is_accelerated ())
+ {
+ g_warning ("OpenCL support is disabled. Skipping.\n");
+ goto skip;
+ }
+
+ tile = gegl_tile_new (TEXTURE_SIZE_BYTES * 4);
+
+ components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ {
+ gint cnt;
+ gfloat *tile_components = g_new (gfloat, TEXTURE_SIZE * 4);
+
+ memset (gegl_tile_get_data(tile), 0, TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < RANDOM_PIXEL_COUNT; cnt++)
+ {
+ gint i = g_random_int_range (0, TEXTURE_SIZE);
+
+ gfloat *pixel = &components[i * 4];
+
+ pixel[0] = g_random_double ();
+ pixel[1] = g_random_double ();
+ pixel[2] = g_random_double ();
+ pixel[3] = g_random_double ();
+ }
+
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_WRITE);
+
+ /* set tile to a random image */
+ memcpy (gegl_tile_get_data(tile), components, TEXTURE_SIZE_BYTES * 4);
+
+ gegl_tile_unlock (tile);
+
+ gegl_tile_lock (tile, GEGL_TILE_LOCK_READ);
+
+ memcpy (tile_components, gegl_tile_get_data(tile), TEXTURE_SIZE_BYTES * 4);
+
+ for (cnt = 0; cnt < TEXTURE_SIZE * 4; cnt++)
+ if (!GEGL_FLOAT_EQUAL (tile_components[cnt], components[cnt]))
+ {
+ g_printerr ("Tile data inconsistent with original original data "
+ "Aborting.\n");
+
+ retval = FAILURE;
+ break;
+ }
+
+ gegl_tile_unlock (tile);
+ }
+
+ g_free (components);
+ gegl_tile_unref (tile);
+
+skip:
+ gegl_exit ();
+
+ return retval;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]