Commit f767881d authored by André Tupinambá's avatar André Tupinambá Committed by Øyvind "pippin" Kolås

perf: add common bench function to test both opencl and c paths

parent d2c672dc
#include "test-common.h"
void bcontrast4x(GeglBuffer *buffer);
gint
main (gint argc,
gchar **argv)
{
GeglBuffer *buffer, *buffer2;
GeglNode *gegl, *source, *node1, *node2, *node3, *node4, *sink;
gint i;
GeglBuffer *buffer;
gegl_init (&argc, &argv);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
#define ITERATIONS 16
test_start ();
for (i=0;i< ITERATIONS;i++)
{
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node1 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
node2 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
node3 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
node4 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node1, node2, node3, node4, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
test_end ("bcontrast_4x", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
bench("bcontrast_4x", buffer, &bcontrast4x);
return 0;
}
void bcontrast4x(GeglBuffer *buffer)
{
GeglBuffer *buffer2;
GeglNode *gegl, *source, *node1, *node2, *node3, *node4, *sink;
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node1 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
node2 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
node3 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
node4 = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node1, node2, node3, node4, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
#include "test-common.h"
void bcontrast_minichunk(GeglBuffer *buffer);
gint
main (gint argc,
gchar **argv)
{
GeglBuffer *buffer, *buffer2;
GeglNode *gegl, *source, *node, *sink;
gint i;
GeglBuffer *buffer;
gegl_init (&argc, &argv);
g_object_set (gegl_config (), "chunk-size", 32 * 32, NULL);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
#define ITERATIONS 8
test_start ();
for (i=0;i< ITERATIONS;i++)
{
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
test_end ("bcontrast-minichunk", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
bench("bcontrast-minichunk", buffer, &bcontrast_minichunk);
return 0;
}
void bcontrast_minichunk(GeglBuffer *buffer)
{
GeglBuffer *buffer2;
GeglNode *gegl, *source, *node, *sink;
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
#include "test-common.h"
void blur(GeglBuffer *buffer);
gint
main (gint argc,
gchar **argv)
{
GeglBuffer *buffer, *buffer2;
GeglNode *gegl, *source, *node, *sink;
gint i;
GeglBuffer *buffer;
gegl_init (&argc, &argv);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
#define ITERATIONS 16
test_start ();
for (i=0;i< ITERATIONS;i++)
{
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
test_end ("bcontrast", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
bench("bcontrast", buffer, &blur);
return 0;
}
void blur(GeglBuffer *buffer)
{
GeglBuffer *buffer2;
GeglNode *gegl, *source, *node, *sink;
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:brightness-contrast", "contrast", 0.2, NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
#include "test-common.h"
void blur(GeglBuffer *buffer);
gint
main (gint argc,
gchar **argv)
{
GeglBuffer *buffer, *buffer2;
GeglNode *gegl, *source, *node, *sink;
gint i;
GeglBuffer *buffer;
gegl_init (&argc, &argv);
gegl_init(&argc, &argv);
buffer = test_buffer (1024, 1024, babl_format ("RGBA float"));
buffer = test_buffer(1024, 1024, babl_format("RGBA float"));
bench("gaussian-blur", buffer, &blur);
}
#define ITERATIONS 16
test_start ();
for (i=0;i< ITERATIONS;i++)
{
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:gaussian-blur",
void blur(GeglBuffer *buffer)
{
GeglBuffer *buffer2;
GeglNode *gegl, *source, *node, *sink;
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:gaussian-blur",
"std-dev-x", 0.5,
"std-dev-y", 0.5,
NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
test_end ("gaussian-blur", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
return 0;
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
......@@ -4,26 +4,46 @@
static long ticks_start;
typedef void (*t_run_perf)(GeglBuffer *buffer);
long babl_ticks (void); /* using babl_ticks instead of gegl_ticks
to be able to go further back in time */
void test_start (void);
void test_end (const gchar *id,
glong bytes);
void test_end_suffix (const gchar *id,
const gchar *suffix,
glong bytes);
GeglBuffer *test_buffer (gint width,
gint height,
const Babl *format);
void do_bench(const gchar *id,
GeglBuffer *buffer,
t_run_perf test_func,
gboolean opencl);
void bench(const gchar *id,
GeglBuffer *buffer,
t_run_perf test_func );
void test_start (void)
{
ticks_start = babl_ticks ();
}
void test_end_suffix (const gchar *id,
const gchar *suffix,
glong bytes)
{
long ticks = babl_ticks ()-ticks_start;
g_print ("@ %s%s: %.2f megabytes/second\n",
id, suffix, (bytes / 1024.0 / 1024.0) / (ticks / 1000000.0));
}
void test_end (const gchar *id,
glong bytes)
{
long ticks = babl_ticks ()-ticks_start;
g_print ("@ %s: %.2f megabytes/second\n",
id, (bytes / 1024.0 / 1024.0) / (ticks / 1000000.0));
test_end_suffix (id, "", bytes);
}
/* create a test buffer of random data in -0.5 to 2.0 range
......@@ -43,3 +63,39 @@ GeglBuffer *test_buffer (gint width,
g_free (buf);
return buffer;
}
void do_bench (const gchar *id,
GeglBuffer *buffer,
t_run_perf test_func,
gboolean opencl)
{
gchar* suffix = "";
g_object_set(G_OBJECT(gegl_config()),
"use-opencl", opencl,
NULL);
if (opencl)
suffix = " (OpenCL)";
// warm up
test_func(buffer);
#define ITERATIONS 16
test_start ();
for (int i=0; i<ITERATIONS; ++i)
{
test_func(buffer);
}
test_end_suffix (id, suffix, gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
#undef ITERATIONS
}
void bench (const gchar *id,
GeglBuffer *buffer,
t_run_perf test_func)
{
do_bench(id, buffer, test_func, FALSE );
do_bench(id, buffer, test_func, TRUE );
}
#include "test-common.h"
void unsharpmask(GeglBuffer *buffer);
gint
main (gint argc,
gchar **argv)
{
GeglBuffer *buffer, *buffer2;
GeglNode *gegl, *source, *node, *sink;
gint i;
GeglBuffer *buffer;
gegl_init (&argc, &argv);
buffer = test_buffer (2048, 1024, babl_format ("RGBA float"));
bench("unsharp-mask", buffer, &unsharpmask);
return 0;
}
#define ITERATIONS 8
test_start ();
for (i=0;i< ITERATIONS;i++)
{
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:unsharp-mask",
void unsharpmask(GeglBuffer *buffer)
{
GeglBuffer *buffer2;
GeglNode *gegl, *source, *node, *sink;
gegl = gegl_node_new ();
source = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
node = gegl_node_new_child (gegl, "operation", "gegl:unsharp-mask",
"std-dev", 3.1,
"scale", 1.2,
NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
sink = gegl_node_new_child (gegl, "operation", "gegl:buffer-sink", "buffer", &buffer2, NULL);
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
test_end ("unsharp-mask", gegl_buffer_get_pixel_count (buffer) * 16 * ITERATIONS);
return 0;
gegl_node_link_many (source, node, sink, NULL);
gegl_node_process (sink);
g_object_unref (gegl);
g_object_unref (buffer2);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment