29package com.jogamp.opencl.impl;
31import java.nio.Buffer;
32import java.nio.ByteBuffer;
34import com.jogamp.common.nio.Buffers;
35import com.jogamp.common.nio.PointerBuffer;
36import com.jogamp.common.os.Platform;
37import com.jogamp.common.util.Bitstream;
38import com.jogamp.opencl.CLException;
39import com.jogamp.opencl.spi.CLInfoAccessor;
40import com.jogamp.opencl.util.CLUtil;
49 private static final int BB_SIZE = 512;
51 protected final static ThreadLocal<ByteBuffer>
localBB =
new ThreadLocal<ByteBuffer>() {
54 protected ByteBuffer initialValue() {
55 return Buffers.newDirectByteBuffer(BB_SIZE);
59 protected final static ThreadLocal<PointerBuffer>
localNSB =
new ThreadLocal<PointerBuffer>() {
62 protected PointerBuffer initialValue() {
63 return PointerBuffer.allocateDirect(1);
70 final ByteBuffer buffer =
getBB(4).putInt(0, 0);
71 final int ret =
getInfo(key, 4, buffer,
null);
73 return Bitstream.toUInt32Long(buffer.getInt(0));
77 public final long getLong(
final int key) {
79 final ByteBuffer buffer =
getBB(8).putLong(0, 0);
80 final int ret =
getInfo(key, 8, buffer,
null);
83 return buffer.getLong(0);
89 final PointerBuffer sizeBuffer =
getNSB();
90 int ret =
getInfo(key, 0,
null, sizeBuffer);
93 final int clSize = (int)sizeBuffer.get(0);
94 final ByteBuffer buffer =
getBB(clSize);
96 ret =
getInfo(key, buffer.capacity(), buffer,
null);
99 final byte[] array =
new byte[clSize];
100 buffer.get(array).rewind();
107 public final int[]
getInts(
final int key,
final int n) {
109 final ByteBuffer buffer =
getBB(n * (Platform.is32Bit()?4:8));
110 final int ret =
getInfo(key, buffer.capacity(), buffer,
null);
113 final int[] array =
new int[n];
114 for(
int i = 0; i < array.length; i++) {
115 if(Platform.is32Bit()) {
116 array[i] = buffer.getInt();
118 array[i] = (int)buffer.getLong();
126 protected ByteBuffer
getBB(
final int minCapacity) {
127 if(minCapacity > BB_SIZE) {
128 return Buffers.newDirectByteBuffer(minCapacity);
138 protected abstract int getInfo(
int name,
long valueSize, Buffer value, PointerBuffer valueSizeRet);
Main Exception type for runtime OpenCL errors and failed function calls (e.g.
static void checkForError(final int status, final String message)
Throws a CLException when status != CL_SUCCESS.
Internal utility for common OpenCL clGetFooInfo calls.
abstract int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet)
final String getString(final int key)
Returns the String value for the given key.
final int[] getInts(final int key, final int n)
ByteBuffer getBB(final int minCapacity)
final long getLong(final int key)
Returns the long value for the given key.
static final ThreadLocal< PointerBuffer > localNSB
final long getUInt32Long(final int key)
Returns the uint32_t value for the given key, reinterpreted as a long value.
static final ThreadLocal< ByteBuffer > localBB
static String clString2JavaString(final byte[] chars, int clLength)
Internal utility for common OpenCL clGetFooInfo calls.