[gegl/gsoc2011-opencl: 9/14] More OpenCL functions stubs



commit 06e9c1a68b756450a353f116cb901d7483b1a734
Author: Victor Matheus de A. Oliveira <victormatheus gmail com>
Date:   Sun May 15 20:30:40 2011 -0300

    More OpenCL functions stubs
    
    Signed-off-by: Victor Oliveira <victormatheus gmail com>

 gegl/opencl/gegl-cl-init.c  |   86 +++++++++++++++++++++++++++++++++++++++++-
 gegl/opencl/gegl-cl-init.h  |   45 ++++++++++++++++++++++
 gegl/opencl/gegl-cl-types.h |   29 ++++++++++----
 3 files changed, 149 insertions(+), 11 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index a3a7cde..0502ad1 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -3,8 +3,62 @@
 #undef __GEGL_CL_INIT_MAIN__
 
 #include <gmodule.h>
+#include <string.h>
 #include <stdio.h>
 
+/* http://forums.amd.com/forum/messageview.cfm?catid=390&threadid=128536 */
+char *gegl_cl_errstring(cl_int err) {
+  switch (err) {
+    case CL_SUCCESS:                          return strdup("Success!");
+    case CL_DEVICE_NOT_FOUND:                 return strdup("Device not found.");
+    case CL_DEVICE_NOT_AVAILABLE:             return strdup("Device not available");
+    case CL_COMPILER_NOT_AVAILABLE:           return strdup("Compiler not available");
+    case CL_MEM_OBJECT_ALLOCATION_FAILURE:    return strdup("Memory object allocation failure");
+    case CL_OUT_OF_RESOURCES:                 return strdup("Out of resources");
+    case CL_OUT_OF_HOST_MEMORY:               return strdup("Out of host memory");
+    case CL_PROFILING_INFO_NOT_AVAILABLE:     return strdup("Profiling information not available");
+    case CL_MEM_COPY_OVERLAP:                 return strdup("Memory copy overlap");
+    case CL_IMAGE_FORMAT_MISMATCH:            return strdup("Image format mismatch");
+    case CL_IMAGE_FORMAT_NOT_SUPPORTED:       return strdup("Image format not supported");
+    case CL_BUILD_PROGRAM_FAILURE:            return strdup("Program build failure");
+    case CL_MAP_FAILURE:                      return strdup("Map failure");
+    case CL_INVALID_VALUE:                    return strdup("Invalid value");
+    case CL_INVALID_DEVICE_TYPE:              return strdup("Invalid device type");
+    case CL_INVALID_PLATFORM:                 return strdup("Invalid platform");
+    case CL_INVALID_DEVICE:                   return strdup("Invalid device");
+    case CL_INVALID_CONTEXT:                  return strdup("Invalid context");
+    case CL_INVALID_QUEUE_PROPERTIES:         return strdup("Invalid queue properties");
+    case CL_INVALID_COMMAND_QUEUE:            return strdup("Invalid command queue");
+    case CL_INVALID_HOST_PTR:                 return strdup("Invalid host pointer");
+    case CL_INVALID_MEM_OBJECT:               return strdup("Invalid memory object");
+    case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:  return strdup("Invalid image format descriptor");
+    case CL_INVALID_IMAGE_SIZE:               return strdup("Invalid image size");
+    case CL_INVALID_SAMPLER:                  return strdup("Invalid sampler");
+    case CL_INVALID_BINARY:                   return strdup("Invalid binary");
+    case CL_INVALID_BUILD_OPTIONS:            return strdup("Invalid build options");
+    case CL_INVALID_PROGRAM:                  return strdup("Invalid program");
+    case CL_INVALID_PROGRAM_EXECUTABLE:       return strdup("Invalid program executable");
+    case CL_INVALID_KERNEL_NAME:              return strdup("Invalid kernel name");
+    case CL_INVALID_KERNEL_DEFINITION:        return strdup("Invalid kernel definition");
+    case CL_INVALID_KERNEL:                   return strdup("Invalid kernel");
+    case CL_INVALID_ARG_INDEX:                return strdup("Invalid argument index");
+    case CL_INVALID_ARG_VALUE:                return strdup("Invalid argument value");
+    case CL_INVALID_ARG_SIZE:                 return strdup("Invalid argument size");
+    case CL_INVALID_KERNEL_ARGS:              return strdup("Invalid kernel arguments");
+    case CL_INVALID_WORK_DIMENSION:           return strdup("Invalid work dimension");
+    case CL_INVALID_WORK_GROUP_SIZE:          return strdup("Invalid work group size");
+    case CL_INVALID_WORK_ITEM_SIZE:           return strdup("Invalid work item size");
+    case CL_INVALID_GLOBAL_OFFSET:            return strdup("Invalid global offset");
+    case CL_INVALID_EVENT_WAIT_LIST:          return strdup("Invalid event wait list");
+    case CL_INVALID_EVENT:                    return strdup("Invalid event");
+    case CL_INVALID_OPERATION:                return strdup("Invalid operation");
+    case CL_INVALID_GL_OBJECT:                return strdup("Invalid OpenGL object");
+    case CL_INVALID_BUFFER_SIZE:              return strdup("Invalid buffer size");
+    case CL_INVALID_MIP_LEVEL:                return strdup("Invalid mip-map level");
+    default:                                  return strdup("Unknown");
+  }
+}
+
 static gboolean cl_is_accelerated  = FALSE;
 
 gboolean
@@ -16,7 +70,7 @@ gegl_cl_is_accelerated (void)
 #define CL_LOAD_FUNCTION(func)                                                    \
 if (!g_module_symbol (module, #func, (gpointer *)& gegl_##func))                  \
   {                                                                               \
-    g_set_error (error, 0, 0,                                \
+    g_set_error (error, 0, 0,                                                     \
                  "%s: %s", "libOpenCL.so", g_module_error ());                    \
     if (!g_module_close (module))                                                 \
       g_warning ("%s: %s", "libOpenCL.so", g_module_error ());                    \
@@ -24,7 +78,7 @@ if (!g_module_symbol (module, #func, (gpointer *)& gegl_##func))
   }                                                                               \
 if (gegl_##func == NULL)                                                          \
   {                                                                               \
-    g_set_error (error, 0, 0, "symbol gegl_##func is NULL"); \
+    g_set_error (error, 0, 0, "symbol gegl_##func is NULL");                      \
     if (!g_module_close (module))                                                 \
       g_warning ("%s: %s", "libOpenCL.so", g_module_error ());                    \
     return FALSE;                                                                 \
@@ -37,7 +91,9 @@ gegl_cl_init (GError **error)
 
   char buffer[65536];
   cl_platform_id platforms[1024];
+  cl_device_id device;
   cl_uint num_platforms;
+
   int i;
 
   if (!cl_is_accelerated)
@@ -53,6 +109,26 @@ gegl_cl_init (GError **error)
 
       CL_LOAD_FUNCTION (clGetPlatformIDs)
       CL_LOAD_FUNCTION (clGetPlatformInfo)
+      CL_LOAD_FUNCTION (clGetDeviceIDs)
+      CL_LOAD_FUNCTION (clGetDeviceInfo)
+
+      CL_LOAD_FUNCTION (clCreateContext)
+      CL_LOAD_FUNCTION (clCreateCommandQueue)
+      CL_LOAD_FUNCTION (clCreateProgramWithSource)
+      CL_LOAD_FUNCTION (clBuildProgram)
+      CL_LOAD_FUNCTION (clCreateKernel)
+      CL_LOAD_FUNCTION (clSetKernelArg)
+      CL_LOAD_FUNCTION (clGetKernelWorkGroupInfo)
+      CL_LOAD_FUNCTION (clCreateBuffer)
+      CL_LOAD_FUNCTION (clEnqueueWriteBuffer)
+      CL_LOAD_FUNCTION (clEnqueueReadBuffer)
+      CL_LOAD_FUNCTION (clEnqueueNDRangeKernel)
+
+      CL_LOAD_FUNCTION (clReleaseKernel)
+      CL_LOAD_FUNCTION (clReleaseProgram)
+      CL_LOAD_FUNCTION (clReleaseCommandQueue)
+      CL_LOAD_FUNCTION (clReleaseContext)
+      CL_LOAD_FUNCTION (clReleaseMemObject)
 
       cl_is_accelerated = TRUE;
 
@@ -60,11 +136,15 @@ gegl_cl_init (GError **error)
       for (i=0; i<num_platforms; i++)
         {
           gegl_clGetPlatformInfo (platforms[i], CL_PLATFORM_NAME, sizeof(buffer), buffer, NULL);
-          printf("Device ID:%u\n%s\n", i, buffer);
+          printf("Platform ID:%u\n%s\n", i, buffer);
           gegl_clGetPlatformInfo (platforms[i], CL_PLATFORM_VERSION, sizeof(buffer), buffer, NULL);
           printf("Version:%s\n", buffer);
           gegl_clGetPlatformInfo (platforms[i], CL_PLATFORM_EXTENSIONS, sizeof(buffer), buffer, NULL);
           printf("Extensions:%s\n", buffer);
+
+          gegl_clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_DEFAULT, 1, &device, NULL);
+          gegl_clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(buffer), buffer, NULL);
+          printf("Default Device Name:%s\n", buffer);
         }
     }
 
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index 9dc0aba..022140e 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -4,6 +4,8 @@
 #include "gegl-cl-types.h"
 #include <gmodule.h>
 
+char *gegl_cl_errstring(cl_int err);
+
 gboolean gegl_cl_init (GError **error);
 
 gboolean gegl_cl_is_accelerated (void);
@@ -11,9 +13,52 @@ gboolean gegl_cl_is_accelerated (void);
 #ifdef __GEGL_CL_INIT_MAIN__
 t_clGetPlatformIDs  gegl_clGetPlatformIDs  = NULL;
 t_clGetPlatformInfo gegl_clGetPlatformInfo = NULL;
+t_clGetDeviceIDs    gegl_clGetDeviceIDs    = NULL;
+t_clGetDeviceInfo   gegl_clGetDeviceInfo   = NULL;
+
+t_clCreateContext           gegl_clCreateContext           = NULL;
+t_clCreateCommandQueue      gegl_clCreateCommandQueue      = NULL;
+t_clCreateProgramWithSource gegl_clCreateProgramWithSource = NULL;
+t_clBuildProgram            gegl_clBuildProgram            = NULL;
+t_clCreateKernel            gegl_clCreateKernel            = NULL;
+t_clSetKernelArg            gegl_clSetKernelArg            = NULL;
+t_clGetKernelWorkGroupInfo  gegl_clGetKernelWorkGroupInfo  = NULL;
+t_clCreateBuffer            gegl_clCreateBuffer            = NULL;
+t_clEnqueueWriteBuffer      gegl_clEnqueueWriteBuffer      = NULL;
+t_clEnqueueReadBuffer       gegl_clEnqueueReadBuffer       = NULL;
+t_clEnqueueNDRangeKernel    gegl_clEnqueueNDRangeKernel    = NULL;
+
+t_clReleaseKernel       gegl_clReleaseKernel       = NULL;
+t_clReleaseProgram      gegl_clReleaseProgram      = NULL;
+t_clReleaseCommandQueue gegl_clReleaseCommandQueue = NULL;
+t_clReleaseContext      gegl_clReleaseContext      = NULL;
+t_clReleaseMemObject    gegl_clReleaseMemObject    = NULL;
+
 #else
+
 extern t_clGetPlatformIDs  gegl_clGetPlatformIDs;
 extern t_clGetPlatformInfo gegl_clGetPlatformInfo;
+extern t_clGetDeviceIDs    gegl_clGetDeviceIDs;
+extern t_clGetDeviceInfo   gegl_clGetDeviceInfo;
+
+extern t_clCreateContext           gegl_clCreateContext;
+extern t_clCreateCommandQueue      gegl_clCreateCommandQueue;
+extern t_clCreateProgramWithSource gegl_clCreateProgramWithSource;
+extern t_clBuildProgram            gegl_clBuildProgram;
+extern t_clCreateKernel            gegl_clCreateKernel;
+extern t_clSetKernelArg            gegl_clSetKernelArg;
+extern t_clGetKernelWorkGroupInfo  gegl_clGetKernelWorkGroupInfo;
+extern t_clCreateBuffer            gegl_clCreateBuffer;
+extern t_clEnqueueWriteBuffer      gegl_clEnqueueWriteBuffer;
+extern t_clEnqueueReadBuffer       gegl_clEnqueueReadBuffer;
+extern t_clEnqueueNDRangeKernel    gegl_clEnqueueNDRangeKernel;
+
+extern t_clReleaseKernel       gegl_clReleaseKernel;
+extern t_clReleaseProgram      gegl_clReleaseProgram;
+extern t_clReleaseCommandQueue gegl_clReleaseCommandQueue;
+extern t_clReleaseContext      gegl_clReleaseContext;
+extern t_clReleaseMemObject    gegl_clReleaseMemObject;
+
 #endif
 
 #endif  /* __GEGL_CL_INIT_H__ */
diff --git a/gegl/opencl/gegl-cl-types.h b/gegl/opencl/gegl-cl-types.h
index 1182c4c..9d23e0c 100644
--- a/gegl/opencl/gegl-cl-types.h
+++ b/gegl/opencl/gegl-cl-types.h
@@ -8,14 +8,27 @@
 #include <CL/cl_gl_ext.h>
 #include <CL/cl_ext.h>
 
-typedef cl_int (*t_clGetPlatformIDs)(cl_uint,
-                                     cl_platform_id *,
-                                     cl_uint *);
+typedef cl_int (*t_clGetPlatformIDs)  (cl_uint, cl_platform_id *, cl_uint *);
+typedef cl_int (*t_clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *);
+typedef cl_int (*t_clGetDeviceIDs)    (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *);
+typedef cl_int (*t_clGetDeviceInfo)   (cl_device_id, cl_device_info, size_t, void *, size_t *);
 
-typedef cl_int (*t_clGetPlatformInfo)(cl_platform_id,
-                                      cl_platform_info,
-                                      size_t,
-                                      void *,
-                                      size_t *);
+typedef cl_context        (*t_clCreateContext          ) (const cl_context_properties *, cl_uint, const cl_device_id *, void (CL_CALLBACK *) (const char *, const void *, size_t, void *), void *, cl_int *);
+typedef cl_command_queue  (*t_clCreateCommandQueue     ) (cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_int *errcode_ret);
+typedef cl_program        (*t_clCreateProgramWithSource) (cl_context, cl_uint, const char **, const size_t *, cl_int *);
+typedef cl_int            (*t_clBuildProgram           ) (cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK *)(cl_program, void *), void *);
+typedef cl_kernel         (*t_clCreateKernel           ) (cl_program, const char *, cl_int *);
+typedef cl_int            (*t_clSetKernelArg           ) (cl_kernel, cl_uint, size_t, const void *);
+typedef cl_int            (*t_clGetKernelWorkGroupInfo ) (cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void *, size_t *);
+typedef cl_mem            (*t_clCreateBuffer           ) (cl_context, cl_mem_flags, size_t, void *, cl_int *);
+typedef cl_int            (*t_clEnqueueWriteBuffer     ) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *);
+typedef cl_int            (*t_clEnqueueReadBuffer      ) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *);
+typedef cl_int            (*t_clEnqueueNDRangeKernel   ) (cl_command_queue, cl_kernel, cl_uint, const size_t *, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *);
+
+typedef cl_int (*t_clReleaseKernel      ) (cl_kernel);
+typedef cl_int (*t_clReleaseProgram     ) (cl_program);
+typedef cl_int (*t_clReleaseCommandQueue) (cl_command_queue);
+typedef cl_int (*t_clReleaseContext     ) (cl_context);
+typedef cl_int (*t_clReleaseMemObject   ) (cl_mem);
 
 #endif /* __GEGL_CL_TYPES_H__ */



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