2

I am unsure if this is necessary. I have two kernels which I need to launch in serial. Do I need to create an event for the first one and then have the second kernel launch wait for that event or can I assume that everything is the queue executes in the order in which I placed it? Is my use of cl_event in the code bellow nessary?

cl_event acceleration_finished;
    cl_check(clEnqueueNDRangeKernel(cmdq, acceleration_kernel, 1, NULL, &acceleration_blocks, 
            &acceleration_threads, 0, NULL, &acceleration_finished));

    cl_event stepper_finished;
    cl_check(clEnqueueNDRangeKernel(cmdq, stepper_kernel, 1, NULL, &N, 
            NULL, 1, &acceleration_finished, &stepper_finished));

    cl_double3* positions_mapped = clEnqueueMapBuffer(cmdq, positions, CL_TRUE, CL_MAP_READ, 0, 
            sizeof(cl_double3) * N, 1, &stepper_finished, NULL, &error);
    cl_check(error);
chasep255
  • 11,745
  • 8
  • 58
  • 115
  • If the queue is not created with the "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE" flag, then you can assume the tasks run in order. https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateCommandQueue.html – DarkZeros Mar 18 '16 at 13:36
  • Thanks. If you post that as an answer I will accept it. – chasep255 Mar 18 '16 at 13:37

1 Answers1

3

For your case, you can just assume full in-order execution (if you did not manually enabled out-of-order).

There a re 2 types of queues in OpenCL:

  • In-order (default):

    • Tasks are executed in the order they are queued. If any of them blocks for any reason, all the following task will not execute until that one finishes.
    • Events are still being used to check if a given task can start or not.
  • Out-of-order (created with the flag CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE):

    • Tasks execute as soon as they are ready to be consumed (all the events they depend on are CL_COMPLETED).

    • This does not mean that N tasks can run in parallel in a single queue if they do not depend on each other. Some hardware does not support that behavior, and requires to create a separate queue to allow parallel execution of tasks. Some other hardware will only support 1 task at a time. That is implementation dependent.

https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateCommandQueue.html

DarkZeros
  • 8,235
  • 1
  • 26
  • 36