diff options
Diffstat (limited to 'src/com/jogamp/opencl/CLPlatform.java')
-rw-r--r-- | src/com/jogamp/opencl/CLPlatform.java | 84 |
1 files changed, 36 insertions, 48 deletions
diff --git a/src/com/jogamp/opencl/CLPlatform.java b/src/com/jogamp/opencl/CLPlatform.java index 684f006b..4a87b43d 100644 --- a/src/com/jogamp/opencl/CLPlatform.java +++ b/src/com/jogamp/opencl/CLPlatform.java @@ -28,6 +28,7 @@ package com.jogamp.opencl; +import com.jogamp.opencl.impl.CLTLAccessorFactory; import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.DynamicLookupHelper; import com.jogamp.common.JogampRuntimeException; @@ -38,10 +39,10 @@ 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.spi.CLAccessorFactory; 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; @@ -104,22 +105,26 @@ public class CLPlatform { public final CLVersion version; protected static CL cl; + private static CLAccessorFactory defaultFactory; + private final CLAccessorFactory factory; private Set<String> extensions; protected final CLPlatformInfoAccessor info; private CLPlatform(long id) { - initialize(); - this.ID = id; - this.info = new CLTLPlatformInfoAccessor(id, cl); - this.version = new CLVersion(getInfoString(CL_PLATFORM_VERSION)); + this(id, null); } - protected CLPlatform(long id, CLPlatformInfoAccessor accessor) { + protected CLPlatform(long id, CLAccessorFactory factory) { initialize(); this.ID = id; - this.info = accessor; + if(factory == null) { + this.factory = defaultFactory; + }else{ + this.factory = factory; + } + this.info = this.factory.createPlatformInfoAccessor(cl, id); this.version = new CLVersion(getInfoString(CL_PLATFORM_VERSION)); } @@ -127,11 +132,29 @@ public class CLPlatform { * Eagerly initializes JOCL. Subsequent calls do nothing. * @throws JogampRuntimeException if something went wrong in the initialization (e.g. OpenCL lib not found). */ - public synchronized static void initialize() throws JogampRuntimeException { + public static void initialize() throws JogampRuntimeException { + initialize(null); + } + + // keep package private until SPI is stablized + /** + * Eagerly initializes JOCL. Subsequent calls do nothing. + * @param factory CLAccessorFactory used for creating the bindings. + * @throws JogampRuntimeException if something went wrong in the initialization (e.g. OpenCL lib not found). + */ + synchronized static void initialize(CLAccessorFactory factory) throws JogampRuntimeException { if(cl != null) { return; } + + if(defaultFactory == null) { + if(factory == null) { + defaultFactory = new CLTLAccessorFactory(); + }else{ + defaultFactory = factory; + } + } try { @@ -507,47 +530,12 @@ public class CLPlatform { return info.getString(key); } - private final static class CLTLPlatformInfoAccessor extends CLTLInfoAccessor implements CLPlatformInfoAccessor { - - private final long ID; - private final CL cl; - - private CLTLPlatformInfoAccessor(long id, CL cl) { - this.ID = id; - this.cl = cl; - } - - @Override - protected int getInfo(int name, long valueSize, Buffer value, NativeSizeBuffer valueSizeRet) { - return cl.clGetPlatformInfo(ID, name, valueSize, value, valueSizeRet); - } - - @Override - public long[] getDeviceIDs(long type) { - - IntBuffer buffer = getBB(4).asIntBuffer(); - int ret = cl.clGetDeviceIDs(ID, type, 0, null, buffer); - int count = buffer.get(0); - - // return an empty buffer rather than throwing an exception - if(ret == CL.CL_DEVICE_NOT_FOUND || count == 0) { - return new long[0]; - }else{ - checkForError(ret, "error while enumerating devices"); - - NativeSizeBuffer deviceIDs = NativeSizeBuffer.wrap(getBB(count*NativeSizeBuffer.elementSize())); - ret = cl.clGetDeviceIDs(ID, type, count, deviceIDs, null); - checkForError(ret, "error while enumerating devices"); - - long[] ids = new long[count]; - for (int i = 0; i < ids.length; i++) { - ids[i] = deviceIDs.get(i); - } - return ids; - } - - } + final CLAccessorFactory getAccessorFactory(){ + return factory; + } + public final CLPlatformInfoAccessor getCLAccessor(){ + return info; } @Override |