我不确定这是否有必要。 我有两个内核需要以串口方式启动。 我是否需要为第一个事件创建一个事件,然后让第二个内核启动等待该事件,或者我可以假设所有事务都是按照我放置它的顺序执行的队列吗? 我在代码中使用cl_event是否正确?
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);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);最满意答案
对于您的情况,您可以假设完全按顺序执行(如果您没有手动启用无序)。
OpenCL中有两种类型的队列:
有序(默认):
任务按排队顺序执行。 如果它们中的任何一个因任何原因而阻塞,则在完成任务之前,以下所有任务都不会执行。 事件仍在用于检查给定任务是否可以启动。CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE序(使用标志CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE创建) :
任务一旦准备就绪就会执行(它们所依赖的所有事件都是CL_COMPLETED )。
这并不意味着N个任务可以在单个队列中并行运行,如果它们不相互依赖的话。 某些硬件不支持该行为,并且需要创建单独的队列以允许并行执行任务。 其他一些硬件一次只能支持1个任务。 这取决于实现。
https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateCommandQueue.html
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
更多推荐
发布评论