aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLPlatform.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/mbien/opencl/CLPlatform.java')
-rw-r--r--src/com/mbien/opencl/CLPlatform.java43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java
index dde9994b..56ef3713 100644
--- a/src/com/mbien/opencl/CLPlatform.java
+++ b/src/com/mbien/opencl/CLPlatform.java
@@ -1,5 +1,6 @@
package com.mbien.opencl;
+import com.mbien.opencl.impl.CLImpl;
import java.nio.ByteBuffer;
import static com.mbien.opencl.CLException.*;
/**
@@ -13,11 +14,47 @@ public final class CLPlatform {
*/
public final long ID;
- private final CL cl;
+ private static final CL cl;
- CLPlatform(CL cl, long id) {
+ static{
+ System.loadLibrary("gluegen-rt");
+ System.loadLibrary("jocl");
+ cl = new CLImpl();
+ }
+
+ CLPlatform(long id) {
this.ID = id;
- this.cl = cl;
+ }
+
+ /**
+ * 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);
+ checkForError(ret, "can not enumerate platforms");
+
+ // receive platform ids
+ long[] platformId = new long[intBuffer[0]];
+ ret = cl.clGetPlatformIDs(platformId.length, platformId, 0, null, 0);
+ checkForError(ret, "can not enumerate platforms");
+
+ CLPlatform[] platforms = new CLPlatform[platformId.length];
+
+ for (int i = 0; i < platformId.length; i++)
+ platforms[i] = new CLPlatform(platformId[i]);
+
+ return platforms;
+ }
+
+ /**
+ * Returns the low level binding interface to the OpenCL APIs.
+ */
+ public static CL getLowLevelBinding() {
+ return cl;
}
/**