Package com.jogamp.opencl.util

Examples of com.jogamp.opencl.util.CLMultiContext


    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();
        }

    }
View Full Code Here


    }

    @Test
    public void commandQueuePoolTest() throws InterruptedException, ExecutionException {

        CLMultiContext mc = CLMultiContext.create(CLPlatform.listCLPlatforms());

        try {

            CLCommandQueuePool pool = CLCommandQueuePool.create(mc);

            assertTrue(pool.getPoolSize() > 0);

            final int slice = 64;
            final int tasksPerQueue = 10;
            final int taskCount = pool.getPoolSize() * tasksPerQueue;
           
            IntBuffer data = Buffers.newDirectIntBuffer(slice*taskCount);
            List<CLTestTask> tasks = createTasks(programSource, data, taskCount, slice);

            out.println("invoking "+tasks.size()+" tasks on "+pool.getPoolSize()+" queues");

            // blocking invoke
            List<Future<IntBuffer>> results = pool.invokeAll(tasks);
            assertNotNull(results);
            checkBuffer(1, data);

            // submit blocking emediatly
            for (CLTestTask task : tasks) {
                IntBuffer ret = pool.submit(task).get();
                assertNotNull(ret);
                checkBuffer(2, ret);
            }
            checkBuffer(2, data);

            // submitAll using futures
            List<Future<IntBuffer>> futures = pool.submitAll(tasks);
            for (Future<IntBuffer> future : futures) {
                IntBuffer ret = future.get();
                assertNotNull(ret);
                checkBuffer(3, ret);
            }
            checkBuffer(3, data);

            // switching contexts using different program
            final String decrementProgramSource = programSource.replaceAll("\\+\\+", "--");
            tasks = createTasks(decrementProgramSource, data, taskCount, slice);
            List<Future<IntBuffer>> results2 = pool.invokeAll(tasks);
            assertNotNull(results2);
            checkBuffer(2, data);

            // Note: we have to make sure that we don't resubmit old tasks at this point since
            // we wait only for completion of a subset of tasks.
            // submit any
            data = Buffers.newDirectIntBuffer(slice*taskCount);
            tasks = createTasks(decrementProgramSource, data, taskCount, slice);

            IntBuffer ret1 = pool.invokeAny(tasks);
            assertNotNull(ret1);
            checkBuffer(-1, ret1);
            checkContains(-1, data);

            // completionservice take/any test
            data = Buffers.newDirectIntBuffer(slice*taskCount);
            tasks = createTasks(decrementProgramSource, data, taskCount, slice);

            CLTaskCompletionService<IntBuffer> service = new CLTaskCompletionService<IntBuffer>(pool);
            for (CLTestTask task : tasks) {
                service.submit(task);
            }
            IntBuffer ret2 = service.take().get();
            assertNotNull(ret2);
            checkBuffer(-1, ret2);
            checkContains(-1, data);

            pool.release();
        }finally{
            mc.release();
        }
    }
View Full Code Here

    }

    @Test
    public void forkJoinTest() throws InterruptedException, ExecutionException {

        CLMultiContext mc = CLMultiContext.create(CLPlatform.listCLPlatforms());

        try{

            CLForkJoinPool pool = CLForkJoinPool.create(mc);

            final int size = 64;
            LogicTest task = new LogicTest(size);
            Future<Integer> future = pool.submit(task);
            assertNotNull(future);
            assertEquals(size, (int)future.get());

            pool.release();

        }finally{
            mc.release();
        }

    }
View Full Code Here

TOP

Related Classes of com.jogamp.opencl.util.CLMultiContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.