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