29package com.jogamp.opencl.util;
31import com.jogamp.common.JogampRuntimeException;
32import com.jogamp.opencl.llb.CL;
33import com.jogamp.opencl.CLDevice;
34import com.jogamp.opencl.CLPlatform;
35import com.jogamp.opencl.CLProperty;
36import java.lang.annotation.Annotation;
37import java.lang.reflect.InvocationTargetException;
38import java.lang.reflect.Method;
39import java.nio.ByteBuffer;
40import java.util.ArrayList;
41import java.util.LinkedHashMap;
55 while(clLength > 0 && chars[--clLength] == 0);
57 return clLength==0 ?
"" :
new String(chars, 0, clLength+1);
64 final byte[] array =
new byte[clLength];
65 chars.get(array).rewind();
88 return readCLProperties(platform);
95 return readCLProperties(dev);
98 private static Map<String, String> readCLProperties(
final Object obj) {
100 return invoke(listMethods(obj.getClass()), obj);
101 }
catch (
final IllegalArgumentException ex) {
102 throw new JogampRuntimeException(ex);
103 }
catch (
final IllegalAccessException ex) {
104 throw new JogampRuntimeException(ex);
108 static Map<String, String> invoke(
final List<Method> methods,
final Object obj)
throws IllegalArgumentException, IllegalAccessException {
109 final Map<String, String> map =
new LinkedHashMap<String, String>();
110 for (
final Method method : methods) {
113 info = method.invoke(obj);
114 }
catch (
final InvocationTargetException ex) {
115 info = ex.getTargetException();
118 if(info.getClass().isArray()) {
122 final String value = method.getAnnotation(CLProperty.class).value();
123 map.put(value, info.toString());
128 static List<Method> listMethods(
final Class<?> clazz)
throws SecurityException {
129 final List<Method> list =
new ArrayList<Method>();
130 for (
final Method method : clazz.getDeclaredMethods()) {
131 final Annotation[] annotations = method.getDeclaredAnnotations();
132 for (
final Annotation annotation : annotations) {
133 if (annotation instanceof CLProperty) {
141 private static List<Number> asList(
final Object info) {
142 final List<Number> list =
new ArrayList<Number>();
143 if(info instanceof
int[]) {
144 final int[] array = (
int[]) info;
145 for (
final int i : array) {
148 }
else if(info instanceof
long[]) {
149 final long[] array = (
long[]) info;
150 for (
final long i : array) {
153 }
else if(info instanceof
float[]) {
154 final float[] array = (
float[]) info;
155 for (
final float i : array) {
158 }
else if(info instanceof
double[]) {
159 final double[] array = (
double[]) info;
160 for (
final double i : array) {
This object represents an OpenCL device.
static int clBoolean(final boolean b)
Returns b ? CL.CL_TRUE : CL.CL_FALSE.
static String clString2JavaString(final byte[] chars, int clLength)
static Map< String, String > obtainPlatformProperties(final CLPlatform platform)
Reads all platform properties and returns them as key-value map.
static String clString2JavaString(final ByteBuffer chars, final int clLength)
static Map< String, String > obtainDeviceProperties(final CLDevice dev)
Reads all device properties and returns them as key-value map.
static boolean clBoolean(final int clBoolean)
Returns true if clBoolean == CL.CL_TRUE.
Java bindings to OpenCL, the Open Computing Language.
static final int CL_TRUE
Define "CL_TRUE" with expression '1', CType: int.
static final int CL_FALSE
Define "CL_FALSE" with expression '0', CType: int.