From 3d033bfadaf569d2198de6ca5dfac855dc25ac35 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 1 Feb 2010 18:19:04 +0100 Subject: CLKernel can now optionally force 64bit args to passed as 32bit args to OpenCL. --- src/com/mbien/opencl/CLKernel.java | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/com/mbien/opencl/CLKernel.java') 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(); } -- cgit v1.2.3