aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nbproject/project.properties2
-rw-r--r--resources/cl-common.cfg7
-rw-r--r--resources/cl-impl.cfg4
-rw-r--r--resources/clImplCustomCode.java6
-rw-r--r--src/com/mbien/opencl/CLCommandQueue.java20
-rw-r--r--src/com/mbien/opencl/CLDevice.java11
-rw-r--r--src/com/mbien/opencl/CLException.java5
-rw-r--r--src/com/mbien/opencl/CLImageFormat.java2
-rw-r--r--src/com/mbien/opencl/CLKernel.java6
-rw-r--r--src/com/mbien/opencl/CLPlatform.java38
-rw-r--r--src/com/mbien/opencl/CLUtils.java4
-rw-r--r--src/com/mbien/opencl/NativeLibLoader.java22
-rw-r--r--test/com/mbien/opencl/CLConcurrencyTest.java4
-rw-r--r--test/com/mbien/opencl/HighLevelBindingTest.java4
14 files changed, 119 insertions, 16 deletions
diff --git a/nbproject/project.properties b/nbproject/project.properties
index eab4a1e..8622d80 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -40,7 +40,7 @@ javac.classpath=\
${file.reference.newt.all.jar}:\
${file.reference.nativewindow.all.jar}
# Space-separated list of extra javac options
-javac.compilerargs=
+javac.compilerargs=-Xlint
javac.deprecation=true
javac.source=1.5
javac.target=1.5
diff --git a/resources/cl-common.cfg b/resources/cl-common.cfg
index 6a42f30..79c2845 100644
--- a/resources/cl-common.cfg
+++ b/resources/cl-common.cfg
@@ -26,6 +26,10 @@ Ignore CL_LONG_MAX
Ignore CL_LONG_MIN
Ignore CL_ULONG_MAX
+
+#use CLException instead of RunTimeException
+RuntimeExceptionType CLException
+
#enforce client side "good behavior" by generating direct-memory-only bindings for
#performance critical functions.
#NioDirectOnly __ALL__
@@ -78,6 +82,7 @@ NioDirectOnly clWaitForEvents
#extensions
NioDirectOnly clGetGLContextInfoKHR
+
#common rename emitted struct accessors
#struct cl_image_format
RenameJavaType cl_image_format CLImageFormatImpl
@@ -87,10 +92,12 @@ StructPackage cl_image_format com.mbien.opencl.impl
RenameJavaMethod image_channel_order imageChannelOrder
RenameJavaMethod image_channel_data_type imageChannelDataType
+
ClassJavadoc CLImageFormatImpl /**
ClassJavadoc CLImageFormatImpl * Struct accessor for cl_image_format.
ClassJavadoc CLImageFormatImpl * @author Michael Bien
ClassJavadoc CLImageFormatImpl */
+
# Pick up on-line OpenCL doc and link it with the javadoc
TagNativeBinding true \ No newline at end of file
diff --git a/resources/cl-impl.cfg b/resources/cl-impl.cfg
index ec2718d..ac67e48 100644
--- a/resources/cl-impl.cfg
+++ b/resources/cl-impl.cfg
@@ -22,6 +22,10 @@ GetProcAddressTableExpr addressTable
ProcAddressNameExpr $UpperCase(arg)
ForceProcAddressGen clGetGLContextInfoKHR
+Unignore clGetExtensionFunctionAddress
+#AccessControl clGetExtensionFunctionAddress PACKAGE_PRIVATE
+ArgumentIsString clGetExtensionFunctionAddress 0
+
#append to generated c files
CustomCCode #include <CL/cl.h>
CustomCCode #include <GL3/gl3.h>
diff --git a/resources/clImplCustomCode.java b/resources/clImplCustomCode.java
index 6ee9193..814bb21 100644
--- a/resources/clImplCustomCode.java
+++ b/resources/clImplCustomCode.java
@@ -1,5 +1,9 @@
- CLProcAddressTable addressTable = new CLProcAddressTable();
+ final static CLProcAddressTable addressTable = new CLProcAddressTable();
+
+// static{
+// ProcAddressHelper.resetProcAddressTable(addressTable, );
+// }
public long clCreateContext(PointerBuffer properties, PointerBuffer devices, CreateContextCallback pfn_notify, Object userData, IntBuffer errcode_ret) {
diff --git a/src/com/mbien/opencl/CLCommandQueue.java b/src/com/mbien/opencl/CLCommandQueue.java
index d7586a9..0967a27 100644
--- a/src/com/mbien/opencl/CLCommandQueue.java
+++ b/src/com/mbien/opencl/CLCommandQueue.java
@@ -20,9 +20,11 @@ import static com.mbien.opencl.CL.*;
public class CLCommandQueue implements CLResource {
public final long ID;
+
private final CLContext context;
private final CLDevice device;
private final CL cl;
+ private long properties;
/*
* Those direct memory buffers are used to pass data between the JVM and OpenCL.
@@ -35,6 +37,7 @@ public class CLCommandQueue implements CLResource {
this.context = context;
this.cl = context.cl;
this.device = device;
+ this.properties = properties;
this.bufferA = PointerBuffer.allocateDirect(3);
this.bufferB = PointerBuffer.allocateDirect(3);
@@ -450,7 +453,7 @@ public class CLCommandQueue implements CLResource {
if(localWorkSizeX != 0 && localWorkSizeY !=0) {
localWorkSize = copy2NIO(bufferC, localWorkSizeX, localWorkSizeY);
}
- this.putNDRangeKernel(kernel, 2, globalWorkOffset, globalWorkSize, localWorkSize);
+ this.putNDRangeKernel(kernel, 2, globalWorkOffset, globalWorkSize, localWorkSize, events);
return this;
}
@@ -525,13 +528,26 @@ public class CLCommandQueue implements CLResource {
return this;
}
-
public CLCommandQueue finish() {
int ret = cl.clFinish(ID);
checkForError(ret, "can not finish command queue");
return this;
}
+ /**
+ * Returns true only when {@link Mode#PROFILING_MODE} has been enabled.
+ */
+ public boolean isProfilingEnabled() {
+ return (Mode.PROFILING_MODE.QUEUE_MODE & properties) != 0;
+ }
+
+ /**
+ * Returns true only when {@link Mode#OUT_OF_ORDER_EXEC_MODE} mode has been enabled.
+ */
+ public boolean isOutOfOrderModeEnabled() {
+ return (Mode.OUT_OF_ORDER_EXEC_MODE.QUEUE_MODE & properties) != 0;
+ }
+
public void release() {
int ret = cl.clReleaseCommandQueue(ID);
context.onCommandQueueReleased(device, this);
diff --git a/src/com/mbien/opencl/CLDevice.java b/src/com/mbien/opencl/CLDevice.java
index e754a4b..c613424 100644
--- a/src/com/mbien/opencl/CLDevice.java
+++ b/src/com/mbien/opencl/CLDevice.java
@@ -263,14 +263,14 @@ public final class CLDevice {
/**
* Returns the size of global memory cache line in bytes.
*/
- public long getGlobalMemCachlineSize() {
+ public long getGlobalMemCachelineSize() {
return deviceInfo.getLong(CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE);
}
/**
* Returns the size of global memory cache in bytes.
*/
- public long getGlobalMemCachSize() {
+ public long getGlobalMemCacheSize() {
return deviceInfo.getLong(CL_DEVICE_GLOBAL_MEM_CACHE_SIZE);
}
@@ -466,6 +466,13 @@ public final class CLDevice {
}
/**
+ * Returns true if the extension is supported on this device.
+ */
+ public boolean isExtensionAvailable(String extension) {
+ return getExtensions().contains(extension);
+ }
+
+ /**
* Returns all device extension names as unmodifiable Set.
*/
public Set<String> getExtensions() {
diff --git a/src/com/mbien/opencl/CLException.java b/src/com/mbien/opencl/CLException.java
index 3703f23..4ca216c 100644
--- a/src/com/mbien/opencl/CLException.java
+++ b/src/com/mbien/opencl/CLException.java
@@ -12,6 +12,11 @@ public class CLException extends RuntimeException {
private final static String ERROR_CODE_DOC = "http://www.khronos.org/opencl/sdk/1.0/docs/man/xhtml/errors.html";
+ public CLException(String message) {
+ super(message);
+ errorcode = 0;
+ }
+
public CLException(int error, String message) {
super(message + "\nerror: " + identifyError(error) + " (man page: "+ERROR_CODE_DOC+")");
errorcode = error;
diff --git a/src/com/mbien/opencl/CLImageFormat.java b/src/com/mbien/opencl/CLImageFormat.java
index b555179..d2625f7 100644
--- a/src/com/mbien/opencl/CLImageFormat.java
+++ b/src/com/mbien/opencl/CLImageFormat.java
@@ -172,7 +172,7 @@ public final class CLImageFormat {
/**
* Represents a normalized 5-6-5 3-channel RGB image. The channel order must
- * be {@link ChannelOrder#CL_RGB}.
+ * be {@link ChannelOrder#RGB}.
*/
UNORM_SHORT_565(CL_UNORM_SHORT_565),
diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java
index cb03cf8..0dc9db1 100644
--- a/src/com/mbien/opencl/CLKernel.java
+++ b/src/com/mbien/opencl/CLKernel.java
@@ -12,11 +12,11 @@ import static com.mbien.opencl.CL.*;
/**
* High level abstraction for an OpenCL Kernel.
- * CLKernel is not threadsafe.
- * "A kernel is a function declared in a program. A kernel is identified by the <code>kernel</code> qualifier
+ * A kernel is a function declared in a program. A kernel is identified by the <code>kernel</code> qualifier
* applied to any function in a program. A kernel object encapsulates the specific <code>kernel</code>
* function declared in a program and the argument values to be used when executing this
- * <code>kernel</code> function."
+ * <code>kernel</code> function.
+ * CLKernel is not threadsafe.
* @author Michael Bien
*/
public class CLKernel implements CLResource/*, Cloneable*/ {
diff --git a/src/com/mbien/opencl/CLPlatform.java b/src/com/mbien/opencl/CLPlatform.java
index fc1b78f..2f3cbf5 100644
--- a/src/com/mbien/opencl/CLPlatform.java
+++ b/src/com/mbien/opencl/CLPlatform.java
@@ -2,9 +2,14 @@ package com.mbien.opencl;
import com.mbien.opencl.impl.CLImpl;
import com.sun.gluegen.runtime.PointerBuffer;
+import com.sun.gluegen.runtime.ProcAddressHelper;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Scanner;
+import java.util.Set;
import static com.mbien.opencl.CLException.*;
import static com.mbien.opencl.CL.*;
@@ -22,9 +27,12 @@ public final class CLPlatform {
private static final CL cl;
+ private Set<String> extensions;
+
static{
- System.loadLibrary("gluegen-rt");
- System.loadLibrary("jocl");
+ NativeLibLoader.loadJOCL();
+// System.loadLibrary("gluegen-rt");
+// ProcAddressHelper.resetProcAddressTable(table, null);
cl = new CLImpl();
}
@@ -186,6 +194,32 @@ public final class CLPlatform {
}
/**
+ * Returns true if the extension is supported on this platform.
+ */
+ public boolean isExtensionAvailable(String extension) {
+ return getExtensions().contains(extension);
+ }
+
+ /**
+ * Returns all platform extension names as unmodifiable Set.
+ */
+ public Set<String> getExtensions() {
+
+ if(extensions == null) {
+ extensions = new HashSet<String>();
+ String ext = getInfoString(CL_PLATFORM_EXTENSIONS);
+ Scanner scanner = new Scanner(ext);
+
+ while(scanner.hasNext())
+ extensions.add(scanner.next());
+
+ extensions = Collections.unmodifiableSet(extensions);
+ }
+
+ return extensions;
+ }
+
+ /**
* Returns a info string in exchange for a key (CL_PLATFORM_*).
*/
public String getInfoString(int key) {
diff --git a/src/com/mbien/opencl/CLUtils.java b/src/com/mbien/opencl/CLUtils.java
index eb66a7a..03fb559 100644
--- a/src/com/mbien/opencl/CLUtils.java
+++ b/src/com/mbien/opencl/CLUtils.java
@@ -32,6 +32,7 @@ class CLUtils {
map.put("CL_PLATFORM_PROFILE", platform.getProfile());
map.put("CL_PLATFORM_VERSION", platform.getVersion());
map.put("CL_PLATFORM_VENDOR", platform.getVendor());
+ map.put("CL_PLATFORM_EXTENSIONS", platform.getExtensions().toString());
// map.put("fastest device (estimated)", platform.getMaxFlopsDevice().toString());
return map;
@@ -53,7 +54,8 @@ class CLUtils {
map.put("CL_DEVICE_MAX_PARAMETER_SIZE", dev.getMaxParameterSize()+" Byte");
map.put("CL_DEVICE_LOCAL_MEM_SIZE", dev.getLocalMemSize()/1024+" KB");
map.put("CL_DEVICE_LOCAL_MEM_TYPE", dev.getLocalMemType()+"");
- map.put("CL_DEVICE_GLOBAL_MEM_CACHE_SIZE", dev.getGlobalMemCachSize()+"");
+ map.put("CL_DEVICE_GLOBAL_MEM_CACHE_SIZE", dev.getGlobalMemCacheSize()+"");
+ map.put("CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE", dev.getGlobalMemCachelineSize()+"");
map.put("CL_DEVICE_GLOBAL_MEM_CACHE_TYPE", dev.getGlobalMemCacheType()+"");
map.put("CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE", dev.getMaxConstantBufferSize()+"");
map.put("CL_DEVICE_MAX_CONSTANT_ARGS", dev.getMaxConstantArgs()+"");
diff --git a/src/com/mbien/opencl/NativeLibLoader.java b/src/com/mbien/opencl/NativeLibLoader.java
new file mode 100644
index 0000000..b814843
--- /dev/null
+++ b/src/com/mbien/opencl/NativeLibLoader.java
@@ -0,0 +1,22 @@
+package com.mbien.opencl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import com.sun.nativewindow.impl.NativeLibLoaderBase;
+
+/**
+ *
+ * @author Michael Bien
+ */
+class NativeLibLoader extends NativeLibLoaderBase {
+
+ @SuppressWarnings("unchecked")
+ public static void loadJOCL() {
+ AccessController.doPrivileged(new PrivilegedAction() {
+ public Object run() {
+ loadLibrary("jocl", null, true);
+ return null;
+ }
+ });
+ }
+}
diff --git a/test/com/mbien/opencl/CLConcurrencyTest.java b/test/com/mbien/opencl/CLConcurrencyTest.java
index 94e8c4e..e7a244c 100644
--- a/test/com/mbien/opencl/CLConcurrencyTest.java
+++ b/test/com/mbien/opencl/CLConcurrencyTest.java
@@ -19,7 +19,7 @@ public class CLConcurrencyTest {
@Test
public void testEvents() throws IOException {
- out.println(" - - - event synchronisation test - - - ");
+ out.println(" - - - event synchronization test - - - ");
final int groupSize = 256;
final int elements = roundUp(groupSize, ONE_MB/SIZEOF_INT * 5); // 5MB per buffer
@@ -82,7 +82,7 @@ public class CLConcurrencyTest {
@Test
public void concurrencyTest() throws IOException, InterruptedException {
- out.println(" - - - queue synchronisation test - - - ");
+ out.println(" - - - QueueBarrier test - - - ");
final int elements = ONE_MB/SIZEOF_INT * 10; // 20MB per buffer
diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java
index 6ae9ac7..9c0e234 100644
--- a/test/com/mbien/opencl/HighLevelBindingTest.java
+++ b/test/com/mbien/opencl/HighLevelBindingTest.java
@@ -58,6 +58,7 @@ public class HighLevelBindingTest {
out.println(" version: "+platform.getVersion());
out.println(" vendor: "+platform.getVendor());
out.println(" max FLOPS device: "+platform.getMaxFlopsDevice());
+ out.println(" extensions: "+platform.getExtensions());
CLDevice[] clDevices = platform.listCLDevices();
for (CLDevice device : clDevices) {
@@ -74,7 +75,8 @@ public class HighLevelBindingTest {
out.println(" max param size: "+device.getMaxParameterSize()+" byte");
out.println(" local mem: "+device.getLocalMemSize()/1024+" KB");
out.println(" local mem type: "+device.getLocalMemType());
- out.println(" global mem cache size: "+device.getGlobalMemCachSize());
+ out.println(" global mem cache size: "+device.getGlobalMemCacheSize());
+ out.println(" global mem cacheline size: "+device.getGlobalMemCachelineSize());
out.println(" global mem cache type: "+device.getGlobalMemCacheType());
out.println(" constant buffer size: "+device.getMaxConstantBufferSize());
out.println(" error correction support: "+device.isErrorCorrectionSupported());