[gegl] opencl: optimizations



commit 266dd432e9c454ddbe97b0b5750dc5d8b37a4b90
Author: Victor Oliveira <victormatheus gmail com>
Date:   Sat Apr 28 15:40:03 2012 -0300

    opencl: optimizations
    
    removing unnecessary barriers and flags

 gegl/buffer/gegl-buffer-cl-cache.c    |   15 +++++++--------
 gegl/buffer/gegl-buffer-cl-iterator.c |   32 ++++++++++----------------------
 gegl/opencl/gegl-cl-init.c            |    5 ++---
 3 files changed, 19 insertions(+), 33 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-cl-cache.c b/gegl/buffer/gegl-buffer-cl-cache.c
index ad0f279..2ccb52f 100644
--- a/gegl/buffer/gegl-buffer-cl-cache.c
+++ b/gegl/buffer/gegl-buffer-cl-cache.c
@@ -134,20 +134,19 @@ gegl_buffer_cl_cache_flush2 (GeglTileHandlerCache *cache,
 
           gegl_cl_color_babl (entry->buffer->soft_format, &size);
 
-          data = gegl_clEnqueueMapBuffer(gegl_cl_get_command_queue(), entry->tex, CL_TRUE,
-                                         CL_MAP_READ, 0, entry->roi.width * entry->roi.height * size,
-                                         0, NULL, NULL, &cl_err);
-          if (cl_err != CL_SUCCESS) CL_ERROR;
+          data = g_malloc(entry->roi.width * entry->roi.height * size);
+
+          cl_err = gegl_clEnqueueReadBuffer(gegl_cl_get_command_queue(),
+                                            entry->tex, CL_TRUE, 0, entry->roi.width * entry->roi.height * size, data,
+                                            0, NULL, NULL);
 
           /* tile-ize */
           gegl_buffer_set (entry->buffer, &entry->roi, 0, entry->buffer->soft_format, data, GEGL_AUTO_ROWSTRIDE);
 
-          cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), entry->tex, data,
-                                                 0, NULL, NULL);
-          if (cl_err != CL_SUCCESS) CL_ERROR;
-
           entry->used --;
           need_cl = TRUE;
+
+          g_free(data);
         }
     }
 
diff --git a/gegl/buffer/gegl-buffer-cl-iterator.c b/gegl/buffer/gegl-buffer-cl-iterator.c
index c64222d..73047eb 100644
--- a/gegl/buffer/gegl-buffer-cl-iterator.c
+++ b/gegl/buffer/gegl-buffer-cl-iterator.c
@@ -222,10 +222,6 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
         {
           if (i->flags[no] == GEGL_CL_BUFFER_WRITE)
             {
-              /* Wait Processing */
-              cl_err = gegl_clEnqueueBarrier(gegl_cl_get_command_queue());
-              if (cl_err != CL_SUCCESS) CL_ERROR;
-
               /* color conversion in the GPU (output) */
               if (i->conv[no] == GEGL_CL_COLOR_CONVERT)
                 for (j=0; j < i->n; j++)
@@ -235,10 +231,6 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                     if (cl_err == FALSE) CL_ERROR;
                   }
 
-              /* Wait Processing */
-              cl_err = gegl_clEnqueueBarrier(gegl_cl_get_command_queue());
-              if (cl_err != CL_SUCCESS) CL_ERROR;
-
               /* GPU -> CPU */
               for (j=0; j < i->n; j++)
                 {
@@ -247,18 +239,18 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                   /* tile-ize */
                   if (i->conv[no] == GEGL_CL_COLOR_NOT_SUPPORTED)
                     {
-                      data = gegl_clEnqueueMapBuffer(gegl_cl_get_command_queue(), i->tex_op[no][j], CL_TRUE,
-                                                     CL_MAP_READ,
-                                                     0, i->size[no][j] * i->op_cl_format_size [no],
-                                                     0, NULL, NULL, &cl_err);
+                      data = g_malloc(i->size[no][j] * i->op_cl_format_size [no]);
+
+                      cl_err = gegl_clEnqueueReadBuffer(gegl_cl_get_command_queue(),
+                                                        i->tex_op[no][j], CL_TRUE,
+                                                        0, i->size[no][j] * i->op_cl_format_size [no], data,
+                                                        0, NULL, NULL);
                       if (cl_err != CL_SUCCESS) CL_ERROR;
 
                       /* color conversion using BABL */
                       gegl_buffer_set (i->buffer[no], &i->roi[no][j], 0, i->format[no], data, GEGL_AUTO_ROWSTRIDE);
 
-                      cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), i->tex_op[no][j], data,
-                                                             0, NULL, NULL);
-                      if (cl_err != CL_SUCCESS) CL_ERROR;
+                      g_free(data);
                     }
                   else
 #ifdef OPENCL_USE_CACHE
@@ -460,10 +452,6 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                     }
                 }
             }
-
-          /* Wait Processing */
-          cl_err = gegl_clEnqueueBarrier(gegl_cl_get_command_queue());
-          if (cl_err != CL_SUCCESS) CL_ERROR;
         }
       else if (i->flags[no] == GEGL_CL_BUFFER_WRITE)
         {
@@ -476,7 +464,7 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                   {
                   g_assert (i->tex_op[no][j] == NULL);
                   i->tex_op[no][j] = gegl_clCreateBuffer (gegl_cl_get_context (),
-                                                          CL_MEM_ALLOC_HOST_PTR | CL_MEM_WRITE_ONLY,
+                                                          CL_MEM_WRITE_ONLY,
                                                           i->size[no][j] * i->op_cl_format_size [no],
                                                           NULL, &cl_err);
                   if (cl_err != CL_SUCCESS) CL_ERROR;
@@ -491,7 +479,7 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                   {
                   g_assert (i->tex_buf[no][j] == NULL);
                   i->tex_buf[no][j] = gegl_clCreateBuffer (gegl_cl_get_context (),
-                                                           CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, /* cache */
+                                                           CL_MEM_READ_WRITE, /* cache */
                                                            i->size[no][j] * i->buf_cl_format_size [no],
                                                            NULL, &cl_err);
                   if (cl_err != CL_SUCCESS) CL_ERROR;
@@ -506,7 +494,7 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                   {
                   g_assert (i->tex_buf[no][j] == NULL);
                   i->tex_buf[no][j] = gegl_clCreateBuffer (gegl_cl_get_context (),
-                                                           CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, /* cache */
+                                                           CL_MEM_READ_WRITE, /* cache */
                                                            i->size[no][j] * i->buf_cl_format_size [no],
                                                            NULL, &cl_err);
                   if (cl_err != CL_SUCCESS) CL_ERROR;
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 554005b..46bf858 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -154,15 +154,14 @@ if ((gegl_##func = (t_##func) GetProcAddress(module, #func)) == NULL)
 #define CL_LOAD_FUNCTION(func)                                                    \
 if (!g_module_symbol (module, #func, (gpointer *)& gegl_##func))                  \
   {                                                                               \
-    g_set_error (error, 0, 0,                                                     \
-                 "%s: %s", "libOpenCL.so", g_module_error ());                    \
+    GEGL_NOTE (GEGL_DEBUG_OPENCL, "%s: %s", "libOpenCL.so", g_module_error ());   \
     if (!g_module_close (module))                                                 \
       g_warning ("%s: %s", "libOpenCL.so", g_module_error ());                    \
     return FALSE;                                                                 \
   }                                                                               \
 if (gegl_##func == NULL)                                                          \
   {                                                                               \
-    g_set_error (error, 0, 0, "symbol gegl_##func is NULL");                      \
+    GEGL_NOTE (GEGL_DEBUG_OPENCL, "symbol gegl_##func is NULL");                  \
     if (!g_module_close (module))                                                 \
       g_warning ("%s: %s", "libOpenCL.so", g_module_error ());                    \
     return FALSE;                                                                 \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]