diff options
author | Michael Bien <[email protected]> | 2011-04-04 19:04:29 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-04-04 19:04:29 +0200 |
commit | 6612391c7ad8309ebd315cdf2a91a71f11793a61 (patch) | |
tree | 02374fe2a54bdde53c46de193123d0626d3807a4 /test/com/jogamp/opencl | |
parent | 38a1408b585fd3fe7b274708b531e98d73f1ac0c (diff) |
fixed a bug which used a wrong eventlist offset under certain conditions and added a regression test.
Diffstat (limited to 'test/com/jogamp/opencl')
-rw-r--r-- | test/com/jogamp/opencl/CLCommandQueueTest.java | 71 | ||||
-rw-r--r-- | test/com/jogamp/opencl/testkernels.cl | 23 |
2 files changed, 85 insertions, 9 deletions
diff --git a/test/com/jogamp/opencl/CLCommandQueueTest.java b/test/com/jogamp/opencl/CLCommandQueueTest.java index e40d07e4..1d47ced6 100644 --- a/test/com/jogamp/opencl/CLCommandQueueTest.java +++ b/test/com/jogamp/opencl/CLCommandQueueTest.java @@ -35,8 +35,11 @@ import java.util.concurrent.CountDownLatch; import com.jogamp.opencl.util.MultiQueueBarrier; import com.jogamp.opencl.CLCommandQueue.Mode; import com.jogamp.opencl.CLMemory.Mem; +import com.jogamp.opencl.util.CLDeviceFilters; +import com.jogamp.opencl.util.CLPlatformFilters; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.IntBuffer; import java.util.EnumSet; import java.util.concurrent.TimeUnit; import org.junit.Test; @@ -47,6 +50,7 @@ import static com.jogamp.opencl.TestUtils.*; import static com.jogamp.opencl.CLEvent.*; import static com.jogamp.opencl.CLVersion.*; import static com.jogamp.common.nio.Buffers.*; +import static com.jogamp.opencl.CLCommandQueue.Mode.*; /** * @@ -62,8 +66,8 @@ public class CLCommandQueueTest { //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_MODE)); - assertTrue(queueMode.contains(Mode.PROFILING_MODE)); + assertTrue(queueMode.contains(OUT_OF_ORDER_MODE)); + assertTrue(queueMode.contains(PROFILING_MODE)); assertNotNull(Mode.valuesOf(0)); assertEquals(0, Mode.valuesOf(0).size()); @@ -151,6 +155,67 @@ public class CLCommandQueueTest { context.release(); } } + + @Test + public void eventConditionsTest() throws IOException { + + out.println(" - - - event conditions test - - - "); + + CLPlatform platform = CLPlatform.getDefault(CLPlatformFilters.queueMode(OUT_OF_ORDER_MODE)); + + CLDevice device = null; + // we can still test this with in-order queues + if(platform == null) { + device = CLPlatform.getDefault().getMaxFlopsDevice(); + }else{ + device = platform.getMaxFlopsDevice(CLDeviceFilters.queueMode(OUT_OF_ORDER_MODE)); + } + + CLContext context = CLContext.create(device); + + try{ + + CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); + + CLBuffer<IntBuffer> buffer = context.createBuffer(newDirectIntBuffer(new int[]{ 1,1,1, 1,1,1, 1,1,1 })); + + int elements = buffer.getNIOCapacity(); + + CLCommandQueue queue; + if(device.getQueueProperties().contains(OUT_OF_ORDER_MODE)) { + queue = device.createCommandQueue(OUT_OF_ORDER_MODE); + }else{ + queue = device.createCommandQueue(); + } + + CLEventList writeEvent = new CLEventList(1); + CLEventList kernelEvents = new CLEventList(2); + + // (1+1)*2 = 4; conditions enforce propper order + CLKernel addKernel = program.createCLKernel("add").putArg(buffer).putArg(1).putArg(elements); + CLKernel mulKernel = program.createCLKernel("mul").putArg(buffer).putArg(2).putArg(elements); + + queue.putWriteBuffer(buffer, false, writeEvent); + + queue.put1DRangeKernel(addKernel, 0, elements, 1, writeEvent, kernelEvents); + queue.put1DRangeKernel(mulKernel, 0, elements, 1, writeEvent, kernelEvents); + + queue.putReadBuffer(buffer, false, kernelEvents, null); + + queue.finish(); + + writeEvent.release(); + kernelEvents.release(); + + for (int i = 0; i < elements; i++) { + assertEquals(4, buffer.getBuffer().get(i)); + } + + }finally{ + context.release(); + } + + } @Test public void profilingEventsTest() throws IOException { @@ -174,7 +239,7 @@ public class CLCommandQueueTest { CLProgram program = context.createProgram(getClass().getResourceAsStream("testkernels.cl")).build(); CLKernel vectorAddKernel = program.createCLKernel("VectorAddGM").setArg(3, elements); - CLCommandQueue queue = device.createCommandQueue(Mode.PROFILING_MODE); + CLCommandQueue queue = device.createCommandQueue(PROFILING_MODE); out.println(queue); diff --git a/test/com/jogamp/opencl/testkernels.cl b/test/com/jogamp/opencl/testkernels.cl index ec7e8bf6..2b8c097d 100644 --- a/test/com/jogamp/opencl/testkernels.cl +++ b/test/com/jogamp/opencl/testkernels.cl @@ -1,22 +1,33 @@ - // OpenCL Kernel Function for element by element vector addition kernel void VectorAddGM(global const int* a, global const int* b, global int* c, int iNumElements) { - // get index into global data array int iGID = get_global_id(0); - // bound check (equivalent to the limit on a 'for' loop for standard/serial C code if (iGID >= iNumElements) { return; } - // add the vector elements c[iGID] = a[iGID] + b[iGID]; } kernel void Test(global const int* a, global const int* b, global int* c, int iNumElements) { - // get index into global data array int iGID = get_global_id(0); - // bound check (equivalent to the limit on a 'for' loop for standard/serial C code if (iGID >= iNumElements) { return; } c[iGID] = iGID; } + + kernel void add(global int* a, int value, int iNumElements) { + int iGID = get_global_id(0); + if (iGID >= iNumElements) { + return; + } + a[iGID] += value; + } + + kernel void mul(global int* a, int value, int iNumElements) { + + int iGID = get_global_id(0); + if (iGID >= iNumElements) { + return; + } + a[iGID] *= value; + } |