[gegl/gsoc2011-opencl: 6/14] 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: 6/14] OpenCL shared resources created in gegl_cl_init
- Date: Mon, 1 Aug 2011 20:33:40 +0000 (UTC)
commit 17b900c3b91d9368865333adef8df30e666d2c9d
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..aaf1bcc 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_INFO, "OpenCL: Platform Name:%s", buffer);
+ gegl_clGetPlatformInfo (platform, CL_PLATFORM_VERSION, sizeof(buffer), buffer, NULL);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "OpenCL: Version:%s", buffer);
+ gegl_clGetPlatformInfo (platform, CL_PLATFORM_EXTENSIONS, sizeof(buffer), buffer, NULL);
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "OpenCL: Extensions:%s", 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_INFO, "OpenCL: Default Device Name:%s", 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]