aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/mbien/opencl/CLContext.java13
-rw-r--r--src/com/mbien/opencl/CLDevice.java18
-rw-r--r--src/com/mbien/opencl/CLException.java5
-rw-r--r--test/com/mbien/opencl/JOCLTest.java130
4 files changed, 83 insertions, 83 deletions
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java
index 533d45d4..bcfb09a0 100644
--- a/src/com/mbien/opencl/CLContext.java
+++ b/src/com/mbien/opencl/CLContext.java
@@ -1,8 +1,6 @@
package com.mbien.opencl;
import com.mbien.opencl.impl.CLImpl;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import java.nio.IntBuffer;
/**
@@ -48,8 +46,8 @@ public final class CLContext {
type |= deviceTypes[i].CL_TYPE;
}
- long context = cl.clCreateContextFromType(null, 0, type, null, null, null, 0);
- return new CLContext(context);
+ long ctxID = cl.clCreateContextFromType(null, 0, type, null, null, null, 0);
+ return new CLContext(ctxID);
}
/**
@@ -124,4 +122,11 @@ public final class CLContext {
return platforms;
}
+ /**
+ * Returns the low level binding interface to the OpenCL APIs.
+ */
+ public static CL getLowLevelBinding() {
+ return cl;
+ }
+
}
diff --git a/src/com/mbien/opencl/CLDevice.java b/src/com/mbien/opencl/CLDevice.java
index 3db2511f..ba20f4b2 100644
--- a/src/com/mbien/opencl/CLDevice.java
+++ b/src/com/mbien/opencl/CLDevice.java
@@ -13,8 +13,6 @@ import java.util.Set;
*/
public final class CLDevice {
- //FIXME gluegen does not generate CL_DEVICE_TYPE_* remove hardcoded values ASAP
-
/**
* Enumeration for the type of a device.
*/
@@ -22,19 +20,19 @@ public final class CLDevice {
/**
* CL_DEVICE_TYPE_CPU
*/
- CPU(1 << 1),
+ CPU(CL.CL_DEVICE_TYPE_CPU),
/**
* CL_DEVICE_TYPE_GPU
*/
- GPU(1 << 2),
+ GPU(CL.CL_DEVICE_TYPE_GPU),
/**
* CL_DEVICE_TYPE_ACCELERATOR
*/
- ACCELERATOR(1 << 3),
+ ACCELERATOR(CL.CL_DEVICE_TYPE_ACCELERATOR),
/**
* CL_DEVICE_TYPE_DEFAULT
*/
- DEFAULT(1 << 0);
+ DEFAULT(CL.CL_DEVICE_TYPE_DEFAULT);
/**
* Value of wrapped OpenCL device type.
@@ -47,13 +45,13 @@ public final class CLDevice {
public static Type valueOf(int clDeviceType) {
switch(clDeviceType) {
- case(1 << 0):
+ case(CL.CL_DEVICE_TYPE_DEFAULT):
return DEFAULT;
- case(1 << 1):
+ case(CL.CL_DEVICE_TYPE_CPU):
return CPU;
- case(1 << 2):
+ case(CL.CL_DEVICE_TYPE_GPU):
return GPU;
- case(1 << 3):
+ case(CL.CL_DEVICE_TYPE_ACCELERATOR):
return ACCELERATOR;
}
return null;
diff --git a/src/com/mbien/opencl/CLException.java b/src/com/mbien/opencl/CLException.java
index c81dc039..e8ed771f 100644
--- a/src/com/mbien/opencl/CLException.java
+++ b/src/com/mbien/opencl/CLException.java
@@ -19,11 +19,10 @@ public class CLException extends RuntimeException {
}
public CLException(int error, String message) {
- super(resolveError(error) + ": " + message);
+ super(identifyError(error) + ": " + message);
}
-
- private static final String resolveError(int error) {
+ private static final String identifyError(int error) {
switch (error) {
case CL.CL_INVALID_VALUE:
diff --git a/test/com/mbien/opencl/JOCLTest.java b/test/com/mbien/opencl/JOCLTest.java
index 89292320..0eccf430 100644
--- a/test/com/mbien/opencl/JOCLTest.java
+++ b/test/com/mbien/opencl/JOCLTest.java
@@ -1,16 +1,15 @@
package com.mbien.opencl;
-import com.mbien.opencl.impl.CLImpl;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
+import static java.lang.System.*;
/**
- *
+ * Test for testing basic functionality.
* @author Michael Bien
*/
public class JOCLTest {
@@ -18,60 +17,16 @@ public class JOCLTest {
public JOCLTest() {
}
- @Before
- public void setUpClass() throws Exception {
- }
-
- @After
- public void tearDownClass() throws Exception {
- }
-
-// @Test
- public void highLevelTest() {
- System.out.println(" - - - highLevelTest - - - ");
-
- CLPlatform[] clPlatforms = CLContext.listCLPlatforms();
-
- for (CLPlatform platform : clPlatforms) {
-
- System.out.println("platform info:");
- System.out.println("name: "+platform.getName());
- System.out.println("profile: "+platform.getProfile());
- System.out.println("version: "+platform.getVersion());
- System.out.println("vendor: "+platform.getVendor());
-
- CLDevice[] clDevices = platform.listCLDevices();
- for (CLDevice device : clDevices) {
- System.out.println("device info:");
- System.out.println("name: "+device.getName());
- System.out.println("profile: "+device.getProfile());
- System.out.println("vendor: "+device.getVendor());
- System.out.println("type: "+device.getType());
- System.out.println("global mem: "+device.getGlobalMemSize()/(1024*1024)+" MB");
- System.out.println("local mem: "+device.getLocalMemSize()/1024+" KB");
- System.out.println("clock: "+device.getMaxClockFrequency()+" MHz");
- System.out.println("max work group size: "+device.getMaxWorkGroupSize());
- System.out.println("max compute units: "+device.getMaxComputeUnits());
- System.out.println("extensions: "+device.getExtensions());
- }
- }
-
-
- CLContext ctx = CLContext.create();
- CLDevice device = ctx.getMaxFlopsDevice();
- System.out.println("max FLOPS device: " + device);
- ctx.release();
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ out.println("OS: " + System.getProperty("os.name"));
+ out.println("VM: " + System.getProperty("java.vm.name"));
}
@Test
public void lowLevelTest() {
- System.out.println(" - - - lowLevelTest - - - ");
- // already loaded
- System.out.print("loading native libs...");
- System.loadLibrary("gluegen-rt");
- System.loadLibrary("jocl");
- System.out.println("done");
+ out.println(" - - - lowLevelTest - - - ");
CreateContextCallback cb = new CreateContextCallback() {
@Override
@@ -80,17 +35,17 @@ public class JOCLTest {
}
};
- System.out.println("creating OpenCL context");
+ out.println("creating OpenCL context");
int ret = 0;
- CL cl = new CLImpl();
+ CL cl = CLContext.getLowLevelBinding();
int[] intBuffer = new int[1];
// find all available OpenCL platforms
ret = cl.clGetPlatformIDs(0, null, 0, intBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println("#platforms: "+intBuffer[0]);
+ out.println("#platforms: "+intBuffer[0]);
long[] platformId = new long[intBuffer[0]];
ret = cl.clGetPlatformIDs(platformId.length, platformId, 0, null, 0);
@@ -104,28 +59,28 @@ public class JOCLTest {
for (int i = 0; i < platformId.length; i++) {
long platform = platformId[i];
- System.out.println("platform id: "+platform);
+ out.println("platform id: "+platform);
ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_PROFILE, bb.capacity(), bb, longBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println(" profile: "+new String(bb.array(), 0, (int)longBuffer[0]));
+ out.println(" profile: "+new String(bb.array(), 0, (int)longBuffer[0]));
ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_VERSION, bb.capacity(), bb, longBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println(" version: "+new String(bb.array(), 0, (int)longBuffer[0]));
+ out.println(" version: "+new String(bb.array(), 0, (int)longBuffer[0]));
ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_NAME, bb.capacity(), bb, longBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println(" name: "+new String(bb.array(), 0, (int)longBuffer[0]));
+ out.println(" name: "+new String(bb.array(), 0, (int)longBuffer[0]));
ret = cl.clGetPlatformInfo(platform, CL.CL_PLATFORM_VENDOR, bb.capacity(), bb, longBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println(" vendor: "+new String(bb.array(), 0, (int)longBuffer[0]));
+ out.println(" vendor: "+new String(bb.array(), 0, (int)longBuffer[0]));
//find all devices
ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, 0, null, 0, intBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println("#devices: "+intBuffer[0]);
+ out.println("#devices: "+intBuffer[0]);
long[] devices = new long[intBuffer[0]];
ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, devices.length, devices, 0, null, 0);
@@ -135,11 +90,11 @@ public class JOCLTest {
long device = devices[j];
ret = cl.clGetDeviceInfo(device, CL.CL_DEVICE_NAME, bb.capacity(), bb, longBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println(" device: "+new String(bb.array(), 0, (int)longBuffer[0]));
+ out.println(" device: "+new String(bb.array(), 0, (int)longBuffer[0]));
ret = cl.clGetDeviceInfo(device, CL.CL_DEVICE_TYPE, bb.capacity(), bb, longBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println(" type: " + CLDevice.Type.valueOf(bb.get()));
+ out.println(" type: " + CLDevice.Type.valueOf(bb.get()));
bb.rewind();
}
@@ -149,15 +104,58 @@ public class JOCLTest {
Arrays.fill(longBuffer, 0);
long context = cl.clCreateContextFromType(null, 0, CL.CL_DEVICE_TYPE_ALL, cb, null, null, 0);
- System.out.println("context handle: "+context);
+ out.println("context handle: "+context);
ret = cl.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, 0, null, longBuffer, 0);
assertEquals(CL.CL_SUCCESS, ret);
- System.out.println("CL_CONTEXT_DEVICES result: "+longBuffer[0]);
+ out.println("CL_CONTEXT_DEVICES result: "+longBuffer[0]);
+
+ ret = cl.clGetContextInfo(context, CL.CL_CONTEXT_NUM_DEVICES, 0, null, longBuffer, 0);
+ assertEquals(CL.CL_SUCCESS, ret);
+
+ out.println("CL_CONTEXT_NUM_DEVICES result: "+longBuffer[0]);
cl.clReleaseContext(context);
}
+ @Test
+ public void highLevelTest() {
+
+ out.println(" - - - highLevelTest - - - ");
+
+ CLPlatform[] clPlatforms = CLContext.listCLPlatforms();
+
+ for (CLPlatform platform : clPlatforms) {
+
+ out.println("platform info:");
+ out.println(" name: "+platform.getName());
+ out.println(" profile: "+platform.getProfile());
+ out.println(" version: "+platform.getVersion());
+ out.println(" vendor: "+platform.getVendor());
+
+ CLDevice[] clDevices = platform.listCLDevices();
+ for (CLDevice device : clDevices) {
+ out.println("device info:");
+ out.println(" name: "+device.getName());
+ out.println(" profile: "+device.getProfile());
+ out.println(" vendor: "+device.getVendor());
+ out.println(" type: "+device.getType());
+ out.println(" global mem: "+device.getGlobalMemSize()/(1024*1024)+" MB");
+ out.println(" local mem: "+device.getLocalMemSize()/1024+" KB");
+ out.println(" clock: "+device.getMaxClockFrequency()+" MHz");
+ out.println(" max work group size: "+device.getMaxWorkGroupSize());
+ out.println(" max compute units: "+device.getMaxComputeUnits());
+ out.println(" extensions: "+device.getExtensions());
+ }
+ }
+
+
+ CLContext ctx = CLContext.create();
+// CLDevice device = ctx.getMaxFlopsDevice();
+// out.println("max FLOPS device: " + device);
+ ctx.release();
+ }
+
} \ No newline at end of file