diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/mbien/opencl/CLCommandQueue.java | 2 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLException.java | 2 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLInfoAccessor.java | 3 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLKernel.java | 15 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLPlatform.java | 3 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLProgram.java | 34 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLProgramBuilder.java | 2 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLSampler.java | 3 | ||||
-rw-r--r-- | src/com/mbien/opencl/NativeLibLoader.java | 3 | ||||
-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 |
13 files changed, 66 insertions, 30 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 { |