Class CLCommandQueuePool<C extends CLQueueContext>
- java.lang.Object
-
- com.jogamp.opencl.util.concurrent.CLCommandQueuePool<C>
-
- All Implemented Interfaces:
CLResource
public class CLCommandQueuePool<C extends CLQueueContext> extends Object implements CLResource
A multithreaded, fixed size pool of OpenCL command queues. It serves as a multiplexer distributing tasks over N queues usually run on N devices. The usage of this pool is similar toExecutorServicebut it usesCLTasks instead ofCallables and provides a per-queue context for resource sharing across all tasks of one queue.- Author:
- Michael Bien
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCLCommandQueuePool.FinishActionThe action executed after a task completes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <C extends CLQueueContext>
CLCommandQueuePool<C>create(CLQueueContextFactory<C> factory, CLMultiContext mc, CLCommandQueue.Mode... modes)static <C extends CLQueueContext>
CLCommandQueuePool<C>create(CLQueueContextFactory<C> factory, Collection<CLCommandQueue> queues)static <C extends CLQueueContext>
CLCommandQueuePool<C>create(CLQueueContextFactory<C> factory, Collection<CLDevice> devices, CLCommandQueue.Mode... modes)voidfinishQueues()CallsCLCommandQueue.finish()on all queues.voidflushQueues()CallsCLCommandQueue.flush()on all queues.CLCommandQueuePool.FinishActiongetFinishAction()List<CLCommandQueue>getQueues()Returns the command queues used in this pool.intgetSize()Returns the size of this pool (number of command queues).<R> List<java.util.concurrent.Future<R>>invokeAll(Collection<? extends CLTask<? super C,R>> tasks)Submits all tasks to the pool for immediate execution (blocking) and returns theirFutureholding the result.<R> List<java.util.concurrent.Future<R>>invokeAll(Collection<? extends CLTask<? super C,R>> tasks, long timeout, java.util.concurrent.TimeUnit unit)Submits all tasks to the pool for immediate execution (blocking) and returns theirFutureholding the result.booleanisReleased()Returns true ifCLResource.release()has been called.voidrelease()Releases all queues.voidsetFinishAction(CLCommandQueuePool.FinishAction action)Sets the action which is run after every completed task.<R> java.util.concurrent.Future<R>submit(CLTask<? super C,R> task)Submits this task to the pool for execution returning itsFuture.<R> List<java.util.concurrent.Future<R>>submitAll(Collection<? extends CLTask<? super C,R>> tasks)Submits all tasks to the pool for execution and returns theirFuture.CLCommandQueuePool<C>switchContext(CLQueueContextFactory<C> factory)Switches the context of all queues - this operation can be expensive.StringtoString()
-
-
-
Method Detail
-
create
public static <C extends CLQueueContext> CLCommandQueuePool<C> create(CLQueueContextFactory<C> factory, CLMultiContext mc, CLCommandQueue.Mode... modes)
-
create
public static <C extends CLQueueContext> CLCommandQueuePool<C> create(CLQueueContextFactory<C> factory, Collection<CLDevice> devices, CLCommandQueue.Mode... modes)
-
create
public static <C extends CLQueueContext> CLCommandQueuePool<C> create(CLQueueContextFactory<C> factory, Collection<CLCommandQueue> queues)
-
submit
public <R> java.util.concurrent.Future<R> submit(CLTask<? super C,R> task)
Submits this task to the pool for execution returning itsFuture.- See Also:
ExecutorService.submit(java.util.concurrent.Callable)
-
submitAll
public <R> List<java.util.concurrent.Future<R>> submitAll(Collection<? extends CLTask<? super C,R>> tasks)
Submits all tasks to the pool for execution and returns theirFuture. Callssubmit(com.jogamp.opencl.util.concurrent.CLTask)for every task.
-
invokeAll
public <R> List<java.util.concurrent.Future<R>> invokeAll(Collection<? extends CLTask<? super C,R>> tasks) throws InterruptedException
Submits all tasks to the pool for immediate execution (blocking) and returns theirFutureholding the result.- Throws:
InterruptedException- See Also:
ExecutorService.invokeAll(java.util.Collection)
-
invokeAll
public <R> List<java.util.concurrent.Future<R>> invokeAll(Collection<? extends CLTask<? super C,R>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws InterruptedException
Submits all tasks to the pool for immediate execution (blocking) and returns theirFutureholding the result.- Throws:
InterruptedException- See Also:
ExecutorService.invokeAll(java.util.Collection, long, java.util.concurrent.TimeUnit)
-
switchContext
public CLCommandQueuePool<C> switchContext(CLQueueContextFactory<C> factory)
Switches the context of all queues - this operation can be expensive. Blocks until all tasks finish and sets up a new context for all queues.- Returns:
- this
-
flushQueues
public void flushQueues()
CallsCLCommandQueue.flush()on all queues.
-
finishQueues
public void finishQueues()
CallsCLCommandQueue.finish()on all queues.
-
release
public void release()
Releases all queues.- Specified by:
releasein interfaceCLResource
-
getQueues
public List<CLCommandQueue> getQueues()
Returns the command queues used in this pool.
-
getSize
public int getSize()
Returns the size of this pool (number of command queues).
-
getFinishAction
public CLCommandQueuePool.FinishAction getFinishAction()
-
isReleased
public boolean isReleased()
Description copied from interface:CLResourceReturns true ifCLResource.release()has been called.- Specified by:
isReleasedin interfaceCLResource
-
setFinishAction
public void setFinishAction(CLCommandQueuePool.FinishAction action)
Sets the action which is run after every completed task. This is mainly intended for debugging, default value isCLCommandQueuePool.FinishAction.DO_NOTHING.
-
-