Top Description Inners Fields Constructors Methods
com.jogamp.opencl.util.concurrent

public Class CLCommandQueuePool<C extends CLQueueContext>

extends Object
implements CLResource
Class Inheritance
All Implemented Interfaces
com.jogamp.opencl.CLResource
Imports
com.jogamp.common.util.InterruptSource, com.jogamp.opencl.CLCommandQueue, .CLDevice, .CLResource, com.jogamp.opencl.util.CLMultiContext, java.util.ArrayList, .Collection, .List, java.util.concurrent.Callable, .ExecutorService, .Executors, .Future, .ThreadFactory, .TimeUnit

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 to ExecutorService but it uses CLTasks instead of Callables and provides a per-queue context for resource sharing across all tasks of one queue.
Author
Michael Bien

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
CLCommandQueuePool.FinishAction

The action executed after a task completes.

private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private List<CLQueueContext>
private ExecutorService
private CLCommandQueuePool.FinishAction
private boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <C extends CLQueueContext> CLCommandQueuePool<C>
create(final CLQueueContextFactory<C> factory, final CLMultiContext mc, final CLCommandQueue.Mode... modes)

public static <C extends CLQueueContext> CLCommandQueuePool<C>
create(final CLQueueContextFactory<C> factory, final Collection<CLDevice> devices, final CLCommandQueue.Mode... modes)

public static <C extends CLQueueContext> CLCommandQueuePool<C>
create(final CLQueueContextFactory<C> factory, final Collection<CLCommandQueue> queues)

public void
finishQueues()

Calls CLCommandQueue#finish() on all queues.

public void
flushQueues()

Calls CLCommandQueue#flush() on all queues.

public CLCommandQueuePool.FinishAction
public List<CLCommandQueue>
getQueues()

Returns the command queues used in this pool.

public int
getSize()

Returns the size of this pool (number of command queues).

private List<CLQueueContext>
private void
public <R> List<Future<R>>
invokeAll(final Collection<? extends CLTask<? super C, R>> tasks)

Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.

public <R> List<Future<R>>
invokeAll(final Collection<? extends CLTask<? super C, R>> tasks, final long timeout, final TimeUnit unit)

Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.

public boolean
isReleased()

Implements com.jogamp.opencl.CLResource.isReleased.

Returns true if release() has been called.
public void
release()

Implements com.jogamp.opencl.CLResource.release.

Releases all queues.
public void
setFinishAction(final CLCommandQueuePool.FinishAction action)

Sets the action which is run after every completed task.

public <R> Future<R>
submit(final CLTask<? super C, R> task)

Submits this task to the pool for execution returning its Future.

public <R> List<Future<R>>
submitAll(final Collection<? extends CLTask<? super C, R>> tasks)

Submits all tasks to the pool for execution and returns their Future.

public CLCommandQueuePool<C>

Returns:

this
switchContext
(final CLQueueContextFactory<C> factory)

Switches the context of all queues - this operation can be expensive.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private <R> List<CLCommandQueuePool.TaskWrapper<C, R>>
wrapTasks(final Collection<? extends CLTask<? super C, R>> tasks)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

contextsback to summary
private List<CLQueueContext> contexts
excecutorback to summary
private ExecutorService excecutor
finishActionback to summary
private CLCommandQueuePool.FinishAction finishAction
releasedback to summary
private boolean released

Constructor Detail

CLCommandQueuePoolback to summary
private CLCommandQueuePool(final CLQueueContextFactory<C> factory, final Collection<CLCommandQueue> queues)

Method Detail

createback to summary
public static <C extends CLQueueContext> CLCommandQueuePool<C> create(final CLQueueContextFactory<C> factory, final CLMultiContext mc, final CLCommandQueue.Mode... modes)
createback to summary
public static <C extends CLQueueContext> CLCommandQueuePool<C> create(final CLQueueContextFactory<C> factory, final Collection<CLDevice> devices, final CLCommandQueue.Mode... modes)
createback to summary
public static <C extends CLQueueContext> CLCommandQueuePool<C> create(final CLQueueContextFactory<C> factory, final Collection<CLCommandQueue> queues)
finishQueuesback to summary
public void finishQueues()

Calls CLCommandQueue#finish() on all queues.

flushQueuesback to summary
public void flushQueues()

Calls CLCommandQueue#flush() on all queues.

getFinishActionback to summary
public CLCommandQueuePool.FinishAction getFinishAction()
getQueuesback to summary
public List<CLCommandQueue> getQueues()

Returns the command queues used in this pool.

getSizeback to summary
public int getSize()

Returns the size of this pool (number of command queues).

initContextsback to summary
private List<CLQueueContext> initContexts(final Collection<CLCommandQueue> queues, final CLQueueContextFactory<C> factory)
initExecutorback to summary
private void initExecutor()
invokeAllback to summary
public <R> List<Future<R>> invokeAll(final Collection<? extends CLTask<? super C, R>> tasks) throws InterruptedException

Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.

See Also
ExecutorService#invokeAll(java.util.Collection)
invokeAllback to summary
public <R> List<Future<R>> invokeAll(final Collection<? extends CLTask<? super C, R>> tasks, final long timeout, final TimeUnit unit) throws InterruptedException

Submits all tasks to the pool for immediate execution (blocking) and returns their Future holding the result.

See Also
ExecutorService#invokeAll(java.util.Collection, long, java.util.concurrent.TimeUnit)
isReleasedback to summary
public boolean isReleased()

Implements com.jogamp.opencl.CLResource.isReleased.

Doc from com.jogamp.opencl.CLResource.isReleased.

Returns true if release() has been called.

Annotations
@Override
releaseback to summary
public void release()

Implements com.jogamp.opencl.CLResource.release.

Releases all queues.

Annotations
@Override
setFinishActionback to summary
public void setFinishAction(final CLCommandQueuePool.FinishAction action)

Sets the action which is run after every completed task. This is mainly intended for debugging, default value is FinishAction#DO_NOTHING.

submitback to summary
public <R> Future<R> submit(final CLTask<? super C, R> task)

Submits this task to the pool for execution returning its Future.

See Also
ExecutorService#submit(java.util.concurrent.Callable)
submitAllback to summary
public <R> List<Future<R>> submitAll(final Collection<? extends CLTask<? super C, R>> tasks)

Submits all tasks to the pool for execution and returns their Future. Calls submit(com.jogamp.opencl.util.concurrent.CLTask) for every task.

switchContextback to summary
public CLCommandQueuePool<C> switchContext(final 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:CLCommandQueuePool<C>

this

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
wrapTasksback to summary
private <R> List<CLCommandQueuePool.TaskWrapper<C, R>> wrapTasks(final Collection<? extends CLTask<? super C, R>> tasks)
com.jogamp.opencl.util.concurrent back to summary

public final Enum CLCommandQueuePool.FinishAction

extends Enum<CLCommandQueuePool.FinishAction>
Class Inheritance

The action executed after a task completes.

Field Summary

Modifier and TypeField and Description
public static final CLCommandQueuePool.FinishAction
DO_NOTHING

Does nothing, the task is responsible to make sure all computations have finished when the task finishes

public static final CLCommandQueuePool.FinishAction
FINISH

Finishes the queue on task completion.

public static final CLCommandQueuePool.FinishAction
FLUSH

Flushes the queue on task completion.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static CLCommandQueuePool.FinishAction
public static CLCommandQueuePool.FinishAction[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DO_NOTHINGback to summary
public static final CLCommandQueuePool.FinishAction DO_NOTHING

Does nothing, the task is responsible to make sure all computations have finished when the task finishes

FINISHback to summary
public static final CLCommandQueuePool.FinishAction FINISH

Finishes the queue on task completion.

FLUSHback to summary
public static final CLCommandQueuePool.FinishAction FLUSH

Flushes the queue on task completion.

Constructor Detail

FinishActionback to summary
private FinishAction()

Method Detail

valueOfback to summary
public static CLCommandQueuePool.FinishAction valueOf(String name)
valuesback to summary
public static CLCommandQueuePool.FinishAction[] values()
com.jogamp.opencl.util.concurrent back to summary

private Class CLCommandQueuePool.QueueThread

extends Thread
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final CLQueueContext

Constructor Summary

AccessConstructor and Description
public
QueueThread(final ThreadGroup group, final Runnable runnable, final CLQueueContext context, final int index)

Method Summary

Inherited from com.jogamp.common.util.InterruptSource.Thread:
clearInterruptSourcecreategetInterruptCountergetInterruptSourceinterrupt

Field Detail

contextback to summary
private final CLQueueContext context

Constructor Detail

QueueThreadback to summary
public QueueThread(final ThreadGroup group, final Runnable runnable, final CLQueueContext context, final int index)
com.jogamp.opencl.util.concurrent back to summary

private Class CLCommandQueuePool.QueueThreadFactory

extends Object
implements ThreadFactory
Class Inheritance
  • java.lang.Object
  • com.jogamp.opencl.util.concurrent.CLCommandQueuePool.QueueThreadFactory
All Implemented Interfaces
java.util.concurrent.ThreadFactory

Field Summary

Modifier and TypeField and Description
private final List<CLQueueContext>
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public synchronized Thread
newThread(final Runnable
a runnable to be executed by new thread instance
runnable
)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private final List<CLQueueContext> context
indexback to summary
private int index

Constructor Detail

QueueThreadFactoryback to summary
private QueueThreadFactory(final List<CLQueueContext> queues)

Method Detail

newThreadback to summary
public synchronized Thread newThread(final Runnable runnable)

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Parameters
runnable:Runnable

a runnable to be executed by new thread instance

Returns:Thread

constructed thread, or null if the request to create a thread is rejected

com.jogamp.opencl.util.concurrent back to summary

private Class CLCommandQueuePool.TaskWrapper<C extends CLQueueContext, R>

extends Object
implements Callable<R>
Class Inheritance
  • java.lang.Object
  • com.jogamp.opencl.util.concurrent.CLCommandQueuePool.TaskWrapper
All Implemented Interfaces
java.util.concurrent.Callable

Field Summary

Modifier and TypeField and Description
private final CLCommandQueuePool.FinishAction
private final CLTask<? super C, R>

Constructor Summary

AccessConstructor and Description
public
TaskWrapper(final CLTask<? super C, R> task, final CLCommandQueuePool.FinishAction mode)

Method Summary

Modifier and TypeMethod and Description
public R
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

modeback to summary
private final CLCommandQueuePool.FinishAction mode
taskback to summary
private final CLTask<? super C, R> task

Constructor Detail

TaskWrapperback to summary
public TaskWrapper(final CLTask<? super C, R> task, final CLCommandQueuePool.FinishAction mode)

Method Detail

callback to summary
public R call() throws Exception

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:R

computed result

Exceptions
Exception:
if unable to compute a result