diff options
author | Michael Bien <[email protected]> | 2010-01-07 23:30:30 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-01-07 23:30:30 +0100 |
commit | 14d666509596e5b954a5c20e0be9f5826a3ce733 (patch) | |
tree | b4eaab6c3c6fde65628a3a2240e4d459760b98d3 /src | |
parent | 9575f39cc204dc31d85233ecf4b09443190c3673 (diff) |
added put/rewind idiom to CLKernel for function arguments.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/mbien/opencl/CLKernel.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLKernel.java b/src/com/mbien/opencl/CLKernel.java index 544e2752..87474878 100644 --- a/src/com/mbien/opencl/CLKernel.java +++ b/src/com/mbien/opencl/CLKernel.java @@ -24,6 +24,8 @@ public class CLKernel implements CLResource { private final CLProgram program; private final CL cl; + private int argIndex; + CLKernel(CLProgram program, long id) { this.ID = id; this.program = program; @@ -49,6 +51,37 @@ public class CLKernel implements CLResource { numArgs = (int)longArray[0]; } + + public CLKernel putArg(CLBuffer<?> value) { + setArg(argIndex++, value); + return this; + } + + public CLKernel putArg(int value) { + setArg(argIndex++, value); + return this; + } + + public CLKernel putArg(long value) { + setArg(argIndex++, value); + return this; + } + + public CLKernel putArg(float value) { + setArg(argIndex++, value); + return this; + } + + public CLKernel putArg(double value) { + setArg(argIndex++, value); + return this; + } + + public CLKernel putArgs(CLBuffer<?>... values) { + setArgs(argIndex, values); + argIndex += values.length; + return this; + } public CLKernel setArg(int argumentIndex, CLBuffer<?> value) { setArgument(argumentIndex, CPU.is32Bit()?4:8, wrap(value.ID)); @@ -75,6 +108,17 @@ public class CLKernel implements CLResource { return this; } + public CLKernel setArgs(CLBuffer<?>... values) { + setArgs(0, values); + return this; + } + + private final void setArgs(int startIndex, CLBuffer<?>... values) { + for (int i = 0; i < values.length; i++) { + setArg(i+startIndex, values[i]); + } + } + private final void setArgument(int argumentIndex, int size, Buffer value) { if(argumentIndex >= numArgs || argumentIndex < 0) { throw new IndexOutOfBoundsException("kernel "+ toString() +" has "+numArgs+ @@ -105,6 +149,11 @@ public class CLKernel implements CLResource { return BufferFactory.newDirectByteBuffer(8).putLong(value).rewind(); } + public CLKernel rewind() { + argIndex = 0; + return this; + } + /** * Releases all resources of this kernel from its context. */ |