summaryrefslogtreecommitdiffstats
path: root/src/com/mbien
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-02-01 01:09:18 +0100
committerMichael Bien <[email protected]>2010-02-01 01:09:18 +0100
commite4e7dc4e7a63206c091cd3288adc6a7346f74191 (patch)
treeab2435f774da803489fd58612e6b1f22a3e46cee /src/com/mbien
parent2015fa5cd47b9be234f30e4b98d06b83486e4fb2 (diff)
trivial bugfixes, typo and javadoc warning fixes.
began to switch to gluegen's libloading infrastructure. added CL extensions accessors to CLPlatform. optimized isFooEnabled() methods for CLCommandQueue.
Diffstat (limited to 'src/com/mbien')
-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
8 files changed, 97 insertions, 11 deletions
diff --git a/src/com/mbien/opencl/CLCommandQueue.java b/src/com/mbien/opencl/CLCommandQueue.java
index d7586a93..0967a27b 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 e754a4bc..c6134248 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 3703f235..4ca216c4 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 b5551798..d2625f7f 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 cb03cf8e..0dc9db19 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 fc1b78f3..2f3cbf54 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 eb66a7a3..03fb559c 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 00000000..b8148432
--- /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;
+ }
+ });
+ }
+}