aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-03-08 16:23:28 +0100
committerMichael Bien <[email protected]>2010-03-08 16:23:28 +0100
commit5ad19147a76f80635dcae18693929edbf1da2cbf (patch)
tree929896eab7d454edcb2267d9287d619600868250
parentc77d94f00de586f3ffa54312dd752650a6ff4d7b (diff)
moved utilities to util package.
several smaller improvements and doc fixes.
-rw-r--r--src/com/mbien/opencl/CLCommandQueue.java2
-rw-r--r--src/com/mbien/opencl/CLException.java2
-rw-r--r--src/com/mbien/opencl/CLInfoAccessor.java3
-rw-r--r--src/com/mbien/opencl/CLKernel.java15
-rw-r--r--src/com/mbien/opencl/CLPlatform.java3
-rw-r--r--src/com/mbien/opencl/CLProgram.java34
-rw-r--r--src/com/mbien/opencl/CLProgramBuilder.java2
-rw-r--r--src/com/mbien/opencl/CLSampler.java3
-rw-r--r--src/com/mbien/opencl/NativeLibLoader.java3
-rw-r--r--src/com/mbien/opencl/util/CLBuildConfiguration.java (renamed from src/com/mbien/opencl/CLBuildConfiguration.java)8
-rw-r--r--src/com/mbien/opencl/util/CLProgramConfiguration.java (renamed from src/com/mbien/opencl/CLProgramConfiguration.java)8
-rw-r--r--src/com/mbien/opencl/util/CLUtil.java (renamed from src/com/mbien/opencl/CLUtils.java)7
-rw-r--r--src/com/mbien/opencl/util/MultiQueueBarrier.java (renamed from src/com/mbien/opencl/MultiQueueBarrier.java)6
-rw-r--r--test/com/mbien/opencl/CLCommandQueueTest.java13
-rw-r--r--test/com/mbien/opencl/CLProgramTest.java2
-rw-r--r--test/com/mbien/opencl/LowLevelBindingTest.java13
16 files changed, 84 insertions, 40 deletions
diff --git a/src/com/mbien/opencl/CLCommandQueue.java b/src/com/mbien/opencl/CLCommandQueue.java
index a33593ad..e74ed7ba 100644
--- a/src/com/mbien/opencl/CLCommandQueue.java
+++ b/src/com/mbien/opencl/CLCommandQueue.java
@@ -9,7 +9,7 @@ import java.util.List;
import static com.mbien.opencl.CLException.*;
import static com.mbien.opencl.CL.*;
-import static com.mbien.opencl.CLUtils.*;
+import static com.mbien.opencl.util.CLUtil.*;
/**
* The command queue is used to queue a set of operations for a specific {@link CLDevice}.
diff --git a/src/com/mbien/opencl/CLException.java b/src/com/mbien/opencl/CLException.java
index baa187a5..63696a81 100644
--- a/src/com/mbien/opencl/CLException.java
+++ b/src/com/mbien/opencl/CLException.java
@@ -49,7 +49,7 @@ public class CLException extends RuntimeException {
specificEx.fillInStackTrace();
return specificEx;
}
- return new CLException(status, "unknown", "unknown cause: code" + status);
+ return new CLException(status, "unknown", "unknown cause: code " + status);
}
/**
diff --git a/src/com/mbien/opencl/CLInfoAccessor.java b/src/com/mbien/opencl/CLInfoAccessor.java
index d2e58f3d..316c1257 100644
--- a/src/com/mbien/opencl/CLInfoAccessor.java
+++ b/src/com/mbien/opencl/CLInfoAccessor.java
@@ -1,5 +1,6 @@
package com.mbien.opencl;
+import com.mbien.opencl.util.CLUtil;
import com.sun.gluegen.runtime.PointerBuffer;
import java.nio.Buffer;
import java.nio.ByteBuffer;
@@ -51,7 +52,7 @@ abstract class CLInfoAccessor {
byte[] array = new byte[clSize-1]; // last char is always null
buffer.get(array).rewind();
- return CLUtils.clString2JavaString(array, clSize);
+ return CLUtil.clString2JavaString(array, clSize);
}
diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java
index 696007ba..4b60cab9 100644
--- a/src/com/mbien/opencl/CLKernel.java
+++ b/src/com/mbien/opencl/CLKernel.java
@@ -1,5 +1,6 @@
package com.mbien.opencl;
+import com.mbien.opencl.util.CLUtil;
import com.sun.gluegen.runtime.BufferFactory;
import com.sun.gluegen.runtime.CPU;
import com.sun.gluegen.runtime.PointerBuffer;
@@ -17,6 +18,8 @@ import static com.mbien.opencl.CL.*;
* function declared in a program and the argument values to be used when executing this
* <code>kernel</code> function.
* CLKernel is not threadsafe.
+ * @see CLProgram#createCLKernel(java.lang.String)
+ * @see CLProgram#createCLKernels()
* @author Michael Bien
*/
public class CLKernel extends CLObject implements CLResource, Cloneable {
@@ -47,7 +50,7 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, bb.capacity(), bb, null);
checkForError(ret, "error while asking for kernel function name");
- this.name = CLUtils.clString2JavaString(bb, bb.capacity());
+ this.name = CLUtil.clString2JavaString(bb, bb.capacity());
// get number of arguments
ret = cl.clGetKernelInfo(ID, CL_KERNEL_NUM_ARGS, bb.capacity(), bb, null);
@@ -56,6 +59,11 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
numArgs = bb.getInt(0);
}
+
+// public CLKernel putArg(Buffer value) {
+// setArg(argIndex++, value);
+// return this;
+// }
public CLKernel putArg(CLMemory<?> value) {
setArg(argIndex++, value);
@@ -98,6 +106,11 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
return this;
}
+// public CLKernel setArg(int argumentIndex, Buffer value) {
+// setArgument(argumentIndex, CLMemory.sizeOfBufferElem(value)*value.capacity(), value);
+// return this;
+// }
+
public CLKernel setArg(int argumentIndex, CLMemory<?> value) {
setArgument(argumentIndex, CPU.is32Bit()?4:8, wrap(value.ID));
return this;
diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java
index 597878b3..76284dcf 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.util.CLUtil;
import com.mbien.opencl.impl.CLImpl;
import com.sun.gluegen.runtime.PointerBuffer;
import java.nio.ByteBuffer;
@@ -243,7 +244,7 @@ public final class CLPlatform {
int ret = cl.clGetPlatformInfo(ID, key, bb.capacity(), bb, pb);
checkForError(ret, "can not receive info string");
- return CLUtils.clString2JavaString(bb, (int)pb.get(0));
+ return CLUtil.clString2JavaString(bb, (int)pb.get(0));
}
@Override
diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java
index df556937..58071a59 100644
--- a/src/com/mbien/opencl/CLProgram.java
+++ b/src/com/mbien/opencl/CLProgram.java
@@ -1,5 +1,7 @@
package com.mbien.opencl;
+import com.mbien.opencl.util.CLProgramConfiguration;
+import com.mbien.opencl.util.CLUtil;
import com.sun.gluegen.runtime.BufferFactory;
import com.sun.gluegen.runtime.CPU;
import com.sun.gluegen.runtime.PointerBuffer;
@@ -25,6 +27,8 @@ import static com.mbien.opencl.CL.*;
* @author Michael Bien
*/
public class CLProgram extends CLObject implements CLResource {
+
+// private final static Object buildLock = new Object();
private final Set<CLKernel> kernels;
private Map<CLDevice, Status> buildStatusMap;
@@ -87,16 +91,18 @@ public class CLProgram extends CLObject implements CLResource {
private void initBuildStatus() {
if(buildStatusMap == null) {
- Map<CLDevice, Status> map = new HashMap<CLDevice, Status>();
- CLDevice[] devices = getCLDevices();
- for (CLDevice device : devices) {
- Status status = getBuildStatus(device);
- if(status == Status.BUILD_SUCCESS) {
- executable = true;
+// synchronized(buildLock) {
+ Map<CLDevice, Status> map = new HashMap<CLDevice, Status>();
+ CLDevice[] devices = getCLDevices();
+ for (CLDevice device : devices) {
+ Status status = getBuildStatus(device);
+ if(status == Status.BUILD_SUCCESS) {
+ executable = true;
+ }
+ map.put(device, status);
}
- map.put(device, status);
- }
- this.buildStatusMap = Collections.unmodifiableMap(map);
+ this.buildStatusMap = Collections.unmodifiableMap(map);
+// }
}
}
@@ -116,7 +122,7 @@ public class CLProgram extends CLObject implements CLResource {
ret = cl.clGetProgramBuildInfo(ID, device, flag, bb.capacity(), bb, null);
checkForError(ret, "on clGetProgramBuildInfo");
- return CLUtils.clString2JavaString(bb, (int)pb.get(0));
+ return CLUtil.clString2JavaString(bb, (int)pb.get(0));
}
private String getProgramInfoString(int flag) {
@@ -135,7 +141,7 @@ public class CLProgram extends CLObject implements CLResource {
ret = cl.clGetProgramInfo(ID, flag, bb.capacity(), bb, null);
checkForError(ret, "on clGetProgramInfo");
- return CLUtils.clString2JavaString(bb, (int)pb.get(0));
+ return CLUtil.clString2JavaString(bb, (int)pb.get(0));
}
// private int getProgramInfoInt(int flag) {
@@ -238,7 +244,11 @@ public class CLProgram extends CLObject implements CLResource {
executable = false;
// Build the program
- int ret = cl.clBuildProgram(ID, count, deviceIDs, options, null, null);
+ int ret = 0;
+ // building programs is not threadsafe
+// synchronized(buildLock) {
+ ret = cl.clBuildProgram(ID, count, deviceIDs, options, null, null);
+// }
if(ret != CL_SUCCESS) {
throw newException(ret, "\n"+getBuildLog());
diff --git a/src/com/mbien/opencl/CLProgramBuilder.java b/src/com/mbien/opencl/CLProgramBuilder.java
index 14300ef0..fea611a9 100644
--- a/src/com/mbien/opencl/CLProgramBuilder.java
+++ b/src/com/mbien/opencl/CLProgramBuilder.java
@@ -1,5 +1,7 @@
package com.mbien.opencl;
+import com.mbien.opencl.util.CLBuildConfiguration;
+import com.mbien.opencl.util.CLProgramConfiguration;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
diff --git a/src/com/mbien/opencl/CLSampler.java b/src/com/mbien/opencl/CLSampler.java
index 28b712a9..73e98013 100644
--- a/src/com/mbien/opencl/CLSampler.java
+++ b/src/com/mbien/opencl/CLSampler.java
@@ -5,10 +5,11 @@ import java.nio.Buffer;
import static com.mbien.opencl.CLException.*;
import static com.mbien.opencl.CL.*;
-import static com.mbien.opencl.CLUtils.*;
+import static com.mbien.opencl.util.CLUtil.*;
/**
* Object representing an OpenCL sampler.
+ * @see CLContext#createSampler(com.mbien.opencl.CLSampler.AddressingMode, com.mbien.opencl.CLSampler.FilteringMode, boolean)
* @author Michael Bien
*/
public class CLSampler extends CLObject implements CLResource {
diff --git a/src/com/mbien/opencl/NativeLibLoader.java b/src/com/mbien/opencl/NativeLibLoader.java
index b8148432..d6808dbc 100644
--- a/src/com/mbien/opencl/NativeLibLoader.java
+++ b/src/com/mbien/opencl/NativeLibLoader.java
@@ -10,9 +10,8 @@ import com.sun.nativewindow.impl.NativeLibLoaderBase;
*/
class NativeLibLoader extends NativeLibLoaderBase {
- @SuppressWarnings("unchecked")
public static void loadJOCL() {
- AccessController.doPrivileged(new PrivilegedAction() {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
loadLibrary("jocl", null, true);
return null;
diff --git a/src/com/mbien/opencl/CLBuildConfiguration.java b/src/com/mbien/opencl/util/CLBuildConfiguration.java
index 875f8d3a..e65a9f98 100644
--- a/src/com/mbien/opencl/CLBuildConfiguration.java
+++ b/src/com/mbien/opencl/util/CLBuildConfiguration.java
@@ -1,5 +1,7 @@
-package com.mbien.opencl;
+package com.mbien.opencl.util;
+import com.mbien.opencl.CLDevice;
+import com.mbien.opencl.CLProgram;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Map;
@@ -7,8 +9,8 @@ import java.util.Map;
/**
* Configuration representing everything needed to build an OpenCL program.
* @author Michael Bien
- * @see CLProgramBuilder#createConfiguration()
- * @see CLProgramBuilder#loadConfiguration(java.io.ObjectInputStream)
+ * @see com.mbien.opencl.CLProgramBuilder#createConfiguration()
+ * @see com.mbien.opencl.CLProgramBuilder#loadConfiguration(java.io.ObjectInputStream)
*/
public interface CLBuildConfiguration extends Cloneable {
diff --git a/src/com/mbien/opencl/CLProgramConfiguration.java b/src/com/mbien/opencl/util/CLProgramConfiguration.java
index 405b911d..105a4b72 100644
--- a/src/com/mbien/opencl/CLProgramConfiguration.java
+++ b/src/com/mbien/opencl/util/CLProgramConfiguration.java
@@ -1,5 +1,7 @@
-package com.mbien.opencl;
+package com.mbien.opencl.util;
+import com.mbien.opencl.CLDevice;
+import com.mbien.opencl.CLProgram;
import java.util.Map;
/**
@@ -7,8 +9,8 @@ import java.util.Map;
* CLProgramConfiguration is a helper for building programs with more complex configurations or
* building multiple programs with the similar configuration.
* @see CLProgram#prepare()
- * @see CLProgramBuilder#createConfiguration(com.mbien.opencl.CLProgram)
- * @see CLProgramBuilder#loadConfiguration(java.io.ObjectInputStream, com.mbien.opencl.CLContext)
+ * @see com.mbien.opencl.CLProgramBuilder#createConfiguration(com.mbien.opencl.CLProgram)
+ * @see com.mbien.opencl.CLProgramBuilder#loadConfiguration(java.io.ObjectInputStream, com.mbien.opencl.CLContext)
* @author Michael Bien
*/
public interface CLProgramConfiguration extends CLBuildConfiguration {
diff --git a/src/com/mbien/opencl/CLUtils.java b/src/com/mbien/opencl/util/CLUtil.java
index 8f89980e..f33451f3 100644
--- a/src/com/mbien/opencl/CLUtils.java
+++ b/src/com/mbien/opencl/util/CLUtil.java
@@ -1,5 +1,8 @@
-package com.mbien.opencl;
+package com.mbien.opencl.util;
+import com.mbien.opencl.CL;
+import com.mbien.opencl.CLDevice;
+import com.mbien.opencl.CLPlatform;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.LinkedHashMap;
@@ -9,7 +12,7 @@ import java.util.Map;
*
* @author Michael Bien
*/
-class CLUtils {
+public class CLUtil {
public static String clString2JavaString(byte[] chars, int clLength) {
return clLength==0 ? "" : new String(chars, 0, clLength-1);
diff --git a/src/com/mbien/opencl/MultiQueueBarrier.java b/src/com/mbien/opencl/util/MultiQueueBarrier.java
index 1158a446..a23ca9ad 100644
--- a/src/com/mbien/opencl/MultiQueueBarrier.java
+++ b/src/com/mbien/opencl/util/MultiQueueBarrier.java
@@ -1,5 +1,7 @@
-package com.mbien.opencl;
+package com.mbien.opencl.util;
+import com.mbien.opencl.CLCommandQueue;
+import com.mbien.opencl.CLEventList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -7,7 +9,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
- * A high-level utility to synchronize multiple {@link CLCommandQueue}s.
+ * An utility for synchronizing multiple concurrent {@link CLCommandQueue}s.
* @author Michael Bien
*/
public class MultiQueueBarrier {
diff --git a/test/com/mbien/opencl/CLCommandQueueTest.java b/test/com/mbien/opencl/CLCommandQueueTest.java
index 9b502263..66757348 100644
--- a/test/com/mbien/opencl/CLCommandQueueTest.java
+++ b/test/com/mbien/opencl/CLCommandQueueTest.java
@@ -1,5 +1,6 @@
package com.mbien.opencl;
+import com.mbien.opencl.util.MultiQueueBarrier;
import com.mbien.opencl.CLCommandQueue.Mode;
import com.mbien.opencl.CLMemory.Mem;
import java.io.IOException;
@@ -191,6 +192,8 @@ public class CLCommandQueueTest {
final CLCommandQueue queue1 = devices[0 ].createCommandQueue();
final CLCommandQueue queue2 = devices[secondDevice].createCommandQueue();
+ fillBuffer(clBufferC.buffer, 12345);
+
if (secondDevice > 0) {
System.out.println("using two devices");
}
@@ -206,8 +209,8 @@ public class CLCommandQueueTest {
fillBuffer(clBufferB1.buffer, 67890);
// System.out.println("C buffer");
- queue1.putWriteBuffer(clBufferA1, false) // write A
- .putWriteBuffer(clBufferB1, true); // write B
+ queue1.putWriteBuffer(clBufferA1, false) // write A
+ .putWriteBuffer(clBufferB1, false); // write B
// System.out.println("C args");
vectorAddKernel1.setArgs(clBufferA1, clBufferB1, clBufferC); // C = A+B
@@ -231,15 +234,15 @@ public class CLCommandQueueTest {
fillBuffer(clBufferB2.buffer, 67890);
// System.out.println("D buffer");
- queue2.putWriteBuffer(clBufferA2, false) // write A
- .putWriteBuffer(clBufferB2, true); // write B
+ queue2.putWriteBuffer(clBufferA2, false) // write A
+ .putWriteBuffer(clBufferB2, false); // write B
// System.out.println("D args");
vectorAddKernel2.setArgs(clBufferA2, clBufferB2, clBufferD); // D = A+B
// System.out.println("D kernels");
CLEventList events2 = new CLEventList(2);
- queue2.put1DRangeKernel(vectorAddKernel2, 0, elements, 256, events2)
+ queue2.put1DRangeKernel(vectorAddKernel2, 0, elements, groupSize, events2)
.putReadBuffer(clBufferD, false, events2);
barrier.waitFor(queue2, events2);
diff --git a/test/com/mbien/opencl/CLProgramTest.java b/test/com/mbien/opencl/CLProgramTest.java
index 647ba1cb..f46933c6 100644
--- a/test/com/mbien/opencl/CLProgramTest.java
+++ b/test/com/mbien/opencl/CLProgramTest.java
@@ -1,5 +1,7 @@
package com.mbien.opencl;
+import com.mbien.opencl.util.CLBuildConfiguration;
+import com.mbien.opencl.util.CLProgramConfiguration;
import com.mbien.opencl.CLProgram.Status;
import java.io.File;
import java.io.FileInputStream;
diff --git a/test/com/mbien/opencl/LowLevelBindingTest.java b/test/com/mbien/opencl/LowLevelBindingTest.java
index 78ca3555..935ba73c 100644
--- a/test/com/mbien/opencl/LowLevelBindingTest.java
+++ b/test/com/mbien/opencl/LowLevelBindingTest.java
@@ -12,7 +12,7 @@ import org.junit.Test;
import static org.junit.Assert.*;
import static java.lang.System.*;
import static com.mbien.opencl.TestUtils.*;
-import static com.mbien.opencl.CLUtils.*;
+import static com.mbien.opencl.util.CLUtil.*;
import static com.sun.gluegen.runtime.BufferFactory.*;
/**
@@ -52,13 +52,16 @@ public class LowLevelBindingTest {
@Test
public void contextlessTest() {
- System.out.println("low level tests temporary disabled");
-/*
+ out.println("low level tests temporary disabled");
out.println(" - - - lowLevelTest; contextless binding - - - ");
- int ret = CL.CL_SUCCESS;
- CL cl = CLPlatform.getLowLevelBinding();
+ CL cl = CLPlatform.getLowLevelCLInterface();
+
+ System.out.println(((CLImpl)cl).clGetExtensionFunctionAddress("clCreateFromGLBuffer").getLong());
+ System.out.println(((CLImpl)cl).clGetExtensionFunctionAddress("clEnqueueAcquireGLObjects").getLong());
+/*
+ int ret = CL.CL_SUCCESS;
int[] intBuffer = new int[1];
// find all available OpenCL platforms