[gegl/gsoc2011-opencl: 1/14] Basic infrastucture for OpenCL. Dynamic loading of OpenCL libs using dlopen.
- From: Victor Matheus de Araujo Oliveira <vmaolive src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/gsoc2011-opencl: 1/14] Basic infrastucture for OpenCL. Dynamic loading of OpenCL libs using dlopen.
- Date: Fri, 20 May 2011 14:22:17 +0000 (UTC)
commit b2bc334ea27635b1073ec935066d8d2e201b8668
Author: victor matheus de araujo <victormatheus gmail com>
Date: Sun May 8 20:16:28 2011 -0300
Basic infrastucture for OpenCL. Dynamic loading of OpenCL libs using dlopen.
Signed-off-by: Victor Oliveira <victormatheus gmail com>
gegl/opencl/Makefile.am | 24 ++++++++++++++++++++++
gegl/opencl/gegl-cl-init.c | 45 +++++++++++++++++++++++++++++++++++++++++++
gegl/opencl/gegl-cl-init.h | 18 +++++++++++++++++
gegl/opencl/gegl-cl-types.h | 21 ++++++++++++++++++++
4 files changed, 108 insertions(+), 0 deletions(-)
---
diff --git a/gegl/opencl/Makefile.am b/gegl/opencl/Makefile.am
new file mode 100644
index 0000000..539b481
--- /dev/null
+++ b/gegl/opencl/Makefile.am
@@ -0,0 +1,24 @@
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_builddir)/gegl \
+ -I$(top_srcdir)/gegl \
+ -I$(top_builddir)/gegl/property-types \
+ -I$(top_srcdir)/gegl/property-types \
+ -I$(top_builddir)/gegl/buffer \
+ -I$(top_srcdir)/gegl/buffer
+
+AM_CFLAGS = $(DEP_CFLAGS) $(BABL_CFLAGS) $(OPENCL_CFLAGS)
+
+LIBS = $(OPENCL_LIBS)
+
+noinst_LTLIBRARIES = libcl.la
+
+#libcl_publicdir = $(includedir)/gegl-$(GEGL_API_VERSION)/gegl/cl
+#libcl_public_HEADERS = gegl-cl-init.h
+
+libcl_la_SOURCES = \
+ gegl-cl-init.c \
+ gegl-cl-init.h \
+ gegl-cl-types.h
+
+#libcl_la_SOURCES = $(libcl_sources) $(libcl_public_HEADERS)
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
new file mode 100644
index 0000000..9a9390e
--- /dev/null
+++ b/gegl/opencl/gegl-cl-init.c
@@ -0,0 +1,45 @@
+#define __GEGL_CL_INIT_MAIN__
+#include "gegl-cl-init.h"
+#undef __GEGL_CL_INIT_MAIN__
+
+#include <dlfcn.h>
+#include <stdio.h>
+
+static gboolean cl_is_accelerated = FALSE;
+
+gboolean
+gegl_cl_is_accelerated (void)
+{
+ return cl_is_accelerated;
+}
+
+#define CL_LOAD_FUNCTION(func) \
+gegl_##func = (t_##func) dlsym(handle, "#func"); \
+ \
+dlsym_error = dlerror(); \
+if (dlsym_error) \
+ { \
+ fprintf(stderr, "Cannot load symbol '%s': %s\n", "#func", dlsym_error); \
+ dlclose(handle); \
+ return; \
+ }
+
+void gegl_cl_init (void)
+{
+ void* handle = dlopen("libOpenCL.so", RTLD_LAZY);
+ const char *dlsym_error;
+
+ if (!handle) {
+ fprintf(stderr, "Cannot open library: %s\n", dlerror());
+ return;
+ }
+
+ CL_LOAD_FUNCTION (clGetPlatformIDs)
+ CL_LOAD_FUNCTION (clGetPlatformInfo)
+
+ cl_is_accelerated = TRUE;
+
+ return;
+}
+
+#undef CL_LOAD_FUNCTION
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
new file mode 100644
index 0000000..733d596
--- /dev/null
+++ b/gegl/opencl/gegl-cl-init.h
@@ -0,0 +1,18 @@
+#ifndef __GEGL_CL_INIT_H__
+#define __GEGL_CL_INIT_H__
+
+#include "gegl-cl-types.h"
+
+void gegl_cl_init (void);
+
+gboolean gegl_cl_is_accelerated (void);
+
+#ifdef __GEGL_CL_INIT_MAIN__
+t_clGetPlatformIDs gegl_clGetPlatformIDs = NULL;
+t_clGetPlatformInfo gegl_clGetPlatformInfo = NULL;
+#else
+extern t_clGetPlatformIDs gegl_clGetPlatformIDs;
+extern t_clGetPlatformInfo gegl_clGetPlatformInfo;
+#endif
+
+#endif /* __GEGL_CL_INIT_H__ */
diff --git a/gegl/opencl/gegl-cl-types.h b/gegl/opencl/gegl-cl-types.h
new file mode 100644
index 0000000..1182c4c
--- /dev/null
+++ b/gegl/opencl/gegl-cl-types.h
@@ -0,0 +1,21 @@
+#ifndef __GEGL_CL_TYPES_H__
+#define __GEGL_CL_TYPES_H__
+
+#include <glib-object.h>
+
+#include <CL/cl.h>
+#include <CL/cl_gl.h>
+#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_clGetPlatformInfo)(cl_platform_id,
+ cl_platform_info,
+ size_t,
+ void *,
+ size_t *);
+
+#endif /* __GEGL_CL_TYPES_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]