[gegl] opencl: allocate the random buffer once and for all
- From: Téo Mazars <teom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] opencl: allocate the random buffer once and for all
- Date: Sat, 16 Nov 2013 19:01:26 +0000 (UTC)
commit 0a4431dbdfc640d0f762f8724e01c5bc2608b165
Author: Téo Mazars <teomazars gmail com>
Date: Sat Nov 16 19:52:56 2013 +0100
opencl: allocate the random buffer once and for all
gegl/gegl-init.c | 1 +
gegl/opencl/gegl-cl-init.c | 9 +++++++++
gegl/opencl/gegl-cl-init.h | 2 ++
gegl/opencl/gegl-cl-random.c | 36 ++++++++++++++++++++++++++++--------
gegl/opencl/gegl-cl-random.h | 2 ++
operations/common/noise-hurl.c | 3 ---
6 files changed, 42 insertions(+), 11 deletions(-)
---
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 9c3723b..e7fa4fe 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -452,6 +452,7 @@ gegl_exit (void)
gegl_operation_gtype_cleanup ();
gegl_extension_handler_cleanup ();
gegl_random_cleanup ();
+ gegl_cl_cleanup ();
if (module_db != NULL)
{
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 29cd647..f6eb0a9 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -859,3 +859,12 @@ gegl_cl_compile_and_build (const char *program_source, const char *kernel_name[]
return cl_data;
}
+
+void
+gegl_cl_cleanup (void)
+{
+ cl_int err;
+ err = gegl_cl_random_cleanup ();
+ if (err != CL_SUCCESS)
+ GEGL_NOTE (GEGL_DEBUG_OPENCL, "Could not free cl_random_data: %s", gegl_cl_errstring (err));
+}
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index cfd2da1..fd0dfd5 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -27,6 +27,8 @@ gboolean gegl_cl_init (GError **error);
gboolean gegl_cl_init_with_opengl (GError **error);
+void gegl_cl_cleanup (void);
+
gboolean gegl_cl_is_accelerated (void);
gboolean gegl_cl_has_gl_sharing (void);
diff --git a/gegl/opencl/gegl-cl-random.c b/gegl/opencl/gegl-cl-random.c
index 46e88a0..2b2c855 100644
--- a/gegl/opencl/gegl-cl-random.c
+++ b/gegl/opencl/gegl-cl-random.c
@@ -21,21 +21,41 @@
#include "opencl/gegl-cl.h"
#include "gegl-random-priv.h"
+static cl_mem cl_random_data = NULL;
+
cl_mem
gegl_cl_load_random_data (gint *cl_err)
{
- cl_mem cl_random_data;
- guint32 *random_data;
+ if (cl_random_data == NULL)
+ {
+ guint32 *random_data;
- random_data = gegl_random_get_data ();
- cl_random_data = gegl_clCreateBuffer (gegl_cl_get_context (),
- CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
- RANDOM_DATA_SIZE * sizeof (guint32),
- (void*) random_data,
- cl_err);
+ random_data = gegl_random_get_data ();
+ cl_random_data = gegl_clCreateBuffer (gegl_cl_get_context (),
+ CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
+ RANDOM_DATA_SIZE * sizeof (guint32),
+ (void*) random_data,
+ cl_err);
+ }
+ else
+ {
+ *cl_err = CL_SUCCESS;
+ }
return cl_random_data;
}
+cl_int
+gegl_cl_random_cleanup (void)
+{
+ cl_int cl_err = CL_SUCCESS;
+ if (cl_random_data != NULL)
+ {
+ cl_err = gegl_clReleaseMemObject (cl_random_data);
+ cl_random_data = NULL;
+ }
+ return cl_err;
+}
+
void
gegl_cl_random_get_ushort4 (const GeglRandom *in_rand,
cl_ushort4 *out_rand)
diff --git a/gegl/opencl/gegl-cl-random.h b/gegl/opencl/gegl-cl-random.h
index 33b7bda..bc1782d 100644
--- a/gegl/opencl/gegl-cl-random.h
+++ b/gegl/opencl/gegl-cl-random.h
@@ -24,6 +24,8 @@
/** Load the random data needed to generate random numbers in the GPU*/
cl_mem gegl_cl_load_random_data (int *cl_err);
+cl_int gegl_cl_random_cleanup (void);
+
void
gegl_cl_random_get_ushort4 (const GeglRandom *in_rand, cl_ushort4 *out_rand);
diff --git a/operations/common/noise-hurl.c b/operations/common/noise-hurl.c
index 9c9f560..e1aa759 100644
--- a/operations/common/noise-hurl.c
+++ b/operations/common/noise-hurl.c
@@ -187,9 +187,6 @@ cl_process (GeglOperation *operation,
cl_err = gegl_clFinish (gegl_cl_get_command_queue ());
CL_CHECK;
-
- cl_err = gegl_clReleaseMemObject (cl_random_data);
- CL_CHECK_ONLY (cl_err);
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]