aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/com/jogamp/opencl/CLCommandQueueTest.java295
1 files changed, 152 insertions, 143 deletions
diff --git a/test/com/jogamp/opencl/CLCommandQueueTest.java b/test/com/jogamp/opencl/CLCommandQueueTest.java
index cafdbc1..2147a6b 100644
--- a/test/com/jogamp/opencl/CLCommandQueueTest.java
+++ b/test/com/jogamp/opencl/CLCommandQueueTest.java
@@ -63,61 +63,61 @@ public class CLCommandQueueTest {
CLContext context = CLContext.create();
- 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);
- CLBuffer<ByteBuffer> clBufferD = 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();
-
- out.println(queue);
-
- final CLEventList events = new CLEventList(2);
+ try{
- out.println(events);
+ 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);
+ CLBuffer<ByteBuffer> clBufferD = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
- assertEquals(0, events.size());
+ fillBuffer(clBufferA.buffer, 12345);
+ fillBuffer(clBufferB.buffer, 67890);
- queue.putWriteBuffer(clBufferA, false, events) // write A
- .putWriteBuffer(clBufferB, false, events);// write B
+ CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build();
+ CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements);
+ CLCommandQueue queue = context.getDevices()[0].createCommandQueue();
- out.println(events);
+ out.println(queue);
- assertEquals(2, events.size());
- queue.putWaitForEvents(events, true);
+ final CLEventList events = new CLEventList(2);
- events.release();
- assertEquals(0, events.size());
+ out.println(events);
- vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferC); // C = A+B
- queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, events);
+ assertEquals(0, events.size());
- vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferD); // D = A+B
- queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, events);
+ queue.putWriteBuffer(clBufferA, false, events) // write A
+ .putWriteBuffer(clBufferB, false, events);// write B
- assertEquals(2, events.size());
- queue.putWaitForEvent(events, 0, false)
- .putWaitForEvent(events, 1, true);
+ out.println(events);
- queue.putReadBuffer(clBufferC, false)
- .putReadBuffer(clBufferD, true);
+ assertEquals(2, events.size());
+ queue.putWaitForEvents(events, true);
- events.release();
+ events.release();
+ assertEquals(0, events.size());
- checkIfEqual(clBufferC.buffer, clBufferD.buffer, elements);
+ vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferC); // C = A+B
+ queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, events);
+ vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferD); // D = A+B
+ queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, events);
- context.release();
+ assertEquals(2, events.size());
+ queue.putWaitForEvent(events, 0, false)
+ .putWaitForEvent(events, 1, true);
+ queue.putReadBuffer(clBufferC, false)
+ .putReadBuffer(clBufferD, true);
- out.println("results are valid");
+ events.release();
+ checkIfEqual(clBufferC.buffer, clBufferD.buffer, elements);
+ out.println("results are valid");
+ }finally{
+ context.release();
+ }
}
+
@Test
public void profilingEventsTest() throws IOException {
@@ -127,44 +127,48 @@ public class CLCommandQueueTest {
CLContext context = CLContext.create();
- 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);
+ try {
- fillBuffer(clBufferA.buffer, 12345);
- fillBuffer(clBufferB.buffer, 67890);
+ 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);
- CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build();
- CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements);
- CLCommandQueue queue = context.getDevices()[0].createCommandQueue(Mode.PROFILING_MODE);
+ fillBuffer(clBufferA.buffer, 12345);
+ fillBuffer(clBufferB.buffer, 67890);
- out.println(queue);
+ CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build();
+ CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements);
+ CLCommandQueue queue = context.getDevices()[0].createCommandQueue(Mode.PROFILING_MODE);
- queue.putWriteBuffer(clBufferA, true) // write A
- .putWriteBuffer(clBufferB, true);// write B
+ out.println(queue);
- final CLEventList events = new CLEventList(1);
+ queue.putWriteBuffer(clBufferA, true) // write A
+ .putWriteBuffer(clBufferB, true);// write B
- assertEquals(0, events.size());
+ final CLEventList events = new CLEventList(1);
- vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferC); // C = A+B
- queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, events);
+ assertEquals(0, events.size());
- assertEquals(1, events.size());
- CLEvent probe = events.getEvent(0);
- out.println(probe);
+ vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferC); // C = A+B
+ queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, events);
- queue.putWaitForEvents(events, true);
- assertEquals(CLEvent.ExecutionStatus.COMPLETE, probe.getStatus());
+ assertEquals(1, events.size());
+ CLEvent probe = events.getEvent(0);
+ out.println(probe);
- out.println(probe);
- long time = probe.getProfilingInfo(CLEvent.ProfilingCommand.END)
- - probe.getProfilingInfo(CLEvent.ProfilingCommand.START);
- out.println("time: "+time);
- assertTrue(time > 0);
+ queue.putWaitForEvents(events, true);
+ assertEquals(CLEvent.ExecutionStatus.COMPLETE, probe.getStatus());
- events.release();
- context.release();
+ out.println(probe);
+ long time = probe.getProfilingInfo(CLEvent.ProfilingCommand.END)
+ - probe.getProfilingInfo(CLEvent.ProfilingCommand.START);
+ out.println("time: "+time);
+ assertTrue(time > 0);
+
+ events.release();
+ }finally{
+ context.release();
+ }
}
@@ -261,26 +265,29 @@ public class CLCommandQueueTest {
CLContext context = CLContext.create();
- final CLUserEvent customEvent = CLUserEvent.create(context);
+ try{
- final CountDownLatch countdown = new CountDownLatch(1);
- customEvent.registerCallback(new CLEventListener() {
+ final CLUserEvent customEvent = CLUserEvent.create(context);
- public void eventStateChanged(CLEvent event, int status) {
- out.println("event received: "+event);
- assertEquals(event, customEvent);
- countdown.countDown();
- }
+ final CountDownLatch countdown = new CountDownLatch(1);
+ customEvent.registerCallback(new CLEventListener() {
- });
+ public void eventStateChanged(CLEvent event, int status) {
+ out.println("event received: "+event);
+ assertEquals(event, customEvent);
+ countdown.countDown();
+ }
- customEvent.setStatus(ExecutionStatus.COMPLETE);
- countdown.await(2, TimeUnit.SECONDS);
- assertEquals(countdown.getCount(), 0);
+ });
- customEvent.release();
+ customEvent.setStatus(ExecutionStatus.COMPLETE);
+ countdown.await(2, TimeUnit.SECONDS);
+ assertEquals(countdown.getCount(), 0);
- context.release();
+ customEvent.release();
+ }finally{
+ context.release();
+ }
}
@@ -293,101 +300,103 @@ public class CLCommandQueueTest {
CLContext context = CLContext.create();
- CLDevice[] devices = context.getDevices();
+ try{
- // ignore this test if we can't test in parallel
- if (devices.length < 2) {
- out.println("aborting test... need at least 2 devices");
- context.release();
- return;
- }
+ CLDevice[] devices = context.getDevices();
- final CLBuffer<ByteBuffer> clBufferC = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
- final CLBuffer<ByteBuffer> clBufferD = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
+ // ignore this test if we can't test in parallel
+ if (devices.length < 2) {
+ out.println("aborting test... need at least 2 devices");
+ return;
+ }
- final CLBuffer<ByteBuffer> clBufferA1 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
- final CLBuffer<ByteBuffer> clBufferB1 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
- final CLBuffer<ByteBuffer> clBufferA2 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
- final CLBuffer<ByteBuffer> clBufferB2 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
+ final CLBuffer<ByteBuffer> clBufferC = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
+ final CLBuffer<ByteBuffer> clBufferD = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
- CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build();
+ final CLBuffer<ByteBuffer> clBufferA1 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
+ final CLBuffer<ByteBuffer> clBufferB1 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
+ final CLBuffer<ByteBuffer> clBufferA2 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
+ final CLBuffer<ByteBuffer> clBufferB2 = context.createByteBuffer(elements * SIZEOF_INT, Mem.READ_ONLY);
- //two independent kernel instances
- final CLKernel vectorAddKernel1 = program.createCLKernel("VectorAddGM").setArg(3, elements);
- final CLKernel vectorAddKernel2 = program.createCLKernel("VectorAddGM").setArg(3, elements);
+ CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build();
- final CLCommandQueue queue1 = devices[0].createCommandQueue();
- final CLCommandQueue queue2 = devices[1].createCommandQueue();
+ //two independent kernel instances
+ final CLKernel vectorAddKernel1 = program.createCLKernel("VectorAddGM").setArg(3, elements);
+ final CLKernel vectorAddKernel2 = program.createCLKernel("VectorAddGM").setArg(3, elements);
- out.println(queue1);
- out.println(queue2);
+ final CLCommandQueue queue1 = devices[0].createCommandQueue();
+ final CLCommandQueue queue2 = devices[1].createCommandQueue();
- fillBuffer(clBufferC.buffer, 12345);
+ out.println(queue1);
+ out.println(queue2);
+ fillBuffer(clBufferC.buffer, 12345);
- final MultiQueueBarrier barrier = new MultiQueueBarrier(2);
- Thread thread1 = new Thread("C") {
+ final MultiQueueBarrier barrier = new MultiQueueBarrier(2);
- @Override
- public void run() {
+ Thread thread1 = new Thread("C") {
- fillBuffer(clBufferA1.buffer, 12345);
- fillBuffer(clBufferB1.buffer, 67890);
+ @Override
+ public void run() {
-// System.out.println("C buffer");
- queue1.putWriteBuffer(clBufferA1, false) // write A
- .putWriteBuffer(clBufferB1, false); // write B
+ fillBuffer(clBufferA1.buffer, 12345);
+ fillBuffer(clBufferB1.buffer, 67890);
-// System.out.println("C args");
- vectorAddKernel1.setArgs(clBufferA1, clBufferB1, clBufferC); // C = A+B
+ // System.out.println("C buffer");
+ queue1.putWriteBuffer(clBufferA1, false) // write A
+ .putWriteBuffer(clBufferB1, false); // write B
-// System.out.println("C kernels");
- CLEventList events1 = new CLEventList(2);
- queue1.put1DRangeKernel(vectorAddKernel1, 0, elements, groupSize, events1)
- .putReadBuffer(clBufferC, false, events1);
+ // System.out.println("C args");
+ vectorAddKernel1.setArgs(clBufferA1, clBufferB1, clBufferC); // C = A+B
- barrier.waitFor(queue1, events1);
+ // System.out.println("C kernels");
+ CLEventList events1 = new CLEventList(2);
+ queue1.put1DRangeKernel(vectorAddKernel1, 0, elements, groupSize, events1)
+ .putReadBuffer(clBufferC, false, events1);
- }
- };
+ barrier.waitFor(queue1, events1);
- Thread thread2 = new Thread("D") {
+ }
+ };
- @Override
- public void run() {
+ Thread thread2 = new Thread("D") {
- fillBuffer(clBufferA2.buffer, 12345);
- fillBuffer(clBufferB2.buffer, 67890);
+ @Override
+ public void run() {
-// System.out.println("D buffer");
- queue2.putWriteBuffer(clBufferA2, false) // write A
- .putWriteBuffer(clBufferB2, false); // write B
+ fillBuffer(clBufferA2.buffer, 12345);
+ fillBuffer(clBufferB2.buffer, 67890);
-// System.out.println("D args");
- vectorAddKernel2.setArgs(clBufferA2, clBufferB2, clBufferD); // D = A+B
+ // System.out.println("D buffer");
+ queue2.putWriteBuffer(clBufferA2, false) // write A
+ .putWriteBuffer(clBufferB2, false); // write B
-// System.out.println("D kernels");
- CLEventList events2 = new CLEventList(2);
- queue2.put1DRangeKernel(vectorAddKernel2, 0, elements, groupSize, events2)
- .putReadBuffer(clBufferD, false, events2);
+ // System.out.println("D args");
+ vectorAddKernel2.setArgs(clBufferA2, clBufferB2, clBufferD); // D = A+B
- barrier.waitFor(queue2, events2);
+ // System.out.println("D kernels");
+ CLEventList events2 = new CLEventList(2);
+ queue2.put1DRangeKernel(vectorAddKernel2, 0, elements, groupSize, events2);
+ queue2.putReadBuffer(clBufferD, false, events2);
- }
- };
+ barrier.waitFor(queue2, events2);
- out.println("starting threads");
- thread1.start();
- thread2.start();
- barrier.await();
- out.println("done");
+ }
+ };
- checkIfEqual(clBufferC.buffer, clBufferD.buffer, elements);
+ out.println("starting threads");
+ thread1.start();
+ thread2.start();
+ assertTrue(barrier.await(5, TimeUnit.SECONDS));
+ out.println("done");
- context.release();
+ checkIfEqual(clBufferC.buffer, clBufferD.buffer, elements);
+ out.println("results are valid");
- out.println("results are valid");
+ }finally{
+ context.release();
+ }
}
}