aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/jogamp/opencl/CLDevice.java13
-rw-r--r--src/com/jogamp/opencl/CLEvent.java7
-rw-r--r--src/com/jogamp/opencl/CLImage.java4
-rw-r--r--src/com/jogamp/opencl/CLPlatform.java37
-rw-r--r--src/com/jogamp/opencl/CLSampler.java3
-rw-r--r--src/com/jogamp/opencl/CLTLInfoAccessor.java (renamed from src/com/jogamp/opencl/CLInfoAccessor.java)8
-rw-r--r--src/com/jogamp/opencl/spi/CLInfoAccessor.java25
-rw-r--r--src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java14
8 files changed, 89 insertions, 22 deletions
diff --git a/src/com/jogamp/opencl/CLDevice.java b/src/com/jogamp/opencl/CLDevice.java
index 0381038e..84a27f33 100644
--- a/src/com/jogamp/opencl/CLDevice.java
+++ b/src/com/jogamp/opencl/CLDevice.java
@@ -30,6 +30,7 @@ package com.jogamp.opencl;
import com.jogamp.opencl.util.CLUtil;
import com.jogamp.common.nio.NativeSizeBuffer;
+import com.jogamp.opencl.spi.CLInfoAccessor;
import java.nio.Buffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
@@ -51,11 +52,11 @@ import static com.jogamp.opencl.CL.*;
* @see CLContext#getMaxFlopsDevice(com.jogamp.opencl.CLDevice.Type)
* @author Michael Bien
*/
-public final class CLDevice extends CLObject {
+public class CLDevice extends CLObject {
private Set<String> extensions;
- private final CLDeviceInfoAccessor deviceInfo;
+ private final CLInfoAccessor deviceInfo;
private final CLPlatform platform;
CLDevice(CL cl, CLPlatform platform, long id) {
@@ -64,6 +65,12 @@ public final class CLDevice extends CLObject {
this.deviceInfo = new CLDeviceInfoAccessor(cl, id);
}
+ protected CLDevice(CL cl, CLPlatform platform, CLInfoAccessor deviceAccessor, long id) {
+ super(cl, id);
+ this.platform = platform;
+ this.deviceInfo = deviceAccessor;
+ }
+
CLDevice(CLContext context, long id) {
super(context, id);
this.platform = context.getPlatform();
@@ -691,7 +698,7 @@ public final class CLDevice extends CLObject {
return CLUtil.obtainDeviceProperties(this);
}
- private final static class CLDeviceInfoAccessor extends CLInfoAccessor {
+ private final static class CLDeviceInfoAccessor extends CLTLInfoAccessor {
private final CL cl;
private final long ID;
diff --git a/src/com/jogamp/opencl/CLEvent.java b/src/com/jogamp/opencl/CLEvent.java
index 876be3da..a48e4fef 100644
--- a/src/com/jogamp/opencl/CLEvent.java
+++ b/src/com/jogamp/opencl/CLEvent.java
@@ -64,12 +64,13 @@ public class CLEvent extends CLObject implements CLResource {
// apparently only ExecutionStatus.COMPLETE is allowed -> private
private void registerCallback(final CLEventListener callback, ExecutionStatus trigger) {
cl.clSetEventCallback(ID, trigger.STATUS, new CLEventCallback() {
- public void eventStateChanged(long event, int status) {
+ @Override public void eventStateChanged(long event, int status) {
callback.eventStateChanged(CLEvent.this, status);
}
});
}
+ @Override
public void release() {
int ret = cl.clReleaseEvent(ID);
checkForError(ret, "can not release event");
@@ -138,7 +139,7 @@ public class CLEvent extends CLObject implements CLResource {
- private class CLEventInfoAccessor extends CLInfoAccessor {
+ private class CLEventInfoAccessor extends CLTLInfoAccessor {
@Override
protected int getInfo(int name, long valueSize, Buffer value, NativeSizeBuffer valueSizeRet) {
@@ -147,7 +148,7 @@ public class CLEvent extends CLObject implements CLResource {
}
- private class CLEventProfilingInfoAccessor extends CLInfoAccessor {
+ private class CLEventProfilingInfoAccessor extends CLTLInfoAccessor {
@Override
protected int getInfo(int name, long valueSize, Buffer value, NativeSizeBuffer valueSizeRet) {
diff --git a/src/com/jogamp/opencl/CLImage.java b/src/com/jogamp/opencl/CLImage.java
index 01dd6ea2..48f3934f 100644
--- a/src/com/jogamp/opencl/CLImage.java
+++ b/src/com/jogamp/opencl/CLImage.java
@@ -41,7 +41,7 @@ public abstract class CLImage<B extends Buffer> extends CLMemory<B> {
protected CLImageFormat format;
- final CLInfoAccessor imageInfo;
+ final CLTLInfoAccessor imageInfo;
public final int width;
public final int height;
@@ -100,7 +100,7 @@ public abstract class CLImage<B extends Buffer> extends CLMemory<B> {
}
- protected final static class CLImageInfoAccessor extends CLInfoAccessor {
+ protected final static class CLImageInfoAccessor extends CLTLInfoAccessor {
private final long id;
private final CL cl;
diff --git a/src/com/jogamp/opencl/CLPlatform.java b/src/com/jogamp/opencl/CLPlatform.java
index ee6a6bdf..684f006b 100644
--- a/src/com/jogamp/opencl/CLPlatform.java
+++ b/src/com/jogamp/opencl/CLPlatform.java
@@ -30,18 +30,18 @@ package com.jogamp.opencl;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.os.DynamicLookupHelper;
-import java.nio.Buffer;
-import java.security.PrivilegedAction;
import com.jogamp.common.JogampRuntimeException;
import com.jogamp.common.os.NativeLibrary;
import com.jogamp.common.nio.NativeSizeBuffer;
import com.jogamp.gluegen.runtime.FunctionAddressResolver;
+import com.jogamp.opencl.spi.CLPlatformInfoAccessor;
import com.jogamp.opencl.util.CLUtil;
import com.jogamp.opencl.impl.CLImpl;
import com.jogamp.opencl.impl.CLProcAddressTable;
import com.jogamp.opencl.util.Filter;
import com.jogamp.opencl.util.JOCLVersion;
+import java.nio.Buffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.Collections;
@@ -50,6 +50,7 @@ import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
+import java.security.PrivilegedAction;
import static java.security.AccessController.*;
import static com.jogamp.opencl.CLException.*;
@@ -90,7 +91,7 @@ import static com.jogamp.opencl.CL.*;
* @see #getDefault()
* @see #listCLPlatforms()
*/
-public final class CLPlatform {
+public class CLPlatform {
/**
* OpenCL platform id for this platform.
@@ -102,16 +103,23 @@ public final class CLPlatform {
*/
public final CLVersion version;
- private static CL cl;
+ protected static CL cl;
private Set<String> extensions;
- private final CLPlatformInfoAccessor info;
+ protected final CLPlatformInfoAccessor info;
private CLPlatform(long id) {
initialize();
this.ID = id;
- this.info = new CLPlatformInfoAccessor(id, cl);
+ this.info = new CLTLPlatformInfoAccessor(id, cl);
+ this.version = new CLVersion(getInfoString(CL_PLATFORM_VERSION));
+ }
+
+ protected CLPlatform(long id, CLPlatformInfoAccessor accessor) {
+ initialize();
+ this.ID = id;
+ this.info = accessor;
this.version = new CLVersion(getInfoString(CL_PLATFORM_VERSION));
}
@@ -128,6 +136,7 @@ public final class CLPlatform {
try {
final CLProcAddressTable table = new CLProcAddressTable(new FunctionAddressResolver() {
+ @Override
public long resolve(String name, DynamicLookupHelper lookup) {
//FIXME workaround to fix a gluegen issue
@@ -150,6 +159,7 @@ public final class CLPlatform {
//load JOCL and init table
doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
NativeLibrary libOpenCL = JOCLJNILibLoader.loadOpenCL();
@@ -284,7 +294,7 @@ public final class CLPlatform {
//add device to list
for (int n = 0; n < deviceIDs.length; n++) {
- list.add(new CLDevice(cl, this, deviceIDs[n]));
+ list.add(createDevice(deviceIDs[n]));
}
}
@@ -304,7 +314,7 @@ public final class CLPlatform {
//add device to list
for (int n = 0; n < deviceIDs.length; n++) {
- CLDevice device = new CLDevice(cl, this, deviceIDs[n]);
+ CLDevice device = createDevice(deviceIDs[n]);
addIfAccepted(device, list, filters);
}
@@ -312,6 +322,10 @@ public final class CLPlatform {
}
+ protected CLDevice createDevice(long id) {
+ return new CLDevice(cl, this, id);
+ }
+
private static <I> void addIfAccepted(I item, List<I> list, Filter<I>[] filters) {
if(filters == null) {
list.add(item);
@@ -489,16 +503,16 @@ public final class CLPlatform {
/**
* Returns a info string in exchange for a key (CL_PLATFORM_*).
*/
- public String getInfoString(int key) {
+ public final String getInfoString(int key) {
return info.getString(key);
}
- private final static class CLPlatformInfoAccessor extends CLInfoAccessor {
+ private final static class CLTLPlatformInfoAccessor extends CLTLInfoAccessor implements CLPlatformInfoAccessor {
private final long ID;
private final CL cl;
- private CLPlatformInfoAccessor(long id, CL cl) {
+ private CLTLPlatformInfoAccessor(long id, CL cl) {
this.ID = id;
this.cl = cl;
}
@@ -508,6 +522,7 @@ public final class CLPlatform {
return cl.clGetPlatformInfo(ID, name, valueSize, value, valueSizeRet);
}
+ @Override
public long[] getDeviceIDs(long type) {
IntBuffer buffer = getBB(4).asIntBuffer();
diff --git a/src/com/jogamp/opencl/CLSampler.java b/src/com/jogamp/opencl/CLSampler.java
index f215cab1..63e25cb4 100644
--- a/src/com/jogamp/opencl/CLSampler.java
+++ b/src/com/jogamp/opencl/CLSampler.java
@@ -73,6 +73,7 @@ public class CLSampler extends CLObject implements CLResource {
return samplerInfo.getLong(CL_SAMPLER_NORMALIZED_COORDS) == CL_TRUE;
}
+ @Override
public void release() {
int ret = cl.clReleaseSampler(ID);
context.onSamplerReleased(this);
@@ -81,7 +82,7 @@ public class CLSampler extends CLObject implements CLResource {
}
}
- private class CLSamplerInfoAccessor extends CLInfoAccessor {
+ private class CLSamplerInfoAccessor extends CLTLInfoAccessor {
@Override
protected int getInfo(int name, long valueSize, Buffer value, NativeSizeBuffer valueSizeRet) {
diff --git a/src/com/jogamp/opencl/CLInfoAccessor.java b/src/com/jogamp/opencl/CLTLInfoAccessor.java
index 08d7305e..286dbe6b 100644
--- a/src/com/jogamp/opencl/CLInfoAccessor.java
+++ b/src/com/jogamp/opencl/CLTLInfoAccessor.java
@@ -28,6 +28,7 @@
package com.jogamp.opencl;
+import com.jogamp.opencl.spi.CLInfoAccessor;
import com.jogamp.common.nio.NativeSizeBuffer;
import com.jogamp.common.os.Platform;
import com.jogamp.opencl.util.CLUtil;
@@ -39,10 +40,10 @@ import static com.jogamp.opencl.CLException.*;
/**
* Internal utility for common OpenCL clGetFooInfo calls.
- * Threadsafe.
+ * Threadsafe, threadlocal implementation.
* @author Michael Bien
*/
-abstract class CLInfoAccessor {
+public abstract class CLTLInfoAccessor implements CLInfoAccessor {
private static final int BB_SIZE = 512;
@@ -63,6 +64,7 @@ abstract class CLInfoAccessor {
};
+ @Override
public final long getLong(int key) {
ByteBuffer buffer = getBB(8).putLong(0, 0);
@@ -72,6 +74,7 @@ abstract class CLInfoAccessor {
return buffer.getLong(0);
}
+ @Override
public final String getString(int key) {
NativeSizeBuffer sizeBuffer = getNSB();
@@ -91,6 +94,7 @@ abstract class CLInfoAccessor {
}
+ @Override
public final int[] getInts(int key, int n) {
ByteBuffer buffer = getBB(n * (Platform.is32Bit()?4:8));
diff --git a/src/com/jogamp/opencl/spi/CLInfoAccessor.java b/src/com/jogamp/opencl/spi/CLInfoAccessor.java
new file mode 100644
index 00000000..0ff0aeac
--- /dev/null
+++ b/src/com/jogamp/opencl/spi/CLInfoAccessor.java
@@ -0,0 +1,25 @@
+/*
+ * Created on Thursday, May 19 2011 16:43
+ */
+package com.jogamp.opencl.spi;
+
+/**
+ * Internal utility for common OpenCL clGetFooInfo calls.
+ * Provides common accessors to CL objects.
+ * @author Michael Bien
+ */
+public interface CLInfoAccessor {
+
+ int[] getInts(int key, int n);
+
+ /**
+ * Returns the long value for the given key.
+ */
+ long getLong(int key);
+
+ /**
+ * Returns the String value for the given key.
+ */
+ String getString(int key);
+
+}
diff --git a/src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java b/src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java
new file mode 100644
index 00000000..eb97fb56
--- /dev/null
+++ b/src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java
@@ -0,0 +1,14 @@
+/*
+ * Created on Thursday, May 19 2011 16:47
+ */
+package com.jogamp.opencl.spi;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public interface CLPlatformInfoAccessor extends CLInfoAccessor {
+
+ long[] getDeviceIDs(long type);
+
+}