diff options
Diffstat (limited to 'src/com/jogamp/opencl/CLPlatform.java')
-rw-r--r-- | src/com/jogamp/opencl/CLPlatform.java | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/com/jogamp/opencl/CLPlatform.java b/src/com/jogamp/opencl/CLPlatform.java index ee6a6bdf..684f006b 100644 --- a/src/com/jogamp/opencl/CLPlatform.java +++ b/src/com/jogamp/opencl/CLPlatform.java @@ -30,18 +30,18 @@ package com.jogamp.opencl; import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.DynamicLookupHelper; -import java.nio.Buffer; -import java.security.PrivilegedAction; import com.jogamp.common.JogampRuntimeException; import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.nio.NativeSizeBuffer; import com.jogamp.gluegen.runtime.FunctionAddressResolver; +import com.jogamp.opencl.spi.CLPlatformInfoAccessor; import com.jogamp.opencl.util.CLUtil; import com.jogamp.opencl.impl.CLImpl; import com.jogamp.opencl.impl.CLProcAddressTable; import com.jogamp.opencl.util.Filter; import com.jogamp.opencl.util.JOCLVersion; +import java.nio.Buffer; import java.nio.IntBuffer; import java.util.ArrayList; import java.util.Collections; @@ -50,6 +50,7 @@ import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Set; +import java.security.PrivilegedAction; import static java.security.AccessController.*; import static com.jogamp.opencl.CLException.*; @@ -90,7 +91,7 @@ import static com.jogamp.opencl.CL.*; * @see #getDefault() * @see #listCLPlatforms() */ -public final class CLPlatform { +public class CLPlatform { /** * OpenCL platform id for this platform. @@ -102,16 +103,23 @@ public final class CLPlatform { */ public final CLVersion version; - private static CL cl; + protected static CL cl; private Set<String> extensions; - private final CLPlatformInfoAccessor info; + protected final CLPlatformInfoAccessor info; private CLPlatform(long id) { initialize(); this.ID = id; - this.info = new CLPlatformInfoAccessor(id, cl); + this.info = new CLTLPlatformInfoAccessor(id, cl); + this.version = new CLVersion(getInfoString(CL_PLATFORM_VERSION)); + } + + protected CLPlatform(long id, CLPlatformInfoAccessor accessor) { + initialize(); + this.ID = id; + this.info = accessor; this.version = new CLVersion(getInfoString(CL_PLATFORM_VERSION)); } @@ -128,6 +136,7 @@ public final class CLPlatform { try { final CLProcAddressTable table = new CLProcAddressTable(new FunctionAddressResolver() { + @Override public long resolve(String name, DynamicLookupHelper lookup) { //FIXME workaround to fix a gluegen issue @@ -150,6 +159,7 @@ public final class CLPlatform { //load JOCL and init table doPrivileged(new PrivilegedAction<Object>() { + @Override public Object run() { NativeLibrary libOpenCL = JOCLJNILibLoader.loadOpenCL(); @@ -284,7 +294,7 @@ public final class CLPlatform { //add device to list for (int n = 0; n < deviceIDs.length; n++) { - list.add(new CLDevice(cl, this, deviceIDs[n])); + list.add(createDevice(deviceIDs[n])); } } @@ -304,7 +314,7 @@ public final class CLPlatform { //add device to list for (int n = 0; n < deviceIDs.length; n++) { - CLDevice device = new CLDevice(cl, this, deviceIDs[n]); + CLDevice device = createDevice(deviceIDs[n]); addIfAccepted(device, list, filters); } @@ -312,6 +322,10 @@ public final class CLPlatform { } + protected CLDevice createDevice(long id) { + return new CLDevice(cl, this, id); + } + private static <I> void addIfAccepted(I item, List<I> list, Filter<I>[] filters) { if(filters == null) { list.add(item); @@ -489,16 +503,16 @@ public final class CLPlatform { /** * Returns a info string in exchange for a key (CL_PLATFORM_*). */ - public String getInfoString(int key) { + public final String getInfoString(int key) { return info.getString(key); } - private final static class CLPlatformInfoAccessor extends CLInfoAccessor { + private final static class CLTLPlatformInfoAccessor extends CLTLInfoAccessor implements CLPlatformInfoAccessor { private final long ID; private final CL cl; - private CLPlatformInfoAccessor(long id, CL cl) { + private CLTLPlatformInfoAccessor(long id, CL cl) { this.ID = id; this.cl = cl; } @@ -508,6 +522,7 @@ public final class CLPlatform { return cl.clGetPlatformInfo(ID, name, valueSize, value, valueSizeRet); } + @Override public long[] getDeviceIDs(long type) { IntBuffer buffer = getBB(4).asIntBuffer(); |