diff options
author | Michael Bien <[email protected]> | 2010-01-08 00:11:55 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-08 00:11:55 +0100 |
commit | 286f94a7b148856666d7c05853ba9b2ba799b638 (patch) | |
tree | f7dc2acfaeb18d11979c58f3e40f5da923955da1 /src/com/mbien/opencl/CLInfoAccessor.java | |
parent | 14d666509596e5b954a5c20e0be9f5826a3ce733 (diff) |
introduced CLSampler and CLEvent.
refactored code to use internal CLInfoAccessor utility where it makes sense.
static imports.
Diffstat (limited to 'src/com/mbien/opencl/CLInfoAccessor.java')
-rw-r--r-- | src/com/mbien/opencl/CLInfoAccessor.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLInfoAccessor.java b/src/com/mbien/opencl/CLInfoAccessor.java new file mode 100644 index 00000000..e366f7ea --- /dev/null +++ b/src/com/mbien/opencl/CLInfoAccessor.java @@ -0,0 +1,51 @@ +package com.mbien.opencl; + +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import static com.mbien.opencl.CLException.*; + +/** + * Internal utility for common OpenCL clGetFooInfo calls. + * @author Michael Bien + */ +abstract class CLInfoAccessor { + + private final static ByteBuffer buffer; + private final static long[] longBuffer; + + // 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]; + } + + public CLInfoAccessor() { + } + + final long getLong(int key) { + + buffer.rewind(); + int ret = getInfo(key, 8, buffer, null, 0); + checkForError(ret, "error while asking for info value"); + + return buffer.getLong(); + } + + final String getString(int key) { + + buffer.rewind(); + int ret = getInfo(key, buffer.capacity(), buffer, longBuffer, 0); + checkForError(ret, "error while asking for info string"); + + return CLUtils.clString2JavaString(buffer.array(), (int)longBuffer[0]); + + } + + protected abstract int getInfo(int name, long valueSize, Buffer value, long[] valueSizeRet, int valueSizeRetOffset); + + +} |