29package com.jogamp.opencl;
31import org.junit.FixMethodOrder;
33import org.junit.rules.Timeout;
34import org.junit.runners.MethodSorters;
36import java.util.concurrent.CountDownLatch;
38import com.jogamp.opencl.test.util.MiscUtils;
39import com.jogamp.opencl.test.util.UITestCase;
40import com.jogamp.opencl.util.MultiQueueBarrier;
41import com.jogamp.opencl.CLCommandQueue.Mode;
42import com.jogamp.opencl.CLMemory.Mem;
43import com.jogamp.opencl.util.CLDeviceFilters;
44import com.jogamp.opencl.util.CLPlatformFilters;
45import com.jogamp.opencl.llb.CL;
47import java.io.IOException;
48import java.nio.ByteBuffer;
49import java.nio.IntBuffer;
50import java.util.EnumSet;
51import java.util.concurrent.TimeUnit;
55import static org.junit.Assert.*;
56import static java.lang.System.*;
57import static com.jogamp.opencl.test.util.MiscUtils.*;
58import static com.jogamp.opencl.CLEvent.*;
59import static com.jogamp.opencl.CLVersion.*;
60import static com.jogamp.common.nio.Buffers.*;
61import static com.jogamp.opencl.CLCommandQueue.Mode.*;
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70 public Timeout methodTimeout =
new Timeout(20000);
77 assertTrue(queueMode.contains(OUT_OF_ORDER_MODE));
78 assertTrue(queueMode.contains(PROFILING_MODE));
82 for (
final Mode mode :
Mode.values()) {
87 for (
final ProfilingCommand cmd : ProfilingCommand.values()) {
88 assertEquals(cmd, ProfilingCommand.valueOf(cmd.COMMAND));
91 for (
final CommandType type : CommandType.values()) {
92 assertEquals(type, CommandType.valueOf(type.TYPE));
95 for (
final ExecutionStatus status : ExecutionStatus.values()) {
96 assertEquals(status, ExecutionStatus.valueOf(status.STATUS));
104 out.println(
" - - - event synchronization test - - - ");
112 final int elements = roundUp(groupSize, ONE_MB / SIZEOF_INT * 5);
119 fillBuffer(clBufferA.buffer, 12345);
120 fillBuffer(clBufferB.buffer, 67890);
132 assertEquals(0, events.size());
139 assertEquals(2, events.size());
143 assertEquals(0, events.size());
145 vectorAddKernel.
setArgs(clBufferA, clBufferB, clBufferC);
148 vectorAddKernel.
setArgs(clBufferA, clBufferB, clBufferD);
151 assertEquals(2, events.size());
164 checkIfEqual(clBufferC.buffer, clBufferD.buffer, elements);
165 out.println(
"results are valid");
171 @SuppressWarnings(
"unchecked")
175 out.println(
" - - - event conditions test - - - ");
181 if(platform ==
null) {
222 for (
int i = 0; i < elements; i++) {
223 assertEquals(4, buffer.
getBuffer().get(i));
235 out.println(
" - - - event synchronization test - - - ");
243 final int elements = roundUp(groupSize, ONE_MB / SIZEOF_INT * 5);
249 fillBuffer(clBufferA.buffer, 12345);
250 fillBuffer(clBufferB.buffer, 67890);
263 assertEquals(0, events.size());
265 vectorAddKernel.
setArgs(clBufferA, clBufferB, clBufferC);
268 assertEquals(1, events.size());
278 out.println(
"time: "+time);
279 assertTrue(time > 0);
290 out.println(
" - - - user events test - - - ");
295 if(platform.isAtLeast(CL_1_1)) {
296 theChosenOne = platform;
302 out.println(
"test disabled, required CLVersion: "+CL_1_1+
" available: "+theChosenOne.
getVersion());
312 final int elements = roundUp(groupSize, ONE_MB / SIZEOF_INT * 5);
318 fillBuffer(clBufferA.buffer, 12345);
319 fillBuffer(clBufferB.buffer, 67890);
328 vectorAddKernel.
setArgs(clBufferA, clBufferB, clBufferC);
333 assertEquals(CommandType.USER, condition.
getType());
334 assertEquals(ExecutionStatus.SUBMITTED, condition.
getStatus());
335 out.println(condition);
339 assertEquals(1, conditions.size());
340 assertEquals(1, conditions.
capacity());
341 assertEquals(0, events.size());
344 queue.
put1DRangeKernel(vectorAddKernel, 0, elements, groupSize, conditions, events);
345 assertEquals(1, events.size());
352 assertEquals(ExecutionStatus.SUBMITTED, status.
getStatus());
354 assertEquals(ExecutionStatus.QUEUED, status.
getStatus());
371 out.println(
" - - - event callback test - - - ");
376 out.println(
"test disabled, required CLVersion: "+CL_1_1+
" available: "+platform.
getVersion());
386 final CountDownLatch countdown =
new CountDownLatch(1);
389 public void eventStateChanged(
final CLEvent event,
final int status) {
390 out.println(
"event received: "+event);
391 assertEquals(event, customEvent);
392 countdown.countDown();
397 customEvent.
setStatus(ExecutionStatus.COMPLETE);
398 countdown.await(2, TimeUnit.SECONDS);
399 assertEquals(countdown.getCount(), 0);
411 out.println(
" - - - QueueBarrier test - - - ");
413 final int elements = ONE_MB / SIZEOF_INT * 10;
422 if (devices.length < 2) {
423 out.println(
"aborting test... need at least 2 devices");
447 fillBuffer(clBufferC.buffer, 12345);
452 final Thread thread1 =
new Thread(
"C") {
459 fillBuffer(clBufferA1.buffer, 12345);
460 fillBuffer(clBufferB1.buffer, 67890);
467 vectorAddKernel1.
setArgs(clBufferA1, clBufferB1, clBufferC);
474 barrier.
waitFor(queue1, events1);
479 final Thread thread2 =
new Thread(
"D") {
486 final int localWorkSize = Math.min( maxWorkItemSize, kernelWorkGroupSize );
488 fillBuffer(clBufferA2.buffer, 12345);
489 fillBuffer(clBufferB2.buffer, 67890);
496 vectorAddKernel2.
setArgs(clBufferA2, clBufferB2, clBufferD);
500 queue2.
put1DRangeKernel(vectorAddKernel2, 0, elements, localWorkSize, events2);
503 barrier.
waitFor(queue2, events2);
508 out.println(
"starting threads");
511 assertTrue(barrier.
await(5, TimeUnit.SECONDS));
514 checkIfEqual(clBufferC.buffer, clBufferD.buffer, elements);
515 out.println(
"results are valid");
517 }
catch (
final Throwable t ) {
524 public static void main(
final String[] args)
throws IOException {
526 org.junit.runner.JUnitCore.
main(tstname);
OpenCL buffer object wrapping an optional NIO buffer.
static void main(final String[] args)
void eventConditionsTest()
void profilingEventsTest()
The command queue is used to queue a set of operations for a specific CLDevice.
CLCommandQueue put1DRangeKernel(final CLKernel kernel, final long globalWorkOffset, final long globalWorkSize, final long localWorkSize)
Calls {@native clEnqueueNDRangeKernel}.
CLCommandQueue finish()
Calls {@native clFinish}.
CLDevice getDevice()
Returns the device of this command queue.
CLCommandQueue putWaitForEvents(final CLEventList list, final boolean blockingWait)
Calls {@native clWaitForEvents} if blockingWait equals true otherwise {@native clEnqueueWaitForEvents...
CLCommandQueue putWaitForEvent(final CLEventList list, final int index, final boolean blockingWait)
Calls {@native clWaitForEvents} if blockingWait equals true otherwise {@native clEnqueueWaitForEvents...
CLCommandQueue putWriteBuffer(final CLBuffer<?> writeBuffer, final boolean blockingRead)
Calls {@native clEnqueueWriteBuffer}.
CLCommandQueue putReadBuffer(final CLBuffer<?> readBuffer, final boolean blockingRead)
Calls {@native clEnqueueReadBuffer}.
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
CLDevice[] getDevices()
Returns all devices associated with this CLContext.
CLProgram createProgram(final String src)
Creates a program from the given sources, the returned program is not build yet.
static CLContext create()
Creates a context on all available devices (CL_DEVICE_TYPE_ALL).
final CLBuffer<?> createBuffer(final int size, final Mem... flags)
Creates a CLBuffer with the specified flags.
final CLBuffer< ByteBuffer > createByteBuffer(final int size, final Mem... flags)
Creates a CLBuffer with the specified flags and buffer size in bytes.
CLPlatform getPlatform()
Returns the CLPlatform this context is running on.
This object represents an OpenCL device.
CLCommandQueue createCommandQueue()
int[] getMaxWorkItemSizes()
Returns the maximum number of work-items that can be specified in each dimension of the work-group.
EnumSet< CLCommandQueue.Mode > getQueueProperties()
Returns the command-queue properties supported by the device.
Fixed size list for storing CLEvents.
int capacity()
Returns the maximum size of this list.
void release()
Releases all CLEvents in this list.
CLEvent getEvent(final int index)
Event objects can be used for synchronizing command queues, e.g you can wait until a event occurs or ...
long getProfilingInfo(final ProfilingCommand command)
ExecutionStatus getStatus()
Returns the execution status of the command which triggers this event.
boolean isComplete()
Returns true only if getStatus returns ExecutionStatus#COMPLETE.
void registerCallback(final CLEventListener callback)
Registers a callback which will be called when the event terminates (COMPLETE or ERROR).
void release()
Releases the OpenCL resource.
High level abstraction for an OpenCL Kernel.
CLKernel setArg(final int argumentIndex, final CLMemory<?> value)
CLKernel putArg(final CLMemory<?> value)
long getWorkGroupSize(final CLDevice device)
Returns the work group size for this kernel on the given device.
CLKernel setArgs(final CLMemory<?>... values)
B getBuffer()
Returns the optional NIO buffer for this memory object.
int getNIOCapacity()
Returns the capacity of the wrapped direct buffer or 0 if no buffer available.
Represents a OpenCL program executed on one or more CLDevices.
CLProgram build()
Builds this program for all devices associated with the context.
CLKernel createCLKernel(final String kernelName)
Creates a kernel with the specified kernel name.
Custom, user controlled event.
CLUserEvent setComplete()
Sets this event's status to CLEvent.ExecutionStatus#COMPLETE.
static CLUserEvent create(final CLContext context)
Creates a new user event.
CLUserEvent setStatus(final CLEvent.ExecutionStatus status)
Sets the event execution status.
CommandType getType()
Returns CLEvent.CommandType#USER.
static Filter< CLDevice > queueMode(final Mode... modes)
Accepts all devices supporting the specified command queue modes.
An utility for synchronizing multiple concurrent CLCommandQueues.
MultiQueueBarrier await()
Blocks until all Threads which called waitFor continue execution.
MultiQueueBarrier waitFor(final CLCommandQueue queue)
Blocks the current Thread until all commands on the CLCommandQueue finished excecution.
Enumeration for the command-queue settings.
static Mode valueOf(final int queueMode)
static EnumSet< Mode > valuesOf(final long bitfield)
COMPLETE
The command has completed.
START
A 64-bit value that describes the current device time counter in nanoseconds when the command identif...
END
A 64-bit value that describes the current device time counter in nanoseconds when the command identif...
Memory settings for configuring CLMemory.
READ_ONLY
Enum representing CL_MEM_READ_ONLY.
A callback for a specific command execution status.
Java bindings to OpenCL, the Open Computing Language.
static final int CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
Define "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE" with expression '(1 << 0)', CType: int.
static final int CL_QUEUE_PROFILING_ENABLE
Define "CL_QUEUE_PROFILING_ENABLE" with expression '(1 << 1)', CType: int.