summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/HowToBuild.html68
-rw-r--r--src/com/jogamp/opencl/CLContext.java9
-rw-r--r--src/com/jogamp/opencl/CLDevice.java34
-rw-r--r--src/com/jogamp/opencl/CLEvent.java8
-rw-r--r--src/com/jogamp/opencl/CLImage.java7
-rw-r--r--src/com/jogamp/opencl/CLPlatform.java103
-rw-r--r--src/com/jogamp/opencl/CLSampler.java6
-rw-r--r--src/com/jogamp/opencl/impl/CLTLAccessorFactory.java92
-rw-r--r--src/com/jogamp/opencl/impl/CLTLInfoAccessor.java (renamed from src/com/jogamp/opencl/CLInfoAccessor.java)12
-rw-r--r--src/com/jogamp/opencl/spi/CLAccessorFactory.java18
-rw-r--r--src/com/jogamp/opencl/spi/CLInfoAccessor.java25
-rw-r--r--src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java14
-rw-r--r--test/com/jogamp/opencl/CLCommandQueueTest.java19
13 files changed, 284 insertions, 131 deletions
diff --git a/doc/HowToBuild.html b/doc/HowToBuild.html
index 5556a4e0..04e3e4d6 100644
--- a/doc/HowToBuild.html
+++ b/doc/HowToBuild.html
@@ -31,42 +31,58 @@
<h3>Useful Links</h3>
<ul>
<li><a href="../../jogl/doc/HowToBuild.html">JOGL Build HowTo</a></li>
- <li><a href="http://jogamp.org/chuck/job/jocl_onmaster/label=linux64-null-centos54-jogamp-x64-chuck-001/javadoc/">JOCL JavaDoc</a></li>
- <li><a href="http://jogamp.org/wiki/index.php/JOCL_FAQ#Getting_Started">JOCL Hello World</a></li>
- <li><a href="http://www.khronos.org/opencl/sdk/1.0/docs/man/xhtml/">OpenCL Reference Pages</a></li>
- <li><a href="http://www.khronos.org/registry/cl/specs/opencl-1.0.48.pdf">OpenCL 1.0 Specification</a></li>
+ <li><a href="../../deployment/autobuilds/master/">Download JOCL</a></li>
+ <li><a href="../../deployment/webstart-next/javadoc/jocl/javadoc/">JOCL JavaDoc</a></li>
+ <li><a href="../../wiki/index.php/JOCL_FAQ#Getting_Started">JOCL Hello World</a></li>
+ <li><a href="http://github.com/mbien/jocl">Code Repository</a></li>
+ <li><a href="http://github.com/mbien/jocl-demos">Demos Repository</a></li>
+ </ul>
+ <h3>External References</h3>
+ <ul>
+ <li><a href="http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/">OpenCL Reference Pages</a></li>
+ <li><a href="http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf">OpenCL 1.1 Specification</a></li>
<li><a href="http://www.khronos.org/files/opencl-quick-reference-card.pdf">OpenCL Quick Reference</a></li>
- <li><a href="http://developer.amd.com/documentation/videos/OpenCLTechnicalOverviewVideoSeries/Pages/default.aspx">ATI Stream OpenCL Technical Overview Video Series</a></li>
+ </ul>
+ <h3>External Tutorials</h3>
+ <ul>
+ <li><a href="http://developer.amd.com/zones/OpenCLZone/universities/pages/default.aspx">AMD OpenCL University Kit</a></li>
+ <li><a href="http://developer.amd.com/documentation/videos/OpenCLTechnicalOverviewVideoSeries/Pages/default.aspx">AMD Stream OpenCL Technical Overview Video Series</a></li>
<li><a href="http://www.macresearch.org/opencl">Mac Research OpenCL Tutorials</a></li>
</ul>
+ <a href="http://www.khronos.org/opencl/"><img src="http://www.khronos.org/opencl/images/opencl_100px.png" alt="OpenCL"/></a>
</div>
<div id="text">
<h2>Prerequisites</h2>
<hr/>
<p>
- <b>Follow all steps</b> described in <a href="../../jogl/doc/HowToBuild.html">How to build JOGL</a>.<br/>
- If you could successfully pass the <code>junit.run</code> tests, you may continue here.<br/>
+ <b>Follow all steps</b> described in <a href="../../jogl/doc/HowToBuild.html">How to build JOGL</a>,
+ since GlueGen and JOGL are required as compiletime dependencies.
</p>
<h2>Platform and Component Requirements</h2>
<hr/>
- First you have to install an OpenCL SDK on your platform.
+ To verify the build you will have to install a OpenCL implementation on your platform.
+ <p>
+ Some vendors ship OpenCL already with the graphics driver or operating system.
+ So please make sure your system is up2date.
+ </p>
+ OpenCL SDKs for the desktop:
<ul>
<li> <b>GPU NVidia</b> Geforce >= 8<br/>
- Install the latest NVidia graphics driver available for your platform,<br/>
- and the GPU computing SDK (<i>gpucomputingsdk</i>).
<ul>
- <li> NVidia <a href="http://developer.nvidia.com/object/cuda_3_0_downloads.html">GPU Computing SDK code samples</a></li>
+ <li> NVidia <a href="http://developer.nvidia.com/cuda-downloads">GPU Computing SDK</a></li>
</ul>
</li>
- <li> <b>GPU AMD</b><br/>
- Install the latest AMD graphics driver available for your platform,<br/>
- and install the AMD Stream SDK, see below.
- </li>
+ <li> <b>GPU AMD or</b></li>
<li> <b>CPU x86 x86_64 SSE3</b>
<ul>
- <li> AMD <a href="http://developer.amd.com/gpu/ATIStreamSDK/Pages/default.aspx">ATI Stream SDK</a></li>
+ <li> AMD <a href="http://developer.amd.com/gpu/AMDAPPSDK/Pages/default.aspx">Accelerated Parallel Processing SDK</a></li>
+ </ul>
+ </li>
+ <li> <b>CPU Intel</b>
+ <ul>
+ <li>Intel <a href="http://software.intel.com/en-us/articles/opencl-sdk/">OpenCL SDK</a></li>
</ul>
</li>
</ul>
@@ -83,7 +99,7 @@
<li><a href="http://github.com/mbien/jocl">JOCL Dev GIT Repo</a></li>
</ul>
- It is crucial that you checkout the source code under the common root directory:
+ It is important that you checkout the source project side by side to its dependencies:
<pre>
/home/dude/projects/jogamp> git clone git://github.com/mbien/jocl.git jocl
</pre>
@@ -91,31 +107,21 @@
<pre>
/home/dude/projects/jogamp
/home/dude/projects/jogamp/gluegen
- /home/dude/projects/jogamp/jogl
/home/dude/projects/jogamp/jocl
+ /home/dude/projects/jogamp/jogl
</pre>
- </li>
-
- <li> <b>Unset your CLASSPATH environment variable:</b> <br/>
- The Ant build requires that the JOGL jars not be visible on the classpath. On Unix, type <code> unsetenv CLASSPATH </code>
- into a csh or tcsh shell, or <code> unset CLASSPATH </code> into a Bourne shell. On Windows, type <code> set CLASSPATH= </code> into a command prompt.</li>
-
- <li> <b>Optional</b> <i>Copy and edit <b>jocl.properties</b>:</i> <br/>
- To specify different basic options for the build,<br/>
- copy <b>jocl/jocl.properties</b> into your home directory (pointed to by the Java system property <b>user.home</b>). <br/>
- Edit the copy to change desired settings.
+ you can now open the projects with NetBeans or proceed with:
</li>
<li> <b>Build the source tree:</b> <br/>
Open a command shell in the "jocl" directory of the source tree and type <code>"ant jar"</code>.
</li>
<li> <b>Test your build:</b> <br/>
- Stay in your command shell in the "jocl" directory of the source tree and type <code>"ant test"</code>.
+ <code>"ant test"</code>
</li>
<li> <b>Build Javadoc:</b> <br/>
- Stay in your command shell in the "jocl" directory of the source tree and type <code>"ant javadoc"</code>.
- This will produce the end-user documentation for JOCL.
+ <code>"ant javadoc"</code>
</li>
</ol>
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index c8a847a2..43755c37 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -242,7 +242,7 @@ public class CLContext extends CLObject implements CLResource {
}
/**
- * Creates a program from the given sources, the program is not build yet.
+ * Creates a program from the given sources, the returned program is not build yet.
*/
public CLProgram createProgram(String src) {
CLProgram program = CLProgram.create(this, src);
@@ -251,7 +251,8 @@ public class CLContext extends CLObject implements CLResource {
}
/**
- * Creates a program and reads the source from stream, the program is not build yet.
+ * Creates a program and reads the source from stream, the returned program is not build yet.
+ * The InputStream is automatically closed after the sources have been read.
* @throws IOException when a IOException occurred while reading or closing the stream.
*/
public CLProgram createProgram(InputStream source) throws IOException {
@@ -260,14 +261,14 @@ public class CLContext extends CLObject implements CLResource {
throw new IllegalArgumentException("input stream for program source must not be null");
BufferedReader reader = new BufferedReader(new InputStreamReader(source));
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder(2048);
String line;
try {
while ((line = reader.readLine()) != null)
sb.append(line).append("\n");
} finally {
- source.close();
+ reader.close();
}
return createProgram(sb.toString());
diff --git a/src/com/jogamp/opencl/CLDevice.java b/src/com/jogamp/opencl/CLDevice.java
index 95f9d1a6..07f7c5f2 100644
--- a/src/com/jogamp/opencl/CLDevice.java
+++ b/src/com/jogamp/opencl/CLDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 - 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2009 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -29,8 +29,7 @@
package com.jogamp.opencl;
import com.jogamp.opencl.util.CLUtil;
-import com.jogamp.common.nio.PointerBuffer;
-import java.nio.Buffer;
+import com.jogamp.opencl.spi.CLInfoAccessor;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collections;
@@ -51,23 +50,23 @@ import static com.jogamp.opencl.CL.*;
* @see CLContext#getMaxFlopsDevice(com.jogamp.opencl.CLDevice.Type)
* @author Michael Bien
*/
-public final class CLDevice extends CLObject {
+public class CLDevice extends CLObject {
private Set<String> extensions;
- private final CLDeviceInfoAccessor deviceInfo;
+ private final CLInfoAccessor deviceInfo;
private final CLPlatform platform;
- CLDevice(CL cl, CLPlatform platform, long id) {
+ protected CLDevice(CL cl, CLPlatform platform, long id) {
super(cl, id);
this.platform = platform;
- this.deviceInfo = new CLDeviceInfoAccessor(cl, id);
+ this.deviceInfo = platform.getAccessorFactory().createDeviceInfoAccessor(cl, id);
}
- CLDevice(CLContext context, long id) {
+ protected CLDevice(CLContext context, long id) {
super(context, id);
this.platform = context.getPlatform();
- this.deviceInfo = new CLDeviceInfoAccessor(context.getCL(), id);
+ this.deviceInfo = platform.getAccessorFactory().createDeviceInfoAccessor(cl, id);
}
public CLCommandQueue createCommandQueue() {
@@ -691,21 +690,8 @@ public final class CLDevice extends CLObject {
return CLUtil.obtainDeviceProperties(this);
}
- private final static class CLDeviceInfoAccessor extends CLInfoAccessor {
-
- private final CL cl;
- private final long ID;
-
- private CLDeviceInfoAccessor(CL cl, long id) {
- this.cl = cl;
- this.ID = id;
- }
-
- @Override
- protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
- return cl.clGetDeviceInfo(ID, name, valueSize, value, valueSizeRet);
- }
-
+ public final CLInfoAccessor getCLAccessor() {
+ return deviceInfo;
}
@Override
diff --git a/src/com/jogamp/opencl/CLEvent.java b/src/com/jogamp/opencl/CLEvent.java
index 4365fd6a..928d0d92 100644
--- a/src/com/jogamp/opencl/CLEvent.java
+++ b/src/com/jogamp/opencl/CLEvent.java
@@ -28,6 +28,7 @@
package com.jogamp.opencl;
+import com.jogamp.opencl.impl.CLTLInfoAccessor;
import com.jogamp.opencl.impl.CLEventCallback;
import com.jogamp.common.nio.PointerBuffer;
import java.nio.Buffer;
@@ -64,12 +65,13 @@ public class CLEvent extends CLObject implements CLResource {
// apparently only ExecutionStatus.COMPLETE is allowed -> private
private void registerCallback(final CLEventListener callback, ExecutionStatus trigger) {
cl.clSetEventCallback(ID, trigger.STATUS, new CLEventCallback() {
- public void eventStateChanged(long event, int status) {
+ @Override public void eventStateChanged(long event, int status) {
callback.eventStateChanged(CLEvent.this, status);
}
});
}
+ @Override
public void release() {
int ret = cl.clReleaseEvent(ID);
checkForError(ret, "can not release event");
@@ -138,7 +140,7 @@ public class CLEvent extends CLObject implements CLResource {
- private class CLEventInfoAccessor extends CLInfoAccessor {
+ private class CLEventInfoAccessor extends CLTLInfoAccessor {
@Override
protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
@@ -147,7 +149,7 @@ public class CLEvent extends CLObject implements CLResource {
}
- private class CLEventProfilingInfoAccessor extends CLInfoAccessor {
+ private class CLEventProfilingInfoAccessor extends CLTLInfoAccessor {
@Override
protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
diff --git a/src/com/jogamp/opencl/CLImage.java b/src/com/jogamp/opencl/CLImage.java
index acb36aed..fa3ab800 100644
--- a/src/com/jogamp/opencl/CLImage.java
+++ b/src/com/jogamp/opencl/CLImage.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 - 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2009 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -29,6 +29,7 @@
package com.jogamp.opencl;
import com.jogamp.common.nio.PointerBuffer;
+import com.jogamp.opencl.impl.CLTLInfoAccessor;
import java.nio.Buffer;
import static com.jogamp.opencl.CL.*;
@@ -41,7 +42,7 @@ public abstract class CLImage<B extends Buffer> extends CLMemory<B> {
protected CLImageFormat format;
- final CLInfoAccessor imageInfo;
+ final CLTLInfoAccessor imageInfo;
public final int width;
public final int height;
@@ -100,7 +101,7 @@ public abstract class CLImage<B extends Buffer> extends CLMemory<B> {
}
- protected final static class CLImageInfoAccessor extends CLInfoAccessor {
+ protected final static class CLImageInfoAccessor extends CLTLInfoAccessor {
private final long id;
private final CL cl;
diff --git a/src/com/jogamp/opencl/CLPlatform.java b/src/com/jogamp/opencl/CLPlatform.java
index d9a258c0..ab2e32b0 100644
--- a/src/com/jogamp/opencl/CLPlatform.java
+++ b/src/com/jogamp/opencl/CLPlatform.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 - 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2009 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -28,17 +28,18 @@
package com.jogamp.opencl;
+import com.jogamp.opencl.impl.CLTLAccessorFactory;
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.PointerBuffer;
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.spi.CLAccessorFactory;
import com.jogamp.opencl.util.Filter;
import com.jogamp.opencl.util.JOCLVersion;
@@ -50,6 +51,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 +92,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 +104,27 @@ public final class CLPlatform {
*/
public final CLVersion version;
- private static CL cl;
+ protected static CL cl;
+ private static CLAccessorFactory defaultFactory;
+ private final CLAccessorFactory factory;
private Set<String> extensions;
- private final CLPlatformInfoAccessor info;
+ protected final CLPlatformInfoAccessor info;
private CLPlatform(long id) {
+ this(id, null);
+ }
+
+ protected CLPlatform(long id, CLAccessorFactory factory) {
initialize();
this.ID = id;
- this.info = new CLPlatformInfoAccessor(id, cl);
+ 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));
}
@@ -119,15 +132,34 @@ public final 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 {
final CLProcAddressTable table = new CLProcAddressTable(new FunctionAddressResolver() {
+ @Override
public long resolve(String name, DynamicLookupHelper lookup) {
//FIXME workaround to fix a gluegen issue
@@ -150,6 +182,7 @@ public final class CLPlatform {
//load JOCL and init table
doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
NativeLibrary libOpenCL = JOCLJNILibLoader.loadOpenCL();
@@ -284,7 +317,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 +337,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 +345,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,50 +526,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 long ID;
- private final CL cl;
-
- private CLPlatformInfoAccessor(long id, CL cl) {
- this.ID = id;
- this.cl = cl;
- }
-
- @Override
- protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
- return cl.clGetPlatformInfo(ID, name, valueSize, value, valueSizeRet);
- }
-
- 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");
-
- PointerBuffer deviceIDs = PointerBuffer.wrap(getBB(count*PointerBuffer.ELEMENT_SIZE));
- 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
diff --git a/src/com/jogamp/opencl/CLSampler.java b/src/com/jogamp/opencl/CLSampler.java
index 73e153d9..8632143b 100644
--- a/src/com/jogamp/opencl/CLSampler.java
+++ b/src/com/jogamp/opencl/CLSampler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 - 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2009 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -29,6 +29,7 @@
package com.jogamp.opencl;
import com.jogamp.common.nio.PointerBuffer;
+import com.jogamp.opencl.impl.CLTLInfoAccessor;
import java.nio.Buffer;
@@ -73,6 +74,7 @@ public class CLSampler extends CLObject implements CLResource {
return samplerInfo.getLong(CL_SAMPLER_NORMALIZED_COORDS) == CL_TRUE;
}
+ @Override
public void release() {
int ret = cl.clReleaseSampler(ID);
context.onSamplerReleased(this);
@@ -81,7 +83,7 @@ public class CLSampler extends CLObject implements CLResource {
}
}
- private class CLSamplerInfoAccessor extends CLInfoAccessor {
+ private class CLSamplerInfoAccessor extends CLTLInfoAccessor {
@Override
protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
diff --git a/src/com/jogamp/opencl/impl/CLTLAccessorFactory.java b/src/com/jogamp/opencl/impl/CLTLAccessorFactory.java
new file mode 100644
index 00000000..2f34fec5
--- /dev/null
+++ b/src/com/jogamp/opencl/impl/CLTLAccessorFactory.java
@@ -0,0 +1,92 @@
+/*
+ * Created on Wednesday, May 25 2011 00:57
+ */
+package com.jogamp.opencl.impl;
+
+import java.nio.IntBuffer;
+import com.jogamp.common.nio.PointerBuffer;
+import com.jogamp.opencl.CL;
+import com.jogamp.opencl.spi.CLAccessorFactory;
+import com.jogamp.opencl.spi.CLInfoAccessor;
+import com.jogamp.opencl.spi.CLPlatformInfoAccessor;
+import java.nio.Buffer;
+
+import static com.jogamp.opencl.CLException.*;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class CLTLAccessorFactory implements CLAccessorFactory {
+
+ @Override
+ public CLInfoAccessor createDeviceInfoAccessor(CL cl, long id) {
+ return new CLDeviceInfoAccessor(cl, id);
+ }
+
+ @Override
+ public CLPlatformInfoAccessor createPlatformInfoAccessor(CL cl, long id) {
+ return new CLTLPlatformInfoAccessor(cl, id);
+ }
+
+ private final static class CLDeviceInfoAccessor extends CLTLInfoAccessor {
+
+ private final CL cl;
+ private final long ID;
+
+ private CLDeviceInfoAccessor(CL cl, long id) {
+ this.cl = cl;
+ this.ID = id;
+ }
+
+ @Override
+ public int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) {
+ return cl.clGetDeviceInfo(ID, name, valueSize, value, valueSizeRet);
+ }
+
+ }
+
+ private final static class CLTLPlatformInfoAccessor extends CLTLInfoAccessor implements CLPlatformInfoAccessor {
+
+ private final long ID;
+ private final CL cl;
+
+ private CLTLPlatformInfoAccessor(CL cl, long id) {
+ this.ID = id;
+ this.cl = cl;
+ }
+
+ @Override
+ public int getInfo(int name, long valueSize, Buffer value, PointerBuffer 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");
+
+ PointerBuffer deviceIDs = PointerBuffer.wrap(getBB(count*PointerBuffer.ELEMENT_SIZE));
+ 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;
+ }
+
+ }
+
+ }
+
+}
diff --git a/src/com/jogamp/opencl/CLInfoAccessor.java b/src/com/jogamp/opencl/impl/CLTLInfoAccessor.java
index b005ec04..c31b22a6 100644
--- a/src/com/jogamp/opencl/CLInfoAccessor.java
+++ b/src/com/jogamp/opencl/impl/CLTLInfoAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 - 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2009 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -26,8 +26,9 @@
* or implied, of JogAmp Community.
*/
-package com.jogamp.opencl;
+package com.jogamp.opencl.impl;
+import com.jogamp.opencl.spi.CLInfoAccessor;
import com.jogamp.common.nio.PointerBuffer;
import com.jogamp.common.os.Platform;
import com.jogamp.opencl.util.CLUtil;
@@ -39,10 +40,10 @@ import static com.jogamp.opencl.CLException.*;
/**
* Internal utility for common OpenCL clGetFooInfo calls.
- * Threadsafe.
+ * Threadsafe, threadlocal implementation.
* @author Michael Bien
*/
-abstract class CLInfoAccessor {
+public abstract class CLTLInfoAccessor implements CLInfoAccessor {
private static final int BB_SIZE = 512;
@@ -63,6 +64,7 @@ abstract class CLInfoAccessor {
};
+ @Override
public final long getLong(int key) {
ByteBuffer buffer = getBB(8).putLong(0, 0);
@@ -72,6 +74,7 @@ abstract class CLInfoAccessor {
return buffer.getLong(0);
}
+ @Override
public final String getString(int key) {
PointerBuffer sizeBuffer = getNSB();
@@ -91,6 +94,7 @@ abstract class CLInfoAccessor {
}
+ @Override
public final int[] getInts(int key, int n) {
ByteBuffer buffer = getBB(n * (Platform.is32Bit()?4:8));
diff --git a/src/com/jogamp/opencl/spi/CLAccessorFactory.java b/src/com/jogamp/opencl/spi/CLAccessorFactory.java
new file mode 100644
index 00000000..6239bb37
--- /dev/null
+++ b/src/com/jogamp/opencl/spi/CLAccessorFactory.java
@@ -0,0 +1,18 @@
+/*
+ * Created on Wednesday, May 25 2011 00:53
+ */
+package com.jogamp.opencl.spi;
+
+import com.jogamp.opencl.CL;
+
+/**
+ * Implementations of this interface are factories responsible for creating CLAccessors.
+ * @author Michael Bien
+ */
+public interface CLAccessorFactory {
+
+ CLInfoAccessor createDeviceInfoAccessor(CL cl, long id);
+
+ CLPlatformInfoAccessor createPlatformInfoAccessor(CL cl, long id);
+
+}
diff --git a/src/com/jogamp/opencl/spi/CLInfoAccessor.java b/src/com/jogamp/opencl/spi/CLInfoAccessor.java
new file mode 100644
index 00000000..0ff0aeac
--- /dev/null
+++ b/src/com/jogamp/opencl/spi/CLInfoAccessor.java
@@ -0,0 +1,25 @@
+/*
+ * Created on Thursday, May 19 2011 16:43
+ */
+package com.jogamp.opencl.spi;
+
+/**
+ * Internal utility for common OpenCL clGetFooInfo calls.
+ * Provides common accessors to CL objects.
+ * @author Michael Bien
+ */
+public interface CLInfoAccessor {
+
+ int[] getInts(int key, int n);
+
+ /**
+ * Returns the long value for the given key.
+ */
+ long getLong(int key);
+
+ /**
+ * Returns the String value for the given key.
+ */
+ String getString(int key);
+
+}
diff --git a/src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java b/src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java
new file mode 100644
index 00000000..eb97fb56
--- /dev/null
+++ b/src/com/jogamp/opencl/spi/CLPlatformInfoAccessor.java
@@ -0,0 +1,14 @@
+/*
+ * Created on Thursday, May 19 2011 16:47
+ */
+package com.jogamp.opencl.spi;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public interface CLPlatformInfoAccessor extends CLInfoAccessor {
+
+ long[] getDeviceIDs(long type);
+
+}
diff --git a/test/com/jogamp/opencl/CLCommandQueueTest.java b/test/com/jogamp/opencl/CLCommandQueueTest.java
index c8c028af..5636a40d 100644
--- a/test/com/jogamp/opencl/CLCommandQueueTest.java
+++ b/test/com/jogamp/opencl/CLCommandQueueTest.java
@@ -191,25 +191,24 @@ public class CLCommandQueueTest {
}else{
queue = device.createCommandQueue();
}
-
- CLEventList writeEvent = new CLEventList(1);
- CLEventList kernelEvents = new CLEventList(2);
+
+ // simulate in-order queue by accumulating events of prior commands
+ CLEventList events = new CLEventList(3);
// (1+1)*2 = 4; conditions enforce propper order
CLKernel addKernel = program.createCLKernel("add").putArg(buffer).putArg(1).putArg(elements);
CLKernel mulKernel = program.createCLKernel("mul").putArg(buffer).putArg(2).putArg(elements);
- queue.putWriteBuffer(buffer, false, writeEvent);
+ queue.putWriteBuffer(buffer, false, events);
- queue.put1DRangeKernel(addKernel, 0, elements, 1, writeEvent, kernelEvents);
- queue.put1DRangeKernel(mulKernel, 0, elements, 1, writeEvent, kernelEvents);
+ queue.put1DRangeKernel(addKernel, 0, elements, 1, events, events);
+ queue.put1DRangeKernel(mulKernel, 0, elements, 1, events, events);
- queue.putReadBuffer(buffer, false, kernelEvents, null);
+ queue.putReadBuffer(buffer, false, events, null);
queue.finish();
- writeEvent.release();
- kernelEvents.release();
+ events.release();
for (int i = 0; i < elements; i++) {
assertEquals(4, buffer.getBuffer().get(i));
@@ -372,7 +371,7 @@ public class CLCommandQueueTest {
final CountDownLatch countdown = new CountDownLatch(1);
customEvent.registerCallback(new CLEventListener() {
-
+ @Override
public void eventStateChanged(CLEvent event, int status) {
out.println("event received: "+event);
assertEquals(event, customEvent);