diff options
Diffstat (limited to 'test/com/mbien/opencl')
-rw-r--r-- | test/com/mbien/opencl/CLCommandQueueTest.java (renamed from test/com/mbien/opencl/CLConcurrencyTest.java) | 170 | ||||
-rw-r--r-- | test/com/mbien/opencl/CLProgramTest.java | 14 | ||||
-rw-r--r-- | test/com/mbien/opencl/HighLevelBindingTest.java | 41 |
3 files changed, 164 insertions, 61 deletions
diff --git a/test/com/mbien/opencl/CLConcurrencyTest.java b/test/com/mbien/opencl/CLCommandQueueTest.java index e7a244c3..b52ef5ed 100644 --- a/test/com/mbien/opencl/CLConcurrencyTest.java +++ b/test/com/mbien/opencl/CLCommandQueueTest.java @@ -1,52 +1,82 @@ package com.mbien.opencl; +import com.mbien.opencl.CLCommandQueue.Mode; import com.mbien.opencl.CLMemory.Mem; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.EnumSet; import org.junit.Test; import static org.junit.Assert.*; import static java.lang.System.*; import static com.mbien.opencl.TestUtils.*; +import static com.mbien.opencl.CLEvent.*; import static com.sun.gluegen.runtime.BufferFactory.*; /** * * @author Michael Bien */ -public class CLConcurrencyTest { +public class CLCommandQueueTest { - @Test - public void testEvents() throws IOException { + private final int groupSize = 256; + + @Test + public void enumsTest() { + + //CLCommandQueueEnums + EnumSet<Mode> queueMode = Mode.valuesOf(CL.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL.CL_QUEUE_PROFILING_ENABLE); + assertTrue(queueMode.contains(Mode.OUT_OF_ORDER_EXEC_MODE)); + assertTrue(queueMode.contains(Mode.PROFILING_MODE)); + + assertNotNull(Mode.valuesOf(0)); + assertEquals(0, Mode.valuesOf(0).size()); + for (Mode mode : Mode.values()) { + assertEquals(mode, Mode.valueOf(mode.QUEUE_MODE)); + } + + // CLEvent enums + for (ProfilingCommand cmd : ProfilingCommand.values()) { + assertEquals(cmd, ProfilingCommand.valueOf(cmd.COMMAND)); + } + + for (CommandType type : CommandType.values()) { + assertEquals(type, CommandType.valueOf(type.TYPE)); + } + + for (ExecutionStatus status : ExecutionStatus.values()) { + assertEquals(status, ExecutionStatus.valueOf(status.STATUS)); + } + + } + + @Test + public void eventsTest() throws IOException { out.println(" - - - event synchronization test - - - "); - final int groupSize = 256; - final int elements = roundUp(groupSize, ONE_MB/SIZEOF_INT * 5); // 5MB per buffer + final int elements = roundUp(groupSize, ONE_MB / SIZEOF_INT * 5); // 5MB per buffer 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); + 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); - + CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements); CLCommandQueue queue = context.getCLDevices()[0].createCommandQueue(); final CLEventList events = new CLEventList(2); - + assertEquals(0, events.size()); - queue.putWriteBuffer(clBufferA, false, events) // write A - .putWriteBuffer(clBufferB, false, events); // write B + queue.putWriteBuffer(clBufferA, false, events) // write A + .putWriteBuffer(clBufferB, false, events);// write B assertEquals(2, events.size()); queue.putWaitForEvents(events, true); @@ -70,56 +100,100 @@ public class CLConcurrencyTest { events.release(); checkIfEqual(clBufferC.buffer, clBufferD.buffer, elements); - + context.release(); out.println("results are valid"); - } + } + @Test + public void profilingEventsTest() throws IOException { + + out.println(" - - - event synchronization test - - - "); + + final int elements = roundUp(groupSize, ONE_MB / SIZEOF_INT * 5); // 5MB per buffer + + 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); + + 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.getCLDevices()[0].createCommandQueue(Mode.PROFILING_MODE); - @Test - public void concurrencyTest() throws IOException, InterruptedException { + queue.putWriteBuffer(clBufferA, true) // write A + .putWriteBuffer(clBufferB, true);// write B + + final CLEventList events = new CLEventList(1); + + assertEquals(0, events.size()); + + vectorAddKernel.setArgs(clBufferA, clBufferB, clBufferC); // C = A+B + queue.put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, events); + + assertEquals(1, events.size()); + CLEvent probe = events.getEvent(0); + out.println(probe); + + queue.putWaitForEvents(events, true); + assertEquals(CLEvent.ExecutionStatus.COMPLETE, probe.getStatus()); + + out.println(probe); + long time = probe.getProfilingInfo(CLEvent.ProfilingCommand.END) + - probe.getProfilingInfo(CLEvent.ProfilingCommand.START); + out.println("time: "+time); + assertTrue(time > 0); + + events.release(); + context.release(); + + } + + @Test + public void concurrencyTest() throws IOException, InterruptedException { out.println(" - - - QueueBarrier test - - - "); - final int elements = ONE_MB/SIZEOF_INT * 10; // 20MB per buffer + final int elements = ONE_MB / SIZEOF_INT * 10; // 20MB per buffer CLContext context = CLContext.create(); CLDevice[] devices = context.getCLDevices(); - if(devices.length < 2) { + if (devices.length < 2) { out.println("aborting test... need at least 2 devices"); context.release(); return; } - final CLBuffer<ByteBuffer> clBufferC = context.createByteBuffer(elements*SIZEOF_INT, Mem.READ_ONLY); - final CLBuffer<ByteBuffer> clBufferD = 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); - 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> 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); CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); - final CLKernel vectorAddKernel1 = program.createCLKernel("VectorAddGM") - .setArg(3, elements); - - final CLKernel vectorAddKernel2 = program.createCLKernel("VectorAddGM") - .setArg(3, elements); - + final CLKernel vectorAddKernel1 = program.createCLKernel("VectorAddGM").setArg(3, elements); + final CLKernel vectorAddKernel2 = program.createCLKernel("VectorAddGM").setArg(3, elements); int secondDevice = devices.length > 1 ? 1 : 0; final CLCommandQueue queue1 = devices[0 ].createCommandQueue(); final CLCommandQueue queue2 = devices[secondDevice].createCommandQueue(); - if(secondDevice > 0) - System.out.println("using two devices"); + if (secondDevice > 0) { + System.out.println("using two devices"); + } final QueueBarrier barrier = new QueueBarrier(2); @@ -132,21 +206,20 @@ public class CLConcurrencyTest { fillBuffer(clBufferB1.buffer, 67890); // System.out.println("C buffer"); - queue1.putWriteBuffer(clBufferA1, false) // write A - .putWriteBuffer(clBufferB1, true); // write B + queue1.putWriteBuffer(clBufferA1, false) // write A + .putWriteBuffer(clBufferB1, true); // write B // System.out.println("C args"); vectorAddKernel1.setArgs(clBufferA1, clBufferB1, clBufferC); // C = A+B // System.out.println("C kernels"); CLEventList events1 = new CLEventList(2); - queue1.put1DRangeKernel(vectorAddKernel1, 0, elements, 256, events1) + queue1.put1DRangeKernel(vectorAddKernel1, 0, elements, groupSize, events1) .putReadBuffer(clBufferC, false, events1); barrier.waitFor(queue1, events1); } - }; Thread thread2 = new Thread("D") { @@ -156,10 +229,10 @@ public class CLConcurrencyTest { fillBuffer(clBufferA2.buffer, 12345); fillBuffer(clBufferB2.buffer, 67890); - + // System.out.println("D buffer"); - queue2.putWriteBuffer(clBufferA2, false) // write A - .putWriteBuffer(clBufferB2, true); // write B + queue2.putWriteBuffer(clBufferA2, false) // write A + .putWriteBuffer(clBufferB2, true); // write B // System.out.println("D args"); vectorAddKernel2.setArgs(clBufferA2, clBufferB2, clBufferD); // D = A+B @@ -172,7 +245,6 @@ public class CLConcurrencyTest { barrier.waitFor(queue2, events2); } - }; out.println("starting threads"); @@ -185,13 +257,7 @@ public class CLConcurrencyTest { context.release(); -// vectorAddKernel2.release(); - out.println("results are valid"); - } - - - - -}
\ No newline at end of file + } +} diff --git a/test/com/mbien/opencl/CLProgramTest.java b/test/com/mbien/opencl/CLProgramTest.java index 01fc1504..84e0eed5 100644 --- a/test/com/mbien/opencl/CLProgramTest.java +++ b/test/com/mbien/opencl/CLProgramTest.java @@ -1,5 +1,6 @@ package com.mbien.opencl; +import com.mbien.opencl.CLProgram.Status; import java.io.IOException; import java.util.Map; import org.junit.Test; @@ -7,6 +8,7 @@ import org.junit.Test; import static org.junit.Assert.*; import static java.lang.System.*; import static com.mbien.opencl.CLProgram.CompilerOptions.*; +import static com.mbien.opencl.CLProgram.Status.*; /** * @@ -15,6 +17,15 @@ import static com.mbien.opencl.CLProgram.CompilerOptions.*; public class CLProgramTest { @Test + public void enumsTest() { + + // CLProgram enums + for (Status e : Status.values()) { + assertEquals(e, Status.valueOf(e.STATUS)); + } + } + + @Test public void rebuildProgramTest() throws IOException { out.println(" - - - CLProgramTest; rebuild program test - - - "); @@ -116,7 +127,8 @@ public class CLProgramTest { assertEquals(program.getSource().length(), 0); try{ - program.createCLKernels(); + Map<String, CLKernel> kernels = program.createCLKernels(); + fail("expected an exception from createCLKernels but got: "+kernels); }catch(CLException ex) { // expected, not build yet } diff --git a/test/com/mbien/opencl/HighLevelBindingTest.java b/test/com/mbien/opencl/HighLevelBindingTest.java index ec3586d7..21014e8a 100644 --- a/test/com/mbien/opencl/HighLevelBindingTest.java +++ b/test/com/mbien/opencl/HighLevelBindingTest.java @@ -3,6 +3,9 @@ package com.mbien.opencl; import com.mbien.opencl.CLMemory.Mem; import com.mbien.opencl.CLCommandQueue.Mode; import com.mbien.opencl.CLDevice.FPConfig; +import com.mbien.opencl.CLDevice.GlobalMemCacheType; +import com.mbien.opencl.CLDevice.LocalMemType; +import com.mbien.opencl.CLDevice.Type; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Arrays; @@ -31,20 +34,42 @@ public class HighLevelBindingTest { } @Test - public void contextlessTest() { - - out.println(" - - - highLevelTest; contextless - - - "); - + public void enumsTest() { + // enum tests final EnumSet<FPConfig> singleFPConfig = FPConfig.valuesOf(CL.CL_FP_DENORM | CL.CL_FP_ROUND_TO_INF); assertEquals(0, FPConfig.valuesOf(0).size()); assertTrue(singleFPConfig.contains(FPConfig.DENORM)); assertTrue(singleFPConfig.contains(FPConfig.ROUND_TO_INF)); - final EnumSet<Mode> queueMode = Mode.valuesOf(CL.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL.CL_QUEUE_PROFILING_ENABLE); - assertEquals(0, Mode.valuesOf(0).size()); - assertTrue(queueMode.contains(Mode.OUT_OF_ORDER_EXEC_MODE)); - assertTrue(queueMode.contains(Mode.PROFILING_MODE)); + // CLDevice enums + for (FPConfig e : FPConfig.values()) { + EnumSet<FPConfig> set = FPConfig.valuesOf(e.CONFIG); + assertTrue(set.contains(e)); + } + for (GlobalMemCacheType e : GlobalMemCacheType.values()) { + assertEquals(e, GlobalMemCacheType.valueOf(e.TYPE)); + } + for (LocalMemType e : LocalMemType.values()) { + assertEquals(e, LocalMemType.valueOf(e.TYPE)); + } + for (Type e : Type.values()) { + assertEquals(e, Type.valueOf(e.TYPE)); + } + + // CLMemory enums + for (Mem e : Mem.values()) { + assertEquals(e, Mem.valueOf(e.CONFIG)); + } + + } + + + + @Test + public void contextlessTest() { + + out.println(" - - - highLevelTest; contextless - - - "); // platform/device info tests CLPlatform[] clPlatforms = CLPlatform.listCLPlatforms(); |