diff options
-rw-r--r-- | src/com/jogamp/opencl/CLEvent.java | 16 | ||||
-rw-r--r-- | src/com/jogamp/opencl/CLEventList.java | 10 | ||||
-rw-r--r-- | src/com/jogamp/opencl/CLUserEvent.java | 59 | ||||
-rw-r--r-- | test/com/jogamp/opencl/CLCommandQueueTest.java | 59 |
4 files changed, 142 insertions, 2 deletions
diff --git a/src/com/jogamp/opencl/CLEvent.java b/src/com/jogamp/opencl/CLEvent.java index bf4ac690..5b71cc29 100644 --- a/src/com/jogamp/opencl/CLEvent.java +++ b/src/com/jogamp/opencl/CLEvent.java @@ -40,6 +40,13 @@ public class CLEvent extends CLObject implements CLResource { public ExecutionStatus getStatus() { return ExecutionStatus.valueOf(getStatusCode()); } + + /** + * Returns true only if {@link #getStatus} returns {@link ExecutionStatus#COMPLETE}. + */ + public boolean isComplete() { + return ExecutionStatus.COMPLETE.equals(getStatus()); + } public int getStatusCode() { return (int)eventInfo.getLong(CL_EVENT_COMMAND_EXECUTION_STATUS); @@ -57,7 +64,7 @@ public class CLEvent extends CLObject implements CLResource { @Override public String toString() { - return "CLEvent [id: " + ID + return getClass().getSimpleName()+" [id: " + ID + " name: " + getType() + " status: " + getStatus()+"]"; } @@ -237,8 +244,13 @@ public class CLEvent extends CLObject implements CLResource { MAP_IMAGE(CL_COMMAND_MAP_IMAGE), UNMAP_MEM_OBJECT(CL_COMMAND_UNMAP_MEM_OBJECT), MARKER(CL_COMMAND_MARKER), + READ_BUFFER_RECT(CL_COMMAND_READ_BUFFER_RECT), + WRITE_BUFFER_RECT(CL_COMMAND_WRITE_BUFFER_RECT), + COPY_BUFFER_RECT(CL_COMMAND_COPY_BUFFER_RECT), + USER(CL_COMMAND_USER), ACQUIRE_GL_OBJECTS(CL_COMMAND_ACQUIRE_GL_OBJECTS), - RELEASE_GL_OBJECTS(CL_COMMAND_RELEASE_GL_OBJECTS); + RELEASE_GL_OBJECTS(CL_COMMAND_RELEASE_GL_OBJECTS), + GL_FENCE_SYNC_OBJECT_KHR(CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR); /** * Value of wrapped OpenCL command type. diff --git a/src/com/jogamp/opencl/CLEventList.java b/src/com/jogamp/opencl/CLEventList.java index b9b4cd4b..43f2b36b 100644 --- a/src/com/jogamp/opencl/CLEventList.java +++ b/src/com/jogamp/opencl/CLEventList.java @@ -19,6 +19,16 @@ public final class CLEventList implements CLResource, Iterable<CLEvent> { this.IDs = PointerBuffer.allocateDirect(capacity); } + public CLEventList(CLEvent... events) { + this.events = events; + this.IDs = PointerBuffer.allocateDirect(events.length); + for (CLEvent event : events) { + IDs.put(event.ID); + } + IDs.rewind(); + size = events.length; + } + void createEvent(CLContext context) { if(events[size] != null) diff --git a/src/com/jogamp/opencl/CLUserEvent.java b/src/com/jogamp/opencl/CLUserEvent.java new file mode 100644 index 00000000..56fb7a0c --- /dev/null +++ b/src/com/jogamp/opencl/CLUserEvent.java @@ -0,0 +1,59 @@ +/* + * Created on Wednesday, June 16 2010 18:05 + */ + +package com.jogamp.opencl; + +import static com.jogamp.opencl.CLException.*; +import static com.jogamp.opencl.CL.*; + +/** + * Custom, user controlled event. + * @see CLEvent + * @author Michael Bien + */ +public class CLUserEvent extends CLEvent { + + CLUserEvent(CLContext context, long ID) { + super(context, ID); + } + + /** + * Creates a new user event. + */ + public static CLUserEvent create(CLContext context) { + int[] error = new int[1]; + long ID = context.cl.clCreateUserEvent(context.ID, error, 0); + checkForError(error[0], "can not create user event."); + return new CLUserEvent(context, ID); + } + + /** + * Sets the event execution status. + * Calls {@native clSetUserEventStatus}. + */ + public CLUserEvent setStatus(CLEvent.ExecutionStatus status) { + int err = cl.clSetUserEventStatus(ID, status.STATUS); + if(err != CL_SUCCESS) { + newException(err, "can not set status "+status); + } + return this; + } + + /** + * Sets this event's status to {@link CLEvent.ExecutionStatus#COMPLETE}. + * @see #setStatus(com.jogamp.opencl.CLEvent.ExecutionStatus) + */ + public CLUserEvent setComplete() { + return setStatus(ExecutionStatus.COMPLETE); + } + + /** + * Returns {@link CLEvent.CommandType#USER}. + */ + @Override + public CommandType getType() { + return CommandType.USER; + } + +} diff --git a/test/com/jogamp/opencl/CLCommandQueueTest.java b/test/com/jogamp/opencl/CLCommandQueueTest.java index 9070b268..3df894e5 100644 --- a/test/com/jogamp/opencl/CLCommandQueueTest.java +++ b/test/com/jogamp/opencl/CLCommandQueueTest.java @@ -162,6 +162,65 @@ public class CLCommandQueueTest { } @Test + public void customEventsTest() throws IOException, InterruptedException { + out.println(" - - - user events test - - - "); + + final int elements = roundUp(groupSize, ONE_MB / SIZEOF_INT * 5); // 5MB per buffer + + final CLContext context = CLContext.create(); + + try{ + + CLBuffer<ByteBuffer> clBufferA = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY); + CLBuffer<ByteBuffer> clBufferB = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY); + CLBuffer<ByteBuffer> clBufferC = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY); + + fillBuffer(clBufferA.buffer, 12345); + fillBuffer(clBufferB.buffer, 67890); + + CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); + CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements); + CLCommandQueue queue = context.getDevices()[0].createCommandQueue(); + + queue.putWriteBuffer(clBufferA, true) // write A + .putWriteBuffer(clBufferB, true);// write B + + vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferC); // C = A+B + + // the interesting part... + + CLUserEvent condition = CLUserEvent.create(context); + assertEquals(CommandType.USER, condition.getType()); + assertEquals(ExecutionStatus.SUBMITTED, condition.getStatus()); + out.println(condition); + + final CLEventList conditions = new CLEventList(condition); + final CLEventList events = new CLEventList(1); + assertEquals(1, conditions.size()); + assertEquals(1, conditions.capacity()); + assertEquals(0, events.size()); + assertEquals(1, events.capacity()); + + queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, conditions, events); + assertEquals(1, events.size()); + + Thread.sleep(1000); + final CLEvent status = events.getEvent(0); + + assertEquals(ExecutionStatus.QUEUED, status.getStatus()); + condition.setComplete(); + assertTrue(condition.isComplete()); + + queue.finish(); + assertTrue(status.isComplete()); + + }finally{ + context.release(); + } + + } + + @Test public void concurrencyTest() throws IOException, InterruptedException { out.println(" - - - QueueBarrier test - - - "); |