summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/jogamp/opencl/CLKernel.java68
-rw-r--r--src/com/jogamp/opencl/CLProgram.java2
-rw-r--r--test/com/jogamp/opencl/CLProgramTest.java19
3 files changed, 65 insertions, 24 deletions
diff --git a/src/com/jogamp/opencl/CLKernel.java b/src/com/jogamp/opencl/CLKernel.java
index 78c5fc93..4c898b4b 100644
--- a/src/com/jogamp/opencl/CLKernel.java
+++ b/src/com/jogamp/opencl/CLKernel.java
@@ -62,28 +62,36 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
private boolean force32BitArgs;
CLKernel(CLProgram program, long id) {
+ this(program, null, id);
+ }
+
+ CLKernel(CLProgram program, String name, long id) {
super(program.getContext(), id);
+
this.program = program;
this.buffer = Buffers.newDirectByteBuffer((is32Bit()?4:8)*3);
- NativeSizeBuffer size = NativeSizeBuffer.allocateDirect(1);
-
- // get function name
- int ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, 0, null, size);
- checkForError(ret, "error while asking for kernel function name");
+ if(name == null) {
+ // get function name
+ NativeSizeBuffer size = NativeSizeBuffer.wrap(buffer);
+ int ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, 0, null, size);
+ checkForError(ret, "error while asking for kernel function name");
- ByteBuffer bb = Buffers.newDirectByteBuffer((int)size.get(0));
+ ByteBuffer bb = Buffers.newDirectByteBuffer((int)size.get(0));
- ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, bb.capacity(), bb, null);
- checkForError(ret, "error while asking for kernel function name");
-
- this.name = CLUtil.clString2JavaString(bb, bb.capacity());
+ ret = cl.clGetKernelInfo(ID, CL_KERNEL_FUNCTION_NAME, bb.capacity(), bb, null);
+ checkForError(ret, "error while asking for kernel function name");
+
+ this.name = CLUtil.clString2JavaString(bb, bb.capacity());
+ }else{
+ this.name = name;
+ }
// get number of arguments
- ret = cl.clGetKernelInfo(ID, CL_KERNEL_NUM_ARGS, bb.capacity(), bb, null);
+ int ret = cl.clGetKernelInfo(ID, CL_KERNEL_NUM_ARGS, buffer.capacity(), buffer, null);
checkForError(ret, "error while asking for number of function arguments.");
- numArgs = bb.getInt(0);
+ numArgs = buffer.getInt(0);
}
@@ -93,32 +101,38 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
// }
public CLKernel putArg(CLMemory<?> value) {
- setArg(argIndex++, value);
+ setArg(argIndex, value);
+ argIndex++;
return this;
}
public CLKernel putArg(int value) {
- setArg(argIndex++, value);
+ setArg(argIndex, value);
+ argIndex++;
return this;
}
public CLKernel putArg(long value) {
- setArg(argIndex++, value);
+ setArg(argIndex, value);
+ argIndex++;
return this;
}
public CLKernel putArg(float value) {
- setArg(argIndex++, value);
+ setArg(argIndex, value);
+ argIndex++;
return this;
}
public CLKernel putArg(double value) {
- setArg(argIndex++, value);
+ setArg(argIndex, value);
+ argIndex++;
return this;
}
public CLKernel putNullArg(int size) {
- setNullArg(argIndex++, size);
+ setNullArg(argIndex, size);
+ argIndex++;
return this;
}
@@ -128,11 +142,21 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
return this;
}
+ /**
+ * Resets the argument index to 0.
+ */
public CLKernel rewind() {
argIndex = 0;
return this;
}
+ /**
+ * Returns the argument index used in the relative putArt(...) methods.
+ */
+ public int position() {
+ return argIndex;
+ }
+
// public CLKernel setArg(int argumentIndex, Buffer value) {
// setArgument(argumentIndex, CLMemory.sizeOfBufferElem(value)*value.capacity(), value);
// return this;
@@ -224,19 +248,19 @@ public class CLKernel extends CLObject implements CLResource, Cloneable {
}
private Buffer wrap(float value) {
- return buffer.putFloat(value).rewind();
+ return buffer.putFloat(0, value);
}
private Buffer wrap(double value) {
- return buffer.putDouble(value).rewind();
+ return buffer.putDouble(0, value);
}
private Buffer wrap(int value) {
- return buffer.putInt(value).rewind();
+ return buffer.putInt(0, value);
}
private Buffer wrap(long value) {
- return buffer.putLong(value).rewind();
+ return buffer.putLong(0, value);
}
/**
diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java
index 1b1dd1d5..e8706a73 100644
--- a/src/com/jogamp/opencl/CLProgram.java
+++ b/src/com/jogamp/opencl/CLProgram.java
@@ -407,7 +407,7 @@ public class CLProgram extends CLObject implements CLResource {
throw newException(err[0], "unable to create Kernel with name: "+kernelName);
}
- CLKernel kernel = new CLKernel(this, id);
+ CLKernel kernel = new CLKernel(this, kernelName, id);
kernels.add(kernel);
return kernel;
}
diff --git a/test/com/jogamp/opencl/CLProgramTest.java b/test/com/jogamp/opencl/CLProgramTest.java
index 49c25180..a3ee26f3 100644
--- a/test/com/jogamp/opencl/CLProgramTest.java
+++ b/test/com/jogamp/opencl/CLProgramTest.java
@@ -268,7 +268,7 @@ public class CLProgramTest {
@Test
public void kernelTest() {
- String source = "__attribute__((reqd_work_group_size(1, 1, 1))) kernel void foo(void) { }\n";
+ String source = "__attribute__((reqd_work_group_size(1, 1, 1))) kernel void foo(float a, int b) { }\n";
CLContext context = CLContext.create();
@@ -287,6 +287,23 @@ public class CLProgramTest {
assertEquals(1, wgs[1]);
assertEquals(1, wgs[2]);
+ // put args test
+ assertEquals(0, kernel.position());
+
+ kernel.putArg(1.0f);
+ assertEquals(1, kernel.position());
+
+ kernel.putArg(2);
+ assertEquals(2, kernel.position());
+
+ try{
+ kernel.putArg(3);
+ fail("exception not thrown");
+ }catch (IndexOutOfBoundsException expected){ }
+
+ assertEquals(2, kernel.position());
+ assertEquals(0, kernel.rewind().position());
+
}finally{
context.release();
}