diff options
Diffstat (limited to 'test/com/jogamp/opencl')
-rw-r--r-- | test/com/jogamp/opencl/CLBufferTest.java | 96 | ||||
-rw-r--r-- | test/com/jogamp/opencl/CLProgramTest.java | 19 | ||||
-rw-r--r-- | test/com/jogamp/opencl/LowLevelBindingTest.java | 26 | ||||
-rw-r--r-- | test/com/jogamp/opencl/gl/CLGLTest.java | 143 | ||||
-rw-r--r-- | test/com/jogamp/opencl/util/concurrent/CLMultiContextTest.java | 172 |
5 files changed, 397 insertions, 59 deletions
diff --git a/test/com/jogamp/opencl/CLBufferTest.java b/test/com/jogamp/opencl/CLBufferTest.java index 1b718277..e85f4504 100644 --- a/test/com/jogamp/opencl/CLBufferTest.java +++ b/test/com/jogamp/opencl/CLBufferTest.java @@ -3,14 +3,14 @@ * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. @@ -31,8 +31,14 @@ package com.jogamp.opencl; import com.jogamp.opencl.CLMemory.Mem; import com.jogamp.opencl.CLMemory.Map; import com.jogamp.common.nio.Buffers; +import java.nio.Buffer; import java.nio.ByteBuffer; +import java.nio.DoubleBuffer; import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.LongBuffer; +import java.nio.ShortBuffer; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.junit.Test; @@ -41,6 +47,8 @@ import static org.junit.Assert.*; import static java.lang.System.*; import static com.jogamp.opencl.TestUtils.*; import static com.jogamp.common.nio.Buffers.*; +import static com.jogamp.opencl.util.CLPlatformFilters.*; +import static com.jogamp.opencl.CLVersion.*; /** * @@ -48,6 +56,62 @@ import static com.jogamp.common.nio.Buffers.*; */ public class CLBufferTest { + + @Test + public void createBufferTest() { + + out.println(" - - - highLevelTest; create buffer test - - - "); + + CLContext context = CLContext.create(); + try{ + int size = 6; + + CLBuffer<ByteBuffer> bb = context.createByteBuffer(size); + CLBuffer<ShortBuffer> sb = context.createShortBuffer(size); + CLBuffer<IntBuffer> ib = context.createIntBuffer(size); + CLBuffer<LongBuffer> lb = context.createLongBuffer(size); + CLBuffer<FloatBuffer> fb = context.createFloatBuffer(size); + CLBuffer<DoubleBuffer> db = context.createDoubleBuffer(size); + + List<CLMemory<? extends Buffer>> buffers = context.getMemoryObjects(); + assertEquals(6, buffers.size()); + + assertEquals(1, bb.getElementSize()); + assertEquals(2, sb.getElementSize()); + assertEquals(4, ib.getElementSize()); + assertEquals(8, lb.getElementSize()); + assertEquals(4, fb.getElementSize()); + assertEquals(8, db.getElementSize()); + + ByteBuffer anotherNIO = newDirectByteBuffer(2); + + for (CLMemory<? extends Buffer> memory : buffers) { + + CLBuffer<? extends Buffer> buffer = (CLBuffer<? extends Buffer>) memory; + Buffer nio = buffer.getBuffer(); + + assertEquals(nio.capacity(), buffer.getCLCapacity()); + assertEquals(buffer.getNIOSize(), buffer.getCLSize()); + assertEquals(sizeOfBufferElem(nio), buffer.getElementSize()); + assertEquals(nio.capacity() * sizeOfBufferElem(nio), buffer.getCLSize()); + + CLBuffer<ByteBuffer> clone = buffer.cloneWith(anotherNIO); + + assertEquals(buffer.ID, clone.ID); + assertTrue(clone.equals(buffer)); + assertTrue(buffer.equals(clone)); + + assertEquals(buffer.getCLSize(), clone.getCLCapacity()); + assertEquals(buffer.getCLSize(), clone.getCLSize()); + assertEquals(anotherNIO.capacity(), clone.getNIOCapacity()); + } + + }finally{ + context.release(); + } + + } + @Test public void writeCopyReadBufferTest() { @@ -123,7 +187,7 @@ public class CLBufferTest { context.release(); } - + @Test public void mapBufferTest() { @@ -153,9 +217,9 @@ public class CLBufferTest { } CLCommandQueue queue = context.getDevices()[0].createCommandQueue(); - + // fill only first buffer -> we will copy the payload to the second later. - ByteBuffer mappedBufferA = queue.putMapBuffer(clBufferA, Map.READ_WRITE, true); + ByteBuffer mappedBufferA = queue.putMapBuffer(clBufferA, Map.WRITE, true); assertEquals(sizeInBytes, mappedBufferA.capacity()); fillBuffer(mappedBufferA, 12345); // write to A @@ -182,21 +246,13 @@ public class CLBufferTest { out.println(" - - - subBufferTest - - - "); - CLPlatform[] platforms = CLPlatform.listCLPlatforms(); - CLPlatform theChosenOne = null; - for (CLPlatform platform : platforms) { - if(platform.isAtLeast(CLVersion.CL_1_1)) { - theChosenOne = platform; - break; - } - } - - if(theChosenOne == null) { + CLPlatform platform = CLPlatform.getDefault(version(CL_1_1)); + if(platform == null) { out.println("aborting subBufferTest"); return; } - CLContext context = CLContext.create(theChosenOne); + CLContext context = CLContext.create(platform); try{ final int subelements = 5; // device only @@ -253,8 +309,8 @@ public class CLBufferTest { out.println(" - - - destructorCallbackTest - - - "); - CLPlatform platform = CLPlatform.getDefault(); - if(!platform.isAtLeast(CLVersion.CL_1_1)) { + CLPlatform platform = CLPlatform.getDefault(version(CL_1_1)); + if(platform == null) { out.println("aborting destructorCallbackTest"); return; } 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(); } diff --git a/test/com/jogamp/opencl/LowLevelBindingTest.java b/test/com/jogamp/opencl/LowLevelBindingTest.java index d5ef3f50..9e603879 100644 --- a/test/com/jogamp/opencl/LowLevelBindingTest.java +++ b/test/com/jogamp/opencl/LowLevelBindingTest.java @@ -30,7 +30,7 @@ package com.jogamp.opencl; import java.util.Random; import com.jogamp.opencl.impl.BuildProgramCallback; -import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.common.nio.NativeSizeBuffer; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -109,12 +109,12 @@ public class LowLevelBindingTest { checkForError(ret); out.println("#platforms: "+intBuffer.get(0)); - PointerBuffer platformId = PointerBuffer.allocateDirect(intBuffer.get(0)); + NativeSizeBuffer platformId = NativeSizeBuffer.allocateDirect(intBuffer.get(0)); ret = cl.clGetPlatformIDs(platformId.capacity(), platformId, null); checkForError(ret); // print platform info - PointerBuffer longBuffer = PointerBuffer.allocateDirect(1); + NativeSizeBuffer longBuffer = NativeSizeBuffer.allocateDirect(1); ByteBuffer bb = newDirectByteBuffer(128); for (int i = 0; i < platformId.capacity(); i++) { @@ -143,7 +143,7 @@ public class LowLevelBindingTest { checkForError(ret); out.println("#devices: "+intBuffer.get(0)); - PointerBuffer devices = PointerBuffer.allocateDirect(intBuffer.get(0)); + NativeSizeBuffer devices = NativeSizeBuffer.allocateDirect(intBuffer.get(0)); ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, devices.capacity(), devices, null); //print device info @@ -176,7 +176,7 @@ public class LowLevelBindingTest { checkForError(ret); out.println("#platforms: "+intBuffer.get(0)); - PointerBuffer pb = PointerBuffer.allocateDirect(intBuffer.get(0)); + NativeSizeBuffer pb = NativeSizeBuffer.allocateDirect(intBuffer.get(0)); ret = cl.clGetPlatformIDs(pb.capacity(), pb, null); checkForError(ret); @@ -187,14 +187,14 @@ public class LowLevelBindingTest { checkForError(ret); out.println("#devices: "+intBuffer.get(0)); - PointerBuffer devices = PointerBuffer.allocateDirect(intBuffer.get(0)); + NativeSizeBuffer devices = NativeSizeBuffer.allocateDirect(intBuffer.get(0)); ret = cl.clGetDeviceIDs(platform, CL.CL_DEVICE_TYPE_ALL, devices.capacity(), devices, null); long context = cl.clCreateContext(null, devices, null, intBuffer); checkError("on clCreateContext", intBuffer.get()); //get number of devices - PointerBuffer longBuffer = PointerBuffer.allocateDirect(1); + NativeSizeBuffer longBuffer = NativeSizeBuffer.allocateDirect(1); ret = cl.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, 0, null, longBuffer); checkError("on clGetContextInfo", ret); @@ -223,19 +223,19 @@ public class LowLevelBindingTest { checkForError(ret); assertTrue(intBuffer.get(0) > 0); - PointerBuffer pb = PointerBuffer.allocateDirect(intBuffer.get(0)); + NativeSizeBuffer pb = NativeSizeBuffer.allocateDirect(intBuffer.get(0)); ret = cl.clGetPlatformIDs(pb.capacity(), pb, null); checkForError(ret); long platform = pb.get(0); - PointerBuffer properties = PointerBuffer.allocateDirect(3).put(CL.CL_CONTEXT_PLATFORM) + NativeSizeBuffer properties = NativeSizeBuffer.allocateDirect(3).put(CL.CL_CONTEXT_PLATFORM) .put(platform).put(0) // 0 terminated array .rewind(); long context = cl.clCreateContextFromType(properties, CL.CL_DEVICE_TYPE_ALL, null, null); out.println("context handle: "+context); checkError("on clCreateContextFromType", ret); - PointerBuffer longBuffer = PointerBuffer.allocateDirect(1); + NativeSizeBuffer longBuffer = NativeSizeBuffer.allocateDirect(1); ret = cl.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, 0, null, longBuffer); checkError("on clGetContextInfo", ret); @@ -284,7 +284,7 @@ public class LowLevelBindingTest { // Create the program - PointerBuffer lengths = PointerBuffer.allocateDirect(1).put(programSource.length()).rewind(); + NativeSizeBuffer lengths = NativeSizeBuffer.allocateDirect(1).put(programSource.length()).rewind(); final long program = cl.clCreateProgramWithSource(context, 1, new String[] {programSource}, lengths, intBuffer); out.println("program id: "+program); checkError("on clCreateProgramWithSource", intBuffer.get(0)); @@ -370,8 +370,8 @@ public class LowLevelBindingTest { checkError("on clEnqueueWriteBuffer", ret); // Launch kernel - PointerBuffer gWS = PointerBuffer.allocateDirect(1).put(globalWorkSize).rewind(); - PointerBuffer lWS = PointerBuffer.allocateDirect(1).put(localWorkSize).rewind(); + NativeSizeBuffer gWS = NativeSizeBuffer.allocateDirect(1).put(globalWorkSize).rewind(); + NativeSizeBuffer lWS = NativeSizeBuffer.allocateDirect(1).put(localWorkSize).rewind(); ret = cl.clEnqueueNDRangeKernel(commandQueue, kernel, 1, null, gWS, lWS, 0, null, null); checkError("on clEnqueueNDRangeKernel", ret); diff --git a/test/com/jogamp/opencl/gl/CLGLTest.java b/test/com/jogamp/opencl/gl/CLGLTest.java index 01fd4679..464f1468 100644 --- a/test/com/jogamp/opencl/gl/CLGLTest.java +++ b/test/com/jogamp/opencl/gl/CLGLTest.java @@ -32,10 +32,10 @@ package com.jogamp.opencl.gl; -import com.jogamp.common.os.Platform; -import org.junit.Rule; -import org.junit.rules.MethodRule; -import org.junit.rules.Timeout; +import com.jogamp.common.nio.Buffers; +import com.jogamp.opencl.CLCommandQueue; +import javax.media.opengl.GL2; +import javax.media.opengl.GLException; import com.jogamp.opencl.CLDevice; import com.jogamp.newt.Display; import com.jogamp.newt.NewtFactory; @@ -43,12 +43,20 @@ import com.jogamp.newt.Screen; import com.jogamp.newt.Window; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opencl.CLContext; +import com.jogamp.opencl.CLMemory.Mem; import com.jogamp.opencl.CLPlatform; +import com.jogamp.opencl.util.CLDeviceFilters; +import com.jogamp.opencl.util.CLPlatformFilters; +import java.nio.IntBuffer; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import javax.media.opengl.GLContext; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.MethodRule; +import org.junit.rules.Timeout; +import static com.jogamp.opencl.util.CLPlatformFilters.*; import static org.junit.Assert.*; import static java.lang.System.*; @@ -65,15 +73,9 @@ public class CLGLTest { private static GLWindow glWindow; private static Window window; -// @BeforeClass - public static void init() { + public static void initGL() { GLProfile.initSingleton(true); - // FIXME remove when JOCL is stabelized on mac - if(Platform.getOS().toLowerCase().contains("mac")) { - fail("quick exit to prevent deadlock"); - } - Display display = NewtFactory.createDisplay(null); // local display assertNotNull(display); @@ -92,25 +94,30 @@ public class CLGLTest { glcontext = glWindow.getContext(); // glcontext.makeCurrent(); - out.println("useing glcontext:"); - out.println(glcontext); +// out.println(" - - - - glcontext - - - - "); +// out.println(glcontext); +// out.println(" - - - - - - - - - - - - - "); + } + + private void deinitGL() throws GLException { + glcontext.release(); + glWindow.destroy(); + window.destroy(); + + glcontext = null; + glWindow = null; + window = null; } @Test public void createContextTest() { - init(); + initGL(); out.println(" - - - glcl; createContextTest - - - "); - CLDevice[] devices = CLPlatform.getDefault().listCLDevices(); - CLDevice device = null; - for (CLDevice d : devices) { - if(d.isGLMemorySharingSupported()) { - device = d; - break; - } - } + CLPlatform platform = CLPlatform.getDefault(CLPlatformFilters.glSharing()); + CLDevice device = platform.getMaxFlopsDevice(CLDeviceFilters.glSharing()); if(device == null) { out.println("Aborting test: no GLCL capable devices found."); @@ -122,7 +129,7 @@ public class CLGLTest { out.println(device.getPlatform()); assertNotNull(glcontext); - glcontext.makeCurrent(); + makeGLCurrent(); assertTrue(glcontext.isCurrent()); CLContext context = CLGLContext.create(glcontext, device); @@ -139,10 +146,96 @@ public class CLGLTest { // destroy cl context, gl context still current context.release(); - glcontext.release(); - glWindow.destroy(); + deinitGL(); + } + + } + + @Test + public void vboSharing() { + + out.println(" - - - glcl; vboSharing - - - "); + + initGL(); + makeGLCurrent(); + assertTrue(glcontext.isCurrent()); + + CLPlatform platform = CLPlatform.getDefault(glSharing(glcontext)); + if(platform == null) { + out.println("test aborted"); + return; + } + + CLDevice theChosenOne = platform.getMaxFlopsDevice(CLDeviceFilters.glSharing()); + out.println(theChosenOne); + + CLGLContext context = CLGLContext.create(glcontext, theChosenOne); + + try{ + out.println(context); + + GL2 gl = glcontext.getGL().getGL2(); + + int[] id = new int[1]; + gl.glGenBuffers(id.length, id, 0); + + IntBuffer glData = Buffers.newDirectIntBuffer(new int[] {0,1,2,3,4,5,6,7,8}); + glData.rewind(); + + // create and write GL buffer + gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, id[0]); + gl.glBufferData(GL2.GL_ARRAY_BUFFER, glData.capacity()*4, glData, GL2.GL_STATIC_DRAW); + gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0); + gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); + gl.glFinish(); + + + // create CLGL buffer + IntBuffer clData = Buffers.newDirectIntBuffer(9); + CLGLBuffer<IntBuffer> clBuffer = context.createFromGLBuffer(clData, id[0], glData.capacity()*4, Mem.READ_ONLY); + + assertEquals(glData.capacity(), clBuffer.getCLCapacity()); + assertEquals(glData.capacity()*4, clBuffer.getCLSize()); + + + CLCommandQueue queue = theChosenOne.createCommandQueue(); + + // read gl buffer into cl nio buffer + queue.putAcquireGLObject(clBuffer) + .putReadBuffer(clBuffer, true) + .putReleaseGLObject(clBuffer); + + while(clData.hasRemaining()) { + assertEquals(glData.get(), clData.get()); + } + + out.println(clBuffer); + + clBuffer.release(); + + gl.glDeleteBuffers(1, id, 0); + + }finally{ + context.release(); + deinitGL(); } + + } + private void makeGLCurrent() { + // we are patient... + while(true) { + try{ + glcontext.makeCurrent(); + break; + }catch(RuntimeException ex) { + try { + Thread.sleep(200); + // I don't give up yet! + } catch (InterruptedException ignore) { } + } + } } diff --git a/test/com/jogamp/opencl/util/concurrent/CLMultiContextTest.java b/test/com/jogamp/opencl/util/concurrent/CLMultiContextTest.java new file mode 100644 index 00000000..81d34907 --- /dev/null +++ b/test/com/jogamp/opencl/util/concurrent/CLMultiContextTest.java @@ -0,0 +1,172 @@ +/* + * Created on Tuesday, May 03 2011 + */ +package com.jogamp.opencl.util.concurrent; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.opencl.CLBuffer; +import com.jogamp.opencl.CLCommandQueue; +import com.jogamp.opencl.CLContext; +import com.jogamp.opencl.CLDevice; +import com.jogamp.opencl.CLKernel; +import com.jogamp.opencl.CLPlatform; +import com.jogamp.opencl.util.concurrent.CLQueueContext.CLSimpleQueueContext; +import com.jogamp.opencl.util.concurrent.CLQueueContextFactory.CLSimpleContextFactory; +import java.nio.IntBuffer; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import org.junit.Rule; +import org.junit.rules.MethodRule; +import org.junit.rules.Timeout; +import com.jogamp.opencl.util.CLMultiContext; +import java.nio.Buffer; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; + +import static org.junit.Assert.*; +import static java.lang.System.*; + +/** + * + * @author Michael Bien + */ +public class CLMultiContextTest { + + @Rule + public MethodRule methodTimeout= new Timeout(10000); + + @Test + public void createMultiContextTest() { + + CLMultiContext mc = CLMultiContext.create(CLPlatform.listCLPlatforms()); + + try{ + List<CLContext> contexts = mc.getContexts(); + List<CLDevice> devices = mc.getDevices(); + + assertFalse(contexts.isEmpty()); + assertFalse(devices.isEmpty()); + + for (CLContext context : contexts) { + out.println(context); + } + for (CLDevice device : devices) { + out.println(device); + } + + }finally{ + mc.release(); + } + + } + + private final static String programSource = + "kernel void compute(global int* array, int numElements) { \n" + + " int index = get_global_id(0); \n" + + " if (index >= numElements) { \n" + + " return; \n" + + " } \n" + + " array[index]++; \n" + + "} \n"; + + private final class CLTestTask implements CLTask<CLSimpleQueueContext, Buffer> { + + private final Buffer data; + + public CLTestTask(Buffer buffer) { + this.data = buffer; + } + + public Buffer execute(CLSimpleQueueContext qc) { + + CLCommandQueue queue = qc.getQueue(); + CLContext context = qc.getCLContext(); + CLKernel kernel = qc.getKernel("compute"); + + CLBuffer<Buffer> buffer = null; + try{ + buffer = context.createBuffer(data); + int gws = buffer.getCLCapacity(); + + kernel.putArg(buffer).putArg(gws).rewind(); + + queue.putWriteBuffer(buffer, true); + queue.put1DRangeKernel(kernel, 0, gws, 0); + queue.putReadBuffer(buffer, true); + }finally{ + if(buffer != null) { + buffer.release(); + } + } + + return data; + } + + } + + @Test + public void commandQueuePoolTest() throws InterruptedException, ExecutionException { + + CLMultiContext mc = CLMultiContext.create(CLPlatform.listCLPlatforms()); + + try { + + CLSimpleContextFactory factory = CLQueueContextFactory.createSimple(programSource); + CLCommandQueuePool<CLSimpleQueueContext> pool = CLCommandQueuePool.create(factory, mc); + + assertTrue(pool.getSize() > 0); + + final int slice = 64; + final int tasksPerQueue = 10; + final int taskCount = pool.getSize() * tasksPerQueue; + + IntBuffer data = Buffers.newDirectIntBuffer(slice*taskCount); + + List<CLTestTask> tasks = new ArrayList<CLTestTask>(taskCount); + + for (int i = 0; i < taskCount; i++) { + IntBuffer subBuffer = Buffers.slice(data, i*slice, slice); + assertEquals(slice, subBuffer.capacity()); + tasks.add(new CLTestTask(subBuffer)); + } + + out.println("invoking "+tasks.size()+" tasks on "+pool.getSize()+" queues"); + + // blocking invoke + pool.invokeAll(tasks); + checkBuffer(1, data); + + // submit blocking emediatly + for (CLTestTask task : tasks) { + pool.submit(task).get(); + } + checkBuffer(2, data); + + // submitAll using futures + List<Future<Buffer>> futures = pool.submitAll(tasks); + for (Future<Buffer> future : futures) { + future.get(); + } + checkBuffer(3, data); + + // switching contexts using different program + factory = CLQueueContextFactory.createSimple(programSource.replaceAll("\\+\\+", "--")); + pool.switchContext(factory); + pool.invokeAll(tasks); + checkBuffer(2, data); + + pool.release(); + }finally{ + mc.release(); + } + } + + private void checkBuffer(int expected, IntBuffer data) { + while(data.hasRemaining()) { + assertEquals(expected, data.get()); + } + data.rewind(); + } + +} |