[gegl/gsoc2011-opencl: 6/18] OpenCL shared resources created in gegl_cl_init



commit 249ae3d70ceba3b76b50c4475984f29dfc66864b
Author: Victor Oliveira <victormatheus gmail com>
Date:   Sat Jul 2 01:32:44 2011 -0300

    OpenCL shared resources created in gegl_cl_init
    
    a default platform, device, context and command
    queue is created in gegl_cl_init

 gegl/opencl/gegl-cl-init.c |   52 ++++++++++++++++++++++++++++++++++++++++++++
 gegl/opencl/gegl-cl-init.h |   18 +++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 59563a9..a53cce9 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -6,6 +6,14 @@
 #include <string.h>
 #include <stdio.h>
 
+guint
+gegl_cl_count_lines(const char* kernel_source[])
+{
+  guint count = 0;
+  while (kernel_source[count++] != NULL);
+  return count-1;
+}
+
 /* http://forums.amd.com/forum/messageview.cfm?catid=390&threadid=128536 */
 char *gegl_cl_errstring(cl_int err) {
   switch (err) {
@@ -61,12 +69,41 @@ char *gegl_cl_errstring(cl_int err) {
 
 static gboolean cl_is_accelerated  = FALSE;
 
+static cl_platform_id   platform = NULL;
+static cl_device_id     device   = NULL;
+static cl_context       ctx      = NULL;
+static cl_command_queue cq       = NULL;
+
 gboolean
 gegl_cl_is_accelerated (void)
 {
   return cl_is_accelerated;
 }
 
+cl_platform_id
+gegl_cl_get_platform (void)
+{
+  return platform;
+}
+
+cl_device_id
+gegl_cl_get_device (void)
+{
+  return device;
+}
+
+cl_context
+gegl_cl_get_context (void)
+{
+  return ctx;
+}
+
+cl_command_queue
+gegl_cl_get_command_queue (void)
+{
+  return cq;
+}
+
 #define CL_LOAD_FUNCTION(func)                                                    \
 if (!g_module_symbol (module, #func, (gpointer *)& gegl_##func))                  \
   {                                                                               \
@@ -135,6 +172,21 @@ gegl_cl_init (GError **error)
       CL_LOAD_FUNCTION (clReleaseMemObject)
 
       cl_is_accelerated = TRUE;
+
+      gegl_clGetPlatformIDs (1, &platform, NULL);
+      gegl_clGetPlatformInfo (platform, CL_PLATFORM_NAME, sizeof(buffer), buffer, NULL);
+      g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Platform Name:%s\n", buffer);
+      gegl_clGetPlatformInfo (platform, CL_PLATFORM_VERSION, sizeof(buffer), buffer, NULL);
+      g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Version:%s\n", buffer);
+      gegl_clGetPlatformInfo (platform, CL_PLATFORM_EXTENSIONS, sizeof(buffer), buffer, NULL);
+      g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Extensions:%s\n", buffer);
+
+      gegl_clGetDeviceIDs(platform, CL_DEVICE_TYPE_DEFAULT, 1, &device, NULL);
+      gegl_clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(buffer), buffer, NULL);
+      g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Default Device Name:%s\n", buffer);
+
+      ctx = gegl_clCreateContext(0, 1, &device, NULL, NULL, NULL);
+      cq  = gegl_clCreateCommandQueue(ctx, device, 0, NULL);
     }
 
   return TRUE;
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index 2016a6e..58c13b6 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -4,12 +4,30 @@
 #include "gegl-cl-types.h"
 #include <gmodule.h>
 
+#define CL_SAFE_CALL(func)                                          \
+func;                                                               \
+if (errcode != CL_SUCCESS)                                          \
+{                                                                   \
+  g_warning("OpenCL error in %s, Line %u in file %s\nError:%s",     \
+            #func, __LINE__, __FILE__, gegl_cl_errstring(errcode)); \
+}
+
+guint gegl_cl_count_lines(const char* kernel_source[]);
+
 char *gegl_cl_errstring(cl_int err);
 
 gboolean gegl_cl_init (GError **error);
 
 gboolean gegl_cl_is_accelerated (void);
 
+cl_platform_id gegl_cl_get_platform (void);
+
+cl_device_id gegl_cl_get_device (void);
+
+cl_context gegl_cl_get_context (void);
+
+cl_command_queue gegl_cl_get_command_queue (void);
+
 #ifdef __GEGL_CL_INIT_MAIN__
 t_clGetPlatformIDs  gegl_clGetPlatformIDs  = NULL;
 t_clGetPlatformInfo gegl_clGetPlatformInfo = NULL;



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