summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-02-25 19:13:15 +0100
committerMichael Bien <[email protected]>2010-02-25 19:13:15 +0100
commit0857dbb04fe9259f1076e9559b822c5032c23461 (patch)
tree5a45cd56bf861876f13d32a731a7cf0feb8c725e /src
parent0b7b387ff2d829f611b385a6aebfe91ee746196a (diff)
introduced CLBuildConfiguration and CLProgramConfiguration interfaces for CLProgramBuilder.
Diffstat (limited to 'src')
-rw-r--r--src/com/mbien/opencl/CLBuildConfiguration.java68
-rw-r--r--src/com/mbien/opencl/CLContext.java12
-rw-r--r--src/com/mbien/opencl/CLProgram.java6
-rw-r--r--src/com/mbien/opencl/CLProgramBuilder.java83
-rw-r--r--src/com/mbien/opencl/CLProgramConfiguration.java38
5 files changed, 157 insertions, 50 deletions
diff --git a/src/com/mbien/opencl/CLBuildConfiguration.java b/src/com/mbien/opencl/CLBuildConfiguration.java
new file mode 100644
index 00000000..7b6ee1e2
--- /dev/null
+++ b/src/com/mbien/opencl/CLBuildConfiguration.java
@@ -0,0 +1,68 @@
+package com.mbien.opencl;
+
+import java.util.Map;
+
+/**
+ * Configuration representing everything needed to build an OpenCL program.
+ * @author Michael Bien
+ */
+public interface CLBuildConfiguration {
+
+ /**
+ * Builds or rebuilds the program.
+ * @param program The program which should be build.
+ */
+ public CLProgram build(CLProgram program);
+
+ /**
+ * Adds the device as build target.
+ */
+ public CLBuildConfiguration forDevice(CLDevice device);
+
+ /**
+ * Adds the devices as build target.
+ */
+ public CLBuildConfiguration forDevices(CLDevice... devices);
+
+ /**
+ * Resets this builder's configuration like options, devices and definitions.
+ */
+ public CLBuildConfiguration reset();
+
+ /**
+ * Adds the definition to the build configuration.
+ * @see public CLProgram#define(java.lang.String)
+ */
+ public CLBuildConfiguration withDefine(String name);
+
+ /**
+ * Adds the definition to the build configuration.
+ * @see public CLProgram#define(java.lang.String, java.lang.String)
+ */
+ public CLBuildConfiguration withDefine(String name, Object value);
+
+ /**
+ * Adds the definitions to the build configuration.
+ * @see public CLProgram#define(java.lang.String)
+ */
+ public CLBuildConfiguration withDefines(String... names);
+
+ /**
+ * Adds the definitions to the build configuration.
+ * @see public CLProgram#define(java.lang.String, java.lang.String)
+ */
+ public CLBuildConfiguration withDefines(Map<String, String> defines);
+
+ /**
+ * Adds the compiler option to the build configuration.
+ * @see CompilerOptions
+ */
+ public CLBuildConfiguration withOption(String option);
+
+ /**
+ * Adds the compiler options to the build configuration.
+ * @see CompilerOptions
+ */
+ public CLBuildConfiguration withOptions(String... options);
+
+}
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java
index 73146acd..4cc21d0f 100644
--- a/src/com/mbien/opencl/CLContext.java
+++ b/src/com/mbien/opencl/CLContext.java
@@ -192,15 +192,15 @@ public class CLContext extends CLObject implements CLResource {
}
/**
- * Creates a program and reads the sources from stream, the program is not build yet.
+ * Creates a program and reads the source from stream, the program is not build yet.
* @throws IOException when a IOException occurred while reading or closing the stream.
*/
- public CLProgram createProgram(InputStream sources) throws IOException {
+ public CLProgram createProgram(InputStream source) throws IOException {
- if(sources == null)
- throw new IllegalArgumentException("input stream for program sources must not be null");
+ if(source == null)
+ throw new IllegalArgumentException("input stream for program source must not be null");
- BufferedReader reader = new BufferedReader(new InputStreamReader(sources));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(source));
StringBuilder sb = new StringBuilder();
String line;
@@ -208,7 +208,7 @@ public class CLContext extends CLObject implements CLResource {
while ((line = reader.readLine()) != null)
sb.append(line).append("\n");
} finally {
- sources.close();
+ source.close();
}
return createProgram(sb.toString());
diff --git a/src/com/mbien/opencl/CLProgram.java b/src/com/mbien/opencl/CLProgram.java
index 562df69b..44e747bf 100644
--- a/src/com/mbien/opencl/CLProgram.java
+++ b/src/com/mbien/opencl/CLProgram.java
@@ -247,10 +247,10 @@ public class CLProgram extends CLObject implements CLResource {
}
/**
- * Prepares the build for this program by returning a {@link CLProgramBuilder}.
+ * Prepares the build for this program by returning a new {@link CLProgramConfiguration}.
*/
- public CLProgramBuilder prepare() {
- return new CLProgramBuilder(this);
+ public CLProgramConfiguration prepare() {
+ return CLProgramBuilder.createForProgram(this);
}
/**
diff --git a/src/com/mbien/opencl/CLProgramBuilder.java b/src/com/mbien/opencl/CLProgramBuilder.java
index 3f7ab07b..e342101e 100644
--- a/src/com/mbien/opencl/CLProgramBuilder.java
+++ b/src/com/mbien/opencl/CLProgramBuilder.java
@@ -13,99 +13,99 @@ import java.util.Set;
* @see CLProgram#prepare()
* @author Michael Bien
*/
-public final class CLProgramBuilder {
+public final class CLProgramBuilder implements CLProgramConfiguration {
private transient CLProgram program;
- private final Set<String> optionList = new HashSet<String>();
- private final Set<String> defineList = new HashSet<String>();
- private final Set<CLDevice> deviceList = new HashSet<CLDevice>();
+ private String source;
+ private Map<CLDevice, byte[]> binaries;
- public CLProgramBuilder() { }
+ private final Set<String> optionSet = new HashSet<String>();
+ private final Set<String> defineSet = new HashSet<String>();
+ private final Set<CLDevice> deviceSet = new HashSet<CLDevice>();
- public CLProgramBuilder(CLProgram program) {
+
+ private CLProgramBuilder() { }
+
+ private CLProgramBuilder(CLProgram program) {
this.program = program;
}
+ public static CLProgramConfiguration createForProgram(CLProgram program) {
+ return new CLProgramBuilder(program);
+ }
+
+ public static CLBuildConfiguration createConfiguration() {
+ return new CLProgramBuilder();
+ }
+
public CLProgramBuilder withOption(String option) {
- this.optionList.add(option);
+ optionSet.add(option);
return this;
}
public CLProgramBuilder withOptions(String... options) {
for (String option : options) {
- this.optionList.add(option);
+ optionSet.add(option);
}
return this;
}
public CLProgramBuilder withDefine(String name) {
- this.defineList.add(CLProgram.define(name));
+ defineSet.add(CLProgram.define(name));
return this;
}
public CLProgramBuilder withDefines(String... names) {
for (String name : names) {
- this.defineList.add(CLProgram.define(name));
+ defineSet.add(CLProgram.define(name));
}
return this;
}
public CLProgramBuilder withDefine(String name, Object value) {
- this.defineList.add(CLProgram.define(name, value.toString()));
+ defineSet.add(CLProgram.define(name, value.toString()));
return this;
}
public CLProgramBuilder withDefines(Map<String, String> defines) {
for (String name : defines.keySet()) {
- defineList.add(CLProgram.define(name, defines.get(name)));
+ defineSet.add(CLProgram.define(name, defines.get(name)));
}
return this;
}
public CLProgramBuilder forDevice(CLDevice device) {
- CLDevice[] devices = new CLDevice[]{device};
- for (CLDevice device1 : devices) {
- this.deviceList.add(device1);
- }
+ deviceSet.add(device);
return this;
}
public CLProgramBuilder forDevices(CLDevice... devices) {
for (CLDevice device : devices) {
- this.deviceList.add(device);
+ deviceSet.add(device);
}
return this;
}
- /**
- * Builds or rebuilds a program.
- */
public CLProgram build() {
return build(program);
}
- /**
- * Builds or rebuilds a program.
- */
public CLProgram build(CLProgram program) {
if(program == null) {
throw new NullPointerException("no program has been set");
}
List<String> setup = new ArrayList<String>();
- setup.addAll(optionList);
- setup.addAll(defineList);
+ setup.addAll(optionSet);
+ setup.addAll(defineSet);
String options = CLProgram.optionsOf(setup.toArray(new String[setup.size()]));
- CLDevice[] devices = deviceList.toArray(new CLDevice[deviceList.size()]);
+ CLDevice[] devices = deviceSet.toArray(new CLDevice[deviceSet.size()]);
return program.build(options, devices);
}
- /**
- * Resets this builder's configuration like options, devices and defines.
- */
public CLProgramBuilder reset() {
- optionList.clear();
- defineList.clear();
- deviceList.clear();
+ optionSet.clear();
+ defineSet.clear();
+ deviceSet.clear();
return this;
}
@@ -125,9 +125,9 @@ public final class CLProgramBuilder {
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("CLProgramBuilder");
- sb.append("{optionList=").append(optionList);
- sb.append(", defineList=").append(defineList);
- sb.append(", deviceList=").append(deviceList);
+ sb.append("{options=").append(optionSet);
+ sb.append(", defines=").append(defineSet);
+ sb.append(", devices=").append(deviceSet);
sb.append('}');
return sb.toString();
}
@@ -139,18 +139,19 @@ public final class CLProgramBuilder {
CLProgramBuilder that = (CLProgramBuilder) o;
- if (defineList != null ? !defineList.equals(that.defineList) : that.defineList != null) return false;
- if (deviceList != null ? !deviceList.equals(that.deviceList) : that.deviceList != null) return false;
- if (optionList != null ? !optionList.equals(that.optionList) : that.optionList != null) return false;
+ if (defineSet != null ? !defineSet.equals(that.defineSet) : that.defineSet != null) return false;
+ if (deviceSet != null ? !deviceSet.equals(that.deviceSet) : that.deviceSet != null) return false;
+ if (optionSet != null ? !optionSet.equals(that.optionSet) : that.optionSet != null) return false;
return true;
}
@Override
public int hashCode() {
- int result = optionList != null ? optionList.hashCode() : 0;
- result = 31 * result + (defineList != null ? defineList.hashCode() : 0);
- result = 31 * result + (deviceList != null ? deviceList.hashCode() : 0);
+ int result = optionSet != null ? optionSet.hashCode() : 0;
+ result = 31 * result + (defineSet != null ? defineSet.hashCode() : 0);
+ result = 31 * result + (deviceSet != null ? deviceSet.hashCode() : 0);
return result;
}
+
}
diff --git a/src/com/mbien/opencl/CLProgramConfiguration.java b/src/com/mbien/opencl/CLProgramConfiguration.java
new file mode 100644
index 00000000..e13ffd63
--- /dev/null
+++ b/src/com/mbien/opencl/CLProgramConfiguration.java
@@ -0,0 +1,38 @@
+package com.mbien.opencl;
+
+import java.util.Map;
+
+/**
+ * Configuration representing everything needed to build an OpenCL program (program included).
+ * @author Michael Bien
+ */
+public interface CLProgramConfiguration extends CLBuildConfiguration {
+
+ /**
+ * Builds or rebuilds a program.
+ */
+ public CLProgram build();
+
+ /**
+ * Returns the program.
+ */
+ public CLProgram getProgram();
+
+ /**
+ * Sets the program which should be build.
+ */
+ public CLProgramConfiguration setProgram(CLProgram program);
+
+
+ // overwrite with CLProgramConfiguration as return type
+ @Override public CLProgramConfiguration forDevice(CLDevice device);
+ @Override public CLProgramConfiguration forDevices(CLDevice... devices);
+ @Override public CLProgramConfiguration withDefine(String name);
+ @Override public CLProgramConfiguration withDefine(String name, Object value);
+ @Override public CLProgramConfiguration withDefines(String... names);
+ @Override public CLProgramConfiguration withDefines(Map<String, String> defines);
+ @Override public CLProgramConfiguration withOption(String option);
+ @Override public CLProgramConfiguration withOptions(String... options);
+ @Override public CLProgramConfiguration reset();
+
+}