From 286f94a7b148856666d7c05853ba9b2ba799b638 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 8 Jan 2010 00:11:55 +0100 Subject: introduced CLSampler and CLEvent. refactored code to use internal CLInfoAccessor utility where it makes sense. static imports. --- src/com/mbien/opencl/CLInfoAccessor.java | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/com/mbien/opencl/CLInfoAccessor.java (limited to 'src/com/mbien/opencl/CLInfoAccessor.java') 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); + + +} -- cgit v1.2.3