summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLPlatform.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-09-30 17:59:22 +0200
committerMichael Bien <[email protected]>2009-09-30 17:59:22 +0200
commita550876d23b84427667111c5e2700766752b6040 (patch)
treede61e1605ebb782625437f1b8e5888ca54ae6862 /src/com/mbien/opencl/CLPlatform.java
parent5db5f6ac97894bcb9804e4bfcc4607cfdae637a6 (diff)
started with high level abstraction.
Diffstat (limited to 'src/com/mbien/opencl/CLPlatform.java')
-rw-r--r--src/com/mbien/opencl/CLPlatform.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java
new file mode 100644
index 00000000..582e8abc
--- /dev/null
+++ b/src/com/mbien/opencl/CLPlatform.java
@@ -0,0 +1,96 @@
+package com.mbien.opencl;
+
+import java.nio.ByteBuffer;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class CLPlatform {
+
+ private final long platformID;
+ private final CL cl;
+
+ CLPlatform(CL cl, long id) {
+ this.platformID = id;
+ this.cl = cl;
+ }
+
+ public CLDevice[] listCLDevices() {
+
+ int[] intBuffer = new int[1];
+
+ //find all devices
+ int ret = cl.clGetDeviceIDs(platformID, CL.CL_DEVICE_TYPE_ALL, 0, null, 0, intBuffer, 0);
+ if(CL.CL_SUCCESS != ret)
+ throw new CLException(ret, "error while enumerating devices");
+
+ long[] deviceIDs = new long[intBuffer[0]];
+ ret = cl.clGetDeviceIDs(platformID, CL.CL_DEVICE_TYPE_ALL, deviceIDs.length, deviceIDs, 0, null, 0);
+ if(CL.CL_SUCCESS != ret)
+ throw new CLException(ret, "error while enumerating devices");
+
+ CLDevice[] devices = new CLDevice[deviceIDs.length];
+
+ //print device info
+ for (int i = 0; i < deviceIDs.length; i++)
+ devices[i] = new CLDevice(cl, deviceIDs[i]);
+
+ return devices;
+
+ }
+
+ /**
+ * Returns the platform name.
+ */
+ public String getName() {
+ return getInfoString(CL.CL_PLATFORM_NAME);
+ }
+
+ /**
+ * Returns the platform version.
+ */
+ public String getVersion() {
+ return getInfoString(CL.CL_PLATFORM_VERSION);
+ }
+
+ /**
+ * Returns the platform profile.
+ */
+ public String getProfile() {
+ return getInfoString(CL.CL_PLATFORM_PROFILE);
+ }
+
+ /**
+ * Returns the platform vendor.
+ */
+ public String getVendor() {
+ return getInfoString(CL.CL_PLATFORM_VENDOR);
+ }
+
+ /**
+ * Returns a info string in exchange for a key (CL_PLATFORM_*).
+ */
+ public String getInfoString(int key) {
+ long[] longBuffer = new long[1];
+ ByteBuffer bb = ByteBuffer.allocate(512);
+
+ int ret = cl.clGetPlatformInfo(platformID, key, bb.capacity(), bb, longBuffer, 0);
+ if(CL.CL_SUCCESS != ret)
+ throw new CLException(ret, "can not receive info string");
+
+ return new String(bb.array(), 0, (int)longBuffer[0]);
+ }
+
+ @Override
+ public String toString() {
+ return "CLPlatform [name:" + getName()
+ +" vendor:"+getVendor()
+ +" profile:"+getProfile()
+ +" version:"+getVersion()+"]";
+ }
+
+
+
+
+}