aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLInfoAccessor.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-01-15 16:45:29 +0100
committerMichael Bien <[email protected]>2010-01-15 16:45:29 +0100
commit64f212c105fd0f23e8116307b64ee4b87928823d (patch)
tree02adbfa7a3ef1a9b0c5379ae86a9fe1187b7314c /src/com/mbien/opencl/CLInfoAccessor.java
parentd446e57f45811c23da651f7a5f481ddaed4c01c6 (diff)
CLInfoAccessor uses now threadlocal direct nio buffers for all operations.
javadoc improvements. added event based profiling functionality.
Diffstat (limited to 'src/com/mbien/opencl/CLInfoAccessor.java')
-rw-r--r--src/com/mbien/opencl/CLInfoAccessor.java48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/com/mbien/opencl/CLInfoAccessor.java b/src/com/mbien/opencl/CLInfoAccessor.java
index e366f7ea..7a303dc3 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.sun.gluegen.runtime.PointerBuffer;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -8,44 +9,53 @@ import static com.mbien.opencl.CLException.*;
/**
* Internal utility for common OpenCL clGetFooInfo calls.
+ * Threadsafe.
* @author Michael Bien
*/
abstract class CLInfoAccessor {
- private final static ByteBuffer buffer;
- private final static long[] longBuffer;
+ private final static ThreadLocal<ByteBuffer> localBB = new ThreadLocal<ByteBuffer>() {
- // TODO revisit for command queue concurrency
- // TODO use direct memory code path as soon gluegen is fixed
- static{
- buffer = ByteBuffer.allocate(512);
- buffer.order(ByteOrder.nativeOrder());
- longBuffer = new long[1];
- }
+ @Override
+ protected ByteBuffer initialValue() {
+ return ByteBuffer.allocateDirect(512).order(ByteOrder.nativeOrder());
+ }
- public CLInfoAccessor() {
- }
+ };
+ private final static ThreadLocal<PointerBuffer> localPB = new ThreadLocal<PointerBuffer>() {
+
+ @Override
+ protected PointerBuffer initialValue() {
+ return PointerBuffer.allocateDirect(1);
+ }
+
+ };
final long getLong(int key) {
- buffer.rewind();
- int ret = getInfo(key, 8, buffer, null, 0);
+ ByteBuffer buffer = localBB.get();
+ int ret = getInfo(key, 8, buffer, null);
checkForError(ret, "error while asking for info value");
- return buffer.getLong();
+ return buffer.getLong(0);
}
final String getString(int key) {
-
- buffer.rewind();
- int ret = getInfo(key, buffer.capacity(), buffer, longBuffer, 0);
+
+ ByteBuffer buffer = localBB.get();
+ PointerBuffer pbuffer = localPB.get();
+ int ret = getInfo(key, buffer.capacity(), buffer, pbuffer);
checkForError(ret, "error while asking for info string");
- return CLUtils.clString2JavaString(buffer.array(), (int)longBuffer[0]);
+ int clSize = (int)pbuffer.get(0);
+ byte[] array = new byte[clSize-1]; // last char is always null
+ buffer.get(array).rewind();
+
+ return CLUtils.clString2JavaString(array, clSize);
}
- protected abstract int getInfo(int name, long valueSize, Buffer value, long[] valueSizeRet, int valueSizeRetOffset);
+ protected abstract int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet);
}