summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-02-01 18:19:04 +0100
committerMichael Bien <[email protected]>2010-02-01 18:19:04 +0100
commit3d033bfadaf569d2198de6ca5dfac855dc25ac35 (patch)
treee915e77ec95a343e34271c344e15c533ab64cd5e /src
parente4e7dc4e7a63206c091cd3288adc6a7346f74191 (diff)
CLKernel can now optionally force 64bit args to passed as 32bit args to OpenCL.
Diffstat (limited to 'src')
-rw-r--r--src/com/mbien/opencl/CLKernel.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java
index 0dc9db19..7e2ee54e 100644
--- a/src/com/mbien/opencl/CLKernel.java
+++ b/src/com/mbien/opencl/CLKernel.java
@@ -31,6 +31,7 @@ public class CLKernel implements CLResource/*, Cloneable*/ {
private final ByteBuffer buffer;
private int argIndex;
+ private boolean force32BitArgs;
CLKernel(CLProgram program, long id) {
this.ID = id;
@@ -101,7 +102,11 @@ public class CLKernel implements CLResource/*, Cloneable*/ {
}
public CLKernel setArg(int argumentIndex, long value) {
- setArgument(argumentIndex, 8, wrap(value));
+ if(force32BitArgs) {
+ setArgument(argumentIndex, 4, wrap((int)value));
+ }else{
+ setArgument(argumentIndex, 8, wrap(value));
+ }
return this;
}
@@ -111,7 +116,11 @@ public class CLKernel implements CLResource/*, Cloneable*/ {
}
public CLKernel setArg(int argumentIndex, double value) {
- setArgument(argumentIndex, 8, wrap(value));
+ if(force32BitArgs) {
+ setArgument(argumentIndex, 4, wrap((float)value));
+ }else{
+ setArgument(argumentIndex, 8, wrap(value));
+ }
return this;
}
@@ -140,6 +149,22 @@ public class CLKernel implements CLResource/*, Cloneable*/ {
checkForError(ret, "error on clSetKernelArg");
}
+ /**
+ * Forces double and long arguments to be passed as float and int to the OpenCL kernel.
+ * This can be used in applications which want to mix kernels with different floating point precison.
+ */
+ public CLKernel setForce32BitArgs(boolean force) {
+ this.force32BitArgs = force;
+ return this;
+ }
+
+ /**
+ * @see #setForce32BitArgs(boolean)
+ */
+ public boolean isForce32BitArgsEnabled() {
+ return force32BitArgs;
+ }
+
private final Buffer wrap(float value) {
return buffer.putFloat(value).rewind();
}