[gegl/gsoc2011-opencl_3: 6/10] OpenCL shared resources created in gegl_cl_init
- From: Victor Matheus de Araujo Oliveira <vmaolive src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/gsoc2011-opencl_3: 6/10] OpenCL shared resources created in gegl_cl_init
- Date: Sat, 2 Jul 2011 04:48:55 +0000 (UTC)
commit 5d942906233cb444412e073af7cef9a1d1b60374
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 | 44 ++++++++++++++++++++++++++++++++++++++++++++
gegl/opencl/gegl-cl-init.h | 16 ++++++++++++++++
2 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index f664a06..46e97d4 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -61,12 +61,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)) \
{ \
@@ -131,6 +160,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 cf4e5c3..c9dcbeb 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -4,12 +4,28 @@
#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)); \
+}
+
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]