summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-05-02 22:55:02 +0200
committerMichael Bien <[email protected]>2010-05-02 22:55:02 +0200
commit3b3dc4591d3690f61b9488ed74e7c9248def1fd5 (patch)
treec7c30c0a51d9a1dc22e9c52bb239b1ea96df3b07 /src
parent59148a192446ddfefb13516d7ada72e6fa1661c7 (diff)
CLBuildListener functionality for high level bindings.
- uses low level BuildProgramCallback internally - updated tests, testing async builds
Diffstat (limited to 'src')
-rw-r--r--src/com/jogamp/opencl/CLProgram.java84
-rw-r--r--src/com/jogamp/opencl/CLProgramBuilder.java15
-rw-r--r--src/com/jogamp/opencl/impl/BuildProgramCallback.java (renamed from src/com/jogamp/opencl/BuildProgramCallback.java)4
-rw-r--r--src/com/jogamp/opencl/util/CLBuildConfiguration.java7
-rw-r--r--src/com/jogamp/opencl/util/CLBuildListener.java25
-rw-r--r--src/com/jogamp/opencl/util/CLProgramConfiguration.java6
6 files changed, 130 insertions, 11 deletions
diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java
index 43fd9665..b6c1d7a2 100644
--- a/src/com/jogamp/opencl/CLProgram.java
+++ b/src/com/jogamp/opencl/CLProgram.java
@@ -5,6 +5,8 @@ import com.jogamp.opencl.util.CLUtil;
import com.jogamp.common.nio.Int64Buffer;
import com.jogamp.common.os.Platform;
import com.jogamp.common.nio.PointerBuffer;
+import com.jogamp.opencl.impl.BuildProgramCallback;
+import com.jogamp.opencl.util.CLBuildListener;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Collections;
@@ -179,17 +181,40 @@ public class CLProgram extends CLObject implements CLResource {
* @return this
*/
public CLProgram build() {
- build(null, (CLDevice[])null);
+ build(null, (String)null, (CLDevice[]) null);
+ return this;
+ }
+
+ /**
+ * Builds this program for all devices associated with the context.
+ * @see CLBuildListener
+ * @param listener A listener who is notified when the program was built.
+ * @return this
+ */
+ public CLProgram build(CLBuildListener listener) {
+ build(listener, null, (CLDevice[])null);
return this;
}
/**
* Builds this program for the given devices.
- * @return this
* @param devices A list of devices this program should be build on or null for all devices of its context.
+ * @return this
*/
public CLProgram build(CLDevice... devices) {
- build(null, devices);
+ build(null, (String) null, devices);
+ return this;
+ }
+
+ /**
+ * Builds this program for the given devices.
+ * @see CLBuildListener
+ * @param listener A listener who is notified when the program was built.
+ * @param devices A list of devices this program should be build on or null for all devices of its context.
+ * @return this
+ */
+ public CLProgram build(CLBuildListener listener, CLDevice... devices) {
+ build(listener,null, devices);
return this;
}
@@ -199,17 +224,39 @@ public class CLProgram extends CLObject implements CLResource {
* @return this
*/
public CLProgram build(String options) {
- build(options, (CLDevice[])null);
+ build(null, options, (CLDevice[])null);
return this;
}
/**
* Builds this program for all devices associated with the context using the specified build options.
* @see CompilerOptions
+ * @see CLBuildListener
+ * @param listener A listener who is notified when the program was built.
* @return this
*/
+ public CLProgram build(CLBuildListener listener, String options) {
+ build(listener, options, (CLDevice[])null);
+ return this;
+ }
+
+ /**
+ * Builds this program for all devices associated with the context using the specified build options.
+ * @see CompilerOptions
+ */
public CLProgram build(String... options) {
- build(optionsOf(options), (CLDevice[])null);
+ build(null, optionsOf(options), (CLDevice[])null);
+ return this;
+ }
+
+ /**
+ * Builds this program for all devices associated with the context using the specified build options.
+ * @see CompilerOptions
+ * @see CLBuildListener
+ * @param listener A listener who is notified when the program was built.
+ */
+ public CLProgram build(CLBuildListener listener, String... options) {
+ build(listener, optionsOf(options), (CLDevice[])null);
return this;
}
@@ -217,10 +264,24 @@ public class CLProgram extends CLObject implements CLResource {
* Builds this program for the given devices and with the specified build options. In case this program was
* already built and there are kernels associated with this program they will be released first before rebuild.
* @see CompilerOptions
- * @return this
* @param devices A list of devices this program should be build on or null for all devices of its context.
+ * @return this
*/
public CLProgram build(String options, CLDevice... devices) {
+ build(null, options, devices);
+ return this;
+ }
+
+ /**
+ * Builds this program for the given devices and with the specified build options. In case this program was
+ * already built and there are kernels associated with this program they will be released first before rebuild.
+ * @see CompilerOptions
+ * @see CLBuildListener
+ * @return this
+ * @param devices A list of devices this program should be build on or null for all devices of its context.
+ * @param listener A listener who is notified when the program was built.
+ */
+ public CLProgram build(final CLBuildListener listener, String options, CLDevice... devices) {
if(released) {
throw new CLException("can not build a released program");
@@ -252,11 +313,20 @@ public class CLProgram extends CLObject implements CLResource {
buildStatusMap = null;
executable = false;
+ BuildProgramCallback callback = null;
+ if(listener != null) {
+ callback = new BuildProgramCallback() {
+ public void buildFinished(long cl_program) {
+ listener.buildFinished(CLProgram.this);
+ }
+ };
+ }
+
// Build the program
int ret = 0;
// building programs is not threadsafe
// synchronized(buildLock) {
- ret = cl.clBuildProgram(ID, count, deviceIDs, options, null);
+ ret = cl.clBuildProgram(ID, count, deviceIDs, options, callback);
// }
if(ret != CL_SUCCESS) {
diff --git a/src/com/jogamp/opencl/CLProgramBuilder.java b/src/com/jogamp/opencl/CLProgramBuilder.java
index 855d9837..e9440755 100644
--- a/src/com/jogamp/opencl/CLProgramBuilder.java
+++ b/src/com/jogamp/opencl/CLProgramBuilder.java
@@ -1,6 +1,7 @@
package com.jogamp.opencl;
import com.jogamp.opencl.util.CLBuildConfiguration;
+import com.jogamp.opencl.util.CLBuildListener;
import com.jogamp.opencl.util.CLProgramConfiguration;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -178,11 +179,21 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa
@Override
public CLProgram build() {
- return build(program);
+ return build(program, null);
+ }
+
+ @Override
+ public CLProgram build(CLBuildListener listener) {
+ return build(program, listener);
}
@Override
public CLProgram build(CLProgram program) {
+ return build(program, null);
+ }
+
+ @Override
+ public CLProgram build(CLProgram program, CLBuildListener listener) {
if(program == null) {
throw new NullPointerException("no program has been set");
}
@@ -191,7 +202,7 @@ public final class CLProgramBuilder implements CLProgramConfiguration, Serializa
setup.addAll(defineSet);
String options = CLProgram.optionsOf(setup.toArray(new String[setup.size()]));
CLDevice[] devices = binariesMap.keySet().toArray(new CLDevice[binariesMap.size()]);
- return program.build(options, devices);
+ return program.build(listener, options, devices);
}
@Override
diff --git a/src/com/jogamp/opencl/BuildProgramCallback.java b/src/com/jogamp/opencl/impl/BuildProgramCallback.java
index c37891ec..e4d68a4f 100644
--- a/src/com/jogamp/opencl/BuildProgramCallback.java
+++ b/src/com/jogamp/opencl/impl/BuildProgramCallback.java
@@ -1,4 +1,4 @@
-package com.jogamp.opencl;
+package com.jogamp.opencl.impl;
/**
* A callback an application can register to be called when the program executable
@@ -6,7 +6,7 @@ package com.jogamp.opencl;
* Note1: registering a build callback can make {@link CL#clBuildProgram} non blocking (OpenCL implementation dependent).<br/>
* Note2: the thread which calls this method is unspecified. The Application should ensure propper synchronization.
* @author Michael Bien
- * @see CL#clBuildProgram(long, int, com.jogamp.common.nio.PointerBuffer, java.lang.String, com.jogamp.opencl.BuildProgramCallback)
+ * @see com.jogamp.opencl.CL#clBuildProgram(long, int, com.jogamp.common.nio.PointerBuffer, java.lang.String, com.jogamp.opencl.impl.BuildProgramCallback)
*/
public interface BuildProgramCallback {
diff --git a/src/com/jogamp/opencl/util/CLBuildConfiguration.java b/src/com/jogamp/opencl/util/CLBuildConfiguration.java
index 1de62637..7019f1d2 100644
--- a/src/com/jogamp/opencl/util/CLBuildConfiguration.java
+++ b/src/com/jogamp/opencl/util/CLBuildConfiguration.java
@@ -21,6 +21,13 @@ public interface CLBuildConfiguration extends Cloneable {
public CLProgram build(CLProgram program);
/**
+ * Builds or rebuilds the program.
+ * @param program The program which should be build.
+ * @param listener The callback who is notified when the program has built.
+ */
+ public CLProgram build(CLProgram program, CLBuildListener listener);
+
+ /**
* Sets the program which should be build.
*/
public CLProgramConfiguration setProgram(CLProgram program);
diff --git a/src/com/jogamp/opencl/util/CLBuildListener.java b/src/com/jogamp/opencl/util/CLBuildListener.java
new file mode 100644
index 00000000..04769bb2
--- /dev/null
+++ b/src/com/jogamp/opencl/util/CLBuildListener.java
@@ -0,0 +1,25 @@
+/*
+ * Sunday, May 02 2010 20:38
+ */
+
+package com.jogamp.opencl.util;
+
+import com.jogamp.opencl.CLProgram;
+
+/**
+ * A callback an application can register to be called when the program executable
+ * has been built (successfully or unsuccessfully).<br/>
+ * Note1: registering a build callback can make {@link CL#clBuildProgram} non blocking (OpenCL implementation dependent).<br/>
+ * Note2: the thread which calls this method is unspecified. The Application should ensure propper synchronization.
+ * @author Michael Bien
+ * @see com.jogamp.opencl.CL#clBuildProgram(long, int, com.jogamp.common.nio.PointerBuffer, java.lang.String, com.jogamp.opencl.impl.BuildProgramCallback)
+ */
+public interface CLBuildListener {
+
+ /**
+ * Called when the program executable
+ * has been built (successfully or unsuccessfully).
+ */
+ public void buildFinished(CLProgram program);
+
+}
diff --git a/src/com/jogamp/opencl/util/CLProgramConfiguration.java b/src/com/jogamp/opencl/util/CLProgramConfiguration.java
index 901e28ce..de80376b 100644
--- a/src/com/jogamp/opencl/util/CLProgramConfiguration.java
+++ b/src/com/jogamp/opencl/util/CLProgramConfiguration.java
@@ -21,6 +21,12 @@ public interface CLProgramConfiguration extends CLBuildConfiguration {
public CLProgram build();
/**
+ * Builds or rebuilds a program.
+ * @param listener The callback who will be notified when the program has built.
+ */
+ public CLProgram build(CLBuildListener listener);
+
+ /**
* Returns the program.
*/
public CLProgram getProgram();