summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/mbien/opencl/CLContext.java')
-rw-r--r--src/com/mbien/opencl/CLContext.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java
new file mode 100644
index 00000000..dc3c7279
--- /dev/null
+++ b/src/com/mbien/opencl/CLContext.java
@@ -0,0 +1,45 @@
+package com.mbien.opencl;
+
+import com.mbien.opencl.impl.CLImpl;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class CLContext {
+
+ private final static CL cl;
+
+ static{
+ System.loadLibrary("gluegen-rt");
+ System.loadLibrary("jocl");
+ cl = new CLImpl();
+ }
+
+ /**
+ * Lists all available OpenCL implementaitons.
+ * @throws CLException if something went wrong initializing OpenCL
+ */
+ public static CLPlatform[] listCLPlatforms() {
+
+ int[] intBuffer = new int[1];
+ // find all available OpenCL platforms
+ int ret = cl.clGetPlatformIDs(0, null, 0, intBuffer, 0);
+ if(CL.CL_SUCCESS != ret)
+ throw new CLException(ret, "can not enumerate platforms");
+
+ // receive platform ids
+ long[] platformId = new long[intBuffer[0]];
+ ret = cl.clGetPlatformIDs(platformId.length, platformId, 0, null, 0);
+ if(CL.CL_SUCCESS != ret)
+ throw new CLException(ret, "can not enumerate platforms");
+
+ CLPlatform[] platforms = new CLPlatform[platformId.length];
+
+ for (int i = 0; i < platformId.length; i++)
+ platforms[i] = new CLPlatform(cl, platformId[i]);
+
+ return platforms;
+ }
+
+}