summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLPlatform.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-10-20 22:06:10 +0200
committerMichael Bien <[email protected]>2009-10-20 22:06:10 +0200
commitabe0135b4457d4c4ff722b0f39a47cad6c178f7e (patch)
treecba794c54c5cc0f9d005b8ab2d7781f739c01d07 /src/com/mbien/opencl/CLPlatform.java
parent7f2db980b303fa75f3830679ce65fe4ae41c30dc (diff)
refactored JOCLTest into LowLevelBindingTest and HighLevelBindingTest.
moved listCLPlatforms() and getLowLevelBinding() from CLContext to CLPlatform. added method to create CLPrograms from InputStreams and updated test.
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;
}
/**