aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-02-12 02:15:06 +0100
committerMichael Bien <[email protected]>2010-02-12 02:15:06 +0100
commita93e4532f9515f5b2c0d2c67a45db1236a29ab12 (patch)
tree71623ffb0c352481d0eaa816d3a842245a403121
parent3d033bfadaf569d2198de6ca5dfac855dc25ac35 (diff)
fixed bug in CL[GL]Context.create(..., device), added test.
CLKernel is now Cloneable.
-rw-r--r--resources/clImplCustomCode.java4
-rw-r--r--src/com/mbien/opencl/CLContext.java12
-rw-r--r--src/com/mbien/opencl/CLDevice.java4
-rw-r--r--src/com/mbien/opencl/CLGLContext.java16
-rw-r--r--src/com/mbien/opencl/CLKernel.java12
-rw-r--r--test/com/mbien/opencl/HighLevelBindingTest.java41
6 files changed, 75 insertions, 14 deletions
diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java
index 814bb219..e981fbcc 100644
--- a/resources/clImplCustomCode.java
+++ b/resources/clImplCustomCode.java
@@ -18,11 +18,11 @@
return this.clCreateContext0(
properties!=null?properties.getBuffer():null, BufferFactory.getDirectBufferByteOffset(properties),
- devices!=null?devices.getBuffer():null, BufferFactory.getDirectBufferByteOffset(devices),
+ devices!=null?devices.remaining():0, devices!=null?devices.getBuffer():null, BufferFactory.getDirectBufferByteOffset(devices),
null, null,
errcode_ret, BufferFactory.getDirectBufferByteOffset(errcode_ret) );
}
- private native long clCreateContext0(Object cl_context_properties, int props_offset, Object devices, int devices_offset, CreateContextCallback pfn_notify, Object userData, Object errcode_ret, int err_offset);
+ private native long clCreateContext0(Object cl_context_properties, int props_offset, int numDevices, Object devices, int devices_offset, CreateContextCallback pfn_notify, Object userData, Object errcode_ret, int err_offset);
public long clCreateContextFromType(PointerBuffer properties, long device_type, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret) {
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java
index e75aaddd..99322035 100644
--- a/src/com/mbien/opencl/CLContext.java
+++ b/src/com/mbien/opencl/CLContext.java
@@ -113,7 +113,7 @@ public class CLContext implements CLResource {
* Creates a context on the specified platform and with the specified
* device types.
*/
- private static final CLContext create(CLPlatform platform, CLDevice.Type... deviceTypes) {
+ public static final CLContext create(CLPlatform platform, CLDevice.Type... deviceTypes) {
long type = toDeviceBitmap(deviceTypes);
@@ -125,10 +125,16 @@ public class CLContext implements CLResource {
* Creates a context on the specified platform and with the specified
* devices.
*/
- private static final CLContext create(CLPlatform platform, CLDevice[] devices) {
+ public static final CLContext create(CLPlatform platform, CLDevice... devices) {
PointerBuffer properties = setupContextProperties(platform);
- return new CLContext(createContext(properties, devices));
+ CLContext context = new CLContext(createContext(properties, devices));
+ if(devices != null) {
+ for (int i = 0; i < devices.length; i++) {
+ devices[i].setContext(context);
+ }
+ }
+ return context;
}
protected static final long createContextFromType(PointerBuffer properties, long deviceType) {
diff --git a/src/com/mbien/opencl/CLDevice.java b/src/com/mbien/opencl/CLDevice.java
index c6134248..d6013166 100644
--- a/src/com/mbien/opencl/CLDevice.java
+++ b/src/com/mbien/opencl/CLDevice.java
@@ -72,6 +72,10 @@ public final class CLDevice {
CLContext getContext() {
return context;
}
+
+ void setContext(CLContext context) {
+ this.context = context;
+ }
/**
* Returns the name of this device.
diff --git a/src/com/mbien/opencl/CLGLContext.java b/src/com/mbien/opencl/CLGLContext.java
index a66772e7..a96891c0 100644
--- a/src/com/mbien/opencl/CLGLContext.java
+++ b/src/com/mbien/opencl/CLGLContext.java
@@ -39,6 +39,10 @@ public final class CLGLContext extends CLContext {
return create(glContext, platform, CLDevice.Type.ALL);
}
+ /**
+ * Creates a shared context on the specified platform and with the specified
+ * device types.
+ */
public static CLGLContext create(GLContext glContext, CLDevice.Type... deviceTypes) {
return create(glContext, null, deviceTypes);
}
@@ -55,7 +59,7 @@ public final class CLGLContext extends CLContext {
* Creates a shared context on the specified platform and with the specified
* device types.
*/
- private static final CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice.Type... deviceTypes) {
+ public static final CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice.Type... deviceTypes) {
long[] glID = new long[1];
PointerBuffer properties = setupContextProperties(glContext, platform, glID);
@@ -69,13 +73,19 @@ public final class CLGLContext extends CLContext {
* Creates a shared context on the specified platform and with the specified
* devices.
*/
- private static final CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice... devices) {
+ public static final CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice... devices) {
long[] glID = new long[1];
PointerBuffer properties = setupContextProperties(glContext, platform, glID);
long clID = createContext(properties, devices);
- return new CLGLContext(clID, glID[0]);
+ CLGLContext context = new CLGLContext(clID, glID[0]);
+ if(devices != null) {
+ for (int i = 0; i < devices.length; i++) {
+ devices[i].setContext(context);
+ }
+ }
+ return context;
}
diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java
index 7e2ee54e..eb817f14 100644
--- a/src/com/mbien/opencl/CLKernel.java
+++ b/src/com/mbien/opencl/CLKernel.java
@@ -19,7 +19,7 @@ import static com.mbien.opencl.CL.*;
* CLKernel is not threadsafe.
* @author Michael Bien
*/
-public class CLKernel implements CLResource/*, Cloneable*/ {
+public class CLKernel implements CLResource, Cloneable {
public final long ID;
public final String name;
@@ -228,11 +228,11 @@ public class CLKernel implements CLResource/*, Cloneable*/ {
}
/**
- * Returns a new instance of this kernel.
+ * Returns a new instance of this kernel with uninitialized arguments.
*/
-// @Override
-// public CLKernel clone() {
-// return program.createCLKernel(name);
-// }
+ @Override
+ public CLKernel clone() {
+ return program.createCLKernel(name).setForce32BitArgs(force32BitArgs);
+ }
}
diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java
index 9c0e2343..ec3586d7 100644
--- a/test/com/mbien/opencl/HighLevelBindingTest.java
+++ b/test/com/mbien/opencl/HighLevelBindingTest.java
@@ -107,6 +107,47 @@ public class HighLevelBindingTest {
}
@Test
+ public void createContextTest() {
+
+ out.println(" - - - highLevelTest; create context - - - ");
+
+ CLPlatform platform = CLPlatform.getDefault();
+ int deviceCount = platform.listCLDevices().length;
+ CLDevice firstDevice = platform.listCLDevices()[0];
+
+ CLContext c = CLContext.create();
+ assertNotNull(c);
+ assertEquals(deviceCount, c.getCLDevices().length);
+ c.release();
+
+ c = CLContext.create(platform);
+ assertNotNull(c);
+ assertEquals(deviceCount, c.getCLDevices().length);
+ c.release();
+
+ c = CLContext.create(firstDevice);
+ assertNotNull(c);
+ assertEquals(1, c.getCLDevices().length);
+ c.release();
+
+ c = CLContext.create(CLDevice.Type.ALL);
+ assertNotNull(c);
+ assertEquals(deviceCount, c.getCLDevices().length);
+ c.release();
+
+ c = CLContext.create(platform, firstDevice);
+ assertNotNull(c);
+ assertEquals(1, c.getCLDevices().length);
+ c.release();
+
+ c = CLContext.create(platform, CLDevice.Type.ALL);
+ assertNotNull(c);
+ assertEquals(deviceCount, c.getCLDevices().length);
+ c.release();
+
+ }
+
+ @Test
public void vectorAddGMTest() throws IOException {
out.println(" - - - highLevelTest; global memory kernel - - - ");